Dotclear

source: inc/admin/lib.dc.adminurl.php @ 2849:97e1b334e54b

Revision 2849:97e1b334e54b, 3.3 KB checked in by Dsls, 11 years ago (diff)

Deprecated $core->adminurl->decode, use $core->adminurl->get instead (with urlencode set to false)

Added dcPage::getPF to shortcut plugin file inclusion

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14/**
15@ingroup DC_CORE
16@nosubgrouping
17@brief URL Handler for admin urls
18
19*/
20class dcAdminURL
21{
22     /** @var dcCore dcCore instance */
23     protected $core;
24     protected $urls;
25
26     /**
27     Inits dcAdminURL object
28
29     @param    core      <b>dcCore</b>       Dotclear core reference
30     */
31     public function __construct($core)
32     {
33          $this->core = $core;
34          $this->urls = new ArrayObject();
35     }
36
37     /**
38      * Registers a new url
39      * @param  string $name   the url name
40      * @param  string $url    url value
41      * @param  array  $params query string params (optional)
42      */
43     public function register($name,$url,$params=array())
44     {
45          $this->urls[$name] = array('url' => $url, 'qs' => $params);
46     }
47
48     /**
49      * Registers a new url as a copy of an existing one
50      * @param  string $name   url name
51      * @param  streing $orig   url to copy information from
52      * @param  array  $params extra parameters to add
53      * @param  string $newurl new url if different from the original
54      */
55     public function registercopy($name,$orig,$params=array(),$newurl='')
56     {
57          if (!isset($this->urls[$orig])) {
58               throw new exception ('Unknown URL handler for '.$orig);
59          }
60          $url = $this->urls[$orig];
61          $url['qs'] = array_merge($url['qs'],$params);
62          if ($newurl != '') {
63               $url['url'] = $newurl;
64          }
65          $this->urls[$name] = $url;
66     }
67
68     /**
69      * retrieves a URL given its name, and optional parameters
70      *
71      * @param  string $name      URL Name
72      * @param  array  $params    query string parameters, given as an associative array
73      * @param  boolean $urlencode set to true if url may not be encoded
74      * @param  string $separator separator to use between QS parameters
75      * @return string            the forged url
76      */
77     public function get($name,$params=array(),$urlencode=true,$separator='&amp;')
78     {
79          if (!isset($this->urls[$name])) {
80               throw new exception ('Unknown URL handler for '.$name);
81          }
82          // compatibility check for old behavior
83          if (!is_bool($urlencode)) {
84               $separator=$urlencode;
85               $urlencode = true;
86          }
87          $url = $this->urls[$name];
88          $p = array_merge($url['qs'],$params);
89          $u = $url['url'];
90          if (!empty($p)) {
91               $u .= '?'.http_build_query($p,'',$separator);
92          }
93          return $urlencode?$u:urldecode($u);
94     }
95
96     /**
97      * retrieves a URL (decoded — useful for echoing) given its name, and optional parameters
98      *
99      * @deprecated should use get(...,true,...) instead
100      *
101      * @param  string $name      URL Name
102      * @param  array  $params    query string parameters, given as an associative array
103      * @param  string $separator separator to use between QS parameters
104      * @return string            the forged decoded url
105      */
106     public function decode($name,$params=array(),$separator='&')
107     {
108          return urldecode($this->get($name,$params,false,$separator));
109     }
110
111     /**
112      * Returns $urls property content.
113      *
114      * @return  ArrayObject
115      */
116     public function dumpUrls()
117     {
118          return $this->urls;
119     }
120}
Note: See TracBrowser for help on using the repository browser.

Sites map