protected function _initParams()
 {
     $url = jUrl::getEngine()->parseFromRequest($this, $_GET);
     if ($_SERVER['REQUEST_METHOD'] == 'PUT') {
         $_PUT = $this->readHttpBody();
         if (is_string($_PUT)) {
             $this->params['__httpbody'] = $_PUT;
         } else {
             $this->params = array_merge($url->params, $_PUT);
         }
     } else {
         $this->params = array_merge($url->params, $_POST);
     }
 }
 protected function _initParams()
 {
     $url = jUrl::getEngine()->parseFromRequest($this, $_GET);
     $this->params = array_merge($url->params, $_POST);
 }
Beispiel #3
0
 /**
  * Parse a url from the request
  * @param jRequest $request
  * @param array  $params            url parameters ($_REQUEST, or $_GET)
  * @return jUrlAction
  * @since 1.1
  */
 static function parseFromRequest($request, $params)
 {
     return jUrl::getEngine()->parseFromRequest($request, $params);
 }
 /**
  * get the jUrl object corresponding to the action
  * @return jUrl
  */
 public function toUrl()
 {
     return jUrl::getEngine()->create($this);
 }
/**
* @package    jelix
* @subpackage jtpl_plugin
* @author     Laurent Jouanneau
* @copyright  2007 Laurent Jouanneau
* @contributor Christian Tritten (christian.tritten@laposte.net)
* @copyright  2007 Christian Tritten
* @link        http://www.jelix.org
* @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
*/
function jtpl_function_html_pagelinks($tpl, $action, $actionParams, $itemsTotal, $offset, $pageSize = 15, $paramName = 'offset', $displayProperties = array())
{
    $offset = intval($offset);
    if ($offset <= 0) {
        $offset = 0;
    }
    $itemsTotal = intval($itemsTotal);
    $pageSize = intval($pageSize);
    if ($pageSize < 1) {
        $pageSize = 1;
    }
    if ($itemsTotal > $pageSize) {
        $jUrlEngine = jUrl::getEngine();
        $urlaction = jUrl::get($action, $actionParams, jUrl::JURLACTION);
        $defaultDisplayProperties = array('start-label' => '|&lt;', 'prev-label' => '&lt;', 'next-label' => '&gt;', 'end-label' => '&gt;|', 'area-size' => 0);
        if (is_array($displayProperties) && count($displayProperties) > 0) {
            $displayProperties = array_merge($defaultDisplayProperties, $displayProperties);
        } else {
            $displayProperties = $defaultDisplayProperties;
        }
        $pages = array();
        $currentPage = 1;
        $numpage = 1;
        $prevBound = 0;
        $nextBound = 0;
        for ($curidx = 0; $curidx < $itemsTotal; $curidx += $pageSize) {
            if ($offset >= $curidx && $offset < $curidx + $pageSize) {
                $pages[$numpage] = '<li class="pagelinks-current">' . $numpage . '</li>';
                $prevBound = $curidx - $pageSize;
                $nextBound = $curidx + $pageSize;
                $currentPage = $numpage;
            } else {
                $urlaction->params[$paramName] = $curidx;
                $url = $jUrlEngine->create($urlaction);
                $pages[$numpage] = '<li><a href="' . $url->toString(true) . '">' . $numpage . '</a></li>';
            }
            $numpage++;
        }
        $urlaction->params[$paramName] = 0;
        $urlStartPage = $jUrlEngine->create($urlaction);
        $urlaction->params[$paramName] = $prevBound;
        $urlPrevPage = $jUrlEngine->create($urlaction);
        $urlaction->params[$paramName] = $nextBound;
        $urlNextPage = $jUrlEngine->create($urlaction);
        $urlaction->params[$paramName] = (count($pages) - 1) * $pageSize;
        $urlEndPage = $jUrlEngine->create($urlaction);
        echo '<ul class="pagelinks">';
        if (!empty($displayProperties['start-label'])) {
            echo '<li class="pagelinks-start';
            if ($prevBound >= 0) {
                echo '"><a href="', $urlStartPage->toString(true), '">', $displayProperties['start-label'], '</a>';
            } else {
                echo ' pagelinks-disabled">', $displayProperties['start-label'];
            }
            echo '</li>', "\n";
        }
        if (!empty($displayProperties['prev-label'])) {
            echo '<li class="pagelinks-prev';
            if ($prevBound >= 0) {
                echo '"><a href="', $urlPrevPage->toString(true), '">', $displayProperties['prev-label'], '</a>';
            } else {
                echo ' pagelinks-disabled">', $displayProperties['prev-label'];
            }
            echo '</li>', "\n";
        }
        foreach ($pages as $key => $page) {
            if ($displayProperties['area-size'] == 0 || $currentPage - $displayProperties['area-size'] <= $key && $currentPage + $displayProperties['area-size'] >= $key) {
                echo $page, "\n";
            }
        }
        if (!empty($displayProperties['next-label'])) {
            echo '<li class="pagelinks-next';
            if ($nextBound < $itemsTotal) {
                echo '"><a href="', $urlNextPage->toString(true), '">', $displayProperties['next-label'], '</a>';
            } else {
                echo ' pagelinks-disabled">', $displayProperties['next-label'];
            }
            echo '</li>', "\n";
        }
        if (!empty($displayProperties['end-label'])) {
            echo '<li class="pagelinks-end';
            if ($nextBound < $itemsTotal) {
                echo '"><a href="', $urlEndPage->toString(true), '">', $displayProperties['end-label'], '</a>';
            } else {
                echo ' pagelinks-disabled">', $displayProperties['end-label'];
            }
            echo '</li>', "\n";
        }
        echo '</ul>';
    } else {
        echo '<ul class="pagelinks"><li class="pagelinks-current">1</li></ul>';
    }
}
Beispiel #6
0
 /**
  * Parse a url
  * @param string $scriptNamePath    /path/index.php
  * @param string $pathinfo          the path info of the url.
  * @param array  $params            url parameter ($_REQUEST)
  * @return jUrlAction
  */
 static function parse($scriptNamePath, $pathinfo, $params)
 {
     return jUrl::getEngine()->parse($scriptNamePath, $pathinfo, $params);
 }
 function testBasicSignificantEngine()
 {
     global $gJConfig, $gJCoord;
     $gJCoord->request->urlScriptPath = '/';
     $gJCoord->request->params = array();
     //$gJCoord->request->type=;
     $gJConfig->urlengine = array('engine' => 'basic_significant', 'enableParser' => true, 'multiview' => false, 'basePath' => '/', 'defaultEntrypoint' => 'index', 'entrypointExtension' => '.php', 'notfoundAct' => 'jelix~notfound', 'significantFile' => 'urls.xml');
     jUrl::getEngine(true);
     // on recharge le nouveau moteur d'url
     $resultList = array();
     $resultList[] = array('module' => 'jelix_tests', 'action' => 'urlsig:url1', 'mois' => '10', 'annee' => '2005', 'id' => '35');
     $resultList[] = array('module' => 'jelix_tests', 'action' => 'urlsig:url2', 'mois' => '05', 'annee' => '2004');
     $resultList[] = array('module' => 'jelix_tests', 'action' => 'urlsig:url3', 'rubrique' => 'actualite', 'id_art' => '65', 'article' => 'c\'est la fete au village');
     $resultList[] = array('module' => 'jelix_tests', 'action' => 'urlsig:url4', 'first' => 'premier', 'second' => 'deuxieme');
     $resultList[] = array();
     $resultList[] = array('module' => 'news', 'action' => 'main:bar', 'aaa' => 'bbb');
     $resultList[] = array('module' => 'jelix_tests', 'action' => 'urlsig:url5', 'foo' => 'oof', 'bar' => 'rab');
     $resultList[] = array('module' => 'jelix_tests', 'action' => 'urlsig:url8', 'rubrique' => 'vetements', 'id_article' => '98');
     $resultList[] = array('module' => 'jelix_tests', 'action' => 'default:index', 'rubrique' => 'vetements', 'id_article' => '98');
     $resultList[] = array('module' => 'jelix_tests', 'action' => 'urlsig:index', 'rubrique' => 'vetements', 'id_article' => '98');
     $resultList[] = array('rubrique' => 'vetements', 'id_article' => '98');
     $resultList[] = array('module' => 'jelix_tests', 'action' => 'actu:foo', 'aaa' => 'bbb');
     $resultList[] = array('module' => 'jelix_tests', 'action' => 'actu:bar', 'aaa' => 'bbb');
     $resultList[] = array('module' => 'jelix_tests', 'action' => 'urlsig:bar', 'aaa' => 'bbb');
     $request = array(array("index.php", "/jelix_tests/urlsig/url1", array('mois' => '10', 'annee' => '2005', 'id' => '35')), array("testnews.php", "/jelix_tests/urlsig/url2", array('mois' => '05', 'annee' => '2004')), array("testnews.php", "/jelix_tests/urlsig/url3", array('rubrique' => 'actualite', 'id_art' => '65', 'article' => 'c\'est la fete au village')), array("foo/bar.php", "/jelix_tests/urlsig/url4", array('first' => 'premier', 'second' => 'deuxieme')), array("xmlrpc.php", "", array()), array("news.php", "/news/main/bar", array('aaa' => 'bbb')), array("index.php", "/jelix_tests/urlsig/url5", array('foo' => 'oof', 'bar' => 'rab')), array("index.php", "/jelix_tests/urlsig/url8", array('rubrique' => 'vetements', 'id_article' => '98')), array("index.php", "/jelix_tests/", array('rubrique' => 'vetements', 'id_article' => '98')), array("index.php", "/jelix_tests/urlsig/", array('rubrique' => 'vetements', 'id_article' => '98')), array("index.php", "", array('rubrique' => 'vetements', 'id_article' => '98')), array("actu.php", "/jelix_tests/actu/foo", array('aaa' => 'bbb')), array("actu.php", "/jelix_tests/actu/bar", array('aaa' => 'bbb')), array("actu.php", "/jelix_tests/urlsig/bar", array('aaa' => 'bbb')));
     //$this->sendMessage("significant, multiview = false");
     foreach ($request as $k => $urldata) {
         $url = jUrl::parse($urldata[0], $urldata[1], $urldata[2]);
         $p = $url->params;
         ksort($p);
         ksort($resultList[$k]);
         $this->assertTrue($p == $resultList[$k], 'created:' . var_export($p, true) . ' expected:' . var_export($resultList[$k], true));
     }
     $gJConfig->urlengine['multiview'] = true;
     $request = array(array("index", "/jelix_tests/urlsig/url1", array('mois' => '10', 'annee' => '2005', 'id' => '35')), array("testnews", "/jelix_tests/urlsig/url2", array('mois' => '05', 'annee' => '2004')), array("testnews", "/jelix_tests/urlsig/url3", array('rubrique' => 'actualite', 'id_art' => '65', 'article' => 'c\'est la fete au village')), array("foo/bar", "/jelix_tests/urlsig/url4", array('first' => 'premier', 'second' => 'deuxieme')), array("xmlrpc", "", array()), array("news", "/news/main/bar", array('aaa' => 'bbb')), array("index", "/jelix_tests/urlsig/url5", array('foo' => 'oof', 'bar' => 'rab')), array("index", "/jelix_tests/urlsig/url8", array('rubrique' => 'vetements', 'id_article' => '98')), array("index", "/jelix_tests/", array('rubrique' => 'vetements', 'id_article' => '98')), array("index", "/jelix_tests/urlsig/", array('rubrique' => 'vetements', 'id_article' => '98')), array("index", "", array('rubrique' => 'vetements', 'id_article' => '98')), array("actu.php", "/jelix_tests/actu/foo", array('aaa' => 'bbb')), array("actu.php", "/jelix_tests/actu/bar", array('aaa' => 'bbb')), array("actu.php", "/jelix_tests/urlsig/bar", array('aaa' => 'bbb')));
     foreach ($request as $k => $urldata) {
         $url = jUrl::parse($urldata[0], $urldata[1], $urldata[2]);
         $p = $url->params;
         ksort($p);
         ksort($resultList[$k]);
         $this->assertTrue($p == $resultList[$k], 'created:' . var_export($p, true) . ' expected:' . var_export($resultList[$k], true));
     }
 }
