Example #1
0
/**
 * Makes archive link for a certain date.
 */
function make_archive_link($date = "")
{
    global $db, $Paths, $Weblogs, $Current_weblog;
    if ($date == "") {
        $date = $db->entry['date'];
    }
    $filelink = $Paths['pivot_url'] . $Weblogs[$Current_weblog]['archive_path'] . make_archive_name($date);
    $filelink = fixPath($filelink);
    return $filelink;
}
function snippet_archiveprevious($text = "")
{
    global $Cfg, $db, $Weblogs, $Current_weblog, $Archive_array, $archive_array_prev, $Pivot_Vars, $Paths;
    if ($text == "") {
        $text = lang('weblog_text', 'previous_archive');
    }
    if (!defined('LIVEPAGE')) {
        // in 'normal' archive pages'..
        if (!isset($db->entry)) {
            return "";
        }
        // get the filename for the current archive..
        $current_archive = make_archive_name();
        $id = $db->entry['code'];
        // get the archive_array, if it's not done yet.
        if (!isset($Archive_array)) {
            make_archive_array();
        }
        // we make another array where we number the archives. As far as i know this is
        // the only decent way to find the next or previous entries..
        // sometime i will want to cache this for performance
        $counter = 0;
        // 2004/11/23 =*=*= JM - foreach() test
        if (is_array($Archive_array[$Current_weblog])) {
            foreach ($Archive_array[$Current_weblog] as $this_key => $this_val) {
                $temp_arr[$counter] = $this_key;
                if ($this_key == $current_archive) {
                    $this_count = $counter;
                }
                $counter++;
            }
        }
        // then, we'll pick out the next one in the array (remember, the array
        // is in reverse chronological order)
        if (isset($temp_arr[$this_count - 1])) {
            $prev_arc = $temp_arr[$this_count - 1];
            $target = set_target('', 'target="_self"');
            $date = $Archive_array[$Current_weblog][$prev_arc];
            $link = make_archive_link($date);
            $text = format_date($date, $text);
            $link = sprintf("<a href=\"%s\" %s>%s</a>", $link, $target, $text);
            return $link;
        } else {
            return "";
        }
    } else {
        // display link for pages in 'live archives'
        // guessstimate the current sybweblog.
        reset($Weblogs[$Current_weblog]['sub_weblog']);
        $my_subweblog = current($Weblogs[$Current_weblog]['sub_weblog']);
        $show = $my_subweblog['num_entries'];
        if (!isset($Pivot_Vars['o']) || empty($Pivot_Vars['o']) || $Pivot_Vars['o'] <= 0) {
            $offset = -1;
        } else {
            if ($Pivot_Vars['o'] < $show) {
                $offset = 0;
            } else {
                $offset = $Pivot_Vars['o'] - $show;
            }
        }
        // if it's the first one, we don't have to show it.
        if ($offset >= 0) {
            if ($Cfg['mod_rewrite'] == 0) {
                $url = $Paths['pivot_url'] . "archive.php?c=%s&amp;o=%s";
            } else {
                $url = $Paths['log_url'] . "category/%s/?o=%s";
            }
            $link = sprintf($url, para_category($Pivot_Vars['c']), $offset);
            if (para_weblog_needed($Current_weblog)) {
                $link .= '&amp;w=' . para_weblog($Current_weblog);
            } elseif (isset($_GET['w']) && !empty($_GET['w'])) {
                $link .= '&amp;w=' . htmlspecialchars($_GET['w']);
            }
            if (isset($_GET['t']) && !empty($_GET['t'])) {
                $link .= '&amp;t=' . htmlspecialchars($_GET['t']);
            }
            $target = set_target('', 'target="_self"');
            $link = sprintf("<a href=\"%s\" %s>%s</a>", $link, $target, $text);
        } else {
            $link = "";
        }
        return $link;
    }
}
function make_default()
{
    global $Weblogs, $Current_weblog, $db, $entry;
    $db = new db();
    $arc_list = "";
    if (file_exists($pivot_dir . "db/ser-archive_overview_cat.php") && file_exists($pivot_dir . "db/ser-archive_overview_cat.php")) {
        $arc_array_cat = load_serialize($pivot_dir . "db/ser-archive_overview_cat.php", TRUE);
        $arc_array_mon = load_serialize($pivot_dir . "db/ser-archive_overview_mon.php", TRUE);
        // if over three three days old.
        if (mktime() - filemtime($pivot_dir . "db/ser-archive_overview_cat.php") > 259200) {
            unlink($pivot_dir . "db/ser-archive_overview_cat.php");
            unlink($pivot_dir . "db/ser-archive_overview_mon.php");
        }
    } else {
        $list_entries = $db->getlist_range("1970-01-01-00-00", "2020-12-31-23-59", "", "", FALSE);
        // iterate through all of the entries, building the arrays for both the
        // per-month and per-category lists..
        foreach ($list_entries as $list_entry) {
            $date = format_date($list_entry['date'], $Weblogs[$Current_weblog]['fulldate_format']);
            $link = make_filelink($list_entry['code']);
            list($ye, $mo) = explode("-", $list_entry['date']);
            if (isset($list_entry['category'])) {
                foreach ($list_entry['category'] as $cat) {
                    $arc_array_cat[$cat][$ye] = 1;
                }
            }
            $arc_array_mon[$ye][$mo] = 1;
        }
        save_serialize($pivot_dir . "db/ser-archive_overview_cat.php", $arc_array_cat, FALSE);
        save_serialize($pivot_dir . "db/ser-archive_overview_mon.php", $arc_array_mon, FALSE);
    }
    $current_cats = find_cats_in_weblog($Current_weblog);
    // build the per-month list
    foreach ($arc_array_mon as $ye => $months) {
        $arc_list .= "<p><b>{$ye}:</b><br />\n";
        ksort($months);
        $temp_arr = array();
        foreach ($months as $mo => $dummy) {
            $temp_arr[] = sprintf("<a href=\"%s/%s/\">%s</a>\n", $ye, $mo, lang('months', -1 + $mo));
        }
        $arc_list .= implode(", ", $temp_arr) . "<br /></p>\n";
    }
    // build the per-category list
    ksort($arc_array_cat);
    if (count($arc_array_cat) > 1) {
        foreach ($arc_array_cat as $cat => $year) {
            if (in_array($cat, $current_cats)) {
                $arc_list .= "<p><b>{$cat}:</b>\n";
                ksort($year);
                $temp_arr = array();
                foreach ($year as $ye => $dummy) {
                    $temp_arr[] = sprintf("<a href=\"%s/%s/\">%s</a>\n", $cat, $ye, $ye);
                }
                $arc_list .= implode(", ", $temp_arr) . "</p>\n";
            }
        }
    }
    // the search template for the current weblog
    if (isset($Weblogs[$Current_weblog]['extra_template']) && $Weblogs[$Current_weblog]['extra_template'] != "") {
        $template_html = load_template($Weblogs[$Current_weblog]['extra_template']);
    } else {
        $template_html = load_template($Weblogs[$Current_weblog]['archive_template']);
    }
    $template_html = replace_subweblogs_templates($template_html, $arc_list);
    $filename = $Weblogs[$Current_weblog]['archive_path'] . make_archive_name();
    if (!$template_html) {
        ErrorOut("Could not load template file: <i>{$template}</i> [does not exist]");
    } else {
        $output = $template_html;
        $output = parse_step4($output);
    }
    echo $output;
    flush();
}
Example #4
0
 /**
  * Gets an array of archives - flat file implementation.
  *
  * Reads or creates/updates "db/ser-archives.php".
  *
  * @param boolean $force tells if "db/ser-archives.php" should be updated
  * @return array
  */
 function get_archive_array($force = FALSE)
 {
     global $pivot_path;
     if ($force || !file_exists($pivot_path . 'db/ser-archives.php')) {
         debug("REBUILD make_archive_array");
         $Archive_array = array();
         $lastdate = 0;
         ksort($this->date_index);
         foreach ($this->date_index as $code => $date) {
             $this->entry['code'] = $code;
             $this->check_current_index();
             $this->entry_from_indexline();
             if ($this->entry['status'] == 'publish') {
                 $in_weblogs = find_weblogs_with_cat($this->entry['category']);
                 foreach ($in_weblogs as $in_weblog) {
                     $name = make_archive_name($this->entry['date'], $in_weblog);
                     $Archive_array[$in_weblog][$name] = $this->entry['date'];
                 }
             }
         }
         // sort the array, to maintain correct order..
         foreach ($Archive_array as $key => $value) {
             krsort($Archive_array[$key]);
         }
         // save the archive_array, for easier retrieval next time..
         save_serialize($pivot_path . 'db/ser-archives.php', $Archive_array);
     } else {
         // just load the file, and get the last 3 entries. Much easier..
         $Archive_array = load_serialize($pivot_path . 'db/ser-archives.php');
         $entries_arr = $this->getlist(-3);
         // loop for all entries
         foreach ($entries_arr as $loopentry) {
             // Skipping entries on hold. (If the three last enries
             // are on hold this for loop does nothing.)
             if ($loopentry['status'] != "publish") {
                 continue;
             }
             // then loop for all the weblogs that publish this entry
             $in_weblogs = find_weblogs_with_cat($loopentry['category']);
             foreach ($in_weblogs as $in_weblog) {
                 $name = make_archive_name($loopentry['date'], $in_weblog);
                 $Archive_array[$in_weblog][$name] = $loopentry['date'];
             }
         }
         // sort the array, to maintain correct order..
         foreach ($Archive_array as $key => $value) {
             krsort($Archive_array[$key]);
         }
     }
     return $Archive_array;
 }