less errors

This commit is contained in:
Daku 2012-03-12 08:10:36 +00:00
parent 60666f9300
commit 45365f7eb5

View file

@ -97,31 +97,34 @@ class ShimmieApi extends Extension {
if($event->page_matches("api/shimmie/get_user")) { if($event->page_matches("api/shimmie/get_user")) {
$query = $user->id; $query = $user->id;
$type = "id";
if($event->count_args() == 1) { if($event->count_args() == 1) {
$query = $event->get_arg(0); $query = $event->get_arg(0);
} }
if(isset($_GET['name'])) { elseif(isset($_GET['id'])) {
$query = $_GET['name'];
}
if(isset($_GET['id'])) {
$query = $_GET['id']; $query = $_GET['id'];
} }
elseif(isset($_GET['name'])) {
$query = $_GET['name'];
$type = "name";
}
$all = $database->get_row( $all = $database->get_row(
"SELECT id,name,joindate,class FROM users WHERE name=? OR id=?", "SELECT id,name,joindate,class FROM users WHERE ".$type."=?",
array($_GET['name'], int_escape($_GET['id']))); array($query));
//FIXME?: For some weird reason, get_all seems to return twice. Unsetting second value to make things look nice.. if(!empty($all)){
// - it returns data as eg array(0=>1234, 'id'=>1234, 1=>'bob', 'name'=>bob, ...); //FIXME?: For some weird reason, get_all seems to return twice. Unsetting second value to make things look nice..
for($i=0; $i<4; $i++) unset($all[$i]); // - it returns data as eg array(0=>1234, 'id'=>1234, 1=>'bob', 'name'=>bob, ...);
$all['uploadcount'] = Image::count_images(array("user_id=".$all['id'])); for($i=0; $i<4; $i++) unset($all[$i]);
$all['uploadperday'] = sprintf("%.1f", ($all['uploadcount'] / (((time() - strtotime($all['joindate'])) / 86400) + 1))); $all['uploadcount'] = Image::count_images(array("user_id=".$all['id']));
$all['commentcount'] = $database->get_one( $all['uploadperday'] = sprintf("%.1f", ($all['uploadcount'] / (((time() - strtotime($all['joindate'])) / 86400) + 1)));
"SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id", $all['commentcount'] = $database->get_one(
array("owner_id"=>$all['id'])); "SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id",
$all['commentperday'] = sprintf("%.1f", ($all['commentcount'] / (((time() - strtotime($all['joindate'])) / 86400) + 1))); array("owner_id"=>$all['id']));
$all['commentperday'] = sprintf("%.1f", ($all['commentcount'] / (((time() - strtotime($all['joindate'])) / 86400) + 1)));
if(isset($_GET['recent'])){ if(isset($_GET['recent'])){
$recent = $database->get_all( $recent = $database->get_all(
"SELECT * FROM images WHERE owner_id=? ORDER BY id DESC LIMIT 0, 5", "SELECT * FROM images WHERE owner_id=? ORDER BY id DESC LIMIT 0, 5",
array($all['id'])); array($all['id']));
@ -138,6 +141,7 @@ class ShimmieApi extends Extension {
unset($all['recentposts'][$i]['notes']); unset($all['recentposts'][$i]['notes']);
$i += 1; $i += 1;
} }
}
} }
$page->set_data(json_encode($all)); $page->set_data(json_encode($all));
} }