/**
  *
  * @param string $scriptNamePath    /path/index.php
  * @param string $pathinfo          the path info part of the url (part between script name and query)
  * @param array  $params            url parameters (query part e.g. $_REQUEST)
  * @param boolean $isHttps          says if the given url is asked with https or not
  * @return jUrlAction
  */
 protected function _parse($scriptNamePath, $pathinfo, $params, $isHttps)
 {
     $urlact = null;
     $isDefault = false;
     $url = new jUrl($scriptNamePath, $params, $pathinfo);
     foreach ($this->dataParseUrl as $k => $infoparsing) {
         // the first element indicates if the entry point is a default entry point or not
         if ($k == 0) {
             $isDefault = $infoparsing;
             continue;
         }
         if (count($infoparsing) < 7) {
             // an handler will parse the request URI
             list($module, $action, $reg, $selectorHandler, $secondariesActions, $needHttps) = $infoparsing;
             $url2 = clone $url;
             if ($reg != '') {
                 if (preg_match($reg, $pathinfo, $m)) {
                     $url2->pathInfo = isset($m[1]) ? $m[1] : '/';
                 } else {
                     continue;
                 }
             }
             $s = new jSelectorUrlHandler($selectorHandler);
             include_once $s->getPath();
             $c = $s->className . 'UrlsHandler';
             $handler = new $c();
             $url2->params['module'] = $module;
             // if the action parameter exists in the current url
             // and if it is one of secondaries actions, then we keep it
             // else we take the action indicated in the url mapping
             if ($secondariesActions && isset($params['action'])) {
                 if (strpos($params['action'], ':') === false) {
                     $params['action'] = 'default:' . $params['action'];
                 }
                 if (in_array($params['action'], $secondariesActions)) {
                     // action peut avoir été écrasé par une itération précédente
                     $url2->params['action'] = $params['action'];
                 } else {
                     $url2->params['action'] = $action;
                 }
             } else {
                 $url2->params['action'] = $action;
             }
             // appel au handler
             if ($urlact = $handler->parse($url2)) {
                 break;
             }
         } elseif (preg_match($infoparsing[2], $pathinfo, $matches)) {
             /* we have this array
                             array( 0=>'module', 1=>'action', 2=>'regexp_pathinfo',
                             3=>array('year','month'), // list of dynamic value included in the url,
                                                   // alphabetical ascendant order
                             4=>array(0, 1..), // list of integer which indicates for each
                                             // dynamic value: 0: urlencode, 1:urlencode except '/', 2:escape, 4: lang, 8: locale
             
                             5=>array('bla'=>'whatIWant' ), // list of static values
                             6=>false or array('secondaries','actions')
                             */
             list($module, $action, $reg, $dynamicValues, $escapes, $staticValues, $secondariesActions, $needHttps) = $infoparsing;
             if (isset($params['module']) && $params['module'] !== $module) {
                 continue;
             }
             if ($module != '') {
                 $params['module'] = $module;
             }
             // if the action parameter exists in the current url
             // and if it is one of secondaries actions, then we keep it
             // else we take the action indicated in the url mapping
             if ($secondariesActions && isset($params['action'])) {
                 if (strpos($params['action'], ':') === false) {
                     $params['action'] = 'default:' . $params['action'];
                 }
                 if (!in_array($params['action'], $secondariesActions) && $action != '') {
                     $params['action'] = $action;
                 }
             } else {
                 if ($action != '') {
                     $params['action'] = $action;
                 }
             }
             // let's merge static parameters
             if ($staticValues) {
                 foreach ($staticValues as $n => $v) {
                     if (!empty($v) && $v[0] == '$') {
                         // special statique value
                         $typeStatic = $v[1];
                         $v = substr($v, 2);
                         if ($typeStatic == 'l') {
                             jApp::config()->locale = jLocale::langToLocale($v);
                         } else {
                             if ($typeStatic == 'L') {
                                 jApp::config()->locale = $v;
                             }
                         }
                     }
                     $params[$n] = $v;
                 }
             }
             // now let's read dynamic parameters
             if (count($matches)) {
                 array_shift($matches);
                 foreach ($dynamicValues as $k => $name) {
                     if (isset($matches[$k])) {
                         if ($escapes[$k] & 2) {
                             $params[$name] = jUrl::unescape($matches[$k]);
                         } else {
                             $params[$name] = $matches[$k];
                             if ($escapes[$k] & 4) {
                                 $v = $matches[$k];
                                 if (preg_match('/^\\w{2,3}$/', $v, $m)) {
                                     jApp::config()->locale = jLocale::langToLocale($v);
                                 } else {
                                     jApp::config()->locale = $v;
                                     $params[$name] = substr($v, 0, strpos('_'));
                                 }
                             } else {
                                 if ($escapes[$k] & 8) {
                                     $v = $matches[$k];
                                     if (preg_match('/^\\w{2,3}$/', $v, $m)) {
                                         jApp::config()->locale = $params[$name] = jLocale::langToLocale($v);
                                     } else {
                                         jApp::config()->locale = $v;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $urlact = new jUrlAction($params);
             break;
         }
     }
     if (!$urlact) {
         if ($isDefault && $pathinfo == '') {
             // if we didn't find the url in the mapping, and if this is the default
             // entry point, then we do anything
             $urlact = new jUrlAction($params);
         } else {
             try {
                 $urlact = jUrl::get(jApp::config()->urlengine['notfoundAct'], array(), jUrl::JURLACTION);
             } catch (Exception $e) {
                 $urlact = new jUrlAction(array('module' => 'jelix', 'action' => 'error:notfound'));
             }
         }
     } else {
         if ($needHttps && !$isHttps) {
             // the url is declared for HTTPS, but the request does not come from HTTPS
             // -> 404 not found
             $urlact = new jUrlAction(array('module' => 'jelix', 'action' => 'error:notfound'));
         }
     }
     return $urlact;
 }
Exemple #2
0
 /**
  * extract parameters for the action from the path info.
  *
  * @params array $infoparsing  we have this array
  *                   array(
  *                   0=>'module',
  *                   1=>'action',
  *                   2=>'regexp_pathinfo',
  *                   3=>array('year','month'), // list of dynamic value included in the url,
  *                                         // alphabetical ascendant order
  *                   4=>array(0, 1..), // list of integer which indicates for each
  *                                   // dynamic value: 0: urlencode, 1:urlencode except '/', 2:escape, 4: lang, 8: locale
  *           
  *                   5=>array('bla'=>'whatIWant' ), // list of static values
  *                   6=>false or array('secondaries','actions')
  *                   7=>true/false  true if https is needed
  * @params array $matches  result of the match with the regexp corresponding to the url
  *
  * @return \jUrlAction or null if the handler does not accept the url
  */
 protected function parseGetParams($infoparsing, \jUrl $url, $matches)
 {
     list($module, $action, $reg, $dynamicValues, $escapes, $staticValues, $secondariesActions, $needsHttps) = $infoparsing;
     $params = $url->params;
     $params['module'] = $module;
     if ($secondariesActions && isset($params['action'])) {
         // if the action parameter exists in the current url
         // and if it is one of secondaries actions, then we keep it
         // else we take the action indicated in the url mapping
         if (strpos($params['action'], ':') === false) {
             $params['action'] = 'default:' . $params['action'];
         }
         if (!in_array($params['action'], $secondariesActions) && $action != '') {
             $params['action'] = $action;
         }
     } elseif ($action != '') {
         if (substr($action, -2) == ':*') {
             $action = substr($action, 0, -1);
             // This is an url for a whole controller
             if (isset($matches[1]) && $matches[1]) {
                 $action .= $matches[1];
             } else {
                 $action .= 'index';
             }
             $matches = array();
         }
         // else this is an url for a specific action
         $params['action'] = $action;
     } elseif (count($matches) == 2) {
         // this an url for a whole module
         if ($matches[1] == '/' || $matches[1] == '') {
             $params['action'] = 'default:index';
         } else {
             $pathInfoParts = explode('/', $matches[1]);
             $co = count($pathInfoParts);
             if ($co == 2) {
                 $params['action'] = $pathInfoParts[1] . ':index';
             } else {
                 $params['action'] = $pathInfoParts[1] . ':' . $pathInfoParts[2];
             }
         }
         $matches = array();
     }
     // let's merge static parameters
     if ($staticValues) {
         foreach ($staticValues as $n => $v) {
             if (!empty($v) && $v[0] == '$') {
                 // special statique value
                 $typeStatic = $v[1];
                 $v = substr($v, 2);
                 if ($typeStatic == 'l') {
                     App::config()->locale = Locale::langToLocale($v);
                 } elseif ($typeStatic == 'L') {
                     App::config()->locale = $v;
                 }
             }
             $params[$n] = $v;
         }
     }
     // now let's read dynamic parameters
     if (count($matches)) {
         array_shift($matches);
         foreach ($dynamicValues as $k => $name) {
             if (isset($matches[$k])) {
                 if ($escapes[$k] & self::ESCAPE_NON_ASCII) {
                     $params[$name] = \jUrl::unescape($matches[$k]);
                 } else {
                     $params[$name] = $matches[$k];
                     if ($escapes[$k] & self::ESCAPE_LANG) {
                         $v = $matches[$k];
                         if (preg_match('/^\\w{2,3}$/', $v, $m)) {
                             App::config()->locale = Locale::langToLocale($v);
                         } else {
                             App::config()->locale = $v;
                             $params[$name] = substr($v, 0, strpos('_'));
                         }
                     } elseif ($escapes[$k] & self::ESCAPE_LOCALE) {
                         $v = $matches[$k];
                         if (preg_match('/^\\w{2,3}$/', $v, $m)) {
                             App::config()->locale = $params[$name] = Locale::langToLocale($v);
                         } else {
                             App::config()->locale = $v;
                         }
                     }
                 }
             }
         }
     }
     $urlact = new \jUrlAction($params);
     $urlact->needsHttps = $needsHttps;
     return $urlact;
 }
 /**
  * provide a atom feeds for each forum
  */
 function atom()
 {
     $ftitle = jUrl::unescape($this->param('ftitle'), true);
     $id_forum = $this->intParam('id_forum');
     // if the forum is accessible by anonymous then the Atom will be available
     // otherwise NO Atom will be available
     if (!jAcl2::check('hfnu.posts.rss', 'forum' . $id_forum)) {
         jMessage::add(jLocale::get('havefnubb~main.permissions.denied'), 'error');
         $rep = $this->getResponse('html');
         $tpl = new jTpl();
         $rep->body->assign('MAIN', $tpl->fetch('havefnubb~403.html'));
         $rep->setHttpStatus('403', 'Permission denied');
         return $rep;
     }
     if ($id_forum == 0) {
         jLog::log(__METHOD__ . ' line : ' . __LINE__ . ' [this should not be 0] $id_forum', 'DEBUG');
         $rep = $this->getResponse('html');
         $tpl = new jTpl();
         $rep->body->assign('MAIN', $tpl->fetch('havefnubb~404.html'));
         $rep->setHttpStatus('404', 'Not found');
         return $rep;
     }
     $rep = $this->getResponse('atom1.0');
     $gJConfig = jApp::config();
     // entete du flux atom
     $rep->infos->title = $gJConfig->havefnubb['title'];
     $rep->infos->webSiteUrl = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'];
     $rep->infos->copyright = $gJConfig->havefnubb['title'];
     $rep->infos->description = $gJConfig->havefnubb['description'];
     $rep->infos->updated = date('Y-m-d H:i:s');
     $rep->infos->published = date('Y-m-d H:i:s');
     $rep->infos->selfLink = jUrl::get('havefnubb~posts:atom', array('ftitle' => $ftitle, 'id_forum' => $fid_forum));
     $rep->infos->ttl = 60;
     $dao = jDao::get('havefnubb~forum');
     $forum = $dao->get($id_forum);
     if (jUrl::escape($forum->forum_name, true) != $ftitle) {
         jLog::log(__METHOD__ . ' line : ' . __LINE__ . ' [this should not be different] $forum->forum_name and $ftitle', 'DEBUG');
         $rep = $this->getResponse('html');
         $tpl = new jTpl();
         $rep->body->assign('MAIN', $tpl->fetch('havefnubb~404.html'));
         $rep->setHttpStatus('404', 'Not found');
         return $rep;
     }
     // 1- limit of posts
     $nbPostPerPage = 0;
     $nbPostPerPage = (int) $gJConfig->havefnubb['posts_per_page'];
     // 2- get the posts of the current forum, limited by point 1
     // get all the posts of the current Forum by its Id
     list($page, $nbPosts, $posts) = jClasses::getService('havefnubb~hfnuposts')->getThreads($id_forum, 0, $nbPostPerPage);
     $first = true;
     foreach ($posts as $post) {
         if ($first) {
             // le premier enregistrement permet de connaitre
             // la date du channel
             $rep->infos->updated = date('Y-m-d H:i:s', $post->date_created);
             $rep->infos->published = date('Y-m-d H:i:s', $post->date_created);
             $first = false;
         }
         $url = jUrl::getFull('havefnubb~posts:view', array('id_post' => $post->id_post, 'thread_id' => $post->thread_id, 'ftitle' => $post->forum_name, 'id_forum' => $post->id_forum, 'ptitle' => $post->subject));
         $item = $rep->createItem($post->subject, $url, date('Y-m-d H:i:s', $post->date_created));
         $item->authorName = $post->login;
         $render = new jWiki();
         $item->content = $render->render($post->message);
         $item->contentType = 'html';
         $item->idIsPermalink = true;
         // on ajoute l'item dans le fil atom
         $rep->addItem($item);
     }
     return $rep;
 }
 /**
  *
  * @param string $scriptNamePath    /path/index.php
  * @param string $pathinfo          the path info part of the url (part between script name and query)
  * @param array  $params            url parameters (query part e.g. $_REQUEST)
  * @return jUrlAction
  */
 protected function _parse($scriptNamePath, $pathinfo, $params)
 {
     global $gJConfig;
     /*if(substr($pathinfo,-1) == '/' && $pathinfo != '/'){
               $pathinfo = substr($pathinfo,0,-1);
       }*/
     $urlact = null;
     $isDefault = false;
     $url = new jUrl($scriptNamePath, $params, $pathinfo);
     foreach ($this->dataParseUrl as $k => $infoparsing) {
         // le premier paramètre indique si le point d'entré actuelle est un point d'entré par défaut ou non
         if ($k == 0) {
             $isDefault = $infoparsing;
             continue;
         }
         if (count($infoparsing) < 5) {
             // on a un tableau du style
             // array( 0=> 'module', 1=>'action', 2=>'selecteur handler', 3=>array('actions','secondaires'))
             $s = new jSelectorUrlHandler($infoparsing[2]);
             $c = $s->className . 'UrlsHandler';
             $handler = new $c();
             $url->params['module'] = $infoparsing[0];
             // si une action est présente dans l'url actuelle
             // et qu'elle fait partie des actions secondaires, alors on la laisse
             // sinon on prend celle indiquée dans la conf
             if ($infoparsing[3] && isset($params['action'])) {
                 if (strpos($params['action'], ':') === false) {
                     $params['action'] = 'default:' . $params['action'];
                 }
                 if (in_array($params['action'], $infoparsing[3])) {
                     $url->params['action'] = $params['action'];
                 } else {
                     $url->params['action'] = $infoparsing[1];
                 }
             } else {
                 $url->params['action'] = $infoparsing[1];
             }
             // appel au handler
             if ($urlact = $handler->parse($url)) {
                 break;
             }
         } else {
             /* on a un tableau du style
                array( 0=>'module', 1=>'action', 2=>'regexp_pathinfo',
                3=>array('annee','mois'), // tableau des valeurs dynamiques, classées par ordre croissant
                4=>array(true, false), // tableau des valeurs escapes
                5=>array('bla'=>'cequejeveux' ) // tableau des valeurs statiques
                6=>false ou array('act','act'...) // autres actions secondaires autorisées
                */
             if (preg_match($infoparsing[2], $pathinfo, $matches)) {
                 if ($infoparsing[0] != '') {
                     $params['module'] = $infoparsing[0];
                 }
                 // si une action est présente dans l'url actuelle
                 // et qu'elle fait partie des actions secondaires, alors on la laisse
                 // sinon on prend celle indiquée dans la conf
                 if ($infoparsing[6] && isset($params['action'])) {
                     if (strpos($params['action'], ':') === false) {
                         $params['action'] = 'default:' . $params['action'];
                     }
                     if (!in_array($params['action'], $infoparsing[6]) && $infoparsing[1] != '') {
                         $params['action'] = $infoparsing[1];
                     }
                 } else {
                     if ($infoparsing[1] != '') {
                         $params['action'] = $infoparsing[1];
                     }
                 }
                 // on fusionne les parametres statiques
                 if ($infoparsing[5]) {
                     $params = array_merge($params, $infoparsing[5]);
                 }
                 if (count($matches)) {
                     array_shift($matches);
                     foreach ($infoparsing[3] as $k => $name) {
                         if (isset($matches[$k])) {
                             if ($infoparsing[4][$k]) {
                                 $params[$name] = jUrl::unescape($matches[$k]);
                             } else {
                                 $params[$name] = $matches[$k];
                             }
                         }
                     }
                 }
                 $urlact = new jUrlAction($params);
                 break;
             }
         }
     }
     if (!$urlact) {
         if ($isDefault && $pathinfo == '') {
             // si on n'a pas trouvé de correspondance, mais que c'est l'entry point
             // par defaut pour le type de request courant, alors on laisse passer..
             $urlact = new jUrlAction($params);
         } else {
             try {
                 $urlact = jUrl::get($gJConfig->urlengine['notfoundAct'], array(), jUrl::JURLACTION);
             } catch (Exception $e) {
                 $urlact = new jUrlAction(array('module' => 'jelix', 'action' => 'error:notfound'));
             }
         }
     }
     return $urlact;
 }
 protected function _parse($scriptNamePath, $pathinfo, $params, $isHttps)
 {
     $urlact = null;
     $isDefault = false;
     $url = new jUrl($scriptNamePath, $params, $pathinfo);
     foreach ($this->dataParseUrl as $k => $infoparsing) {
         if ($k == 0) {
             $isDefault = $infoparsing;
             continue;
         }
         if (count($infoparsing) < 7) {
             list($module, $action, $reg, $selectorHandler, $secondariesActions, $needHttps) = $infoparsing;
             $url2 = clone $url;
             if ($reg != '') {
                 if (preg_match($reg, $pathinfo, $m)) {
                     $url2->pathInfo = isset($m[1]) ? $m[1] : '/';
                 } else {
                     continue;
                 }
             }
             $s = new jSelectorUrlHandler($selectorHandler);
             include_once $s->getPath();
             $c = $s->className . 'UrlsHandler';
             $handler = new $c();
             $url2->params['module'] = $module;
             if ($secondariesActions && isset($params['action'])) {
                 if (strpos($params['action'], ':') === false) {
                     $params['action'] = 'default:' . $params['action'];
                 }
                 if (in_array($params['action'], $secondariesActions)) {
                     $url2->params['action'] = $params['action'];
                 } else {
                     $url2->params['action'] = $action;
                 }
             } else {
                 $url2->params['action'] = $action;
             }
             if ($urlact = $handler->parse($url2)) {
                 break;
             }
         } elseif (preg_match($infoparsing[2], $pathinfo, $matches)) {
             list($module, $action, $reg, $dynamicValues, $escapes, $staticValues, $secondariesActions, $needHttps) = $infoparsing;
             if (isset($params['module']) && $params['module'] !== $module) {
                 continue;
             }
             if ($module != '') {
                 $params['module'] = $module;
             }
             if ($secondariesActions && isset($params['action'])) {
                 if (strpos($params['action'], ':') === false) {
                     $params['action'] = 'default:' . $params['action'];
                 }
                 if (!in_array($params['action'], $secondariesActions) && $action != '') {
                     $params['action'] = $action;
                 }
             } else {
                 if ($action != '') {
                     $params['action'] = $action;
                 }
             }
             if ($staticValues) {
                 foreach ($staticValues as $n => $v) {
                     if ($v[0] == '$') {
                         $typeStatic = $v[1];
                         $v = substr($v, 2);
                         if ($typeStatic == 'l') {
                             jApp::config()->locale = jLocale::langToLocale($v);
                         } else {
                             if ($typeStatic == 'L') {
                                 jApp::config()->locale = $v;
                             }
                         }
                     }
                     $params[$n] = $v;
                 }
             }
             if (count($matches)) {
                 array_shift($matches);
                 foreach ($dynamicValues as $k => $name) {
                     if (isset($matches[$k])) {
                         if ($escapes[$k] & 2) {
                             $params[$name] = jUrl::unescape($matches[$k]);
                         } else {
                             $params[$name] = $matches[$k];
                             if ($escapes[$k] & 4) {
                                 $v = $matches[$k];
                                 if (preg_match('/^\\w{2,3}$/', $v, $m)) {
                                     jApp::config()->locale = jLocale::langToLocale($v);
                                 } else {
                                     jApp::config()->locale = $v;
                                     $params[$name] = substr($v, 0, strpos('_'));
                                 }
                             } else {
                                 if ($escapes[$k] & 8) {
                                     $v = $matches[$k];
                                     if (preg_match('/^\\w{2,3}$/', $v, $m)) {
                                         jApp::config()->locale = $params[$name] = jLocale::langToLocale($v);
                                     } else {
                                         jApp::config()->locale = $v;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $urlact = new jUrlAction($params);
             break;
         }
     }
     if (!$urlact) {
         if ($isDefault && $pathinfo == '') {
             $urlact = new jUrlAction($params);
         } else {
             try {
                 $urlact = jUrl::get(jApp::config()->urlengine['notfoundAct'], array(), jUrl::JURLACTION);
             } catch (Exception $e) {
                 $urlact = new jUrlAction(array('module' => 'jelix', 'action' => 'error:notfound'));
             }
         }
     } else {
         if ($needHttps && !$isHttps) {
             $urlact = new jUrlAction(array('module' => 'jelix', 'action' => 'error:notfound'));
         }
     }
     return $urlact;
 }