Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 14 | class Context |
||
| 15 | { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Allow rewrite |
||
| 19 | * @var bool TRUE: using rewrite mod, FALSE: otherwise |
||
| 20 | */ |
||
| 21 | public $allow_rewrite = FALSE; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Request method |
||
| 25 | * @var string GET|POST|XMLRPC|JSON |
||
| 26 | */ |
||
| 27 | public $request_method = 'GET'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * js callback function name. |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | public $js_callback_func = ''; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Response method.If it's not set, it follows request method. |
||
| 37 | * @var string HTML|XMLRPC|JSON|JS_CALLBACK |
||
| 38 | */ |
||
| 39 | public $response_method = ''; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Conatins request parameters and environment variables |
||
| 43 | * @var object |
||
| 44 | */ |
||
| 45 | public $context = NULL; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * DB info |
||
| 49 | * @var object |
||
| 50 | */ |
||
| 51 | public $db_info = NULL; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * FTP info |
||
| 55 | * @var object |
||
| 56 | */ |
||
| 57 | public $ftp_info = NULL; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * ssl action cache file |
||
| 61 | * @var array |
||
| 62 | */ |
||
| 63 | public $sslActionCacheFile = './files/cache/sslCacheFile.php'; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * List of actions to be sent via ssl (it is used by javascript xml handler for ajax) |
||
| 67 | * @var array |
||
| 68 | */ |
||
| 69 | public $ssl_actions = array(); |
||
| 70 | |||
| 71 | /** |
||
| 72 | * obejct oFrontEndFileHandler() |
||
| 73 | * @var object |
||
| 74 | */ |
||
| 75 | public $oFrontEndFileHandler; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * script codes in <head>..</head> |
||
| 79 | * @var string |
||
| 80 | */ |
||
| 81 | public $html_header = NULL; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * class names of <body> |
||
| 85 | * @var array |
||
| 86 | */ |
||
| 87 | public $body_class = array(); |
||
| 88 | |||
| 89 | /** |
||
| 90 | * codes after <body> |
||
| 91 | * @var string |
||
| 92 | */ |
||
| 93 | public $body_header = NULL; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * class names before </body> |
||
| 97 | * @var string |
||
| 98 | */ |
||
| 99 | public $html_footer = NULL; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * path of Xpress Engine |
||
| 103 | * @var string |
||
| 104 | */ |
||
| 105 | public $path = ''; |
||
| 106 | // language information - it is changed by HTTP_USER_AGENT or user's cookie |
||
| 107 | /** |
||
| 108 | * language type |
||
| 109 | * @var string |
||
| 110 | */ |
||
| 111 | public $lang_type = ''; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * contains language-specific data |
||
| 115 | * @var object |
||
| 116 | */ |
||
| 117 | public $lang = NULL; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * list of loaded languages (to avoid re-loading them) |
||
| 121 | * @var array |
||
| 122 | */ |
||
| 123 | public $loaded_lang_files = array(); |
||
| 124 | |||
| 125 | /** |
||
| 126 | * site's browser title |
||
| 127 | * @var string |
||
| 128 | */ |
||
| 129 | public $site_title = ''; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * variables from GET or form submit |
||
| 133 | * @var mixed |
||
| 134 | */ |
||
| 135 | public $get_vars = NULL; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Checks uploaded |
||
| 139 | * @var bool TRUE if attached file exists |
||
| 140 | */ |
||
| 141 | public $is_uploaded = FALSE; |
||
| 142 | /** |
||
| 143 | * Pattern for request vars check |
||
| 144 | * @var array |
||
| 145 | */ |
||
| 146 | public $patterns = array( |
||
| 147 | '/<\?/iUsm', |
||
| 148 | '/<\%/iUsm', |
||
| 149 | '/<script\s*?language\s*?=\s*?("|\')?\s*?php\s*("|\')?/iUsm' |
||
| 150 | ); |
||
| 151 | /** |
||
| 152 | * Check init |
||
| 153 | * @var bool FALSE if init fail |
||
| 154 | */ |
||
| 155 | public $isSuccessInit = TRUE; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * returns static context object (Singleton). It's to use Context without declaration of an object |
||
| 159 | * |
||
| 160 | * @return object Instance |
||
| 161 | */ |
||
| 162 | function &getInstance() |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Cunstructor |
||
| 175 | * |
||
| 176 | * @return void |
||
| 177 | */ |
||
| 178 | function Context() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Initialization, it sets DB information, request arguments and so on. |
||
| 197 | * |
||
| 198 | * @see This function should be called only once |
||
| 199 | * @return void |
||
| 200 | */ |
||
| 201 | function init() |
||
| 202 | { |
||
| 203 | // fix missing HTTP_RAW_POST_DATA in PHP 5.6 and above |
||
| 204 | if(!isset($GLOBALS['HTTP_RAW_POST_DATA']) && version_compare(PHP_VERSION, '5.6.0', '>=') === TRUE) |
||
| 205 | { |
||
| 206 | $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents("php://input"); |
||
| 207 | |||
| 208 | // If content is not XML JSON, unset |
||
| 209 | if(!preg_match('/^[\<\{\[]/', $GLOBALS['HTTP_RAW_POST_DATA']) && strpos($_SERVER['CONTENT_TYPE'], 'json') === FALSE && strpos($_SERVER['HTTP_CONTENT_TYPE'], 'json') === FALSE) |
||
| 210 | { |
||
| 211 | unset($GLOBALS['HTTP_RAW_POST_DATA']); |
||
| 212 | } |
||
| 213 | } |
||
| 214 | |||
| 215 | // set context variables in $GLOBALS (to use in display handler) |
||
| 216 | $this->context = &$GLOBALS['__Context__']; |
||
| 217 | $this->context->lang = &$GLOBALS['lang']; |
||
| 218 | $this->context->_COOKIE = $_COOKIE; |
||
| 219 | |||
| 220 | // 20140429 editor/image_link |
||
| 221 | $this->_checkGlobalVars(); |
||
| 222 | |||
| 223 | $this->setRequestMethod(''); |
||
| 224 | |||
| 225 | $this->_setXmlRpcArgument(); |
||
| 226 | $this->_setJSONRequestArgument(); |
||
| 227 | $this->_setRequestArgument(); |
||
| 228 | $this->_setUploadedArgument(); |
||
| 229 | |||
| 230 | $this->loadDBInfo(); |
||
| 231 | if($this->db_info->use_sitelock == 'Y') |
||
| 232 | { |
||
| 233 | if(is_array($this->db_info->sitelock_whitelist)) $whitelist = $this->db_info->sitelock_whitelist; |
||
| 234 | |||
| 235 | if(!IpFilter::filter($whitelist)) |
||
| 236 | { |
||
| 237 | $title = ($this->db_info->sitelock_title) ? $this->db_info->sitelock_title : 'Maintenance in progress...'; |
||
| 238 | $message = $this->db_info->sitelock_message; |
||
| 239 | |||
| 240 | define('_XE_SITELOCK_', TRUE); |
||
| 241 | define('_XE_SITELOCK_TITLE_', $title); |
||
| 242 | define('_XE_SITELOCK_MESSAGE_', $message); |
||
| 243 | |||
| 244 | header("HTTP/1.1 403 Forbidden"); |
||
| 245 | if(FileHandler::exists(_XE_PATH_ . 'common/tpl/sitelock.user.html')) |
||
| 246 | { |
||
| 247 | include _XE_PATH_ . 'common/tpl/sitelock.user.html'; |
||
| 248 | } |
||
| 249 | else |
||
| 250 | { |
||
| 251 | include _XE_PATH_ . 'common/tpl/sitelock.html'; |
||
| 252 | } |
||
| 253 | exit; |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | // If XE is installed, get virtual site information |
||
| 258 | if(self::isInstalled()) |
||
| 259 | { |
||
| 260 | $oModuleModel = getModel('module'); |
||
| 261 | $site_module_info = $oModuleModel->getDefaultMid(); |
||
| 262 | |||
| 263 | if(!isset($site_module_info)) |
||
| 264 | { |
||
| 265 | $site_module_info = new stdClass(); |
||
| 266 | } |
||
| 267 | |||
| 268 | // if site_srl of site_module_info is 0 (default site), compare the domain to default_url of db_config |
||
| 269 | if($site_module_info->site_srl == 0 && $site_module_info->domain != $this->db_info->default_url) |
||
| 270 | { |
||
| 271 | $site_module_info->domain = $this->db_info->default_url; |
||
| 272 | } |
||
| 273 | |||
| 274 | $this->set('site_module_info', $site_module_info); |
||
| 275 | if($site_module_info->site_srl && isSiteID($site_module_info->domain)) |
||
| 276 | { |
||
| 277 | $this->set('vid', $site_module_info->domain, TRUE); |
||
| 278 | } |
||
| 279 | |||
| 280 | if(!isset($this->db_info)) |
||
| 281 | { |
||
| 282 | $this->db_info = new stdClass(); |
||
| 283 | } |
||
| 284 | |||
| 285 | $this->db_info->lang_type = $site_module_info->default_language; |
||
| 286 | if(!$this->db_info->lang_type) |
||
| 287 | { |
||
| 288 | $this->db_info->lang_type = 'en'; |
||
| 289 | } |
||
| 290 | if(!$this->db_info->use_db_session) |
||
| 291 | { |
||
| 292 | $this->db_info->use_db_session = 'N'; |
||
| 293 | } |
||
| 294 | } |
||
| 295 | |||
| 296 | // Load Language File |
||
| 297 | $lang_supported = $this->loadLangSelected(); |
||
| 298 | |||
| 299 | // Retrieve language type set in user's cookie |
||
| 300 | if($this->lang_type = $this->get('l')) |
||
| 301 | { |
||
| 302 | if($_COOKIE['lang_type'] != $this->lang_type) |
||
| 303 | { |
||
| 304 | setcookie('lang_type', $this->lang_type, $_SERVER['REQUEST_TIME'] + 3600 * 24 * 1000); |
||
| 305 | } |
||
| 306 | } |
||
| 307 | elseif($_COOKIE['lang_type']) |
||
| 308 | { |
||
| 309 | $this->lang_type = $_COOKIE['lang_type']; |
||
| 310 | } |
||
| 311 | |||
| 312 | // If it's not exists, follow default language type set in db_info |
||
| 313 | if(!$this->lang_type) |
||
| 314 | { |
||
| 315 | $this->lang_type = $this->db_info->lang_type; |
||
| 316 | } |
||
| 317 | |||
| 318 | // if still lang_type has not been set or has not-supported type , set as English. |
||
| 319 | if(!$this->lang_type) |
||
| 320 | { |
||
| 321 | $this->lang_type = 'en'; |
||
| 322 | } |
||
| 323 | if(is_array($lang_supported) && !isset($lang_supported[$this->lang_type])) |
||
| 324 | { |
||
| 325 | $this->lang_type = 'en'; |
||
| 326 | } |
||
| 327 | |||
| 328 | $this->set('lang_supported', $lang_supported); |
||
| 329 | $this->setLangType($this->lang_type); |
||
| 330 | |||
| 331 | // load module module's language file according to language setting |
||
| 332 | $this->loadLang(_XE_PATH_ . 'modules/module/lang'); |
||
| 333 | |||
| 334 | // set session handler |
||
| 335 | if(self::isInstalled() && $this->db_info->use_db_session == 'Y') |
||
| 336 | { |
||
| 337 | $oSessionModel = getModel('session'); |
||
| 338 | $oSessionController = getController('session'); |
||
| 339 | session_set_save_handler( |
||
| 340 | array(&$oSessionController, 'open'), array(&$oSessionController, 'close'), array(&$oSessionModel, 'read'), array(&$oSessionController, 'write'), array(&$oSessionController, 'destroy'), array(&$oSessionController, 'gc') |
||
| 341 | ); |
||
| 342 | } |
||
| 343 | |||
| 344 | if($sess = $_POST[session_name()]) session_id($sess); |
||
| 345 | session_start(); |
||
| 346 | |||
| 347 | // set authentication information in Context and session |
||
| 348 | if(self::isInstalled()) |
||
| 349 | { |
||
| 350 | $oModuleModel = getModel('module'); |
||
| 351 | $oModuleModel->loadModuleExtends(); |
||
| 352 | |||
| 353 | $oMemberModel = getModel('member'); |
||
| 354 | $oMemberController = getController('member'); |
||
| 355 | |||
| 356 | if($oMemberController && $oMemberModel) |
||
| 357 | { |
||
| 358 | // if signed in, validate it. |
||
| 359 | if($oMemberModel->isLogged()) |
||
| 360 | { |
||
| 361 | $oMemberController->setSessionInfo(); |
||
| 362 | } |
||
| 363 | // check auto sign-in |
||
| 364 | elseif($_COOKIE['xeak']) |
||
| 365 | { |
||
| 366 | $oMemberController->doAutologin(); |
||
| 367 | } |
||
| 368 | |||
| 369 | $this->set('is_logged', $oMemberModel->isLogged()); |
||
| 370 | $this->set('logged_info', $oMemberModel->getLoggedInfo()); |
||
| 371 | } |
||
| 372 | } |
||
| 373 | |||
| 374 | // load common language file |
||
| 375 | $this->lang = &$GLOBALS['lang']; |
||
| 376 | $this->loadLang(_XE_PATH_ . 'common/lang/'); |
||
| 377 | |||
| 378 | // check if using rewrite module |
||
| 379 | $this->allow_rewrite = ($this->db_info->use_rewrite == 'Y' ? TRUE : FALSE); |
||
| 380 | |||
| 381 | // set locations for javascript use |
||
| 382 | $url = array(); |
||
| 383 | $current_url = self::getRequestUri(); |
||
| 384 | if($_SERVER['REQUEST_METHOD'] == 'GET') |
||
| 385 | { |
||
| 386 | if($this->get_vars) |
||
| 387 | { |
||
| 388 | $url = array(); |
||
| 389 | View Code Duplication | foreach($this->get_vars as $key => $val) |
|
| 390 | { |
||
| 391 | if(is_array($val) && count($val) > 0) |
||
| 392 | { |
||
| 393 | foreach($val as $k => $v) |
||
| 394 | { |
||
| 395 | $url[] = $key . '[' . $k . ']=' . urlencode($v); |
||
| 396 | } |
||
| 397 | } |
||
| 398 | elseif($val) |
||
| 399 | { |
||
| 400 | $url[] = $key . '=' . urlencode($val); |
||
| 401 | } |
||
| 402 | } |
||
| 403 | |||
| 404 | $current_url = self::getRequestUri(); |
||
| 405 | if($url) $current_url .= '?' . join('&', $url); |
||
| 406 | } |
||
| 407 | else |
||
| 408 | { |
||
| 409 | $current_url = $this->getUrl(); |
||
| 410 | } |
||
| 411 | } |
||
| 412 | else |
||
| 413 | { |
||
| 414 | $current_url = self::getRequestUri(); |
||
| 415 | } |
||
| 416 | |||
| 417 | $this->set('current_url', $current_url); |
||
| 418 | $this->set('request_uri', self::getRequestUri()); |
||
| 419 | |||
| 420 | if(strpos($current_url, 'xn--') !== FALSE) |
||
| 421 | { |
||
| 422 | $this->set('current_url', self::decodeIdna($current_url)); |
||
| 423 | } |
||
| 424 | |||
| 425 | if(strpos(self::getRequestUri(), 'xn--') !== FALSE) |
||
| 426 | { |
||
| 427 | $this->set('request_uri', self::decodeIdna(self::getRequestUri())); |
||
| 428 | } |
||
| 429 | } |
||
| 430 | |||
| 431 | /** |
||
| 432 | * Finalize using resources, such as DB connection |
||
| 433 | * |
||
| 434 | * @return void |
||
| 435 | */ |
||
| 436 | function close() |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Load the database information |
||
| 443 | * |
||
| 444 | * @return void |
||
| 445 | */ |
||
| 446 | function loadDBInfo() |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Get DB's db_type |
||
| 525 | * |
||
| 526 | * @return string DB's db_type |
||
| 527 | */ |
||
| 528 | function getDBType() |
||
| 533 | |||
| 534 | /** |
||
| 535 | * Set DB information |
||
| 536 | * |
||
| 537 | * @param object $db_info DB information |
||
| 538 | * @return void |
||
| 539 | */ |
||
| 540 | function setDBInfo($db_info) |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Get DB information |
||
| 548 | * |
||
| 549 | * @return object DB information |
||
| 550 | */ |
||
| 551 | function getDBInfo() |
||
| 556 | |||
| 557 | /** |
||
| 558 | * Return ssl status |
||
| 559 | * |
||
| 560 | * @return object SSL status (Optional - none|always|optional) |
||
| 561 | */ |
||
| 562 | function getSslStatus() |
||
| 567 | |||
| 568 | /** |
||
| 569 | * Return default URL |
||
| 570 | * |
||
| 571 | * @return string Default URL |
||
| 572 | */ |
||
| 573 | function getDefaultUrl() |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Find supported languages |
||
| 581 | * |
||
| 582 | * @return array Supported languages |
||
| 583 | */ |
||
| 584 | function loadLangSupported() |
||
| 599 | |||
| 600 | /** |
||
| 601 | * Find selected languages to serve in the site |
||
| 602 | * |
||
| 603 | * @return array Selected languages |
||
| 604 | */ |
||
| 605 | function loadLangSelected() |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Single Sign On (SSO) |
||
| 640 | * |
||
| 641 | * @return bool True : Module handling is necessary in the control path of current request , False : Otherwise |
||
| 642 | */ |
||
| 643 | function checkSSO() |
||
| 732 | |||
| 733 | /** |
||
| 734 | * Check if FTP info is registered |
||
| 735 | * |
||
| 736 | * @return bool True: FTP information is registered, False: otherwise |
||
| 737 | */ |
||
| 738 | function isFTPRegisted() |
||
| 742 | |||
| 743 | /** |
||
| 744 | * Get FTP information |
||
| 745 | * |
||
| 746 | * @return object FTP information |
||
| 747 | */ |
||
| 748 | function getFTPInfo() |
||
| 761 | |||
| 762 | /** |
||
| 763 | * Add string to browser title |
||
| 764 | * |
||
| 765 | * @param string $site_title Browser title to be added |
||
| 766 | * @return void |
||
| 767 | */ |
||
| 768 | function addBrowserTitle($site_title) |
||
| 785 | |||
| 786 | /** |
||
| 787 | * Set string to browser title |
||
| 788 | * |
||
| 789 | * @param string $site_title Browser title to be set |
||
| 790 | * @return void |
||
| 791 | */ |
||
| 792 | function setBrowserTitle($site_title) |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Get browser title |
||
| 804 | * |
||
| 805 | * @return string Browser title(htmlspecialchars applied) |
||
| 806 | */ |
||
| 807 | function getBrowserTitle() |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Return layout's title |
||
| 819 | * @return string layout's title |
||
| 820 | */ |
||
| 821 | public function getSiteTitle() |
||
| 832 | |||
| 833 | /** |
||
| 834 | * Get browser title |
||
| 835 | * @deprecated |
||
| 836 | */ |
||
| 837 | function _getBrowserTitle() |
||
| 841 | |||
| 842 | /** |
||
| 843 | * Load language file according to language type |
||
| 844 | * |
||
| 845 | * @param string $path Path of the language file |
||
| 846 | * @return void |
||
| 847 | */ |
||
| 848 | function loadLang($path) |
||
| 886 | |||
| 887 | /** |
||
| 888 | * Evaluation of xml language file |
||
| 889 | * |
||
| 890 | * @param string Path of the language file |
||
| 891 | * @return void |
||
| 892 | */ |
||
| 893 | function _evalxmlLang($path) |
||
| 920 | |||
| 921 | /** |
||
| 922 | * Load language file of xml type |
||
| 923 | * |
||
| 924 | * @param string $path Path of the language file |
||
| 925 | * @return string file name |
||
| 926 | */ |
||
| 927 | function _loadXmlLang($path) |
||
| 934 | |||
| 935 | /** |
||
| 936 | * Load language file of php type |
||
| 937 | * |
||
| 938 | * @param string $path Path of the language file |
||
| 939 | * @return string file name |
||
| 940 | */ |
||
| 941 | function _loadPhpLang($path) |
||
| 964 | |||
| 965 | /** |
||
| 966 | * Set lang_type |
||
| 967 | * |
||
| 968 | * @param string $lang_type Language type. |
||
| 969 | * @return void |
||
| 970 | */ |
||
| 971 | function setLangType($lang_type = 'ko') |
||
| 980 | |||
| 981 | /** |
||
| 982 | * Get lang_type |
||
| 983 | * |
||
| 984 | * @return string Language type |
||
| 985 | */ |
||
| 986 | function getLangType() |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Return string accoring to the inputed code |
||
| 994 | * |
||
| 995 | * @param string $code Language variable name |
||
| 996 | * @return string If string for the code exists returns it, otherwise returns original code |
||
| 997 | */ |
||
| 998 | function getLang($code) |
||
| 1010 | |||
| 1011 | /** |
||
| 1012 | * Set data to lang variable |
||
| 1013 | * |
||
| 1014 | * @param string $code Language variable name |
||
| 1015 | * @param string $val `$code`s value |
||
| 1016 | * @return void |
||
| 1017 | */ |
||
| 1018 | function setLang($code, $val) |
||
| 1026 | |||
| 1027 | /** |
||
| 1028 | * Convert strings of variables in $source_object into UTF-8 |
||
| 1029 | * |
||
| 1030 | * @param object $source_obj Conatins strings to convert |
||
| 1031 | * @return object converted object |
||
| 1032 | */ |
||
| 1033 | function convertEncoding($source_obj) |
||
| 1064 | |||
| 1065 | /** |
||
| 1066 | * Check flag |
||
| 1067 | * |
||
| 1068 | * @param mixed $val |
||
| 1069 | * @param string $key |
||
| 1070 | * @param mixed $charset charset |
||
| 1071 | * @see arrayConvWalkCallback will replaced array_walk_recursive in >=PHP5 |
||
| 1072 | * @return void |
||
| 1073 | */ |
||
| 1074 | function checkConvertFlag(&$val, $key = null, $charset = null) |
||
| 1091 | |||
| 1092 | /** |
||
| 1093 | * Convert array type variables into UTF-8 |
||
| 1094 | * |
||
| 1095 | * @param mixed $val |
||
| 1096 | * @param string $key |
||
| 1097 | * @param string $charset character set |
||
| 1098 | * @see arrayConvWalkCallback will replaced array_walk_recursive in >=PHP5 |
||
| 1099 | * @return object converted object |
||
| 1100 | */ |
||
| 1101 | function doConvertEncoding(&$val, $key = null, $charset) |
||
| 1109 | |||
| 1110 | /** |
||
| 1111 | * Convert strings into UTF-8 |
||
| 1112 | * |
||
| 1113 | * @param string $str String to convert |
||
| 1114 | * @return string converted string |
||
| 1115 | */ |
||
| 1116 | function convertEncodingStr($str) |
||
| 1124 | |||
| 1125 | function decodeIdna($domain) |
||
| 1136 | |||
| 1137 | /** |
||
| 1138 | * Force to set response method |
||
| 1139 | * |
||
| 1140 | * @param string $method Response method. [HTML|XMLRPC|JSON] |
||
| 1141 | * @return void |
||
| 1142 | */ |
||
| 1143 | function setResponseMethod($method = 'HTML') |
||
| 1150 | |||
| 1151 | /** |
||
| 1152 | * Get reponse method |
||
| 1153 | * |
||
| 1154 | * @return string Response method. If it's not set, returns request method. |
||
| 1155 | */ |
||
| 1156 | function getResponseMethod() |
||
| 1170 | |||
| 1171 | /** |
||
| 1172 | * Determine request method |
||
| 1173 | * |
||
| 1174 | * @param string $type Request method. (Optional - GET|POST|XMLRPC|JSON) |
||
| 1175 | * @return void |
||
| 1176 | */ |
||
| 1177 | function setRequestMethod($type = '') |
||
| 1189 | |||
| 1190 | /** |
||
| 1191 | * handle global arguments |
||
| 1192 | * |
||
| 1193 | * @return void |
||
| 1194 | */ |
||
| 1195 | function _checkGlobalVars() |
||
| 1205 | |||
| 1206 | /** |
||
| 1207 | * handle request arguments for GET/POST |
||
| 1208 | * |
||
| 1209 | * @return void |
||
| 1210 | */ |
||
| 1211 | function _setRequestArgument() |
||
| 1253 | |||
| 1254 | function _recursiveCheckVar($val) |
||
| 1275 | |||
| 1276 | /** |
||
| 1277 | * Handle request arguments for JSON |
||
| 1278 | * |
||
| 1279 | * @return void |
||
| 1280 | */ |
||
| 1281 | function _setJSONRequestArgument() |
||
| 1296 | |||
| 1297 | /** |
||
| 1298 | * Handle request arguments for XML RPC |
||
| 1299 | * |
||
| 1300 | * @return void |
||
| 1301 | */ |
||
| 1302 | function _setXmlRpcArgument() |
||
| 1332 | |||
| 1333 | /** |
||
| 1334 | * Filter xml variables |
||
| 1335 | * |
||
| 1336 | * @param string $key Variable key |
||
| 1337 | * @param object $val Variable value |
||
| 1338 | * @return mixed filtered value |
||
| 1339 | */ |
||
| 1340 | function _filterXmlVars($key, $val) |
||
| 1383 | |||
| 1384 | /** |
||
| 1385 | * Filter request variable |
||
| 1386 | * |
||
| 1387 | * @see Cast variables, such as _srl, page, and cpage, into interger |
||
| 1388 | * @param string $key Variable key |
||
| 1389 | * @param string $val Variable value |
||
| 1390 | * @param string $do_stripslashes Whether to strip slashes |
||
| 1391 | * @return mixed filtered value. Type are string or array |
||
| 1392 | */ |
||
| 1393 | function _filterRequestVar($key, $val, $do_stripslashes = 1) |
||
| 1453 | |||
| 1454 | /** |
||
| 1455 | * Check if there exists uploaded file |
||
| 1456 | * |
||
| 1457 | * @return bool True: exists, False: otherwise |
||
| 1458 | */ |
||
| 1459 | function isUploaded() |
||
| 1464 | |||
| 1465 | /** |
||
| 1466 | * Handle uploaded file |
||
| 1467 | * |
||
| 1468 | * @return void |
||
| 1469 | */ |
||
| 1470 | function _setUploadedArgument() |
||
| 1512 | |||
| 1513 | /** |
||
| 1514 | * Return request method |
||
| 1515 | * @return string Request method type. (Optional - GET|POST|XMLRPC|JSON) |
||
| 1516 | */ |
||
| 1517 | function getRequestMethod() |
||
| 1522 | |||
| 1523 | /** |
||
| 1524 | * Return request URL |
||
| 1525 | * @return string request URL |
||
| 1526 | */ |
||
| 1527 | function getRequestUrl() |
||
| 1544 | |||
| 1545 | /** |
||
| 1546 | * Return js callback func. |
||
| 1547 | * @return string callback func. |
||
| 1548 | */ |
||
| 1549 | function getJSCallbackFunc() |
||
| 1563 | |||
| 1564 | /** |
||
| 1565 | * Make URL with args_list upon request URL |
||
| 1566 | * |
||
| 1567 | * @param int $num_args Arguments nums |
||
| 1568 | * @param array $args_list Argument list for set url |
||
| 1569 | * @param string $domain Domain |
||
| 1570 | * @param bool $encode If TRUE, use url encode. |
||
| 1571 | * @param bool $autoEncode If TRUE, url encode automatically, detailed. Use this option, $encode value should be TRUE |
||
| 1572 | * @return string URL |
||
| 1573 | */ |
||
| 1574 | function getUrl($num_args = 0, $args_list = array(), $domain = null, $encode = TRUE, $autoEncode = FALSE) |
||
| 1821 | |||
| 1822 | /** |
||
| 1823 | * Return after removing an argument on the requested URL |
||
| 1824 | * |
||
| 1825 | * @param string $ssl_mode SSL mode |
||
| 1826 | * @param string $domain Domain |
||
| 1827 | * @retrun string converted URL |
||
| 1828 | */ |
||
| 1829 | function getRequestUri($ssl_mode = FOLLOW_REQUEST_SSL, $domain = null) |
||
| 1919 | |||
| 1920 | /** |
||
| 1921 | * Set a context value with a key |
||
| 1922 | * |
||
| 1923 | * @param string $key Key |
||
| 1924 | * @param mixed $val Value |
||
| 1925 | * @param mixed $set_to_get_vars If not FALSE, Set to get vars. |
||
| 1926 | * @return void |
||
| 1927 | */ |
||
| 1928 | function set($key, $val, $set_to_get_vars = 0) |
||
| 1946 | |||
| 1947 | /** |
||
| 1948 | * Return key's value |
||
| 1949 | * |
||
| 1950 | * @param string $key Key |
||
| 1951 | * @return string Key |
||
| 1952 | */ |
||
| 1953 | function get($key) |
||
| 1963 | |||
| 1964 | /** |
||
| 1965 | * Get one more vars in object vars with given arguments(key1, key2, key3,...) |
||
| 1966 | * |
||
| 1967 | * @return object |
||
| 1968 | */ |
||
| 1969 | function gets() |
||
| 1986 | |||
| 1987 | /** |
||
| 1988 | * Return all data |
||
| 1989 | * |
||
| 1990 | * @return object All data |
||
| 1991 | */ |
||
| 1992 | function getAll() |
||
| 1997 | |||
| 1998 | /** |
||
| 1999 | * Return values from the GET/POST/XMLRPC |
||
| 2000 | * |
||
| 2001 | * @return Object Request variables. |
||
| 2002 | */ |
||
| 2003 | function getRequestVars() |
||
| 2012 | |||
| 2013 | /** |
||
| 2014 | * Register if an action is to be encrypted by SSL. Those actions are sent to https in common/js/xml_handler.js |
||
| 2015 | * |
||
| 2016 | * @param string $action act name |
||
| 2017 | * @return void |
||
| 2018 | */ |
||
| 2019 | function addSSLAction($action) |
||
| 2036 | |||
| 2037 | /** |
||
| 2038 | * Register if actions are to be encrypted by SSL. Those actions are sent to https in common/js/xml_handler.js |
||
| 2039 | * |
||
| 2040 | * @param string $action act name |
||
| 2041 | * @return void |
||
| 2042 | */ |
||
| 2043 | function addSSLActions($action_array) |
||
| 2064 | |||
| 2065 | /** |
||
| 2066 | * Delete if action is registerd to be encrypted by SSL. |
||
| 2067 | * |
||
| 2068 | * @param string $action act name |
||
| 2069 | * @return void |
||
| 2070 | */ |
||
| 2071 | function subtractSSLAction($action) |
||
| 2083 | |||
| 2084 | /** |
||
| 2085 | * Get SSL Action |
||
| 2086 | * |
||
| 2087 | * @return string acts in array |
||
| 2088 | */ |
||
| 2089 | function getSSLActions() |
||
| 2097 | |||
| 2098 | /** |
||
| 2099 | * Check SSL action are existed |
||
| 2100 | * |
||
| 2101 | * @param string $action act name |
||
| 2102 | * @return bool If SSL exists, return TRUE. |
||
| 2103 | */ |
||
| 2104 | function isExistsSSLAction($action) |
||
| 2109 | |||
| 2110 | /** |
||
| 2111 | * Normalize file path |
||
| 2112 | * |
||
| 2113 | * @deprecated |
||
| 2114 | * @param string $file file path |
||
| 2115 | * @return string normalized file path |
||
| 2116 | */ |
||
| 2117 | function normalizeFilePath($file) |
||
| 2131 | |||
| 2132 | /** |
||
| 2133 | * Get abstract file url |
||
| 2134 | * |
||
| 2135 | * @deprecated |
||
| 2136 | * @param string $file file path |
||
| 2137 | * @return string Converted file path |
||
| 2138 | */ |
||
| 2139 | function getAbsFileUrl($file) |
||
| 2154 | |||
| 2155 | /** |
||
| 2156 | * Load front end file |
||
| 2157 | * |
||
| 2158 | * @param array $args array |
||
| 2159 | * case js : |
||
| 2160 | * $args[0]: file name, |
||
| 2161 | * $args[1]: type (head | body), |
||
| 2162 | * $args[2]: target IE, |
||
| 2163 | * $args[3]: index |
||
| 2164 | * case css : |
||
| 2165 | * $args[0]: file name, |
||
| 2166 | * $args[1]: media, |
||
| 2167 | * $args[2]: target IE, |
||
| 2168 | * $args[3]: index |
||
| 2169 | * |
||
| 2170 | */ |
||
| 2171 | function loadFile($args) |
||
| 2177 | |||
| 2178 | /** |
||
| 2179 | * Unload front end file |
||
| 2180 | * |
||
| 2181 | * @param string $file File name with path |
||
| 2182 | * @param string $targetIe Target IE |
||
| 2183 | * @param string $media Media query |
||
| 2184 | * @return void |
||
| 2185 | */ |
||
| 2186 | function unloadFile($file, $targetIe = '', $media = 'all') |
||
| 2191 | |||
| 2192 | /** |
||
| 2193 | * Unload front end file all |
||
| 2194 | * |
||
| 2195 | * @param string $type Unload target (optional - all|css|js) |
||
| 2196 | * @return void |
||
| 2197 | */ |
||
| 2198 | function unloadAllFiles($type = 'all') |
||
| 2203 | |||
| 2204 | /** |
||
| 2205 | * Add the js file |
||
| 2206 | * |
||
| 2207 | * @deprecated |
||
| 2208 | * @param string $file File name with path |
||
| 2209 | * @param string $optimized optimized (That seems to not use) |
||
| 2210 | * @param string $targetie target IE |
||
| 2211 | * @param string $index index |
||
| 2212 | * @param string $type Added position. (head:<head>..</head>, body:<body>..</body>) |
||
| 2213 | * @param bool $isRuleset Use ruleset |
||
| 2214 | * @param string $autoPath If path not readed, set the path automatically. |
||
| 2215 | * @return void |
||
| 2216 | */ |
||
| 2217 | function addJsFile($file, $optimized = FALSE, $targetie = '', $index = 0, $type = 'head', $isRuleset = FALSE, $autoPath = null) |
||
| 2237 | |||
| 2238 | /** |
||
| 2239 | * Remove the js file |
||
| 2240 | * |
||
| 2241 | * @deprecated |
||
| 2242 | * @param string $file File name with path |
||
| 2243 | * @param string $optimized optimized (That seems to not use) |
||
| 2244 | * @param string $targetie target IE |
||
| 2245 | * @return void |
||
| 2246 | */ |
||
| 2247 | function unloadJsFile($file, $optimized = FALSE, $targetie = '') |
||
| 2252 | |||
| 2253 | /** |
||
| 2254 | * Unload all javascript files |
||
| 2255 | * |
||
| 2256 | * @return void |
||
| 2257 | */ |
||
| 2258 | function unloadAllJsFiles() |
||
| 2263 | |||
| 2264 | /** |
||
| 2265 | * Add javascript filter |
||
| 2266 | * |
||
| 2267 | * @param string $path File path |
||
| 2268 | * @param string $filename File name |
||
| 2269 | * @return void |
||
| 2270 | */ |
||
| 2271 | function addJsFilter($path, $filename) |
||
| 2276 | |||
| 2277 | /** |
||
| 2278 | * Same as array_unique but works only for file subscript |
||
| 2279 | * |
||
| 2280 | * @deprecated |
||
| 2281 | * @param array $files File list |
||
| 2282 | * @return array File list |
||
| 2283 | */ |
||
| 2284 | function _getUniqueFileList($files) |
||
| 2300 | |||
| 2301 | /** |
||
| 2302 | * Returns the list of javascripts that matches the given type. |
||
| 2303 | * |
||
| 2304 | * @param string $type Added position. (head:<head>..</head>, body:<body>..</body>) |
||
| 2305 | * @return array Returns javascript file list. Array contains file, targetie. |
||
| 2306 | */ |
||
| 2307 | function getJsFile($type = 'head') |
||
| 2312 | |||
| 2313 | /** |
||
| 2314 | * Add CSS file |
||
| 2315 | * |
||
| 2316 | * @deprecated |
||
| 2317 | * @param string $file File name with path |
||
| 2318 | * @param string $optimized optimized (That seems to not use) |
||
| 2319 | * @param string $media Media query |
||
| 2320 | * @param string $targetie target IE |
||
| 2321 | * @param string $index index |
||
| 2322 | * @return void |
||
| 2323 | * |
||
| 2324 | */ |
||
| 2325 | function addCSSFile($file, $optimized = FALSE, $media = 'all', $targetie = '', $index = 0) |
||
| 2330 | |||
| 2331 | /** |
||
| 2332 | * Remove css file |
||
| 2333 | * |
||
| 2334 | * @deprecated |
||
| 2335 | * @param string $file File name with path |
||
| 2336 | * @param string $optimized optimized (That seems to not use) |
||
| 2337 | * @param string $media Media query |
||
| 2338 | * @param string $targetie target IE |
||
| 2339 | * @return void |
||
| 2340 | */ |
||
| 2341 | function unloadCSSFile($file, $optimized = FALSE, $media = 'all', $targetie = '') |
||
| 2346 | |||
| 2347 | /** |
||
| 2348 | * Unload all css files |
||
| 2349 | * |
||
| 2350 | * @return void |
||
| 2351 | */ |
||
| 2352 | function unloadAllCSSFiles() |
||
| 2357 | |||
| 2358 | /** |
||
| 2359 | * Return a list of css files |
||
| 2360 | * |
||
| 2361 | * @return array Returns css file list. Array contains file, media, targetie. |
||
| 2362 | */ |
||
| 2363 | function getCSSFile() |
||
| 2368 | |||
| 2369 | /** |
||
| 2370 | * Returns javascript plugin file info |
||
| 2371 | * @param string $pluginName |
||
| 2372 | * @return stdClass |
||
| 2373 | */ |
||
| 2374 | function getJavascriptPluginInfo($pluginName) |
||
| 2423 | /** |
||
| 2424 | * Load javascript plugin |
||
| 2425 | * |
||
| 2426 | * @param string $plugin_name plugin name |
||
| 2427 | * @return void |
||
| 2428 | */ |
||
| 2429 | function loadJavascriptPlugin($plugin_name) |
||
| 2480 | |||
| 2481 | /** |
||
| 2482 | * Add html code before </head> |
||
| 2483 | * |
||
| 2484 | * @param string $header add html code before </head>. |
||
| 2485 | * @return void |
||
| 2486 | */ |
||
| 2487 | function addHtmlHeader($header) |
||
| 2492 | |||
| 2493 | function clearHtmlHeader() |
||
| 2498 | |||
| 2499 | /** |
||
| 2500 | * Returns added html code by addHtmlHeader() |
||
| 2501 | * |
||
| 2502 | * @return string Added html code before </head> |
||
| 2503 | */ |
||
| 2504 | function getHtmlHeader() |
||
| 2509 | |||
| 2510 | /** |
||
| 2511 | * Add css class to Html Body |
||
| 2512 | * |
||
| 2513 | * @param string $class_name class name |
||
| 2514 | */ |
||
| 2515 | function addBodyClass($class_name) |
||
| 2520 | |||
| 2521 | /** |
||
| 2522 | * Return css class to Html Body |
||
| 2523 | * |
||
| 2524 | * @return string Return class to html body |
||
| 2525 | */ |
||
| 2526 | function getBodyClass() |
||
| 2533 | |||
| 2534 | /** |
||
| 2535 | * Add html code after <body> |
||
| 2536 | * |
||
| 2537 | * @param string $header Add html code after <body> |
||
| 2538 | */ |
||
| 2539 | function addBodyHeader($header) |
||
| 2544 | |||
| 2545 | /** |
||
| 2546 | * Returns added html code by addBodyHeader() |
||
| 2547 | * |
||
| 2548 | * @return string Added html code after <body> |
||
| 2549 | */ |
||
| 2550 | function getBodyHeader() |
||
| 2555 | |||
| 2556 | /** |
||
| 2557 | * Add html code before </body> |
||
| 2558 | * |
||
| 2559 | * @param string $footer Add html code before </body> |
||
| 2560 | */ |
||
| 2561 | function addHtmlFooter($footer) |
||
| 2566 | |||
| 2567 | /** |
||
| 2568 | * Returns added html code by addHtmlHeader() |
||
| 2569 | * |
||
| 2570 | * @return string Added html code before </body> |
||
| 2571 | */ |
||
| 2572 | function getHtmlFooter() |
||
| 2577 | |||
| 2578 | /** |
||
| 2579 | * Get config file |
||
| 2580 | * |
||
| 2581 | * @retrun string The path of the config file that contains database settings |
||
| 2582 | */ |
||
| 2583 | function getConfigFile() |
||
| 2587 | |||
| 2588 | /** |
||
| 2589 | * Get FTP config file |
||
| 2590 | * |
||
| 2591 | * @return string The path of the config file that contains FTP settings |
||
| 2592 | */ |
||
| 2593 | function getFTPConfigFile() |
||
| 2597 | |||
| 2598 | /** |
||
| 2599 | * Checks whether XE is installed |
||
| 2600 | * |
||
| 2601 | * @return bool True if the config file exists, otherwise FALSE. |
||
| 2602 | */ |
||
| 2603 | function isInstalled() |
||
| 2607 | |||
| 2608 | /** |
||
| 2609 | * Transforms codes about widget or other features into the actual code, deprecatred |
||
| 2610 | * |
||
| 2611 | * @param string Transforms codes |
||
| 2612 | * @return string Transforms codes |
||
| 2613 | */ |
||
| 2614 | function transContent($content) |
||
| 2618 | |||
| 2619 | /** |
||
| 2620 | * Check whether it is allowed to use rewrite mod |
||
| 2621 | * |
||
| 2622 | * @return bool True if it is allowed to use rewrite mod, otherwise FALSE |
||
| 2623 | */ |
||
| 2624 | function isAllowRewrite() |
||
| 2629 | |||
| 2630 | /** |
||
| 2631 | * Converts a local path into an URL |
||
| 2632 | * |
||
| 2633 | * @param string $path URL path |
||
| 2634 | * @return string Converted path |
||
| 2635 | */ |
||
| 2636 | function pathToUrl($path) |
||
| 2686 | |||
| 2687 | /** |
||
| 2688 | * Get meta tag |
||
| 2689 | * @return array The list of meta tags |
||
| 2690 | */ |
||
| 2691 | function getMetaTag() |
||
| 2709 | |||
| 2710 | /** |
||
| 2711 | * Add the meta tag |
||
| 2712 | * |
||
| 2713 | * @param string $name name of meta tag |
||
| 2714 | * @param string $content content of meta tag |
||
| 2715 | * @param mixed $is_http_equiv value of http_equiv |
||
| 2716 | * @return void |
||
| 2717 | */ |
||
| 2718 | function addMetaTag($name, $content, $is_http_equiv = FALSE) |
||
| 2723 | |||
| 2724 | } |
||
| 2725 | /* End of file Context.class.php */ |
||
| 2727 |