/** * determine which records are viewable by this user. * * @param mixed $user : current user object * @param array $ids : array of article contentids * @param mixed $gids : not applicable here- group id's for those types which are groupable * @return array of (viewable id's, rejected groups) */ public function fetch_validated_list($user, $ids, $gids) { //We need to pull parentnode and permissionsfrom from the table. $sql = "SELECT node.contentid, node.nodeid, node.parentnode, node.permissionsfrom, node.setpublish, node.userid, node.publishdate, node.hidden, node.nosearch, node.userid FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "cms_article AS article ON article.contentid = node.contentid AND node.contenttypeid = " . vB_Types::instance()->getContentTypeID('vBCms_Article') . " WHERE article.contentid in (" . implode(', ', $ids) . ")"; $canview = array(); $hidden = array(); $rst = vB::$vbulletin->db->query_read($sql); if ($rst) { // make sure user cms permissions are stored in the registry if (! isset(vB::$vbulletin->userinfo['permissions']['cms'])) { vBCMS_Permissions::getUserPerms(); } while($record = vB::$vbulletin->db->fetch_array($rst)) { if (in_array($record['permissionsfrom'], vB::$vbulletin->userinfo['permissions']['cms']['canedit']) OR ($record['userid'] == vB::$vbulletin->userinfo['userid'])) { $canview[] = $record['contentid']; } else if (in_array($record['permissionsfrom'], vB::$vbulletin->userinfo['permissions']['cms']['canview']) AND ($record['setpublish'] > 0) AND ($record['publishdate'] <= TIMENOW)) { $canview[] = $record['contentid']; } else { $hidden[] = $record['parentnode']; } } //And let's store the permissionsfrom in case we need it. vBCMS_Permissions::setPermissionsfrom($record['nodeid'], $record['permissionsfrom'], $record['hidden'], $record['setpublish'], $record['publishdate'], $record['userid']); } if (count($canview)) { $articles = vBCms_Search_Result_Article::create_array($canview); } else { $articles = array(); } return array('list' => $articles, 'groups_rejected' => $hidden); }
/** * this will create an array of result objects from an array of ids() * * @param array of integer $ids * @return array of objects */ public function create_array($ids) { $contenttypeid = vB_Types::instance()->getContentTypeID( 'vBCms_StaticHtml'); if (! isset(vB::$vbulletin->userinfo['permissions']['cms'])) { vBCMS_Permissions::getUserPerms(); } if ($rst = vB::$vbulletin->db->query_read("SELECT n.nodeid as itemid, n.setpublish, u.username,n.nodeid, u.userid, i.html_title, n.permissionsfrom, n.hidden, n.url, nc1.value AS previewtext, nc.value AS pagetext, i.title, i.description, n.publishdate, n.parentnode, parent.title AS parenttitle, parent.html_title AS parent_html_title FROM " . TABLE_PREFIX . "cms_node AS n LEFT JOIN " . TABLE_PREFIX . "cms_nodeinfo i ON i.nodeid = n.nodeid LEFT JOIN " . TABLE_PREFIX . "cms_nodeinfo AS parent ON parent.nodeid = n.parentnode LEFT JOIN " . TABLE_PREFIX . "user u ON u.userid = n.userid LEFT JOIN " . TABLE_PREFIX . "cms_nodeconfig AS nc ON nc.nodeid = n.nodeid AND nc.name = 'pagetext' LEFT JOIN " . TABLE_PREFIX . "cms_nodeconfig AS nc1 ON nc1.nodeid = n.nodeid AND nc1.name = 'previewtext' WHERE n.nodeid IN (" . implode(', ', $ids) . ")")) { while ($search_result = vB::$vbulletin->db->fetch_array($rst)) { vBCMS_Permissions::setPermissionsfrom($search_result['nodeid'], $search_result['$permissionsfrom'], $search_result['hidden'], $search_result['setpublish'], $search_result['publishdate'] ); //check permissions if (!vBCMS_Permissions::canView($search_result['nodeid'])) { continue; } $item = new vBCms_Search_Result_StaticPage(); $item->itemid = $search_result['itemid']; $item->contenttypeid = $contenttypeid; if ($rst1 = vB::$vbulletin->db->query_read("SELECT cat.categoryid, cat.category FROM " . TABLE_PREFIX . "cms_nodecategory nc INNER JOIN " . TABLE_PREFIX . "cms_category cat ON nc.categoryid = cat.categoryid WHERE nc.nodeid = " . $search_result['nodeid'])) { while($record = vB::$vbulletin->db->fetch_array($rst1)) { $record['category_url'] = vB_Route::create('vBCms_Route_List', "category/" . $record['route_info'] . "/1")->getCurrentURL(); $categories[$record['categoryid']] = $record; } } // if ($rst1 = vB::$vbulletin->db->query_read("SELECT cat.categoryid, cat.category FROM " . // TABLE_PREFIX . "cms_nodecategory nc INNER JOIN " . TABLE_PREFIX . // "cms_category cat ON nc.categoryid = cat.categoryid WHERE nc.nodeid = " . // $search_result['nodeid'])) // { // while($record = vB::$vbulletin->db->fetch_array($rst1)) // { // $categories[$record['categoryid']] = $record; // } // } $search_result['categories'] = $categories; $item->record = $search_result; $items[$search_result['itemid']] = $item; } return $items; } return false; }
/** * Loads the model info from the cache. * Note: The cache is written after setInfo() so direct assignment of the * properties is needed. * * @return bool - Success */ protected function loadCache($nodeid = false) { // Check if we're cachable if (!$this->cachable) { return false; } // Create a context to identify the cache entry if (!$key = $this->getCacheKey($nodeid)) { return false; } //Check to see if we've already loaded everything we need if ($this->loaded_info AND (($this->loaded_info & $this->required_info) == $this->required_info)) { return true; } //Check to see if we've already read from cache if ($this->cached_data) { return false; } // Fetch the cache info if ($info = vB_Cache::instance()->read($key, true, true)) { //Now see if we have the right content type if (($this->class != 'Content') AND ($info->class == 'Content')) { //invalidate the cache. That means we'll update with the correct //values later $this->loaded_data = false; $this->cached_data = false; return false; } //Now see if the cache has data we don't already have. if ($this->loaded_info AND (($info->loaded_info | $this->loaded_info) == $this->loaded_info)) { $this->cached_data |= $info->loaded_info; return false; } // load the info retrieved from the cache $this->is_valid = $info->is_valid; if ($this->nodeid AND $info->permissionsfrom AND $info->userid) { vBCMS_Permissions::setPermissionsfrom($this->nodeid, $info->permissionsfrom, $info->hidden, $info->setpublish, $info->publishdate, $info->userid); } if (is_array($info->item_properties) AND is_array($this->item_properties)) { foreach(array_merge($this->item_properties, $info->item_properties) as $field) { if (isset($info->$field)) { $this->$field = $info->$field; } } $this->cached_data |= $info->loaded_info; $this->loaded_info |= $info->loaded_info; } if (isset($info->config)) { $this->config = $info->config; } return (($this->loaded_info & $this->required_info) == $this->required_info); } $this->cached_data = false; return false; }