1<?php 2/** 3 * Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt) 4 * 5 * $Id$ 6 * 7 * Default config - create ONLY - old legacy URLs 8 * All possible config options added here - to be used as a reference. 9 * A good programming practice is to remove all non-used options. 10 */ 11if (!defined('e107_INIT')){ exit; } 12 13class core_news_url extends eUrlConfig 14{ 15 public function config() 16 { 17 return array( 18 'config' => array( 19 'allowMain' => false, // [optional] default false; disallow this module (while using this config) to be set as site main URL namespace 20 'noSingleEntry' => true, // [optional] default false; disallow this module to be shown via single entry point when this config is used 21 'legacy' => '{e_BASE}news.php', // [optional] default empty; if it's a legacy module (no single entry point support) - URL to the entry point script 22 'format' => 'get', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored 23 'selfParse' => true, // [optional] default false; use only this->parse() method, no core routine URL parsing 24 'selfCreate' => true, // [optional] default false; use only this->create() method, no core routine URL creating 25 'defaultRoute' => 'list/new',// [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/ 26 'errorRoute' => '', // [optional] default empty; route (no leading module) used when module is found but no inner route is matched, leave empty to force error 404 page 27 'urlSuffix' => '', // [optional] default empty; string to append to the URL (e.g. .html), not used when format is 'get' or legacy non-empty 28 29 ### [optional] used only when assembling URLs via rules(); 30 ### if 'empty' - check if the required parameter is empty (results in assemble fail), 31 ### if 1 or true - it uses the route pattern to match every parameter - EXTREMELY SLOW, be warned 32 'matchValue' => false, 33 34 35 ### [optional] vars mapping (create URL routine), override per rule is allowed 36 ### Keys of this array will be used as a map for finding values from the provided parameters array. 37 ### Those values will be assigned to new keys - corresponding values of mapVars array 38 ### It gives extremely flexibility when used with allowVars. For example we pass $news item array as 39 ### it's retrieved from the DB, with no modifications. This gives us the freedom to create any variations of news 40 ### URLs using the DB data with a single line URL rule. Another aspect of this feature is the simplified code 41 ### for URL assembling - we just do eRouter::create($theRoute, $newsDbArray) 42 ### Not used when in selfCreate mod (create url) 43 'mapVars' => array( 44 //'news_id' => 'id', 45 //'news_sef' => 'name', 46 ), 47 48 ### [optional] allowed vars definition (create URL routine), override per rule is allowed 49 ### This numerical array serves as a filter for passed vars when creating URLs 50 ### Everything outside this scope is ignored while assembling URLs. Exception are route variables. 51 ### For example: when <id:[\d]+> is present in the route string, there is no need to extra allow 'id' 52 ### To disallow everything but route variables, set allowVars to false 53 ### When format is get, false value will disallow everything (no params) and default preserved variables 54 ### will be extracted from mapVars (if available) 55 ### Default value is empty array 56 ### Not used when in selfCreate mod (create url) 57 'allowVars' => array(/*'page', 'name'*/), 58 59 ### Those are regex templates, allowing us to avoid the repeating regex patterns writing in your rules. 60 ### varTemplates are merged with the core predefined templates. Full list with core regex templates and examples can be found 61 ### in rewrite_extended news URL config 62 'varTemplates' => array(/*'testIt' => '[\d]+'*/), 63 ), 64 65 'rules' => array(), // rule set array - can't be used with format 'get' and noSingleEntry true 66 ); 67 } 68 69 /** 70 * If create returns string, 'module' value won't be prefixed from the router 71 * Query mapping in format route?params: 72 * - view/item?id=xxx -> ?extend.id 73 * - list/items[?page=xxx] -> default.0.page 74 * - list/category?id=xxx[&page=xxx] -> list.id.page 75 * - list/category?id=0[&page=xxx] -> default.0.page 76 * - list/short?id=xxx[&page=xxx] -> cat.id.page 77 * - list/day?id=xxx -> ?day-id 78 * - list/month?id=xxx -> ?month-id 79 * - list/year?id=xxx -> ?year-id 80 * - list/nextprev?route=xxx -> PARSED_ROUTE.[FROM] (recursive parse() call) 81 */ 82 public function create($route, $params = array(),$options = array()) 83 { 84 if(!$params) return 'news.php'; 85 86 if(!$route) $route = 'list/items'; 87 if(is_string($route)) $route = explode('/', $route, 2); 88 if('index' == $route[0]) 89 { 90 $route[0] = 'list'; 91 $route[1] = 'items'; 92 } 93 elseif('index' == $route[1]) 94 { 95 $route[1] = 'items'; 96 } 97 98 // return print_a($route,true); 99 ## news are passing array as it is retrieved from the DB, map vars to proper values 100 if(isset($params['news_id']) && !empty($params['news_id'])) $params['id'] = $params['news_id']; 101 //if(isset($params['news_sef']) && !empty($params['news_sef'])) $params['id'] = $params['news_sef']; 102 //if(isset($params['category_sef']) && !empty($params['category_sef'])) $params['category'] = $params['category_sef']; 103 104 $url = 'news.php?'; 105 if('--FROM--' != vartrue($params['page'])) $page = varset($params['page']) ? intval($params['page']) : '0'; 106 else $page = '--FROM--'; 107 108 if($route[0] == 'view') 109 { 110 switch ($route[1]) 111 { 112 case 'item': 113 $url .= 'extend.'.$params['id']; //item.* view is deprecated 114 break; 115 116 default: 117 $url = 'news.php'; 118 break; 119 } 120 } 121 elseif($route[0] == 'list') 122 { 123 switch ($route[1]) 124 { 125 case '': 126 case 'items': 127 if(!$page) $url = 'news.php'; 128 else $url .= 'default.0.'.$page; //item.* view is deprecated 129 break; 130 131 case 'category': 132 if(!vartrue($params['id'])) 133 { 134 $url .= 'default.0.'.$page; 135 } 136 else 137 { 138 $url .= 'list.'.$params['id'].'.'.$page; // 'category_id' would break news_categories_menu. 139 } 140 break; 141 142 case 'all': 143 $url .= 'all.'.$params['id'].'.'.$page; 144 break; 145 146 case 'tag': 147 $url .= 'tag='.$params['tag'].'&page='.$page; 148 break; 149 150 case 'author': 151 $url .= 'author='.$params['author'].'&page='.$page; 152 break; 153 154 case 'short': 155 $url .= 'cat.'.$params['id'].'.'.$page; 156 break; 157 158 case 'day': 159 case 'month': 160 case 'year': 161 if($page) $page = '.'.$page; 162 $url .= $route[1].'.'.$params['id'].$page; 163 break; 164 165 default: 166 $url = 'news.php'; 167 break; 168 } 169 } 170 else 171 { 172 $url = 'news.php'; 173 } 174 175 return $url; 176 } 177 178 public function parse($pathInfo, $params = array(), eRequest $request = null, eRouter $router = null, $config = array()) 179 { 180 // this config doesn't support parsing, it's done by the module entry script (news.php) 181 // this means News are not available via single entry point if this config is currently active 182 return false; 183 } 184 185 186 /** 187 * Admin callback 188 * Language file not loaded as all language data is inside the lan_eurl.php (loaded by default on administration URL page) 189 */ 190 public function admin() 191 { 192 // static may be used for performance 193 static $admin = array( 194 'labels' => array( 195 'name' => LAN_EURL_CORE_NEWS, // Module name 196 'label' => LAN_EURL_DEFAULT, // Current profile name 197 'description' => LAN_EURL_LEGACY, // 198 'examples' => array("{SITEURL}news.php?extend.1") 199 ), 200 // 'generate' => array('table'=> 'news', 'primary'=>'news_id', 'input'=>'news_title', 'output'=>'news_sef'), 201 'form' => array(), // Under construction - additional configuration options 202 'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity 203 ); 204 205 return $admin; 206 } 207} 208 209