FastFrame.php

Go to the documentation of this file.
00001 <?php
00003 // {{{ license
00004 
00005 // +----------------------------------------------------------------------+
00006 // | FastFrame Application Framework                                      |
00007 // +----------------------------------------------------------------------+
00008 // | Copyright (c) 2002-2006 The Codejanitor Group                        |
00009 // +----------------------------------------------------------------------+
00010 // | This source file is subject to the GNU Lesser Public License (LGPL), |
00011 // | that is bundled with this package in the file LICENSE, and is        |
00012 // | available at through the world-wide-web at                           |
00013 // | http://www.fsf.org/copyleft/lesser.html                              |
00014 // | If you did not receive a copy of the LGPL and are unable to          |
00015 // | obtain it through the world-wide-web, you can get it by writing the  |
00016 // | Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
00017 // | MA 02111-1307, USA.                                                  |
00018 // +----------------------------------------------------------------------+
00019 // | Authors: The Horde Team <http://www.horde.org>                       |
00020 // |          Jason Rust <jrust@codejanitor.com>                          |
00021 // |          Dan Allen <dan@mojavelinux.com>                             |
00022 // +----------------------------------------------------------------------+
00023 
00024 // }}}
00025 // {{{ includes
00026 
00027 require_once dirname(__FILE__) . '/FastFrame/Registry.php';
00028 
00029 // }}}
00030 // {{{ class FastFrame
00031 
00045 // }}}
00046 class FastFrame {
00047     // {{{ url()
00048 
00059     function url($in_url, $in_vars = array(), $in_full = false, $in_ssl = false)
00060     {
00061         static $s_webRoot, $b_useSSL, $s_hostname, $b_sessAppend, $s_argSep;
00062         // This avoids hundreds of useless function calls
00063         if (!isset($s_webRoot)) {
00064             $o_registry =& FF_Registry::singleton();
00065             $s_webRoot = $o_registry->getConfigParam('webserver/web_root');
00066             $b_useSSL = $o_registry->getConfigParam('webserver/use_ssl');
00067             $s_hostname = $o_registry->getConfigParam('webserver/hostname');
00068             $b_sessAppend = $o_registry->getConfigParam('session/append');
00069             $s_argSep = ini_get('arg_separator.output');
00070         }
00071 
00072         if (strpos($in_url, 'javascript:') === 0) {
00073             return $in_url;
00074         }
00075 
00076         // If the link does not have the webpath, then add it.
00077         if (strpos($in_url, '/') !== 0 && !preg_match(':^https?\://:', $in_url)) {
00078             $in_url = $s_webRoot . '/' . $in_url;
00079         }
00080 
00081         // See if we need to make this a full query string.
00082         // If using ssl then force all urls to be https.
00083         $b_ssl = ($in_ssl || $b_useSSL);
00084         if (($in_full || $b_ssl) && !preg_match(':^https?\://:', $in_url)) {
00085             $in_url = ($b_ssl ? 'https' : 'http') .  '://' . $s_hostname . $in_url;
00086         }
00087 
00088         // Add the session to the array list if it is configured to do so
00089         $s_sessName = session_name();
00090         if (!isset($in_vars[$s_sessName]) &&
00091             (!isset($_COOKIE[$s_sessName]) || $b_sessAppend)) {
00092             // don't lock the user out with an empty session id!
00093             if (!FastFrame::isEmpty(session_id())) {
00094                 $in_vars[$s_sessName] = session_id();
00095             }
00096             elseif (!empty($_REQUEST[$s_sessName])) {
00097                 $in_vars[$s_sessName] = urlencode($_REQUEST[$s_sessName]);
00098             }
00099         }
00100 
00101         // See if they want the session explicitly unset
00102         if (isset($in_vars[$s_sessName]) && $in_vars[$s_sessName] === false) {
00103             unset($in_vars[$s_sessName]);
00104         }
00105 
00106         foreach($in_vars as $k => $v) {
00107             $in_vars[$k] = urlencode($k) . '=' . urlencode($v);
00108         }
00109 
00110         $queryString = implode($s_argSep, $in_vars);
00111         if (!empty($queryString)) {
00112             $in_url .= (strpos($in_url, '?') === false) ? '?' : $s_argSep;
00113             $in_url .= $queryString;
00114         }
00115 
00116         return $in_url;
00117     }
00118     
00119     // }}}
00120     // {{{ selfURL()
00121 
00132     function selfURL($in_vars = array(), $in_full = false, $in_ssl = false)
00133     {
00134         // Add on the module, app, and actionId to the beginning
00135         $o_actionHandler =& FF_ActionHandler::singleton();
00136         $in_vars['app'] = isset($in_vars['app']) ? $in_vars['app'] : $o_actionHandler->getAppId();
00137         $in_vars['module'] = isset($in_vars['module']) ? $in_vars['module'] : $o_actionHandler->getModuleId();
00138         $in_vars['actionId'] = isset($in_vars['actionId']) ? $in_vars['actionId'] : $o_actionHandler->getActionId();
00139         // Add on isPopup if it is set
00140         if (FF_Request::getParam('isPopup', 'gp', false) && !isset($in_vars['isPopup'])) {
00141             $in_vars['isPopup'] = 1;
00142         }
00143 
00144         // Add on the url to the beginning
00145         return FastFrame::url($_SERVER['PHP_SELF'], $in_vars, $in_full, $in_ssl);
00146     }
00147 
00148     // }}}
00149     // {{{ redirect()
00150     
00165     function redirect($in_url, $in_htmlRedirect = false)
00166     {
00167         if ($in_htmlRedirect) {
00168             echo '<html><head>
00169                   <script type="text/javascript">document.location.replace("' . $in_url . '"); window.onload = function() { document.body.style.display = "none"; }</script>
00170                   <noscript><meta http-equiv="Refresh" content="0; url=' . $in_url . '"></noscript>
00171                   </head><body>
00172                   ' . _('If you are seeing this page, your browser settings prevent you from automatically redirecting to a new URL.') . '<br /><br />
00173                   ' . sprintf(_('Please <a href="%s">click here</a> to continue.'), $in_url) . '
00174                   </body</html>';
00175         }
00176         else {
00177             header('Location: ' . $in_url, true);
00178         }
00179 
00180         exit;
00181     }
00182 
00183     // }}}
00184     // {{{ isEmpty()
00185 
00198     function isEmpty($in_var)
00199     {
00200         return (empty($in_var) && strlen($in_var) == 0);
00201     }
00202 
00203     // }}}
00204     // {{{ checkBrowser()
00205 
00212     function checkBrowser()
00213     {
00214         require_once 'Net/UserAgent/Detect.php';
00215         if (!IS_AJAX && Net_UserAgent_Detect::getBrowser(array('belowie6', 'belowns6', 'firefox0.x', 'belowopera8'))) {
00216             header('Location: notsupported.php');
00217             exit;
00218         }
00219     }
00220 
00221     // }}}
00222 }
00223 
00224 // {{{ PHP4 compat
00225 if (!defined('E_STRICT')) {
00226     define('E_STRICT', 2048);
00227 }
00228 
00229 // {{{ clone()
00230 
00238 if (version_compare(phpversion(), '5.0') === -1) {
00239     // Needs to be wrapped in eval as clone is a keyword in PHP5
00240     eval('
00241         function clone($obj)
00242         {
00243             return $obj;
00244         }
00245     ');
00246 }
00247 
00248 // }}} 
00249 // }}}
00250 ?>

Generated on Fri Jun 23 11:38:15 2006 for FastFrame by  doxygen 1.4.4