This commit is contained in:
JoseluCross
2017-10-12 01:39:15 +02:00
parent 7c97ee47f0
commit 9b544784f3
2 changed files with 18 additions and 10 deletions

View File

@@ -97,13 +97,11 @@ class DB
* *
* @return mysqli_result the las 10 snippets hosted * @return mysqli_result the las 10 snippets hosted
*/ */
public function loadLast() public function loadLast($page = 0)
{ {
if (isset($_GET["o"])) $page=$page*10;
$first = $_GET["o"] * 10; $query = "SELECT IDC,Name,nick,Lang,Description,Code,Version FROM Users NATURAL JOIN Sources as S NATURAL JOIN Codes WHERE Version = (SELECT MAX(Version) FROM Sources WHERE S.Lang = Lang AND S.IDC = IDC) ORDER BY Modification DESC LIMIT $page, 10";
else //echo $query;
$first = 0;
$query = "SELECT IDC,Name,nick,Lang,Description,Code,Version FROM Users NATURAL JOIN Sources as S NATURAL JOIN Codes WHERE Version = (SELECT MAX(Version) FROM Sources WHERE S.Lang = Lang AND S.IDC = IDC) ORDER BY Modification DESC LIMIT $first, 10";
$code = dbw_query($this->conn, $query); $code = dbw_query($this->conn, $query);
return $code; return $code;
} }
@@ -216,7 +214,11 @@ class DB
$first = $array["o"] * 10; $first = $array["o"] * 10;
else else
$first = 0; $first = 0;
$queryLast = ") AND Version = (SELECT MAX(Version) FROM Sources WHERE S.Lang = Lang AND S.IDC = IDC)" . $this->search($array["search"]) . " ORDER BY Modification DESC LIMIT $first, 10"; if(array_key_exists("search",$array))
$search = $array("search");
else
$search = "";
$queryLast = ") AND Version = (SELECT MAX(Version) FROM Sources WHERE S.Lang = Lang AND S.IDC = IDC)" . $search . " ORDER BY Modification DESC LIMIT $first, 10";
//echo $query.$where.$queryLast; //echo $query.$where.$queryLast;
return dbw_query($this->conn, $query . $where . $queryLast); return dbw_query($this->conn, $query . $where . $queryLast);
} }

View File

@@ -107,16 +107,22 @@ function sendHTTPError($code){
echo $twig->render('error.twig',array("page" => $page, "path" => $path, "user" => $user,"error" => $error)); echo $twig->render('error.twig',array("page" => $page, "path" => $path, "user" => $user,"error" => $error));
} }
/**
* Index page
*
* @param bool $filter if filters are enabled (when ajax)
* @param bool $globalSearch if filters are in nav-bar search box
*/
function firstPage($filter=false,$globalSearch=false){ function firstPage($filter=false,$globalSearch=false){
global $supported,$twig,$path,$user; global $supported,$twig,$path,$user;
$db = new DB(); $db = new DB();
if(!$filter and !$globalSearch) if(!$filter and !$globalSearch) //Common index
if(isset($_GET["p"])) if(isset($_GET["p"])) //If page (not 0)
$query = $db->loadLast($_GET["p"]); $query = $db->loadLast($_GET["p"]);
else else
$query = $db->loadLast(); $query = $db->loadLast();
else else
$query = $db->loadFilter($_POST);; $query = $db->loadFilter($_POST);
$last = lastToArray($db,$query,$supported); $last = lastToArray($db,$query,$supported);
$page = array( $page = array(
"title" => "CodeShare", "title" => "CodeShare",