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; }
function myPlurk_AddPlurkIcon($target, $mother) { global $blogid, $service, $database, $suri, $blogURL, $pluginURL, $configVal; requireComponent('Textcube.Function.misc'); $data = misc::fetchConfigVal($configVal); $attachResponses = isset($data['attachResponses']) && $data['attachResponses'] == 1 ? true : false; $plurklang = Setting::getBlogSettingGlobal('blogLanguage', ''); $plurkIcon = ""; $responsePlurks = ""; if ($suri['directive'] != "/rss" && $suri['directive'] != "/m" && $suri['directive'] != "/i/entry" && $suri['directive'] != "/atom" && $suri['directive'] != "/sync" && POD::queryCount("SELECT id FROM {$database['prefix']}PlurkEntries WHERE blogid={$blogid} AND id={$mother}") > 0) { $plurk_id = intval(POD::queryCell("SELECT plurkid FROM {$database['prefix']}PlurkEntries WHERE blogid={$blogid} AND id={$mother}")); $plurkLink = "http://www.plurk.com/p/" . base_convert($plurk_id, 10, 36); if (!empty($plurkLink)) { $plurkIcon = '<div id="plurkthis"><img src="' . $pluginURL . '/images/plurkicon.png" border="0" width="16" height="16" alt="Plurk This!" /> PLURK: <a href="' . $plurkLink . '" target="_blank">' . $plurkLink . '</a></div><br />'; } if (!$attachResponses) { return $plurkIcon . $target; } $cache = new PageCache(); $cache->name = 'HC_TCPlurkCache'; if ($cache->load()) { $cache->contents = unserialize($cache->contents); if (array_key_exists($mother, $cache->contents) && Timestamp::getUNIXtime() - $cache->dbContents < 600) { return $plurkIcon . $target . $cache->contents[$mother]; } } require_once "libs/plurk_api.php"; $plurk = new plurk_api(); $plurkNickname = isset($data['plurknickname']) ? $data['plurknickname'] : ""; $plurkPassword = isset($data['plurkpassword']) ? $data['plurkpassword'] : ""; $plurk_api = 'iMCH3JDDda7c4bs0qiOchZcxAx7t8PA7'; if (!$plurk->login($plurk_api, $plurkNickname, $plurkPassword)) { return $plurkIcon . $target; } $responsePlurks = ""; $response = $plurk->get_responses($plurk_id); if ($response->responses_seen > 0) { $qualifiers = array("loves", "likes", "shares", "gives", "hates", "wants", "wishes", "needs", "will", "hopes", "asks", "has", "was", "wonders", "feels", "thinks", "says", "is"); $qualifiers_locale = array('en' => $qualifiers, 'zh-TW' => array("愛", "喜歡", "推", "給", "討厭", "想要", "希望", "需要", "打算", "希望", "問", "已經", "曾經", "好奇", "覺得", "想", "說", "正在"), 'zh-CN' => array("爱", "喜欢", "推", "给", "讨厌", "想要", "希望", "需要", "打算", "希望", "问", "已经", "曾经", "好奇", "觉得", "想", "说", "正在")); $lang = "en"; switch ($plurklang) { case "zh-TW": case "zh-CN": $lang = $plurklang; break; default: $lang = "en"; } $friends = array(); $nick2displayname = array('nickname' => array(), 'displayname' => array()); foreach ($response->friends as $friend) { $friends[$friend->uid]['display_name'] = $friend->display_name; $friends[$friend->uid]['nick_name'] = $friend->nick_name; $friends[$friend->uid]['has_profile_image'] = $friend->has_profile_image == 1 ? true : false; $friends[$friend->uid]['avatar'] = $friend->avatar == null ? "" : $friend->avatar; if (!in_array($friend->nick_name, $nick2displayname['nickname'])) { array_push($nick2displayname['nickname'], $friend->nick_name); array_push($nick2displayname['displayname'], $friend->display_name); } } ob_start(); echo "<div class=\"plurkResponse\" id=\"plurkResponse_{$mother}\">\n"; echo "<h3>" . _f("%1 Responses to this Plurk", $response->responses_seen) . "</h3>\n"; echo "<div class=\"plurkResponseLists\">\n<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">\n"; foreach ($response->responses as $commentObj) { $comment = (array) $commentObj; $userIcon = $friends[$comment['user_id']]['has_profile_image'] ? "http://avatars.plurk.com/{$comment['user_id']}-medium{$friends[$comment['user_id']]['avatar']}.gif" : ""; $display_name = $friends[$comment['user_id']]['display_name']; $nick_name = $friends[$comment['user_id']]['nick_name']; $qualifier = in_array($comment['qualifier'], $qualifiers) ? $comment['qualifier'] : ""; $qualifierKey = array_keys($qualifiers, $comment['qualifier']); $qualifier_trans = isset($qualifiers_locale[$lang][$qualifierKey[0]]) ? $qualifiers_locale[$lang][$qualifierKey[0]] : ''; if (preg_match_all('/<a href="http:\\/\\/www.plurk.com\\/(.*?)" class="ex_link">(.*?)<\\/a>/ms', $comment['content'], $matches)) { $mlen = count($matches[1]); for ($i = $mlen - 1; $i >= 0; $i--) { if (in_array($matches[1][$i], $nick2displayname['nickname'])) { $replydisplayname = $nick2displayname['displayname'][array_search($matches[1][$i], $nick2displayname['nickname'])]; $comment['content'] = str_replace('<a href="http://www.plurk.com/' . $matches[1][$i] . '" class="ex_link">' . $matches[2][$i] . '</a>', '<a href="http://www.plurk.com/' . $matches[1][$i] . '" class="ex_link">' . $replydisplayname . '</a>', $comment['content']); } } } echo "<tr><td class=\"user_icon\"><a href=\"http://www.plurk.com/{$nick_name}\" target=\"_blank\"><img src=\"{$userIcon}\" border=\"0\" width=\"45\" height=\"45\" alt=\"{$display_name}\" title=\"{$display_name}\" onerror=\"this.src='{$pluginURL}/images/nonusericon.gif'\" /></a></td>\n"; echo "<td class=\"plurkcontent\"><a href=\"http://www.plurk.com/{$nick_name}\" target=\"_blank\">{$display_name}</a> \n"; echo "<span class=\"qualifier_{$qualifier}\">{$qualifier_trans}</span> <span class=\"plurkcomment\">{$comment['content']}</span></td></tr>\n"; } echo "</table>\n</div>\n<p style=\"text-align:right;line-height:1em;\" class=\"plurkResponseMoreButton\">" . _t('MorePlurk...') . "</p>\n"; echo "</div>\n\n"; $responsePlurks = ob_get_contents(); ob_end_clean(); } else { // no response } $cache->contents[$mother] = $responsePlurks; $cache->contents = serialize($cache->contents); $cache->dbContents = Timestamp::getUNIXtime(); $cache->update(); unset($cache); } return $plurkIcon . $target . $responsePlurks; }
function MT_Cover_getRecentEntries($parameters) { global $database, $blog, $service, $serviceURL, $suri, $configVal, $defaultURL, $skin; requireModel("blog.entry"); requireModel("blog.tag"); $data = Setting::fetchConfigVal($configVal); $data['coverMode'] = !isset($data['coverMode']) ? 1 : $data['coverMode']; if (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/" . getBlogId())) { @mkdir(__TEXTCUBE_CACHE_DIR__ . "/thumbnail/" . getBlogId()); @chmod(__TEXTCUBE_CACHE_DIR__ . "/thumbnail/" . getBlogId(), 0777); } if (!is_dir(__TEXTCUBE_CACHE_DIR__ . "/thumbnail/" . getBlogId() . "/coverPostThumbnail/")) { @mkdir(__TEXTCUBE_CACHE_DIR__ . "/thumbnail/" . getBlogId() . "/coverPostThumbnail/"); @chmod(__TEXTCUBE_CACHE_DIR__ . "/thumbnail/" . getBlogId() . "/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]; } } if (Misc::isMetaBlog() == true && doesHaveOwnership() && $service['type'] != 'single') { $visibility = 'AND e.visibility > 1 AND (c.visibility > 1 OR e.category = 0)'; } else { $visibility = doesHaveOwnership() ? '' : 'AND e.visibility > 1 AND (c.visibility > 1 OR e.category = 0)'; } $multiple = $data['coverMode'] == 2 ? '' : 'e.blogid = ' . getBlogId() . ' AND'; $privateBlogId = POD::queryColumn("SELECT blogid \n\t\tFROM {$database['prefix']}BlogSettings\n\t\tWHERE name = 'visibility'\n\t\tAND value < 2"); if (!empty($privateBlogId)) { $privateBlogs = ' AND e.blogid NOT IN (' . implode(',', $privateBlogId) . ')'; } else { $privateBlogs = ''; } list($entries, $paging) = Paging::fetch("SELECT e.blogid, e.id, e.userid, e.title, e.content, e.slogan, e.category, e.published, e.contentformatter, c.label\n\t\tFROM {$database['prefix']}Entries e\n\t\tLEFT JOIN {$database['prefix']}Categories c ON e.blogid = c.blogid AND e.category = c.id\n\t\tWHERE {$multiple} e.draft = 0 {$visibility} AND e.category >= 0 {$privateBlogs}\n\t\tORDER BY published DESC", $page, $entryLength); $html = ''; foreach ((array) $entries as $entry) { $tagLabelView = ""; $blogid = $data['coverMode'] == 2 ? $entry['blogid'] : getBlogId(); $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'], $service['useEncodedURL']) : $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 .= 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; }