/** * Inserts a linked list to the archives. * * @param array $params * @param object $smarty * @return string */ function smarty_archive_list($params, &$smarty) { global $Archive_array, $PIVOTX; $params = cleanParams($params); $Current_weblog = getDefault($params['weblog'], $PIVOTX['weblogs']->getCurrent()); $format = getDefault($params['format'], "<a href=\"%url%\">%st_day% %st_monname% - %en_day% %en_monname% %st_year% </a><br />"); $unit = getDefault($params['unit'], "month"); $separator = getDefault($params['separator'], ""); // if not yet done, load / make the array of archive filenames (together // with at least one date) if (!isset($Archive_array)) { makeArchiveArray(false, $unit); } // If we use 'isactive', set up the $active_arc and $isactive vars. if (!empty($params['isactive'])) { $active_arc = $pagetype = $PIVOTX['parser']->modifier['archive']; $isactive = $params['isactive']; } else { $isactive = ""; } $output = array(); if (is_array($Archive_array[$Current_weblog])) { // maybe flip and reverse it. if ($params['order'] == 'descending' || $params['order'] == 'desc') { $mylist = $Archive_array[$Current_weblog]; } else { $mylist = array_reverse($Archive_array[$Current_weblog]); } // Iterate over the list, formatting output as we go. $counter = 0; foreach ($mylist as $date) { $counter++; $filelink = makeArchiveLink($date, $unit, $params['weblog']); // Check if the current archive is the 'active' one. if (!empty($isactive) && makeArchiveName($date, '', $unit) == $active_arc) { $thisactive = $isactive; } else { $thisactive = ""; } // fix the rest of the string.. list($start_date, $stop_date) = getDateRange($date, $unit); $this_output = formatDateRange($start_date, $stop_date, $format); $this_output = str_replace("%counter%", $counter, $this_output); $this_output = str_replace("%url%", $filelink, $this_output); $this_output = str_replace("%active%", $thisactive, $this_output); $output[] = "\n" . $this_output; } } return implode($separator, $output); }
/** * Gets an array of archives - flat file implementation. * * Reads or creates/updates "ser-archives.php". The file * contains 3 arrays - one for each time unit. * * @param boolean $force tells if "ser-archives.php" should be updated * @param string $unit the unit of the archives * @return array */ function getArchiveArray($force = FALSE, $unit_para = '') { global $PIVOTX; $units = array('week', 'month', 'year'); $updated = false; if ($force || !file_exists($PIVOTX['paths']['db_path'] . 'ser-archives.php')) { $updated = true; $Archive_array = array(); $lastdate = 0; foreach ($units as $unit) { $Archive_array[$unit] = array(); } ksort($this->date_index); foreach ($this->date_index as $code => $date) { $this->entry['code'] = $code; $this->check_current_index(); $this->entry_from_index(); if ($this->entry['status'] == 'publish') { $in_weblogs = $PIVOTX['weblogs']->getWeblogsWithCat($this->entry['category']); foreach ($in_weblogs as $in_weblog) { foreach ($units as $unit) { $name = makeArchiveName($this->entry['date'], $in_weblog, $unit); $Archive_array[$unit][$in_weblog][$name] = $this->entry['date']; } } } } } else { // just load the file, and get the last 3 entries. Much easier.. $Archive_array = loadSerialize($PIVOTX['paths']['db_path'] . 'ser-archives.php'); $entries_arr = $this->read_entries(array('full' => false, 'show' => 3, 'status' => 'publish', 'order' => 'desc')); // loop for all entries foreach ($entries_arr as $loopentry) { // then loop for all the weblogs that publish this entry $in_weblogs = $PIVOTX['weblogs']->getWeblogsWithCat($loopentry['category']); foreach ($in_weblogs as $in_weblog) { foreach ($units as $unit) { $name = makeArchiveName($loopentry['date'], $in_weblog, $unit); $Archive_array[$unit][$in_weblog][$name] = $loopentry['date']; } } } } // sort the array, to maintain correct order.. foreach ($units as $unit) { foreach ($Archive_array[$unit] as $key => $value) { krsort($Archive_array[$unit][$key]); } } if ($updated) { // save the archive_array, for easier retrieval next time.. saveSerialize($PIVOTX['paths']['db_path'] . 'ser-archives.php', $Archive_array); } if ($unit_para == '') { return $Archive_array; } else { return $Archive_array[$unit_para]; } }
/** * Makes archive link for a certain date. */ function makeArchiveLink($date = "", $unit = "", $override_weblog = "") { global $PIVOTX; if ($date == "") { $vars = $PIVOTX['template']->get_template_vars(); $date = $vars['date']; } if ($unit != '') { $archive_uri = makeArchiveName($date, '', $unit); } else { $archive_uri = makeArchiveName($date); } // Set the weblog, according to passed parameter or current weblog $weblog = getDefault($override_weblog, $PIVOTX['weblogs']->getCurrent()); $site_url = getDefault($PIVOTX['weblogs']->get($weblog, 'site_url'), $PIVOTX['paths']['site_url']); if ($PIVOTX['config']->get('mod_rewrite') < 1) { $link = $site_url . '?a=' . $archive_uri; } else { $prefix = getDefault($PIVOTX['config']->get('localised_archive_prefix'), "archive"); $link = $site_url . makeURI($prefix) . "/" . $archive_uri; } // If we have more than one weblog, add the w=weblogname parameter if (paraWeblogNeeded($weblog)) { if ($PIVOTX['config']->get('mod_rewrite') > 0) { // we treat it as an extra 'folder' $link .= "/" . $weblog; } else { $link .= "&w=" . $weblog; } } // Check if there's a hook set, and if so call it. This hook has no 'return' value. if ($PIVOTX['extensions'] && $PIVOTX['extensions']->hasHook('make_link#archives')) { $PIVOTX['extensions']->executeHook('make_link#archives', $link, array('date' => $date, 'unit' => $unit, 'w' => $weblog)); } return $link; }
/** * Gets an array of archives - sql implementation. * * In contrast to the flat file implementation, the file * "db/ser-archives.php" isn't used. * * @param boolean $force ignored, only used by flat file implementation. * @param string $unit the unit of the archives. * @return array */ function getArchiveArray($force = FALSE, $unit) { global $PIVOTX; $Archive_array = array(); // Get an array with the weblognames $weblognames = $PIVOTX['weblogs']->getWeblogNames(); // .. which we'll iterate through to collect all archives foreach ($weblognames as $weblogname) { // Get the categories published in the current weblog $categories = $PIVOTX['weblogs']->getCategories($weblogname); $categories = array_map('safe_string', $categories); $categories = "'" . implode("', '", $categories) . "'"; /* [JAN] if ($unit=="month" || $unit=="year") { $datelength = 7; } else { $datelength = 10; } // Select all dates of entries in this weblog.. $this->sql->query("SELECT DISTINCT(LEFT(date, $datelength)) AS date [/JAN] */ $this->sql->query("SELECT DISTINCT(date) AS date\n FROM " . $this->entriestable . " AS e\n LEFT JOIN " . $this->categoriestable . " AS c ON (c.target_uid = e.uid)\n WHERE c.category IN ({$categories}) AND\n c.contenttype = 'entry' AND\n e.status='publish'\n ORDER BY date ASC"); $date_index = $this->sql->fetch_all_rows(); $date_index = makeValuepairs($date_index, '', 'date'); // echo nl2br(htmlentities($this->sql->get_last_query())); foreach ($date_index as $date) { $name = makeArchiveName($date, $weblogname, $unit); $Archive_array[$weblogname][$name] = $date; } } // sort the array, to maintain correct order.. foreach ($Archive_array as $key => $value) { krsort($Archive_array[$key]); } return $Archive_array; }