Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TPage.php

Documentation is available at TPage.php

  1. <?php
  2. namespace Adianti\Control;
  3.  
  4. use Adianti\Core\AdiantiCoreTranslator;
  5. use Adianti\Widget\Base\TElement;
  6. use Adianti\Widget\Base\TScript;
  7.  
  8. use Exception;
  9. use ReflectionClass;
  10.  
  11. /**
  12.  * Page Controller Pattern: used as container for all elements inside a page and also as a page controller
  13.  *
  14.  * @version    7.4
  15.  * @package    control
  16.  * @author     Pablo Dall'Oglio
  17.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  18.  * @license    http://www.adianti.com.br/framework-license
  19.  */
  20. class TPage extends TElement
  21. {
  22.     private $body;
  23.     private $constructed;
  24.     private static $loadedjs;
  25.     private static $loadedcss;
  26.     private static $registeredcss;
  27.     
  28.     /**
  29.      * Class Constructor
  30.      */
  31.     public function __construct()
  32.     {
  33.         parent::__construct('div');
  34.         $this->constructed TRUE;
  35.     }
  36.     
  37.     /**
  38.      * Return the Page name
  39.      */
  40.     public function getClassName()
  41.     {
  42.         $rc new ReflectionClass$this );
  43.         return $rc->getShortName();
  44.     }
  45.     
  46.     /**
  47.      * Change page title
  48.      */
  49.     public static function setPageTitle($title)
  50.     {
  51.         TScript::create("document.title='{$title}';");
  52.     }
  53.     
  54.     /**
  55.      * Set target container for page content
  56.      */
  57.     public function setTargetContainer($container)
  58.     {
  59.         if ($container)
  60.         {
  61.             $this->setProperty('adianti_target_container'$container);
  62.             $this->{'class''container-part';
  63.             $this->{'page_name'$this->getClassName();
  64.         }
  65.         else
  66.         {
  67.             unset($this->{'adianti_target_container'});
  68.             unset($this->{'class'});
  69.             unset($this->{'page_name'});
  70.         }
  71.     }
  72.     
  73.     /**
  74.      * Return target container
  75.      */
  76.     public function getTargetContainer()
  77.     {
  78.         return $this->{'adianti_target_container'};
  79.     }
  80.     
  81.     /**
  82.      * Interprets an action based at the URL parameters
  83.      */
  84.     public function run()
  85.     {
  86.         if ($_GET)
  87.         {
  88.             $class  = isset($_GET['class'])  $_GET['class']  NULL;
  89.             $method = isset($_GET['method']$_GET['method'NULL;
  90.             
  91.             if ($class)
  92.             {
  93.                 $object ($class == get_class($this)) $this new $class;
  94.                 if (is_callable(array($object$method) ) )
  95.                 {
  96.                     call_user_func(array($object$method)$_REQUEST);
  97.                 }
  98.             }
  99.             else if (function_exists($method))
  100.             {
  101.                 call_user_func($method$_REQUEST);
  102.             }
  103.         }
  104.     }
  105.     
  106.     /**
  107.      * Include a specific JavaScript function to this page
  108.      * @param $js JavaScript location
  109.      */
  110.     public static function include_js($js)
  111.     {
  112.         self::$loadedjs[$jsTRUE;
  113.     }
  114.     
  115.     /**
  116.      * Include a specific Cascading Stylesheet to this page
  117.      * @param $css  Cascading Stylesheet
  118.      */
  119.     public static function include_css($css)
  120.     {
  121.         self::$loadedcss[$cssTRUE;
  122.     }
  123.     
  124.     /**
  125.      * Register a specific Cascading Stylesheet to this page
  126.      * @param $cssname  Cascading Stylesheet Name
  127.      * @param $csscode  Cascading Stylesheet Code
  128.      */
  129.     public static function register_css($cssname$csscode)
  130.     {
  131.         self::$registeredcss[$cssname$csscode;
  132.     }
  133.     
  134.     /**
  135.      * Open a File Dialog
  136.      * @param $file File Name
  137.      */
  138.     public static function openFile($file$basename null)
  139.     {
  140.         TScript::create("__adianti_download_file('{$file}', '{$basename}')");
  141.     }
  142.     
  143.     /**
  144.      * Open a page in new tab
  145.      */
  146.     public static function openPage($page)
  147.     {
  148.         TScript::create("__adianti_open_page('{$page}');");
  149.     }
  150.     
  151.     /**
  152.      * Return the loaded Cascade Stylesheet files
  153.      * @ignore-autocomplete on
  154.      */
  155.     public static function getLoadedCSS()
  156.     {
  157.         $css self::$loadedcss;
  158.         $csc self::$registeredcss;
  159.         $css_text '';
  160.         
  161.         if ($css)
  162.         {
  163.             foreach ($css as $cssfile => $bool)
  164.             {
  165.                 $css_text .= "    <link rel='stylesheet' type='text/css' media='screen' href='$cssfile'/>\n";
  166.             }
  167.         }
  168.         
  169.         if ($csc)
  170.         {
  171.             $css_text .= "    <style type='text/css' media='screen'>\n";
  172.             foreach ($csc as $cssname => $csscode)
  173.             {
  174.                 $css_text .= $csscode;
  175.             }
  176.             $css_text .= "    </style>\n";
  177.         }
  178.         
  179.         return $css_text;
  180.     }
  181.     
  182.     /**
  183.      * Return the loaded JavaScript files
  184.      * @ignore-autocomplete on
  185.      */
  186.     public static function getLoadedJS()
  187.     {
  188.         $js self::$loadedjs;
  189.         $js_text '';
  190.         if ($js)
  191.         {
  192.             foreach ($js as $jsfile => $bool)
  193.             {
  194.                 $js_text .= "    <script language='JavaScript' src='$jsfile'></script>\n";;
  195.             }
  196.         }
  197.         return $js_text;
  198.     }
  199.     
  200.     /**
  201.      * Discover if the browser is mobile device
  202.      */
  203.     public static function isMobile()
  204.     {
  205.         $isMobile FALSE;
  206.         
  207.         if (PHP_SAPI == 'cli')
  208.         {
  209.             return FALSE;
  210.         }
  211.         
  212.         if (isset($_SERVER['HTTP_X_WAP_PROFILE']or isset($_SERVER['HTTP_PROFILE']))
  213.         {
  214.             $isMobile TRUE;
  215.         }
  216.         
  217.         $mobiBrowsers array('android',   'audiovox''blackberry''epoc',
  218.                               'ericsson'' iemobile''ipaq',       'iphone''ipad'
  219.                               'ipod',      'j2me',     'midp',       'mmp',
  220.                               'mobile',    'motorola''nitro',      'nokia',
  221.                               'opera mini','palm',     'palmsource''panasonic',
  222.                               'phone',     'pocketpc''samsung',    'sanyo',
  223.                               'series60',  'sharp',    'siemens',    'smartphone',
  224.                               'sony',      'symbian',  'toshiba',    'treo',
  225.                               'up.browser','up.link',  'wap',        'wap',
  226.                               'windows ce','htc');
  227.                               
  228.         foreach ($mobiBrowsers as $mb)
  229.         {
  230.             if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),$mb!== FALSE)
  231.             {
  232.                  $isMobile TRUE;
  233.             }
  234.         }
  235.         
  236.         return $isMobile;
  237.     }
  238.     
  239.     /**
  240.      * Intercepts whenever someones assign a new property's value
  241.      * @param $name     Property Name
  242.      * @param $value    Property Value
  243.      */
  244.     public function __set($name$value)
  245.     {
  246.         parent::__set($name$value);
  247.         $this->$name $value;
  248.     }
  249.     
  250.     /**
  251.      * Decide wich action to take and show the page
  252.      */
  253.     public function show()
  254.     {
  255.         // just execute run() from toplevel TPage's, not nested ones
  256.         if (!$this->getIsWrapped())
  257.         {
  258.             $this->run();
  259.         }
  260.         parent::show();
  261.         
  262.         if (!$this->constructed)
  263.         {
  264.             throw new Exception(AdiantiCoreTranslator::translate('You must call ^1 constructor'__CLASS__ ) );
  265.         }
  266.     }
  267. }