Permalink
Browse files

Add server-side basic Item Database client in PHP

  • Loading branch information...
cubehouse committed Jun 28, 2013
1 parent fda4ad3 commit 16b246ce93d8325fecc437cc8df177dc1bb5c09b
Showing with 236 additions and 15 deletions.
  1. +213 −0 php/az4HTML.php
  2. +23 −15 php/az4db.php
View
@@ -0,0 +1,213 @@
+<?php
+$az4HTML_css_done = false;
+$az4HTML_memcache = false;
+
+function az4HTML_cache() {
+ global $az4HTML_memcache;
+
+ if (class_exists("Memcached")){
+ $az4HTML_memcache = new Memcached;
+ if (!$az4HTML_memcache->addServer('localhost', 11211)) $az4HTML_memcache = false;
+ }else{
+ $az4HTML_memcache = false;
+ }
+ return $az4HTML_memcache;
+}
+
+function az4HTML_getCache($key) {
+ $c = az4HTML_cache();
+ if ($c!=false) {
+ $dat = $c->get($key);
+ if (($dat)||($dat!="")) return json_decode($dat);
+ }
+ return false;
+}
+
+function az4HTML_getSettings() {
+ global $az4HTML_config;
+
+ if (isset($az4HTML_config)) return $az4HTML_config;
+
+ $az4HTML_config = az4HTML_getCache("db_settings");
+
+ if ($az4HTML_getCache != false) return $az4HTML_getCache;
+
+ $az4HTML_config = az4HTML_loadJSON("http://api.alphazone4.com/settings");
+
+ $c = az4HTML_cache();
+ if ($c) $c->set("db_settings", json_encode($az4HTML_config), 1800);
+
+ return $az4HTML_config;
+}
+
+function az4HTML_devname($dev) {
+ $settings = az4HTML_getSettings();
+
+ //return "";
+
+ if (!isset($settings->devs->{$dev})) return $dev;
+
+ return $settings->devs->{$dev};
+}
+
+function az4HTML_cat($cat) {
+ $data = az4HTML_loadJSON("http://api.alphazone4.com/get/cat/".$cat);
+
+ $h = az4HTML_css();
+
+ // TODO - az4Markup in PHP
+ if ($data->page) $h .= $data->page;
+
+ // breadcrumb
+ if (sizeof($data->breadcrumb) > 0) {
+ $cs = array();
+ foreach($data->breadcrumb as $crumb) {
+ $cs[] = "<a href='http://alphazone4.com/store/cat/".$crumb->id."'>".$crumb->name."</a>";
+ }
+ $h .= implode(" >>> ", $cs);
+ }
+
+ if ($data->cats && sizeof($data->cats) > 0) {
+ // list cats
+ $h .= "<ul class='thumbnails az4list'>";
+
+ foreach($data->cats as $cat) {
+ $h .= "<li>
+ <a href='http://alphazone4.com/store/cat/".$cat->id."' class='thumbnail'>
+ <div class='imgsml' style='width: 128px; height: 128px;'>
+ <img width='128' height='128' src='http://cdn.alphazone4.com/c/".$cat->image."' alt='".az4HTML_strip($cat->name)."' />
+ </div>
+ <p>".$cat->name."</p>
+ </a>
+ </li>";
+ }
+
+ $h .= "</ul>";
+ } else {
+ // list items
+ $h .= az4HTML_ListItems($data->items);
+ }
+
+ return $h;
+}
+
+function az4HTML_home() {
+ $h = "";
+
+ $config = az4HTML_getSettings();
+
+ $h .= az4HTML_updatelist("EU", "European", $config->euupdates);
+ $h .= az4HTML_updatelist("US", "American", $config->usupdates);
+ $h .= az4HTML_updatelist("JP", "Japanese", $config->jpupdates);
+ $h .= az4HTML_updatelist("HK", "Asian", $config->hkupdates);
+
+ $h .= "
+ <p>
+ <a href='http://alphazone4.com/store/cat/1'>European PlayStation Home Item Database</a><br />
+ <a href='http://alphazone4.com/store/cat/97'>European PlayStation Home Rewards and Free Items</a>
+ </p>
+ <p>
+ <a href='http://alphazone4.com/store/cat/110'>American PlayStation Home Item Database</a><br />
+ <a href='http://alphazone4.com/store/cat/358'>American PlayStation Home Rewards and Free Items</a>
+ </p>
+ <p>
+ <a href='http://alphazone4.com/store/cat/383'>Japanese PlayStation Home Item Database</a>
+ </p>
+ <p>
+ <a href='http://alphazone4.com/store/cat/286'>Asian PlayStation Home Item Database</a>
+ </p>
+ ";
+
+ return $h;
+}
+
+function az4HTML_updatelist($code, $name, $updates) {
+ $h = "Latest ".$name." (".$code.") PlayStation Home Updates";
+
+ $h .= "<ul>";
+ foreach($updates as $u) {
+ $h .= "<li><a href='http://alphazone4.com/store/update/".$u->id."'>European PlayStation Home Update ".$u->name."</a></li>";
+ }
+ $h .= "</ul>";
+
+ return $h;
+}
+
+function az4HTML_update($update) {
+ $data = az4HTML_loadJSON("http://api.alphazone4.com/get/update/".$update);
+
+ $h = "";
+
+ // breadcrumb
+ if (sizeof($data->breadcrumb) > 0) {
+ $cs = array();
+ foreach($data->breadcrumb as $crumb) {
+ $cs[] = "<a href='http://alphazone4.com/store/cat/".$crumb->id."'>".$crumb->name."</a>";
+ }
+ $h .= implode(" >>> ", $cs);
+ }
+
+ $h .= az4HTML_ListItems($data->items);
+
+ return $h;
+}
+
+function az4HTML_ListItems($items) {
+ if (sizeof($items) == 0) return "";
+
+ $h = "";
+
+ foreach($items as $i) {
+ $cats = "";
+ if (sizeof($i->categories) > 0) {
+ foreach($i->categories as $cat) {
+ $cats .= "[[" . $cat->zone . "]] - <a href='http://alphazone4.com/store/cat/".$cat->id."'>".$cat->name."</a><br />";
+ }
+ }
+
+ $updates = "";
+ if (sizeof($i->updates) > 0) {
+ foreach($i->updates as $region => $update) {
+ $updates .= "[[" . $region . "]] - <a href='http://alphazone4.com/store/update/".$update->id."'>".$update->name."</a><br />";
+ }
+ }
+
+ $h .= "<div style='clear:both'>
+ <ul class='thumbnails az4list' style='float: left'><li><a class='thumbnail'>
+ <div class='imgsml' style='width: 128px; height: 128px;'>
+ <img width='128' height='128' alt='PlayStation Home Item: ".az4HTML_strip($i->name)."' src='http://cdn.alphazone4.com/i/".$i->image."' />
+ </div>
+ <p>".$i->name."</p>
+ <p>Rating: ".$i->rating." out of 5 (".$i->votes." votes)</p>
+ </a></li></ul>
+ <strong>".$i->name.(($i->gender!="")?" (".(($i->gender == "M")?"M":"Fem")."ale)":"")."</strong>
+ <p>".$i->description."</p>
+ ".(($i->tutorial != "") ? "<p>Guide/Tutorial/Walkthrough: ".$i->tutorial."</p>" : "").
+ (($i->dev!="")? "<p>Developed by ".az4HTML_devname($i->dev)."</p>" :"")."
+ <p><strong>Available in</strong>:<br />".$cats."</p>
+ <p><strong>Released on</strong>:<br />".$updates."</p>
+ </div>";
+ }
+
+ return $h;
+}
+
+function az4HTML_strip($in) {
+ return str_replace("'", "\'", $in);
+}
+
+function az4HTML_css() {
+ global $az4HTML_css_done;
+
+ if ($az4HTML_css_done) return "";
+
+ $az4HTML_css_done = true;
+
+ return "<style type='text/css'>.az4HTML_list {list-style: none;} .az4HTML_list li {float: left}</style>";
+}
+
+function az4HTML_loadJSON($url) {
+ return json_decode(file_get_contents($url));
+}
+
+?>
View
@@ -13,7 +13,7 @@
Author URI: http://alphazone4.com
*/
-$az4dbwp_page = "database";
+$az4dbwp_page = "store";
// validate if this is a database URL
function az4db_isurl() {
@@ -128,6 +128,21 @@ function az4dbwp_render(){
";
}
+ // generate noscript version of page (very basic version)
+ $noscript = "";
+
+ if (substr($page, 0, 3) == "cat") {
+ require_once(dirname(__FILE__)."/az4HTML.php");
+ $noscript = az4HTML_cat(substr($page, 4));
+ }
+ else if (substr($page, 0, 6) == "update") {
+ require_once(dirname(__FILE__)."/az4HTML.php");
+ $noscript = az4HTML_update(substr($page, 7));
+ } else if ($page == "" || $page == "home" || $page == "/") {
+ require_once(dirname(__FILE__)."/az4HTML.php");
+ $noscript = az4HTML_home();
+ }
+
return <<< EOD
<script type='text/javascript'>
var do_load = true;
@@ -155,29 +170,20 @@ function getCookie(c_name)
{$pushtest}
</script>
<!--[if lte IE 8]>
-<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script>
-<script type="text/javascript">
-function update_browser() {
- CFInstall.check({
- mode: "overlay"
- });
-}
-window.attachEvent("onload", update_browser);
-</script>
<div class='az4db'>
<div class='alert alert-error'>
<strong>You are using an out-of-date browser.</strong>
<p>Internet Explorer 8 and below are no longer supported and are considered 'out-of-date' browsers. Not only that, they also account for less than 2% of our users.</p>
<p>Please upgrade to a newer version of Internet Explorer, of if you can't, you can do one of the following:</p>
<ul>
-<li><a href="http://www.google.com/chromeframe?quickenable=true" target="_blank">Add Google Frame to your browser (instantly makes Internet Explorer display more advanced websites) - even works in schools/offices!</a></li>
-<li><a href="http://www.google.co.uk/chrome" target="_blank">Try Google Chrome</a></li>
+<li><a href="http://www.google.co.uk/chrome/" target="_blank">Try Google Chrome</a></li>
<li><a href="http://www.mozilla.org/firefox/" target="_blank">Try Firefox</a></li>
</ul>
</div>
</div>
<![endif]-->
-<div id='database' class='az4db'>Loading the AlphaZone4 PlayStation Home Item Database...</div>
+<div id='database' class='az4db' style='display:none'>Loading the AlphaZone4 PlayStation Home Item Database...</div>
+<div id='disabled_js_friendly' class='az4db'>{$noscript}</div>
<link rel='stylesheet' type='text/css' href='//api.alphazone4.com/build/style.css' />
<script src='//api.alphazone4.com/build/az4db-jquery.js'></script><script type='text/javascript'>
var hash_page = "";
@@ -200,10 +206,12 @@ function update_browser() {
search = res[ 1 ];
}
}
-if (do_load) az4db_init({
+$("#disabled_js_friendly").hide();
+$("#database").show();
+if (do_load)az4db_init({
baseURL: "{$base}",
basePath: "/{$az4dbwp_page}",
- apiBase: "https://api.alphazone4.com",
+ apiBase: "http://api.alphazone4.com",
linkType: "html5"
});az4db_frame($("#database"),function(frame) {
if (getCookie("az4db_jump")) {

0 comments on commit 16b246c

Please sign in to comment.