Beispiel #1
0
 function doit($action, $text, $cats, $amountperpage, $params)
 {
     global $PIVOTX;
     $Current_weblog = $PIVOTX['weblogs']->getCurrent();
     $modifier = $PIVOTX['parser']->get('modifier');
     // $amountperpage must be numeric, one or larger
     if (!is_numeric($amountperpage) || $amountperpage < 1) {
         return "<!-- snippet {$this->name} error: invalid number of entries to skip ({$amountperpage}) -->\n";
     }
     // Preserving some query parameters
     $query = array();
     if (isset($_GET['w']) && (empty($_GET['rewrite']) || $_GET['rewrite'] == 'offset')) {
         $query['w'] = 'w=' . $_GET['w'];
     }
     if (isset($_GET['t'])) {
         $query['t'] = 't=' . $_GET['t'];
     }
     if (!empty($_GET['u'])) {
         $query['u'] = 'u=' . $_GET['u'];
     }
     // Setting the text for the links
     if ($action == "next") {
         $text = getDefault($params['format'], __("Next page") . " &#187;");
     } elseif ($action == "prev") {
         $text = getDefault($params['format'], "&#171; " . __("Previous page"));
     } elseif ($action == "digg") {
         $text_prev = getDefault($params['format_prev'], "&#171; " . __("Previous page"));
         $text_next = getDefault($params['format_next'], __("Next page") . " &#187;");
     } else {
         $text = getDefault($params['format'], __("Displaying entries %num_from%-%num_to% of %num_tot%"));
     }
     // Get the maximum amount of pages to show.
     $max_digg_pages = getDefault($params['maxpages'], 9);
     // Get the id to attach to the <ul> for Digg style navigation.
     $digg_id = getDefault($params['id'], "pages");
     // Start the real work.
     $eachcatshash = md5(implodeDeep("", $cats));
     if ($PIVOTX['cache']->get('paging', $eachcatshash)) {
         // Check if this is in our simple cache?
         list($temp_tot, $num_tot) = $PIVOTX['cache']->get('paging', $eachcatshash);
     } else {
         // Get the total amount of entries. How we do this depends on the used DB-model..
         // What we do is we get the amount of entries for each item in $cats.
         // For example, let's say we have 10 entries per page and 90 entries in one subweblog, and
         // 65 in the other. In this case we don't need (90+65)/10 pages, but (max(90,65))/10 pages.
         if ($PIVOTX['db']->db_type == "flat") {
             // Get the amount from the Flat files DB..
             $tot = $PIVOTX['db']->get_entries_count();
             foreach ($cats as $eachcats) {
                 if (!is_array($eachcats) && trim($eachcats) == '') {
                     continue;
                 }
                 $temp_tot = count($PIVOTX['db']->read_entries(array('show' => $tot, 'cats' => $eachcats, 'user' => $_GET['u'], 'status' => 'publish')));
                 $num_tot = max($num_tot, $temp_tot);
             }
         } else {
             // Get the amount from our SQL db..
             // Set up DB factory
             $sqlFactory = new sqlFactory($PIVOTX['config']->get('db_model'), $PIVOTX['config']->get('db_databasename'), $PIVOTX['config']->get('db_hostname'), $PIVOTX['config']->get('db_username'), $PIVOTX['config']->get('db_password'));
             // Set up DB connection
             $sql = $sqlFactory->getSqlInstance();
             $entriestable = safeString($PIVOTX['config']->get('db_prefix') . "entries", true);
             $categoriestable = safeString($PIVOTX['config']->get('db_prefix') . "categories", true);
             foreach ($cats as $eachcats) {
                 if (is_array($eachcats)) {
                     $eachcats = implode("','", $eachcats);
                 } else {
                     if (trim($eachcats) == '') {
                         continue;
                     }
                 }
                 $qry['select'] = "COUNT(DISTINCT(e.uid))";
                 $qry['from'] = $entriestable . " AS e, " . $categoriestable . " as c";
                 $qry['where'][] = "e.status='publish' AND e.uid=c.target_uid AND c.category IN ('{$eachcats}')";
                 $sqlquery = $sql->build_select($qry);
                 $sql->query($sqlquery);
                 $temp_tot = current($sql->fetch_row());
                 $num_tot = max($num_tot, $temp_tot);
             }
         }
         $PIVOTX['cache']->set('paging', $eachcatshash, array($temp_tot, $num_tot));
     }
     $offset = intval($modifier['offset']);
     $num_pages = ceil($num_tot / $amountperpage);
     if ($num_tot == 0) {
         return "<!-- snippet {$this->name}: no entries -->\n";
     } elseif ($offset >= $num_pages) {
         return "<!-- snippet {$this->name}: no more entries -->\n";
     }
     if ($action == "next") {
         $offset++;
         if ($offset >= $num_pages) {
             return "<!-- snippet {$this->name} (next): no more entries -->\n";
         }
     } elseif ($action == "prev") {
         if ($offset == 0) {
             return "<!-- snippet {$this->name} (previous): no previous entries -->\n";
         } else {
             $offset--;
         }
     } else {
         if ($num_tot == 0) {
             return "<!-- snippet {$this->name} (curr): no current entries -->\n";
         } else {
             $num = min($num, $num_tot);
         }
     }
     $num_from = $offset * $amountperpage + 1;
     $num_to = min($num_tot, ($offset + 1) * $amountperpage);
     $text = str_replace("%num%", min($num_tot, $amountperpage), $text);
     $text = str_replace("%num_tot%", $num_tot, $text);
     $text = str_replace("%num_from%", $num_from, $text);
     $text = str_replace("%num_to%", $num_to, $text);
     if ($action == "curr") {
         return $text;
     }
     $site_url = getDefault($PIVOTX['weblogs']->get($Current_weblog, 'site_url'), $PIVOTX['paths']['site_url']);
     if ((!empty($modifier['category']) || $params['catsinlink'] == true) && $params['category'] != "*") {
         // Ensure that we get a sorted list of unique categories in
         // the URL - better SEO, one unique URL.
         $catslink = implodeDeep(",", $cats);
         $catslink = array_unique(explode(",", $catslink));
         sort($catslink, SORT_STRING);
         $catslink = implode(",", $catslink);
     }
     if ($PIVOTX['config']->get('mod_rewrite') == 0) {
         if ((!empty($modifier['category']) || $params['catsinlink'] == true) && $params['category'] != "*") {
             $link = $site_url . "?c=" . $catslink . "&amp;o=";
         } else {
             $link = $site_url . "?o=";
         }
     } else {
         if ((!empty($modifier['category']) || $params['catsinlink'] == true) && $params['category'] != "*") {
             $categoryname = getDefault($PIVOTX['config']->get('localised_category_prefix'), "category");
             $link = $site_url . $categoryname . "/" . $catslink . "/";
         } else {
             $pagesname = getDefault($PIVOTX['config']->get('localised_browse_prefix'), "browse");
             $link = $site_url . $pagesname . "/";
         }
     }
     if ($action == 'digg') {
         $link .= '%offset%';
     } else {
         $link .= $offset;
     }
     if (!isset($query['w']) && paraWeblogNeeded($Current_weblog)) {
         if ($PIVOTX['config']->get('mod_rewrite') == 0) {
             $link .= "&amp;w=" . para_weblog($Current_weblog);
         } else {
             $link .= "/" . para_weblog($Current_weblog);
         }
     }
     // Add the query parameters (if any)
     if (count($query) > 0) {
         $query = implode('&amp;', $query);
         if ($PIVOTX['config']->get('mod_rewrite') == 0) {
             $link .= '&amp;' . $query;
         } else {
             $link .= '?' . $query;
         }
     }
     $link = str_replace(array('"', "'"), "", $link);
     if ($action != 'digg') {
         // Perhaps add some extra attributes to the <a> tag
         $extra = "";
         if (!empty($params['target'])) {
             $extra .= " target='" . $params['target'] . "'";
         }
         if (!empty($params['class'])) {
             $extra .= " class='" . $params['class'] . "'";
         }
         if (!empty($params['id'])) {
             $extra .= " id='" . $params['id'] . "'";
         }
         if (!empty($params['datarole'])) {
             $extra .= " data-role='" . $params['datarole'] . "'";
         }
         $output = sprintf('<a href="%s" %s>%s</a>', $link, $extra, $text);
         return $output;
     } else {
         $output = "\n<div id=\"{$digg_id}\">\n    <ul>\n    %links%\n    </ul>\n</div>";
         $links = '';
         // Adding the previous link
         if ($offset == 0) {
             $links .= '<li class="nolink">%text_prev%</li>';
         } else {
             $links .= '<li><a href="%url%">%text_prev%</a></li>';
             $url = str_replace('%offset%', max(0, $offset - 1), $link);
             $links = str_replace('%url%', $url, $links);
         }
         if ($num_pages > $max_digg_pages) {
             // Limit the number of links/listed pages.
             $max_digg_pages = intval($max_digg_pages);
             $start = (int) ($offset - 0.5 * ($max_digg_pages - 1));
             $start = max(0, $start) + 1;
             $stop = (int) ($offset + 0.5 * ($max_digg_pages - 1));
             $stop = max(min(1000, $stop), 3);
             $page = $offset;
             if ($offset == 0) {
                 $links .= '<li class="current">1</li>';
             } else {
                 if ($start >= 1) {
                     $links .= '<li><a href="%url%">1</a></li>';
                     if ($start >= 2) {
                         $links .= '<li class="skip">&#8230;</li>';
                     }
                     $url = str_replace('%offset%', 0, $link);
                     $links = str_replace('%url%', $url, $links);
                 }
             }
         } else {
             // Display all links/listed pages.
             $start = 0;
             $stop = 100;
         }
         // Adding all links before the current page
         while ($start < $offset) {
             $links .= '<li><a href="%url%">' . ($start + 1) . '</a></li>';
             $url = str_replace('%offset%', $start, $link);
             $links = str_replace('%url%', $url, $links);
             $start++;
         }
         // Current page..
         if ($start == $offset) {
             $links .= '<li class="current">' . ($start + 1) . '</li>';
             $start++;
         }
         // Adding all links after the current page
         while ($start < $num_pages) {
             if ($start < $stop) {
                 $links .= '<li><a href="%url%">' . ($start + 1) . '</a></li>';
                 $url = str_replace('%offset%', $start, $link);
                 $links = str_replace('%url%', $url, $links);
             } else {
                 if ($start == $num_pages - 2) {
                     $links .= '<li class="skip">&#8230;</li>';
                 } else {
                     if ($start == $num_pages - 1) {
                         $links .= '<li><a href="%url%">' . ($start + 1) . '</a></li>';
                         $url = str_replace('%offset%', $start, $link);
                         $links = str_replace('%url%', $url, $links);
                     }
                 }
             }
             $page++;
             $start++;
         }
         // Adding the next link
         if ($offset + 1 >= $num_pages) {
             $links .= '<li class="nolink">%text_next%</li>';
         } else {
             $links .= '<li><a href="%url%">%text_next%</a></li>';
             $url = str_replace('%offset%', $offset + 1, $link);
             $links = str_replace('%url%', $url, $links);
         }
         $output = str_replace('%links%', $links, $output);
         $output = str_replace('%text_prev%', $text_prev, $output);
         $output = str_replace('%text_next%', $text_next, $output);
         return $output;
     }
 }