/**
 * displays page links for the twitter bootstrap
 *
 * @param jTpl $tpl template engine
 * @param string $action selector of the action 
 * @param array $actionParams parameters for the action
 * @param integer $itemsTotal number of items
 * @param integer $offset  index of the first item to display
 * @param integer $pageSize  items number in a page
 * @param string $paramName name of the parameter in the actionParams which will content a page offset
 * @param array $displayProperties properties for the links display
 *  */
function jtpl_function_html_pagelinks_bootstrap($tpl, $action, $actionParams, $itemsTotal, $offset, $pageSize = 15, $paramName = 'offset', $displayProperties = array())
{
    $offset = intval($offset);
    if ($offset <= 0) {
        $offset = 0;
    }
    $itemsTotal = intval($itemsTotal);
    $pageSize = intval($pageSize);
    if ($pageSize < 1) {
        $pageSize = 1;
    }
    // If there are at least two pages of results
    if ($itemsTotal > $pageSize) {
        $jUrlEngine = jUrl::getEngine();
        $urlaction = jUrl::get($action, $actionParams, jUrl::JURLACTION);
        $defaultDisplayProperties = array('start-label' => '|&lt;', 'prev-label' => '&lt;', 'next-label' => '&gt;', 'end-label' => '&gt;|', 'area-size' => 0);
        if (is_array($displayProperties) && count($displayProperties) > 0) {
            $displayProperties = array_merge($defaultDisplayProperties, $displayProperties);
        } else {
            $displayProperties = $defaultDisplayProperties;
        }
        $pages = array();
        $currentPage = 1;
        $numpage = 1;
        $prevBound = 0;
        $nextBound = 0;
        // Generates list of page offsets
        for ($curidx = 0; $curidx < $itemsTotal; $curidx += $pageSize) {
            if ($offset >= $curidx && $offset < $curidx + $pageSize) {
                $pages[$numpage] = '<li class="pagelinks-current active"><a href="#">' . $numpage . '</a></li>';
                $prevBound = $curidx - $pageSize;
                $nextBound = $curidx + $pageSize;
                $currentPage = $numpage;
            } else {
                $urlaction->params[$paramName] = $curidx;
                $url = $jUrlEngine->create($urlaction);
                $pages[$numpage] = '<li><a href="' . $url->toString(true) . '">' . $numpage . '</a></li>';
            }
            $numpage++;
        }
        // Calculate start page url
        $urlaction->params[$paramName] = 0;
        $urlStartPage = $jUrlEngine->create($urlaction);
        // Calculate previous page url
        $urlaction->params[$paramName] = $prevBound;
        $urlPrevPage = $jUrlEngine->create($urlaction);
        // Calculate next page url
        $urlaction->params[$paramName] = $nextBound;
        $urlNextPage = $jUrlEngine->create($urlaction);
        // Calculate end page url
        $urlaction->params[$paramName] = (count($pages) - 1) * $pageSize;
        $urlEndPage = $jUrlEngine->create($urlaction);
        // Links display
        echo '<div class="pagination"><ul class="pagelinks">';
        // Start link
        if (!empty($displayProperties['start-label'])) {
            echo '<li class="pagelinks-start prev';
            if ($prevBound >= 0) {
                echo '"><a href="', $urlStartPage->toString(true), '">', $displayProperties['start-label'], '</a>';
            } else {
                echo ' pagelinks-disabled disabled"><a href="#">', $displayProperties['start-label'], '</a>';
            }
            echo '</li>', "\n";
        }
        // Previous link
        if (!empty($displayProperties['prev-label'])) {
            echo '<li class="pagelinks-prev';
            if ($prevBound >= 0) {
                echo '"><a href="', $urlPrevPage->toString(true), '">', $displayProperties['prev-label'], '</a>';
            } else {
                echo ' pagelinks-disabled disabled"><a href="#">', $displayProperties['prev-label'], '</a>';
            }
            echo '</li>', "\n";
        }
        // Pages links
        foreach ($pages as $key => $page) {
            if ($displayProperties['area-size'] == 0 || $currentPage - $displayProperties['area-size'] <= $key && $currentPage + $displayProperties['area-size'] >= $key) {
                echo $page, "\n";
            }
        }
        // Next link
        if (!empty($displayProperties['next-label'])) {
            echo '<li class="pagelinks-next';
            if ($nextBound < $itemsTotal) {
                echo '"><a href="', $urlNextPage->toString(true), '">', $displayProperties['next-label'], '</a>';
            } else {
                echo ' pagelinks-disabled disabled"><a href="#">', $displayProperties['next-label'], '</a>';
            }
            echo '</li>', "\n";
        }
        // End link
        if (!empty($displayProperties['end-label'])) {
            echo '<li class="pagelinks-end next';
            if ($nextBound < $itemsTotal) {
                echo '"><a href="', $urlEndPage->toString(true), '">', $displayProperties['end-label'], '</a>';
            } else {
                echo ' pagelinks-disabled disabled"><a href="#">', $displayProperties['end-label'], '</a>';
            }
            echo '</li>', "\n";
        }
        echo '</ul></div>';
    } else {
        echo '<div class="pagination"><ul class="pagelinks"><li class="pagelinks-current"><a href="#">1</a></li></ul></div>';
    }
}
 function testGetFullUrl()
 {
     global $gJConfig, $gJCoord;
     $gJCoord->request->urlScriptPath = '/';
     $gJCoord->request->params = array();
     //$gJCoord->request->type=;
     $gJConfig->urlengine = array('engine' => 'basic_significant', 'enableParser' => true, 'multiview' => false, 'basePath' => '/', 'defaultEntrypoint' => 'index', 'entrypointExtension' => '.php', 'notfoundAct' => 'jelix~error:notfound', 'simple_urlengine_https' => 'jelix_tests~urlsig:url8@classic @xmlrpc', 'significantFile' => 'urls.xml');
     /*
      parameters
         $_SERVER['HTTPS'] ou non
         $_SERVER['SERVER_NAME'] ou $gJConfig->domainName
         given domainName ou pas
         jelix_tests~urlsig:url3 (http) ou jelix_tests~urlsig:url8 (https)
     */
     $_SERVER['SERVER_NAME'] = 'testapp.local';
     $_SERVER['SERVER_PORT'] = '80';
     // ================= HTTP URL
     unset($_SERVER['HTTPS']);
     // without given domain name, without domain name in config, without https
     $gJConfig->domainName = '';
     jUrl::getEngine(true);
     $url = jUrl::getFull('jelix_tests~urlsig:url1', array(), 0, null);
     $this->assertEqual('http://testapp.local/index.php/jelix_tests/urlsig/url1', $url);
     $url = jUrl::getFull('jelix_tests~urlsig:url8', array(), 0, null);
     $this->assertEqual('https://testapp.local/index.php/jelix_tests/urlsig/url8', $url);
     // with given domain name, without domain name in config, without https
     $url = jUrl::getFull('jelix_tests~urlsig:url1', array(), 0, 'football.local');
     $this->assertEqual('http://football.local/index.php/jelix_tests/urlsig/url1', $url);
     $url = jUrl::getFull('jelix_tests~urlsig:url8', array(), 0, 'football.local');
     $this->assertEqual('https://football.local/index.php/jelix_tests/urlsig/url8', $url);
     // without given domain name, with domain name in config, without https
     $gJConfig->domainName = 'configdomain.local';
     jUrl::getEngine(true);
     $url = jUrl::getFull('jelix_tests~urlsig:url1', array(), 0, null);
     $this->assertEqual('http://configdomain.local/index.php/jelix_tests/urlsig/url1', $url);
     $url = jUrl::getFull('jelix_tests~urlsig:url8', array(), 0, null);
     $this->assertEqual('https://configdomain.local/index.php/jelix_tests/urlsig/url8', $url);
     // with given domain name, with domain name in config, without https
     $url = jUrl::getFull('jelix_tests~urlsig:url1', array(), 0, 'football.local');
     $this->assertEqual('http://football.local/index.php/jelix_tests/urlsig/url1', $url);
     $url = jUrl::getFull('jelix_tests~urlsig:url8', array(), 0, 'football.local');
     $this->assertEqual('https://football.local/index.php/jelix_tests/urlsig/url8', $url);
     $_SERVER['HTTPS'] = 'on';
     $_SERVER['SERVER_PORT'] = '443';
     // without given domain name, without domain name in config, with https
     $gJConfig->domainName = '';
     jUrl::getEngine(true);
     $url = jUrl::getFull('jelix_tests~urlsig:url1', array(), 0, null);
     $this->assertEqual('https://testapp.local/index.php/jelix_tests/urlsig/url1', $url);
     $url = jUrl::getFull('jelix_tests~urlsig:url8', array(), 0, null);
     $this->assertEqual('https://testapp.local/index.php/jelix_tests/urlsig/url8', $url);
     // with given domain name, without domain name in config, with https
     $url = jUrl::getFull('jelix_tests~urlsig:url1', array(), 0, 'football.local');
     $this->assertEqual('https://football.local/index.php/jelix_tests/urlsig/url1', $url);
     $url = jUrl::getFull('jelix_tests~urlsig:url8', array(), 0, 'football.local');
     $this->assertEqual('https://football.local/index.php/jelix_tests/urlsig/url8', $url);
     // without given domain name, with domain name in config, with https
     $gJConfig->domainName = 'configdomain.local';
     jUrl::getEngine(true);
     $url = jUrl::getFull('jelix_tests~urlsig:url1', array(), 0, null);
     $this->assertEqual('https://configdomain.local/index.php/jelix_tests/urlsig/url1', $url);
     $url = jUrl::getFull('jelix_tests~urlsig:url8', array(), 0, null);
     $this->assertEqual('https://configdomain.local/index.php/jelix_tests/urlsig/url8', $url);
     // with given domain name, with domain name in config, with https
     $url = jUrl::getFull('jelix_tests~urlsig:url1', array(), 0, 'football.local');
     $this->assertEqual('https://football.local/index.php/jelix_tests/urlsig/url1', $url);
     $url = jUrl::getFull('jelix_tests~urlsig:url8', array(), 0, 'football.local');
     $this->assertEqual('https://football.local/index.php/jelix_tests/urlsig/url8', $url);
 }