phpDocumentor GloryLands
Interface
[ class tree: GloryLands ] [ index: GloryLands ] [ all elements ]

Source for file glsmarttemplate.php

Documentation is available at glsmarttemplate.php

  1. <?php
  2. /**
  3.   * Game View Template definitions
  4.   *
  5.   * <pre>
  6.   * GloryLands, a Web-Based, Massive Multiplayer Online RPG/Strategy Game
  7.   * Copyright (C) 2008-09  John Haralampidis <jïhnys2[at]gmail.cïm>
  8.   *
  9.   * This program is free software: you can redistribute it and/or modify
  10.   * it under the terms of the GNU General Public License as published by
  11.   * the Free Software Foundation, either version 3 of the License, or
  12.   * (at your option) any later version.
  13.   *
  14.   * This program is distributed in the hope that it will be useful,
  15.   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.   * GNU General Public License for more details.
  18.   *
  19.   * You should have received a copy of the GNU General Public License
  20.   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21.   *
  22.   * For any help/suggestions or troubleshooting you can see the
  23.   * project community website at <http://www.glorylands.gr>
  24.   * </pre>
  25.   *
  26.   * @license GNU/GPLv3 GNU General Public License version 3
  27.   * @package GloryLands
  28.   * @subpackage Interface
  29.   * @author John Haralampidis <jïhnys2[at]gmail.cïm>
  30.   * @copyright Copyright (C) 2007-2009, John Haralampidis
  31.   * @version 1.0
  32.   */
  33.  
  34. /**
  35.   * GloryLands Smart template
  36.   *
  37.   * This class extends the GLTemplate and appends some automation support.
  38.   * In detail:
  39.   *  1) The GLSmartTemplate will automatically extract all the head information
  40.   *     from the HTML template and add them on the root template. That way you
  41.   *     don't need to concern about putting the heading information on a special
  42.   *     location.
  43.   *
  44.   * @package GloryLands
  45.   * @subpackage Interface
  46.   */
  47. class GLSmartTemplate extends GLTemplate {
  48.     
  49.     private function extract_params($param{
  50.         preg_match_all('/(\\w+)=[\'"](.*?)[\'"]/'$param$parmsPREG_SET_ORDER);
  51.         $res array();
  52.         foreach ($parms as $p{
  53.             $res[$p[1]] $res[$p[2]];
  54.         }
  55.         return $res;
  56.     }
  57.     
  58.     private function analyze_header($headers{
  59.         $name strtolower($headers[1]);
  60.         if (!$name$name=strtolower($headers[4]);
  61.         $data $headers[2];
  62.         $param $this->extract_params($data[3]);
  63.         
  64.         echo '['.$name.': '.print_r($param,true).']';
  65.         
  66.         switch ($name{
  67.             case 'script':
  68.             case 'meta':
  69.             case 'title':
  70.             case 'link':
  71.         }
  72.     }
  73.     
  74.     public function fetch({
  75.         $buffer parent::fetch();
  76.         
  77.         // separate head/body
  78.         preg_match('%<head>(.*?)</head>%s'$buffer$head);        
  79.         preg_match('%<body>(.*?)</body>%s'$buffer$body);
  80.         
  81.         // Make sure we have the proper body
  82.         if (sizeof($body== 0{
  83.             $body $buffer;
  84.         else {
  85.             $body $body[0];
  86.         }
  87.         
  88.         // Analyze the header
  89.         if (sizeof($head0{
  90.             $buf trim(substr($head[0],6,-7));
  91.             preg_match('%<(\\w+) ?(.*?)>(.*?)</\\1>|<(\\w+).*?/>%s'$buf$headsPREG_SET_ORDER);
  92.             echo '===[Data]======================='."\n".$buf."\n".'===[Array]======================'."\n".print_r($heads,true);
  93.             foreach ($heads as $h{
  94.                 $this->analyze_header($h);
  95.             }
  96.             
  97.         }
  98.         
  99.         return $body;
  100.     }
  101.     
  102. }
  103.  
  104. ?>

Documentation generated on Tue, 13 Oct 2009 23:49:09 +0300 by phpDocumentor 1.4.1