public function test_private_list() { global $db; $db->do_query('select idUsers from User LIMIT 1'); $uid = Null; while ($arr = $db->get_row_array()) { $uid = $arr['idUsers']; } $projects = EcProject::getUserProjects($uid); $this->assertInternalType('array', $projects); for ($i = 0; $i < count($projects); $i++) { $this->assertInternalType('array', $projects[$i]); $this->assertTrue(array_key_exists('name', $projects[$i])); $this->assertInternalType('string', $projects[0]['name']); $this->assertTrue(array_key_exists('ttl', $projects[$i])); $this->assertTrue(array_key_exists('ttl24', $projects[$i])); $this->assertTrue(array_key_exists('listed', $projects[$i])); $this->assertRegexp('/public|private/', $projects[$i]['listed']); //$this->assertInternalType('int', $projects[0]['ttl']); //$this->assertInternalType('int', $projects[0]['ttl24']); } }
function siteHome() { header("Cache-Control: no-cache, must-revalidate"); global $SITE_ROOT, $db, $log, $auth; $vals = array(); $server = trim($_SERVER["HTTP_HOST"], "/"); $root = trim($SITE_ROOT, "/"); //if($_SERVER["HTTPS"] == 'on'){ header(sprintf('location: http://%s%s ', $server, $root));} if (!$db->connected) { $rurl = "http://{$server}/{$root}/test?redir=true"; header("location: {$rurl}"); return; } $res = $db->do_query("SELECT name, ttl, ttl24 FROM (SELECT name, count(entry.idEntry) as ttl, x.ttl as ttl24 FROM project left join entry on project.name = entry.projectName left join (select count(idEntry) as ttl, projectName from entry where created > ((UNIX_TIMESTAMP() - 86400)*1000) group by projectName) x on project.name = x.projectName Where project.isListed = 1 group by project.name) a order by ttl desc LIMIT 10"); if ($res !== true) { //$vals["projects"] = "<p class=\"error\">Database is not set up correctly, go to the <a href=\"test\">test page</a> to establish the problem.</p>"; //echo applyTemplate("base.html","./index.html",$vals); $rurl = "http://{$server}/{$root}/test?redir=true"; header("location: {$rurl}"); return; } $vals["projects"] = "<div class=\"ecplus-projectlist\"><h1>Most popular projects on this server</h1>"; $i = 0; while ($row = $db->get_row_array()) { $vals["projects"] .= "<div class=\"project\"><a href=\"{#SITE_ROOT#}/{$row["name"]}\">{$row["name"]}</a><div class=\"total\">{$row["ttl"]} entries with <b>" . ($row["ttl24"] ? $row["ttl24"] : "0") . "</b> in the last 24 hours </div></div>"; $i++; } if ($i == 0) { $vals["projects"] = "<p>No projects exist on this server, <a href=\"createProject.html\">create a new project</a></p>"; } else { $vals["projects"] .= "</div>"; } if ($auth->isLoggedIn()) { $vals['userprojects'] = '<div class="ecplus-userprojects"><h1>My Projects</h1>'; $prjs = EcProject::getUserProjects($auth->getEcUserId()); $count = count($prjs); for ($i = 0; $i < $count; $i++) { $vals['userprojects'] .= "<div class=\"project\"><a href=\"{#SITE_ROOT#}/{$prjs[$i]["name"]}\">{$prjs[$i]["name"]}</a><div class=\"total\">{$prjs[$i]["ttl"]} entries with <b>" . ($prjs[$i]["ttl24"] ? $prjs[$i]["ttl24"] : "0") . "</b> in the last 24 hours </div></div>"; } $vals['userprojects'] .= '</div>'; } echo applyTemplate("base.html", "index.html", $vals); }