Beispiel #2
0
/**
 * Make a link to any given $tag.
 *
 * @param string $tag
 * @param string $template
 * @return string
 */
function tagLink($tag, $template = "")
{
    global $PIVOTX;
    $Current_weblog = $PIVOTX['weblogs']->getCurrent();
    $tag = normalizeTag($tag);
    $site_url = getDefault($PIVOTX['weblogs']->get($Current_weblog, 'site_url'), $PIVOTX['paths']['site_url']);
    if ($PIVOTX['config']->get('mod_rewrite') == 0) {
        $link = $site_url . "?t=" . urlencode($tag);
        if (paraWeblogNeeded($Current_weblog)) {
            $link .= "&amp;w=" . para_weblog($Current_weblog);
        }
        if ($template != "") {
            $link .= "&amp;t={$template}";
        }
    } else {
        $prefix = getDefault($PIVOTX['config']->get('localised_tag_prefix'), 'tag');
        $link = $site_url . makeURI($prefix) . '/' . urlencode($tag);
        if (paraWeblogNeeded($Current_weblog)) {
            $link .= "/" . para_weblog($Current_weblog);
        }
        if ($template != "") {
            $link .= "/?t={$template}";
        }
    }
    // Check if there's a hook set, and if so call it.
    if ($PIVOTX['extensions'] && $PIVOTX['extensions']->hasHook('make_link#tag')) {
        $PIVOTX['extensions']->executeHook('make_link#tag', $link, array('tag' => $tag, 'w' => $Current_weblog));
    }
    return $link;
}
/**
 * Makes a link to an Atom or RSS feed.
 *
 *
 * @param string $type
 * @param array $params
 * @return string
 */
