Exemplo n.º 1
0
/**
 * Get Tags that are related to a certain Tag
 *
 * @param string $tag
 * @return unknown
 */
function getRelatedTags($tag)
{
    global $PIVOTX, $paths;
    if ($PIVOTX['config']->get('db_model') == "flat") {
        // Getting related tags for flat files..
        $filename = urlencode($tag) . '.rel';
        if (file_exists($PIVOTX['paths']['db_path'] . "tagdata/{$filename}")) {
            $sTagString = file_get_contents($PIVOTX['paths']['db_path'] . "tagdata/{$filename}", "r");
            $taglist = explode(",", $sTagString);
        }
    } else {
        // Getting tags for SQL
        $tagtable = safeString($PIVOTX['config']->get('db_prefix') . "tags", true);
        // [JAN]
        // 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'));
        // Get a DB connection..
        $sql = $sqlFactory->getSqlInstance();
        //        $sql = new sql('mysql',
        //$PIVOTX['config']->get('db_databasename'),
        //                $PIVOTX['config']->get('db_hostname'),
        //                $PIVOTX['config']->get('db_username'),
        //                $PIVOTX['config']->get('db_password')
        //            );
        // [/JAN]
        // Getting related tags for MySQL db..
        $sql->query("SELECT DISTINCT(t2.tag)\n                    FROM {$tagtable} AS t1, {$tagtable} AS t2\n                    WHERE (t1.tag=" . $sql->quote($tag) . " AND t1.target_uid=t2.target_uid AND t2.tag!=" . $sql->quote($tag) . ")\n                    ORDER BY t2.tag ASC");
        $rows = $sql->fetch_all_rows();
        $taglist = makeValuepairs($rows, '', 'tag');
    }
    if (is_array($taglist)) {
        $output = array();
        foreach ($taglist as $thistag) {
            $output[] = "<a href=\"" . tagLink(str_replace(" ", "+", $thistag)) . "\" class=\"taglinkext\">{$thistag}</a>";
        }
        $output = implode(", \n", $output);
    } else {
        $output .= "\n<p>" . __('No related tags') . "</p>\n";
    }
    return $output;
}
Exemplo n.º 2
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;
     }
 }