Example #1
0
function getEntryContentView($blogid, $id, $content, $formatter, $keywords = array(), $type = 'Post', $useAbsolutePath = true, $bRssMode = false)
{
    $context = Model_Context::getInstance();
    importlib('model.blog.attachment');
    importlib('model.blog.keyword');
    importlib('blogskin');
    $context = Model_Context::getInstance();
    $cacheKey = 'entry-' . $id . '-' . $type . ($bRssMode ? 'format' : 'summarize') . ($useAbsolutePath ? 'absoultePath' : 'relativePath') . $context->getProperty('blog.displaymode', 'desktop');
    $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 ($context->getProperty('blog.displaymode', 'desktop') == 'mobile') {
            $view = stripHTML($view, array('a', 'abbr', 'acronym', 'address', 'b', 'blockquote', 'br', 'caption', 'cite', 'code', 'dd', 'del', 'dfn', 'div', 'dl', 'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'iframe', 'img', 'ins', 'kbd', 'li', 'ol', 'p', 'pre', 'q', 's', 'samp', 'span', 'strike', 'strong', 'sub', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', '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 = Utils_Misc::getContentWidth();
            if (count($images) > 0) {
                for ($i = 0; $i < count($images); $i++) {
                    if (strtolower(Utils_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 = Utils_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;
}
Example #2
0
function FM_TTML_createNewProperty($filename, $imageWidth, $property)
{
    $blogid = getBlogId();
    $image = Utils_Image::getInstance();
    if (in_array($image->getImageType(__TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/{$filename}"), array('gif', 'png', 'jpg', 'bmp'))) {
        return $image->resizeImageToContent($property, __TEXTCUBE_ATTACH_DIR__ . "/{$blogid}/{$filename}", $imageWidth);
    } else {
        return array($property, false);
    }
}