1/** //** ----= CLASS mwUrl =--------------------------------------------------------------------------------------\**//** \ 2* 3* Morweb urls compilation helper. 4* 5* @package Morweb 6* @subpackage Core 7* @category helper 8* 9\**//** ---------------------------------------------------------------------------= by Mr.V!T @ Morad Media Inc. =----/** //**/ 10function mwUrl ($section) { 11return { 12 13 section : $section || false, // Sectional url. Set TRUE for sectional core resoureces (applicable only for resources). 14 _full : false, // Set TRUE to generate full url (inluding protocol and domain). Usefull for emails and standalone pages. 15 _ssl : null, // HTTPS use for full urls, set TRUE to force, FALSE to force non SSL, NULL (default) for autodetect. 16 _salt : false, // Set TRUE or give random string value to prevent browser caching, adding salt to url. 17 18/* ==== SETUP =============================================================================================================== */ 19 20 /** //** ----= full =--------------------------------------------------------------------------------------\**//** \ 21 * 22 * Full mode switcher. 23 * 24 * @param bool [$value] - Value to set. 25 * @param bool [$ssl] - Force ssl usage. 26 * 27 * @return SELF 28 * 29 \**//** -------------------------------------------------------------------= by Mr.V!T @ Morad Media Inc. =----/** //**/ 30 full : function ($value, $ssl) { 31 32 $value = setDefault($value, true); 33 34 this._full = $value; 35 this._ssl = $ssl; 36 37 return this; 38 }, //FUNC full 39 40 /** //** ----= salt =--------------------------------------------------------------------------------------\**//** \ 41 * 42 * Initiates url salting. Use with precaution - this dastically slows down site loading speed. 43 * 44 * @param MIXED [$value] - Set TRUE to randomize salt, or random string value to preset hash value. 45 * 46 * @return SELF 47 * 48 \**//** -------------------------------------------------------------------= by Mr.V!T @ Morad Media Inc. =----/** //**/ 49 salt : function ($value) { 50 51 $value = setDefault($value, true); 52 53 this._salt = ($value === true) ? randomString() : $value; 54 55 return this; 56 }, //FUNC salt 57 58/* ==== RESOURCES =========================================================================================================== */ 59 60 /** //** ----= res =--------------------------------------------------------------------------------------\**//** \ 61 * 62 * Miscellaneous system resource load. Always uses direct load. 63 * 64 * @param string - Path segments to compile. 65 * 66 * @return SELF 67 * 68 \**//** -------------------------------------------------------------------= by Mr.V!T @ Morad Media Inc. =----/** //**/ 69 res : function () { 70 var $arr = Array.prototype.slice.call(arguments); 71 return this.compile( [CMS_ALIAS, CMS_RES].concat($arr) ); 72 }, //FUNC res 73 74 /** //** ----= js =--------------------------------------------------------------------------------------\**//** \ 75 * 76 * JS resource url. For system resource uses direct load by default. 77 * 78 * @param string - Path segments to compile. 79 * 80 * @return SELF 81 * 82 \**//** -------------------------------------------------------------------= by Mr.V!T @ Morad Media Inc. =----/** //**/ 83 js : function () { 84 return this.compile( this.resSegments(CMS_JS, arguments) ); 85 }, //FUNC js 86 87 /** //** ----= css =--------------------------------------------------------------------------------------\**//** \ 88 * 89 * CSS resource url. For system resource uses direct load by default. 90 * 91 * @param string - Path segments to compile. 92 * 93 * @return SELF 94 * 95 \**//** -------------------------------------------------------------------= by Mr.V!T @ Morad Media Inc. =----/** //**/ 96 css : function () { 97 return this.compile( this.resSegments(CMS_CSS, arguments) ); 98 }, //FUNC css 99 100 /** //** ----= images =--------------------------------------------------------------------------------------\**//** \ 101 * 102 * Images resource url. For system resource uses direct load by default. 103 * 104 * @param string $path - Path parts to compile. 105 * 106 * @return SELF 107 * 108 \**//** -------------------------------------------------------------------= by Mr.V!T @ Morad Media Inc. =----/** //**/ 109 images : function () { 110 return this.compile( this.resSegments(CMS_IMAGES, arguments) ); 111 }, //FUNC images 112 113 /** //** ----= image =--------------------------------------------------------------------------------------\**//** \ 114 * 115 * Image resizer url. 116 * 117 * @param string $path - Image path. 118 * 119 * @return SELF 120 * 121 \**//** -------------------------------------------------------------------= by Mr.V!T @ Morad Media Inc. =----/** //**/ 122 image : function ($path, $arguments) { 123 124 $arguments = $arguments || []; 125 126 // Hardcoded resizer path, which always present 127 var $url = this.compile('get/files/image', $path); 128 129 // Nothing else to do, if no arguments given 130 if ( isEmpty($arguments) ) 131 return $url; 132 133 // If arguments provided - compiling GET and appending to url 134 $url += '?'+implode('&', $arguments); 135 136 return $url; 137 }, //FUNC image 138 139/* ==== CONTROLLERS ========================================================================================================= */ 140 141 // ToDo: ajax/call funcitons for sectional controllers calls. 142 143/* ==== HELPERS ============================================================================================================= */ 144 145 /** //** ----= resSegments =------------------------------------------------------------------------------\**//** \ 146 * 147 * Prepares resource segments, based on current settings. 148 * Concatenates resources segments with provided path segments. 149 * 150 * @param string $resource - Resource type path. 151 * @param array [$segments] - Additional segments to concat with. 152 * 153 * @return SELF 154 * 155 \**//** -------------------------------------------------------------------= by Mr.V!T @ Morad Media Inc. =----/** //**/ 156 resSegments : function ($resource, $segments) { 157 158 $resource = $resource || ''; 159
160 // Converting segments into array, in case of arguments object given 161 $segments = Array.prototype.slice.call($segments); 162 163 // Adding section segments 164 var $res = []; 165 166 // Direct resources are using alias 167 if ( isEmpty(this.section) ) 168 $res.push(CMS_ALIAS); 169 170 // Pointing to resource 171 $res.push(CMS_RES); 172 173 // Adding section if specified 174 if ( isString(this.section) ) 175 $res.push(this.section); 176 177 // Finishing with resource segment 178 $res.push($resource); 179 180 // Concatenating with segments 181 $res = $res.concat($segments); 182 183 return $res; 184 }, //FUNC resSegments 185 186 /** //** ----= compile =--------------------------------------------------------------------------------------\**//** \ 187 * 188 * Compiles url from given URI segments. Parts can be passed as array, or as multiple funciton arguments. 189 * 190 * @param string $segments - URI segments to compile. 191 * 192 * @return SELF 193 * 194 \**//** -------------------------------------------------------------------= by Mr.V!T @ Morad Media Inc. =----/** //**/ 195 compile : function ($segments) { 196 197 var $seg = isArray($segments) ? $segments : arguments; 198 199 // Concatenating each non empty segment, trimming slashes and spaces 200 var $res = ''; 201 for ( var $i in $seg ) { 202 $s = $seg[$i]; 203 204 // Making sure strings come 205 if ( !isString($s) ) 206 continue; 207 208 // Timming garbage 209 $s = $s.trim(' /\\'); 210 211 // Skipping empties 212 if ( isEmpty($s) ) 213 continue; 214 215 // Concatenating with leading '/', which always present 216 $res += '/'+$s; 217 218 } //FOR each segment 219 220 // Adding domain if specified 221 if ( this._full ) 222 $res = fullURL($res, this._ssl); 223 224 // Adding salt if specified 225 if ( this._salt ) 226 $res += '?'+this._salt; 227 228 // Done. 229 return $res; 230 }, //FUNC compile 231 232}} //CLASS mwUrl
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.