function buildLinkList($PAGE, $LINKSDB) { // ---- Filter link database according to parameters $search_type = ''; $search_crits = ''; $privateonly = !empty($_SESSION['privateonly']) ? true : false; // Fulltext search if (isset($_GET['searchterm'])) { $search_crits = escape(trim($_GET['searchterm'])); $search_type = LinkFilter::$FILTER_TEXT; $linksToDisplay = $LINKSDB->filter($search_type, $search_crits, false, $privateonly); } elseif (isset($_GET['searchtags'])) { $search_crits = explode(' ', escape(trim($_GET['searchtags']))); $search_type = LinkFilter::$FILTER_TAG; $linksToDisplay = $LINKSDB->filter($search_type, $search_crits, false, $privateonly); } elseif (isset($_SERVER['QUERY_STRING']) && preg_match('/[a-zA-Z0-9-_@]{6}(&.+?)?/', $_SERVER['QUERY_STRING'])) { $search_type = LinkFilter::$FILTER_HASH; $search_crits = substr(trim($_SERVER["QUERY_STRING"], '/'), 0, 6); $linksToDisplay = $LINKSDB->filter($search_type, $search_crits); if (count($linksToDisplay) == 0) { header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); echo '<h1>404 Not found.</h1>Oh crap. The link you are trying to reach does not exist or has been deleted.'; echo '<br>Would you mind <a href="?">clicking here</a>?'; exit; } } else { $linksToDisplay = $LINKSDB->filter('', '', false, $privateonly); } // ---- Handle paging. $keys = array(); foreach ($linksToDisplay as $key => $value) { $keys[] = $key; } // If there is only a single link, we change on-the-fly the title of the page. if (count($linksToDisplay) == 1) { $GLOBALS['pagetitle'] = $linksToDisplay[$keys[0]]['title'] . ' - ' . $GLOBALS['title']; } // Select articles according to paging. $pagecount = ceil(count($keys) / $_SESSION['LINKS_PER_PAGE']); $pagecount = $pagecount == 0 ? 1 : $pagecount; $page = empty($_GET['page']) ? 1 : intval($_GET['page']); $page = $page < 1 ? 1 : $page; $page = $page > $pagecount ? $pagecount : $page; // Start index. $i = ($page - 1) * $_SESSION['LINKS_PER_PAGE']; $end = $i + $_SESSION['LINKS_PER_PAGE']; $linkDisp = array(); while ($i < $end && $i < count($keys)) { $link = $linksToDisplay[$keys[$i]]; $link['description'] = format_description($link['description'], $GLOBALS['redirector']); $classLi = $i % 2 != 0 ? '' : 'publicLinkHightLight'; $link['class'] = $link['private'] == 0 ? $classLi : 'private'; $link['timestamp'] = linkdate2timestamp($link['linkdate']); $taglist = explode(' ', $link['tags']); uasort($taglist, 'strcasecmp'); $link['taglist'] = $taglist; $link['shorturl'] = smallHash($link['linkdate']); // Check for both signs of a note: starting with ? and 7 chars long. if ($link['url'][0] === '?' && strlen($link['url']) === 7) { $link['url'] = index_url($_SERVER) . $link['url']; } $linkDisp[$keys[$i]] = $link; $i++; } // Compute paging navigation $searchterm = empty($_GET['searchterm']) ? '' : '&searchterm=' . $_GET['searchterm']; $searchtags = empty($_GET['searchtags']) ? '' : '&searchtags=' . $_GET['searchtags']; $previous_page_url = ''; if ($i != count($keys)) { $previous_page_url = '?page=' . ($page + 1) . $searchterm . $searchtags; } $next_page_url = ''; if ($page > 1) { $next_page_url = '?page=' . ($page - 1) . $searchterm . $searchtags; } $token = ''; if (isLoggedIn()) { $token = getToken(); } // Fill all template fields. $data = array('linkcount' => count($LINKSDB), 'previous_page_url' => $previous_page_url, 'next_page_url' => $next_page_url, 'page_current' => $page, 'page_max' => $pagecount, 'result_count' => count($linksToDisplay), 'search_type' => $search_type, 'search_crits' => $search_crits, 'redirector' => empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'], 'token' => $token, 'links' => $linkDisp, 'tags' => $LINKSDB->allTags()); // FIXME! temporary fix - see #399. if (!empty($GLOBALS['pagetitle']) && count($linkDisp) == 1) { $data['pagetitle'] = $GLOBALS['pagetitle']; } $pluginManager = PluginManager::getInstance(); $pluginManager->executeHooks('render_linklist', $data, array('loggedin' => isLoggedIn())); foreach ($data as $key => $value) { $PAGE->assign($key, $value); } return; }
/** * Template for the list of links (<div id="linklist">) * This function fills all the necessary fields in the $PAGE for the template 'linklist.html' * * @param pageBuilder $PAGE pageBuilder instance. * @param LinkDB $LINKSDB LinkDB instance. */ function buildLinkList($PAGE, $LINKSDB) { // Used in templates $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : ''; // Smallhash filter if (!empty($_SERVER['QUERY_STRING']) && preg_match('/^[a-zA-Z0-9-_@]{6}($|&|#)/', $_SERVER['QUERY_STRING'])) { try { $linksToDisplay = $LINKSDB->filterHash($_SERVER['QUERY_STRING']); } catch (LinkNotFoundException $e) { $PAGE->render404($e->getMessage()); exit; } } else { // Filter links according search parameters. $privateonly = !empty($_SESSION['privateonly']); $linksToDisplay = $LINKSDB->filterSearch($_GET, false, $privateonly); } // ---- Handle paging. $keys = array(); foreach ($linksToDisplay as $key => $value) { $keys[] = $key; } // If there is only a single link, we change on-the-fly the title of the page. if (count($linksToDisplay) == 1) { $GLOBALS['pagetitle'] = $linksToDisplay[$keys[0]]['title'] . ' - ' . $GLOBALS['title']; } // Select articles according to paging. $pagecount = ceil(count($keys) / $_SESSION['LINKS_PER_PAGE']); $pagecount = $pagecount == 0 ? 1 : $pagecount; $page = empty($_GET['page']) ? 1 : intval($_GET['page']); $page = $page < 1 ? 1 : $page; $page = $page > $pagecount ? $pagecount : $page; // Start index. $i = ($page - 1) * $_SESSION['LINKS_PER_PAGE']; $end = $i + $_SESSION['LINKS_PER_PAGE']; $linkDisp = array(); while ($i < $end && $i < count($keys)) { $link = $linksToDisplay[$keys[$i]]; $link['description'] = format_description($link['description'], $GLOBALS['redirector']); $classLi = $i % 2 != 0 ? '' : 'publicLinkHightLight'; $link['class'] = $link['private'] == 0 ? $classLi : 'private'; $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); $link['timestamp'] = $date->getTimestamp(); $taglist = explode(' ', $link['tags']); uasort($taglist, 'strcasecmp'); $link['taglist'] = $taglist; $link['shorturl'] = smallHash($link['linkdate']); // Check for both signs of a note: starting with ? and 7 chars long. if ($link['url'][0] === '?' && strlen($link['url']) === 7) { $link['url'] = index_url($_SERVER) . $link['url']; } $linkDisp[$keys[$i]] = $link; $i++; } // Compute paging navigation $searchtagsUrl = empty($searchtags) ? '' : '&searchtags=' . urlencode($searchtags); $searchtermUrl = empty($searchterm) ? '' : '&searchterm=' . urlencode($searchterm); $previous_page_url = ''; if ($i != count($keys)) { $previous_page_url = '?page=' . ($page + 1) . $searchtermUrl . $searchtagsUrl; } $next_page_url = ''; if ($page > 1) { $next_page_url = '?page=' . ($page - 1) . $searchtermUrl . $searchtagsUrl; } $token = isLoggedIn() ? getToken() : ''; // Fill all template fields. $data = array('previous_page_url' => $previous_page_url, 'next_page_url' => $next_page_url, 'page_current' => $page, 'page_max' => $pagecount, 'result_count' => count($linksToDisplay), 'search_term' => $searchterm, 'search_tags' => $searchtags, 'redirector' => empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'], 'token' => $token, 'links' => $linkDisp, 'tags' => $LINKSDB->allTags()); // FIXME! temporary fix - see #399. if (!empty($GLOBALS['pagetitle']) && count($linkDisp) == 1) { $data['pagetitle'] = $GLOBALS['pagetitle']; } $pluginManager = PluginManager::getInstance(); $pluginManager->executeHooks('render_linklist', $data, array('loggedin' => isLoggedIn())); foreach ($data as $key => $value) { $PAGE->assign($key, $value); } return; }
$intOSX = $row["osx"]; $intOSY = $row["osy"]; $intTenure = $row["lease_free"]; $intStatus = $row["state_of_trade_id"]; $intType = $row["type_id"]; if ($intType == "1" || $intType == "2" || $intType == "5" || $intType == "7") { $strLinkType = "House"; } elseif ($intType == "3" || $intType == "4" || $intType == "6") { $strLinkType = "Apartment"; } elseif ($intType == "8") { $strLinkType = "Commercial"; } elseif ($intType == "9") { $strLinkType = "Live/Work"; } $intArea = $row["area_id"]; $strLongDescription = format_description($row["longDescription"]); $strDescription = format_strap($row["description"]); $strGCH = $row["gch"]; $strDG = $row["doubleGlazed"]; $intReceptions = $row["receptions"]; $intBedrooms = $row["bedrooms"]; $intBathrooms = $row["bathrooms"]; $intGarden = $row["garden"]; $intParking = $row["parking"]; $strNotes = $row["notes"]; $strTotalArea = $row["total_area"]; $strImage0 = $row["image0"]; $strImage1 = $row["image1"]; $strImage2 = $row["image2"]; $strImage3 = $row["image3"]; $strImage4 = $row["image4"];
function buildLinkList($PAGE, $LINKSDB) { // ---- Filter link database according to parameters $linksToDisplay = array(); $search_type = ''; $search_crits = ''; if (isset($_GET['searchterm'])) { $linksToDisplay = $LINKSDB->filterFulltext(trim($_GET['searchterm'])); $search_crits = escape(trim($_GET['searchterm'])); $search_type = 'fulltext'; } elseif (isset($_GET['searchtags'])) { $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags'])); $search_crits = explode(' ', escape(trim($_GET['searchtags']))); $search_type = 'tags'; } elseif (isset($_SERVER['QUERY_STRING']) && preg_match('/[a-zA-Z0-9-_@]{6}(&.+?)?/', $_SERVER['QUERY_STRING'])) { $linksToDisplay = $LINKSDB->filterSmallHash(substr(trim($_SERVER["QUERY_STRING"], '/'), 0, 6)); if (count($linksToDisplay) == 0) { header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); echo '<h1>404 Not found.</h1>Oh crap. The link you are trying to reach does not exist or has been deleted.'; echo '<br>Would you mind <a href="?">clicking here</a>?'; exit; } $search_type = 'permalink'; } else { $linksToDisplay = $LINKSDB; } // Otherwise, display without filtering. // Option: Show only private links if (!empty($_SESSION['privateonly'])) { $tmp = array(); foreach ($linksToDisplay as $linkdate => $link) { if ($link['private'] != 0) { $tmp[$linkdate] = $link; } } $linksToDisplay = $tmp; } // ---- Handle paging. /* Can someone explain to me why you get the following error when using array_keys() on an object which implements the interface ArrayAccess??? "Warning: array_keys() expects parameter 1 to be array, object given in ... " If my class implements ArrayAccess, why won't array_keys() accept it ? ( $keys=array_keys($linksToDisplay); ) */ $keys = array(); foreach ($linksToDisplay as $key => $value) { $keys[] = $key; } // Stupid and ugly. Thanks PHP. // If there is only a single link, we change on-the-fly the title of the page. if (count($linksToDisplay) == 1) { $GLOBALS['pagetitle'] = $linksToDisplay[$keys[0]]['title'] . ' - ' . $GLOBALS['title']; } // Select articles according to paging. $pagecount = ceil(count($keys) / $_SESSION['LINKS_PER_PAGE']); $pagecount = $pagecount == 0 ? 1 : $pagecount; $page = empty($_GET['page']) ? 1 : intval($_GET['page']); $page = $page < 1 ? 1 : $page; $page = $page > $pagecount ? $pagecount : $page; $i = ($page - 1) * $_SESSION['LINKS_PER_PAGE']; // Start index. $end = $i + $_SESSION['LINKS_PER_PAGE']; $linkDisp = array(); // Links to display while ($i < $end && $i < count($keys)) { $link = $linksToDisplay[$keys[$i]]; $link['description'] = format_description($link['description'], $GLOBALS['redirector']); $classLi = $i % 2 != 0 ? '' : 'publicLinkHightLight'; $link['class'] = $link['private'] == 0 ? $classLi : 'private'; $link['timestamp'] = linkdate2timestamp($link['linkdate']); $taglist = explode(' ', $link['tags']); uasort($taglist, 'strcasecmp'); $link['taglist'] = $taglist; $link['shorturl'] = smallHash($link['linkdate']); if ($link["url"][0] === '?' && strlen($link["url"]) === 7) { $link["url"] = index_url($_SERVER) . $link["url"]; } $linkDisp[$keys[$i]] = $link; $i++; } // Compute paging navigation $searchterm = empty($_GET['searchterm']) ? '' : '&searchterm=' . $_GET['searchterm']; $searchtags = empty($_GET['searchtags']) ? '' : '&searchtags=' . $_GET['searchtags']; $paging = ''; $previous_page_url = ''; if ($i != count($keys)) { $previous_page_url = '?page=' . ($page + 1) . $searchterm . $searchtags; } $next_page_url = ''; if ($page > 1) { $next_page_url = '?page=' . ($page - 1) . $searchterm . $searchtags; } $token = ''; if (isLoggedIn()) { $token = getToken(); } // Fill all template fields. $data = array('pagetitle' => $GLOBALS['pagetitle'], 'linkcount' => count($LINKSDB), 'previous_page_url' => $previous_page_url, 'next_page_url' => $next_page_url, 'page_current' => $page, 'page_max' => $pagecount, 'result_count' => count($linksToDisplay), 'search_type' => $search_type, 'search_crits' => $search_crits, 'redirector' => empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'], 'token' => $token, 'links' => $linkDisp, 'tags' => $LINKSDB->allTags()); $pluginManager = PluginManager::getInstance(); $pluginManager->executeHooks('render_linklist', $data, array('loggedin' => isLoggedIn())); foreach ($data as $key => $value) { $PAGE->assign($key, $value); } return; }
/** * Build a feed item (one per shaare). * * @param array $link Single link array extracted from LinkDB. * @param string $pageaddr Index URL. * * @return array Link array with feed attributes. */ protected function buildItem($link, $pageaddr) { $link['guid'] = $pageaddr . '?' . smallHash($link['linkdate']); // Check for both signs of a note: starting with ? and 7 chars long. if ($link['url'][0] === '?' && strlen($link['url']) === 7) { $link['url'] = $pageaddr . $link['url']; } if ($this->usePermalinks === true) { $permalink = '<a href="' . $link['url'] . '" title="Direct link">Direct link</a>'; } else { $permalink = '<a href="' . $link['guid'] . '" title="Permalink">Permalink</a>'; } $link['description'] = format_description($link['description']) . PHP_EOL . '<br>— ' . $permalink; $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); if ($this->feedType == self::$FEED_RSS) { $link['iso_date'] = $date->format(DateTime::RSS); } else { $link['iso_date'] = $date->format(DateTime::ATOM); } // Save the more recent item. if (empty($this->latestDate) || $this->latestDate < $date) { $this->latestDate = $date; } $taglist = array_filter(explode(' ', $link['tags']), 'strlen'); uasort($taglist, 'strcasecmp'); $link['taglist'] = $taglist; return $link; }