diff --git a/include/Controller.php b/include/Controller.php index 42aa86a3..cff0a748 100644 --- a/include/Controller.php +++ b/include/Controller.php @@ -6,178 +6,188 @@ require_once('Models/MenuModel.php'); * as specified in config.inc. Should be subclassed by all webpages so they can * take advantage of Smarty. */ -class Controller { - private $_smarty; - private $_template; - private $_title; - private $_css_files; - private $_js_files; - private $_show_intro; - private $_content_title; - private $_content; +class Controller +{ + private $_smarty; + private $_template; + private $_title; + private $_css_files; + private $_js_files; + private $_show_intro; + private $_content_title; + private $_content; - /** - * Constructor that will create a Smarty object and configure it according - * to what's been specified in config.inc. - */ - public function __construct() { - /* Create a Smarty object. */ - $this->_smarty = new Smarty(); + /** + * Constructor that will create a Smarty object and configure it according + * to what's been specified in config.inc. + */ + public function __construct() + { + /* Create a Smarty object. */ + $this->_smarty = new Smarty(); - # Stick it globally so we could refer the translations - global $Smarty; - $Smarty = $this->_smarty; + # Stick it globally so we could refer the translations + global $Smarty; + $Smarty = $this->_smarty; - global $lang; - global $available_languages; + global $lang; + global $available_languages; - /* Configure smarty. */ - $this->_smarty->compile_dir = SMARTY_DIR_COMPILE; - $this->_smarty->cache_dir = SMARTY_DIR_CACHE; - $this->_smarty->config_dir = SMARTY_DIR_CONFIG; - $this->_smarty->caching = SMARTY_CACHING_ENABLE; - $this->_smarty->cache_lifetime = SMARTY_CACHING_LIFETIME; - $this->_smarty->compile_check = SMARTY_CACHING_COMPILE_CHECK; - $this->_smarty->force_compile = SMARTY_CACHING_FORCE_RECHECK; - $this->_smarty->template_dir = array("templates_$lang", 'templates'); - $this->_smarty->compile_id = $lang; - $this->_smarty->config_dir = "."; + /* Configure smarty. */ + $this->_smarty->compile_dir = SMARTY_DIR_COMPILE; + $this->_smarty->cache_dir = SMARTY_DIR_CACHE; + $this->_smarty->config_dir = SMARTY_DIR_CONFIG; + $this->_smarty->caching = SMARTY_CACHING_ENABLE; + $this->_smarty->cache_lifetime = SMARTY_CACHING_LIFETIME; + $this->_smarty->compile_check = SMARTY_CACHING_COMPILE_CHECK; + $this->_smarty->force_compile = SMARTY_CACHING_FORCE_RECHECK; + $this->_smarty->template_dir = array("templates_$lang", 'templates'); + $this->_smarty->compile_id = $lang; + $this->_smarty->config_dir = "."; - # First we read English, so all defaults are there - $this->_smarty->configLoad(DIR_LANG . "/lang.en.ini"); + # First we read English, so all defaults are there + $this->_smarty->configLoad(DIR_LANG . "/lang.en.ini"); - # Now we try to read translations - if (is_file(($fname = DIR_LANG . "/lang.$lang.ini")) - && is_readable($fname)) { - $this->_smarty->configLoad($fname); - } + # Now we try to read translations + if (is_file(($fname = DIR_LANG . "/lang.$lang.ini")) + && is_readable($fname)) { + $this->_smarty->configLoad($fname); + } - setlocale(LC_TIME, $Smarty->getConfigVars('locale')); + setlocale(LC_TIME, $Smarty->getConfigVars('locale')); - /** - * Add a output-filter to make sure ampersands are properly encoded to - * HTML-entities. - */ - $this->_smarty->registerFilter('output', array($this, 'outputFilter')); + /** + * Add a output-filter to make sure ampersands are properly encoded to + * HTML-entities. + */ + $this->_smarty->registerFilter('output', array($this, 'outputFilter')); - /* Give Smarty-template access to date(). */ - $this->_smarty->registerPlugin('modifier', 'date_f', array(&$this, 'date_f')); - $this->_smarty->registerPlugin('modifier', 'date_localized', array(&$this, 'date_localized')); + /* Give Smarty-template access to date(). */ + $this->_smarty->registerPlugin('modifier', 'date_f', array(&$this, 'date_f')); + $this->_smarty->registerPlugin('modifier', 'date_localized', array(&$this, 'date_localized')); - /* Give Smarty-templates access to the ampersandEntity() function. */ - $this->_smarty->registerPlugin( - 'modifier', - 'escapeAmpersand', - array(&$this, 'ampersandEntity') - ); + /* Give Smarty-templates access to the ampersandEntity() function. */ + $this->_smarty->registerPlugin( + 'modifier', + 'escapeAmpersand', + array(&$this, 'ampersandEntity') + ); - $this->_title = ''; - $this->_css_files = array(); - $this->_js_files = array(); - $this->_show_intro = false; - $this->_content_title = ''; - $this->_content = ''; + $this->_title = ''; + $this->_css_files = array(); + $this->_js_files = array(); + $this->_show_intro = false; + $this->_content_title = ''; + $this->_content = ''; - /* The menus have caused an exception, need to skip them. */ - if (!ExceptionHandler::skipMenus()) { - $menus = MenuModel::getAllMenus(); - } + /* The menus have caused an exception, need to skip them. */ + if (!ExceptionHandler::skipMenus()) { + $menus = MenuModel::getAllMenus(); + } - # Construct lang URL - $pageurl = preg_replace('/\?lang=[a-z]*$/', '', $_SERVER['REQUEST_URI']); + # Construct lang URL + $pageurl = preg_replace('/\?lang=[a-z]*$/', '', $_SERVER['REQUEST_URI']); - /* Set up the common variables before displaying. */ - $vars = array( - 'release' => RELEASE, - 'baseurl' => URL_BASE, - 'heroes_num' => HEROES_NUM, - 'menus' => $menus, - 'pageurl' => $pageurl, - 'available_languages' => $available_languages, - ); - $this->_smarty->assign($vars); - } + /* Set up the common variables before displaying. */ + $vars = array( + 'release' => RELEASE, + 'baseurl' => URL_BASE, + 'heroes_num' => HEROES_NUM, + 'menus' => $menus, + 'pageurl' => $pageurl, + 'available_languages' => $available_languages, + ); + $this->_smarty->assign($vars); + } - /** Smarty outputfilter, run just before displaying. */ - public function outputFilter($string, $smarty) { - /* Properly encode all ampersands as "&". */ - $string = preg_replace('/&(?!([a-z]+|(#\d+));)/i', '&', $string); - /* Replace weird characters that appears in some of the data. */ - return $string; - } + /** Smarty outputfilter, run just before displaying. */ + public function outputFilter($string, $smarty) + { + /* Properly encode all ampersands as "&". */ + $string = preg_replace('/&(?!([a-z]+|(#\d+));)/i', '&', $string); + /* Replace weird characters that appears in some of the data. */ + return $string; + } - /** Escape ampersands to the HTML-entitiy '&'. */ - static public function ampersandEntity($string) { - //return preg_replace('/&(?!amp|nbsp|lt|gt|quot;)/', '&', $string); - //return preg_replace('/&(?![a-z];|#[0-9];)/', '&', $string); - return $string; - } + /** Escape ampersands to the HTML-entitiy '&'. */ + public static function ampersandEntity($string) + { + //return preg_replace('/&(?!amp|nbsp|lt|gt|quot;)/', '&', $string); + //return preg_replace('/&(?![a-z];|#[0-9];)/', '&', $string); + return $string; + } - /** Formating of dates, registered as a modifier for Smarty templates. */ - public function date_f($timestamp, $format) { - return date($format, $timestamp); - } + /** Formating of dates, registered as a modifier for Smarty templates. */ + public function date_f($timestamp, $format) + { + return date($format, $timestamp); + } - /** Formating of dateAs, registered as a modifier for Smarty templates. */ - public function date_localized($timestamp, $format) { - if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { - $format = preg_replace('#(? $this->_css_files, - 'js_files' => $this->_js_files, - 'content' => $content, - ); - $this->_smarty->assign($vars); - return $this->_smarty->display('pages/index.tpl'); - } + /* Render the HTML using the template and any set variables and displays it. */ + public function display($content) + { + if (!is_string($content) || strlen($content) == 0) { + } + $vars = array( + 'css_files' => $this->_css_files, + 'js_files' => $this->_js_files, + 'content' => $content, + ); + $this->_smarty->assign($vars); + return $this->_smarty->display('pages/index.tpl'); + } - /* Render the HTML using the template and any set variables and returns it. */ - public function fetch($template, $vars=Null) { - if (!is_file(SMARTY_DIR_TEMPLATE . "/{$template}")) { - } - if (!is_null($vars)) { - $this->_smarty->assign($vars); - } - return $this->_smarty->fetch($template); - } + /* Render the HTML using the template and any set variables and returns it. */ + public function fetch($template, $vars = null) + { + if (!is_file(SMARTY_DIR_TEMPLATE . "/{$template}")) { + } + if (!is_null($vars)) { + $this->_smarty->assign($vars); + } + return $this->_smarty->fetch($template); + } - /* Set up the variables used by the template and render the page. */ - public function renderPage($vars, $template) { - if (!is_string($template)) { - } - return $this->display($this->fetch($template, $vars)); - } + /* Set up the variables used by the template and render the page. */ + public function renderPage($vars, $template) + { + if (!is_string($template)) { + } + return $this->display($this->fetch($template, $vars)); + } - /* Assign extra CSS files needed by the different pages/templates. */ - public function addCSSFiles($extra_css) { - if (is_array($extra_css)) { - $this->_css_files = array_merge( - $this->_css_files, - $extra_css - ); - } else if (is_string($extra_css) && strlen($extra_css) > 0) { - $this->_css_files[] = $extra_css; - } - } + /* Assign extra CSS files needed by the different pages/templates. */ + public function addCSSFiles($extra_css) + { + if (is_array($extra_css)) { + $this->_css_files = array_merge( + $this->_css_files, + $extra_css + ); + } elseif (is_string($extra_css) && strlen($extra_css) > 0) { + $this->_css_files[] = $extra_css; + } + } - /* Assign javascripts files needed by the different pages/templates. */ - public function addJSFiles($extra_js) { - if (is_array($extra_js)) { - $this->_js_files = array_merge( - $this->_js_files, - $extra_js - ); - } else if (is_string($extra_js) && strlen($extra_js) > 0) { - $this->_js_files[] = $extra_js; - } - } + /* Assign javascripts files needed by the different pages/templates. */ + public function addJSFiles($extra_js) + { + if (is_array($extra_js)) { + $this->_js_files = array_merge( + $this->_js_files, + $extra_js + ); + } elseif (is_string($extra_js) && strlen($extra_js) > 0) { + $this->_js_files[] = $extra_js; + } + } } -?> diff --git a/include/ExceptionHandler.php b/include/ExceptionHandler.php index 08e9dcaa..816762b9 100644 --- a/include/ExceptionHandler.php +++ b/include/ExceptionHandler.php @@ -1,36 +1,38 @@ getFile() == 'MenuModel.php')) { - $skip_menus = true; - } else { - foreach ($e->getTrace() as $t) { - if (basename($t['file']) == 'MenuModel.php') { - $skip_menus = true; - break; - } - } - } - } - - return $skip_menus; - } - - /* Handle exceptions. */ - static public function handleException(Exception $e) { - self::$_exception = $e; + if (!is_null($e)) { + if (basename($e->getFile() == 'MenuModel.php')) { + $skip_menus = true; + } else { + foreach ($e->getTrace() as $t) { + if (basename($t['file']) == 'MenuModel.php') { + $skip_menus = true; + break; + } + } + } + } + + return $skip_menus; + } + + /* Handle exceptions. */ + public static function handleException(Exception $e) + { + self::$_exception = $e; - require_once('Pages/ExceptionsPage.php'); - $ep = new ExceptionsPage(); - return $ep->index($e); - } + require_once('Pages/ExceptionsPage.php'); + $ep = new ExceptionsPage(); + return $ep->index($e); + } } -?> \ No newline at end of file diff --git a/include/I18N.php b/include/I18N.php index 9ac48ffa..bbb4c83f 100644 --- a/include/I18N.php +++ b/include/I18N.php @@ -6,91 +6,93 @@ require_once('Objects/News.php'); require_once('Models/NewsModel.php'); define('DIR_NEWS', 'data/news'); -class I18N { +class I18N +{ - public function __construct() { - $config = HTMLPurifier_Config::createDefault(); - $this->_purifier = new HTMLPurifier($config); + public function __construct() + { + $config = HTMLPurifier_Config::createDefault(); + $this->_purifier = new HTMLPurifier($config); - $langs = ['en', 'it', 'fr', 'ru', 'de']; - foreach ($langs as $key => $value) { - $this->convertLanguageJsonToSmartyIni('lang.' . $value); - $this->updateNewsI18n($value); - } - } - - private function convertLanguageJsonToSmartyIni($lang) { - $filename = "lang/i18n/{$lang}.json"; - echo("Converting {$filename} from JSON to INI\n"); - $jsonString = file_get_contents($filename); - $json = json_decode($jsonString); - - $output = ""; - foreach ($json as $key => $value) { - $output .= $key . " = " . $this->_purifier->purify( $value ). "\n"; - } - - file_put_contents("lang/{$lang}.ini", $output); - - } - - private function updateNewsI18n($lang) { - - // For non-english, create/overwrite JSON files from our i18n file - if ($lang != 'en') { - echo("Converting " . DIR_NEWS . "/i18n/news.{$lang}.json to individual JSON files\n"); - $i18n = json_decode(file_get_contents(DIR_NEWS . "/i18n/news.{$lang}.json")); - - foreach ($i18n as $key => $value) { - $originalJson = json_decode(file_get_contents(DIR_NEWS . "/{$key}.json")); - $value->date = $this->_purifier->purify( $originalJson->date ); - $value->author = $this->_purifier->purify( $originalJson->author ); - $value->title = $this->_purifier->purify( $value->title ); - $value->content = $this->_purifier->purify( $value->content ); - - file_put_contents(DIR_NEWS . "/{$lang}/{$key}.json", json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); - } - } - else { - // Update the base english i18n file - echo("Converting individual JSON files to I18N base file\n"); - $newsJson = new stdClass(); - $news = $this->getAllNews($lang); - foreach ($news as $key => $value) { - $newsJson->$key = array( - "title" => $this->_purifier->purify( $value->title ), - "content" => $this->_purifier->purify( $value->content ) - ); - } - - file_put_contents(DIR_NEWS . "/i18n/news.{$lang}.json", json_encode($newsJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n"); + $langs = ['en', 'it', 'fr', 'ru', 'de']; + foreach ($langs as $key => $value) { + $this->convertLanguageJsonToSmartyIni('lang.' . $value); + $this->updateNewsI18n($value); + } } - } + private function convertLanguageJsonToSmartyIni($lang) + { + $filename = "lang/i18n/{$lang}.json"; + echo("Converting {$filename} from JSON to INI\n"); + $jsonString = file_get_contents($filename); + $json = json_decode($jsonString); - private function getAllNews($lang) { - if ($lang != 'en') - $dir = DIR_NEWS . "/{$lang}"; - else - $dir = DIR_NEWS; + $output = ""; + foreach ($json as $key => $value) { + $output .= $key . " = " . $this->_purifier->purify($value). "\n"; + } - if (!($files = scandir($dir))) { - throw new ErrorException(self::NO_FILES); - } - $news = new stdClass(); - foreach ($files as $filename) { - if (substr($filename, -5) != '.json') { - continue; - } - if (!($data = @file_get_contents($dir . "/{$filename}"))) { - continue; - } - $key = rtrim($filename, ".json"); - $news->$key = json_decode($data); - } - return $news; - } + file_put_contents("lang/{$lang}.ini", $output); + } + + private function updateNewsI18n($lang) + { + + // For non-english, create/overwrite JSON files from our i18n file + if ($lang != 'en') { + echo("Converting " . DIR_NEWS . "/i18n/news.{$lang}.json to individual JSON files\n"); + $i18n = json_decode(file_get_contents(DIR_NEWS . "/i18n/news.{$lang}.json")); + + foreach ($i18n as $key => $value) { + $originalJson = json_decode(file_get_contents(DIR_NEWS . "/{$key}.json")); + $value->date = $this->_purifier->purify($originalJson->date); + $value->author = $this->_purifier->purify($originalJson->author); + $value->title = $this->_purifier->purify($value->title); + $value->content = $this->_purifier->purify($value->content); + + file_put_contents(DIR_NEWS . "/{$lang}/{$key}.json", json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); + } + } else { + // Update the base english i18n file + echo("Converting individual JSON files to I18N base file\n"); + $newsJson = new stdClass(); + $news = $this->getAllNews($lang); + foreach ($news as $key => $value) { + $newsJson->$key = array( + "title" => $this->_purifier->purify($value->title), + "content" => $this->_purifier->purify($value->content) + ); + } + + file_put_contents(DIR_NEWS . "/i18n/news.{$lang}.json", json_encode($newsJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n"); + } + } + + private function getAllNews($lang) + { + if ($lang != 'en') { + $dir = DIR_NEWS . "/{$lang}"; + } else { + $dir = DIR_NEWS; + } + + if (!($files = scandir($dir))) { + throw new ErrorException(self::NO_FILES); + } + $news = new stdClass(); + foreach ($files as $filename) { + if (substr($filename, -5) != '.json') { + continue; + } + if (!($data = @file_get_contents($dir . "/{$filename}"))) { + continue; + } + $key = rtrim($filename, ".json"); + $news->$key = json_decode($data); + } + return $news; + } } new I18N(); -?> diff --git a/include/Models/ArticleModel.php b/include/Models/ArticleModel.php index 2373adae..eccf74ef 100644 --- a/include/Models/ArticleModel.php +++ b/include/Models/ArticleModel.php @@ -4,22 +4,23 @@ require_once('Objects/Article.php'); /** * The ArticleModel class will generate Article objects. */ -abstract class ArticleModel extends BasicModel { - /* Get all articles. */ - static public function getAllArticles() { - $fname = DIR_DATA . '/press_articles.xml'; - $parser = new XMLParser(); - $a = $parser->parseByFilename($fname); - $entries = array(); - foreach ($a['articles']['article'] as $key => $value) { - $entries[] = new Article(array( - 'name' => $value['name'], - 'url' => $value['url'], - 'language' => $value['language'], - 'posted' => $value['posted'], - )); - } - return $entries; - } +abstract class ArticleModel extends BasicModel +{ + /* Get all articles. */ + public static function getAllArticles() + { + $fname = DIR_DATA . '/press_articles.xml'; + $parser = new XMLParser(); + $a = $parser->parseByFilename($fname); + $entries = array(); + foreach ($a['articles']['article'] as $key => $value) { + $entries[] = new Article(array( + 'name' => $value['name'], + 'url' => $value['url'], + 'language' => $value['language'], + 'posted' => $value['posted'], + )); + } + return $entries; + } } -?> diff --git a/include/Models/BasicModel.php b/include/Models/BasicModel.php index b7566548..a20e82d7 100644 --- a/include/Models/BasicModel.php +++ b/include/Models/BasicModel.php @@ -1,4 +1,4 @@ diff --git a/include/Models/CompatibilityModel.php b/include/Models/CompatibilityModel.php index 6c249006..276b4b58 100644 --- a/include/Models/CompatibilityModel.php +++ b/include/Models/CompatibilityModel.php @@ -5,108 +5,114 @@ require_once('XMLParser.php'); /** * The CompatibilityModel class will generate CompatGame objects. */ -abstract class CompatibilityModel extends BasicModel { - const NO_VERSION = 'No version specified.'; - const NO_VERSION_TARGET = 'No version and/or target specified.'; - const NOT_FOUND = 'Did not find any games for the specified version.'; - const NO_FILES = 'No compatibility files found.'; +abstract class CompatibilityModel extends BasicModel +{ + const NO_VERSION = 'No version specified.'; + const NO_VERSION_TARGET = 'No version and/or target specified.'; + const NOT_FOUND = 'Did not find any games for the specified version.'; + const NO_FILES = 'No compatibility files found.'; - /* Get all the groups and the respectively demos for the specified ScummVM version. */ - static public function getAllData($version) { - if (!is_string($version)) { - throw new ErrorException(self::NO_VERSION); - } - $fname = DIR_COMPAT . "/compat-{$version}.xml"; - if (!file_exists($fname)) { - throw new ErrorException(self::NO_FILES); - } - $parser = new XMLParser(); - $a = $parser->parseByFilename($fname); - $entries = array(); - foreach ($a['compatibility']['company'] as $key => $value) { - $games = array(); - if (is_array($value['games'])) { - foreach ($value['games']['game'] as $data) { - $games[] = new CompatGame($data); - } - $entries[$value['name']] = $games; - } - } - return $entries; - } + /* Get all the groups and the respectively demos for the specified ScummVM version. */ + public static function getAllData($version) + { + if (!is_string($version)) { + throw new ErrorException(self::NO_VERSION); + } + $fname = DIR_COMPAT . "/compat-{$version}.xml"; + if (!file_exists($fname)) { + throw new ErrorException(self::NO_FILES); + } + $parser = new XMLParser(); + $a = $parser->parseByFilename($fname); + $entries = array(); + foreach ($a['compatibility']['company'] as $key => $value) { + $games = array(); + if (is_array($value['games'])) { + foreach ($value['games']['game'] as $data) { + $games[] = new CompatGame($data); + } + $entries[$value['name']] = $games; + } + } + return $entries; + } - /** - * Compares two version strings and returns an integer less than, equal - * to, or greater than zero if the first argument is considered to be - * respectively less than, equal to, or greater than the second. - */ - static public function compareVersions($version1, $version2) { - /* Get the length of the numeric part of the version strings. */ - $lenNumber1 = strspn($version1, ".0123456789"); - $lenNumber2 = strspn($version2, ".0123456789"); - if (($lenNumber1 == $lenNumber2) && (substr($version1, 0, $lenNumber1) == substr($version2, 0, $lenNumber2))) { - /* Same version number. Handle special cases. */ - $extraVersion1 = substr($version1, $lenNumber1); - $extraVersion2 = substr($version2, $lenNumber2); + /** + * Compares two version strings and returns an integer less than, equal + * to, or greater than zero if the first argument is considered to be + * respectively less than, equal to, or greater than the second. + */ + public static function compareVersions($version1, $version2) + { + /* Get the length of the numeric part of the version strings. */ + $lenNumber1 = strspn($version1, ".0123456789"); + $lenNumber2 = strspn($version2, ".0123456789"); + if (($lenNumber1 == $lenNumber2) && (substr($version1, 0, $lenNumber1) == substr($version2, 0, $lenNumber2))) { + /* Same version number. Handle special cases. */ + $extraVersion1 = substr($version1, $lenNumber1); + $extraVersion2 = substr($version2, $lenNumber2); - /* Release candidates go before the final release. */ - $rc1 = substr($extraVersion1, 0, 2); - $rc2 = substr($extraVersion2, 0, 2); - if (($rc1 == "rc") && ($rc2 != "rc")) - return -1; - if (($rc2 == "rc") && ($rc1 != "rc")) - return 1; + /* Release candidates go before the final release. */ + $rc1 = substr($extraVersion1, 0, 2); + $rc2 = substr($extraVersion2, 0, 2); + if (($rc1 == "rc") && ($rc2 != "rc")) { + return -1; + } + if (($rc2 == "rc") && ($rc1 != "rc")) { + return 1; + } - /* Break the tie with the standard comparison. */ - } - return strnatcmp($version1, $version2); - } + /* Break the tie with the standard comparison. */ + } + return strnatcmp($version1, $version2); + } - /* Get version numbers for all available compatibility charts, excluding the DEV charts. */ - static public function getAllVersions() { - if (!($files = scandir(DIR_COMPAT))) { - throw new ErrorException(self::NO_FILES); - } - $dates = array(); - foreach ($files as $file) { - if (substr($file, -4) != '.xml') { - continue; - } - /* Always exclude the DEV-chart. */ - if (strpos($file, 'DEV') === false) { - $dates[] = substr($file, (strpos($file, '-') + 1), -4); - } - } - usort($dates, "CompatibilityModel::compareVersions"); - $dates = array_reverse($dates); - return $dates; - } + /* Get version numbers for all available compatibility charts, excluding the DEV charts. */ + public static function getAllVersions() + { + if (!($files = scandir(DIR_COMPAT))) { + throw new ErrorException(self::NO_FILES); + } + $dates = array(); + foreach ($files as $file) { + if (substr($file, -4) != '.xml') { + continue; + } + /* Always exclude the DEV-chart. */ + if (strpos($file, 'DEV') === false) { + $dates[] = substr($file, (strpos($file, '-') + 1), -4); + } + } + usort($dates, "CompatibilityModel::compareVersions"); + $dates = array_reverse($dates); + return $dates; + } - /* Get a specific CompatGame-object for the requested version. */ - static public function getGameData($version, $target) { - if (!is_string($version) || !is_string($target)) { - throw new ErrorException(self::NO_VERSION_TARGET); - } - if (!($all_games = self::getAllData($version))) { - throw new ErrorException(self::NOT_FOUND); - } - $g = null; - foreach ($all_games as $company => $games) { - foreach ($games as $game) { - if ($game->getTarget() == $target) { - $g = $game; - break; - } - } - if ($g != null) { - break; - } - } - if (is_null($g)) { - throw new ErrorException(self::NOT_FOUND); - } + /* Get a specific CompatGame-object for the requested version. */ + public static function getGameData($version, $target) + { + if (!is_string($version) || !is_string($target)) { + throw new ErrorException(self::NO_VERSION_TARGET); + } + if (!($all_games = self::getAllData($version))) { + throw new ErrorException(self::NOT_FOUND); + } + $g = null; + foreach ($all_games as $company => $games) { + foreach ($games as $game) { + if ($game->getTarget() == $target) { + $g = $game; + break; + } + } + if ($g != null) { + break; + } + } + if (is_null($g)) { + throw new ErrorException(self::NOT_FOUND); + } - return $g; - } + return $g; + } } -?> diff --git a/include/Models/CreditsModel.php b/include/Models/CreditsModel.php index bf925c65..c6ffb0dd 100644 --- a/include/Models/CreditsModel.php +++ b/include/Models/CreditsModel.php @@ -5,17 +5,18 @@ require_once('XMLParser.php'); /** * The CreditsModel will generate CSection objects. */ -abstract class CreditsModel extends BasicModel { - /* Get all credit sections and their contents. */ - static public function getAllCredits() { - $fname = DIR_DATA . '/credits.xml'; - $parser = new XMLParser(); - $a = $parser->parseByFilename($fname); - $sections = array(); - foreach ($a['credits']['section'] as $key => $value) { - $sections[] = new CSection($value); - } - return $sections; - } +abstract class CreditsModel extends BasicModel +{ + /* Get all credit sections and their contents. */ + public static function getAllCredits() + { + $fname = DIR_DATA . '/credits.xml'; + $parser = new XMLParser(); + $a = $parser->parseByFilename($fname); + $sections = array(); + foreach ($a['credits']['section'] as $key => $value) { + $sections[] = new CSection($value); + } + return $sections; + } } -?> diff --git a/include/Models/DocumentationModel.php b/include/Models/DocumentationModel.php index 24d20e3e..96d89cf6 100644 --- a/include/Models/DocumentationModel.php +++ b/include/Models/DocumentationModel.php @@ -4,17 +4,18 @@ require_once('Objects/Document.php'); /** * The DocumentationModel class will generate Document objects. */ -abstract class DocumentationModel extends BasicModel { - /* Get all the documents. */ - static public function getAllDocuments() { - $fname = DIR_DATA . '/documentation.xml'; - $parser = new XMLParser(); - $a = $parser->parseByFilename($fname); - $entries = array(); - foreach ($a['documentation']['document'] as $key => $value) { - $entries[] = new Document($value); - } - return $entries; - } +abstract class DocumentationModel extends BasicModel +{ + /* Get all the documents. */ + public static function getAllDocuments() + { + $fname = DIR_DATA . '/documentation.xml'; + $parser = new XMLParser(); + $a = $parser->parseByFilename($fname); + $entries = array(); + foreach ($a['documentation']['document'] as $key => $value) { + $entries[] = new Document($value); + } + return $entries; + } } -?> diff --git a/include/Models/DownloadsModel.php b/include/Models/DownloadsModel.php index 98d7cf1a..8a19841d 100644 --- a/include/Models/DownloadsModel.php +++ b/include/Models/DownloadsModel.php @@ -5,51 +5,53 @@ require_once('XMLParser.php'); /** * The DownloadsModel will produce DSection objects. */ -abstract class DownloadsModel { - /* Get all download entries. */ - static public function getAllDownloads() { - $fname = DIR_DATA . '/downloads.xml'; - /* Now parse the data. */ - $parser = new XMLParser(); - $a = $parser->parseByFilename($fname); - $sections = array(); - foreach ($a['downloads']['section'] as $key => $value) { - $sections[] = new DSection($value); - } - return $sections; - } +abstract class DownloadsModel +{ + /* Get all download entries. */ + public static function getAllDownloads() + { + $fname = DIR_DATA . '/downloads.xml'; + /* Now parse the data. */ + $parser = new XMLParser(); + $a = $parser->parseByFilename($fname); + $sections = array(); + foreach ($a['downloads']['section'] as $key => $value) { + $sections[] = new DSection($value); + } + return $sections; + } - /* Get all sections and their anchors. */ - static public function getAllSections() { - /* Get the list with all downloads/sections. */ - $downloads = self::getAllDownloads(); - $sections = array(); - foreach ($downloads as $dsection) { - if ($dsection->getAnchor() != '' && $dsection->getTitle() != '') { - $sections[] = array( - 'title' => $dsection->getTitle(), - 'anchor' => $dsection->getAnchor(), - ); - } - foreach ($dsection->getSubSections() as $dsubsection) { - $title = $dsubsection->getTitle(); - /** - * If there is no title for this subsection, use the section - * title instead. - */ - if (empty($title)) { - $title = $dsection->getTitle(); - } - $anchor = $dsubsection->getAnchor(); - if (!empty($anchor)) { - $sections[] = array( - 'title' => $title, - 'anchor' => $anchor, - ); - } - } - } - return $sections; - } + /* Get all sections and their anchors. */ + public static function getAllSections() + { + /* Get the list with all downloads/sections. */ + $downloads = self::getAllDownloads(); + $sections = array(); + foreach ($downloads as $dsection) { + if ($dsection->getAnchor() != '' && $dsection->getTitle() != '') { + $sections[] = array( + 'title' => $dsection->getTitle(), + 'anchor' => $dsection->getAnchor(), + ); + } + foreach ($dsection->getSubSections() as $dsubsection) { + $title = $dsubsection->getTitle(); + /** + * If there is no title for this subsection, use the section + * title instead. + */ + if (empty($title)) { + $title = $dsection->getTitle(); + } + $anchor = $dsubsection->getAnchor(); + if (!empty($anchor)) { + $sections[] = array( + 'title' => $title, + 'anchor' => $anchor, + ); + } + } + } + return $sections; + } } -?> diff --git a/include/Models/FAQModel.php b/include/Models/FAQModel.php index 11d93981..e914eb6f 100644 --- a/include/Models/FAQModel.php +++ b/include/Models/FAQModel.php @@ -9,89 +9,92 @@ require_once('XMLParser.php'); * QASection-objects representing the different sections on the F.A.Q.-page on * the website. */ -abstract class FAQModel extends BasicModel{ - const ERROR_READING_FILE = 'Could not load the frequently asked questions.'; +abstract class FAQModel extends BasicModel +{ + const ERROR_READING_FILE = 'Could not load the frequently asked questions.'; - /* Get the full path and filename for the F.A.Q. XML-file. */ - static public function getFilename() { - global $lang; + /* Get the full path and filename for the F.A.Q. XML-file. */ + public static function getFilename() + { + global $lang; - if ($lang != 'en') { - $localized = DIR_DATA . "/faq-xml." . $lang . ".xml"; + if ($lang != 'en') { + $localized = DIR_DATA . "/faq-xml." . $lang . ".xml"; - if (is_file($localized)) { - if (!is_readable($localized)) { - $file = "\n\nFilename: " . basename($localized) . "\n"; - throw new ErrorException(self::FILE_NOT_FOUND . $file); - } else { - return $localized; - } - } - } + if (is_file($localized)) { + if (!is_readable($localized)) { + $file = "\n\nFilename: " . basename($localized) . "\n"; + throw new ErrorException(self::FILE_NOT_FOUND . $file); + } else { + return $localized; + } + } + } - return DIR_DATA . '/faq-xml.xml'; - } + return DIR_DATA . '/faq-xml.xml'; + } - /* Get last modification time. */ - static public function getLastUpdated() { - return date('F d, Y', @filemtime(self::getFilename())); - } + /* Get last modification time. */ + public static function getLastUpdated() + { + return date('F d, Y', @filemtime(self::getFilename())); + } - /* Get all question and answers. */ - static public function getFAQ() { - if (!($data = @file_get_contents(self::getFilename()))) { - throw new ErrorException(self::ERROR_READING_FILE); - } - /** - * Let's replace some of the docbook tags and wrap some HTML-entities - * inside CDATA containers. - */ - $pattern = array( - '/(.+)<\/ulink>/isU', - '/(.+)<\/itemizedlist>/isU', - '/(.+)<\/simpara><\/listitem>/isU', - '/(.+)<\/simpara>/isU', - '/(.+)<\/emphasis>/isU', - '/(.+)<\/envar>/isU', - '/]+)?>(.+)<\/command>/isU', - '/
(.+)<\/blockquote>/isU', - '/]+)?>(.+)<\/programlisting>/isU', - '/(.+)<\/quote>/isU', - '//isU', - '/(&(?:lt|gt|quot);)/is', - ); - $replace = array( - '\\2', - '\\1', - '\\1', - '\\1', - '\\1', // emphasis - '\\1', - '\\1', // command - '\\1', - '\\1', // programlisting - '“\\1”', - '', - '', - ); - $data = preg_replace($pattern, $replace, $data); - /* Remove this weird character as it displays as À in Firefox. */ - $data = str_replace(chr(194), '', $data); + /* Get all question and answers. */ + public static function getFAQ() + { + if (!($data = @file_get_contents(self::getFilename()))) { + throw new ErrorException(self::ERROR_READING_FILE); + } + /** + * Let's replace some of the docbook tags and wrap some HTML-entities + * inside CDATA containers. + */ + $pattern = array( + '/(.+)<\/ulink>/isU', + '/(.+)<\/itemizedlist>/isU', + '/(.+)<\/simpara><\/listitem>/isU', + '/(.+)<\/simpara>/isU', + '/(.+)<\/emphasis>/isU', + '/(.+)<\/envar>/isU', + '/]+)?>(.+)<\/command>/isU', + '/
(.+)<\/blockquote>/isU', + '/]+)?>(.+)<\/programlisting>/isU', + '/(.+)<\/quote>/isU', + '//isU', + '/(&(?:lt|gt|quot);)/is', + ); + $replace = array( + '\\2', + '\\1', + '\\1', + '\\1', + '\\1', // emphasis + '\\1', + '\\1', // command + '\\1', + '\\1', // programlisting + '“\\1”', + '', + '', + ); + $data = preg_replace($pattern, $replace, $data); + /* Remove this weird character as it displays as À in Firefox. */ + $data = str_replace(chr(194), '', $data); - /* Now parse the data. */ - $parser = new XMLParser(); - $a = $parser->parseByData($data); - $sections = array(); - /** - * Build a map of the defined hrefs so we can give the xrefs the correct - * text. - */ - $xref = array(); - $count = 1; - foreach ($a['faq']['section'] as $data) { - $sections[] = new QASection($data, $count++, $xref); - } - return $sections; - } + /* Now parse the data. */ + $parser = new XMLParser(); + $a = $parser->parseByData($data); + $sections = array(); + /** + * Build a map of the defined hrefs so we can give the xrefs the correct + * text. + */ + $xref = array(); + $count = 1; + foreach ($a['faq']['section'] as $data) { + $sections[] = new QASection($data, $count++, $xref); + } + return $sections; + } } -?> diff --git a/include/Models/GameDemosModel.php b/include/Models/GameDemosModel.php index 3a37531a..de7f2eb6 100644 --- a/include/Models/GameDemosModel.php +++ b/include/Models/GameDemosModel.php @@ -5,25 +5,26 @@ require_once('XMLParser.php'); /** * The GameDemosModel class will generate GameDemo objects. */ -abstract class GameDemosModel extends BasicModel { - /* Get all the groups and their respective demos. */ - static public function getAllGroupsAndDemos() { - $fname = DIR_DATA . '/game_demos.xml'; - $parser = new XMLParser(); - $a = $parser->parseByFilename($fname); - $entries = array(); - foreach ($a['game_demos']['group'] as $key => $value) { - $demos = array(); - foreach ($value['demos']['demo'] as $data) { - $demos[] = new GameDemo($data); - } - $entries[] = array( - 'name' => $value['name'], - 'href' => $value['href'], - 'demos' => $demos, - ); - } - return $entries; - } +abstract class GameDemosModel extends BasicModel +{ + /* Get all the groups and their respective demos. */ + public static function getAllGroupsAndDemos() + { + $fname = DIR_DATA . '/game_demos.xml'; + $parser = new XMLParser(); + $a = $parser->parseByFilename($fname); + $entries = array(); + foreach ($a['game_demos']['group'] as $key => $value) { + $demos = array(); + foreach ($value['demos']['demo'] as $data) { + $demos[] = new GameDemo($data); + } + $entries[] = array( + 'name' => $value['name'], + 'href' => $value['href'], + 'demos' => $demos, + ); + } + return $entries; + } } -?> diff --git a/include/Models/GamesModel.php b/include/Models/GamesModel.php index 774d4cbd..29ae30cd 100644 --- a/include/Models/GamesModel.php +++ b/include/Models/GamesModel.php @@ -5,51 +5,53 @@ require_once('XMLParser.php'); /** * The GamesModel will produce DSection objects. */ -abstract class GamesModel { - /* Get all download entries. */ - static public function getAllDownloads() { - $fname = DIR_DATA . '/games.xml'; - /* Now parse the data. */ - $parser = new XMLParser(); - $a = $parser->parseByFilename($fname); - $sections = array(); - foreach ($a['downloads']['section'] as $key => $value) { - $sections[] = new DSection($value); - } - return $sections; - } +abstract class GamesModel +{ + /* Get all download entries. */ + public static function getAllDownloads() + { + $fname = DIR_DATA . '/games.xml'; + /* Now parse the data. */ + $parser = new XMLParser(); + $a = $parser->parseByFilename($fname); + $sections = array(); + foreach ($a['downloads']['section'] as $key => $value) { + $sections[] = new DSection($value); + } + return $sections; + } - /* Get all sections and their anchors. */ - static public function getAllSections() { - /* Get the list with all downloads/sections. */ - $downloads = self::getAllDownloads(); - $sections = array(); - foreach ($downloads as $dsection) { - if ($dsection->getAnchor() != '' && $dsection->getTitle() != '') { - $sections[] = array( - 'title' => $dsection->getTitle(), - 'anchor' => $dsection->getAnchor(), - ); - } - foreach ($dsection->getSubSections() as $dsubsection) { - $title = $dsubsection->getTitle(); - /** - * If there is no title for this subsection, use the section - * title instead. - */ - if (empty($title)) { - $title = $dsection->getTitle(); - } - $anchor = $dsubsection->getAnchor(); - if (!empty($anchor)) { - $sections[] = array( - 'title' => $title, - 'anchor' => $anchor, - ); - } - } - } - return $sections; - } + /* Get all sections and their anchors. */ + public static function getAllSections() + { + /* Get the list with all downloads/sections. */ + $downloads = self::getAllDownloads(); + $sections = array(); + foreach ($downloads as $dsection) { + if ($dsection->getAnchor() != '' && $dsection->getTitle() != '') { + $sections[] = array( + 'title' => $dsection->getTitle(), + 'anchor' => $dsection->getAnchor(), + ); + } + foreach ($dsection->getSubSections() as $dsubsection) { + $title = $dsubsection->getTitle(); + /** + * If there is no title for this subsection, use the section + * title instead. + */ + if (empty($title)) { + $title = $dsection->getTitle(); + } + $anchor = $dsubsection->getAnchor(); + if (!empty($anchor)) { + $sections[] = array( + 'title' => $title, + 'anchor' => $anchor, + ); + } + } + } + return $sections; + } } -?> diff --git a/include/Models/LinksModel.php b/include/Models/LinksModel.php index af73ef12..e1f9b75c 100644 --- a/include/Models/LinksModel.php +++ b/include/Models/LinksModel.php @@ -6,26 +6,27 @@ require_once('XMLParser.php'); * The LinksModel class will generate WebLink objects. * LinkGroup-objects representing a group of external links on the website. */ -abstract class LinksModel extends BasicModel { - /* Get all the groups and the respectively demos. */ - static public function getAllGroupsAndLinks() { - $fname = DIR_DATA . '/links.xml'; - $parser = new XMLParser(); - $a = $parser->parseByFilename($fname); - $entries = array(); - foreach ($a['external_links']['group'] as $key => $value) { - /* Get all links. */ - $links = array(); - foreach ($value['link'] as $data) { - $links[] = new WebLink($data); - } - $entries[] = array( - 'name' => $value['name'], - 'description' => $value['description'], - 'links' => $links, - ); - } - return $entries; - } +abstract class LinksModel extends BasicModel +{ + /* Get all the groups and the respectively demos. */ + public static function getAllGroupsAndLinks() + { + $fname = DIR_DATA . '/links.xml'; + $parser = new XMLParser(); + $a = $parser->parseByFilename($fname); + $entries = array(); + foreach ($a['external_links']['group'] as $key => $value) { + /* Get all links. */ + $links = array(); + foreach ($value['link'] as $data) { + $links[] = new WebLink($data); + } + $entries[] = array( + 'name' => $value['name'], + 'description' => $value['description'], + 'links' => $links, + ); + } + return $entries; + } } -?> diff --git a/include/Models/MenuModel.php b/include/Models/MenuModel.php index a5c285fd..bfcbfac0 100644 --- a/include/Models/MenuModel.php +++ b/include/Models/MenuModel.php @@ -5,21 +5,22 @@ require_once('Objects/MenuItem.php'); /** * The MenuModel class will generates MenuItme objects. */ -abstract class MenuModel extends BasicModel { - /* Get all menu entries. */ - static public function getAllMenus() { - $fname = DIR_DATA . '/menus.xml'; - $parser = new XMLParser(); - $a = $parser->parseByFilename($fname); - $entries = array(); - foreach ($a['menus']['group'] as $key => $value) { - $entries[] = new MenuItem(array( - 'name' => $value['name'], - 'class' => $value['class'], - 'link' => $value['link'], - )); - } - return $entries; - } +abstract class MenuModel extends BasicModel +{ + /* Get all menu entries. */ + public static function getAllMenus() + { + $fname = DIR_DATA . '/menus.xml'; + $parser = new XMLParser(); + $a = $parser->parseByFilename($fname); + $entries = array(); + foreach ($a['menus']['group'] as $key => $value) { + $entries[] = new MenuItem(array( + 'name' => $value['name'], + 'class' => $value['class'], + 'link' => $value['link'], + )); + } + return $entries; + } } -?> diff --git a/include/Models/NewsModel.php b/include/Models/NewsModel.php index 0e90c4c3..8a6a1c10 100644 --- a/include/Models/NewsModel.php +++ b/include/Models/NewsModel.php @@ -4,81 +4,85 @@ require_once('Objects/News.php'); /** * The NewsModel class will generate News objects */ -abstract class NewsModel extends BasicModel { - const NO_FILES = 'No news files found.'; - const INVALID_DATE = 'Invalid date, use yyyyMMdd. or yyyyMMddHHmm'; - const FILE_NOT_FOUND = 'The requested news file doesn\'t exist.'; +abstract class NewsModel extends BasicModel +{ + const NO_FILES = 'No news files found.'; + const INVALID_DATE = 'Invalid date, use yyyyMMdd. or yyyyMMddHHmm'; + const FILE_NOT_FOUND = 'The requested news file doesn\'t exist.'; - /* Get a list of all the available news files. */ - static public function getListOfNewsFilenames() { - if (!($files = scandir(DIR_NEWS))) { - throw new ErrorException(self::NO_FILES); - } - $filenames = array(); - foreach ($files as $file) { - if (substr($file, -5) != '.json') { - continue; - } - $filenames[] = substr($file, 0, -5); - } - sort($filenames, SORT_STRING); - return $filenames; - } + /* Get a list of all the available news files. */ + public static function getListOfNewsFilenames() + { + if (!($files = scandir(DIR_NEWS))) { + throw new ErrorException(self::NO_FILES); + } + $filenames = array(); + foreach ($files as $file) { + if (substr($file, -5) != '.json') { + continue; + } + $filenames[] = substr($file, 0, -5); + } + sort($filenames, SORT_STRING); + return $filenames; + } - /* Get all news items ordered by date, descending. */ - static public function getAllNews($processContent = false) { - if (!($files = scandir(DIR_NEWS))) { - throw new ErrorException(self::NO_FILES); - } - global $lang; - $news = array(); - foreach ($files as $filename) { - if (substr($filename, -5) != '.json') { - continue; - } - if (!is_file(($fname = DIR_NEWS . "/$lang/" . basename($filename))) - || !is_readable($fname) || !($data = @file_get_contents($fname))) { - if (!($data = @file_get_contents(DIR_NEWS . "/{$filename}"))) { - continue; - } - } - $news[] = new News(json_decode($data), $filename, $processContent); - } - return array_reverse($news); - } + /* Get all news items ordered by date, descending. */ + public static function getAllNews($processContent = false) + { + if (!($files = scandir(DIR_NEWS))) { + throw new ErrorException(self::NO_FILES); + } + global $lang; + $news = array(); + foreach ($files as $filename) { + if (substr($filename, -5) != '.json') { + continue; + } + if (!is_file(($fname = DIR_NEWS . "/$lang/" . basename($filename))) + || !is_readable($fname) || !($data = @file_get_contents($fname))) { + if (!($data = @file_get_contents(DIR_NEWS . "/{$filename}"))) { + continue; + } + } + $news[] = new News(json_decode($data), $filename, $processContent); + } + return array_reverse($news); + } - /* Get the latest number of news items, or if no number is specified get all news items. */ - static public function getLatestNews($num=-1, $processContent = false) { - if ($num == -1) { - return NewsModel::getAllNews($processContent); - } else { - if (!($newslist = NewsModel::getListOfNewsFilenames())) { - throw new ErrorException(self::NO_FILES); - } - rsort($newslist, SORT_STRING); - $newslist = array_slice($newslist, 0, $num); - $news = array(); - foreach ($newslist as $filename) { - $news[] = NewsModel::getOneByFilename($filename, $processContent); - } - return $news; - } - } + /* Get the latest number of news items, or if no number is specified get all news items. */ + public static function getLatestNews($num = -1, $processContent = false) + { + if ($num == -1) { + return NewsModel::getAllNews($processContent); + } else { + if (!($newslist = NewsModel::getListOfNewsFilenames())) { + throw new ErrorException(self::NO_FILES); + } + rsort($newslist, SORT_STRING); + $newslist = array_slice($newslist, 0, $num); + $news = array(); + foreach ($newslist as $filename) { + $news[] = NewsModel::getOneByFilename($filename, $processContent); + } + return $news; + } + } - /* Get the news item that was posted on a specific date. */ - static public function getOneByFilename($filename, $processContent = false) { - if (is_null($filename) || !preg_match('/^\d{8,12}[a-z]?$/', $filename)) { - throw new ErrorException(self::INVALID_DATE); - } - global $lang; - if (!is_file(($fname = DIR_NEWS . "/$lang/{$filename}.json")) - || !is_readable($fname) || !($data = @file_get_contents($fname))) { - if (!is_file(($fname = DIR_NEWS . "/{$filename}.json")) - || !is_readable($fname) || !($data = @file_get_contents($fname))) { - throw new ErrorException(self::FILE_NOT_FOUND); - } - } - return new News(json_decode($data), $fname, $processContent); - } + /* Get the news item that was posted on a specific date. */ + public static function getOneByFilename($filename, $processContent = false) + { + if (is_null($filename) || !preg_match('/^\d{8,12}[a-z]?$/', $filename)) { + throw new ErrorException(self::INVALID_DATE); + } + global $lang; + if (!is_file(($fname = DIR_NEWS . "/$lang/{$filename}.json")) + || !is_readable($fname) || !($data = @file_get_contents($fname))) { + if (!is_file(($fname = DIR_NEWS . "/{$filename}.json")) + || !is_readable($fname) || !($data = @file_get_contents($fname))) { + throw new ErrorException(self::FILE_NOT_FOUND); + } + } + return new News(json_decode($data), $fname, $processContent); + } } -?> diff --git a/include/Models/ScreenshotsModel.php b/include/Models/ScreenshotsModel.php index eb8bee49..9a7ba835 100644 --- a/include/Models/ScreenshotsModel.php +++ b/include/Models/ScreenshotsModel.php @@ -5,68 +5,72 @@ require_once('XMLParser.php'); /** * The ScreenshotsModel will generate Screenshot objects. */ -abstract class ScreenshotsModel extends BasicModel { - const INVALID_TARGET = 'Invalid target specified.'; - const INVALID_CATEGORY = 'Invalid category specified.'; +abstract class ScreenshotsModel extends BasicModel +{ + const INVALID_TARGET = 'Invalid target specified.'; + const INVALID_CATEGORY = 'Invalid category specified.'; - /* Get all screenshots. */ - static public function getAllScreenshots() { - $fname = DIR_DATA . '/screenshots.xml'; - $parser = new XMLParser(); - $a = $parser->parseByFilename($fname); - $entries = array(); - BasicObject::toArray($a['screenshots']['group']); - foreach ($a['screenshots']['group'] as $value) { - BasicObject::toArray($value['game']); - $games = array(); - foreach ($value['game'] as $data) { - $games[] = new Screenshot($data); - } + /* Get all screenshots. */ + public static function getAllScreenshots() + { + $fname = DIR_DATA . '/screenshots.xml'; + $parser = new XMLParser(); + $a = $parser->parseByFilename($fname); + $entries = array(); + BasicObject::toArray($a['screenshots']['group']); + foreach ($a['screenshots']['group'] as $value) { + BasicObject::toArray($value['game']); + $games = array(); + foreach ($value['game'] as $data) { + $games[] = new Screenshot($data); + } - $entries[] = array( - 'title' => $value['title'], - 'category' => $value['category'], - 'games' => $games, - ); - } - return $entries; - } + $entries[] = array( + 'title' => $value['title'], + 'category' => $value['category'], + 'games' => $games, + ); + } + return $entries; + } - /* Get all screenshots in one category. */ - static public function getCategoryScreenshots($category) { - $sshots = self::getAllScreenshots(); - foreach ($sshots as $shots) { - if ($shots['category'] == $category) { - return $shots; - } - } - throw new ErrorException(self::INVALID_CATEGORY); - } + /* Get all screenshots in one category. */ + public static function getCategoryScreenshots($category) + { + $sshots = self::getAllScreenshots(); + foreach ($sshots as $shots) { + if ($shots['category'] == $category) { + return $shots; + } + } + throw new ErrorException(self::INVALID_CATEGORY); + } - /* Get screenshots for a specific target. */ - static public function getTargetScreenshots($target) { - $sshots = self::getAllScreenshots(); - foreach ($sshots as $shots) { - foreach ($shots['games'] as $starget) { - if ($starget->getCategory() == $target) { - return $starget; - } - } - } - throw new ErrorException(self::INVALID_TARGET); - } + /* Get screenshots for a specific target. */ + public static function getTargetScreenshots($target) + { + $sshots = self::getAllScreenshots(); + foreach ($sshots as $shots) { + foreach ($shots['games'] as $starget) { + if ($starget->getCategory() == $target) { + return $starget; + } + } + } + throw new ErrorException(self::INVALID_TARGET); + } - /* Get a random screenshot (an object and not a filename) .*/ - static public function getRandomScreenshot() { - $sshots = self::getAllScreenshots(); - $catpos = rand(0, count($sshots) - 1); - $scrpos = rand(0, count($sshots[$catpos]['games']) - 1); - $screenshot = array( - 'category' => $sshots[$catpos]['category'], - 'screenshot' => $sshots[$catpos]['games'][$scrpos], - ); - unset ($sshots); - return $screenshot; - } + /* Get a random screenshot (an object and not a filename) .*/ + public static function getRandomScreenshot() + { + $sshots = self::getAllScreenshots(); + $catpos = rand(0, count($sshots) - 1); + $scrpos = rand(0, count($sshots[$catpos]['games']) - 1); + $screenshot = array( + 'category' => $sshots[$catpos]['category'], + 'screenshot' => $sshots[$catpos]['games'][$scrpos], + ); + unset($sshots); + return $screenshot; + } } -?> diff --git a/include/Models/SubprojectsModel.php b/include/Models/SubprojectsModel.php index 3a5d7e61..58db17cc 100644 --- a/include/Models/SubprojectsModel.php +++ b/include/Models/SubprojectsModel.php @@ -5,31 +5,32 @@ require_once('Objects/Project.php'); /** * The SubprojectsModel will generate Project objects. */ -abstract class SubprojectsModel extends BasicModel { - /* Get all the groups and the respectively demos. */ - static public function getAllSubprojects() { - $fname = DIR_DATA . '/subprojects.xml'; - $parser = new XMLParser(); - $a = $parser->parseByFilename($fname); - $entries = array(); - BasicObject::toArray($a['subprojects']['project']); - foreach ($a['subprojects']['project'] as $key => $value) { - $downloads = array(); - foreach ($value['entries'] as $type => $data) { - if ($type == 'file') { - BasicObject::toArray($data); - foreach ($data as $file) { - $downloads[] = new File($file); - } - } - } - $entries[] = new Project(array( - 'name' => $value['name'], - 'info' => $value['info'], - 'downloads' => $downloads, - )); - } - return $entries; - } +abstract class SubprojectsModel extends BasicModel +{ + /* Get all the groups and the respectively demos. */ + public static function getAllSubprojects() + { + $fname = DIR_DATA . '/subprojects.xml'; + $parser = new XMLParser(); + $a = $parser->parseByFilename($fname); + $entries = array(); + BasicObject::toArray($a['subprojects']['project']); + foreach ($a['subprojects']['project'] as $key => $value) { + $downloads = array(); + foreach ($value['entries'] as $type => $data) { + if ($type == 'file') { + BasicObject::toArray($data); + foreach ($data as $file) { + $downloads[] = new File($file); + } + } + } + $entries[] = new Project(array( + 'name' => $value['name'], + 'info' => $value['info'], + 'downloads' => $downloads, + )); + } + return $entries; + } } -?> diff --git a/include/Objects/Article.php b/include/Objects/Article.php index c4bea184..38ebf19e 100644 --- a/include/Objects/Article.php +++ b/include/Objects/Article.php @@ -4,38 +4,43 @@ require_once('Objects/BasicObject.php'); * The article class represents a link on the website to an article covering * ScummVM in some way. */ -class Article extends BasicObject { - private $_name; - private $_url; - private $_language; - private $_posted; +class Article extends BasicObject +{ + private $_name; + private $_url; + private $_language; + private $_posted; - /* Article object constructor. */ - public function __construct($data) { - $this->_name = $data['name']; - $this->_url = $data['url']; - $this->_language = $data['language']; - $this->_posted = $data['posted']; - } + /* Article object constructor. */ + public function __construct($data) + { + $this->_name = $data['name']; + $this->_url = $data['url']; + $this->_language = $data['language']; + $this->_posted = $data['posted']; + } - /* Get the name. */ - public function getName() { - return $this->_name; - } + /* Get the name. */ + public function getName() + { + return $this->_name; + } - /* Get the URL. */ - public function getURL() { - return $this->_url; - } + /* Get the URL. */ + public function getURL() + { + return $this->_url; + } - /* Get the language. */ - public function getLanguage() { - return $this->_language; - } + /* Get the language. */ + public function getLanguage() + { + return $this->_language; + } - /* Get the date it was posted. */ - public function getPosted() { - return $this->_posted; - } + /* Get the date it was posted. */ + public function getPosted() + { + return $this->_posted; + } } -?> diff --git a/include/Objects/BasicObject.php b/include/Objects/BasicObject.php index 2d0abf12..7a2f757e 100644 --- a/include/Objects/BasicObject.php +++ b/include/Objects/BasicObject.php @@ -3,17 +3,18 @@ * The BasicObject class is inherited by all other objects and houses all common * functions. */ -abstract class BasicObject { - /** - * If the input array doesn't contain the numerical key 0, wrap it inside - * an array. This functions operates on the data directly. - * - * @param mixed &$data the input - */ - static public function toArray(&$data) { - if (!is_array($data) || !array_key_exists(0, $data)) { - $data = array($data); - } - } +abstract class BasicObject +{ + /** + * If the input array doesn't contain the numerical key 0, wrap it inside + * an array. This functions operates on the data directly. + * + * @param mixed &$data the input + */ + public static function toArray(&$data) + { + if (!is_array($data) || !array_key_exists(0, $data)) { + $data = array($data); + } + } } -?> diff --git a/include/Objects/CSection.php b/include/Objects/CSection.php index c8471520..36cfb12a 100644 --- a/include/Objects/CSection.php +++ b/include/Objects/CSection.php @@ -5,75 +5,81 @@ require_once('Objects/Person.php'); * The Section class represens a section (or a subsection) on the credits page * on the website. */ -class CSection extends BasicObject { - private $_title; - private $_groups; - private $_subsections; - private $_paragraphs; - private $_anchor; +class CSection extends BasicObject +{ + private $_title; + private $_groups; + private $_subsections; + private $_paragraphs; + private $_anchor; - /* CSection object constructor. */ - public function __construct($data) { - $this->_title = $data['title']; - $this->_anchor = $data['anchor']; - $this->_groups = array(); - $this->_subsections = array(); - $this->_paragraphs = array(); + /* CSection object constructor. */ + public function __construct($data) + { + $this->_title = $data['title']; + $this->_anchor = $data['anchor']; + $this->_groups = array(); + $this->_subsections = array(); + $this->_paragraphs = array(); - if (isset ($data['subsection'])) { - foreach ($data['subsection'] as $value) { - $this->_subsections[] = new CSection($value); - } - } - if (isset ($data['group'])) { - parent::toArray($data['group']); - foreach ($data['group'] as $value) { - $persons = array(); -if (is_string($value['person'])) { - var_dump($value); - die(); -} - parent::toArray($value['person']); - foreach ($value['person'] as $args) { - $persons[] = new Person($args); - } - if (count($persons) > 0) { - $this->_groups[] = array( - 'name' => $value['name'], - 'persons' => $persons, - ); - } - } - } - if (isset ($data['paragraph'])) { - parent::toArray($data['paragraph']); - $this->_paragraphs = $data['paragraph']; - } - } + if (isset($data['subsection'])) { + foreach ($data['subsection'] as $value) { + $this->_subsections[] = new CSection($value); + } + } + if (isset($data['group'])) { + parent::toArray($data['group']); + foreach ($data['group'] as $value) { + $persons = array(); + if (is_string($value['person'])) { + var_dump($value); + die(); + } + parent::toArray($value['person']); + foreach ($value['person'] as $args) { + $persons[] = new Person($args); + } + if (count($persons) > 0) { + $this->_groups[] = array( + 'name' => $value['name'], + 'persons' => $persons, + ); + } + } + } + if (isset($data['paragraph'])) { + parent::toArray($data['paragraph']); + $this->_paragraphs = $data['paragraph']; + } + } - /* Get the title. */ - public function getTitle() { - return $this->_title; - } + /* Get the title. */ + public function getTitle() + { + return $this->_title; + } /* Get the anchor. */ - public function getAnchor() { - return $this->_anchor; - } + public function getAnchor() + { + return $this->_anchor; + } - /* Get the optional list of groups. */ - public function getGroups() { - return $this->_groups; - } + /* Get the optional list of groups. */ + public function getGroups() + { + return $this->_groups; + } - /* Get the optional list of subsections. */ - public function getSubSections() { - return $this->_subsections; - } + /* Get the optional list of subsections. */ + public function getSubSections() + { + return $this->_subsections; + } - /* Get the optional list of paragraphs. */ - public function getParagraphs() { - return $this->_paragraphs; - } + /* Get the optional list of paragraphs. */ + public function getParagraphs() + { + return $this->_paragraphs; + } } -?> diff --git a/include/Objects/CompatGame.php b/include/Objects/CompatGame.php index da41998c..d5bf6f5a 100644 --- a/include/Objects/CompatGame.php +++ b/include/Objects/CompatGame.php @@ -4,45 +4,50 @@ require_once('Objects/BasicObject.php'); * The CompatGame class represents a game on the compatibility charts on the * website. */ -class CompatGame extends BasicObject { - private $_name; - private $_target; - private $_supportLevel; - private $_notes; +class CompatGame extends BasicObject +{ + private $_name; + private $_target; + private $_supportLevel; + private $_notes; - /* Project object constructor. */ - public function __construct($data) { - $this->_name = $data['name']; - $this->_target = $data['target']; - // In old compat pages we used 'percent' instead of 'support_level'. - // we still want to support those thus we check whether the old tag - // is present here. - if (array_key_exists('percent', $data)) { - $this->_supportLevel = $data['percent']; - } else { - $this->_supportLevel = $data['support_level']; - } - $this->_notes = $data['notes']; - } + /* Project object constructor. */ + public function __construct($data) + { + $this->_name = $data['name']; + $this->_target = $data['target']; + // In old compat pages we used 'percent' instead of 'support_level'. + // we still want to support those thus we check whether the old tag + // is present here. + if (array_key_exists('percent', $data)) { + $this->_supportLevel = $data['percent']; + } else { + $this->_supportLevel = $data['support_level']; + } + $this->_notes = $data['notes']; + } - /* Get the name. */ - public function getName() { - return $this->_name; - } + /* Get the name. */ + public function getName() + { + return $this->_name; + } - /* Get the target name. */ - public function getTarget() { - return $this->_target; - } + /* Get the target name. */ + public function getTarget() + { + return $this->_target; + } - /* Get the support level. */ - public function getSupportLevel() { - return $this->_supportLevel; - } + /* Get the support level. */ + public function getSupportLevel() + { + return $this->_supportLevel; + } - /* Get the notes. */ - public function getNotes() { - return $this->_notes; - } + /* Get the notes. */ + public function getNotes() + { + return $this->_notes; + } } -?> diff --git a/include/Objects/DSection.php b/include/Objects/DSection.php index 9317e2aa..e9616038 100644 --- a/include/Objects/DSection.php +++ b/include/Objects/DSection.php @@ -4,44 +4,49 @@ require_once('Objects/DSubSection.php'); /** * The DSection object represents a section on the downloads page. */ -class DSection extends BasicObject{ - private $_title; - private $_anchor; - private $_baseurl; - private $_subsections; +class DSection extends BasicObject +{ + private $_title; + private $_anchor; + private $_baseurl; + private $_subsections; - /* DSection object constructor. */ - public function __construct($data) { - $this->_title = $data['title']; - $this->_anchor = $data['anchor']; - $this->_baseurl = $data['baseurl']; - $this->_baseturl = $data['baseturl']; - $this->_subsections = array(); + /* DSection object constructor. */ + public function __construct($data) + { + $this->_title = $data['title']; + $this->_anchor = $data['anchor']; + $this->_baseurl = $data['baseurl']; + $this->_baseturl = $data['baseturl']; + $this->_subsections = array(); - parent::toArray($data['subsection']); - foreach ($data['subsection'] as $key => $value) { - $this->_subsections[] = new DSubSection($value, $this->_baseurl, $this->_baseturl); - } - } + parent::toArray($data['subsection']); + foreach ($data['subsection'] as $key => $value) { + $this->_subsections[] = new DSubSection($value, $this->_baseurl, $this->_baseturl); + } + } - /* Get the title. */ - public function getTitle() { - return $this->_title; - } + /* Get the title. */ + public function getTitle() + { + return $this->_title; + } - /* Get the anchor name. */ - public function getAnchor() { - return $this->_anchor; - } + /* Get the anchor name. */ + public function getAnchor() + { + return $this->_anchor; + } - /* Get the base URL. */ - public function getBaseURL() { - return $this->_baseurl; - } + /* Get the base URL. */ + public function getBaseURL() + { + return $this->_baseurl; + } - /* Get the list of optional subsections. */ - public function getSubSections() { - return $this->_subsections; - } + /* Get the list of optional subsections. */ + public function getSubSections() + { + return $this->_subsections; + } } -?> diff --git a/include/Objects/DSubSection.php b/include/Objects/DSubSection.php index 654fc43a..d3edae04 100644 --- a/include/Objects/DSubSection.php +++ b/include/Objects/DSubSection.php @@ -5,71 +5,79 @@ require_once('Objects/WebLink.php'); /** * The DSubSection object represents a subsection on the downloads page. */ -class DSubSection extends BasicObject { - private $_title; - private $_anchor; - private $_notes; - private $_footer; - private $_files; - private $_links; +class DSubSection extends BasicObject +{ + private $_title; + private $_anchor; + private $_notes; + private $_footer; + private $_files; + private $_links; - /* DSubSection constructor. */ - public function __construct($data, $baseurl, $baseturl) { - $this->_title = $data['title']; - $this->_anchor = $data['anchor']; - $this->_notes = $data['notes']; - $this->_footer = $data['footer']; - $this->_files = array(); - $this->_links = array(); - $this->_items = array(); + /* DSubSection constructor. */ + public function __construct($data, $baseurl, $baseturl) + { + $this->_title = $data['title']; + $this->_anchor = $data['anchor']; + $this->_notes = $data['notes']; + $this->_footer = $data['footer']; + $this->_files = array(); + $this->_links = array(); + $this->_items = array(); - foreach ($data['entries'] as $type => $item) { - parent::toArray($item); - if ($type == 'file') { - foreach ($item as $file) { - $this->_items[] = new File($file, $baseurl, $baseturl); - } - } elseif ($type == 'link') { - foreach ($item as $link) { - $this->_items[] = new WebLink($link); - } - } - } - } + foreach ($data['entries'] as $type => $item) { + parent::toArray($item); + if ($type == 'file') { + foreach ($item as $file) { + $this->_items[] = new File($file, $baseurl, $baseturl); + } + } elseif ($type == 'link') { + foreach ($item as $link) { + $this->_items[] = new WebLink($link); + } + } + } + } - /* Get the title. */ - public function getTitle() { - return $this->_title; - } + /* Get the title. */ + public function getTitle() + { + return $this->_title; + } - /* Get the anchor name. */ - public function getAnchor() { - return $this->_anchor; - } + /* Get the anchor name. */ + public function getAnchor() + { + return $this->_anchor; + } - /* Get the optional notes. */ - public function getNotes() { - return $this->_notes; - } + /* Get the optional notes. */ + public function getNotes() + { + return $this->_notes; + } - /* Get the optional footer. */ - public function getFooter() { - return $this->_footer; - } + /* Get the optional footer. */ + public function getFooter() + { + return $this->_footer; + } - /* Get the list of files. */ - public function getFiles() { - return $this->_files; - } + /* Get the list of files. */ + public function getFiles() + { + return $this->_files; + } - /* Get the list of links. */ - public function getLinks() { - return $this->_links; - } + /* Get the list of links. */ + public function getLinks() + { + return $this->_links; + } - /* Get the list of items. */ - public function getItems() { - return $this->_items; - } + /* Get the list of items. */ + public function getItems() + { + return $this->_items; + } } -?> diff --git a/include/Objects/Document.php b/include/Objects/Document.php index 93f02ae5..a68255be 100644 --- a/include/Objects/Document.php +++ b/include/Objects/Document.php @@ -3,31 +3,35 @@ require_once('Objects/BasicObject.php'); /** * The Document class represents a Document on the website. */ -class Document extends BasicObject { - private $_name; - private $_url; - private $_description; +class Document extends BasicObject +{ + private $_name; + private $_url; + private $_description; - /* Document object constructor. */ - public function __construct($data) { - $this->_name = $data['name']; - $this->_url = $data['url']; - $this->_description = $data['description']; - } + /* Document object constructor. */ + public function __construct($data) + { + $this->_name = $data['name']; + $this->_url = $data['url']; + $this->_description = $data['description']; + } - /* Get the name. */ - public function getName() { - return $this->_name; - } + /* Get the name. */ + public function getName() + { + return $this->_name; + } - /* Get the URL. */ - public function getURL() { - return $this->_url; - } + /* Get the URL. */ + public function getURL() + { + return $this->_url; + } - /* Get the description. */ - public function getDescription() { - return $this->_description; - } + /* Get the description. */ + public function getDescription() + { + return $this->_description; + } } -?> diff --git a/include/Objects/File.php b/include/Objects/File.php index 9d440e33..7ef65572 100644 --- a/include/Objects/File.php +++ b/include/Objects/File.php @@ -3,125 +3,132 @@ require_once('Objects/BasicObject.php'); /** * The File object represents a file on the website. */ -class File extends BasicObject { - private $_category_icon; - private $_url; - private $_name; - private $_type; - private $_extra_info; - private $_user_agent; +class File extends BasicObject +{ + private $_category_icon; + private $_url; + private $_name; + private $_type; + private $_extra_info; + private $_user_agent; - public function __construct($data, $baseurl=null, $baseturl=null) { - $this->_category_icon = $data['category_icon']; - $this->_name = $data['name']; - $this->_extra_info = $data['extra_info']; - $this->_type = strtolower($data['type']); - $this->_user_agent = isset($data["user_agent"]) ? $data["user_agent"] : ""; + public function __construct($data, $baseurl = null, $baseturl = null) + { + $this->_category_icon = $data['category_icon']; + $this->_name = $data['name']; + $this->_extra_info = $data['extra_info']; + $this->_type = strtolower($data['type']); + $this->_user_agent = isset($data["user_agent"]) ? $data["user_agent"] : ""; - $fname = ""; + $fname = ""; - /* If it's not an array, we didn't get any attributes. */ - if (!is_array($data['url'])) { - $url = $data['url']; - $attributes = array(); - } else { - $url = $data['url'][0]; - $attributes = $data['url']['@attributes']; - } - - if (!preg_match('/^((https?)|(ftp)):\/\//', $url)) { - if ($attributes['type'] == 'downloads') { - $url = DIR_DOWNLOADS . "/{$url}"; - } else if ($attributes['type'] == 'tools') { - $url = $baseturl . $url; - } else { - $url = $baseurl . $url; - } - - $fname = "." . $url; - $fname = str_replace('{$release}', RELEASE, $fname); - $fname = str_replace('{$release_tools}', RELEASE_TOOLS, $fname); - - if (is_file($fname) && is_readable($fname)) { - $this->_extra_info = array(); - $sz = round((@filesize($fname) / 1024)); - - if ($sz < 1024) { - $sz = $sz . "K"; - } else { - $sz /= 1024; - - if ($sz < 1024) { - $sz = round($sz, 1) . "M"; - } else { - $sz /= 1024; - $sz = round($sz, 2) . "G"; - } - } - $this->_extra_info['size'] = $sz; - $ext = substr($url, (strrpos($url, '.'))); - - if ($ext == '.bz2' || $ext == '.gz' || $ext == '.xz' || $ext == '.7z') - $ext = substr($url, strrpos($url, '.', -(strlen($url) - strrpos($url, '.') + 1))); - - if ( (is_file($fname . '.sha256') && is_readable($fname . '.sha256')) - && (@filemtime($fname . '.sha256') > @filemtime($fname)) ) - { - $this->_extra_info['sha256'] = file_get_contents($fname . '.sha256'); + /* If it's not an array, we didn't get any attributes. */ + if (!is_array($data['url'])) { + $url = $data['url']; + $attributes = array(); } else { - $hash = hash_file('sha256', $fname); - $this->_extra_info['sha256'] = $hash; - file_put_contents($fname . '.sha256', $hash); + $url = $data['url'][0]; + $attributes = $data['url']['@attributes']; } - $this->_extra_info['ext'] = $ext; - $this->_extra_info['msg'] = $data['extra_msg']; - } - } - $this->_url = $url; + if (!preg_match('/^((https?)|(ftp)):\/\//', $url)) { + if ($attributes['type'] == 'downloads') { + $url = DIR_DOWNLOADS . "/{$url}"; + } elseif ($attributes['type'] == 'tools') { + $url = $baseturl . $url; + } else { + $url = $baseurl . $url; + } - /** - * Get the filesize/last modified information and put it in - * $this->_extra_info. - */ - if ($attributes['extra_info'] == 'true') { - if (is_file($fname) && is_readable($fname)) { - $this->_extra_info['date'] = date('F j, Y, g:i a', @filemtime($fname)); - if (!is_null($data['extra_info'])) { - $this->_extra_info['info'] = $data['extra_info']; - } - } - } - } + $fname = "." . $url; + $fname = str_replace('{$release}', RELEASE, $fname); + $fname = str_replace('{$release_tools}', RELEASE_TOOLS, $fname); - /* Get the category icon. */ - public function getCategoryIcon() { - return $this->_category_icon; - } + if (is_file($fname) && is_readable($fname)) { + $this->_extra_info = array(); + $sz = round((@filesize($fname) / 1024)); - /* Get the URL. */ - public function getURL() { - return $this->_url; - } + if ($sz < 1024) { + $sz = $sz . "K"; + } else { + $sz /= 1024; - /* Get the name. */ - public function getName() { - return $this->_name; - } + if ($sz < 1024) { + $sz = round($sz, 1) . "M"; + } else { + $sz /= 1024; + $sz = round($sz, 2) . "G"; + } + } + $this->_extra_info['size'] = $sz; + $ext = substr($url, (strrpos($url, '.'))); - /* Get the type. */ - public function getType() { - return $this->_type; - } + if ($ext == '.bz2' || $ext == '.gz' || $ext == '.xz' || $ext == '.7z') { + $ext = substr($url, strrpos($url, '.', -(strlen($url) - strrpos($url, '.') + 1))); + } - /* Get the extra information. */ - public function getExtraInfo() { - return $this->_extra_info; - } + if ((is_file($fname . '.sha256') && is_readable($fname . '.sha256')) + && (@filemtime($fname . '.sha256') > @filemtime($fname)) ) { + $this->_extra_info['sha256'] = file_get_contents($fname . '.sha256'); + } else { + $hash = hash_file('sha256', $fname); + $this->_extra_info['sha256'] = $hash; + file_put_contents($fname . '.sha256', $hash); + } - /* Get the user-agent. */ - public function getUserAgent() { - return $this->_user_agent; - } + $this->_extra_info['ext'] = $ext; + $this->_extra_info['msg'] = $data['extra_msg']; + } + } + $this->_url = $url; + + /** + * Get the filesize/last modified information and put it in + * $this->_extra_info. + */ + if ($attributes['extra_info'] == 'true') { + if (is_file($fname) && is_readable($fname)) { + $this->_extra_info['date'] = date('F j, Y, g:i a', @filemtime($fname)); + if (!is_null($data['extra_info'])) { + $this->_extra_info['info'] = $data['extra_info']; + } + } + } + } + + /* Get the category icon. */ + public function getCategoryIcon() + { + return $this->_category_icon; + } + + /* Get the URL. */ + public function getURL() + { + return $this->_url; + } + + /* Get the name. */ + public function getName() + { + return $this->_name; + } + + /* Get the type. */ + public function getType() + { + return $this->_type; + } + + /* Get the extra information. */ + public function getExtraInfo() + { + return $this->_extra_info; + } + + /* Get the user-agent. */ + public function getUserAgent() + { + return $this->_user_agent; + } } -?> diff --git a/include/Objects/GameDemo.php b/include/Objects/GameDemo.php index c5766ad3..b702ded2 100644 --- a/include/Objects/GameDemo.php +++ b/include/Objects/GameDemo.php @@ -3,38 +3,43 @@ require_once('Objects/BasicObject.php'); /** * The GameDemo class represents a game demo item on the website. */ -class GameDemo extends BasicObject { - private $_name; - private $_url; - private $_target; - private $_category; - - /* GameDemo object constructor. */ - public function __construct($data) { - $this->_name = $data['name']; - $this->_url = $data['url']; - $this->_target = $data['target']; - $this->_category = isset($data['category']) ? $data['category'] : $data['target']; - } +class GameDemo extends BasicObject +{ + private $_name; + private $_url; + private $_target; + private $_category; + + /* GameDemo object constructor. */ + public function __construct($data) + { + $this->_name = $data['name']; + $this->_url = $data['url']; + $this->_target = $data['target']; + $this->_category = isset($data['category']) ? $data['category'] : $data['target']; + } - /* Get the name of the demo. */ - public function getName() { - return $this->_name; - } + /* Get the name of the demo. */ + public function getName() + { + return $this->_name; + } - /* Get the download URL for the demo. */ - public function getURL() { - return $this->_url; - } + /* Get the download URL for the demo. */ + public function getURL() + { + return $this->_url; + } - /* Get the target name for the demo. */ - public function getTarget() { - return $this->_target; - } - - /* Get the category for the demo. */ - public function getCategory() { - return $this->_category; - } + /* Get the target name for the demo. */ + public function getTarget() + { + return $this->_target; + } + + /* Get the category for the demo. */ + public function getCategory() + { + return $this->_category; + } } -?> diff --git a/include/Objects/MenuItem.php b/include/Objects/MenuItem.php index 700d210a..c835e47b 100644 --- a/include/Objects/MenuItem.php +++ b/include/Objects/MenuItem.php @@ -3,34 +3,38 @@ require_once('Objects/BasicObject.php'); /** * The menu class represents a sidebar menu group on the website. */ -class MenuItem extends BasicObject { - private $_name; - private $_class; - private $_entries; +class MenuItem extends BasicObject +{ + private $_name; + private $_class; + private $_entries; - /* Menu object constructor. */ - public function __construct($data) { - $this->_name = $data['name']; - $this->_class = $data['class']; - $this->_entries = array(); - foreach ($data['link'] as $key => $value) { - $this->_entries[$value['name']] = $value['href']; - } - } + /* Menu object constructor. */ + public function __construct($data) + { + $this->_name = $data['name']; + $this->_class = $data['class']; + $this->_entries = array(); + foreach ($data['link'] as $key => $value) { + $this->_entries[$value['name']] = $value['href']; + } + } - /* Get the name. */ - public function getName() { - return $this->_name; - } + /* Get the name. */ + public function getName() + { + return $this->_name; + } - /* Get the CSS class. */ - public function getClass() { - return $this->_class; - } + /* Get the CSS class. */ + public function getClass() + { + return $this->_class; + } - /* Get the list of links, with the name as key and URL as value. */ - public function getEntries() { - return $this->_entries; - } + /* Get the list of links, with the name as key and URL as value. */ + public function getEntries() + { + return $this->_entries; + } } -?> diff --git a/include/Objects/News.php b/include/Objects/News.php index 430d4a34..2aaae6a0 100644 --- a/include/Objects/News.php +++ b/include/Objects/News.php @@ -3,76 +3,84 @@ require_once('Objects/BasicObject.php'); /** * The news class represents a news item on the website. */ -class News extends BasicObject { - private $_title; - private $_date; - private $_author; - private $_image; - private $_content; - private $_filename; +class News extends BasicObject +{ + private $_title; + private $_date; + private $_author; + private $_image; + private $_content; + private $_filename; - /** - * News object constructor that extracts the data from the JSON scheme - * used. The format looks like this: - * + /** + * News object constructor that extracts the data from the JSON scheme + * used. The format looks like this: + * * { * "title": "Article Title", * "content": "Your article content goes here", * "date": "UNIX timestamp", * "author": "Name" * } - * - * - */ - public function __construct($data, $filename, $processContent = false) { - $this->_title = $processContent ? $this->processText($data->title) : $data->title; - $this->_date = $data->date; - $this->_author = $data->author; - $this->_content = $processContent ? $this->processText($data->content) : $data->content; - $this->_filename = basename($filename); - } + * + * + */ + public function __construct($data, $filename, $processContent = false) + { + $this->_title = $processContent ? $this->processText($data->title) : $data->title; + $this->_date = $data->date; + $this->_author = $data->author; + $this->_content = $processContent ? $this->processText($data->content) : $data->content; + $this->_filename = basename($filename); + } - /** - * Search and replace specific text from the title and content of a news item. - * Used to filter out entities from the RSS/atom feeds that are not in the XML - * standard. - * - * Check: - * http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references - * for a list of valid entities for both XML and HTML - */ - function processText($text) { - return html_entity_decode($text, ENT_COMPAT, 'UTF-8'); - } + /** + * Search and replace specific text from the title and content of a news item. + * Used to filter out entities from the RSS/atom feeds that are not in the XML + * standard. + * + * Check: + * http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references + * for a list of valid entities for both XML and HTML + */ + function processText($text) + { + return html_entity_decode($text, ENT_COMPAT, 'UTF-8'); + } - /* Get the title. */ - public function getTitle() { - return $this->_title; - } + /* Get the title. */ + public function getTitle() + { + return $this->_title; + } - /* Get the date. */ - public function getDate() { - return $this->_date; - } + /* Get the date. */ + public function getDate() + { + return $this->_date; + } - /* Get the author. */ - public function getAuthor() { - return $this->_author; - } + /* Get the author. */ + public function getAuthor() + { + return $this->_author; + } - /* Get the content. */ - public function getContent() { - return $this->_content; - } + /* Get the content. */ + public function getContent() + { + return $this->_content; + } - /* Get the filename. */ - public function getFilename() { - return $this->_filename; - } + /* Get the filename. */ + public function getFilename() + { + return $this->_filename; + } /* Get the News link. */ - public function getLink() { - return URL_BASE . 'news/' . substr( $this->_filename, 0, -5); - } + public function getLink() + { + return URL_BASE . 'news/' . substr($this->_filename, 0, -5); + } } -?> diff --git a/include/Objects/Person.php b/include/Objects/Person.php index f4bd2fec..b778683d 100644 --- a/include/Objects/Person.php +++ b/include/Objects/Person.php @@ -4,31 +4,35 @@ require_once('Objects/BasicObject.php'); * The Person class represents a person entry on the credits page on the * website. */ -class Person extends BasicObject { - private $_name; - private $_alias; - private $_description; +class Person extends BasicObject +{ + private $_name; + private $_alias; + private $_description; - /* Person object constructor. */ - public function __construct($args) { - $this->_name = $args['name']; - $this->_alias = $args['alias']; - $this->_description = $args['description']; - } + /* Person object constructor. */ + public function __construct($args) + { + $this->_name = $args['name']; + $this->_alias = $args['alias']; + $this->_description = $args['description']; + } - /* Get the name. */ - public function getName() { - return $this->_name; - } + /* Get the name. */ + public function getName() + { + return $this->_name; + } - /* Get the alias. */ - public function getAlias() { - return $this->_alias; - } + /* Get the alias. */ + public function getAlias() + { + return $this->_alias; + } - /* Get the description. */ - public function getDescription() { - return $this->_description; - } + /* Get the description. */ + public function getDescription() + { + return $this->_description; + } } -?> diff --git a/include/Objects/Project.php b/include/Objects/Project.php index 979af28c..a95e1c2f 100644 --- a/include/Objects/Project.php +++ b/include/Objects/Project.php @@ -3,50 +3,54 @@ require_once('Objects/BasicObject.php'); /** * The Project class represents a subproject on the website. */ -class Project extends BasicObject { - private $_name; - private $_info; - private $_downloads; +class Project extends BasicObject +{ + private $_name; + private $_info; + private $_downloads; - /* Project object constructor. */ - public function __construct($data) { - $this->_name = $data['name']; - $this->_info = $data['info']; - $this->_downloads = $data['downloads']; - /*$this->_downloads = array(); - parent::toArray($data['download']); - foreach ($data['download'] as $ddata) { - $download = array( - 'name' => $ddata['name'], - 'filename' => $ddata['filename'], - 'type' => $ddata['type'], - ); - # Add detailed information about daily builds. - if ($ddata['type'] == 'SVN_DAILY') { - $url = DIR_DOWNLOADS . "/{$ddata['filename']}"; - $download['info'] = array( - 'url' => $url, - 'filesize' => intval(@filesize($url) / 1024), - 'modified' => date('F j, Y, g:i a', @filemtime($url)), - ); - } - $this->_downloads[] = $download; - }*/ - } + /* Project object constructor. */ + public function __construct($data) + { + $this->_name = $data['name']; + $this->_info = $data['info']; + $this->_downloads = $data['downloads']; + /*$this->_downloads = array(); + parent::toArray($data['download']); + foreach ($data['download'] as $ddata) { + $download = array( + 'name' => $ddata['name'], + 'filename' => $ddata['filename'], + 'type' => $ddata['type'], + ); + # Add detailed information about daily builds. + if ($ddata['type'] == 'SVN_DAILY') { + $url = DIR_DOWNLOADS . "/{$ddata['filename']}"; + $download['info'] = array( + 'url' => $url, + 'filesize' => intval(@filesize($url) / 1024), + 'modified' => date('F j, Y, g:i a', @filemtime($url)), + ); + } + $this->_downloads[] = $download; + }*/ + } - /* Get the name of the project. */ - public function getName() { - return $this->_name; - } + /* Get the name of the project. */ + public function getName() + { + return $this->_name; + } - /* Get the information text for this project. */ - public function getInfo() { - return $this->_info; - } + /* Get the information text for this project. */ + public function getInfo() + { + return $this->_info; + } - /* Get the list of downloads available for this project. */ - public function getDownloads() { - return $this->_downloads; - } + /* Get the list of downloads available for this project. */ + public function getDownloads() + { + return $this->_downloads; + } } -?> diff --git a/include/Objects/QAEntry.php b/include/Objects/QAEntry.php index afd73d80..af0e793d 100644 --- a/include/Objects/QAEntry.php +++ b/include/Objects/QAEntry.php @@ -4,71 +4,76 @@ require_once('Objects/BasicObject.php'); * The QAEntry class represents a question-answer pair on the website * F.A.Q. page. */ -class QAEntry extends BasicObject { - private $_hrefs; - private $_question; - private $_answer; - private $_xref; +class QAEntry extends BasicObject +{ + private $_hrefs; + private $_question; + private $_answer; + private $_xref; - /** - * QAEntry object constructor. - * - * @param array $data list containing all qaentry data - * @param int $section_number the section this entry belongs too - * @param int $entry_number part of the href value incase it's not set - * @param array $xref reference to xref map - */ - public function __construct($data, $section_number, $entry_number, &$xref) { - $this->_hrefs = array(); - if (! empty($data['href'])) { - array_push($this->_hrefs, $data['href']); - $xref[$data['href']] = $data['question']; - } - array_push($this->_hrefs, "{$section_number}_{$entry_number}"); + /** + * QAEntry object constructor. + * + * @param array $data list containing all qaentry data + * @param int $section_number the section this entry belongs too + * @param int $entry_number part of the href value incase it's not set + * @param array $xref reference to xref map + */ + public function __construct($data, $section_number, $entry_number, &$xref) + { + $this->_hrefs = array(); + if (! empty($data['href'])) { + array_push($this->_hrefs, $data['href']); + $xref[$data['href']] = $data['question']; + } + array_push($this->_hrefs, "{$section_number}_{$entry_number}"); - $this->_question = $data['question']; - $this->_answer = $data['answer']; - /* Save a reference to the xref table for later use. */ - $this->_xref = &$xref; - } + $this->_question = $data['question']; + $this->_answer = $data['answer']; + /* Save a reference to the xref table for later use. */ + $this->_xref = &$xref; + } - /* Get the primary anchor name for this entry. */ - public function getHref() { - return $this->_hrefs[0]; - } + /* Get the primary anchor name for this entry. */ + public function getHref() + { + return $this->_hrefs[0]; + } - /* Get all anchor names for this entry. */ - public function getHrefs() { - return $this->_hrefs; - } + /* Get all anchor names for this entry. */ + public function getHrefs() + { + return $this->_hrefs; + } - /* Get the question for this entry. */ - public function getQuestion() { - return $this->_question; - } + /* Get the question for this entry. */ + public function getQuestion() + { + return $this->_question; + } - /* Get the answer for this entry. */ - public function getAnswer() { - $answer = &$this->_answer; - $xref = &$this->_xref; - /* If we find a xref we need to make the final conversion to HTML. */ - if (strpos($answer, '_xref as $anchor => $text) { - $xref['pattern'][] = "/<\/a>/"; - $xref['replace'][] = "{$text}"; - } - } - $answer = preg_replace($xref['pattern'], $xref['replace'], $answer); - } - return $this->_answer; - } + /* Get the answer for this entry. */ + public function getAnswer() + { + $answer = &$this->_answer; + $xref = &$this->_xref; + /* If we find a xref we need to make the final conversion to HTML. */ + if (strpos($answer, '_xref as $anchor => $text) { + $xref['pattern'][] = "/<\/a>/"; + $xref['replace'][] = "{$text}"; + } + } + $answer = preg_replace($xref['pattern'], $xref['replace'], $answer); + } + return $this->_answer; + } } -?> diff --git a/include/Objects/QASection.php b/include/Objects/QASection.php index 5aba60b6..b5eefea3 100644 --- a/include/Objects/QASection.php +++ b/include/Objects/QASection.php @@ -5,44 +5,48 @@ require_once('Objects/QAEntry.php'); * The QASection class represents a section with questions and answers on the * website F.A.Q. page. */ -class QASection extends BasicObject { - private $_title; - private $_entries; - private $_toc; +class QASection extends BasicObject +{ + private $_title; + private $_entries; + private $_toc; - /** - * QASection object constructor. - * - * @param array $data list containing all qasection data - * @param int $section_number used in the TOC - * @param array $xref reference to xref map - */ - public function __construct($data, $section_number, &$xref) { - $this->_title = $data['title']; - $this->_entries = array(); - $this->_toc = array(); - parent::toArray($data['entry']); - $count = 1; - foreach ($data['entry'] as $key => $value) { - $qa = new QAEntry($value, $section_number, $count++, $xref); - $this->_entries[] = $qa; - $this->_toc[$qa->getHref()] = $qa->getQuestion(); - } - } + /** + * QASection object constructor. + * + * @param array $data list containing all qasection data + * @param int $section_number used in the TOC + * @param array $xref reference to xref map + */ + public function __construct($data, $section_number, &$xref) + { + $this->_title = $data['title']; + $this->_entries = array(); + $this->_toc = array(); + parent::toArray($data['entry']); + $count = 1; + foreach ($data['entry'] as $key => $value) { + $qa = new QAEntry($value, $section_number, $count++, $xref); + $this->_entries[] = $qa; + $this->_toc[$qa->getHref()] = $qa->getQuestion(); + } + } - /* Get the title of this section. */ - public function getTitle() { - return $this->_title; - } + /* Get the title of this section. */ + public function getTitle() + { + return $this->_title; + } - /* Get a list with all question-answer entries for this section. */ - public function getEntries() { - return $this->_entries; - } + /* Get a list with all question-answer entries for this section. */ + public function getEntries() + { + return $this->_entries; + } - /* Get the table of contents for this section. */ - public function getTOC() { - return $this->_toc; - } + /* Get the table of contents for this section. */ + public function getTOC() + { + return $this->_toc; + } } -?> diff --git a/include/Objects/Screenshot.php b/include/Objects/Screenshot.php index c5672e82..f2dd70d7 100644 --- a/include/Objects/Screenshot.php +++ b/include/Objects/Screenshot.php @@ -3,56 +3,61 @@ require_once('Objects/BasicObject.php'); /** * The Screenshot object represents all screenshots for one game. */ -class Screenshot extends BasicObject { - private $_name; - private $_category; - private $_files; +class Screenshot extends BasicObject +{ + private $_name; + private $_category; + private $_files; - /* The Screenshot object constructor. */ - public function __construct($data) { - $this->_name = $data['name']; - $this->_category = $data['category']; - $this->_files = array(); - if (isset($data['image'])) { - if (!isset($data['image'][0])) - parent::toArray($data['image']); + /* The Screenshot object constructor. */ + public function __construct($data) + { + $this->_name = $data['name']; + $this->_category = $data['category']; + $this->_files = array(); + if (isset($data['image'])) { + if (!isset($data['image'][0])) { + parent::toArray($data['image']); + } - foreach ($data['image'] as $value) { - if (isset($value['range'])) { - $attr = $value['range']['@attributes']; - if (!isset($attr['from']) || !isset($attr['to']) || !isset($attr['format']) || !strstr($value['file'], '#n#')) { - throw new ErrorException('Invalid range format for ' . $value['file']); - } - $pat = str_replace("#n#", $attr['format'], $value['file']); - for ($num = $attr['from']; $num <= $attr['to']; $num++) { - $this->_files[] = array( - 'filename' => sprintf($pat, $num), - 'caption' => $value['caption'], - ); - } - } else { - $this->_files[] = array( - 'filename' => $value['file'], - 'caption' => $value['caption'], - ); - } - } - } - } + foreach ($data['image'] as $value) { + if (isset($value['range'])) { + $attr = $value['range']['@attributes']; + if (!isset($attr['from']) || !isset($attr['to']) || !isset($attr['format']) || !strstr($value['file'], '#n#')) { + throw new ErrorException('Invalid range format for ' . $value['file']); + } + $pat = str_replace("#n#", $attr['format'], $value['file']); + for ($num = $attr['from']; $num <= $attr['to']; $num++) { + $this->_files[] = array( + 'filename' => sprintf($pat, $num), + 'caption' => $value['caption'], + ); + } + } else { + $this->_files[] = array( + 'filename' => $value['file'], + 'caption' => $value['caption'], + ); + } + } + } + } - /* Get the name. */ - public function getName() { - return $this->_name; - } + /* Get the name. */ + public function getName() + { + return $this->_name; + } - /* Get the category this screenshot belongs too. */ - public function getCategory() { - return $this->_category; - } + /* Get the category this screenshot belongs too. */ + public function getCategory() + { + return $this->_category; + } - /* Get the list of files, with the base filename as key and the caption as value. */ - public function getFiles() { - return $this->_files; - } + /* Get the list of files, with the base filename as key and the caption as value. */ + public function getFiles() + { + return $this->_files; + } } -?> diff --git a/include/Objects/WebLink.php b/include/Objects/WebLink.php index 10026ba1..2c2d0e1e 100644 --- a/include/Objects/WebLink.php +++ b/include/Objects/WebLink.php @@ -3,36 +3,41 @@ require_once('Objects/BasicObject.php'); /** * The WebLink class represents a link item on the website. */ -class WebLink extends BasicObject { - private $_name; - private $_url; - private $_description; +class WebLink extends BasicObject +{ + private $_name; + private $_url; + private $_description; - /* WebLink object constructor. */ - public function __construct($data) { - $this->_name = $data['name']; - $this->_url = $data['url']; - $this->_description = $data['description']; - } + /* WebLink object constructor. */ + public function __construct($data) + { + $this->_name = $data['name']; + $this->_url = $data['url']; + $this->_description = $data['description']; + } - /* Get the name of the link. */ - public function getName() { - return $this->_name; - } + /* Get the name of the link. */ + public function getName() + { + return $this->_name; + } - /* Get the URL of the link. */ - public function getURL() { - return $this->_url; - } + /* Get the URL of the link. */ + public function getURL() + { + return $this->_url; + } - /* Get the description of the link. */ - public function getDescription() { - return $this->_description; - } - - /* Get the user-agent. */ - public function getUserAgent() { - return ""; - } + /* Get the description of the link. */ + public function getDescription() + { + return $this->_description; + } + + /* Get the user-agent. */ + public function getUserAgent() + { + return ""; + } } -?> diff --git a/include/Pages/CompatibilityPage.php b/include/Pages/CompatibilityPage.php index 64f85e2e..c1113f80 100644 --- a/include/Pages/CompatibilityPage.php +++ b/include/Pages/CompatibilityPage.php @@ -6,104 +6,108 @@ require_once('Models/CompatibilityModel.php'); * either displays the full list of games, or specific details about one * game. It defaults to showing the compatibility list of the DEV-version. */ -class CompatibilityPage extends Controller { - private $_template; - private $_template_details; - private $_supportLevelDesc; - private $_supportLevelClass; +class CompatibilityPage extends Controller +{ + private $_template; + private $_template_details; + private $_supportLevelDesc; + private $_supportLevelClass; - /* Constructor. */ - public function __construct() { - parent::__construct(); - global $Smarty; - $this->_template = 'pages/compatibility.tpl'; - $this->_template_details = 'components/compatibility_details.tpl'; - $this->_supportLevelDesc = array( - 'untested' => $Smarty->getConfigVars('compatibilityUntested'), - 'broken' => $Smarty->getConfigVars('compatibilityBroken'), - 'bugged' => $Smarty->getConfigVars('compatibilityBugged'), - 'good' => $Smarty->getConfigVars('compatibilityGood'), - 'excellent' => $Smarty->getConfigVars('compatibilityExcellent') - ); - $this->_supportLevelClass = array( - 'untested' => 'pctU', - 'broken' => 'pct0', - 'bugged' => 'pct50', - 'good' => 'pct75', - 'excellent' => 'pct100' - ); - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + global $Smarty; + $this->_template = 'pages/compatibility.tpl'; + $this->_template_details = 'components/compatibility_details.tpl'; + $this->_supportLevelDesc = array( + 'untested' => $Smarty->getConfigVars('compatibilityUntested'), + 'broken' => $Smarty->getConfigVars('compatibilityBroken'), + 'bugged' => $Smarty->getConfigVars('compatibilityBugged'), + 'good' => $Smarty->getConfigVars('compatibilityGood'), + 'excellent' => $Smarty->getConfigVars('compatibilityExcellent') + ); + $this->_supportLevelClass = array( + 'untested' => 'pctU', + 'broken' => 'pct0', + 'bugged' => 'pct50', + 'good' => 'pct75', + 'excellent' => 'pct100' + ); + } - /* Display the index page. */ - public function index() { - $version = (!empty($_GET['v']) ? $_GET['v'] : 'DEV'); - $target = $_GET['t']; + /* Display the index page. */ + public function index() + { + $version = (!empty($_GET['v']) ? $_GET['v'] : 'DEV'); + $target = $_GET['t']; - /* Default to DEV */ - $versions = CompatibilityModel::getAllVersions(); - if (!in_array($version, $versions)) { - $version = 'DEV'; - } + /* Default to DEV */ + $versions = CompatibilityModel::getAllVersions(); + if (!in_array($version, $versions)) { + $version = 'DEV'; + } - if ($version === 'DEV' || (CompatibilityModel::compareVersions($version, COMPAT_LAYOUT_CHANGE) >= 0)) { - $oldLayout = 'no'; - } else { - $oldLayout = 'yes'; - } + if ($version === 'DEV' || (CompatibilityModel::compareVersions($version, COMPAT_LAYOUT_CHANGE) >= 0)) { + $oldLayout = 'no'; + } else { + $oldLayout = 'yes'; + } - if (!empty($target)) { - return $this->getGame($target, $version, $oldLayout); - } else { - return $this->getAll($version, $versions, $oldLayout); - } - } + if (!empty($target)) { + return $this->getGame($target, $version, $oldLayout); + } else { + return $this->getAll($version, $versions, $oldLayout); + } + } - /* We should show detailed information for a specific target. */ - public function getGame($target, $version, $oldLayout) { - $game = CompatibilityModel::getGameData($version, $target); - global $Smarty; - - return $this->renderPage( - array( - 'title' => preg_replace('/{version}/', $version, $Smarty->getConfigVars('compatibilityTitle')), - 'content_title' => preg_replace('/{version}/', $version, $Smarty->getConfigVars('compatibilityContentTitle')), - 'version' => $version, - 'game' => $game, - 'old_layout' => $oldLayout, - 'support_level_desc' => $this->_supportLevelDesc, - 'support_level_class' => $this->_supportLevelClass - ), - $this->_template_details - ); - } + /* We should show detailed information for a specific target. */ + public function getGame($target, $version, $oldLayout) + { + $game = CompatibilityModel::getGameData($version, $target); + global $Smarty; + + return $this->renderPage( + array( + 'title' => preg_replace('/{version}/', $version, $Smarty->getConfigVars('compatibilityTitle')), + 'content_title' => preg_replace('/{version}/', $version, $Smarty->getConfigVars('compatibilityContentTitle')), + 'version' => $version, + 'game' => $game, + 'old_layout' => $oldLayout, + 'support_level_desc' => $this->_supportLevelDesc, + 'support_level_class' => $this->_supportLevelClass + ), + $this->_template_details + ); + } - /* We should show all the compatibility stats for a specific version. */ - public function getAll($version, $versions, $oldLayout) { - /* Remove the current version from the versions array. */ - if ($version != 'DEV') { - $key = array_search($version, $versions); - unset($versions[$key]); - } - $filename = DIR_COMPAT . "/compat-{$version}.xml"; - $last_updated = date("F d, Y", @filemtime($filename)); - $compat_data = CompatibilityModel::getAllData($version); + /* We should show all the compatibility stats for a specific version. */ + public function getAll($version, $versions, $oldLayout) + { + /* Remove the current version from the versions array. */ + if ($version != 'DEV') { + $key = array_search($version, $versions); + unset($versions[$key]); + } + $filename = DIR_COMPAT . "/compat-{$version}.xml"; + $last_updated = date("F d, Y", @filemtime($filename)); + $compat_data = CompatibilityModel::getAllData($version); - global $Smarty; - - return $this->renderPage( - array( - 'title' => preg_replace('/{version}/', $version, $Smarty->getConfigVars('compatibilityTitle')), - 'content_title' => preg_replace('/{version}/', $version, $Smarty->getConfigVars('compatibilityContentTitle')), - 'version' => $version, - 'compat_data' => $compat_data, - 'last_updated' => $last_updated, - 'versions' => $versions, - 'old_layout' => $oldLayout, - 'support_level_desc' => $this->_supportLevelDesc, - 'support_level_class' => $this->_supportLevelClass - ), - $this->_template - ); - } + global $Smarty; + + return $this->renderPage( + array( + 'title' => preg_replace('/{version}/', $version, $Smarty->getConfigVars('compatibilityTitle')), + 'content_title' => preg_replace('/{version}/', $version, $Smarty->getConfigVars('compatibilityContentTitle')), + 'version' => $version, + 'compat_data' => $compat_data, + 'last_updated' => $last_updated, + 'versions' => $versions, + 'old_layout' => $oldLayout, + 'support_level_desc' => $this->_supportLevelDesc, + 'support_level_class' => $this->_supportLevelClass + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/ContactPage.php b/include/Pages/ContactPage.php index d76bb8c0..2b9794c2 100644 --- a/include/Pages/ContactPage.php +++ b/include/Pages/ContactPage.php @@ -1,26 +1,28 @@ _template = 'pages/contact.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/contact.tpl'; + } - /* Display the index page. */ - public function index() { - global $Smarty; + /* Display the index page. */ + public function index() + { + global $Smarty; - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('contactTitle'), - 'content_title' => $Smarty->getConfigVars('contactContentTitle'), - ), - $this->_template - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('contactTitle'), + 'content_title' => $Smarty->getConfigVars('contactContentTitle'), + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/CreditsPage.php b/include/Pages/CreditsPage.php index b1053a96..40134cc0 100644 --- a/include/Pages/CreditsPage.php +++ b/include/Pages/CreditsPage.php @@ -2,28 +2,30 @@ require_once('Controller.php'); require_once('Models/CreditsModel.php'); -class CreditsPage extends Controller { - private $template; +class CreditsPage extends Controller +{ + private $template; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template = 'pages/credits.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/credits.tpl'; + } - /* Display the index page. */ - public function index() { - $credits = CreditsModel::getAllCredits(); - global $Smarty; - - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('creditsTitle'), - 'content_title' => $Smarty->getConfigVars('creditsContentTitle'), - 'credits' => $credits, - ), - $this->_template - ); - } + /* Display the index page. */ + public function index() + { + $credits = CreditsModel::getAllCredits(); + global $Smarty; + + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('creditsTitle'), + 'content_title' => $Smarty->getConfigVars('creditsContentTitle'), + 'credits' => $credits, + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/DemosPage.php b/include/Pages/DemosPage.php index 2d978a4f..52e8ed92 100644 --- a/include/Pages/DemosPage.php +++ b/include/Pages/DemosPage.php @@ -2,28 +2,30 @@ require_once('Controller.php'); require_once('Models/GameDemosModel.php'); -class DemosPage extends Controller { - private $_template; +class DemosPage extends Controller +{ + private $_template; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template = 'pages/game_demos.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/game_demos.tpl'; + } - /* Display the index page. */ - public function index() { - $demos = GameDemosModel::getAllGroupsAndDemos(); - global $Smarty; + /* Display the index page. */ + public function index() + { + $demos = GameDemosModel::getAllGroupsAndDemos(); + global $Smarty; - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('demosTitle'), - 'content_title' => $Smarty->getConfigVars('demosContentTitle'), - 'demos' => $demos, - ), - $this->_template - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('demosTitle'), + 'content_title' => $Smarty->getConfigVars('demosContentTitle'), + 'demos' => $demos, + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/DocumentationPage.php b/include/Pages/DocumentationPage.php index a7cbb9bc..400a7ca7 100644 --- a/include/Pages/DocumentationPage.php +++ b/include/Pages/DocumentationPage.php @@ -2,30 +2,32 @@ require_once('Controller.php'); require_once('Models/DocumentationModel.php'); -class DocumentationPage extends Controller { - private $_template; +class DocumentationPage extends Controller +{ + private $_template; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template = 'pages/documentation.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/documentation.tpl'; + } - /* Display the index page. */ - public function index() { - $document = $_GET['d']; - global $Smarty; + /* Display the index page. */ + public function index() + { + $document = $_GET['d']; + global $Smarty; - $documents = DocumentationModel::getAllDocuments(); + $documents = DocumentationModel::getAllDocuments(); - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('documentationTitle'), - 'content_title' => $Smarty->getConfigVars('documentationContentTitle'), - 'documents' => $documents, - ), - $this->_template - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('documentationTitle'), + 'content_title' => $Smarty->getConfigVars('documentationContentTitle'), + 'documents' => $documents, + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/DownloadsPage.php b/include/Pages/DownloadsPage.php index 1e1cb1fa..d9172c69 100644 --- a/include/Pages/DownloadsPage.php +++ b/include/Pages/DownloadsPage.php @@ -2,68 +2,72 @@ require_once('Controller.php'); require_once('Models/DownloadsModel.php'); -class DownloadsPage extends Controller { - private $_template; +class DownloadsPage extends Controller +{ + private $_template; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template = 'pages/downloads.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/downloads.tpl'; + } - function getRecommendedDownloadsJS(&$downloads) { - $js = "var versions = {\n"; + function getRecommendedDownloadsJS(&$downloads) + { + $js = "var versions = {\n"; - foreach ($downloads as $dsection) { - foreach ($dsection->getSubSections() as $dsubsection) { - foreach ($dsubsection->getItems() as $curItem) { - $userAgent = $curItem->getUserAgent(); + foreach ($downloads as $dsection) { + foreach ($dsection->getSubSections() as $dsubsection) { + foreach ($dsubsection->getItems() as $curItem) { + $userAgent = $curItem->getUserAgent(); - if ($userAgent != "") { - $url = str_replace('{$release}', RELEASE, $curItem->getURL()); - sscanf($url, "/frs/scummvm/%s", $versionStr); - $version = substr($versionStr, 0, strpos($versionStr, "/")); - $name = strip_tags($curItem->getName()); - $data = $curItem->getExtraInfo(); - if (is_array($data)) { - $extra_text = $data['size'] . " "; - if ($data['ext'] == '.exe') - $extra_text = $extra_text . 'Win32 '; + if ($userAgent != "") { + $url = str_replace('{$release}', RELEASE, $curItem->getURL()); + sscanf($url, "/frs/scummvm/%s", $versionStr); + $version = substr($versionStr, 0, strpos($versionStr, "/")); + $name = strip_tags($curItem->getName()); + $data = $curItem->getExtraInfo(); + if (is_array($data)) { + $extra_text = $data['size'] . " "; + if ($data['ext'] == '.exe') { + $extra_text = $extra_text . 'Win32 '; + } - $extra_text .= $data['ext'] . " " . $data['msg']; - } else { - $extra_text = $data; - } + $extra_text .= $data['ext'] . " " . $data['msg']; + } else { + $extra_text = $data; + } - $js .= "\t\t\t'{$userAgent}':\t{ 'os':\t'{$name}', 'ver':\t'{$version}', 'desc':\t'{$extra_text}', 'url':\t'{$url}'},\n"; - } - } - } - } - $js .= "};\n"; + $js .= "\t\t\t'{$userAgent}':\t{ 'os':\t'{$name}', 'ver':\t'{$version}', 'desc':\t'{$extra_text}', 'url':\t'{$url}'},\n"; + } + } + } + } + $js .= "};\n"; - return $js; - } + return $js; + } - /* Display the index page. */ - public function index() { - $downloads = DownloadsModel::getAllDownloads(); - $sections = DownloadsModel::getAllSections(); - $recommendedDownloadsJS = $this->getRecommendedDownloadsJS($downloads); - global $Smarty; - - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('downloadsTitle'), - 'content_title' => $Smarty->getConfigVars('downloadsContentTitle'), - 'downloads' => $downloads, - 'sections' => $sections, - 'release_tools' => RELEASE_TOOLS, - 'release_debian' => RELEASE_DEBIAN, - 'recommendedDownloadsJS' => $recommendedDownloadsJS - ), - $this->_template - ); - } + /* Display the index page. */ + public function index() + { + $downloads = DownloadsModel::getAllDownloads(); + $sections = DownloadsModel::getAllSections(); + $recommendedDownloadsJS = $this->getRecommendedDownloadsJS($downloads); + global $Smarty; + + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('downloadsTitle'), + 'content_title' => $Smarty->getConfigVars('downloadsContentTitle'), + 'downloads' => $downloads, + 'sections' => $sections, + 'release_tools' => RELEASE_TOOLS, + 'release_debian' => RELEASE_DEBIAN, + 'recommendedDownloadsJS' => $recommendedDownloadsJS + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/ExceptionsPage.php b/include/Pages/ExceptionsPage.php index b5963fd4..b9172522 100644 --- a/include/Pages/ExceptionsPage.php +++ b/include/Pages/ExceptionsPage.php @@ -1,27 +1,29 @@ _template = 'components/exception.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'components/exception.tpl'; + } - /* Display the index page. */ - public function index($exception) { - global $Smarty; + /* Display the index page. */ + public function index($exception) + { + global $Smarty; - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('exceptionsTitle'), - 'content_title' => $Smarty->getConfigVars('exceptionsContentTitle'), - 'exception' => $exception, - ), - $this->_template - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('exceptionsTitle'), + 'content_title' => $Smarty->getConfigVars('exceptionsContentTitle'), + 'exception' => $exception, + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/FAQPage.php b/include/Pages/FAQPage.php index a4485e43..38b7e036 100644 --- a/include/Pages/FAQPage.php +++ b/include/Pages/FAQPage.php @@ -2,30 +2,32 @@ require_once('Controller.php'); require_once('Models/FAQModel.php'); -class FAQPage extends Controller { - private $_template; +class FAQPage extends Controller +{ + private $_template; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template = 'pages/faq.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/faq.tpl'; + } - /* Display the index page. */ - public function index() { - $contents = FAQModel::getFAQ(); - $modified = FAQModel::getLastUpdated(); - global $Smarty; + /* Display the index page. */ + public function index() + { + $contents = FAQModel::getFAQ(); + $modified = FAQModel::getLastUpdated(); + global $Smarty; - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('faqTitle'), - 'content_title' => $Smarty->getConfigVars('faqContentTitle'), - 'contents' => $contents, - 'modified' => $modified, - ), - $this->_template - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('faqTitle'), + 'content_title' => $Smarty->getConfigVars('faqContentTitle'), + 'contents' => $contents, + 'modified' => $modified, + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/FeedsPage.php b/include/Pages/FeedsPage.php index 9edfaa54..38221e12 100644 --- a/include/Pages/FeedsPage.php +++ b/include/Pages/FeedsPage.php @@ -2,36 +2,38 @@ require_once('Controller.php'); require_once('Models/NewsModel.php'); -class FeedsPage extends Controller { - private $_template_rss; - private $_template_atom; +class FeedsPage extends Controller +{ + private $_template_rss; + private $_template_atom; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template_rss = 'pages/feed_rss.tpl'; - $this->_template_atom = 'pages/feed_atom.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template_rss = 'pages/feed_rss.tpl'; + $this->_template_atom = 'pages/feed_atom.tpl'; + } - /* Display the index page. */ - public function index() { - $feed = $_GET['f']; - if ($feed == 'atom') { - $template = $this->_template_atom; - } else { - $template = $this->_template_rss; - } + /* Display the index page. */ + public function index() + { + $feed = $_GET['f']; + if ($feed == 'atom') { + $template = $this->_template_atom; + } else { + $template = $this->_template_rss; + } - $news_items = NewsModel::getLatestNews(NEWS_ITEMS, true); + $news_items = NewsModel::getLatestNews(NEWS_ITEMS, true); - header('Content-Type: text/xml; charset=UTF-8'); - print $this->fetch( - $template, - array( - 'news' => $news_items, - ) - ); - return True; - } + header('Content-Type: text/xml; charset=UTF-8'); + print $this->fetch( + $template, + array( + 'news' => $news_items, + ) + ); + return true; + } } -?> diff --git a/include/Pages/GamesPage.php b/include/Pages/GamesPage.php index 2b18d51f..a8df729b 100644 --- a/include/Pages/GamesPage.php +++ b/include/Pages/GamesPage.php @@ -2,32 +2,34 @@ require_once('Controller.php'); require_once('Models/GamesModel.php'); -class GamesPage extends Controller { - private $_template; +class GamesPage extends Controller +{ + private $_template; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template = 'pages/games.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/games.tpl'; + } - /* Display the index page. */ - public function index() { - $downloads = GamesModel::getAllDownloads(); - $sections = GamesModel::getAllSections(); - global $Smarty; + /* Display the index page. */ + public function index() + { + $downloads = GamesModel::getAllDownloads(); + $sections = GamesModel::getAllSections(); + global $Smarty; - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('gamesTitle'), - 'content_title' => $Smarty->getConfigVars('gamesContentTitle'), - 'downloads' => $downloads, - 'sections' => $sections, - 'release_tools' => RELEASE_TOOLS, - 'release_debian' => RELEASE_DEBIAN, - ), - $this->_template - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('gamesTitle'), + 'content_title' => $Smarty->getConfigVars('gamesContentTitle'), + 'downloads' => $downloads, + 'sections' => $sections, + 'release_tools' => RELEASE_TOOLS, + 'release_debian' => RELEASE_DEBIAN, + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/LinksPage.php b/include/Pages/LinksPage.php index de8b991e..e838ad9f 100644 --- a/include/Pages/LinksPage.php +++ b/include/Pages/LinksPage.php @@ -2,28 +2,30 @@ require_once('Controller.php'); require_once('Models/LinksModel.php'); -class LinksPage extends Controller { - private $_template; +class LinksPage extends Controller +{ + private $_template; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template = 'pages/links.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/links.tpl'; + } - /* Display the index page. */ - public function index() { - $links = LinksModel::getAllGroupsAndLinks(); - global $Smarty; - - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('linksTitle'), - 'content_title' => $Smarty->getConfigVars('linksContentTitle'), - 'links' => $links, - ), - $this->_template - ); - } + /* Display the index page. */ + public function index() + { + $links = LinksModel::getAllGroupsAndLinks(); + global $Smarty; + + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('linksTitle'), + 'content_title' => $Smarty->getConfigVars('linksContentTitle'), + 'links' => $links, + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/NewsPage.php b/include/Pages/NewsPage.php index e29fa654..2d864d84 100644 --- a/include/Pages/NewsPage.php +++ b/include/Pages/NewsPage.php @@ -3,73 +3,77 @@ require_once('Controller.php'); require_once('Models/NewsModel.php'); require_once('Models/ScreenshotsModel.php'); -class NewsPage extends Controller { - private $_template; +class NewsPage extends Controller +{ + private $_template; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template = 'pages/news.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/news.tpl'; + } - /* Display the index page. */ - public function index() { - $filename = isset($_GET['d']) ? $_GET['d'] : null; + /* Display the index page. */ + public function index() + { + $filename = isset($_GET['d']) ? $_GET['d'] : null; - if ($filename != null) { - if (strtolower($filename) == 'archive' || $filename == '') { - $filename = null; - } - return $this->getNews($filename); - } - return $this->getNewsIntro(); - } + if ($filename != null) { + if (strtolower($filename) == 'archive' || $filename == '') { + $filename = null; + } + return $this->getNews($filename); + } + return $this->getNewsIntro(); + } - /* Display a specific news item, or all news items. */ - public function getNews($filename = null) { - global $Smarty; + /* Display a specific news item, or all news items. */ + public function getNews($filename = null) + { + global $Smarty; - if ($filename == null) { - $news_items = NewsModel::getAllNews(); - $filename = 'archive'; - } else { - $news_items = array(NewsModel::getOneByFilename($filename)); - } + if ($filename == null) { + $news_items = NewsModel::getAllNews(); + $filename = 'archive'; + } else { + $news_items = array(NewsModel::getOneByFilename($filename)); + } - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('newsTitle'), - 'content_title' => $Smarty->getConfigVars('newsContentTitle'), - 'show_intro' => false, - 'news_items' => $news_items, - 'news_archive_link' => false, - ), - $this->_template - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('newsTitle'), + 'content_title' => $Smarty->getConfigVars('newsContentTitle'), + 'show_intro' => false, + 'news_items' => $news_items, + 'news_archive_link' => false, + ), + $this->_template + ); + } - /* Display the main page with limited news items and intro text. */ - public function getNewsIntro() { - global $Smarty; + /* Display the main page with limited news items and intro text. */ + public function getNewsIntro() + { + global $Smarty; - $news_items = NewsModel::getLatestNews(NEWS_ITEMS); - $random_shot = ScreenshotsModel::getRandomScreenshot(); + $news_items = NewsModel::getLatestNews(NEWS_ITEMS); + $random_shot = ScreenshotsModel::getRandomScreenshot(); - $this->addJSFiles(array( - 'baguetteBox.min.js' - )); + $this->addJSFiles(array( + 'baguetteBox.min.js' + )); - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('newsTitle'), - 'content_title' => $Smarty->getConfigVars('newsContentTitle'), - 'show_intro' => true, - 'news_items' => $news_items, - 'news_archive_link' => true, - 'random_shot' => $random_shot, - ), - $this->_template - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('newsTitle'), + 'content_title' => $Smarty->getConfigVars('newsContentTitle'), + 'show_intro' => true, + 'news_items' => $news_items, + 'news_archive_link' => true, + 'random_shot' => $random_shot, + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/PressPage.php b/include/Pages/PressPage.php index b6e06976..02200f9f 100644 --- a/include/Pages/PressPage.php +++ b/include/Pages/PressPage.php @@ -2,28 +2,30 @@ require_once('Controller.php'); require_once('Models/ArticleModel.php'); -class PressPage extends Controller { - private $_template; +class PressPage extends Controller +{ + private $_template; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template = 'pages/press.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/press.tpl'; + } - /* Display the index page. */ - public function index() { - $articles = ArticleModel::getAllArticles(); - global $Smarty; + /* Display the index page. */ + public function index() + { + $articles = ArticleModel::getAllArticles(); + global $Smarty; - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('pressTitle'), - 'content_title' => $Smarty->getConfigVars('pressContentTitle'), - 'articles' => $articles, - ), - $this->_template - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('pressTitle'), + 'content_title' => $Smarty->getConfigVars('pressContentTitle'), + 'articles' => $articles, + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/PressSnowberryPage.php b/include/Pages/PressSnowberryPage.php index f7129fe9..12f9e842 100644 --- a/include/Pages/PressSnowberryPage.php +++ b/include/Pages/PressSnowberryPage.php @@ -2,28 +2,30 @@ require_once('Controller.php'); require_once('Models/ArticleModel.php'); -class PressSnowberryPage extends Controller { - private $_template; +class PressSnowberryPage extends Controller +{ + private $_template; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template = 'pages/press_snowberry.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/press_snowberry.tpl'; + } - /* Display the index page. */ - public function index() { - $articles = ArticleModel::getAllArticles(); - global $Smarty; + /* Display the index page. */ + public function index() + { + $articles = ArticleModel::getAllArticles(); + global $Smarty; - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('pressSnowberryTitle'), - 'content_title' => $Smarty->getConfigVars('pressSnowberryContentTitle'), - 'articles' => $articles, - ), - $this->_template - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('pressSnowberryTitle'), + 'content_title' => $Smarty->getConfigVars('pressSnowberryContentTitle'), + 'articles' => $articles, + ), + $this->_template + ); + } } -?> diff --git a/include/Pages/ScreenshotsPage.php b/include/Pages/ScreenshotsPage.php index ca2d1667..528db1dc 100644 --- a/include/Pages/ScreenshotsPage.php +++ b/include/Pages/ScreenshotsPage.php @@ -2,92 +2,96 @@ require_once('Controller.php'); require_once('Models/ScreenshotsModel.php'); -class ScreenshotsPage extends Controller { - private $_template; - private $_template_category; +class ScreenshotsPage extends Controller +{ + private $_template; + private $_template_category; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template = 'pages/screenshots.tpl'; - $this->_template_category = 'pages/screenshots_category.tpl'; - $this->_template_viewer = 'screenshots_viewer.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/screenshots.tpl'; + $this->_template_category = 'pages/screenshots_category.tpl'; + $this->_template_viewer = 'screenshots_viewer.tpl'; + } - /* Display the index page. */ - public function index() { - $category = $_GET['cat']; - $game = $_GET['game']; - $json = $_POST['json']; + /* Display the index page. */ + public function index() + { + $category = $_GET['cat']; + $game = $_GET['game']; + $json = $_POST['json']; - if (!empty($json)) { - return $this->getAllJSON(); - } else if (!empty($category)) { - return $this->getCategory($category, $game); - } + if (!empty($json)) { + return $this->getAllJSON(); + } elseif (!empty($category)) { + return $this->getCategory($category, $game); + } - $this->addJSFiles(array( - 'baguetteBox.min.js' - )); + $this->addJSFiles(array( + 'baguetteBox.min.js' + )); - $screenshot = ScreenshotsModel::getAllScreenshots(); - $random_shot = ScreenshotsModel::getRandomScreenshot(); + $screenshot = ScreenshotsModel::getAllScreenshots(); + $random_shot = ScreenshotsModel::getRandomScreenshot(); - global $Smarty; + global $Smarty; - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('screenshotsTitle'), - 'content_title' => $Smarty->getConfigVars('screenshotsContentTitle'), - 'screenshots' => $screenshot, - 'random_shot' => $random_shot, - ), - $this->_template - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('screenshotsTitle'), + 'content_title' => $Smarty->getConfigVars('screenshotsContentTitle'), + 'screenshots' => $screenshot, + 'random_shot' => $random_shot, + ), + $this->_template + ); + } - /* Display the selected category. */ - public function getCategory($category, $game) { - $this->addJSFiles(array( - 'baguetteBox.min.js' - )); + /* Display the selected category. */ + public function getCategory($category, $game) + { + $this->addJSFiles(array( + 'baguetteBox.min.js' + )); - if (empty($game)) { - $screenshots = ScreenshotsModel::getCategoryScreenshots($category); - } else { - $screenshots = array( - 'category' => $category, - 'games' => array(ScreenshotsModel::getTargetScreenshots($game)) - ); - } + if (empty($game)) { + $screenshots = ScreenshotsModel::getCategoryScreenshots($category); + } else { + $screenshots = array( + 'category' => $category, + 'games' => array(ScreenshotsModel::getTargetScreenshots($game)) + ); + } - global $Smarty; + global $Smarty; - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('screenshotsTitle'), - 'content_title' => $Smarty->getConfigVars('screenshotsContentTitle'), - 'screenshots' => $screenshots, - 'category' => $category, - 'game' => $game, - ), - $this->_template_category - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('screenshotsTitle'), + 'content_title' => $Smarty->getConfigVars('screenshotsContentTitle'), + 'screenshots' => $screenshots, + 'category' => $category, + 'game' => $game, + ), + $this->_template_category + ); + } - /* Get a list with all screenshot filenames/captions as a JSON list. */ - public function getAllJSON() { - $sshots = array(); - foreach (ScreenshotsModel::getAllScreenshots() as $category) { - foreach ($category['games'] as $screenshot) { - foreach ($screenshot->getFiles() as $files) { - $files['filename'] = DIR_SCREENSHOTS . "/{$files['filename']}-full.png"; - $sshots[] = array_values($files); - } - } - } - print json_encode($sshots); - return True; - } + /* Get a list with all screenshot filenames/captions as a JSON list. */ + public function getAllJSON() + { + $sshots = array(); + foreach (ScreenshotsModel::getAllScreenshots() as $category) { + foreach ($category['games'] as $screenshot) { + foreach ($screenshot->getFiles() as $files) { + $files['filename'] = DIR_SCREENSHOTS . "/{$files['filename']}-full.png"; + $sshots[] = array_values($files); + } + } + } + print json_encode($sshots); + return true; + } } -?> diff --git a/include/Pages/SubprojectsPage.php b/include/Pages/SubprojectsPage.php index fb0e03a1..2719fa45 100644 --- a/include/Pages/SubprojectsPage.php +++ b/include/Pages/SubprojectsPage.php @@ -2,28 +2,30 @@ require_once('Controller.php'); require_once('Models/SubprojectsModel.php'); -class SubprojectsPage extends Controller { - private $_template; +class SubprojectsPage extends Controller +{ + private $_template; - /* Constructor. */ - public function __construct() { - parent::__construct(); - $this->_template = 'pages/subprojects.tpl'; - } + /* Constructor. */ + public function __construct() + { + parent::__construct(); + $this->_template = 'pages/subprojects.tpl'; + } - /* Display the index page. */ - public function index() { - $subprojects = SubprojectsModel::getAllSubprojects(); - global $Smarty; + /* Display the index page. */ + public function index() + { + $subprojects = SubprojectsModel::getAllSubprojects(); + global $Smarty; - return $this->renderPage( - array( - 'title' => $Smarty->getConfigVars('subprojectsTitle'), - 'content_title' => $Smarty->getConfigVars('subprojectsContentTitle'), - 'subprojects' => $subprojects, - ), - $this->_template - ); - } + return $this->renderPage( + array( + 'title' => $Smarty->getConfigVars('subprojectsTitle'), + 'content_title' => $Smarty->getConfigVars('subprojectsContentTitle'), + 'subprojects' => $subprojects, + ), + $this->_template + ); + } } -?> diff --git a/include/XMLParser.php b/include/XMLParser.php index d1bb2eba..0e6b7bcb 100644 --- a/include/XMLParser.php +++ b/include/XMLParser.php @@ -9,288 +9,295 @@ * @author Fredrik Wendel * @version 1.0 */ -class XMLParser { - const FILE_NOT_FOUND = 'The filename specified doesn\'t point to an exiting file.'; - const FILE_NOT_READABLE = 'Unable to read the contents of the file.'; - const DATA_NOT_XML = 'The data provided is not XML.'; - const PARSER_ERROR = 'Error parsing XML.'; +class XMLParser +{ + const FILE_NOT_FOUND = 'The filename specified doesn\'t point to an exiting file.'; + const FILE_NOT_READABLE = 'Unable to read the contents of the file.'; + const DATA_NOT_XML = 'The data provided is not XML.'; + const PARSER_ERROR = 'Error parsing XML.'; - const NS_HTML4 = 'http://www.w3.org/TR/html4/'; - const NS_XHTML = 'http://www.w3.org/TR/xhtml1/'; + const NS_HTML4 = 'http://www.w3.org/TR/html4/'; + const NS_XHTML = 'http://www.w3.org/TR/xhtml1/'; - static private $empty_elements = array('br', 'hr', 'img'); - private $_tree; - private $_data; - private $_ptr; + private static $empty_elements = array('br', 'hr', 'img'); + private $_tree; + private $_data; + private $_ptr; - /** - * Constructor. - * - * @access public - * @since 1.0 - */ - public function __construct() { - $this->_tree = array(); - $this->_data = null; - $this->_ptr = null; - } + /** + * Constructor. + * + * @access public + * @since 1.0 + */ + public function __construct() + { + $this->_tree = array(); + $this->_data = null; + $this->_ptr = null; + } - /** - * Parse XML by filename, will read the XML data from a file and then parse - * it. Returns a multidimensional array (aka tree). Optionally it will also - * clear the tree and remove nested single arrays and link the values to the - * parent directly instead. - * - * @param string $filename full path the XML file to parse - * @return bool|array - * @access public - * @since 1.0 - * @throws ErrorException - */ - public function parseByFilename($filename) { - global $lang; + /** + * Parse XML by filename, will read the XML data from a file and then parse + * it. Returns a multidimensional array (aka tree). Optionally it will also + * clear the tree and remove nested single arrays and link the values to the + * parent directly instead. + * + * @param string $filename full path the XML file to parse + * @return bool|array + * @access public + * @since 1.0 + * @throws ErrorException + */ + public function parseByFilename($filename) + { + global $lang; - if ($lang != 'en') { - $fname = substr($filename, 0, strrpos($filename, '.')); - $fext = strrchr($filename, '.' ); + if ($lang != 'en') { + $fname = substr($filename, 0, strrpos($filename, '.')); + $fext = strrchr($filename, '.'); - $localized = $fname . "." . $lang . $fext; + $localized = $fname . "." . $lang . $fext; - if (is_file($localized)) { - if (!is_readable($localized)) { - $file = "\n\nFilename: " . basename($localized) . "\n"; - throw new ErrorException(self::FILE_NOT_FOUND . $file); - } else { - $filename = $localized; - } - } - } + if (is_file($localized)) { + if (!is_readable($localized)) { + $file = "\n\nFilename: " . basename($localized) . "\n"; + throw new ErrorException(self::FILE_NOT_FOUND . $file); + } else { + $filename = $localized; + } + } + } - $file = "\n\nFilename: " . basename($filename) . "\n"; - /* If we can't read the file there is nothing we can do. */ - if (!is_file($filename) || !is_readable($filename)) { - throw new ErrorException(self::FILE_NOT_FOUND . $file); - } - /* Read the file contents. */ - if (!($xml = @file_get_contents($filename))) { - throw new ErrorException(self::FILE_NOT_READABLE . $file); - } + $file = "\n\nFilename: " . basename($filename) . "\n"; + /* If we can't read the file there is nothing we can do. */ + if (!is_file($filename) || !is_readable($filename)) { + throw new ErrorException(self::FILE_NOT_FOUND . $file); + } + /* Read the file contents. */ + if (!($xml = @file_get_contents($filename))) { + throw new ErrorException(self::FILE_NOT_READABLE . $file); + } - /* Parse the XML. */ - try { - return $this->parseByData($xml); - } catch (ErrorException $e) { - $msg = "{$e->getMessage()}{$file}"; - throw new ErrorException($msg); - } - } + /* Parse the XML. */ + try { + return $this->parseByData($xml); + } catch (ErrorException $e) { + $msg = "{$e->getMessage()}{$file}"; + throw new ErrorException($msg); + } + } - /** - * Parses the XML data and returns a multidimensional array (aka tree). - * Optionally it will also clear the tree and remove nested single arrays - * and link the values to the parent directly instead. - * - * @param string $xml the XML to parse - * @param bool $destroy_single_arrays whether to keep nested single arrays or not - * @return bool|array - * @access public - * @since 1.0 - * @throws ErrorException - */ - public function parseByData($xml) { - if (!is_string($xml) || strlen($xml) == 0) { - throw new ErrorException(self::DATA_NOT_XML); - } - /* Create a parser and set the options */ - $parser = xml_parser_create_ns(); - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); - xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); - xml_set_object($parser, $this); - xml_set_element_handler($parser, 'startElement', 'endElement'); - xml_set_character_data_handler($parser, 'getElement'); + /** + * Parses the XML data and returns a multidimensional array (aka tree). + * Optionally it will also clear the tree and remove nested single arrays + * and link the values to the parent directly instead. + * + * @param string $xml the XML to parse + * @param bool $destroy_single_arrays whether to keep nested single arrays or not + * @return bool|array + * @access public + * @since 1.0 + * @throws ErrorException + */ + public function parseByData($xml) + { + if (!is_string($xml) || strlen($xml) == 0) { + throw new ErrorException(self::DATA_NOT_XML); + } + /* Create a parser and set the options */ + $parser = xml_parser_create_ns(); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); + xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); + xml_set_object($parser, $this); + xml_set_element_handler($parser, 'startElement', 'endElement'); + xml_set_character_data_handler($parser, 'getElement'); - /** - * Workaround the XML-parser not being able to handle HTML-entities by - * encapsulating them as CDATA. - */ - $pattern = '/(&(?:(?!quot|amp|apos|lt|gt)([a-z]+)|(#\d+));)/iU'; - $replace = ''; - $xml = preg_replace($pattern, $replace, $xml); - /* Parse the data and free the parser resource. */ - if (!xml_parse($parser, $xml, true)) { - $error = "\n\nError code: " . xml_get_error_code($parser) . "\n"; - $error .= "Line: " . xml_get_current_line_number($parser) . ", character: " . xml_get_current_column_number($parser) . "\n"; - $error .= "Error message: " . xml_error_string(xml_get_error_code($parser)) . "\n"; - xml_parser_free($parser); - throw new ErrorException(self::PARSER_ERROR . $error); - } - xml_parser_free($parser); - /** - * The root element will contain an array with an empty key, so we can - * skip that one right now. - */ - $tree = $this->_tree['']; - $this->simplifyArray($tree); - return $tree; - } + /** + * Workaround the XML-parser not being able to handle HTML-entities by + * encapsulating them as CDATA. + */ + $pattern = '/(&(?:(?!quot|amp|apos|lt|gt)([a-z]+)|(#\d+));)/iU'; + $replace = ''; + $xml = preg_replace($pattern, $replace, $xml); + /* Parse the data and free the parser resource. */ + if (!xml_parse($parser, $xml, true)) { + $error = "\n\nError code: " . xml_get_error_code($parser) . "\n"; + $error .= "Line: " . xml_get_current_line_number($parser) . ", character: " . xml_get_current_column_number($parser) . "\n"; + $error .= "Error message: " . xml_error_string(xml_get_error_code($parser)) . "\n"; + xml_parser_free($parser); + throw new ErrorException(self::PARSER_ERROR . $error); + } + xml_parser_free($parser); + /** + * The root element will contain an array with an empty key, so we can + * skip that one right now. + */ + $tree = $this->_tree['']; + $this->simplifyArray($tree); + return $tree; + } - /** - * Handles new tags opening in the XML-document. - * - * @param resource $parser XML parser resource - * @param string $name name of the tag - * @param array $attrs list of all attributes for the tag (if any) - * @access private - * @since 1.0 - */ - private function startElement($parser, $name, $attrs) { - /* If we find a colon in the name, we need to check the namespace. */ - if (strpos($name, ':') !== false) { - $namespace = implode(':', explode(':', $name, -1)); - /* Got (X)HTML data. */ - if (in_array($namespace, array(self::NS_HTML4, self::NS_XHTML))) { - $pos = strrpos($name, ':'); - $namespace = substr($name, 0, $pos); - $name = substr($name, ($pos+1)); - $data = "<{$name}"; - foreach ($attrs as $key => $value) { - $data .= " {$key}=\"{$value}\""; - } - /* Handle HTML "empty" elements (ie:
,
) properly. */ - if ($namespace == self::NS_XHTML && in_array($name, self::$empty_elements)) { - $data .= " /"; - } - $data .= ">"; - $this->getElement($parser, $data); - } - /* If not we can just rock on. */ - } else { - if (!is_array($attrs) || (is_array($attrs) && count($attrs) == 0)) { - $element = null; - } else { - $element = $attrs; - /*$element = array(); - foreach ($attrs as $key => $value) { - $element[$key] = $value; - }*/ - } + /** + * Handles new tags opening in the XML-document. + * + * @param resource $parser XML parser resource + * @param string $name name of the tag + * @param array $attrs list of all attributes for the tag (if any) + * @access private + * @since 1.0 + */ + private function startElement($parser, $name, $attrs) + { + /* If we find a colon in the name, we need to check the namespace. */ + if (strpos($name, ':') !== false) { + $namespace = implode(':', explode(':', $name, -1)); + /* Got (X)HTML data. */ + if (in_array($namespace, array(self::NS_HTML4, self::NS_XHTML))) { + $pos = strrpos($name, ':'); + $namespace = substr($name, 0, $pos); + $name = substr($name, ($pos+1)); + $data = "<{$name}"; + foreach ($attrs as $key => $value) { + $data .= " {$key}=\"{$value}\""; + } + /* Handle HTML "empty" elements (ie:
,
) properly. */ + if ($namespace == self::NS_XHTML && in_array($name, self::$empty_elements)) { + $data .= " /"; + } + $data .= ">"; + $this->getElement($parser, $data); + } + /* If not we can just rock on. */ + } else { + if (!is_array($attrs) || (is_array($attrs) && count($attrs) == 0)) { + $element = null; + } else { + $element = $attrs; + /*$element = array(); + foreach ($attrs as $key => $value) { + $element[$key] = $value; + }*/ + } - /* Get the key for the last node in the tree. */ - end($this->_tree); - $key = key($this->_tree); + /* Get the key for the last node in the tree. */ + end($this->_tree); + $key = key($this->_tree); - /* Store the position so we can add the data later. */ - $this->_ptr = &$this->_tree[$key][$name]; - /* Store a reference the attributes. */ - if ($element != null) { - $this->_ptr['@attributes'] = &$element; - } else { - /** - * For one reason or another that escapes me, we must do this, - * or the tree won't be properly built. We will work against it - * in endElement() by overwriting the empty elements created - * here. - */ - $this->_ptr[] = &$element; - } - /** - * Store the reference directly in the tree until this node (and - * it's children) are done. Will get removed in endElement(). - */ - $this->_tree[$name] = &$element; - } - } + /* Store the position so we can add the data later. */ + $this->_ptr = &$this->_tree[$key][$name]; + /* Store a reference the attributes. */ + if ($element != null) { + $this->_ptr['@attributes'] = &$element; + } else { + /** + * For one reason or another that escapes me, we must do this, + * or the tree won't be properly built. We will work against it + * in endElement() by overwriting the empty elements created + * here. + */ + $this->_ptr[] = &$element; + } + /** + * Store the reference directly in the tree until this node (and + * it's children) are done. Will get removed in endElement(). + */ + $this->_tree[$name] = &$element; + } + } - /** - * Handles data between tags in the XML-document. - * - * @param resource $parser XML parser resource - * @param mixed $data data found between tags - * @access private - * @since 1.0 - */ - private function getElement($parser, $data) { - $this->_data .= $data; - } + /** + * Handles data between tags in the XML-document. + * + * @param resource $parser XML parser resource + * @param mixed $data data found between tags + * @access private + * @since 1.0 + */ + private function getElement($parser, $data) + { + $this->_data .= $data; + } - /** - * Handles tags closing in the XML-document. - * - * @param resource $parser XML parser resource - * @param string $name name of the tag - * @access private - * @since 1.0 - */ - private function endElement($parser, $name) { - /* If we find a colon in the name, we need to check the namespace. */ - if (strpos($name, ':') !== false) { - $namespace = implode(':', explode(':', $name, -1)); - /* Got (X)HTML data. */ - if (in_array($namespace, array(self::NS_HTML4, self::NS_XHTML))) { - $pos = strrpos($name, ':'); - $namespace = substr($name, 0, $pos); - $name = substr($name, ($pos+1)); - /* Handle HTML "empty" elements (ie:
,
) properly. */ - if (!in_array($name, self::$empty_elements)) { - $this->getElement($parser, ""); - } - } - /* Otherwise we can just add the data. */ - } else { - $data = trim($this->_data); - if (!empty($data)) { - /* If we got an empty element in the array, overwrite it. */ - $pos = count($this->_ptr); - if (is_null($this->_ptr[($pos-1)])) { - $pos--; - } - $this->_ptr[$pos] = $data; - } + /** + * Handles tags closing in the XML-document. + * + * @param resource $parser XML parser resource + * @param string $name name of the tag + * @access private + * @since 1.0 + */ + private function endElement($parser, $name) + { + /* If we find a colon in the name, we need to check the namespace. */ + if (strpos($name, ':') !== false) { + $namespace = implode(':', explode(':', $name, -1)); + /* Got (X)HTML data. */ + if (in_array($namespace, array(self::NS_HTML4, self::NS_XHTML))) { + $pos = strrpos($name, ':'); + $namespace = substr($name, 0, $pos); + $name = substr($name, ($pos+1)); + /* Handle HTML "empty" elements (ie:
,
) properly. */ + if (!in_array($name, self::$empty_elements)) { + $this->getElement($parser, ""); + } + } + /* Otherwise we can just add the data. */ + } else { + $data = trim($this->_data); + if (!empty($data)) { + /* If we got an empty element in the array, overwrite it. */ + $pos = count($this->_ptr); + if (is_null($this->_ptr[($pos-1)])) { + $pos--; + } + $this->_ptr[$pos] = $data; + } - /* Reset the internal data holder. */ - $this->_data = null; - /* Remove the reference. */ - $pop = array_pop($this->_tree); - } - } + /* Reset the internal data holder. */ + $this->_data = null; + /* Remove the reference. */ + $pop = array_pop($this->_tree); + } + } - /** - * Removes unnecessary arrays in an array tree, if an array contains an - * array with just one element in it, the middle array will be removed. - * It won't touch 'attributes' keys though. - * - * @param array $array reference to the array tree - * @param string $parent name of the parent - * @param boolean $all_singles remove named single arrays or just 0 ones - * @access private - * @since 1.0 - */ - private function simplifyArray(&$array, $parent='', $all_singles=false) { - if (is_array($array) && count($array) > 0) { - foreach ((array)$array as $key => $value) { - if (is_array($value) && $key !== '@attributes') { - $this->simplifyArray($array[$key], $key); - } - if (count($array) == 1) { - if (array_key_exists(0, $array)) { - // HACK: The compatibility page assumes that the entry - // 'game' is always an array. In case only one 'game' - // tag is specified in a 'games' tag this would result - // in the array of 'game' being simplified (i.e. - // replaced by its contents). This breaks the - // compatibility page. We work around this issue by - // simply not simplifying arrays when the parent is - // named 'game'. - if ($parent !== 'game') { - $array = $array[0]; - } - } else { - $keys = array_keys($array); - $this->simplifyArray($array[$keys[0]], $keys[0]); - } - } - } - } - } + /** + * Removes unnecessary arrays in an array tree, if an array contains an + * array with just one element in it, the middle array will be removed. + * It won't touch 'attributes' keys though. + * + * @param array $array reference to the array tree + * @param string $parent name of the parent + * @param boolean $all_singles remove named single arrays or just 0 ones + * @access private + * @since 1.0 + */ + private function simplifyArray(&$array, $parent = '', $all_singles = false) + { + if (is_array($array) && count($array) > 0) { + foreach ((array)$array as $key => $value) { + if (is_array($value) && $key !== '@attributes') { + $this->simplifyArray($array[$key], $key); + } + if (count($array) == 1) { + if (array_key_exists(0, $array)) { + // HACK: The compatibility page assumes that the entry + // 'game' is always an array. In case only one 'game' + // tag is specified in a 'games' tag this would result + // in the array of 'game' being simplified (i.e. + // replaced by its contents). This breaks the + // compatibility page. We work around this issue by + // simply not simplifying arrays when the parent is + // named 'game'. + if ($parent !== 'game') { + $array = $array[0]; + } + } else { + $keys = array_keys($array); + $this->simplifyArray($array[$keys[0]], $keys[0]); + } + } + } + } + } } -?> diff --git a/include/config.inc.php b/include/config.inc.php index c9d3b603..00ffc421 100644 --- a/include/config.inc.php +++ b/include/config.inc.php @@ -15,15 +15,15 @@ date_default_timezone_set("UTC"); /* Base URL to the website. */ if ($_SERVER['SERVER_PORT'] == '80') { - $url = "http://{$_SERVER['SERVER_NAME']}"; -} else if ($_SERVER['SERVER_PORT'] == '443') { - $url = "https://{$_SERVER['SERVER_NAME']}"; + $url = "http://{$_SERVER['SERVER_NAME']}"; +} elseif ($_SERVER['SERVER_PORT'] == '443') { + $url = "https://{$_SERVER['SERVER_NAME']}"; } else { - $url = "http://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}"; + $url = "http://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}"; } if (substr($url, -1) != '/') { - $url .= '/'; + $url .= '/'; } define('URL_BASE', $url); unset($url); @@ -57,4 +57,3 @@ define('SMARTY_CACHING_ENABLE', 0); define('SMARTY_CACHING_LIFETIME', (60 * 60)); define('SMARTY_CACHING_COMPILE_CHECK', true); # used when developing define('SMARTY_CACHING_FORCE_RECHECK', true); # used when developing -?>