public function output() { global $vbulletin; $sectionid = 1; //First we'll generate the category list //compose the sql $rst = vB::$vbulletin->db->query_read($sql = "SELECT parent.category AS parentcat, cat.categoryid, cat.category,\n\t\tcat.catleft, cat.catright, info.title AS node, parentnode.nodeid, count(nodecat.nodeid) as qty\n\tFROM " . TABLE_PREFIX . "cms_node AS node\n\t\tINNER JOIN " . TABLE_PREFIX . "cms_node AS parentnode ON (node.nodeleft >= parentnode.nodeleft AND node.nodeleft <= parentnode.noderight)\n\t\tINNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info ON info.nodeid = parentnode.nodeid\n\tINNER JOIN " . TABLE_PREFIX . "cms_category AS parent on parent.parentnode = node.nodeid\n\t\tINNER JOIN " . TABLE_PREFIX . "cms_category AS cat ON (cat.catleft >= parent.catleft AND cat.catleft <= parent.catright)\n\t\tLEFT JOIN " . TABLE_PREFIX . "cms_nodecategory AS nodecat ON nodecat.categoryid = cat.categoryid\n\t\tWHERE parentnode.nodeid = " . $sectionid . " AND " . vBCMS_Permissions::getPermissionString() . "\n\t\tGROUP BY parent.category, cat.categoryid, cat.category,\n\t\tcat.catleft, cat.catright, info.title, parentnode.nodeid\n\t\tORDER BY node.nodeleft, catleft;"); $parents = array(); $level = 0; $nodes = array(); if ($record = vB::$vbulletin->db->fetch_array($rst)) { $record['level'] = $level; $record['route_info'] = $record['categoryid'] . ($record['category'] != '' ? '-' . str_replace(' ', '-', $record['category']) : ''); $nodes[strtolower($record['category'])] = $parents[0] = $record; $last_category = -1; while ($record = vB::$vbulletin->db->fetch_array($rst)) { $record['route_info'] = $record['categoryid'] . ($record['category'] != '' ? '-' . str_replace(' ', '-', $record['category']) : ''); if ($record['categoryid'] == $last_category) { continue; } //note that since we're already sorted by by catleft we don't need to check that. while (intval($record['catright']) > intval($parents['level']['catright']) and $level > 0) { $level--; } $level++; $record['level'] = $level; $nodes[strtolower($record['category'])] = $parents[$level] = $record; $last_category = $record['categoryid']; } } ksort($nodes); return $nodes; }
public function process() { if (!vB::$vbulletin->products['vbcms']) { return true; } if (!$this->content['cms_nodeid']) { return true; } $nodes = vB::$db->query_read_slave("\n\t\t\tSELECT\n\t\t\t\tnode.nodeid AS n_nodeid, node.url AS n_url, node.comments_enabled AS n_comments_enabled, node.userid AS n_userid,\n\t\t\t\tni.viewcount AS n_viewcount, ni.title AS n_title, ni.html_title AS n_html_title, a.contentid AS n_contentid,\n\t\t\t\ta.pagetext AS a_pagetext, a.contentid AS a_contentid, node.nodeid AS a_nodeid, node.parentnode AS n_parentnode,\n\t\t\t\tthread.replycount AS n_replycount, node.publishdate AS n_publishdate, node.setpublish AS n_published\n\t\t\tFROM " . TABLE_PREFIX . "cms_node AS node\n\t\t\tINNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS ni ON (node.nodeid = ni.nodeid)\n\t\t\tINNER JOIN " . TABLE_PREFIX . "cms_article AS a ON (node.contentid = a.contentid)\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "thread AS thread ON (thread.threadid = ni.associatedthreadid)\n\t\t\tWHERE\n\t\t\t\tnode.nodeid IN (" . implode(",", array_keys($this->content['cms_nodeid'])) . ")\n\t\t\t\t\tAND\n\t\t\t\t" . vBCMS_Permissions::getPermissionString() . "\n\t\t"); while ($node = vB::$db->fetch_array($nodes)) { $this->content['cms_node'][$node['n_nodeid']] = $this->parse_array($node, 'n_'); $this->content['cms_article'][$node['a_contentid']] = $this->parse_array($node, 'a_'); $this->content['userid'][$node['n_userid']] = 1; } $this->content['cms_nodeid'] = array(); }
public function process() { if (!vB::$vbulletin->products['vbcms']) { return true; } if (!$this->content['cms_postid']) { return true; } $posts = vB::$db->query_read_slave("\n\t\t\tSELECT\n\t\t\t\tp.pagetext AS p_pagetext, p.postid AS p_postid, p.threadid AS p_threadid, p.title AS p_title, p.visible AS p_visible, p.userid AS p_userid, p.username AS p_username,\n\t\t\t\tni.nodeid AS p_nodeid, ni.viewcount AS ni_viewcount, node.nodeid AS ni_nodeid, ni.title AS ni_title, ni.html_title AS ni_html_title,\n\t\t\t\tnode.url AS ni_url, node.comments_enabled AS ni_comments_enabled, node.userid AS ni_userid, node.parentnode AS ni_parentnode,\n\t\t\t\ta.pagetext AS a_pagetext, a.contentid AS a_contentid, node.nodeid AS a_nodeid, a.contentid AS ni_contentid, thread.replycount AS ni_replycount,\n\t\t\t\tnode.publishdate AS ni_publishdate, node.setpublish AS ni_published, thread.forumid AS p_forumid\n\t\t\tFROM " . TABLE_PREFIX . "post AS p\n\t\t\tINNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS ni ON (p.threadid = ni.associatedthreadid)\n\t\t\tINNER JOIN " . TABLE_PREFIX . "cms_node AS node ON (ni.nodeid = node.nodeid)\n\t\t\tINNER JOIN " . TABLE_PREFIX . "cms_article AS a ON (node.contentid = a.contentid)\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "thread AS thread ON (thread.threadid = p.threadid)\n\t\t\tWHERE\n\t\t\t\tp.postid IN (" . implode(",", array_keys($this->content['cms_postid'])) . ")\n\t\t\t\t\tAND\n\t\t\t\t" . vBCMS_Permissions::getPermissionString() . "\n\t\t"); while ($post = vB::$db->fetch_array($posts)) { unset($this->content['cms_nodeid'][$post['ni_nodeid']]); $this->content['cms_post'][$post['p_postid']] = $this->parse_array($post, 'p_'); $this->content['userid'][$post['p_userid']] = 1; if (!$this->content['cms_node'][$post['ni_nodeid']]) { $this->content['cms_node'][$post['ni_nodeid']] = $this->parse_array($post, 'ni_'); $this->content['cms_article'][$post['a_contentid']] = $this->parse_array($post, 'a_'); $this->content['userid'][$post['ni_userid']] = 1; } } $this->content['cms_postid'] = array(); }
function do_get_cms_section() { global $vbulletin, $db; $vbulletin->input->clean_array_gpc('r', array('sectionid' => TYPE_UINT, 'page' => TYPE_UINT, 'perpage' => TYPE_UINT)); $sectionid = $vbulletin->GPC['sectionid']; if (!$vbulletin->GPC_exists['sectionid']) { $sectionid = 1; } $sectionid = intval($sectionid); $page = 1; if ($vbulletin->GPC['page']) { $page = $vbulletin->GPC['page']; } $perpage = 10; if ($vbulletin->GPC['perpage']) { $perpage = $vbulletin->GPC['perpage']; } if ($perpage > 50 || $perpage < 5) { $perpage = 10; } if ($page < 1) { $page = 1; } $limitsql = 'LIMIT ' . ($page - 1) * $perpage . ', ' . $perpage; if (!isset(vB::$vbulletin->userinfo['permissions']['cms'])) { vBCMS_Permissions::getUserPerms(); } $config = $vbulletin->db->query_first("\n\tSELECT config1.value AS priority, config2.value AS contentfrom, nodeinfo.title AS section_title\n\tFROM " . TABLE_PREFIX . "cms_node AS node\n\tLEFT JOIN " . TABLE_PREFIX . "cms_nodeconfig AS config1 ON config1.nodeid = node.nodeid AND config1.name = 'section_priority'\n\tLEFT JOIN " . TABLE_PREFIX . "cms_nodeconfig AS config2 ON config2.nodeid = node.nodeid AND config2.name = 'contentfrom'\n\tLEFT JOIN " . TABLE_PREFIX . "cms_nodeinfo AS nodeinfo ON nodeinfo.nodeid = node.nodeid\n\tWHERE node.nodeid = {$sectionid}\n\tGROUP BY node.nodeid\n "); $sortby = 3; $exact = false; $section_title = 'News'; if ($config) { if (isset($config['priority'])) { $sortby = intval($config['priority']); } if (isset($config['contentfrom'])) { if (intval($config['contentfrom']) != 2) { $exact = true; } } if (isset($config['section_title'])) { $section_title = $config['section_title']; } } $extrasql = $orderby = ''; if ($sortby == 3) { $extrasql = " INNER JOIN (SELECT parentnode, MAX(lastupdated) AS lastupdated\n\t FROM " . TABLE_PREFIX . "cms_node AS node WHERE contenttypeid <> " . vb_Types::instance()->getContentTypeID("vBCms_Section") . " AND\t" . vBCMS_Permissions::getPermissionString() . " GROUP BY parentnode ) AS ordering ON ordering.parentnode = node.parentnode\n\t AND node.lastupdated = ordering.lastupdated WHERE 1=1"; $orderby = " ORDER BY node.setpublish DESC, node.publishdate DESC "; } else { if ($sortby == 2) { $orderby = " ORDER BY node.publishdate DESC "; } else { if ($sortby == 4) { $orderby = " ORDER BY info.title ASC "; } else { if ($sortby == 5) { $orderby = " ORDER BY sectionorder.displayorder ASC "; } else { $orderby = " ORDER BY CASE WHEN sectionorder.displayorder > 0 THEN sectionorder.displayorder ELSE 9999999 END ASC,\n\t node.publishdate DESC"; } } } } $sql = "\n\tSELECT SQL_CALC_FOUND_ROWS\n\t node.nodeid AS itemid,\n\t (node.nodeleft = 1) AS isroot, node.nodeid, node.contenttypeid, node.contentid, node.url, node.parentnode, node.styleid, node.userid,\n\t node.layoutid, node.publishdate, node.setpublish, node.issection, parent.permissionsfrom as parentpermissions,\n\t node.permissionsfrom, node.publicpreview, node.showtitle, node.showuser, node.showpreviewonly, node.showall,\n\t node.showupdated, node.showviewcount, node.showpublishdate, node.settingsforboth, node.includechildren, node.editshowchildren,\n\t node.shownav, node.hidden, node.nosearch, node.nodeleft,\n\t info.description, info.title, info.html_title, info.viewcount, info.creationdate, info.workflowdate,\n\t info.workflowstatus, info.workflowcheckedout, info.workflowlevelid, info.associatedthreadid,\n\t user.username, sectionorder.displayorder, thread.replycount, parentinfo.title AS parenttitle\n\tFROM " . TABLE_PREFIX . "cms_node AS node\n\tINNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info ON info.nodeid = node.nodeid\n\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON user.userid = node.userid\n\tLEFT JOIN " . TABLE_PREFIX . "thread AS thread ON thread.threadid = info.associatedthreadid\n\tLEFT JOIN " . TABLE_PREFIX . "cms_sectionorder AS sectionorder ON sectionorder.sectionid = {$sectionid}\n\tAND sectionorder.nodeid = node.nodeid\n\tLEFT JOIN " . TABLE_PREFIX . "cms_node AS parent ON parent.nodeid = node.parentnode\n\tLEFT JOIN " . TABLE_PREFIX . "cms_nodeinfo AS parentinfo ON parentinfo.nodeid = parent.nodeid\n\t" . ($sectionid ? " INNER JOIN " . TABLE_PREFIX . "cms_node AS rootnode\n\t\t\t\t\tON rootnode.nodeid = {$sectionid}\n\t\t\t\t\tAND (node.nodeleft >= rootnode.nodeleft AND node.nodeleft <= rootnode.noderight) AND node.nodeleft != rootnode.nodeleft " : '') . $extrasql . " AND node.contenttypeid <> " . vb_Types::instance()->getContentTypeID("vBCms_Section") . " AND node.new != 1 " . " AND ( (" . vBCMS_Permissions::getPermissionString() . ") OR (node.setpublish AND node.publishdate <" . TIMENOW . " AND node.publicpreview > 0)) " . ($exact ? "AND (node.parentnode = " . intval($sectionid) . " OR sectionorder.displayorder > 0 )" : '') . ($sortby == 5 ? " AND sectionorder.displayorder > 0 " : '') . "\n\t\t\t\t{$orderby}\n\t\t\t\t{$limitsql}\n "; $articles = array(); $items = $vbulletin->db->query_read_slave($sql); $total = $vbulletin->db->found_rows(); while ($item = $vbulletin->db->fetch_array($items)) { $article = new vBCms_Item_Content_Article($item['nodeid'], vBCms_Item_Content::INFO_CONTENT); $tmp = array('articleid' => $article->getNodeId(), 'title' => prepare_utf8_string($article->getTitle()), 'pubdate' => prepare_utf8_string(vbdate('M j, Y g:i A T', $article->getPublishDate())), 'preview' => prepare_utf8_string(preview_chop(str_replace(array("\n", "\r", "\t"), array('', '', ''), strip_tags($article->getPreviewText(false))), FR_PREVIEW_LEN))); $thread_id = $article->getThreadId(); if ($thread_id) { $tmp['threadid'] = $thread_id; } $previewimage = $article->getPreviewImage(); if ($previewimage) { if (strpos($previewimage, 'http') === false) { $previewimage = $vbulletin->options['bburl'] . '/' . $previewimage; } $tmp['image'] = $vbulletin->options['bburl'] . "/forumrunner/image.php?url={$previewimage}&w=160&h=160"; } $articles[] = $tmp; } $out = array('total_articles' => $total, 'articles' => $articles, 'section_title' => prepare_utf8_string(strip_tags($section_title))); return $out; }
/** This function gets the article information based on the defined criteria * * @return array */ protected function getContent() { // First, compose the sql $sql = "SELECT node.contenttypeid, node.url, node.publishdate, node.userid, node.setpublish, node.publicpreview, info.title, user.username, node.showuser, node.nodeid, node.contenttypeid, thread.replycount FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "contenttype AS type on type.contenttypeid = node.contenttypeid INNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info on info.nodeid = node.nodeid " . ( (($this->config['categories'] != '') AND ($this->config['categories'] != '0')) ? " INNER JOIN " . TABLE_PREFIX . "cms_nodecategory nc ON nc.nodeid = node.nodeid " : '') . " LEFT JOIN " . TABLE_PREFIX . "user AS user ON user.userid = node.userid LEFT JOIN " . TABLE_PREFIX . "thread AS thread ON thread.threadid = info.associatedthreadid WHERE type.isaggregator = '0' AND " . vBCMS_Permissions::getPermissionString() ; if (($this->config['categories'] != '') AND ($this->config['categories'] != '0') ) { $sql .= "\n AND nc.categoryid IN (" . $this->config['categories'] . ")\n"; } if (($this->config['sections'] != '') AND ($this->config['sections'] != '0')) { $sql .= "\n AND node.parentnode IN (" . $this->config['sections'] . ")\n"; } if (isset($this->config['days']) AND (intval($this->config['days'])) ) { $sql .= "\n AND node.publishdate > " . (TIMENOW - (86400 * $this->config['days'])) . "\n"; } $sql .= "\n ORDER BY node.publishdate DESC LIMIT " . $this->config['count']; $items = array(); //Execute if ($rst = vB::$db->query_read($sql)) { $current_record = array('contentid' => -1); //now build the results array while($item = vB::$db->fetch_array($rst)) { $item['categories'] = array(); $item['tags'] = array(); $class = vB_Types::instance()->getContentTypeClass($item['contenttypeid']); $package = vB_Types::instance()->getContentTypePackage($item['contenttypeid']); $node = vBCms_Content::create($package, $class, $item['nodeid']); $item['pagetext'] = $item['previewtext'] = ''; //get the avatar if (vB::$vbulletin->options['avatarenabled']) { $item['avatar'] = fetch_avatar_url($item['userid']); } if (method_exists($node, 'getPageText')) { $item['pagetext'] = fetch_censored_text($node->getPageText()); } if (method_exists($node, 'getPreviewText')) { $item['previewtext'] = fetch_censored_text($node->getPreviewText()); } else if (!empty($item['pagetext'])) { $item['previewtext'] = vB_Search_Searchtools::getSummary($item['pagetext'], 200); } if (method_exists($node, 'getPreviewImage')) { $item['pagetext'] = fetch_censored_text($node->getPageText()); } $items[$item['nodeid']] = $item; } //Let's get the tags and the categories // we can do that with one query each. if (count($articles)) { //first let's get categories $nodeids = implode(', ', array_keys($item)); $sql = "SELECT nc.nodeid, nc.categoryid, category.category FROM " . TABLE_PREFIX . "cms_nodecategory AS nc INNER JOIN " . TABLE_PREFIX . "cms_category AS category ON category.categoryid = nc.categoryid WHERE nc.nodeid IN ($nodeids)"; if ($rst = vB::$db->query_read($sql)) { while ($record = vB::$db->fetch_array($rst)) { $route_info = $record['categoryid'] . ($record['category'] != '' ? '-' . str_replace(' ', '-', $record['category']) : ''); $record['route_info'] = $route_info; $record['category_url'] = vB_Route::create('vBCms_Route_List', "category/" . $record['route_info'] . "/1")->getCurrentURL(); $items[$record['nodeid']]['categories'][$record['categoryid']] = $record; } } //next tags; $sql = "SELECT tag.tagid, node.nodeid, tag.tagtext FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "tagcontent AS tc ON (tc.contentid = node.contentid AND tc.contenttypeid = node.contenttypeid) INNER JOIN " . TABLE_PREFIX . "tag AS tag ON tag.tagid = tc.tagid WHERE node.nodeid IN ($nodeids) "; if ($rst = vB::$db->query_read($sql)) { while ($record = vB::$db->fetch_array($rst)) { $items[$record['nodeid']]['tags'][$record['tagid']] = $record['tagtext']; } } } } return $items; }
/** * This is the second function for creating navigation. It gives us * the parent of the current node, and the top-level parent. * We return a tree, from the parent of this node to the top-level parent * * @return array($nodeid => array(title, url), ordered by title */ public function getParentNodes($nodeid = null, $parents = null) { if (! isset($this->content)) { return false; } if (is_null($nodeid)) { $parents = array(); if (! $nodeid = $this->content->getNodeId() OR !$this->checkNodeLR()) { return false; } }; $user_where = vBCMS_Permissions::getPermissionString() ; if ($rst = vB::$db->query_read("SELECT node2.nodeid, cms_nodeinfo.title, node2.url FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "cms_node AS node2 ON (node.nodeleft >= node2.nodeleft AND node.nodeleft <=node2.noderight) INNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS cms_nodeinfo ON cms_nodeinfo.nodeid = node2.nodeid WHERE node.nodeid = $nodeid AND node2.nodeid <> $nodeid AND ($user_where) order by node.nodeleft DESC ;")) { while ($row = vB::$db->fetch_row($rst)) { $parents[] = array('title' =>$row[1], 'url' => $row[2], 'nodeid' => $row[0]); } } return $parents; }
/** * Fetches the SQL for loading. * $required_query is used to identify which query to build for classes that * have multiple queries for fetching info. * * This can safely be based on $this->required_info as long as a consitent * flag is used for identifying the query. * * @param int $required_query - The required query * @param bool $force_rebuild - Whether to rebuild the string * * @return string */ protected function getLoadQuery($required_query = self::QUERY_BASIC, $force_rebuild = false) { // Hooks should check the required query before populating the hook vars $hook_query_fields = $hook_query_joins = $hook_query_where = ''; ($hook = vBulletinHook::fetch_hook($this->query_hook)) ? eval($hook) : false; // Internal hooks for loading content with QUERY_BASIC $content_query_fields = $content_query_joins = $content_query_where = ''; // if ($this->requireLoad(vBCms_Item_Content::INFO_CONTENT)) // { $content_query_fields = $this->getContentQueryFields(); $content_query_joins = $this->getContentQueryJoins(); $content_query_where = $this->getContentQueryWhere(); // } // Content item queries if (self::QUERY_BASIC == $required_query) { $calc_rows = $this->requireLoad(vBCms_Item_Content::INFO_BASIC) ? 'SQL_CALC_FOUND_ROWS' : ''; if (! isset(vB::$vbulletin->userinfo['permissions']['cms'])) { require_once DIR . '/packages/vbcms/permissions.php'; vBCMS_Permissions::getUserPerms(); } //We need a nodeid for the displayorder below if ($this->filter_node_exact AND !$this->filter_node ) { $this->filter_node = $this->filter_node_exact; } //enforce the max_records limits if ($this->max_records) { $this->paginate = true; if (!$this->start) { $this->start = 0; } $this->quantity = $this->max_records; } $filter_notcontenttype = $this->getFilterNotContentTypeSql(); $sql = "SELECT $calc_rows node.nodeid AS itemid" . ($this->requireLoad(vBCms_Item_Content::INFO_BASIC) ? " ,(node.nodeleft = 1) AS isroot, node.nodeid, node.contenttypeid, node.contentid, node.url, node.parentnode, node.styleid, node.userid, node.layoutid, node.publishdate, node.setpublish, node.issection, parent.permissionsfrom as parentpermissions, node.showrating, node.permissionsfrom, node.publicpreview, node.shownav, node.hidden, node.nosearch " : '') . ($this->requireLoad(vBCms_Item_Content::INFO_NODE) ? ", info.description, info.title, info.viewcount, info.creationdate, info.workflowdate, info.workflowstatus, info.workflowcheckedout, info.workflowlevelid, info.associatedthreadid, user.username, sectionorder.displayorder" : '') . ($this->requireLoad(vBCms_Item_Content::INFO_DEPTH) ? ", (COUNT(pdepth.nodeid) - 1) AS depth" : '') . " $content_query_fields $hook_query_fields FROM " . TABLE_PREFIX . "cms_node AS node " . ($this->requireLoad(vBCms_Item_Content::INFO_NODE) ? " INNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info ON info.nodeid = node.nodeid LEFT JOIN " . TABLE_PREFIX . "user AS user ON user.userid = node.userid LEFT JOIN " . TABLE_PREFIX . "cms_sectionorder AS sectionorder ON sectionorder.sectionid = node.parentnode AND sectionorder.nodeid = node.nodeid" : '') . ($this->requireLoad(self::INFO_BASIC) ? " LEFT JOIN " . TABLE_PREFIX . "cms_node AS parent ON parent.nodeid = node.parentnode " : '') . ($this->filter_node ? "INNER JOIN " . TABLE_PREFIX . "cms_node AS rootnode ON rootnode.nodeid = " . intval($this->filter_node) : '') . ($this->requireLoad(vBCms_Item_Content::INFO_DEPTH) ? " LEFT JOIN " . TABLE_PREFIX . "cms_node AS pdepth ON (node.nodeleft >= pdepth.nodeleft AND node.nodeleft <=pdepth.noderight>" : '') . " $content_query_joins $hook_query_joins WHERE node.new != 1 " . ($this->itemid ? " AND node.nodeid IN (" . implode(',', $this->itemid) . ") " : '') . ($this->filter_ignorepermissions ? '' : " AND " . vBCMS_Permissions::getPermissionString()) . ((($this->filter_contenttype AND ($this->filter_contenttype == vB_Types::instance()->getContentTypeID("vBCms_Section"))) OR $this->filter_onlysections) ? '' : "AND node.new != 1 ") . ($this->filter_contenttype ? "AND node.contenttypeid = " . intval($this->filter_contenttype) . " " : '') . ($this->filter_contentid ? "AND node.contentid = " . intval($this->contentid) . " ": '') . ($this->filter_node ? "AND (node.nodeleft >= rootnode.nodeleft AND node.nodeleft <= rootnode.noderight) AND node.nodeleft != rootnode.nodeleft " : '') . ($this->filter_nosections ? "AND node.issection != '1' " : '') . ($this->filter_onlysections ? "AND node.issection = '1' " : '') . ($this->filter_userid ? "AND node.userid = " . intval($this->filter_userid) . " " : '') . ($this->visible_only ? "AND node.hidden = 0 " : '') . (intval($this->filter_node_exact) ? "AND (node.parentnode = " . $this->filter_node_exact . " OR sectionorder.displayorder > 0 )": ''). ($this->filter_published ? "AND node.setpublish = '1' AND node.publishdate <= " . intval(TIMENOW) . " " : '') . ($this->filter_unpublished ? "AND node.setpublish = '0' OR node.publishdate > " . intval(TIMENOW) . " " : '') . " $content_query_where $hook_query_where " . ($this->requireLoad(vBCms_Item_Content::INFO_DEPTH) ? " GROUP BY node.nodeid " : '') . (isset($this->orderby) ? " ORDER BY " . $this->orderby : ($this->requireLoad(vBCms_Item_Content::INFO_NODE) ? " ORDER BY CASE WHEN sectionorder.displayorder > 0 THEN sectionorder.displayorder ELSE 9999999 END ASC, node.publishdate DESC" : 'ORDER BY node.setpublish DESC, node.publishdate DESC' )) . ($this->paginate ? " LIMIT " . intval($this->start) . ', ' . intval($this->quantity) : ''); return $sql; } else if (self::QUERY_PARENTS == $required_query) { return "SELECT node.nodeid AS itemid, parent.nodeid, parent.url, parent.styleid, parent.layoutid, parent.publishdate, parent.setpublish, parent.hidden, info.title, info.description $hook_query_fields FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "cms_node AS parent ON (node.nodeleft >= parent.nodeleft AND node.nodeleft <= parent.noderight) INNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info ON info.nodeid = parent.nodeid LEFT JOIN " . TABLE_PREFIX . "cms_sectionorder AS ord ON ord.nodeid = node.nodeid AND ord.sectionid = node.parentnode " . $hook_query_joins . " WHERE node.nodeid IN (" . implode(',', $this->itemid) . ") AND parent.nodeid != node.nodeid $hook_query_where ORDER BY parent.nodeleft, ord.displayorder" ; } else if (self::QUERY_CONFIG == $required_query) { return "SELECT nodeid AS itemid, name, value, serialized $hook_query_fields FROM " . TABLE_PREFIX . "cms_nodeconfig $hook_query_joins WHERE nodeid IN (" . implode(',', $this->itemdid) . ") $hook_query_where "; } throw (new vB_Exception_Model('Invalid query id \'' . htmlspecialchars_uni($required_query) . '\' specified for collection')); }
/** * This does the actual work of creating the navigation elements. This needs some * styling, but we'll do that later. * We use the existing search functionality. It's already all there, we just need * to * * @return string; */ private function makeResults($config) { //Start by generating the sql and executing it. $sql = "SELECT post.postid, thread.threadid, node.nodeid, info.title, user.username as cms_author, node.userid AS cms_authorid, thread.replycount, node.url, post.userid from " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info ON node.nodeid = info.nodeid INNER JOIN " . TABLE_PREFIX . "user AS user ON user.userid = node.userid INNER JOIN " . TABLE_PREFIX . "thread AS thread ON thread.threadid = info.associatedthreadid INNER JOIN " . TABLE_PREFIX . "post AS post ON post.threadid = thread.threadid WHERE node.comments_enabled > 0 AND node.setpublish > 0 AND post.postid <> thread.firstpostid AND post.dateline > ". (TIMENOW - intval($config['days']) * 86400) . " AND " . vBCMS_Permissions::getPermissionString() . " AND thread.visible = 1 AND post.visible = 1 ORDER BY post.dateline DESC LIMIT 50"; $rst = vB::$vbulletin->db->query_read($sql); $blocked_threads = array(); $results = array(); while($record = vB::$vbulletin->db->fetch_array($rst) AND count($results) < $config['count']) { $results[]= $record; } return $results; }
/** * Fetches the standard page view for a widget. * * @param bool $skip_errors - If using a collection, omit widgets that throw errors * @return vBCms_View_Widget - The resolved view, or array of views */ public function getPageView() { $this->assertWidget(); $config = $this->widget->getConfig(); if (!isset($config['template_name']) OR ($config['template_name'] == '') ) { $config['template_name'] = 'vbcms_widget_categorynavcurrent_page'; } // Create view $view = new vBCms_View_Widget($config['template_name']); $this->sectionid = $this->content->getContentTypeId() == vb_Types::instance()->getContentTypeID("vBCms_Section") ? $this->content->getNodeId() : $this->content->getParentId(); try { $categoryid = max(1, intval(vB_Router::getSegment('value'))); } catch (vB_Exception_Router $e) { $categoryid = 0; } if (!$nodes = vB_Cache::instance()->read($cache_key = $this->getHash($this->widget->getId(), $this->sectionid), true, true )) { //First we'll generate the category list //compose the sql $rst = vB::$vbulletin->db->query_read($sql = "SELECT parent.category AS parentcat, cat.categoryid, cat.category, cat.catleft, cat.catright, info.title AS node, node.nodeid, count(nodecat.nodeid) as qty FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info ON info.nodeid = node.nodeid INNER JOIN " . TABLE_PREFIX . "cms_category AS parent on parent.parentnode = node.nodeid INNER JOIN " . TABLE_PREFIX . "cms_category AS cat ON (cat.catleft >= parent.catleft AND cat.catleft <= parent.catright) LEFT JOIN " . TABLE_PREFIX . "cms_nodecategory AS nodecat ON nodecat.categoryid = cat.categoryid WHERE node.nodeid = " . $this->sectionid . " AND " . vBCMS_Permissions::getPermissionString() . " GROUP BY parent.category, cat.categoryid, cat.category, cat.catleft, cat.catright, info.title ORDER BY catleft;"); $parents = array(); $level = 0; $nodes = array(); if ($record = vB::$vbulletin->db->fetch_array($rst)) { $record['level'] = $level; $record['route_info'] = $record['categoryid'] . ($record['category'] != '' ? '-' . str_replace(' ', '-', $record['category']) : ''); $nodes[strtolower($record['category'])] = $parents[0] = $record; $last_category = -1; while($record = vB::$vbulletin->db->fetch_array($rst)) { $record['route_info'] = $record['categoryid'] . ($record['category'] != '' ? '-' . str_replace(' ', '-', $record['category']) : ''); if ($record['categoryid'] == $last_category ) { continue; } //note that since we're already sorted by by catleft we don't need to check that. while((intval($record['catright']) > intval($parents['level']['catright'])) AND $level > 0) { $level--; } $level++; $record['level'] = $level; $nodes[strtolower($record['category'])] = $parents[$level] = $record; $last_category = $record['categoryid']; } } ksort($nodes); $key = array_keys($nodes); $size = sizeOf($key); for ($i = 0; $i < $size; $i++) { if ($categoryid == $nodes[$key[$i]]['categoryid']) { $nodes[$key[$i]]['myself'] = true; } else { $nodes[$key[$i]]['myself'] = false; } } vB_Cache::instance()->write($cache_key, $nodes, $this->cache_ttl, 'categories_updated'); } foreach ($nodes as $nodeid => $record) { $route = vB_Route::create('vBCms_Route_List', "category/" . $record['route_info'] . "/1")->getCurrentURL(); $nodes[$nodeid]['view_url'] = $route; } // Modify $nodes to add myself var (currently selected category) $view->widget_title = $this->widget->getTitle(); $view->nodes = $nodes; return $view; }
private function getPublished($year, $month) { //Getting the start date is easy. Getting the end date is a bit complex. Leap years and all that. //Easiest way is to get the start of the next month and subract a second. //Ensure permissions are loaded $hash = self::getMyHash($year, $month); if (!($articles = vB_Cache::instance()->read($hash, true, false))) { $offset = vBCms_ContentManager::getTimeOffset(vB::$vbulletin->userinfo); $start = gmmktime (0, 0, 0, $month, 1, $year); $weekday = gmdate('w', $start); $start -= $offset; $end = gmmktime (0, 0, 0, ($month == 12 ? 1 : $month + 1 ), 1, ($month == 12 ? $year + 1 : $year )) - $offset - 1; $articles = array(); $rst = vB::$vbulletin->db->query_read($sql = "SELECT node.nodeid, node.publishdate, node.setpublish FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info ON info.nodeid = node.nodeid WHERE node.setpublish > 0 AND node.publishdate BETWEEN $start AND $end AND node.contenttypeid <> " . vB_Types::instance()->getContentTypeID("vBCms_Section") . " AND " . vBCMS_Permissions::getPermissionString() . " AND hidden = 0 ORDER BY node.publishdate LIMIT 5000" ); $nextday = $start + 86400; $dom = 1; $articles[1] = array('data' => array(), 'time' => $start + 1, 'wday' => $weekday); //Now we want to end with an array of day => array('data ' => array, 'time' => unixtime) //So we need to build the array as we go. while($record = vB::$vbulletin->db->fetch_array($rst)) { //see if we need to advance to a new date if (intval($record['publishdate']) > $nextday) { while (intval($record['publishdate']) > $nextday) { $nextday += 86400; $start += 86400; $dom ++; $weekday = ($weekday == 6 ? 0 : ($weekday + 1)); $articles[$dom] = array('data' => array(), 'time' => $start + 1, 'wday' => $weekday); } } if ($record['setpublish']) { $articles[$dom]['data'][] = $record; } } //we may have some days at the end without articles. while($end > $start + 86400 ) { $dom++; $weekday = ($weekday == 6 ? 0 : ($weekday + 1)); $articles[$dom] = array('data' => array(), 'time' => $start + 1, 'wday' => $weekday); $start += 86400; } vB_Cache::instance()->write($hash , $articles, 1440, array('cms_calendar_published', 'sections_updated')); } //Now we want to turn this into an array of week=>(array(1-7); $week = 1; $calendar = array(1 => array()); //Pad the start with empty records as needed if ($articles[1]['wday'] != 0) { for ($i = 0; $i < $articles[1]['wday']; $i++) { $calendar[1][$i] = array('count' => 0, 'url' => '', 'day' => ''); } } $monthday = 1; $route = new vBCms_Route_List; while($monthday <= count($articles)) { //If we've filled a week, we need to advance $count = 0; foreach ($articles[$monthday]['data'] as $record) { $count = 1; $url = $route->getCurrentUrl(array('type' =>'day', 'value' => $articles[$monthday]['time'])) ; break; } $calendar[$week][$articles[$monthday]['wday']] = array('count' => $count, 'url' => $url, 'day' =>($monthday ? $monthday : '') ); if (($articles[$monthday]['wday'] == 6) AND ($monthday < count($articles))) { $week++; $calendar[$week] = array(); } $monthday++; } //We need to fill out a full week. Note that monthday is now one past the last day of the month if ($articles[$monthday - 1]['wday'] < 6) { for ($i = $articles[$monthday - 1]['wday'] + 1; $i <= 6 ; $i++) $calendar[$week][$i] = array('count' => 0, 'url' => '', 'day' => ''); } unset($route); return $calendar; }
public function getCount() { $hook_query_fields = $hook_query_joins = $hook_query_where = ''; ($hook = vBulletinHook::fetch_hook($this->query_hook)) ? eval($hook) : false; // Internal hooks for loading content with QUERY_BASIC // if ($this->requireLoad(vBCms_Item_Content::INFO_CONTENT)) // { $content_query_fields = $this->getContentQueryFields(); $content_query_joins = $this->getContentQueryJoins(); $content_query_where = $this->getContentQueryWhere(); // } $filter_notcontenttype = $this->getFilterNotContentTypeSql(); //make sure permissions are loaded. if (! isset(vB::$vbulletin->userinfo['permissions']['cms'])) { vBCMS_Permissions::getUserPerms(); } if (!count(vB::$vbulletin->userinfo['permissions']['cms']['allview'])) { return false; } $sql = "SELECT count(node.nodeid) AS qty FROM " . TABLE_PREFIX . "cms_node AS node" . ($this->filter_node ? " INNER JOIN " . TABLE_PREFIX . "cms_node AS rootnode ON rootnode.nodeid = " . intval($this->filter_node) : '') . " $content_query_joins $hook_query_joins LEFT JOIN " . TABLE_PREFIX . "cms_sectionorder AS sectionorder ON sectionorder.sectionid = " . intval($this->filter_node) ." AND sectionorder.nodeid = node.nodeid WHERE (1=1) ". ($this->filter_contenttype ? "AND node.contenttypeid = " . intval($this->filter_contenttype) . " " : '') . ($this->filter_contentid ? "AND node.contentid = " . intval($this->contentid) . " ": '') . ($this->filter_node ? "AND (node.nodeleft >= rootnode.nodeleft AND node.nodeleft <= rootnode.noderight) AND node.nodeleft != rootnode.nodeleft " : '') . ($this->filter_nosections ? "AND node.issection != '1' " : '') . ($this->filter_onlysections ? "AND node.issection = '1' " : '') . ($this->filter_userid ? "AND node.userid = " . intval($this->filter_userid) . " " : '') . ($this->filter_published ? "AND node.setpublish = '1' AND node.publishdate <= " . intval(TIMENOW) . " " : '') . ($this->filter_unpublished ? "AND node.setpublish = '0' OR node.publishdate > " . intval(TIMENOW) . " " : '') . " " . ((($this->filter_contenttype AND ($this->filter_contenttype == vB_Types::instance()->getContentTypeID("vBCms_Section"))) OR $this->filter_onlysections) ? '' : "AND node.new != 1 ") . (intval($this->filter_node_exact) ? "AND (node.parentnode = " . $this->filter_node_exact . " OR sectionorder.displayorder > 0 )": '') . (($this->orderby == 5) ? " AND sectionorder.displayorder > 0 " : '') . ($this->filter_ignorepermissions ? '' : " AND " . vBCMS_Permissions::getPermissionString()) . " $filter_notcontenttype $content_query_where $hook_query_where "; if ($record = vB::$vbulletin->db->query_first($sql)) { return intval($record['qty']); } }
public static function getAllCategories() { $context = new vB_Context('widget' , array('permissions' => vB::$vbulletin->userinfo->permissions['cms'])); $cache_key = strval($context); if (!$nodes = vB_Cache::instance()->read($cache_key, true, true)) { //First we'll generate the category list $permString = vBCMS_Permissions::getPermissionString(); //compose the sql $sql = "SELECT parent.category AS parentcat, cat.categoryid, cat.category, parent.categoryid AS parentid, cat.catleft, cat.catright, node.nodeid, info.title, count(nodecat.nodeid) as qty FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info on info.nodeid = node.nodeid INNER JOIN " . TABLE_PREFIX . "cms_category AS parent on parent.parentnode = node.nodeid INNER JOIN " . TABLE_PREFIX . "cms_category AS cat ON (cat.catleft >= parent.catleft AND cat.catleft <= parent.catright) LEFT JOIN " . TABLE_PREFIX . "cms_nodecategory AS nodecat ON nodecat.categoryid = cat.categoryid WHERE node.setpublish > 0 AND node.publishdate <= " . TIMENOW . " AND " . $permString . " GROUP BY parent.category, cat.categoryid, cat.category, cat.catleft, cat.catright, info.title ORDER BY node.nodeleft, cat.catleft;"; $rst = vB::$vbulletin->db->query_read($sql); $parents = array(); $level = 0; $nodes = array(); if ($record = vB::$vbulletin->db->fetch_array($rst)) { $record['level'] = $level; $record['route_info'] = $record['categoryid'] . ($record['category'] != '' ? '-' . str_replace(' ', '-', $record['category']) : ''); $nodes[strtolower($record['category'])] = $parents[0] = $record; $last_category = -1; while($record = vB::$vbulletin->db->fetch_array($rst)) { $record['route_info'] = $record['categoryid'] . ($record['category'] != '' ? '-' . str_replace(' ', '-', $record['category']) : ''); if ($record['categoryid'] == $last_category ) { continue; } //note that since we're already sorted by by catleft we don't need to check that. while((intval($record['catright']) >= intval($parents[$level]['catright'])) AND $level >= 0) { $level--; } $level++; $record['level'] = $level; $nodes[strtolower($record['category'])] = $parents[$level] = $record; $last_category = $record['categoryid']; } } $keys = array_keys($nodes); $size = sizeOf($key); for ($i = 0; $i < $size; $i++) { if ($categoryid == $nodes[$keys[$i]]['categoryid']) { $nodes[$keys[$i]]['myself'] = true; } else { $nodes[$keys[$i]]['myself'] = false; } } vB_Cache::instance()->write($cache_key, $nodes, 1440, 'categories_updated'); } return $nodes; }
/** This function gets the article information based on the defined criteria * * @return array */ protected function getContent() { // First, compose the sql $sql = "SELECT article.pagetext, article.previewimage, article.imagewidth, article.imageheight, article.previewvideo, article.htmlstate, node.url, node.publishdate, node.userid, node.setpublish, node.publicpreview, info.title, user.username, node.showuser, node.nodeid, node.contenttypeid, thread.replycount FROM " . TABLE_PREFIX . "cms_article AS article INNER JOIN " . TABLE_PREFIX . "cms_node AS node ON (node.contentid = article.contentid AND node.contenttypeid = " . vb_Types::instance()->getContentTypeID("vBCms_Article") . ") INNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info on info.nodeid = node.nodeid " . ( (($this->config['categories'] != '') AND ($this->config['categories'] != '0')) ? " INNER JOIN " . TABLE_PREFIX . "cms_nodecategory nc ON nc.nodeid = node.nodeid " : '') . " LEFT JOIN " . TABLE_PREFIX . "user AS user ON user.userid = node.userid LEFT JOIN " . TABLE_PREFIX . "thread AS thread ON thread.threadid = info.associatedthreadid WHERE " . vBCMS_Permissions::getPermissionString() ; if (($this->config['categories'] != '') AND ($this->config['categories'] != '0') ) { $sql .= "\n AND nc.categoryid IN (" . $this->config['categories'] . ")\n"; } if (($this->config['sections'] != '') AND ($this->config['sections'] != '0')) { $sql .= "\n AND node.parentnode IN (" . $this->config['sections'] . ")\n"; } if (isset($this->config['days']) AND (intval($this->config['days'])) ) { $sql .= "\n AND node.publishdate > " . (TIMENOW - (86400 * $this->config['days'])) . "\n"; } $sql .= "\n ORDER BY node.publishdate DESC LIMIT " . $this->config['count']; $articles = array(); //Execute if ($rst = vB::$db->query_read($sql)) { $current_record = array('contentid' => -1); $contenttypeid = vb_Types::instance()->getContentTypeId($this->package . '_' . $this->view_class); //now build the results array $bbcode_parser = new vBCms_BBCode_HTML(vB::$vbulletin, vBCms_BBCode_HTML::fetchCmsTags()); while($article = vB::$db->fetch_array($rst)) { $article['categories'] = array(); $article['tags'] = array(); $allow_html = vBCMS_Permissions::canUseHtml($article['nodeid'], $contenttypeid, $article['userid']); $pagetext = $bbcode_parser->get_preview(fetch_censored_text($article['pagetext']), vB::$vbulletin->options['default_cms_previewlength'], $allow_html); $article['previewtext'] = strip_bbcode($pagetext); //get the avatar if (vB::$vbulletin->options['avatarenabled']) { $article['avatar'] = fetch_avatar_url($article['userid']); } $articles[$article['nodeid']] = $article; } //Let's get the tags and the categories // we can do that with one query each. if (count($articles)) { //first let's get categories $nodeids = implode(', ', array_keys($articles)); $sql = "SELECT nc.nodeid, nc.categoryid, category.category FROM " . TABLE_PREFIX . "cms_nodecategory AS nc INNER JOIN " . TABLE_PREFIX . "cms_category AS category ON category.categoryid = nc.categoryid WHERE nc.nodeid IN ($nodeids)"; if ($rst = vB::$db->query_read($sql)) { while ($record = vB::$db->fetch_array($rst)) { $route_info = $record['categoryid'] . ($record['category'] != '' ? '-' . str_replace(' ', '-', $record['category']) : ''); $record['route_info'] = $route_info; $record['category_url'] = vB_Route::create('vBCms_Route_List', "category/" . $record['route_info'] . "/1")->getCurrentURL(); $articles[$record['nodeid']]['categories'][$record['categoryid']] = $record; } } //next tags; $sql = "SELECT tag.tagid, node.nodeid, tag.tagtext FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "tagcontent AS tc ON (tc.contentid = node.contentid AND tc.contenttypeid = node.contenttypeid) INNER JOIN " . TABLE_PREFIX . "tag AS tag ON tag.tagid = tc.tagid WHERE node.nodeid IN ($nodeids) "; if ($rst = vB::$db->query_read($sql)) { while ($record = vB::$db->fetch_array($rst)) { $articles[$record['nodeid']]['tags'][$record['tagid']] = $record['tagtext']; } } } } return $articles; }