function makeFeedLink($type = 'rss', $params = array())
{
    global $PIVOTX;
    // Check if we should override our own Feed with a value from the
    // weblog config..
    $override_link = $type == "rss" ? $PIVOTX['weblogs']->get('', 'rss_url') : $PIVOTX['weblogs']->get('', 'atom_url');
    if (!empty($override_link)) {
        return $override_link;
    } else {
        // Else we process as usual..
        $link = $PIVOTX['paths']['host'] . fixpath($PIVOTX['paths']['site_url']);
        // Check if it is a category feed or weblog/site feed
        if (isset($params['category'])) {
            $prefix = getDefault($PIVOTX['config']->get('localised_category_prefix'), "category");
            if ($PIVOTX['config']->get('mod_rewrite') > 0) {
                $link .= $prefix . '/' . $params['category'] . '/' . $type;
            } else {
                $link .= "index.php?feed=" . $type . '&amp;c=' . $params['category'];
            }
        } else {
            if ($PIVOTX['config']->get('mod_rewrite') > 0) {
                $link .= $type;
            } else {
                $link .= "index.php?feed=" . $type;
            }
        }
        // Check if it is a special content feed.
        if (isset($params['content'])) {
            if ($PIVOTX['config']->get('mod_rewrite') > 0) {
                $link .= '/' . $params['content'];
            } else {
                $link .= "&amp;content=" . $params['content'];
            }
        } else {
            // If we have more than one weblog, add the w=weblogname parameter
            $weblog = $PIVOTX['weblogs']->getCurrent();
            if (paraWeblogNeeded($weblog)) {
                if ($PIVOTX['config']->get('mod_rewrite') > 0) {
                    // we treat it as an extra 'folder'
                    $link .= "/" . $weblog;
                } else {
                    $link .= "&amp;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#feed')) {
            $PIVOTX['extensions']->executeHook('make_link#feed', $link, array('type' => $type, 'append' => $append, 'w' => $weblog));
        }
        return $link;
    }
}