Source for file mr_test.php

Documentation is available at mr_test.php

  1. <?php
  2. /**
  3.  * Testscript for Advanced Mod Rewrite Plugin.
  4.  *
  5.  * The goal of this testscript is to provide an easy way for a variance comparison
  6.  * of created SEO URLs against their resolved parts.
  7.  *
  8.  * This testscript fetches the full category and article structure of actual
  9.  * Contenido installation, creates the SEO URLs for each existing category/article
  10.  * and resolves the generated URLs.
  11.  *
  12.  * Usage:
  13.  * ------
  14.  * 1. Install the Advanced Mod Rewrite Plugin
  15.  * 2. Set your desired plugin settings by using the Advanced Mod Rewrite area
  16.  *    in the Backend
  17.  * 3. Copy this file to your client directory, it is normally named '/cms/'
  18.  * 4. Exclude this file from rewriting, add following line in your .htaccess
  19.  *    RewriteRule ^cms/mr_test.php.*$ - [L]
  20.  * 5. Browse to http://host/cms/mr_test.php
  21.  * 6. Disable the script after finished testing, see line 31
  22.  *
  23.  * @author      Murat Purc <murat@purc.de>
  24.  * @copyright   © Murat Purc 2008
  25.  * @package     Contenido
  26.  * @subpackage  ModRewrite
  27.  */
  28.  
  29.  
  30. // Uncomment following line, if you're finished with the tests
  31. #die('Testscript disabled');
  32.  
  33.  
  34. ####################################################################################################
  35. ##### Contenido front_content.php header (compressed)
  36.  
  37. if (!defined("CON_FRAMEWORK")) define("CON_FRAMEWORK"true)}
  38. $contenido_path '';
  39. include_once ("config.php");
  40. include_once ($contenido_path 'classes/class.security.php');
  41. Contenido_Security::checkRequests();
  42. if (isset($_REQUEST['belang'])) {
  43.     $aValid array('de_DE''en_US''fr_FR''it_IT''nl_NL');
  44.     if (!in_array(strval($_REQUEST['belang'])$aValid)) {
  45.         die('Please use a valid language!');
  46.     }
  47. }
  48. include_once ($contenido_path."includes/startup.php");
  49. if ($cfg['http_params_check']['enabled'=== true{
  50.     cInclude('classes''class.httpinputvalidator.php');
  51.     $oHttpInputValidator new HttpInputValidator($cfg["path"]["contenido"$cfg["path"]["includes"'/config.http_check.php');
  52. }
  53. cInclude("includes""functions.con.php");
  54. cInclude("includes""functions.con2.php");
  55. cInclude("includes""functions.api.php");
  56. cInclude("includes""functions.pathresolver.php");
  57. if ($contenido{
  58.     page_open(array ('sess' => 'Contenido_Session''auth' => 'Contenido_Challenge_Crypt_Auth''perm' => 'Contenido_Perm'));
  59.     i18nInit($cfg["path"]["contenido"].$cfg["path"]["locale"]$belang);
  60. else {
  61.     page_open(array ('sess' => 'Contenido_Frontend_Session''auth' => 'Contenido_Frontend_Challenge_Crypt_Auth''perm' => 'Contenido_Perm'));
  62. }
  63. require_once $cfg['path']['contenido'$cfg['path']['includes''functions.includePluginConf.php';
  64. # Don't call hook, otherwhise the plugin will try to resolve the url and redirects to errorpage
  65. #CEC_Hook::execute('Contenido.Frontend.AfterLoadPlugins');
  66. $db new DB_Contenido;
  67. $sess->register("cfgClient");
  68. $sess->register("errsite_idcat");
  69. $sess->register("errsite_idart");
  70. $sess->register("encoding");
  71. if ($cfgClient["set"!= "set"{
  72.     rereadClients();
  73. }
  74. $sql "SELECT idlang, encoding FROM ".$cfg["tab"]["lang"];
  75. $db->query($sql);
  76. while ($db->next_record()) {
  77.     $encoding[$db->f("idlang")$db->f("encoding");
  78. }
  79. if (is_numeric($tmpchangelang&& $tmpchangelang 0{
  80.     $savedlang $lang;
  81.     $lang $tmpchangelang;
  82. }
  83. if (isset($changeclient&& !is_numeric($changeclient)) {
  84.     unset ($changeclient);
  85. }
  86. if (isset($client&& !is_numeric($client)) {
  87.     unset ($client);
  88. }
  89. if (isset($changelang&& !is_numeric($changelang)) {
  90.     unset ($changelang);
  91. }
  92. if (isset($lang&& !is_numeric($lang)) {
  93.     unset ($lang);
  94. }
  95. if (isset($changeclient)){
  96.     $client $changeclient;
  97.     unset($lang);
  98.     unset($load_lang);
  99. }
  100. if (isset($changelang)) $lang $changelang;
  101. if (!isset($client)) {
  102.     $client $load_client;
  103. }
  104. if (!isset($lang)) {
  105.     if(isset($load_lang)){
  106.         $lang $load_lang;
  107.     else {
  108.         $sql "SELECT
  109.                     B.idlang
  110.                 FROM
  111.                     ".$cfg["tab"]["clients_lang"]." AS A,
  112.                     ".$cfg["tab"]["lang"]." AS B
  113.                 WHERE
  114.                     A.idclient='".Contenido_Security::toInteger($client)."' AND
  115.                     A.idlang = B.idlang
  116.                 LIMIT
  117.                     0,1";
  118.         $db->query($sql);
  119.         $db->next_record();
  120.         $lang $db->f("idlang");
  121.     }
  122. }
  123. if (!$sess->is_registered("lang") ) $sess->register("lang");
  124. if (!$sess->is_registered("client") ) $sess->register("client");
  125. if (isset ($username)) {
  126.     $auth->login_if(true);
  127. }
  128. header("Content-Type: text/html; charset={$encoding[$lang]}");
  129. if (isset ($logout)) {
  130.     $auth->logout(true);
  131.     $auth->unauth(true);
  132.     $auth->auth["uname""nobody";
  133. }
  134. if (file_exists("config.local.php")) {
  135.     include ("config.local.php");
  136. }
  137. $errurl  "front_content.php?client=$client&idcat=".$errsite_idcat[$client]."&idart=".$errsite_idart[$client]."&lang=$lang&error=1";
  138. $errsite 'Location: ' CEC_Hook::execute('Contenido.Frontend.CreateURL'$errurl);
  139. if (isset($mr_preprocessedPageError)) {
  140.     unset($mr_preprocessedPageError);
  141.     header($errsite);
  142. }
  143. if (isset($path&& strlen($path1{
  144.     if ($cfg["urlpathresolve"== true{
  145.         $iLangCheck 0;
  146.         $idcat prResolvePathViaURLNames($path$iLangCheck);
  147.     else {
  148.         $iLangCheck 0;
  149.         $idcat prResolvePathViaCategoryNames($path$iLangCheck);
  150.         if($lang != iLangCheck){
  151.             $lang $iLangCheck;
  152.         }
  153.     }
  154. }
  155.  
  156.  
  157. ####################################################################################################
  158. ##### Plugin related area
  159.  
  160.  
  161. // set debug configuration, if you want to see the debug toolbar
  162. $options array(
  163.     'enable'                    => true,
  164.     'ressource_urls'            => array('/contenido/logs/errorlog.txt'),
  165.     'dump_super_globals'        => array('$_GET''$_POST''$_COOKIE''$_SESSION'),
  166.     'ignore_empty_superglobals' => true,
  167.     'magic_word'                => 'foobar'
  168. );
  169. $oDebug Contenido_mpDebug::getInstance();
  170. $oDebug->setConfig($options);
  171.  
  172. ##############
  173. ###just4dev###
  174. /*
  175. $tmp = '';
  176. foreach ($cfg['mod_rewrite'] as $p => $v) {
  177.     if (is_array($v) || is_object($v)) {
  178. #        $tmp .= $p . ': is_array($v) || is_object($v)' . "\n";
  179.     } elseif (strpos($p, 'seperator') !== false) {
  180.         $tmp .= $p . ': ' . $v . "\n";
  181.     } else {
  182. #        $tmp .= $p . ': ' . $v . "\n";
  183.     }
  184. }
  185.  
  186. echo "<pre>\$cfg: $tmp</pre>";
  187. $oUrl = ModRewriteUrlUtil::getInstance();
  188. #$conUrl = '/was-ist-contenido-index.html?foo=bar';
  189. $url    = 'front_content.php?idart=2&lang=1';
  190. $mrUrl = CEC_Hook::execute('Contenido.Frontend.CreateURL', $url);
  191. #$mrUrl  = $oUrl->toModRewriteUrl($conUrl);
  192. #echo "<pre>\$conUrl: $conUrl</pre>";
  193. echo "<pre>\$mrUrl: $mrUrl</pre>";
  194. return;
  195. */
  196. ##############
  197.  
  198.  
  199. ####################################################################################################
  200. ##### Form processing / Controller
  201.  
  202.  
  203. $mrTestNoOptionSelected false;
  204. if (!_getRequest('idart'&& !_getRequest('idcat'&& !_getRequest('idcatart'&& !_getRequest('idartlang')) {
  205.     $mrTestNoOptionSelected true;
  206. }
  207.  
  208. $aData['form']['idart_chk']     (_getRequest('idart')) ' checked="checked"' '';
  209. $aData['form']['idcat_chk']     (_getRequest('idcat')) ' checked="checked"' '';
  210. $aData['form']['idcatart_chk']  (_getRequest('idcatart')) ' checked="checked"' '';
  211. $aData['form']['idartlang_chk'(_getRequest('idartlang')) ' checked="checked"' '';
  212. $aData['form']['maxitems']      _getRequest('maxitems'200);
  213.  
  214.  
  215. $oMrTestAction new ModRewriteTestActions();
  216.  
  217. if ($mrTestNoOptionSelected{
  218.     $oMrTestAction->executeIndex();
  219. else {
  220.     $oMrTestAction->executeTest();
  221. }
  222.  
  223.  
  224. if (isset($oDebug)) {
  225.     if (is_array($GLOBALS['DB_Contenido_QueryCache']&& count($GLOBALS['DB_Contenido_QueryCache']0{
  226.         $oDebug->addDebug($GLOBALS['DB_Contenido_QueryCache']'sql statements');
  227.     }
  228.     $aData['content'.= $oDebug->getResults(false);
  229. }
  230.  
  231.  
  232. ####################################################################################################
  233. ##### Contenido front_content.php footer
  234.  
  235. if (file_exists("config.after.php")) {@include("config.after.php");}
  236. if (isset ($savedlang)){$lang $savedlang;}
  237. page_close();
  238.  
  239.  
  240. ####################################################################################################
  241. #### Template / View
  242.  
  243. echo <<<HTML
  244. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  245.    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  246. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="de">
  247. <head>
  248.     <title>Test - Contenido Plugin Advanced Mod Rewrite</title>
  249.     <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" />
  250.     <style type="text/css">
  251.     body {margin:0; padding:0; background:#fff; color:#000; font-family:arial,helvetica,sans-serif; font-size:12px;}
  252.     #wrap {margin:15px 10px;}
  253.     h1 {font-size:16px;}
  254.     form {width:70%; border:1px solid #999; background:#eaeaea; padding:0.5em; margin-bottom:15px;}
  255.     fieldset {margin-bottom:10px;}
  256.     fieldset p {margin:0;}
  257.     form .chk {width:24%; float:left;}
  258.     .left {float:left;}
  259.     .right {float:right;}
  260.     .clear {clear:both; font-size:0pt !important; height:0pt !important; line-height:0pt !important;}
  261.     </style>
  262. </head>
  263. <body>
  264. <div id="wrap">
  265.  
  266. <h1>Advanced Mod Rewrite test</h1>
  267.  
  268. <!-- ###just4dev### -->
  269. <pre>$tmp</pre>
  270.  
  271. <form name="mr_test" id="mr_test" action="{$_SERVER['PHP_SELF']}">
  272.     <fieldset>
  273.         <legend>Parameter to add</legend>
  274.         <p></p>
  275.         <div class="chk">
  276.             <input type="checkbox" id="idart" name="idart" value="1"{$aData['form']['idart_chk']} /><label for="idart">idart</label>
  277.         </div>
  278.         <div class="chk">
  279.             <input type="checkbox" id="idcat" name="idcat" value="1"{$aData['form']['idcat_chk']} /><label for="idcat">idcat</label>
  280.         </div>
  281.         <div class="chk">
  282.             <input type="checkbox" id="idcatart" name="idcatart" value="1"{$aData['form']['idcatart_chk']} /><label for="idcatart">idcatart</label>
  283.         </div>
  284.         <div class="chk">
  285.             <input type="checkbox" id="idartlang" name="idartlang" value="1"{$aData['form']['idartlang_chk']} /><label for="idartlang">idartlang</label>
  286.         </div>
  287.         <br class="clear" />
  288.     </fieldset>
  289.     <div style="margin:0.3em 0;">
  290.         <div class="left">
  291.             <label for="maxitems">Max items to process: </label><input type="text" id="maxitems" maxlength="4" name="maxitems" value="{$aData['form']['maxitems']}" />
  292.         </div>
  293.         <div class="right" style="padding-right:5px;">
  294.             <input type="submit" name="test" value="run test" />
  295.         </div>
  296.         <br class="clear" />
  297.     </div>
  298. </form>
  299.  
  300. {$aData['content']}
  301.  
  302. </div>
  303. </body>
  304. </html>
  305. HTML;
  306.  
  307.  
  308. ####################################################################################################
  309. ##### Classes / Functions
  310.  
  311.  
  312. /**
  313.  * Simple action controller.
  314.  *
  315.  * @author      Murat Purc <murat@purc.de>
  316.  * @copyright   © Murat Purc 2008
  317.  * @package     Contenido
  318.  * @subpackage  ModRewriteTest
  319.  */
  320.  
  321.     private $data;
  322.  
  323.     function __construct({
  324.         $this->data = $GLOBALS['aData'];
  325.     }
  326.  
  327.     /**
  328.      * Execute index action
  329.      */
  330.     function executeIndex({
  331.         $this->data['content''<pre>
  332.  
  333. Select several options from above and run the test.
  334.  
  335. <b>The result will be a outputlist like:</b>
  336.  
  337. Navigationame
  338. builder in:    The URL beeing passed to the URL builder
  339. builder out:   Result of rebuild URL, should be consistent with your settings
  340. resolved url:  Resolved URL (the URL beeing returned by URL builder) by ModRewriteController
  341. resolved data: Some resolved variables like $client, $lang, etc.
  342.  
  343. <b>Example:</b>
  344.  
  345. Navigationame
  346. builder in:    front_content.php?idcat=1&foo=bar
  347. builder out:   /deutsch-hauptnavigation.index.html?foo=bar
  348. resolved url:  /deutsch/hauptnavigation/index.html?foo=bar
  349. resolved data: client=1; lang=1; changelang=1; idcat=1
  350. </pre>';
  351.  
  352.     }
  353.  
  354.     /**
  355.      * Execute test action
  356.      */
  357.     function executeTest({
  358.         $this->data['content''';
  359.  
  360.         // Array for testcases
  361.         $aTests  array();
  362.  
  363.         // Instance of mr test
  364.         $oMRTest new ModRewriteTest();
  365.  
  366.         $startTime getmicrotime();
  367.  
  368.         // Fetch complete Contenido page structure
  369.         $aStruct $oMRTest->fetchFullStructure();
  370.         Contenido_mpDebug::getInstance()->addDebug($aStruct'mr_test.php $aStruct');
  371.  
  372.         // Loop through the structure and compose testcases
  373.         foreach ($aStruct as $idcat => $aCat{
  374.             // category
  375.             $aTests[array(
  376.                 'url'   => $oMRTest->composeURL($aCat'c'),
  377.                 'level' => $aCat['level'],
  378.                 'name'  => $aCat['name']
  379.             );
  380.  
  381.             foreach ($aCat['articles'as $idart => $aArt{
  382.                 // articles
  383.                 $aTests[array(
  384.                     'url'  => $oMRTest->composeURL($aArt'a'),
  385.                     'level' => $aCat['level'],
  386.                     'name' => $aCat['name'' :: ' $aArt['title']
  387.                 );
  388.             }
  389.         }
  390.  
  391.         // compose content
  392.         $this->data['content''<pre>';
  393.  
  394.         $oMRUrlStack ModRewriteUrlStack::getInstance();
  395.  
  396.         // first loop to add urls to mr url stack
  397.         foreach ($aTests as $p => $v{
  398.             $oMRUrlStack->add($v['url']);
  399.         }
  400.  
  401.         // second loop to do the rest
  402.         foreach ($aTests as $p => $v{
  403.             $url    mr_buildNewUrl($v['url']);
  404.             $arr    $oMRTest->resolveUrl($url);
  405.             $resUrl $oMRTest->getResolvedUrl();
  406.             $color  'green';
  407.  
  408.             if ($url !== $resUrl{
  409.                 if ($oMRTest->getRoutingFoundState()) {
  410.                     $resUrl 'route to -&gt; ' $resUrl;
  411.                 else {
  412.                     $color  'red';
  413.                 }
  414.             }
  415.             $pref   str_repeat('    '$v['level']);
  416.  
  417.             $this->data['content'.= "\n"
  418.                 . $pref '<strong>' $v['name''</strong>' "\n"
  419.                 . $pref 'builder in:    ' $v['url'"\n"
  420.                 . $pref 'builder out:   <a href="' $url '" target="_blank">' $url '</a>'  "\n"
  421.                 . $pref '<span style="color:' $color '">resolved url:  ' $resUrl "</span>\n"
  422.                 . $pref 'resolved data: ' $oMRTest->getReadableResolvedData($arr"\n";
  423.         }
  424.         $this->data['content'.= '</pre>';
  425.  
  426.         $totalTime sprintf('%.4f'(getmicrotime($startTime));
  427.         $msg '<strong>Execution of test took: ' $totalTime ' seconds.</strong><br /><br />';
  428.  
  429.         $this->data['content'$msg $this->data['content'];
  430.  
  431.     }
  432.  
  433. }
  434.  
  435.  
  436. /**
  437.  * Advanced Mod Rewrite test class.
  438.  *
  439.  * @author      Murat Purc <murat@purc.de>
  440.  * @copyright   © Murat Purc 2008
  441.  * @package     Contenido
  442.  * @subpackage  ModRewriteTest
  443.  */
  444. class ModRewriteTest {
  445.  
  446.     /**
  447.      * @var  array  Global $cfg array
  448.      */
  449.     private $cfg;
  450.  
  451.     /**
  452.      * @var  array  Global $cfg['tab'] array
  453.      */
  454.     private $cfgTab;
  455.  
  456.  
  457.     /**
  458.      * @var  int  Max items to process
  459.      */
  460.     private $maxItems;
  461.  
  462.     /**
  463.      * @var  string  Actual resolved url
  464.      */
  465.     private $sResolvedUrl;
  466.  
  467.  
  468.     /**
  469.      * @var  bool  Routing found flag
  470.      */
  471.     private $bRoutingFound = false;
  472.  
  473.  
  474.     /**
  475.      * Constuctor
  476.      */
  477.     function __construct({
  478.         $this->cfg    = $GLOBALS['cfg'];
  479.         $this->cfgTab = $GLOBALS['cfg']['tab'];
  480.         $this->maxItems = $GLOBALS['aData']['form']['maxitems'];
  481.     }
  482.  
  483.  
  484.     /**
  485.      * Returns resolved URL
  486.      *
  487.      * @return  bool  Resolved URL
  488.      */
  489.     function getResolvedUrl(){
  490.         return $this->sResolvedUrl;
  491.     }
  492.  
  493.  
  494.     /**
  495.      * Returns flagz about found routing
  496.      *
  497.      * @return  bool 
  498.      */
  499.     function getRoutingFoundState(){
  500.         return $this->bRoutingFound;
  501.     }
  502.  
  503.  
  504.     /**
  505.      * Fetchs full structure of the installation (categories and articles) and returns it back.
  506.      *
  507.      * @param   int    $idclient  Client id
  508.      * @param   int    $idlang    Language id
  509.      * @return  array  Full structure as follows
  510.      *  <code>
  511.      *    $arr[idcat] = Category dataset
  512.      *    $arr[idcat]['articles'][idart] = Article dataset
  513.      *  </code>
  514.      */
  515.     function fetchFullStructure($idclient=null$idlang=null{
  516.  
  517.         $db  new DB_Contenido();
  518.         $db2 new DB_Contenido();
  519.  
  520.         if (!$idclient || (int) $idclient == 0{
  521.             $idclient $GLOBALS['client'];
  522.         }
  523.         if (!$idlang || (int) $idlang == 0{
  524.             $idlang $GLOBALS['lang'];
  525.         }
  526.  
  527.         $aTab $this->cfgTab;
  528.  
  529.         $aStruct array();
  530.  
  531.         $sql "SELECT
  532.                     *
  533.                 FROM
  534.                     " $aTab['cat_tree'" AS a,
  535.                     " $aTab['cat_lang'" AS b,
  536.                     " $aTab['cat'" AS c
  537.                 WHERE
  538.                     a.idcat = b.idcat AND
  539.                     c.idcat = a.idcat AND
  540.                     c.idclient = '".$idclient."' AND
  541.                     b.idlang = '".$idlang."'
  542.                 ORDER BY
  543.                     a.idtree";
  544.  
  545.         $db->query($sql);
  546.  
  547.         $loop    false;
  548.         $counter 0;
  549.  
  550.         while ($db->next_record()) {
  551.  
  552.             if (++$counter == $this->maxItems{
  553.                 break// break this loop
  554.             }
  555.  
  556.             $idcat $db->f('idcat');
  557.             $aStruct[$idcat$db->Record;
  558.             $aStruct[$idcat]['articles'array();
  559.  
  560.             if ($this->cfg['is_start_compatible'== true{
  561.                 $compStatement ' a.is_start DESC, ';
  562.             else {
  563.                 $compStatement '';
  564.             }
  565.  
  566.             $sql2 "SELECT
  567.                          *
  568.                      FROM
  569.                          ".$aTab['cat_art']."  AS a,
  570.                          ".$aTab['art']."      AS b,
  571.                          ".$aTab['art_lang']." AS c
  572.                      WHERE
  573.                          a.idcat = '".$idcat."' AND
  574.                          b.idart = a.idart AND
  575.                          c.idart = a.idart AND
  576.                          c.idlang = '".$idlang."' AND
  577.                          b.idclient = '".$idclient."'
  578.                      ORDER BY
  579.                          " $compStatement "
  580.                          c.title ASC";
  581.  
  582.             $db2->query($sql2);
  583.  
  584.             while ($db2->next_record()) {
  585.                 $idart $db2->f('idart');
  586.                 $aStruct[$idcat]['articles'][$idart$db2->Record;
  587.                 if (++$counter == $this->maxItems{
  588.                     break 2// break this and also superior loop
  589.                 }
  590.             }
  591.         }
  592.  
  593.         return $aStruct;
  594.     }
  595.  
  596.  
  597.     /**
  598.      * Creates an URL using passed data.
  599.      *
  600.      * The result is used to generate seo urls...
  601.      *
  602.      * @param  array  $arr  Assoziative array with some data as follows:
  603.      *  <code>
  604.      *  $arr['idcat']
  605.      *  $arr['idart']
  606.      *  $arr['idcatart']
  607.      *  $arr['idartlang']
  608.      *  </code>
  609.      * @param  string  $type  Either 'c' or 'a' (category or article). If set to
  610.      *                         'c' only the parameter idcat will be added to the URL
  611.      */
  612.     function composeURL($arr$type{
  613.         $type ($type == 'a''a' 'c';
  614.  
  615.         $param array();
  616.  
  617.         if ($type == 'c'{
  618.             $param['idcat=' $arr['idcat'];
  619.         else {
  620.             if (_getRequest('idart')) {
  621.                 $param['idart=' $arr['idart'];
  622.             }
  623.             if (_getRequest('idcat')) {
  624.                 $param['idcat=' $arr['idcat'];
  625.             }
  626.             if (_getRequest('idcatart')) {
  627.                 $param['idcatart=' $arr['idcatart'];
  628.             }
  629.             if (_getRequest('idartlang')) {
  630.                 $param['idartlang=' $arr['idartlang'];
  631.             }
  632.         }
  633.         $param['foo=bar';
  634.         return 'front_content.php?' implode('&amp;'$param);
  635.  
  636.     }
  637.  
  638.  
  639.     /**
  640.      * Resolves variables of an page (idcat, idart, idclient, idlang, etc.) by
  641.      * processing passed url using ModRewriteController
  642.      *
  643.      * @param   string  $url  Url to resolve
  644.      * @return  array   Assoziative array with resolved data
  645.      */
  646.     public function resolveUrl($url){
  647.  
  648.         // some globals to reset
  649.         $aGlobs array(
  650.             'mr_preprocessedPageError''idart''idcat'
  651.         );
  652.         foreach ($aGlobs as $p => $k{
  653.             if (isset($GLOBALS[$k])) unset($GLOBALS[$k])}
  654.         }
  655.  
  656.         $aReturn array();
  657.  
  658.         // create an mod rewrite controller instance and execute processing
  659.         $oMRController new ModRewriteController($url);
  660.         $oMRController->execute();
  661.  
  662.         if ($oMRController->errorOccured()) {
  663.  
  664.             // an error occured (idcat and or idart couldn't catched by controller)
  665.             $aReturn['mr_preprocessedPageError'1;
  666.  
  667. ##++##            $this->sResolvedUrl  = '';
  668.             $this->bRoutingFound = false;
  669.  
  670.         else {
  671.  
  672.             // set some global variables
  673.  
  674.             $this->sResolvedUrl  = $oMRController->getResolvedUrl();
  675.             $this->bRoutingFound = $oMRController->getRoutingFoundState();
  676.  
  677.             if ($oMRController->getClient()) {
  678.                 $aReturn['client'$oMRController->getClient();
  679.             }
  680.  
  681.             if ($oMRController->getChangeClient()) {
  682.                 $aReturn['changeclient'$oMRController->getChangeClient();
  683.             }
  684.  
  685.             if ($oMRController->getLang()) {
  686.                 $aReturn['lang'$oMRController->getLang();
  687.             }
  688.  
  689.             if ($oMRController->getChangeLang()) {
  690.                 $aReturn['changelang'$oMRController->getChangeLang();
  691.             }
  692.  
  693.             if ($oMRController->getIdArt()) {
  694.                 $aReturn['idart'$oMRController->getIdArt();
  695.             }
  696.  
  697.             if ($oMRController->getIdCat()) {
  698.                 $aReturn['idcat'$oMRController->getIdCat();
  699.             }
  700.  
  701.             if ($oMRController->getPath()) {
  702.                 $aReturn['path'$oMRController->getPath();
  703.             }
  704.  
  705.         }
  706.  
  707.         return $aReturn;
  708.     }
  709.  
  710.  
  711.     /**
  712.      * Creates a readable string from passed resolved data array.
  713.      *
  714.      * @param   array   Assoziative array with resolved data
  715.      * @return  string  Readable resolved data
  716.      */
  717.     public function getReadableResolvedData(array $data{
  718.         // compose resolved string
  719.         $ret '';
  720.         foreach ($data as $k => $v{
  721.             $ret .= $k '=' $v '; ';
  722.         }
  723.         $ret substr($ret0strlen($ret)-2);
  724.         return $ret;
  725.     }
  726.  
  727. }
  728.  
  729.  
  730. /**
  731.  * Minimalistic'n simple way to get request variables.
  732.  *
  733.  * Checks occurance in $_GET, then in $_POST. Uses trim() and strip_tags() to preclean data.
  734.  *
  735.  * @param   string  $key      Name of var to get
  736.  * @param   mixed   $default  Default value to return
  737.  * @return  mixed   The value
  738.  */
  739. function _getRequest($key$default=null{
  740.     static $cache;
  741.     if (!isset($cache)) {
  742.         $cache array();
  743.     }
  744.     if (isset($cache[$key])) {
  745.         return $cache[$key];
  746.     }
  747.     if (isset($_GET[$key])) {
  748.         $val $_GET[$key];
  749.     elseif (isset($_POST[$key])) {
  750.         $val $_POST[$key];
  751.     else {
  752.         $val $default;
  753.     }
  754.     $cache[$keystrip_tags(trim($val));
  755.     return $cache[$key];
  756. }

Documentation generated on Tue, 25 Nov 2008 22:07:52 +0100 by phpDocumentor 1.4.1