/** * * * @param unknown $params * @param unknown $bBlog (reference) */ function smarty_function_nextprev($params, &$bBlog) { // Initialize default values... $skip = 0; $num = 20; $max_pages = 0; $pages_before = 0; // Set the num parameter if (is_numeric($params['num'])) { $num = $params['num']; } // Set the max_pages parameter if (is_numeric($params['max_pages'])) { $max_pages = $params['max_pages']; $pages_before = (int) ($max_pages / 2); } // Acquire the page skip count; if set, snag it. $newSkip = $_GET["pageskip"]; if ($newSkip) { $skip = $newSkip; } $sectionid = $_GET["sectionid"]; $QuerySection = ''; $ExtraParams = ''; if ($sectionid) { $QuerySection .= " AND sections like '%:{$sectionid}:%'"; $ExtraParams .= "§ionid={$sectionid}"; } else { // This is for the case of Clean URLS $sectionid = $bBlog->get_template_vars("sectionid"); if ($sectionid) { $QuerySection .= " AND sections like '%:{$sectionid}:%'"; } } $query_params = $params['query']; if ($query_params) { $QuerySection .= " AND {$query_params}"; } $link_params = $params['link']; if ($link_params) { $ExtraParams .= $link_params; } $posts = $params['posts']; // Calculate the new offset $offset = $skip * $num; $nextoffset = $offset + $num; $bBlog->assign("current_offset", $offset); // Get number of entries... if ($posts) { $entryCount = count($posts); if ($params['adjust']) { $bBlog->assign('posts', array_slice($posts, $offset, $num)); } } else { // invariant: Need to query the database and count $countArray = $bBlog->get_results("select count(*) as nElements from " . T_POSTS . " where status = 'live' {$QuerySection};"); if ($bBlog->num_rows <= 0) { $entryCount = 0; } else { foreach ($countArray as $cnt) { $entryCount = $cnt->nElements; } } } // Create the previous pages... $i = 0; $current_page = $skip; if ($max_pages != 0) { $i = $current_page - $pages_before; if ($i < 0) { $i = 0; } } $bBlog->assign("current_page", $current_page + 1); $bBlog->assign("gofirstpage", $i + 1); while ($i < $current_page) { $cp = $i + 1; $prevpages[] = array('page' => $cp, 'url' => $_SERVER["PHP_SELF"] . "?pageskip={$i}{$ExtraParams}"); ++$i; } $bBlog->assign("goprevpages", $prevpages); // Create the next pages $i = $current_page + 1; $numberOfPages = (int) ($entryCount / $num); $pages = $numberOfPages; if ($pages * $num < $entryCount) { $pages++; $numberOfPages++; } if ($max_pages != 0) { $pages = $i + $pages_before; if ($pages > $numberOfPages) { $pages = $numberOfPages; } } $bBlog->assign("golastpage", $pages); $bBlog->assign("gonum_pages", $numberOfPages); while ($i < $pages) { $nextpages[] = array('page' => $i + 1, 'url' => $_SERVER["PHP_SELF"] . "?pageskip={$i}{$ExtraParams}"); ++$i; } $bBlog->assign("gonextpages", $nextpages); // Get the previous count... if ($offset == 0) { $previous = 0; $bBlog->assign("goprev", ""); } else { $previous = $skip - 1; $bBlog->assign("goprev", $_SERVER["PHP_SELF"] . "?pageskip={$previous}{$ExtraParams}"); } // Get the next count... if ($nextoffset < $entryCount) { $next = $skip + 1; $bBlog->assign("gonext", $_SERVER["PHP_SELF"] . "?pageskip={$next}{$ExtraParams}"); } else { $next = 0; $bBlog->assign("gonext", ""); } }
/** * * * @param unknown $params * @param unknown $bBlog (reference) * @return unknown */ function smarty_function_links($params, &$bBlog) { $markedlinks = ''; if (!isset($params['sep'])) { $sep = "<br />"; } else { $sep = $params['sep']; } if (isset($params['presep'])) { $presep = $params['presep']; } // use this for lists if (isset($params['desc'])) { $asde = "DESC"; } else { $asde = ""; } if (isset($params['ord'])) { $order = $params['ord']; } else { $order = "position"; } if (isset($params['num'])) { $max = $params['num']; } else { $max = "20"; } if (isset($params['cat'])) { $cat = $bBlog->get_var("select categoryid from " . T_CATEGORIES . " where name='" . $params['cat'] . "'"); } if (isset($params['notcat'])) { $notcat = $bBlog->get_var("select categoryid from " . T_CATEGORIES . " where name='" . $params['notcat'] . "'"); } if ($cat) { $links = $bBlog->get_results("select * from " . T_LINKS . " where category='" . $cat . "' order by " . $order . " " . $asde . " limit " . $max); } elseif ($notcat) { $links = $bBlog->get_results("select * from " . T_LINKS . " where category !='" . $notcat . "' order by " . $order . " " . $asde . " limit " . $max); } else { $links = $bBlog->get_results("select * from " . T_LINKS . " order by " . $order . " " . $asde . " limit " . $max); } if (!empty($links)) { foreach ($links as $link) { $url = $link->url; $nicename = $link->nicename; $markedlinks .= $presep . '<a href="' . $url . '">' . $nicename . '</a>' . $sep; } } return $markedlinks; }
/** * * * @param unknown $bBlog (reference) */ function populateSelectList(&$bBlog) { $posts_with_comments_q = "SELECT " . T_POSTS . ".postid, " . T_POSTS . ".title, count(*) c FROM " . T_COMMENTS . ", " . T_POSTS . " \tWHERE " . T_POSTS . ".postid = " . T_COMMENTS . ".postid GROUP BY " . T_POSTS . ".postid ORDER BY " . T_POSTS . ".posttime DESC "; // previously function populateSelectList(&$bBlog){ // $posts_with_comments_q = "SELECT ".T_POSTS.".postid, ".T_POSTS.".title, count(*) c FROM ".T_COMMENTS.", ".T_POSTS." WHERE ".T_POSTS.".postid = ".T_COMMENTS.".postid GROUP BY ".T_POSTS.".postid ORDER BY ".T_POSTS.".posttime DESC LIMIT 0 , 30 "; //removed the LIMIT parameter as it was unnecessary $posts_with_comments = $bBlog->get_results($posts_with_comments_q, ARRAY_A); $bBlog->assign("postselect", $posts_with_comments); }
/** * * * @param unknown $bBlog (reference) */ function admin_plugin_links_run(&$bBlog) { if (isset($_GET['linkdo'])) { $linkdo = $_GET['linkdo']; } elseif (isset($_POST['linkdo'])) { $linkdo = $_POST['linkdo']; } else { $linkdo = ''; } switch ($linkdo) { case "New": // add new link $maxposition = $bBlog->get_var("select position from " . T_LINKS . " order by position desc limit 0,1"); $position = $maxposition + 10; $bBlog->query("insert into " . T_LINKS . "\n set nicename='" . my_addslashes($_POST['nicename']) . "',\n url='" . my_addslashes($_POST['url']) . "',\n category='" . my_addslashes($_POST['category']) . "',\n\t position='{$position}'"); break; case "Delete": // delete link $bBlog->query("delete from " . T_LINKS . " where linkid=" . $_POST['linkid']); break; case "Save": // update an existing link $bBlog->query("update " . T_LINKS . "\n set nicename='" . my_addslashes($_POST['nicename']) . "',\n url='" . my_addslashes($_POST['url']) . "',\n category='" . my_addslashes($_POST['category']) . "'\n where linkid=" . $_POST['linkid']); break; case "Up": $bBlog->query("update " . T_LINKS . " set position=position-15 where linkid=" . $_POST['linkid']); reorder_links(); break; case "Down": $bBlog->query("update " . T_LINKS . " set position=position+15 where linkid=" . $_POST['linkid']); reorder_links(); break; default: // show form break; } if (isset($_GET['catdo'])) { $catdo = $_GET['catdo']; } elseif (isset($_POST['catdo'])) { $catdo = $_POST['catdo']; } else { $catdo = ''; } switch ($catdo) { case "New": // add new category $bBlog->query("insert into " . T_CATEGORIES . "\n set name='" . my_addslashes($_POST['name']) . "'"); break; case "Delete": // delete category // have to remove all references to the category in the links $bBlog->query("update " . T_LINKS . "\n set linkid=0 where linkid=" . $_POST['categoryid']); // delete the category $bBlog->query("delete from " . T_CATEGORIES . " where categoryid=" . $_POST['categoryid']); break; case "Save": // update an existing category $bBlog->query("update " . T_CATEGORIES . "\n set name='" . my_addslashes($_POST['name']) . "'\n where categoryid=" . $_POST['categoryid']); break; default: // show form break; } $bBlog->assign('ecategories', $bBlog->get_results("select * from " . T_CATEGORIES)); $bBlog->assign('elinks', $bBlog->get_results("select * from " . T_LINKS . " order by position")); }