function getEntryWithPagingBySlogan($blogid, $slogan, $isNotice = false, $categoryId = false) { global $database; global $blogURL; requireModel('blog.category'); $entries = array(); $paging = $isNotice ? Paging::init("{$blogURL}/notice", '/') : Paging::init("{$blogURL}/entry", '/'); $visibility = doesHaveOwnership() ? '' : 'AND e.visibility > 0'; $visibility .= $isNotice || doesHaveOwnership() ? '' : getPrivateCategoryExclusionQuery($blogid); $visibility .= doesHaveOwnership() && !Acl::check('group.editors') ? ' AND (e.userid = ' . getUserId() . ' OR e.visibility > 0)' : ''; $category = $isNotice ? 'e.category = -2' : 'e.category >= 0'; if ($categoryId !== false) { if (!$categoryId == 0) { // Not a 'total' category. $childCategories = getChildCategoryId($blogid, $categoryId); if (!empty($childCategories)) { $category = 'e.category IN (' . $categoryId . ',' . implode(",", $childCategories) . ')'; } else { $category = 'e.category = ' . $categoryId; } } } $currentEntry = POD::queryRow("SELECT e.*, c.label AS categoryLabel \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 e.blogid = {$blogid} \n\t\t\tAND e.slogan = '" . POD::escapeString($slogan) . "' \n\t\t\tAND e.draft = 0 {$visibility} AND {$category}"); $result = POD::query("SELECT e.id, e.slogan \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 e.blogid = {$blogid} \n\t\t\tAND e.draft = 0 {$visibility} AND {$category} \n\t\tORDER BY e.published DESC"); if (!$result || !$currentEntry) { return array($entries, $paging); } if ($categoryId !== false) { $paging['pages'] = $categoryId == 0 ? getEntriesTotalCount($blogid) : getEntriesCountByCategory($blogid, $categoryId); $paging['postfix'] = '?category=' . $categoryId; } else { $paging['pages'] = $isNotice ? getNoticesTotalCount($blogid) : getEntriesTotalCount($blogid); } for ($i = 1; $entry = POD::fetch($result); $i++) { if ($entry['slogan'] != $slogan) { if (array_push($paging['before'], $entry['slogan']) > 4) { if ($i == 5) { $paging['first'] = array_shift($paging['before']); } else { array_shift($paging['before']); } } continue; } $paging['page'] = $i; array_push($entries, $currentEntry); $paging['after'] = array(); for ($i++; count($paging['after']) < 4 && ($entry = POD::fetch($result)); $i++) { array_push($paging['after'], $entry['slogan']); } if ($i < $paging['pages']) { while ($entry = POD::fetch($result)) { $paging['last'] = $entry['slogan']; } } if (count($paging['before']) > 0) { $paging['prev'] = $paging['before'][count($paging['before']) - 1]; } if (isset($paging['after'][0])) { $paging['next'] = $paging['after'][0]; } return array($entries, $paging); } $paging['page'] = $paging['pages'] + 1; return array($entries, $paging); }
function getEntryWithPagingBySlogan($blogid, $slogan, $isSpecialEntry = false, $categoryId = false) { importlib('model.blog.category'); $ctx = Model_Context::getInstance(); importlib('model.blog.category'); $entries = array(); $paging = $isSpecialEntry ? $isSpecialEntry == 'page' ? Paging::init($ctx->getProperty('uri.blog') . "/page", '/') : Paging::init($ctx->getProperty('uri.blog') . "/notice", '/') : Paging::init($ctx->getProperty('uri.blog') . "/entry", '/'); if ($categoryId !== false) { if ($categoryId != 0) { // Not a 'total' category. $childCategories = getChildCategoryId($blogid, $categoryId); } } $pool = DBModel::getInstance(); $pool->init("Entries"); $pool->setAlias("Entries", "e"); $pool->setAlias("Categories", "c"); $pool->join("Categories", "left", array(array("e.blogid", "eq", "c.blogid"), array("e.category", "eq", "c.id"))); if (!doesHaveOwnership()) { $pool->setQualifier("e.visibility", ">", 0); } if (!($isSpecialEntry || doesHaveOwnership())) { $pool = getPrivateCategoryExclusionQualifier($pool, $blogid); } if (doesHaveOwnership() && !Acl::check('group.editors')) { $pool->setQualifierSet(array('e.userid', 'eq', getUserId()), 'OR', array('e.visibility', '>', 0)); } if ($isSpecialEntry) { if ($isSpecialEntry == 'page') { $pool->setQualifier("e.category", "=", -3); } else { $pool->setQualifier("e.category", "=", -2); } } else { $pool->setQualifier("e.category", ">=", 0); } if ($categoryId !== false) { if (!empty($childCategories)) { $pool->setQualifier("e.category", "hasoneof", $childCategories); } else { $pool->setQualifier("e.category", "eq", $categoryId); } } $pool->setQualifier("e.blogid", "eq", $blogid); $pool->setQualifier("e.slogan", "eq", $slogan, true); $pool->setQualifier("e.draft", "eq", 0); $currentEntry = $pool->getRow("e.*, c.label AS categoryLabel"); $pool->unsetQualifier("e.id"); $pool->setOrder("e.published", "DESC"); $result = $pool->getAll("e.id, e.slogan"); if (!$result || !$currentEntry) { return array($entries, $paging); } if ($categoryId !== false) { $paging['pages'] = $categoryId == 0 ? getEntriesTotalCount($blogid) : getEntriesCountByCategory($blogid, $categoryId); $paging['postfix'] = '?category=' . $categoryId; } else { $paging['pages'] = $isSpecialEntry ? $isSpecialEntry == 'page' ? getPagesTotalCount($blogid) : getNoticesTotalCount($blogid) : getEntriesTotalCount($blogid); } for ($i = 1; $entry = array_shift($result); $i++) { if ($entry['slogan'] != $slogan) { if (array_push($paging['before'], $entry['slogan']) > 4) { if ($i == 5) { $paging['first'] = array_shift($paging['before']); } else { array_shift($paging['before']); } } continue; } $paging['page'] = $i; array_push($entries, $currentEntry); $paging['after'] = array(); for ($i++; count($paging['after']) < 4 && ($entry = array_shift($result)); $i++) { array_push($paging['after'], $entry['slogan']); } if ($i < $paging['pages']) { while ($entry = array_shift($result)) { $paging['last'] = $entry['slogan']; } } if (count($paging['before']) > 0) { $paging['prev'] = $paging['before'][count($paging['before']) - 1]; } if (isset($paging['after'][0])) { $paging['next'] = $paging['after'][0]; } return array($entries, $paging); } $paging['page'] = $paging['pages'] + 1; return array($entries, $paging); }