当前位置: 首页>>代码示例>>PHP>>正文


PHP Misc::getAttributesFromString方法代码示例

本文整理汇总了PHP中Misc::getAttributesFromString方法的典型用法代码示例。如果您正苦于以下问题:PHP Misc::getAttributesFromString方法的具体用法?PHP Misc::getAttributesFromString怎么用?PHP Misc::getAttributesFromString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Misc的用法示例。


在下文中一共展示了Misc::getAttributesFromString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: FM_TTML_bindAttachments

function FM_TTML_bindAttachments($entryId, $folderPath, $folderURL, $content, $useAbsolutePath = false, $bRssMode = false)
{
    $context = Model_Context::getInstance();
    requireModel('blog.attachment');
    $blogid = getBlogId();
    getAttachments($blogid, $entryId);
    // For attachment caching.
    $view = str_replace('[##_ATTACH_PATH_##]', $useAbsolutePath ? $context->getProperty('uri.service') . "/attach/{$blogid}" : $folderURL, $content);
    $view = str_replace('http://tt_attach_path/', $useAbsolutePath ? $context->getProperty('uri.service') . "/attach/{$blogid}/" : $folderURL . '/', $view);
    $count = 0;
    $bWritedGalleryJS = false;
    while (($start = strpos($view, '[##_')) !== false && ($end = strpos($view, '_##]', $start + 4)) !== false) {
        $count++;
        $attributes = explode('|', substr($view, $start + 4, $end - $start - 4));
        $prefix = '';
        $buf = '';
        if ($attributes[0] == 'Gallery') {
            if (count($attributes) % 2 == 1) {
                array_pop($attributes);
            }
            if (defined('__TEXTCUBE_MOBILE__') || defined('__TEXTCUBE_IPHONE__')) {
                $images = array_slice($attributes, 1, count($attributes) - 2);
                for ($i = 0; $i < count($images); $i++) {
                    if (!empty($images[$i])) {
                        if ($i % 2 == 0) {
                            $buf .= '<div align="center">' . FM_TTML_getAttachmentBinder($images[$i], '', $folderPath, $folderURL, 1, $useAbsolutePath, $bRssMode) . '</div>';
                        } else {
                            if (strlen($images[$i]) > 0) {
                                $buf .= "<div align=\"center\">{$images[$i]}</div>";
                            }
                        }
                    }
                }
            } else {
                if ($bRssMode == true) {
                    $items = array();
                    for ($i = 1; $i < sizeof($attributes) - 2; $i += 2) {
                        array_push($items, array($attributes[$i], $attributes[$i + 1]));
                    }
                    $galleryAttributes = Misc::getAttributesFromString($attributes[sizeof($attributes) - 1]);
                    $images = array_slice($attributes, 1, count($attributes) - 2);
                    for ($i = 0; $i < count($images); $i++) {
                        if (!empty($images[$i])) {
                            if ($i % 2 == 0) {
                                $setWidth = $setHeight = 0;
                                if (list($width, $height) = @getimagesize("{$folderPath}/{$images[$i]}")) {
                                    $setWidth = $width;
                                    $setHeight = $height;
                                    if (isset($galleryAttributes['width']) && $galleryAttributes['width'] < $setWidth) {
                                        $setHeight = $setHeight * $galleryAttributes['width'] / $setWidth;
                                        $setWidth = $galleryAttributes['width'];
                                    }
                                    if (isset($galleryAttributes['height']) && $galleryAttributes['height'] < $setHeight) {
                                        $setWidth = $setWidth * $galleryAttributes['height'] / $setHeight;
                                        $setHeight = $galleryAttributes['height'];
                                    }
                                    if (intval($setWidth > 0) && intval($setHeight) > 0) {
                                        $tempProperty = 'width="' . intval($setWidth) . '" height="' . intval($setHeight) . '"';
                                    } else {
                                        $tempProperty = '';
                                    }
                                    $buf .= '<div align="center">' . FM_TTML_getAttachmentBinder($images[$i], $tempProperty, $folderPath, $folderURL, 1, $useAbsolutePath, $bRssMode) . '</div>';
                                }
                            } else {
                                if (strlen($images[$i]) > 0) {
                                    $buf .= "<div align=\"center\">{$images[$i]}</div>";
                                }
                            }
                        }
                    }
                } else {
                    $id = "gallery{$entryId}{$count}";
                    $cssId = "tt-gallery-{$entryId}-{$count}";
                    $contentWidth = Misc::getContentWidth();
                    $items = array();
                    for ($i = 1; $i < sizeof($attributes) - 2; $i += 2) {
                        array_push($items, array($attributes[$i], $attributes[$i + 1]));
                    }
                    $galleryAttributes = Misc::getAttributesFromString($attributes[sizeof($attributes) - 1]);
                    if (!isset($galleryAttributes['width'])) {
                        $galleryAttributes['width'] = $contentWidth;
                    }
                    if (!isset($galleryAttributes['height'])) {
                        $galleryAttributes['height'] = 3 / 4 * $galleryAttributes['width'];
                    }
                    if ($galleryAttributes['width'] > $contentWidth) {
                        $galleryAttributes['height'] = $galleryAttributes['height'] * $contentWidth / $galleryAttributes['width'];
                        $galleryAttributes['width'] = $contentWidth;
                    }
                    if ($useAbsolutePath == true && $bWritedGalleryJS == false) {
                        $bWritedGalleryJS = true;
                        $buf .= printScript('gallery.js');
                    }
                    $buf .= CRLF . '<div id="' . $cssId . '" class="tt-gallery-box">' . CRLF;
                    $buf .= '	<script type="text/javascript">' . CRLF;
                    $buf .= '		//<![CDATA[' . CRLF;
                    $buf .= "\t\t\tvar {$id} = new TTGallery(\"{$cssId}\");" . CRLF;
                    $buf .= "\t\t\t{$id}.prevText = \"" . _text('이전 이미지 보기') . "\"; " . CRLF;
                    $buf .= "\t\t\t{$id}.nextText = \"" . _text('다음 이미지 보기') . "\"; " . CRLF;
                    $buf .= "\t\t\t{$id}.enlargeText = \"" . _text('원본 크기로 보기') . "\"; " . CRLF;
//.........这里部分代码省略.........
开发者ID:ragi79,项目名称:Textcube,代码行数:101,代码来源:ttml.php

示例2: getRemoteFeed

function getRemoteFeed($url)
{
    global $service, $serviceURL;
    $xml = fireEvent('GetRemoteFeed', null, $url);
    if (empty($xml)) {
        $request = new HTTPRequest($url);
        $request->referer = $serviceURL;
        $request->timeout = 3;
        if (!$request->send()) {
            return array(2, null, null);
        }
        $xml = $request->responseText;
    }
    $feed = array('xmlurl' => isset($request) ? $request->url : $url);
    $xmls = new XMLStruct();
    if (!$xmls->open($xml, $service['encoding'])) {
        if (preg_match_all('/<link .*?rel\\s*=\\s*[\'"]?alternate.*?>/i', $xml, $matches)) {
            foreach ($matches[0] as $link) {
                $attributes = Misc::getAttributesFromString($link);
                if (isset($attributes['href'])) {
                    $urlInfo = parse_url($url);
                    $rssInfo = parse_url($attributes['href']);
                    $rssURL = false;
                    if (isset($rssInfo['scheme']) && $rssInfo['scheme'] == 'http') {
                        $rssURL = $attributes['href'];
                    } else {
                        if (isset($rssInfo['path'])) {
                            if ($rssInfo['path'][0] == '/') {
                                $rssURL = "{$urlInfo['scheme']}://{$urlInfo['host']}{$rssInfo['path']}";
                            } else {
                                $rssURL = "{$urlInfo['scheme']}://{$urlInfo['host']}" . (isset($urlInfo['path']) ? rtrim($urlInfo['path'], '/') : '') . '/' . $rssInfo['path'];
                            }
                        }
                    }
                    if ($rssURL && $url != $rssURL) {
                        return getRemoteFeed($rssURL);
                    }
                }
            }
        }
        return array(3, null, null);
    }
    if ($xmls->getAttribute('/rss', 'version')) {
        $feed['blogURL'] = $xmls->getValue('/rss/channel/link');
        $feed['title'] = $xmls->getValue('/rss/channel/title');
        $feed['description'] = $xmls->getValue('/rss/channel/description');
        if (Validator::language($xmls->getValue('/rss/channel/language'))) {
            $feed['language'] = $xmls->getValue('/rss/channel/language');
        } else {
            if (Validator::language($xmls->getValue('/rss/channel/dc:language'))) {
                $feed['language'] = $xmls->getValue('/rss/channel/dc:language');
            } else {
                $feed['language'] = 'en-US';
            }
        }
        $feed['modified'] = gmmktime();
    } else {
        if ($xmls->doesExist('/feed')) {
            $feed['blogURL'] = $xmls->getAttribute('/feed/link', 'href');
            $feed['title'] = $xmls->getValue('/feed/title');
            $feed['description'] = $xmls->getValue('/feed/tagline');
            if (Validator::language($xmls->getAttribute('/feed', 'xml:lang'))) {
                $feed['language'] = $xmls->getAttribute('/feed', 'xml:lang');
            } else {
                $feed['language'] = 'en-US';
            }
            $feed['modified'] = gmmktime();
        } else {
            if ($xmls->getAttribute('/rdf:RDF', 'xmlns')) {
                if ($xmls->getAttribute('/rdf:RDF/channel/link', 'href')) {
                    $feed['blogURL'] = $xmls->getAttribute('/rdf:RDF/channel/link', 'href');
                } else {
                    if ($xmls->getValue('/rdf:RDF/channel/link')) {
                        $feed['blogURL'] = $xmls->getValue('/rdf:RDF/channel/link');
                    } else {
                        $feed['blogURL'] = '';
                    }
                }
                $feed['title'] = $xmls->getValue('/rdf:RDF/channel/title');
                $feed['description'] = $xmls->getValue('/rdf:RDF/channel/description');
                if (Validator::language($xmls->getValue('/rdf:RDF/channel/dc:language'))) {
                    $feed['language'] = $xmls->getValue('/rdf:RDF/channel/dc:language');
                } else {
                    if (Validator::language($xmls->getAttribute('/rdf:RDF', 'xml:lang'))) {
                        $feed['language'] = $xmls->getAttribute('/rdf:RDF', 'xml:lang');
                    } else {
                        $feed['language'] = 'en-US';
                    }
                }
                $feed['modified'] = gmmktime();
            } else {
                return array(3, null, null);
            }
        }
    }
    $feed['xmlurl'] = POD::escapeString(Utils_Unicode::lessenAsEncoding(Utils_Unicode::correct($feed['xmlurl'])));
    $feed['blogURL'] = POD::escapeString(Utils_Unicode::lessenAsEncoding(Utils_Unicode::correct($feed['blogURL'])));
    $feed['title'] = POD::escapeString(Utils_Unicode::lessenAsEncoding(Utils_Unicode::correct($feed['title'])));
    $feed['description'] = POD::escapeString(Utils_Unicode::lessenAsEncoding(Utils_Unicode::correct(stripHTML($feed['description']))));
    $feed['language'] = POD::escapeString(Utils_Unicode::lessenAsEncoding(Utils_Unicode::correct($feed['language']), 255));
//.........这里部分代码省略.........
开发者ID:ragi79,项目名称:Textcube,代码行数:101,代码来源:reader.common.php

示例3: resizeImageToContent

 function resizeImageToContent($property, $originSrc, $imageWidth)
 {
     if (!is_readable($originSrc)) {
         return array($property, false);
     }
     list($originWidth, $originHeight, $type, $attr) = getimagesize($originSrc);
     $attributes = Misc::getAttributesFromString($property, false);
     // 단위 변환.
     $onclickFlag = false;
     if (array_key_exists('width', $attributes)) {
         if (preg_match('/(.+)(%?)/', $attributes['width'], $matches)) {
             if ($matches[2] == '%') {
                 $attributes['width'] = round($originWidth * $matches[1] / 100);
             } else {
                 $attributes['width'] = intval($matches[1]);
             }
         }
     }
     if (array_key_exists('height', $attributes)) {
         if (preg_match('/(.+)(%?)/', $attributes['height'], $matches)) {
             if ($matches[2] == '%') {
                 $attributes['height'] = round($originHeight * $matches[1] / 100);
             } else {
                 $attributes['height'] = intval($matches[1]);
             }
         }
     }
     // 가로, 세로 어느 쪽이든 0이면 이미지는 표시되지 않음. 따라서 계산할 필요 없음.
     if (isset($attributes['width']) && $attributes['width'] <= 0 || isset($attributes['height']) && $attributes['height'] <= 0) {
         return array($property, false);
     }
     // 가로만 지정된 이미지의 경우.
     if (isset($attributes['width']) && !isset($attributes['height'])) {
         // 비어있는 세로를 가로의 크기를 이용하여 계산.
         $attributes['height'] = floor($originHeight * $attributes['width'] / $originWidth);
         // 세로만 지정된 이미지의 경우.
     } else {
         if (!isset($attributes['width']) && isset($attributes['height'])) {
             // 비어있는 가로를 세로의 크기를 이용하여 계산.
             $attributes['width'] = floor($originWidth * $attributes['height'] / $originHeight);
             // 둘 다 지정되지 않은 이미지의 경우.
         } else {
             if (!isset($attributes['width']) && !isset($attributes['height'])) {
                 // 둘 다 비어 있을 경우는 오리지널 사이즈로 대치.
                 $attributes['width'] = $originWidth;
                 $attributes['height'] = $originHeight;
             }
         }
     }
     if ($attributes['width'] > $imageWidth) {
         $attributes['height'] = floor($attributes['height'] * $imageWidth / $attributes['width']);
         $attributes['width'] = $imageWidth;
     }
     if ($attributes['width'] < $originWidth || $attributes['height'] < $originHeight) {
         $onclickFlag = true;
     } else {
         $onclickFlag = false;
     }
     $properties = array();
     ksort($attributes);
     foreach ($attributes as $key => $value) {
         array_push($properties, "{$key}=\"{$value}\"");
     }
     return array(implode(' ', $properties), $onclickFlag);
 }
开发者ID:ragi79,项目名称:Textcube,代码行数:65,代码来源:Image.php

示例4: getEntryContentView

function getEntryContentView($blogid, $id, $content, $formatter, $keywords = array(), $type = 'Post', $useAbsolutePath = true, $bRssMode = false)
{
    $ctx = Model_Context::getInstance();
    requireModel('blog.attachment');
    requireModel('blog.keyword');
    requireLibrary('blog.skin');
    $cacheKey = 'entry-' . $id . '-' . $type . ($bRssMode ? 'format' : 'summarize') . ($useAbsolutePath ? 'absoultePath' : 'relativePath') . (defined('__TEXTCUBE_MOBILE__') ? 'mobile' : '');
    $cache = pageCache::getInstance();
    $cache->reset($cacheKey);
    if (!defined('__TEXTCUBE_NO_ENTRY_CACHE__') && $cache->load()) {
        // If cached content exists.
        $view = $cache->contents;
    } else {
        // No cache is found.
        $content = fireEvent('Format' . $type . 'Content', $content, $id);
        $func = $bRssMode ? 'summarizeContent' : 'formatContent';
        $view = $func($blogid, $id, $content, $formatter, $keywords, $useAbsolutePath);
        if (defined('__TEXTCUBE_MOBILE__')) {
            $view = stripHTML($view, array('a', 'abbr', 'acronym', 'address', 'b', 'blockquote', 'br', 'cite', 'code', 'dd', 'del', 'dfn', 'div', 'dl', 'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'ins', 'kbd', 'li', 'ol', 'p', 'pre', 'q', 's', 'samp', 'span', 'strike', 'strong', 'sub', 'sup', 'u', 'ul', 'var'));
        }
        if (!$useAbsolutePath) {
            $view = avoidFlashBorder($view);
        }
        if (!empty($keywords) && is_array($keywords)) {
            $view = bindKeywords($keywords, $view);
        }
        // image resampling
        if (Setting::getBlogSettingGlobal('resamplingDefault') == true) {
            preg_match_all("@<img.+src=['\"](.+)['\"](.*)/?>@Usi", $view, $images, PREG_SET_ORDER);
            $view = preg_replace("@<img.+src=['\"].+['\"].*/?>@Usi", '[#####_#####_#####_image_#####_#####_#####]', $view);
            $contentWidth = Misc::getContentWidth();
            if (count($images) > 0) {
                for ($i = 0; $i < count($images); $i++) {
                    if (strtolower(Misc::getFileExtension($images[$i][1])) == 'gif') {
                        $view = preg_replace('@\\[#####_#####_#####_image_#####_#####_#####\\]@', $images[$i][0], $view, 1);
                        continue;
                    }
                    $attributes = preg_match('/(style="cursor: pointer;" onclick="open_img\\((.[^"]+)\\); return false;")/si', $images[$i][2], $matches) ? ' ' . $matches[1] : '';
                    $attributes .= preg_match('/(alt="([^"]*)")/si', $images[$i][2], $matches) ? ' ' . $matches[1] : ' alt="resize"';
                    $attributes .= preg_match('/(title="([^"]*)")/si', $images[$i][2], $matches) ? $title = ' ' . $matches[1] : '';
                    $tempFileName = array_pop(explode('/', $images[$i][1]));
                    if (preg_match('/(.+)\\.w(\\d{1,})\\-h(\\d{1,})\\.(.+)/', $tempFileName, $matches)) {
                        $tempFileName = $matches[1] . '.' . $matches[4];
                    }
                    $newImage = $images[$i][0];
                    if (file_exists(__TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/{$tempFileName}")) {
                        $tempAttributes = Misc::getAttributesFromString($images[$i][2]);
                        $tempOriginInfo = getimagesize(__TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/{$tempFileName}");
                        if (isset($tempAttributes['width']) && $tempOriginInfo[0] > $tempAttributes['width']) {
                            $image = Utils_Image::getInstance();
                            list($tempImageURL, $tempImageWidth, $tempImageHeight, $tempImageSrc) = $image->getImageResizer($tempFileName, array('width' => $tempAttributes['width']));
                            $newImage = "<img src=\"{$tempImageURL}\" width=\"{$tempImageWidth}\" height=\"{$tempImageHeight}\"{$attributes}/>";
                        }
                    }
                    $view = preg_replace('@\\[#####_#####_#####_image_#####_#####_#####\\]@', $newImage, $view, 1);
                }
            }
        }
        $cache->contents = $view;
        $cache->update();
    }
    $cache->reset();
    $view = fireEvent('View' . $type . 'Content', $view, $id);
    return $view;
}
开发者ID:ragi79,项目名称:Textcube,代码行数:65,代码来源:view.php


注:本文中的Misc::getAttributesFromString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。