Alpha Framework alpha--controller
[ class tree: alpha--controller ] [ index: alpha--controller ] [ all elements ]

Source for file GenSecureQueryStrings.php

Documentation is available at GenSecureQueryStrings.php

  1. <?php
  2.  
  3. // include the config file
  4. if(!isset($config)) {
  5.     require_once '../util/AlphaConfig.inc';
  6.     $config AlphaConfig::getInstance();
  7. }
  8.  
  9. require_once $config->get('sysRoot').'alpha/controller/AlphaController.inc';
  10. require_once $config->get('sysRoot').'alpha/controller/front/FrontController.inc';
  11. require_once $config->get('sysRoot').'alpha/controller/AlphaControllerInterface.inc';
  12. require_once $config->get('sysRoot').'alpha/view/AlphaView.inc';
  13.  
  14. /**
  15.  *
  16.  * Controller used to generate secure URLs from the query strings provided
  17.  * 
  18.  * @package alpha::controller
  19.  * @since 1.0
  20.  * @author John Collins <dev@alphaframework.org>
  21.  * @version $Id: GenSecureQueryStrings.php 1453 2011-12-04 15:12:54Z johnc $
  22.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  23.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  24.  *  All rights reserved.
  25.  * 
  26.  *  <pre>
  27.  *  Redistribution and use in source and binary forms, with or
  28.  *  without modification, are permitted provided that the
  29.  *  following conditions are met:
  30.  * 
  31.  *  * Redistributions of source code must retain the above
  32.  *    copyright notice, this list of conditions and the
  33.  *    following disclaimer.
  34.  *  * Redistributions in binary form must reproduce the above
  35.  *    copyright notice, this list of conditions and the
  36.  *    following disclaimer in the documentation and/or other
  37.  *    materials provided with the distribution.
  38.  *  * Neither the name of the Alpha Framework nor the names
  39.  *    of its contributors may be used to endorse or promote
  40.  *    products derived from this software without specific
  41.  *    prior written permission.
  42.  *   
  43.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  44.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  45.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  46.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  47.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  48.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  49.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  50.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  51.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  52.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  53.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  54.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  55.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  56.  *  </pre>
  57.  *  
  58.  */
  59.     /**
  60.      * Trace logger
  61.      * 
  62.      * @var Logger 
  63.      * @since 1.0
  64.      */
  65.     private static $logger null;
  66.     
  67.     /**
  68.      * Constructor
  69.      * 
  70.      * @since 1.0
  71.      */
  72.     public function __construct({
  73.         self::$logger new Logger('CacheManager');
  74.         self::$logger->debug('>>__construct()');
  75.         
  76.         global $config;
  77.         
  78.         // ensure that the super class constructor is called, indicating the rights group
  79.         parent::__construct('Admin');
  80.         
  81.         $this->setTitle('Generate Secure Query Strings');
  82.         
  83.         self::$logger->debug('<<__construct');
  84.     }
  85.     
  86.     /**
  87.      * Handle GET requests
  88.      * 
  89.      * @param array $params 
  90.      * @since 1.0
  91.      */
  92.     public function doGET($params{
  93.         self::$logger->debug('>>doGET($params=['.var_export($paramstrue).'])');
  94.         
  95.         echo AlphaView::displayPageHead($this);
  96.         
  97.         echo $this->renderForm();
  98.         
  99.         echo AlphaView::displayPageFoot($this);
  100.         
  101.         self::$logger->debug('<<doGET');
  102.     }
  103.     
  104.     /**
  105.      * Handle POST requests
  106.      * 
  107.      * @param array $params 
  108.      * @since 1.0
  109.      */
  110.     public function doPOST($params{
  111.         self::$logger->debug('>>doPOST($params=['.var_export($paramstrue).'])');
  112.         
  113.         global $config;
  114.  
  115.         echo AlphaView::displayPageHead($this);
  116.         
  117.         echo '<p style="width:90%; overflow:scroll;">';
  118.         if(isset($params['QS']))
  119.             echo FrontController::generateSecureURL($params['QS']);
  120.         echo '</p>';
  121.         
  122.         echo $this->renderForm();
  123.         
  124.         echo AlphaView::displayPageFoot($this);
  125.         
  126.         self::$logger->debug('<<doPOST');
  127.     }
  128.     
  129.     /**
  130.      * Renders the HTML form for generating secure URLs
  131.      * 
  132.      * @return string 
  133.      * @since 1.0
  134.      */
  135.     private function renderForm({
  136.         global $config;
  137.         
  138.         $html '<p>Use this form to generate secure (encrypted) URLs which make use of the Front Controller.  Always be sure to specify an action controller'.
  139.             ' (act) at a minimum.</p>';
  140.         $html .= '<p>Example 1: to generate a secure URL for viewing article object 00000000001, enter <em>act=ViewArticle&oid=00000000001</em></p>';
  141.         $html .= '<p>Example 2: to generate a secure URL for viewing an Atom news feed of the articles, enter'.
  142.             ' <em>act=ViewFeed&bo=ArticleObject&type=Atom</em</p>';
  143.  
  144.         $html .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">';
  145.         $html .= '<input type="text" name="QS" size="100"/>';
  146.         $temp new Button('submit''Generate''saveBut');
  147.         $html .= $temp->render();
  148.         $html .= '</form>';
  149.         
  150.         return $html;
  151.     }
  152. }
  153.  
  154. // now build the new controller if this file is called directly
  155. if ('GenSecureQueryStrings.php' == basename($_SERVER['PHP_SELF'])) {
  156.     $controller new GenSecureQueryStrings();
  157.     
  158.     if(!empty($_POST)) {            
  159.         $controller->doPOST($_QUERY);
  160.     }else{
  161.         $controller->doGET($_GET);
  162.     }
  163. }
  164.  
  165. ?>

Documentation generated on Tue, 13 Dec 2011 20:26:58 +0000 by phpDocumentor 1.4.3