function testPageList() { // Completely empty PageList $columns = ""; $exclude = ""; $options = ""; $pl = new PageList($columns, $exclude, $options); $this->assertTrue($pl->isEmpty(), "empty"); $this->assertEquals(0, $pl->getTotal(), "count 0"); $cap = $pl->getCaption(); $this->assertTrue(empty($cap), "empty caption"); // PageList sorting $columns[] = 'pagename'; $pl = new PageList($columns, $exclude, $options); //global $request; $pl->addPage("foo"); $pl->addPage("blarg"); $this->assertEquals(2, $pl->getTotal(), "count 2"); //print_r($pl->getContent()); }
function getSubNodes($cID, $level = 0, $keywords = '', $autoOpenNodes = true) { $db = Loader::db(); $obj = new stdClass(); if (isset($cID) && (Loader::helper('validation/numbers')->integer($cID) || $cID == 0)) { if ($keywords != '' && $keywords != false) { $nc = Page::getByID($cID, 'RECENT'); $pl = new PageList(); if (PERMISSIONS_MODEL != 'simple') { $pl->setViewPagePermissionKeyHandle('view_page_in_sitemap'); } $obj->keywords = $keywords; $pl->filterByName($keywords); $pl->ignoreAliases(); $pl->filterByPath($nc->getCollectionPath()); $pl->displayUnapprovedPages(); $pl->sortByDisplayOrder(); $results = $pl->get(SITEMAP_PAGES_LIMIT); $total = $pl->getTotal(); } else { $pl = new PageList(); if (PERMISSIONS_MODEL != 'simple') { $pl->setViewPagePermissionKeyHandle('view_page_in_sitemap'); } $pl->sortByDisplayOrder(); if (ConcreteDashboardSitemapHelper::showSystemPages()) { $pl->includeSystemPages(); $pl->includeInactivePages(); } $pl->filterByParentID($cID); $pl->displayUnapprovedPages(); $total = $pl->getTotal(); if ($cID == 1) { $results = $pl->get(); } else { $pl->setItemsPerPage(SITEMAP_PAGES_LIMIT); $results = $pl->getPage(); } } $nodes = array(); foreach ($results as $c) { $n = ConcreteDashboardSitemapHelper::getNode($c, $level + 1, $autoOpenNodes); if ($n != false) { $nodes[] = $n; } } $obj->total = $total; $obj->nodeID = $cID; $obj->pageList = $pl; $obj->results = $nodes; } else { $obj->total = 0; $obj->nodeID = 0; $obj->pageList = null; $obj->results = null; } return $obj; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); if (empty($args['s'])) { return ''; } $query = new TextSearchQuery($args['s'], $args['case_exact'], $args['regex']); $pages = $dbi->titleSearch($query, $args['sortby'], $args['limit'], $args['exclude']); $pagelist = new PageList($args['info'], $args['exclude'], $args); while ($page = $pages->next()) { $pagelist->addPage($page); $last_name = $page->getName(); } if ($args['format'] == 'livesearch') { $request->discardOutput(); $request->buffer_output(false); echo '<div class="LSRes">'; echo $pagelist->asXml(); echo '</div>'; if (empty($WikiTheme->DUMP_MODE)) { unset($GLOBALS['ErrorManager']->_postponed_errors); $request->finish(); } } // Provide an unknown WikiWord link to allow for page creation // when a search returns no results if (!$args['noheader']) { $s = $args['s']; if (!$pagelist->getTotal() and !$query->_regex) { $s = WikiLink($args['s'], 'auto'); } $pagelist->setCaption(fmt("Title search results for '%s'", $s)); } if ($args['auto_redirect'] && $pagelist->getTotal() == 1) { return HTML($request->redirect(WikiURL($last_name, false, 'absurl'), false), $pagelist); } return $pagelist; }
function getSubNodes($cID, $level = 0, $keywords = '', $autoOpenNodes = true) { $db = Loader::db(); $obj = new stdClass; if ($keywords != '' && $keywords != false) { $nc = Page::getByID($cID, 'RECENT'); $pl = new PageList(); $obj->keywords = $keywords; $pl->filterByName($keywords); $pl->filterByPath($nc->getCollectionPath()); $pl->displayUnapprovedPages(); $pl->sortByDisplayOrder(); $results = $pl->get(SITEMAP_PAGES_LIMIT); $total = $pl->getTotal(); } else { $pl = new PageList(); $pl->sortByDisplayOrder(); if (ConcreteDashboardSitemapHelper::showSystemPages()) { $pl->includeSystemPages(); } $pl->filterByParentID($cID); $pl->displayUnapprovedPages(); $total = $pl->getTotal(); if ($cID == 1) { $results = $pl->get(); } else { $pl->setItemsPerPage(SITEMAP_PAGES_LIMIT); $results = $pl->getPage(); } } $nodes = array(); foreach($results as $c) { $n = ConcreteDashboardSitemapHelper::getNode($c, $level+1, $autoOpenNodes); if ($n != false) { $nodes[] = $n; } } $obj->total = $total; $obj->nodeID = $cID; $obj->pageList = $pl; $obj->results = $nodes; return $obj; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); if (!empty($args['exclude_from'])) { $args['exclude_from'] = is_string($args['exclude_from']) ? explodePageList($args['exclude_from']) : $args['exclude_from']; } // <! plugin-list !> extract($args); if ($page == _("WantedPages")) { $page = ""; } // There's probably a more memory-efficient way to do this (eg // a tailored SQL query via the backend, but this gets the job // done. // TODO: Move this to backend/dumb/WantedPagesIter.php if (!$page) { $GLOBALS['WikiTheme']->addPageListColumn(array('wanted' => array('_PageList_Column_WantedPages_wanted', 'custom:wanted', _("Wanted From"), 'left'))); } $pagelist = new PageList($page ? '' : 'pagename,wanted', $exclude, $args); // search button? $pagelist->_wpagelist = array(); if (!$page) { list($offset, $maxcount) = $pagelist->limit($limit); $wanted_iter = $dbi->wantedPages($exclude_from, $exclude, $sortby, $limit); while ($row = $wanted_iter->next()) { $wanted = $row['pagename']; $wantedfrom = $row['wantedfrom']; // ignore duplicates: if (empty($pagelist->_wpagelist[$wanted])) { $pagelist->addPage($wanted); } $pagelist->_wpagelist[$wanted][] = $wantedfrom; } $wanted_iter->free(); // update limit, but it's still a hack. $pagelist->_options['limit'] = "{$offset}," . min($pagelist->getTotal(), $maxcount); } elseif ($dbi->isWikiPage($page)) { //only get WantedPages links for one page $page_handle = $dbi->getPage($page); $links = $page_handle->getPageLinks(true); // include_empty while ($link_handle = $links->next()) { if (!$dbi->isWikiPage($linkname = $link_handle->getName())) { $pagelist->addPage($linkname); //if (!array_key_exists($linkname, $this->_wpagelist)) $pagelist->_wpagelist[$linkname][] = 1; } } } /* if ($sortby) { ksort($this->_wpagelist); arsort($this->_wpagelist); }*/ if (!$noheader) { if ($page) { $pagelist->setCaption(sprintf(_("Wanted Pages for %s:"), $page)); } else { $pagelist->setCaption(sprintf(_("Wanted Pages in this wiki:"))); } } // reference obviously doesn't work, so force an update to add _wpagelist to parentobj if (isset($pagelist->_columns[1]) and $pagelist->_columns[1]->_field == 'wanted') { $pagelist->_columns[1]->parentobj =& $pagelist; } return $pagelist; }
/** * Call model data needed by view * * @param int $userID The user ID of who we're viewing * @return null */ public function view($userID = 0) { // Load helpers Loader::model('page_list'); $nh = Loader::helper('navigation'); $ah = Loader::helper('concrete/avatar'); $th = Loader::helper('text'); $ih = Loader::helper('image'); // Set helpers for view // Set the page view first $this->set('bodyData', ['pageViewName' => 'ProfilePageView']); parent::view($userID); // Load the current user $u = new User(); $ui = UserInfo::getByID($u->getUserID()); $profile = $this->get('profile'); // Basic flags identifying the type of user // Whether or not the logged in user is viewing their own "profile" $userIsViewingSelf = $u->getUserID() === $profile->getUserID(); // User is a CO $userIsCityOrganizer = in_array('City Organizers', $profile->getUserObject()->getUserGroups()); /** * New dashboard variables * */ // Remaining variables/logic only needed for "self viewing" if ($userIsViewingSelf) { /** * Helper * */ $html = Loader::helper('html'); $this->addHeaderItem($html->javascript('swfobject.js')); /** * User data * */ // Whether the logged in user has set their first and last name $this->set('userHasSetName', (bool) trim($ui->getAttribute('first_name') . ' ' . $ui->getAttribute('last_name'))); // The home city for the logged in user (false otherwise) $userHomeCity = $ui->getAttribute('home_city'); $this->set('userHomeCity', $userHomeCity); // Whether the logged in user has chosen an avatar/display picture $this->set('userPicture', $ah->getImagePath($ui)); // Walks owned by user $pl = new PageList(); $pl->filterByCollectionTypeHandle('walk'); $pl->filterByUserID($u->getUserID()); // Include the names of draft walks, not last published $pl->displayUnapprovedPages(); $this->set('userWalks', $pl->get()); // Whether the logged in user has created any blog posts $pl = new PageList(); $pl->filterByCollectionTypeHandle(['walk_blog_entry', 'city_blog_entry']); $pl->filterByUserID($u->getUserID()); $this->set('userBlogPosts', $pl->get()); /** * User city data * */ if ($userHomeCity) { // Set the city $city = $ui->getAttribute('home_city'); // Load organizer user for this city $cityOrganizer = UserInfo::getByID($userHomeCity->getCollectionUserID()); if ($cityOrganizer) { // The email address of the city organizer for the logged in user's // home city $cityOrganizerEmailAddress = $cityOrganizer->getUserEmail(); $this->set('cityOrganizerEmailAddress', $cityOrganizerEmailAddress); } // Whether the city has a blog page set up for it $pl = new PageList(); $pl->filterByCollectionTypeHandle('blog'); $pl->filterByParentID($userHomeCity->getCollectionID()); $cityHasBlogSetup = (bool) $pl->getTotal(); $this->set('cityHasBlogSetup', $cityHasBlogSetup); // List of basic data for three walks we want to highlight to city // organizers/walk leaders that showcase creative/unique walks $pl = new PageList(); $pl->filterByCollectionTypeHandle('walk'); $pl->filter(false, 'p1.uID !=' . $u->getUserID()); $pl->filterByAttribute('exclude_page_list', false); $pl->sortBy('RAND()'); // Load this list of featured walks $featuredWalkData = array_map(function ($page) use($nh, $ih) { $_city = Page::getByID($page->getCollectionParentID()); $_country = Page::getByID($_city->getCollectionParentID()); $_thumb = $page->getAttribute('thumbnail'); $countryName = $_country->getCollectionName(); if ($countryName === 'United States') { $countryName = 'United States of America'; } $countryName = str_replace(' ', '_', $countryName); $walkImage = $_thumb ? $ih->getThumbnail($_thumb, 800, 800)->src : ''; return ['walkImagePath' => $walkImage, 'countryName' => $countryName, 'cityName' => $_city->getCollectionName(), 'walkTitle' => $page->getCollectionName(), 'walkPath' => $nh->getLinkToCollection($page)]; }, (array) $pl->get(3)); // Whether the city has any walks posted to it // Whether the city has a blog page set up for it $pl = new PageList(); $pl->filterByCollectionTypeHandle('walk'); $pl->filterByParentID($userHomeCity->getCollectionID()); $pl->filterByAttribute('exclude_page_list', false); $cityWalks = $pl->get(); // Export to view $this->set('cityWalks', $cityWalks); $this->set('cityHasWalks', !empty($cityWalks)); $this->set('city', $city); $this->set('featuredWalkData', $featuredWalkData); // If the user is a city organizer if ($userIsCityOrganizer === true) { // Whether the city organizer's city has its header info set $cityHeaderInfo = $userHomeCity->getCollectionDescription(); $cityHeaderInfoIsEmpty = !trim($cityHeaderInfo); if ($cityHeaderInfoIsEmpty === false) { $cityHeaderInfo = $th->shorten($cityHeaderInfo, 150); } $this->set('cityHeaderInfoIsEmpty', $cityHeaderInfoIsEmpty); $this->set('cityHeaderInfo', $cityHeaderInfo); // Whether the city organizer's city has its short description // set $cityDescription = $userHomeCity->getAttribute('longdescription'); $cityDescriptionIsEmpty = !trim($cityDescription); if ($cityDescriptionIsEmpty === false) { $cityDescription = $th->shorten($cityDescription, 150); } $this->set('cityDescriptionIsEmpty', $cityDescriptionIsEmpty); $this->set('cityDescription', $cityDescription); // Whether the city organizer's city has its background photo // set $cityBackgroundPhotoAttribute = $userHomeCity->getAttribute('full_bg'); $cityBackgroundPhotoIsEmpty = !$cityBackgroundPhotoAttribute; $this->set('cityBackgroundPhotoIsEmpty', $cityBackgroundPhotoIsEmpty); if (!$cityBackgroundPhotoIsEmpty) { $this->set('cityBackgroundPhoto', $cityBackgroundPhotoAttribute->getURL()); } // Whether the header, description and photo are set for the // city organizer's home city $cityHasFullDetails = !($cityHeaderInfoIsEmpty || $cityDescriptionIsEmpty || $cityBackgroundPhotoIsEmpty); $this->set('cityHasFullDetails', $cityHasFullDetails); // Load the cities this CO organizes $pl = new PageList(); $pl->filterByCollectionTypeHandle('city'); $pl->ignoreAliases(); $pl->filterByUserID($u->getUserID()); $cityUsers = []; foreach ($pl->get() as $city) { // Load the user list for this city $ul = new UserList(); $ul->filterByHomeCity($city->getCollectionID()); foreach ($ul->get(65535) as $user) { $cityUsers[] = ['id' => $user->getUserID(), 'firstName' => $user->getAttribute('first_name'), 'lastName' => $user->getAttribute('last_name')]; } } // Sort the users -- needed here for multi-city COs usort($cityUsers, function ($a, $b) { return strcmp(strtoupper($a['first-name']), strtoupper($b['first-name'])); }); $this->set('cityUsers', $cityUsers); // Link to city-editor $this->set('cityComposerURL', View::url('/dashboard/composer/write/-/edit/' . $city->getCollectionID())); } } // Resources $resources = ['showCityOrganizers' => false, 'showGlobalWalks' => true, 'showTips' => true, 'showFiles' => false]; if ($userIsCityOrganizer === true) { $resources['showCityOrganizers'] = true; $resources['showFiles'] = true; // List of basic details for three city organizers that can be // recommended to other city organizers // TODO add an attribute to select 'featured' cities, so we // don't simply grab all cities. Expand this out into a // smart way to recommend other cities. $pl = new PageList(); $pl->filterByCollectionTypeHandle('city'); $pl->filter(false, 'p1.uID !=' . $u->getUserID()); $pl->filterByAttribute('exclude_page_list', false); $pl->sortBy('RAND()'); $recommendedCities = $pl->get(3); $cityOrganizerData = array_map(function ($page) use($ah) { $_co = UserInfo::getByID($page->getCollectionUserID()); return ['cityName' => $page->getCollectionName(), 'organizerImagePath' => $ah->getImagePath($_co), 'organizerName' => trim($_co->getAttribute('first_name') . ' ' . $_co->getAttribute('last_name')), 'organizerEmail' => $_co->getUserEmail()]; }, $pl->get(3)); $this->set('cityOrganizerData', $cityOrganizerData); } $this->set('resources', $resources); } $this->set('nh', $nh); $this->set('u', $u); $this->set('newWalkForm', Page::getByPath('/walk/form')); $this->set('userIsCityOrganizer', $userIsCityOrganizer); $this->set('userIsViewingSelf', $userIsViewingSelf); // Validation helper for form tokens $this->set('valt', Loader::helper('validation/token')); }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); if (empty($page) and $page != '0') { return ''; } // exclude is now already expanded in WikiPlugin::getArgs() if (empty($exclude)) { $exclude = array(); } if (!$include_self) { $exclude[] = $page; } if ($info) { $info = explode(",", $info); if (in_array('count', $info)) { $args['types']['count'] = new _PageList_Column_BackLinks_count('count', _("#"), 'center'); } } if (!empty($limit)) { $args['limit'] = $limit; } $args['dosort'] = !empty($args['sortby']); // override DB sort (??) $pagelist = new PageList($info, $exclude, $args); // support logical AND: page1,page2 $pages = explodePageList($page); $count = count($pages); if (count($pages) > 1) { // AND: the intersection of all these pages $bl = array(); foreach ($pages as $p) { $dp = $dbi->getPage($p); $bi = $dp->getBackLinks(false, $sortby, 0, $exclude); while ($b = $bi->next()) { $name = $b->getName(); if (isset($bl[$name])) { $bl[$name]++; } else { $bl[$name] = 1; } } } foreach ($bl as $b => $v) { if ($v == $count) { $pagelist->addPage($b); } } } else { $p = $dbi->getPage($page); $pagelist->addPages($p->getBackLinks(false, $sortby, 0, $exclude)); } $total = $pagelist->getTotal(); // Localization note: In English, the differences between the // various phrases spit out here may seem subtle or negligible // enough to tempt you to combine/normalize some of these // strings together, but the grammar employed most by other // languages does not always end up with so subtle a // distinction as it does with English in this case. :) if (!$noheader) { if ($page == $request->getArg('pagename') and !$dbi->isWikiPage($page)) { // BackLinks plugin is more than likely being called // upon for an empty page on said page, while either // 'browse'ing, 'create'ing or 'edit'ing. // // Don't bother displaying a WikiLink 'unknown', just // the Un~WikiLink~ified (plain) name of the uncreated // page currently being viewed. $pagelink = $page; if ($pagelist->isEmpty()) { return HTML::p(fmt("No other page links to %s yet.", $pagelink)); } if ($total == 1) { $pagelist->setCaption(fmt("One page would link to %s:", $pagelink)); } else { $pagelist->setCaption(fmt("%s pages would link to %s:", $total, $pagelink)); } } else { if ($count) { $tmp_pages = $pages; $p = array_shift($tmp_pages); $pagelink = HTML(WikiLink($p, 'auto')); foreach ($tmp_pages as $p) { $pagelink->pushContent(" ", _("AND"), " ", WikiLink($p, 'auto')); } } else { // BackLinks plugin is being displayed on a normal page. $pagelink = WikiLink($page, 'auto'); } if ($pagelist->isEmpty()) { return HTML::p(fmt("No page links to %s.", $pagelink)); } //trigger_error("DEBUG: " . $pagelist->getTotal()); if ($total == 1) { $pagelist->setCaption(fmt("One page links to %s:", $pagelink)); } else { $pagelist->setCaption(fmt("%s pages link to %s:", $limit > 0 ? $total : _("Those"), $pagelink)); } } } if (!empty($args['linkmore']) and $dbi->isWikiPage($args['linkmore']) and $limit > 0 and $total > $limit) { $pagelist->addCaption(WikiLink($args['linkmore'], "auto", _("More..."))); } return $pagelist; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); if (empty($page) and $page != '0') { return ''; } // exclude is now already expanded in WikiPlugin::getArgs() if (empty($exclude)) { $exclude = array(); } if (!$include_self) { $exclude[] = $page; } if ($info) { $info = explode(",", $info); if (in_array('count', $info)) { $args['types']['count'] = new _PageList_Column_BackLinks_count('count', _("#"), 'center'); } } $args['dosort'] = !empty($args['sortby']); // override DB sort (??) $pagelist = new PageList($info, $exclude, $args); $p = $dbi->getPage($page); $pagelist->addPages($p->getBackLinks(false, $sortby, $limit, $exclude)); // Localization note: In English, the differences between the // various phrases spit out here may seem subtle or negligible // enough to tempt you to combine/normalize some of these // strings together, but the grammar employed most by other // languages does not always end up with so subtle a // distinction as it does with English in this case. :) if (!$noheader) { if ($page == $request->getArg('pagename') and !$dbi->isWikiPage($page)) { // BackLinks plugin is more than likely being called // upon for an empty page on said page, while either // 'browse'ing, 'create'ing or 'edit'ing. // // Don't bother displaying a WikiLink 'unknown', just // the Un~WikiLink~ified (plain) name of the uncreated // page currently being viewed. $pagelink = $page; if ($pagelist->isEmpty()) { return HTML::p(fmt("No other page links to %s yet.", $pagelink)); } if ($pagelist->getTotal() == 1) { $pagelist->setCaption(fmt("One page would link to %s:", $pagelink)); } else { $pagelist->setCaption(fmt("%s pages would link to %s:", $pagelist->getTotal(), $pagelink)); } } else { // BackLinks plugin is being displayed on a normal page. $pagelink = WikiLink($page, 'auto'); if ($pagelist->isEmpty()) { return HTML::p(fmt("No page links to %s.", $pagelink)); } //trigger_error("DEBUG: " . $pagelist->getTotal()); if ($pagelist->getTotal() == 1) { $pagelist->setCaption(fmt("One page links to %s:", $pagelink)); } else { $pagelist->setCaption(fmt("%s pages link to %s:", $pagelist->getTotal(), $pagelink)); } } } return $pagelist; }