function Load() { $s = new BM_query("parties"); if ($this->letter=="#") $s->AddWhere(sprintf("name regexp '^[^a-z]'")); else $s->AddWhere(sprintf("name like '%s%%'",$this->letter)); $s->AddOrder("name"); $this->parties = $s->perform(); if ($this->parties) { $ids = array(); foreach($this->parties as $group) $ids[] = $group->id; $idstr = implode(",",$ids); $rows = SQLLib::selectRows(sprintf("SELECT count(*) as c, party, party_year FROM `prods` WHERE party in (%s) GROUP by party, party_year order by party_year",$idstr)); $this->partyyears = array(); foreach($rows as $row) if ($row->party) $this->partyyears[$row->party][$row->party_year] = $row->c; $rows = SQLLib::selectRows(sprintf("SELECT * FROM `partylinks` WHERE party in (%s)",$idstr)); $this->partylinks = array(); foreach($rows as $row) if ($row->party) $this->partylinks[$row->party][$row->year] = $row; } }
function LoadFromDB() { $this->partylinks = SQLLib::selectRow(sprintf("SELECT * FROM `partylinks` WHERE party = %d and year = %d",$this->party->id,$this->year)); $this->years = array(); $rows = SQLLib::selectRows(sprintf("SELECT party_year FROM prods WHERE party = %d GROUP BY party_year",$this->party->id)); foreach($rows as $v) $this->years[$v->party_year] = true; $rows = SQLLib::selectRows(sprintf("SELECT invitationyear FROM prods WHERE invitation = %d GROUP BY invitationyear",$this->party->id)); foreach($rows as $v) $this->years[$v->invitationyear] = true; ksort($this->years); }
<? require_once("bootstrap.inc.php"); header("Content-type: application/json; charset=utf-8"); $sql = new SQLSelect(); $sql->AddField("id"); $sql->AddField("nickname as name"); $sql->AddField("avatar"); $sql->AddField("glops"); $sql->AddTable("users"); $r = array(); if ($_POST["search"]) { $sql->AddWhere(sprintf_esc("nickname like '%%%s%%'",_like($_POST["search"]))); $sql->AddOrder(sprintf_esc("if(nickname='%s',1,2), nickname, lastLogin DESC",$_POST["search"])); $sql->SetLimit(10); $r = SQLLib::selectRows( $sql->GetQuery() ); } else if ($_POST["id"]) { $sql->AddWhere(sprintf_esc("id = %d",$_POST["id"])); $sql->SetLimit(1); $r = SQLLib::selectRows( $sql->GetQuery() ); } echo json_encode($r); ?>
function performWithCalcRows(&$count) { $objects = array(); $sql = $this->GetQuery(); $sql = preg_replace("/^SELECT/", "SELECT SQL_CALC_FOUND_ROWS ", $sql); $rows = SQLLib::selectRows($sql); foreach ($rows as $row) { $object = new stdClass(); $this->populate($object, $this->root, $row); foreach (get_object_vars($row) as $k => $v) { $object->{$k} = $v; } if ($this->root->class) { $class = $this->root->class; $field = $class::getPrimaryKey(); $objects[$object->{$field}] = $object; } else { $objects[] = $object; } } $row = SQLLib::selectRow("SELECT FOUND_ROWS() as f"); $count = (int) $row->f; return $objects; }
function LoadFromDB() { $this->prod = PouetProd::spawn( $this->id ); if(!$this->prod) return; if($this->prod->latestip != $_SERVER["REMOTE_ADDR"] && CheckReferrer($_SERVER["HTTP_REFERER"]) ) { SQLLib::Query(sprintf_esc("UPDATE prods SET views=views+1, latestip='%s' WHERE id=%d",$_SERVER["REMOTE_ADDR"],$this->id)); } $this->linkCheck = SQLLib::SelectRow(sprintf_esc("SELECT * FROM prods_linkcheck where prodID = %d",$this->id)); $a = array(&$this->prod); PouetCollectPlatforms( $a ); if ($this->prod->boardID) $this->board = SQLLib::SelectRow(sprintf_esc("SELECT * FROM boards WHERE id = %d",$this->prod->boardID)); $s = new BM_Query(); $s->AddField("added"); $s->AddTable("screenshots"); $s->SetLimit(1); $s->attach(array("screenshots"=>"user"),array("users as user"=>"id")); $s->AddWhere(sprintf_esc("prod=%d",$this->id)); list($this->screenshot) = $s->perform(); $s = new BM_Query(); $s->AddField("prodotherparty.party_compo"); $s->AddField("prodotherparty.party_place"); $s->AddField("prodotherparty.party_year"); $s->AddTable("prodotherparty"); $s->attach(array("prodotherparty"=>"party"),array("parties as party"=>"id")); $s->AddWhere(sprintf_esc("prod=%d",$this->id)); $rows = $s->perform(); foreach($rows as $row) { $this->prod->placings[] = new PouetPlacing( array("party"=>$row->party,"compo"=>$row->party_compo,"ranking"=>$row->party_place,"year"=>$row->party_year) ); } $s = new BM_Query(); $s->AddTable("affiliatedprods"); $s->AddField("affiliatedprods.type"); $s->attach(array("affiliatedprods"=>"original"),array("prods as prodOriginal"=>"id")); $s->attach(array("affiliatedprods"=>"derivative"),array("prods as prodDerivative"=>"id")); $s->AddWhere(sprintf_esc("affiliatedprods.original=%d or affiliatedprods.derivative=%d",$this->id,$this->id)); $this->relatedProds = $s->perform(); $s = new BM_Query(); $s->AddTable("users_cdcs"); $s->attach(array("users_cdcs"=>"user"),array("users as user"=>"id")); $s->AddWhere(sprintf_esc("cdc = %d",$this->id)); $cdcs = $s->perform(); $this->userCDCs = array(); foreach($cdcs as $v) $this->userCDCs[$v->user->id] = $v; $this->isPouetCDC = SQLLib::selectRow(sprintf_esc("select * from cdc where which = %d",$this->id)); $this->awards = SQLLib::selectRows(sprintf_esc("select * from sceneorgrecommended where prodid = %d order by type, category",$this->id)); $s = new BM_Query("credits"); $s->AddField("credits.role"); $s->AddWhere(sprintf("credits.prodID = %d",$this->id)); $s->Attach(array("credits"=>"userID"),array("users as user"=>"id")); $s->AddOrder("credits.role"); $this->credits = $s->perform(); $this->downloadLinks = array(); /* if ($this->prod->sceneorg) { $o = new stdClass(); $o->type = "scene.org"; $o->id = "sceneorgID"; $o->link = "http://scene.org/file.php?id=".(int)$this->prod->sceneorg; $this->downloadLinks[] = $o; } */ if ($this->prod->csdb) { $o = new stdClass(); $o->type = "csdb"; $o->id = "csdbID"; $o->link = "http://csdb.dk/release/?id=".(int)$this->prod->csdb; $this->downloadLinks[] = $o; } if ($this->prod->zxdemo) { $o = new stdClass(); $o->type = "zxdemo"; $o->id = "zxdemoID"; $o->link = "http://zxdemo.org/item.php?id=".(int)$this->prod->zxdemo; $this->downloadLinks[] = $o; } if ($this->prod->demozoo) { $o = new stdClass(); $o->type = "demozoo"; $o->id = "demozooID"; $o->link = "http://demozoo.org/productions/".(int)$this->prod->demozoo."/"; $this->downloadLinks[] = $o; } $this->downloadLinks = array_merge($this->downloadLinks,SQLLib::selectRows(sprintf_esc("select type, link from downloadlinks where prod = %d order by type",$this->id))); $this->screenshotPath = find_screenshot($this->prod->id); }
<? require_once("bootstrap.inc.php"); $r = SQLLib::selectRows(sprintf_esc("select name,type,party_year from prods where name like '%%%s%%' order by views desc limit 10",_like($_GET["what"]))); $res[0] = $_GET["what"]; foreach($r as $o) { $res[1][] = $o->name; $res[2][] = $o->type.($o->party_year?", ".$o->party_year:""); } header("Content-type: application/json; charset=utf-8"); echo json_encode($res); ?>
$PLATFORMS = handle_db_cache( POUET_ROOT_LOCAL . "/cache/enum-platforms.cache", function() { $rows = SQLLIB::selectRows("select * from platforms"); $platforms = array(); foreach($rows as $r) { $platforms[ $r->id ] = get_object_vars($r); unset($platforms[ $r->id ]["id"]); $platforms[ $r->id ]["slug"] = strtolower(preg_replace("/[^a-zA-Z0-9]+/","",$platforms[ $r->id ]["name"])); } ksort($platforms); return $platforms; }); global $COMPOTYPES; $COMPOTYPES = handle_db_cache( POUET_ROOT_LOCAL . "/cache/enum-compotypes.cache", function() { $rows = SQLLib::selectRows("select * from compotypes"); $compos = array(); foreach($rows as $v) $compos[$v->id] = $v->componame; ksort($compos); return $compos; }); $AFFILIATIONS_ORIGINAL = array( "remix" => "remixed in", "port" => "ported to", "final" => "final version", "pack" => "packed in", "related" => "related to", ); $AFFILIATIONS_INVERSE = array(
function PouetCollectAwards( &$prodArray ) { $ids = array(); foreach($prodArray as $v) if ($v->id) $ids[] = $v->id; if (!$ids) return; $rows = SQLLib::selectRows("select * from sceneorgrecommended where prodid in (".implode(",",$ids).") order by type, category"); foreach($prodArray as &$v) { foreach($rows as &$r) { if ($v->id == $r->prodid) { $v->awards[] = $r; unset($r); } } } foreach($prodArray as &$v) $v->cdc = 0; $rows = SQLLib::selectRows("select which from cdc where which in (".implode(",",$ids).")"); foreach($prodArray as &$v) { $v->cdc = 0; foreach($rows as &$r) { if ($v->id == $r->which) { $v->cdc++; } } } $rows = SQLLib::selectRows("select count(*) as c,cdc from users_cdcs where cdc in (".implode(",",$ids).") group by cdc"); foreach($prodArray as &$v) { foreach($rows as &$r) { if ($v->id == $r->cdc) { $v->cdc += $r->c; } } } }
function Load() { $s = new BM_query("groups"); if ($this->letter=="#") $s->AddWhere(sprintf("name regexp '^[^a-z]'")); else $s->AddWhere(sprintf("name like '%s%%'",$this->letter)); $s->AddOrder("name"); $this->groups = $s->perform(); if ($this->groups) { $ids = array(); foreach($this->groups as $group) $ids[] = $group->id; $idstr = implode(",",$ids); for ($x = 1; $x <= 3; $x++) { $counts = SQLLib::selectRows(sprintf("select group".$x." as groupID, count(*) as c from prods where group".$x." in (%s) group by group".$x."",$idstr)); foreach($counts as $count) { $this->prods[$count->groupID] += $count->c; } } } }