3 * TODO: if (stristr ($topic, '~')) {
6 * $title = substr($topic, 1);
9 // will generate : http://base_url/topic/major/title/minor1/1/minor2/2
10 define ('FRIENDLY' , 1);
11 // will generate : http://base_url/?NAV_VAR=topic&major=title&minor1=1&minor2=2
12 define ('REGULAR' , 2);
14 define ('METHOD' , FRIENDLY
);
17 * Object to generate URLs
21 public $options = array ();
26 protected $topic, // REGULAR : NAV_VAR=$topic | FRIENDLY : /$topic/
27 $action,// REGULAR : do=$action | FRIENDLY : /$topic/$action/
28 $major, // REGULAR : &$major=$title
29 $title, // FRIENDLY : ../$major/$title
32 public function __construct ($opt = null) {
34 if (defined('BASE_URL'))
35 $options['base'] = BASE_URL
;
37 $options['base'] = '';
42 public function __destruct () {
47 * method to return the url as a string
50 public function __toString () {
55 * method to generate an friendly URL slug
57 public function buildSlug () {
61 public function getRequest ($varName) {
62 if (defined('METHOD') && METHOD
== FRIENDLY
) {
64 list($urlStr) = array_keys ($_GET);
65 $parArr = explode ('/',$urlStr);
71 if (sizeof($parArr) > 3) {
72 $minors = array_slice ($parArr, 3);
73 // foreach ( $minors as $key => $cont) {
79 if (is_null($varName))
81 if (isset($_REQUEST[$varName]))
82 return $_REQUEST[$varName];
89 * method to return the URL based on $method
91 * TODO: find a method to overlook folders
92 * - done by hardcoding folder names in the rewrite rule
94 public function setRequest ($whereTo = null, $varVal = null) {
95 // generating friendly URLs
96 if ($this->method
== FRIENDLY
) {
100 $whereTo = NAV_VAR
. '=' . $whereTo;
102 if (is_array($varVal)) {
103 foreach ($varVal as $key => $val){
104 if (is_numeric($key) && stristr ($val, '#')) {
105 // probably an href with id in it
108 $tArr[] = $key.(!empty($val) ?
'='.$val : '');
111 $retUrl = implode ('&', $tArr).$end;
112 } elseif (is_string($varVal)){
118 if ($method == 'get'){
119 if (!empty ($whereTo) && !empty ($retUrl) )
121 $outStr .= '/?' . $whereTo . $retUrl;