Пример #1
0
function MT_Cover_getRecentEntries($parameters)
{
    global $skin;
    $context = Model_Context::getInstance();
    $data = $context->getProperty('plugin.config');
    importlib("model.blog.entry");
    importlib("model.blog.tag");
    $data['coverMode'] = !isset($data['coverMode']) ? 1 : $data['coverMode'];
    if (Utils_Misc::isMetaBlog() != true) {
        $data['coverMode'] = 1;
    }
    $data['screenshot'] = !isset($data['screenshot']) ? 1 : $data['screenshot'];
    $data['screenshotSize'] = !isset($data['screenshotSize']) ? 90 : $data['screenshotSize'];
    $data['paging'] = !isset($data['paging']) ? '2' : $data['paging'];
    $data['contentLength'] = !isset($data['contentLength']) ? 250 : $data['contentLength'];
    if (isset($parameters['preview'])) {
        // preview mode
        $retval = '표지에 최신 글 목록을 추가합니다.';
        return htmlspecialchars($retval);
    }
    $entryLength = isset($parameters['entryLength']) ? $parameters['entryLength'] : 10;
    if (!is_dir(__TEXTCUBE_CACHE_DIR__ . "/thumbnail")) {
        @mkdir(__TEXTCUBE_CACHE_DIR__ . "/thumbnail");
        @chmod(__TEXTCUBE_CACHE_DIR__ . "/thumbnail", 0777);
    }
    if (!is_dir(__TEXTCUBE_CACHE_DIR__ . "/thumbnail/" . $context->getProperty('blog.id'))) {
        @mkdir(__TEXTCUBE_CACHE_DIR__ . "/thumbnail/" . $context->getProperty('blog.id'));
        @chmod(__TEXTCUBE_CACHE_DIR__ . "/thumbnail/" . $context->getProperty('blog.id'), 0777);
    }
    if (!is_dir(__TEXTCUBE_CACHE_DIR__ . "/thumbnail/" . $context->getProperty('blog.id') . "/coverPostThumbnail/")) {
        @mkdir(__TEXTCUBE_CACHE_DIR__ . "/thumbnail/" . $context->getProperty('blog.id') . "/coverPostThumbnail/");
        @chmod(__TEXTCUBE_CACHE_DIR__ . "/thumbnail/" . $context->getProperty('blog.id') . "/coverPostThumbnail/", 0777);
    }
    $page = $data['paging'] == '1' && !empty($_GET['page']) ? intval($_GET['page']) : 1;
    $cache = new PageCache();
    $cache->name = 'MT_Cover_RecentPS';
    if ($cache->load()) {
        //If successful loads
        $cache->contents = unserialize($cache->contents);
        // If coverpage is single mode OR coverpage is coverblog and cache is not expired, return cache contents.
        if (($data['coverMode'] == 1 || $data['coverMode'] == 2) && array_key_exists($page, $cache->contents) && Timestamp::getUNIXtime() - $cache->dbContents < 300) {
            return $cache->contents[$page];
        }
    }
    $pool = DBModel::getInstance();
    $pool->reset("BlogSettings");
    $pool->setQualifier("name", "eq", 'visibility', true);
    $pool->setQualifier("value", "<", 2);
    $privateBlogId = $pool->getCell("blogid");
    $pool->reset("Entries");
    $pool->join("Categories", "left", array(array("e.blogid", "eq", "c.blogid"), array("e.category", "eq", "c.id")));
    $pool->setQualifier("e.draft", "eq", 0);
    $pool->setQualifier("e.category", "beq", 0);
    if ($privateBlogId) {
        $pool->setQualifier("e.blogid", "hasnoneof", $privateBlogId);
    }
    if (Utils_Misc::isMetaBlog() == true && doesHaveOwnership() && $context->getProperty('service.type', 'single') != 'single') {
        $pool->setQualifier("e.visibility", ">", 1);
        $pool->setQualifierSet(array("c.visibility", ">", 1), "OR", array("e.category", "eq", 0));
    } else {
        if (!doesHaveOwnership()) {
            $pool->setQualifier("e.visibility", ">", 1);
            $pool->setQualifierSet(array("c.visibility", ">", 1), "OR", array("e.category", "eq", 0));
        }
    }
    if ($data['coverMode'] != 2) {
        $pool->setQualifier("e.blogid", "eq", $context->getProperty("blog.id"));
    }
    list($entries, $paging) = Paging::fetch($pool, $page, $entryLength);
    $html = '';
    foreach ((array) $entries as $entry) {
        $tagLabelView = "";
        $blogid = $data['coverMode'] == 2 ? $entry['blogid'] : $context->getProperty('blog.id');
        $entryTags = getTags($blogid, $entry['id']);
        $defaultURL = getDefaultURL($blogid);
        if (sizeof($entryTags) > 0) {
            $tags = array();
            foreach ($entryTags as $entryTag) {
                $tags[$entryTag['name']] = "<a href=\"{$defaultURL}/tag/" . (Setting::getBlogSettingGlobal('useSloganOnTag', true) ? URL::encode($entryTag['name'], $service['useEncodedURL']) : $entryTag['id']) . '">' . htmlspecialchars($entryTag['name']) . '</a>';
            }
            $tagLabelView = "<div class=\"post_tags\"><span>TAG : </span>" . implode(",\r\n", array_values($tags)) . "</div>";
        }
        if (empty($entry['category'])) {
            $entry['label'] = _text('분류없음');
            $entry['link'] = "{$defaultURL}/category";
        } else {
            $entry['link'] = "{$defaultURL}/category/" . (Setting::getBlogSettingGlobal('useSloganOnCategory', true) ? URL::encode($entry['label'], $service['useEncodedURL']) : $entry['category']);
        }
        $permalink = "{$defaultURL}/" . (Setting::getBlogSettingGlobal('useSloganOnPost', true) ? "entry/" . URL::encode($entry['slogan'], $context->getProperty('service.useEncodedURL', false)) : $entry['id']);
        $html .= '<div class="coverpost">' . CRLF;
        if ($imageName = MT_Cover_getAttachmentExtract($entry['content'])) {
            if (($tempImageSrc = MT_Cover_getImageResizer($blogid, $imageName, $data['screenshotSize'])) && $data['screenshot'] == 1) {
                $html .= '<div class="img_preview"><a href="' . $permalink . '"><img src="' . $tempImageSrc . '" alt="" /></a></div>' . CRLF;
            }
        }
        $html .= '	<div class="content_box">';
        $html .= '		<h2><a href="' . $permalink . '">' . htmlspecialchars($entry['title']) . '</a></h2>' . CRLF;
        $html .= '		<div class="post_info">' . CRLF;
        $html .= '			<span class="category"><a href="' . htmlspecialchars($entry['link']) . '">' . htmlspecialchars($entry['label']) . '</a></span>' . CRLF;
        $html .= '			<span class="date">' . Timestamp::format5($entry['published']) . '</span>' . CRLF;
        $html .= '			<span class="author"><span class="preposition">by </span>' . User::getName($entry['userid']) . '</span>' . CRLF;
        $html .= '		</div>' . CRLF;
        $html .= '		<div class="post_content">' . htmlspecialchars(Utils_Unicode::lessenAsEm(removeAllTags(stripHTML($entry['content'])), $data['contentLength'])) . '</div>' . CRLF;
        $html .= $tagLabelView;
        $html .= '		<div class="clear"></div>' . CRLF;
        $html .= '	</div>';
        $html .= '</div>' . CRLF;
    }
    if ($data['paging'] == '1') {
        $paging['page'] = $page;
        $paging['total'] = POD::queryCell("SELECT COUNT(*) FROM {$database['prefix']}Entries e WHERE {$multiple} e.draft = 0 {$visibility} AND e.category >= 0");
        $html .= Paging::getPagingView($paging, $skin->paging, $skin->pagingItem) . CRLF;
        $html .= '<script type="text/javascript">' . CRLF;
        $html .= '//<![CDATA[' . CRLF;
        if ($paging['page'] > 1) {
            $html .= 'var prevURL = "' . $paging['url'] . '?page=' . ($paging['page'] - 1) . '"' . CRLF;
        }
        if ($paging['page'] < $paging['total']) {
            $html .= 'var nextURL = "' . $paging['url'] . '?page=' . ($paging['page'] + 1) . '"' . CRLF;
        }
        $html .= '//]]>' . CRLF;
        $html .= '</script>';
    }
    $target = $html;
    $cache->contents[$page] = $target;
    $cache->contents = serialize($cache->contents);
    $cache->dbContents = Timestamp::getUNIXtime();
    $cache->update();
    unset($cache);
    return $target;
}