| 1 |
<?php |
<?php |
| 2 |
/** |
/** |
| 3 |
* @package Mambo Open Source |
* @package Mambo |
| 4 |
* @copyright (C) 2005 - 2006 Mambo Foundation Inc. |
* @author Mambo Foundation Inc see README.php |
| 5 |
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL |
* @copyright Mambo Foundation Inc. |
| 6 |
* |
* See COPYRIGHT.php for copyright notices and details. |
| 7 |
* Mambo was originally developed by Miro (www.miro.com.au) in 2000. Miro assigned the copyright in Mambo to The Mambo Foundation in 2005 to ensure |
* @license GNU/GPL Version 2, see LICENSE.php |
| 8 |
* that Mambo remained free Open Source software owned and managed by the community. |
* Mambo is free software; you can redistribute it and/or |
| 9 |
* Mambo is Free Software |
* modify it under the terms of the GNU General Public License |
| 10 |
|
* as published by the Free Software Foundation; version 2 of the License. |
| 11 |
*/ |
*/ |
| 12 |
|
|
| 13 |
/** |
/** |
| 229 |
//$this->rootPath = str_replace('\\', '/', realpath(str_replace('includes', '', dirname(__FILE__)))); |
//$this->rootPath = str_replace('\\', '/', realpath(str_replace('includes', '', dirname(__FILE__)))); |
| 230 |
$this->rootPath = str_replace('\\', '/',str_replace('includes', '', dirname(__FILE__))); |
$this->rootPath = str_replace('\\', '/',str_replace('includes', '', dirname(__FILE__))); |
| 231 |
$this->checkConfig(); |
$this->checkConfig(); |
| 232 |
$this->Itemid = mosGetParam($_REQUEST, 'Itemid', 0); |
$this->Itemid = (int)mosGetParam($_REQUEST, 'Itemid', 0); |
| 233 |
$this->getConfig(); |
$this->getConfig(); |
| 234 |
$this->fixLanguage(); |
$this->fixLanguage(); |
| 235 |
@set_magic_quotes_runtime( 0 ); |
@set_magic_quotes_runtime( 0 ); |
| 325 |
if ($f) { |
if ($f) { |
| 326 |
while ($f AND !feof($f)) { |
while ($f AND !feof($f)) { |
| 327 |
$line = fgets($f); |
$line = fgets($f); |
| 328 |
$altered = str_replace('$', '$this->', $line); |
$altered = preg_replace('/^\$/', '$this->', $line); |
| 329 |
if ($altered != $line) $code .= $altered; |
if ($altered != $line) $code .= $altered; |
| 330 |
} |
} |
| 331 |
} |
} |
| 337 |
eval($code); |
eval($code); |
| 338 |
|
|
| 339 |
|
|
| 340 |
if (isset($_SERVER['DOCUMENT_ROOT']) AND strlen($_SERVER['DOCUMENT_ROOT'])) { |
/*if (isset($_SERVER['DOCUMENT_ROOT']) AND strlen($_SERVER['DOCUMENT_ROOT'])) { |
| 341 |
$docroot = str_replace('\\', '/', str_replace('\\\\', '\\', $_SERVER['DOCUMENT_ROOT'])); |
$docroot = str_replace('\\', '/', str_replace('\\\\', '\\', $_SERVER['DOCUMENT_ROOT'])); |
| 342 |
} |
} |
| 343 |
else { |
else {*/ |
| 344 |
// Find information about where execution started |
// Find information about where execution started |
| 345 |
$origin = array_pop(debug_backtrace()); |
$origin = array_pop(debug_backtrace()); |
| 346 |
// Find the PHP script at the start, with a fix for Windows slashes |
// Find the PHP script at the start, with a fix for Windows slashes |
| 347 |
$absolutepath = str_replace('\\', '/', $origin['file']); |
$absolutepath = str_replace('\\', '/', $origin['file']); |
| 348 |
$localpath = $_SERVER['PHP_SELF']; |
$localpath = $_SERVER['PHP_SELF']; |
| 349 |
$docroot = substr($absolutepath,0,strpos($absolutepath,$localpath)); |
$docroot = substr($absolutepath,0,strpos($absolutepath,$localpath)); |
| 350 |
} |
/*}*/ |
| 351 |
$mamboroot = str_replace('\\', '/', rtrim($this->rootPath, '\/')); |
$mamboroot = str_replace('\\', '/', rtrim($this->rootPath, '\/')); |
| 352 |
$this->subdirectory = substr($mamboroot, strlen($docroot)); |
$this->subdirectory = substr($mamboroot, strlen($docroot)); |
| 353 |
|
|
| 396 |
* @param unknown_type $database |
* @param unknown_type $database |
| 397 |
*/ |
*/ |
| 398 |
function offlineCheck (&$user, &$database) { |
function offlineCheck (&$user, &$database) { |
| 399 |
if ($this->mosConfig_offline OR file_exists($this->rootPath.'/installation/index.php')) { |
global $adminside; |
| 400 |
|
if (($this->mosConfig_offline && !$adminside) OR file_exists($this->rootPath.'/installation/index.php')) { |
| 401 |
require_once($this->rootPath().'/administrator/includes/admin.php'); |
require_once($this->rootPath().'/administrator/includes/admin.php'); |
| 402 |
session_name(md5($this->mosConfig_live_site)); |
session_name(md5($this->mosConfig_live_site)); |
| 403 |
session_start(); |
session_start(); |
| 404 |
$session =& mosSession::getCurrent(); |
$session =& mosSession::getCurrent(); |
| 405 |
|
if (!isset($_SESSION['initiated'])) { |
| 406 |
|
session_regenerate_id(); |
| 407 |
|
$_SESSION['initiated'] = true; |
| 408 |
|
} |
| 409 |
$my =& new mosUser(); |
$my =& new mosUser(); |
| 410 |
$my->getSessionData(); |
$my->getSessionData(); |
| 411 |
if (mosSession::validate($my)) return; |
if (mosSession::validate($my)) return; |
| 423 |
require_once($this->mosConfig_absolute_path.'/includes/phpgettext/error.php'); |
require_once($this->mosConfig_absolute_path.'/includes/phpgettext/error.php'); |
| 424 |
require_once($this->mosConfig_absolute_path.'/includes/mambofunc.php'); |
require_once($this->mosConfig_absolute_path.'/includes/mambofunc.php'); |
| 425 |
require_once($this->mosConfig_absolute_path.'/includes/mambolanguage.class.php'); |
require_once($this->mosConfig_absolute_path.'/includes/mambolanguage.class.php'); |
| 426 |
|
if (!mosGetParam($_REQUEST, 'lang')); |
| 427 |
|
else $this->mosConfig_locale = mosGetParam($_REQUEST, 'lang', $this->mosConfig_locale); |
| 428 |
|
$language =& new mamboLanguage($this->mosConfig_locale, $this->rootPath.'/language/'); |
| 429 |
|
$languages = $language->getLanguages(); |
| 430 |
|
$charset = $language->get('charset'); |
| 431 |
|
$dateformat = $language->get('dateformat'); |
| 432 |
|
$this->mosConfig_lang = $language->get('lang'); |
| 433 |
|
$this->current_language = $language; |
| 434 |
|
if (!defined('_ISO')) DEFINE('_ISO','charset='.$charset); |
| 435 |
|
header('Content-type: text/html; '._ISO); |
| 436 |
|
if (!defined('_DATE_FORMAT_LC')) DEFINE('_DATE_FORMAT_LC', $dateformat); //Uses PHP's strftime Command Format |
| 437 |
|
if (!defined('_DATE_FORMAT_LC2')) DEFINE('_DATE_FORMAT_LC2', $dateformat); |
| 438 |
|
|
| 439 |
#error_reporting(E_ALL) ; |
#error_reporting(E_ALL) ; |
| 440 |
########## DEPRECATED ############ |
########## DEPRECATED ############ |
| 441 |
if (isset($this->mosConfig_lang) AND $this->mosConfig_lang); |
if (isset($this->mosConfig_lang) AND $this->mosConfig_lang); |
| 442 |
else $this->set('mosConfig_lang', 'english'); |
else $this->set('mosConfig_lang', 'english'); |
| 443 |
$language_file = "$this->mosConfig_absolute_path/language/$this->mosConfig_lang.php"; |
$language_file = "$this->mosConfig_absolute_path/language/$this->mosConfig_lang.php"; |
| 444 |
if (file_exists($language_file)) require_once ($language_file); |
if (file_exists($language_file)) require_once ($language_file); |
| 445 |
|
else require_once ("$this->mosConfig_absolute_path/language/english.php"); |
| 446 |
################################### |
################################### |
| 447 |
|
|
| 448 |
|
|
|
$this->mosConfig_lang = mosGetParam($_POST, 'user_lang', $this->mosConfig_lang); |
|
|
|
|
|
|
|
|
$language =& new mamboLanguage($this->mosConfig_lang, $this->rootPath.'/language/'); |
|
|
$languages = $language->getLanguages(); |
|
|
$charset = $language->get('charset'); |
|
|
$dateformat = $language->get('dateformat'); |
|
|
$this->current_language = $language; |
|
|
if (!defined('_ISO')) DEFINE('_ISO','charset='.$charset); |
|
|
if (!defined('_DATE_FORMAT_LC')) DEFINE('_DATE_FORMAT_LC', $dateformat); //Uses PHP's strftime Command Format |
|
|
if (!defined('_DATE_FORMAT_LC2')) DEFINE('_DATE_FORMAT_LC2', $dateformat); |
|
| 449 |
|
|
| 450 |
|
|
| 451 |
} |
} |
| 484 |
* @return unknown |
* @return unknown |
| 485 |
*/ |
*/ |
| 486 |
function determineOptionAndItemid () { |
function determineOptionAndItemid () { |
| 487 |
$this->Itemid = mosGetParam($_REQUEST, 'Itemid', 0); |
$this->Itemid = (int)mosGetParam($_REQUEST, 'Itemid', 0); |
| 488 |
if ($option = strtolower(mosGetParam($_REQUEST, 'option'))); |
if ($option = strtolower(mosGetParam($_REQUEST, 'option'))); |
| 489 |
else { |
else { |
| 490 |
$menuhandler =& mosMenuHandler::getInstance(); |
$menuhandler =& mosMenuHandler::getInstance(); |
| 491 |
$menus =& $menuhandler->getByParentOrder($this->Itemid, 'mainmenu'); |
$menus =& $menuhandler->getByParentOrder($this->Itemid, 'mainmenu'); |
| 492 |
|
if (count($menus)) { |
| 493 |
$this->Itemid = $menus[0]->id; |
$this->Itemid = $menus[0]->id; |
| 494 |
$_REQUEST['Itemid'] = $this->Itemid; |
$_REQUEST['Itemid'] = $this->Itemid; |
| 495 |
$link = $menus[0]->link; |
$link = $menus[0]->link; |
| 501 |
if (isset($temp['option'])) $option = $temp['option']; |
if (isset($temp['option'])) $option = $temp['option']; |
| 502 |
else return ''; |
else return ''; |
| 503 |
} |
} |
| 504 |
|
} |
| 505 |
/** patch to lessen the impact on templates */ |
/** patch to lessen the impact on templates */ |
| 506 |
if ($option == 'search') $option = 'com_search'; |
if ($option == 'search') $option = 'com_search'; |
| 507 |
// checking if we can find the Itemid thru the component |
// checking if we can find the Itemid thru the component |
| 509 |
if ( $option == 'com_content') { |
if ( $option == 'com_content') { |
| 510 |
require_once($this->rootPath().'/components/com_content/content.class.php'); |
require_once($this->rootPath().'/components/com_content/content.class.php'); |
| 511 |
$handler =& contentHandler::getInstance(); |
$handler =& contentHandler::getInstance(); |
| 512 |
$this->Itemid = $handler->getItemid(mosGetParam($_REQUEST, 'id', 0 )); |
$this->Itemid = (int)$handler->getItemid(mosGetParam($_REQUEST, 'id', 0 )); |
| 513 |
$_REQUEST['Itemid'] = $this->Itemid; |
$_REQUEST['Itemid'] = $this->Itemid; |
| 514 |
} |
} |
| 515 |
else { |
else { |
| 521 |
} |
} |
| 522 |
} |
} |
| 523 |
} |
} |
| 524 |
return $option; |
return trim(htmlspecialchars($option)); |
| 525 |
} |
} |
| 526 |
|
|
| 527 |
/** |
/** |
| 582 |
require_once($this->rootPath().'/includes/authenticator.php'); |
require_once($this->rootPath().'/includes/authenticator.php'); |
| 583 |
$authenticator =& mamboAuthenticator::getInstance(); |
$authenticator =& mamboAuthenticator::getInstance(); |
| 584 |
$loggedin = $authenticator->loginUser(); |
$loggedin = $authenticator->loginUser(); |
| 585 |
if ($loggedin) $this->logMessage('_LOGIN_SUCCESS'); |
if ($loggedin) $this->logMessage(T_('You have Logged In succesfully')); |
| 586 |
else mamboCore::redirect('index.php'); |
else mamboCore::redirect('index.php'); |
| 587 |
} |
} |
| 588 |
|
|
| 594 |
require_once($this->rootPath().'/includes/authenticator.php'); |
require_once($this->rootPath().'/includes/authenticator.php'); |
| 595 |
$authenticator =& mamboAuthenticator::getInstance(); |
$authenticator =& mamboAuthenticator::getInstance(); |
| 596 |
$authenticator->logoutUser(); |
$authenticator->logoutUser(); |
| 597 |
$this->logMessage('_LOGOUT_SUCCESS'); |
$this->logMessage(T_('You have Logged Out successfully')); |
| 598 |
} |
} |
| 599 |
|
|
| 600 |
/** |
/** |
| 836 |
if (file_exists( "$rootpath/$imgPath" )) $img = "<img src='$config->mosConfig_live_site/images/M_images/arrow.png' alt='arrow' />"; |
if (file_exists( "$rootpath/$imgPath" )) $img = "<img src='$config->mosConfig_live_site/images/M_images/arrow.png' alt='arrow' />"; |
| 837 |
else $img = '>'; |
else $img = '>'; |
| 838 |
} |
} |
| 839 |
|
$uri =& mosUriHelper::getInstance(); |
| 840 |
foreach ($this->_names as $i=>$name) { |
foreach ($this->_names as $i=>$name) { |
| 841 |
|
$uri->setUri($this->_urls[$i]); |
| 842 |
if ($i === $last AND count($customs) == 0) $result .= "$name</span>"; |
if ($i === $last AND count($customs) == 0) $result .= "$name</span>"; |
| 843 |
elseif (strstr($this->_urls[$i], 'view')) $result .= ""; |
elseif (strstr($uri->get('task'), 'view')) $result .= ""; |
| 844 |
else { |
else { |
| 845 |
$sefurl = sefRelToAbs($this->_urls[$i]); |
$sefurl = sefRelToAbs($this->_urls[$i]); |
| 846 |
$result .= "<a href='$sefurl' class='pathway'>$name</a>"; |
$result .= "<a href='$sefurl' class='pathway'>$name</a>"; |
| 1201 |
function &listAll ($type='file', $recurse=false, $fullpath=false) { |
function &listAll ($type='file', $recurse=false, $fullpath=false) { |
| 1202 |
$results = array(); |
$results = array(); |
| 1203 |
if ($dir = @opendir($this->path)) { |
if ($dir = @opendir($this->path)) { |
| 1204 |
while ($file = readdir($dir)) { |
while (false !== ($file = readdir($dir))) { |
| 1205 |
if ($file == '.' OR $file == '..') continue; |
if ($file == '.' OR $file == '..') continue; |
| 1206 |
if (is_dir($this->path.$file)) { |
if (is_dir($this->path.$file)) { |
| 1207 |
if ($recurse) { |
if ($recurse) { |
| 1217 |
} |
} |
| 1218 |
closedir($dir); |
closedir($dir); |
| 1219 |
} |
} |
| 1220 |
|
asort($results); |
| 1221 |
return $results; |
return $results; |
| 1222 |
} |
} |
| 1223 |
|
|
| 1229 |
function soleDir () { |
function soleDir () { |
| 1230 |
$found = ''; |
$found = ''; |
| 1231 |
if ($dir = @opendir($this->path)) { |
if ($dir = @opendir($this->path)) { |
| 1232 |
while ($file = readdir($dir)) { |
while (false !== ($file = readdir($dir))) { |
| 1233 |
if ($file == '.' OR $file == '..') continue; |
if ($file == '.' OR $file == '..') continue; |
| 1234 |
if (is_dir($this->path.$file)) { |
if (is_dir($this->path.$file)) { |
| 1235 |
if ($found) return ''; |
if ($found) return ''; |
| 1566 |
} |
} |
| 1567 |
} |
} |
| 1568 |
} |
} |
| 1569 |
|
if ($Itemid == 0 && !count($result)){ |
| 1570 |
|
$result[0] = new stdclass; |
| 1571 |
|
$result[0]->id = 1; |
| 1572 |
|
$result[0]->link = 'index.php?option=com_frontpage'; |
| 1573 |
|
$result[0]->parent = 0; |
| 1574 |
|
$result[0]->type = 'components'; |
| 1575 |
|
$result[0]->browserNav = 0; |
| 1576 |
|
$result[0]->name = 'Home'; |
| 1577 |
|
} |
| 1578 |
return $result; |
return $result; |
| 1579 |
} |
} |
| 1580 |
|
|
| 1586 |
function setPathway ($Itemid) { |
function setPathway ($Itemid) { |
| 1587 |
if ($Itemid) { |
if ($Itemid) { |
| 1588 |
$menu =& $this->getMenuByID($Itemid); |
$menu =& $this->getMenuByID($Itemid); |
| 1589 |
|
if (!$menu) return; |
| 1590 |
if ($menu->parent) $this->setPathway($menu->parent); |
if ($menu->parent) $this->setPathway($menu->parent); |
| 1591 |
$pathway =& mosPathway::getInstance(); |
$pathway =& mosPathway::getInstance(); |
| 1592 |
$pathway->addItem($menu->name, $menu->link."&Itemid=$Itemid"); |
$pathway->addItem($menu->name, $menu->link."&Itemid=$Itemid"); |
| 1607 |
if ($this->getIDLikeLink($dblink) == 0) return true; |
if ($this->getIDLikeLink($dblink) == 0) return true; |
| 1608 |
if ($Itemid) { |
if ($Itemid) { |
| 1609 |
$menu =& $this->getMenuByID($Itemid); |
$menu =& $this->getMenuByID($Itemid); |
| 1610 |
|
if (!$menu) return false; |
| 1611 |
if (strpos($menu->link,$dblink) ===0) { |
if (strpos($menu->link,$dblink) ===0) { |
| 1612 |
$access = $menu->access; |
$access = $menu->access; |
| 1613 |
} elseif ($menu_option == 'com_content' AND $Itemid == 1) { |
} elseif ($menu_option == 'com_content' AND $Itemid == 1) { |
| 1707 |
*/ |
*/ |
| 1708 |
function mosShowVIMenu( &$params ) { |
function mosShowVIMenu( &$params ) { |
| 1709 |
global $my, $cur_template, $Itemid; |
global $my, $cur_template, $Itemid; |
| 1710 |
if (mamboCore::get('mosConfig_shownoauth')) $maxaccess = 0; |
if (mamboCore::get('mosConfig_shownoauth')) $maxaccess = 9999999; |
| 1711 |
else $maxaccess = $my->gid; |
else $maxaccess = $my->getAccessGid(); |
| 1712 |
$rows =& $this->getByParentOrder(0, $params->get('menutype'), $maxaccess); |
$rows =& $this->getByParentOrder(0, $params->get('menutype'), $maxaccess); |
| 1713 |
foreach ($rows as $i=>$row) $crosslink[$row->id] = $i; |
foreach ($rows as $i=>$row) $crosslink[$row->id] = $i; |
| 1714 |
// indent icons |
// indent icons |
| 1794 |
function mosShowHFMenu( &$params, $style=0 ) { |
function mosShowHFMenu( &$params, $style=0 ) { |
| 1795 |
global $my, $cur_template, $Itemid; |
global $my, $cur_template, $Itemid; |
| 1796 |
|
|
| 1797 |
if (mamboCore::get('mosConfig_shownoauth')) $maxaccess = 0; |
if (mamboCore::get('mosConfig_shownoauth')) $maxaccess = 9999999; |
| 1798 |
else $maxaccess = $my->gid; |
else $maxaccess = $my->getAccessGid(); |
| 1799 |
$rows =& $this->getByParentOrder(0, $params->get('menutype'), $maxaccess, true); |
$rows =& $this->getByParentOrder(0, $params->get('menutype'), $maxaccess, true); |
| 1800 |
|
|
| 1801 |
$links = array(); |
$links = array(); |
| 1899 |
$selected = $newbot->register(); |
$selected = $newbot->register(); |
| 1900 |
$this->_botRegister($newbot, $selected, $i); |
$this->_botRegister($newbot, $selected, $i); |
| 1901 |
} |
} |
| 1902 |
|
unset($newbot); |
| 1903 |
} |
} |
| 1904 |
} |
} |
| 1905 |
$total++; |
$total++; |
| 1989 |
if (isset($result[0])) return $result[0]; |
if (isset($result[0])) return $result[0]; |
| 1990 |
return null; |
return null; |
| 1991 |
} |
} |
| 1992 |
|
|
| 1993 |
|
function getBot($element, $folder) { |
| 1994 |
|
$returnBot = ''; |
| 1995 |
|
foreach ($this->_bots as $i=>$bot) { |
| 1996 |
|
if ($bot->folder == $folder && $bot->element == $element){ |
| 1997 |
|
$returnBot = $bot; |
| 1998 |
|
break; |
| 1999 |
|
} |
| 2000 |
|
} |
| 2001 |
|
return $returnBot; |
| 2002 |
|
} |
| 2003 |
} |
} |
| 2004 |
|
|
| 2005 |
/** |
/** |
| 2072 |
$this->grp = mosGetParam( $_SESSION, 'session_grp', 0); |
$this->grp = mosGetParam( $_SESSION, 'session_grp', 0); |
| 2073 |
} |
} |
| 2074 |
/** |
/** |
| 2075 |
|
* User access level |
| 2076 |
|
*/ |
| 2077 |
|
function getAccessGid() { |
| 2078 |
|
static $access; |
| 2079 |
|
if (!isset($access)) { |
| 2080 |
|
$acl = new gacl; |
| 2081 |
|
$access = $this->id > 0 ? 1 : 0; |
| 2082 |
|
$access += $acl->acl_check( 'action', 'access', 'users', $this->usertype, 'frontend', 'special' ); |
| 2083 |
|
} |
| 2084 |
|
return $access; |
| 2085 |
|
} |
| 2086 |
|
/** |
| 2087 |
* Validation and filtering |
* Validation and filtering |
| 2088 |
* @return boolean True is satisfactory |
* @return boolean True is satisfactory |
| 2089 |
*/ |
*/ |
| 2090 |
function check() { |
function check() { |
| 2091 |
Global $mosConfig_absolute_path; |
Global $mosConfig_absolute_path; |
| 2092 |
include $mosConfig_absolute_path . ('/language/english.php'); |
//include $mosConfig_absolute_path . ('/language/english.php'); |
| 2093 |
$this->_error = ''; |
$this->_error = ''; |
| 2094 |
if ($this->name == '') $this->_error = _REGWARN_NAME; |
if ($this->name == '') $this->_error = _REGWARN_NAME; |
| 2095 |
elseif ($this->username == '') $this->_error = _REGWARN_UNAME; |
elseif ($this->username == '') $this->_error = _REGWARN_UNAME; |
| 2563 |
$sql['os'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$os',1)"; |
$sql['os'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$os',1)"; |
| 2564 |
$sql['domain'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$tldomain',2)"; |
$sql['domain'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$tldomain',2)"; |
| 2565 |
if ($stats) foreach ($stats as $stat) { |
if ($stats) foreach ($stats as $stat) { |
| 2566 |
if ($stat->type == 0) $sql['agents'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$browser' AND type=0"; |
if ($stat->type == 0) $sql['browser'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$browser' AND type=0"; |
| 2567 |
if ($stat->type == 1) $sql['os'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$os' AND type=1"; |
if ($stat->type == 1) $sql['os'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$os' AND type=1"; |
| 2568 |
if ($stat->type == 2) $sql['domain'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$tldomain' AND type=2"; |
if ($stat->type == 2) $sql['domain'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$tldomain' AND type=2"; |
| 2569 |
} |
} |
| 2583 |
|
|
| 2584 |
function liveBookMark () { |
function liveBookMark () { |
| 2585 |
// support for Firefox Live Bookmarks ability for site syndication |
// support for Firefox Live Bookmarks ability for site syndication |
| 2586 |
|
$live_bookmark = 0; |
| 2587 |
$c_handler =& mosComponentHandler::getInstance(); |
$c_handler =& mosComponentHandler::getInstance(); |
| 2588 |
$params = $c_handler->getParamsByName('Syndicate'); |
$params =& $c_handler->getParamsByName('Syndicate'); |
| 2589 |
|
if (!is_null($params)){ |
| 2590 |
$live_bookmark = $params->get( 'live_bookmark', 0 ); |
$live_bookmark = $params->get( 'live_bookmark', 0 ); |
| 2591 |
|
} |
| 2592 |
|
|
| 2593 |
if ($live_bookmark) { |
if ($live_bookmark) { |
| 2594 |
// custom bookmark file name |
// custom bookmark file name |
| 2595 |
$bookmark_file = $params->get( 'bookmark_file', $live_bookmark ); |
$bookmark_file = $params->get( 'bookmark_file', $live_bookmark ); |
| 2612 |
<?php |
<?php |
| 2613 |
} |
} |
| 2614 |
} |
} |
| 2615 |
|
/** |
| 2616 |
|
* Render head tags |
| 2617 |
|
* tags are assembled into an associative array with the following elements: |
| 2618 |
|
* - title |
| 2619 |
|
* - meta |
| 2620 |
|
* - mambojavascript |
| 2621 |
|
* - custom (custom head tags) |
| 2622 |
|
* - livebookmark |
| 2623 |
|
* - favicon |
| 2624 |
|
* @param unknown keys - array elements to output (null = output all) |
| 2625 |
|
* @param unknown exclude - array elements to exclude in output |
| 2626 |
|
* |
| 2627 |
|
* Usage: mosShowHead() - to render all tags |
| 2628 |
|
* mosShowHead('title') - to render a single tag |
| 2629 |
|
* mosShowHead(array('title', 'meta')) - to selectively render tags (in order) |
| 2630 |
|
* mosShowHead(null, 'custom') - to exclude a single tag |
| 2631 |
|
* mosShowHead(null, array('custom','favicon')) - to exclude multiple tags |
| 2632 |
|
*/ |
| 2633 |
|
function mosShowHead($keys='', $exclude='') { |
| 2634 |
|
if (!is_array($keys)) |
| 2635 |
|
if ($keys !== '' && !is_null($keys)) |
| 2636 |
|
$keys = array($keys); |
| 2637 |
|
else $keys = array(); |
| 2638 |
|
if (!is_array($exclude)) |
| 2639 |
|
if ($exclude !== '') |
| 2640 |
|
$exclude = array($exclude); |
| 2641 |
|
else $exclude = array(); |
| 2642 |
|
|
| 2643 |
|
$this->_head['output'] = array(); |
| 2644 |
|
|
| 2645 |
|
$head = array();; |
| 2646 |
|
$head['title'] = '<title>'.$this->_head['title'].'</title>'; |
| 2647 |
|
|
|
function mosShowHead () { |
|
|
global $_VERSION; |
|
|
$mosConfig_live_site = mamboCore::get('mosConfig_live_site'); |
|
| 2648 |
$this->appendMetaTag( 'description', mamboCore::get('mosConfig_MetaDesc'), true ); |
$this->appendMetaTag( 'description', mamboCore::get('mosConfig_MetaDesc'), true ); |
| 2649 |
$this->appendMetaTag( 'keywords', mamboCore::get('mosConfig_MetaKeys'), true ); |
$this->appendMetaTag( 'keywords', mamboCore::get('mosConfig_MetaKeys'), true ); |
| 2650 |
echo $this->getHead(); |
$head['meta'] = array(); |
| 2651 |
if (mamboCore::get('mosConfig_sef')) { |
foreach ($this->_head['meta'] as $name=>$meta) { |
| 2652 |
echo "<base href=\"$mosConfig_live_site/\" />\r\n"; |
if ($meta[1]) $head['meta'][] = $meta[1]; |
| 2653 |
|
$head['meta'][] = '<meta name="' . $name . '" content="' . $meta[0] . '" />'; |
| 2654 |
|
if ($meta[2]) $head['meta'][] = $meta[2]; |
| 2655 |
} |
} |
| 2656 |
|
$head['meta'] = implode( "\n", $head['meta'] ); |
| 2657 |
|
|
| 2658 |
$my = mamboCore::get('currentUser'); |
$my = mamboCore::get('currentUser'); |
| 2659 |
if ( $my->id ) { |
$head['mambojavascript'] = $my->id ? '<script type="text/javascript" src="'.mamboCore::get('mosConfig_live_site').'/includes/js/mambojavascript.js"></script>' : ''; |
| 2660 |
?> |
|
| 2661 |
<script language="JavaScript1.2" src="<?php echo $mosConfig_live_site;?>/includes/js/mambojavascript.js" type="text/javascript"></script> |
$head['custom'] = array(); |
| 2662 |
<?php |
foreach ($this->_head['custom'] as $html) |
| 2663 |
} |
if (trim($html) !== '') |
| 2664 |
|
$head['custom'][] = $html; |
| 2665 |
|
if (count($head['custom']) !== 0) |
| 2666 |
|
$head['custom'] = implode( "\n", $head['custom'] ); |
| 2667 |
|
else |
| 2668 |
|
$head['custom'] = ''; |
| 2669 |
|
|
| 2670 |
|
ob_start(); |
| 2671 |
$this->liveBookMark(); |
$this->liveBookMark(); |
| 2672 |
// outputs link tag for page |
$head['livebookmark'] = ob_get_contents(); |
| 2673 |
|
ob_end_clean(); |
| 2674 |
|
|
| 2675 |
$configuration =& mamboCore::getMamboCore(); |
$configuration =& mamboCore::getMamboCore(); |
| 2676 |
?> |
$head['favicon'] = "<link rel=\"shortcut icon\" href=\"".$configuration->getFavIcon()."\" />"; |
|
<link rel="shortcut icon" href="<?php echo $configuration->getFavIcon();?>" /> |
|
|
<?php |
|
|
} |
|
| 2677 |
|
|
| 2678 |
|
foreach($head as $key=>$value) |
| 2679 |
|
$this->_head['output'][$key] = "$value"; |
| 2680 |
|
|
| 2681 |
|
$tags = $this->_head['output']; |
| 2682 |
|
if (count($keys) == 0) { |
| 2683 |
|
foreach($tags as $key=>$value) |
| 2684 |
|
if (!in_array($key, $exclude)) |
| 2685 |
|
if ($value !== '') |
| 2686 |
|
echo trim($value)."\n"; |
| 2687 |
|
} else { |
| 2688 |
|
foreach($keys as $key) |
| 2689 |
|
if (isset($tags[$key])) |
| 2690 |
|
if(trim($tags[$key]) !== '') |
| 2691 |
|
echo trim($tags[$key])."\n"; |
| 2692 |
|
} |
| 2693 |
|
} |
| 2694 |
|
|
| 2695 |
/** |
/** |
| 2696 |
* retained for backward compatability |
* retained for backward compatability |
| 3050 |
return ((float)$usec + (float)$sec); |
return ((float)$usec + (float)$sec); |
| 3051 |
} |
} |
| 3052 |
} |
} |
| 3053 |
|
|
| 3054 |
|
|
| 3055 |
|
/** |
| 3056 |
|
* @author Mikolaj Jedrzejak <mikolajj@op.pl> |
| 3057 |
|
* @copyright Copyright Mikolaj Jedrzejak (c) 2003-2004 |
| 3058 |
|
* @version 1.0 2004-07-27 00:37 |
| 3059 |
|
* @link http://www.unicode.org Unicode Homepage |
| 3060 |
|
* @link http://www.mikkom.pl My Homepage |
| 3061 |
|
* |
| 3062 |
|
**/ |
| 3063 |
|
$PATH_TO_CLASS = dirname(ereg_replace("\\\\","/",__FILE__)) . "/" . "ConvertTables" . "/"; |
| 3064 |
|
@require_once($PATH_TO_CLASS."/charsetmapping.php"); |
| 3065 |
|
define ("CONVERT_TABLES_DIR", $PATH_TO_CLASS); |
| 3066 |
|
define ("DEBUG_MODE", 1); |
| 3067 |
|
|
| 3068 |
|
/** |
| 3069 |
|
* -- 1.0 2004-07-28 -- |
| 3070 |
|
* |
| 3071 |
|
* -- The most important thing -- |
| 3072 |
|
* I want to thank all people who helped me fix all bugs, small and big once. |
| 3073 |
|
* I hope that you don't mind that your names are in this file. |
| 3074 |
|
* |
| 3075 |
|
* -- Some Apache issues -- |
| 3076 |
|
* I get info from Lukas Lisa, that in some cases with special apache configuration |
| 3077 |
|
* you have to put header() function with proper encoding to get your result |
| 3078 |
|
* displayed correctly. |
| 3079 |
|
* If you want to see what I mean, go to demo.php and demo1.php |
| 3080 |
|
* |
| 3081 |
|
* -- BETA 1.0 2003-10-21 -- |
| 3082 |
|
* |
| 3083 |
|
* -- You should know about... -- |
| 3084 |
|
* For good understanding this class you shouls read all this stuff first :) but if you are |
| 3085 |
|
* in a hurry just start the demo.php and see what's inside. |
| 3086 |
|
* 1. That I'm not good in english at 03:45 :) - so forgive me all mistakes |
| 3087 |
|
* 2. This class is a BETA version because I haven't tested it enough |
| 3088 |
|
* 3. Feel free to contact me with questions, bug reports and mistakes in PHP and this documentation (email below) |
| 3089 |
|
* |
| 3090 |
|
* -- In a few words... -- |
| 3091 |
|
* Why ConvertCharset class? |
| 3092 |
|
* |
| 3093 |
|
* I have made this class because I had a lot of problems with diferent charsets. First because people |
| 3094 |
|
* from Microsoft wanted to have thair own encoding, second because people from Macromedia didn't |
| 3095 |
|
* thought about other languages, third because sometimes I need to use text written on MAC, and of course |
| 3096 |
|
* it has its own encoding :) |
| 3097 |
|
* |
| 3098 |
|
* Notice & remember: |
| 3099 |
|
* - When I'm saying 1 byte string I mean 1 byte per char. |
| 3100 |
|
* - When I'm saying multibyte string I mean more than one byte per char. |
| 3101 |
|
* |
| 3102 |
|
* So, this are main FEATURES of this class: |
| 3103 |
|
* - conversion between 1 byte charsets |
| 3104 |
|
* - conversion from 1 byte to multi byte charset (utf-8) |
| 3105 |
|
* - conversion from multibyte charset (utf-8) to 1 byte charset |
| 3106 |
|
* - every conversion output can be save with numeric entities (browser charset independent - not a full truth) |
| 3107 |
|
* |
| 3108 |
|
* This is a list of charsets you can operate with, the basic rule is that a char have to be in both charsets, |
| 3109 |
|
* otherwise you'll get an error. |
| 3110 |
|
* |
| 3111 |
|
* - WINDOWS |
| 3112 |
|
* - windows-1250 - Central Europe |
| 3113 |
|
* - windows-1251 - Cyrillic |
| 3114 |
|
* - windows-1252 - Latin I |
| 3115 |
|
* - windows-1253 - Greek |
| 3116 |
|
* - windows-1254 - Turkish |
| 3117 |
|
* - windows-1255 - Hebrew |
| 3118 |
|
* - windows-1256 - Arabic |
| 3119 |
|
* - windows-1257 - Baltic |
| 3120 |
|
* - windows-1258 - Viet Nam |
| 3121 |
|
* - cp874 - Thai - this file is also for DOS |
| 3122 |
|
* |
| 3123 |
|
* - DOS |
| 3124 |
|
* - cp437 - Latin US |
| 3125 |
|
* - cp737 - Greek |
| 3126 |
|
* - cp775 - BaltRim |
| 3127 |
|
* - cp850 - Latin1 |
| 3128 |
|
* - cp852 - Latin2 |
| 3129 |
|
* - cp855 - Cyrylic |
| 3130 |
|
* - cp857 - Turkish |
| 3131 |
|
* - cp860 - Portuguese |
| 3132 |
|
* - cp861 - Iceland |
| 3133 |
|
* - cp862 - Hebrew |
| 3134 |
|
* - cp863 - Canada |
| 3135 |
|
* - cp864 - Arabic |
| 3136 |
|
* - cp865 - Nordic |
| 3137 |
|
* - cp866 - Cyrylic Russian (this is the one, used in IE "Cyrillic (DOS)" ) |
| 3138 |
|
* - cp869 - Greek2 |
| 3139 |
|
* |
| 3140 |
|
* - MAC (Apple) |
| 3141 |
|
* - x-mac-cyrillic |
| 3142 |
|
* - x-mac-greek |
| 3143 |
|
* - x-mac-icelandic |
| 3144 |
|
* - x-mac-ce |
| 3145 |
|
* - x-mac-roman |
| 3146 |
|
* |
| 3147 |
|
* - ISO (Unix/Linux) |
| 3148 |
|
* - iso-8859-1 |
| 3149 |
|
* - iso-8859-2 |
| 3150 |
|
* - iso-8859-3 |
| 3151 |
|
* - iso-8859-4 |
| 3152 |
|
* - iso-8859-5 |
| 3153 |
|
* - iso-8859-6 |
| 3154 |
|
* - iso-8859-7 |
| 3155 |
|
* - iso-8859-8 |
| 3156 |
|
* - iso-8859-9 |
| 3157 |
|
* - iso-8859-10 |
| 3158 |
|
* - iso-8859-11 |
| 3159 |
|
* - iso-8859-12 |
| 3160 |
|
* - iso-8859-13 |
| 3161 |
|
* - iso-8859-14 |
| 3162 |
|
* - iso-8859-15 |
| 3163 |
|
* - iso-8859-16 |
| 3164 |
|
* |
| 3165 |
|
* - MISCELLANEOUS |
| 3166 |
|
* - gsm0338 (ETSI GSM 03.38) |
| 3167 |
|
* - cp037 |
| 3168 |
|
* - cp424 |
| 3169 |
|
* - cp500 |
| 3170 |
|
* - cp856 |
| 3171 |
|
* - cp875 |
| 3172 |
|
* - cp1006 |
| 3173 |
|
* - cp1026 |
| 3174 |
|
* - koi8-r (Cyrillic) |
| 3175 |
|
* - koi8-u (Cyrillic Ukrainian) |
| 3176 |
|
* - nextstep |
| 3177 |
|
* - us-ascii |
| 3178 |
|
* - us-ascii-quotes |
| 3179 |
|
* |
| 3180 |
|
* - DSP implementation for NeXT |
| 3181 |
|
* - stdenc |
| 3182 |
|
* - symbol |
| 3183 |
|
* - zdingbat |
| 3184 |
|
* |
| 3185 |
|
* - And specially for old Polish programs |
| 3186 |
|
* - mazovia |
| 3187 |
|
* |
| 3188 |
|
* -- Now, to the point... -- |
| 3189 |
|
* Here are main variables. |
| 3190 |
|
* |
| 3191 |
|
* DEBUG_MODE |
| 3192 |
|
* |
| 3193 |
|
* You can set this value to: |
| 3194 |
|
* - -1 - No errors or comments |
| 3195 |
|
* - 0 - Only error messages, no comments |
| 3196 |
|
* - 1 - Error messages and comments |
| 3197 |
|
* |
| 3198 |
|
* Default value is 1, and during first steps with class it should be left as is. |
| 3199 |
|
* |
| 3200 |
|
* CONVERT_TABLES_DIR |
| 3201 |
|
* |
| 3202 |
|
* This is a place where you store all files with charset encodings. Filenames should have |
| 3203 |
|
* the same names as encodings. My advise is to keep existing names, because thay |
| 3204 |
|
* were taken from unicode.org (www.unicode.org), and after update to unicode 3.0 or 4.0 |
| 3205 |
|
* the names of files will be the same, so if you want to save your time...uff, leave the |
| 3206 |
|
* names as thay are for future updates. |
| 3207 |
|
* |
| 3208 |
|
* The directory with edings files should be in a class location directory by default, |
| 3209 |
|
* but of course you can change it if you like. |
| 3210 |
|
* |
| 3211 |
|
* @package All about charset... |
| 3212 |
|
* @author Mikolaj Jedrzejak <mikolajj@op.pl> |
| 3213 |
|
* @copyright Copyright Mikolaj Jedrzejak (c) 2003-2004 |
| 3214 |
|
* @version 1.0 2004-07-27 23:11 |
| 3215 |
|
* @access public |
| 3216 |
|
* |
| 3217 |
|
* @link http://www.unicode.org Unicode Homepage |
| 3218 |
|
**/ |
| 3219 |
|
class ConvertCharset { |
| 3220 |
|
var $RecognizedEncoding; //This value keeps information if string contains multibyte chars. |
| 3221 |
|
var $Entities; // This value keeps information if output should be with numeric entities. |
| 3222 |
|
|
| 3223 |
|
/** |
| 3224 |
|
* CharsetChange::NumUnicodeEntity() |
| 3225 |
|
* |
| 3226 |
|
* Unicode encoding bytes, bits representation. |
| 3227 |
|
* Each b represents a bit that can be used to store character data. |
| 3228 |
|
* - bytes, bits, binary representation |
| 3229 |
|
* - 1, 7, 0bbbbbbb |
| 3230 |
|
* - 2, 11, 110bbbbb 10bbbbbb |
| 3231 |
|
* - 3, 16, 1110bbbb 10bbbbbb 10bbbbbb |
| 3232 |
|
* - 4, 21, 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb |
| 3233 |
|
* |
| 3234 |
|
* This function is written in a "long" way, for everyone who woluld like to analize |
| 3235 |
|
* the process of unicode encoding and understand it. All other functions like HexToUtf |
| 3236 |
|
* will be written in a "shortest" way I can write tham :) it does'n mean thay are short |
| 3237 |
|
* of course. You can chech it in HexToUtf() (link below) - very similar function. |
| 3238 |
|
* |
| 3239 |
|
* IMPORTANT: Remember that $UnicodeString input CANNOT have single byte upper half |
| 3240 |
|
* extended ASCII codes, why? Because there is a posibility that this function will eat |
| 3241 |
|
* the following char thinking it's miltibyte unicode char. |
| 3242 |
|
* |
| 3243 |
|
* @param string $UnicodeString Input Unicode string (1 char can take more than 1 byte) |
| 3244 |
|
* @return string This is an input string olso with unicode chars, bus saved as entities |
| 3245 |
|
* @see HexToUtf() |
| 3246 |
|
**/ |
| 3247 |
|
function UnicodeEntity ($UnicodeString) |
| 3248 |
|
{ |
| 3249 |
|
$OutString = ""; |
| 3250 |
|
$StringLenght = strlen ($UnicodeString); |
| 3251 |
|
for ($CharPosition = 0; $CharPosition < $StringLenght; $CharPosition++) |
| 3252 |
|
{ |
| 3253 |
|
$Char = $UnicodeString [$CharPosition]; |
| 3254 |
|
$AsciiChar = ord ($Char); |
| 3255 |
|
|
| 3256 |
|
if ($AsciiChar < 128) //1 7 0bbbbbbb (127) |
| 3257 |
|
{ |
| 3258 |
|
$OutString .= $Char; |
| 3259 |
|
} |
| 3260 |
|
else if ($AsciiChar >> 5 == 6) //2 11 110bbbbb 10bbbbbb (2047) |
| 3261 |
|
{ |
| 3262 |
|
$FirstByte = ($AsciiChar & 31); |
| 3263 |
|
$CharPosition++; |
| 3264 |
|
$Char = $UnicodeString [$CharPosition]; |
| 3265 |
|
$AsciiChar = ord ($Char); |
| 3266 |
|
$SecondByte = ($AsciiChar & 63); |
| 3267 |
|
$AsciiChar = ($FirstByte * 64) + $SecondByte; |
| 3268 |
|
$Entity = sprintf ("&#%d;", $AsciiChar); |
| 3269 |
|
$OutString .= $Entity; |
| 3270 |
|
} |
| 3271 |
|
else if ($AsciiChar >> 4 == 14) //3 16 1110bbbb 10bbbbbb 10bbbbbb |
| 3272 |
|
{ |
| 3273 |
|
$FirstByte = ($AsciiChar & 31); |
| 3274 |
|
$CharPosition++; |
| 3275 |
|
$Char = $UnicodeString [$CharPosition]; |
| 3276 |
|
$AsciiChar = ord ($Char); |
| 3277 |
|
$SecondByte = ($AsciiChar & 63); |
| 3278 |
|
$CharPosition++; |
| 3279 |
|
$Char = $UnicodeString [$CharPosition]; |
| 3280 |
|
$AsciiChar = ord ($Char); |
| 3281 |
|
$ThidrByte = ($AsciiChar & 63); |
| 3282 |
|
$AsciiChar = ((($FirstByte * 64) + $SecondByte) * 64) + $ThidrByte; |
| 3283 |
|
|
| 3284 |
|
$Entity = sprintf ("&#%d;", $AsciiChar); |
| 3285 |
|
$OutString .= $Entity; |
| 3286 |
|
} |
| 3287 |
|
else if ($AsciiChar >> 3 == 30) //4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb |
| 3288 |
|
{ |
| 3289 |
|
$FirstByte = ($AsciiChar & 31); |
| 3290 |
|
$CharPosition++; |
| 3291 |
|
$Char = $UnicodeString [$CharPosition]; |
| 3292 |
|
$AsciiChar = ord ($Char); |
| 3293 |
|
$SecondByte = ($AsciiChar & 63); |
| 3294 |
|
$CharPosition++; |
| 3295 |
|
$Char = $UnicodeString [$CharPosition]; |
| 3296 |
|
$AsciiChar = ord ($Char); |
| 3297 |
|
$ThidrByte = ($AsciiChar & 63); |
| 3298 |
|
$CharPosition++; |
| 3299 |
|
$Char = $UnicodeString [$CharPosition]; |
| 3300 |
|
$AsciiChar = ord ($Char); |
| 3301 |
|
$FourthByte = ($AsciiChar & 63); |
| 3302 |
|
$AsciiChar = ((((($FirstByte * 64) + $SecondByte) * 64) + $ThidrByte) * 64) + $FourthByte; |
| 3303 |
|
|
| 3304 |
|
$Entity = sprintf ("&#%d;", $AsciiChar); |
| 3305 |
|
$OutString .= $Entity; |
| 3306 |
|
} |
| 3307 |
|
} |
| 3308 |
|
return $OutString; |
| 3309 |
|
} |
| 3310 |
|
|
| 3311 |
|
/** |
| 3312 |
|
* ConvertCharset::HexToUtf() |
| 3313 |
|
* |
| 3314 |
|
* This simple function gets unicode char up to 4 bytes and return it as a regular char. |
| 3315 |
|
* It is very similar to UnicodeEntity function (link below). There is one difference |
| 3316 |
|
* in returned format. This time it's a regular char(s), in most cases it will be one or two chars. |
| 3317 |
|
* |
| 3318 |
|
* @param string $UtfCharInHex Hexadecimal value of a unicode char. |
| 3319 |
|
* @return string Encoded hexadecimal value as a regular char. |
| 3320 |
|
* @see UnicodeEntity() |
| 3321 |
|
**/ |
| 3322 |
|
function HexToUtf ($UtfCharInHex) |
| 3323 |
|
{ |
| 3324 |
|
$OutputChar = ""; |
| 3325 |
|
$UtfCharInDec = hexdec($UtfCharInHex); |
| 3326 |
|
if($UtfCharInDec<128) $OutputChar .= chr($UtfCharInDec); |
| 3327 |
|
else if($UtfCharInDec<2048)$OutputChar .= chr(($UtfCharInDec>>6)+192).chr(($UtfCharInDec&63)+128); |
| 3328 |
|
else if($UtfCharInDec<65536)$OutputChar .= chr(($UtfCharInDec>>12)+224).chr((($UtfCharInDec>>6)&63)+128).chr(($UtfCharInDec&63)+128); |
| 3329 |
|
else if($UtfCharInDec<2097152)$OutputChar .= chr($UtfCharInDec>>18+240).chr((($UtfCharInDec>>12)&63)+128).chr(($UtfCharInDec>>6)&63+128). chr($UtfCharInDec&63+128); |
| 3330 |
|
return $OutputChar; |
| 3331 |
|
} |
| 3332 |
|
|
| 3333 |
|
|
| 3334 |
|
/** |
| 3335 |
|
* CharsetChange::MakeConvertTable() |
| 3336 |
|
* |
| 3337 |
|
* This function creates table with two SBCS (Single Byte Character Set). Every conversion |
| 3338 |
|
* is through this table. |
| 3339 |
|
* |
| 3340 |
|
* - The file with encoding tables have to be save in "Format A" of unicode.org charset table format! This is usualy writen in a header of every charset file. |
| 3341 |
|
* - BOTH charsets MUST be SBCS |
| 3342 |
|
* - The files with encoding tables have to be complet (Non of chars can be missing, unles you are sure you are not going to use it) |
| 3343 |
|
* |
| 3344 |
|
* "Format A" encoding file, if you have to build it by yourself should aplly these rules: |
| 3345 |
|
* - you can comment everything with # |
| 3346 |
|
* - first column contains 1 byte chars in hex starting from 0x.. |
| 3347 |
|
* - second column contains unicode equivalent in hex starting from 0x.... |
| 3348 |
|
* - then every next column is optional, but in "Format A" it should contain unicode char name or/and your own comment |
| 3349 |
|
* - the columns can be splited by "spaces", "tabs", "," or any combination of these |
| 3350 |
|
* - below is an example |
| 3351 |
|
* |
| 3352 |
|
* <code> |
| 3353 |
|
* # |
| 3354 |
|
* # The entries are in ANSI X3.4 order. |
| 3355 |
|
* # |
| 3356 |
|
* 0x00 0x0000 # NULL end extra comment, if needed |
| 3357 |
|
* 0x01 0x0001 # START OF HEADING |
| 3358 |
|
* # Oh, one more thing, you can make comments inside of a rows if you like. |
| 3359 |
|
* 0x02 0x0002 # START OF TEXT |
| 3360 |
|
* 0x03 0x0003 # END OF TEXT |
| 3361 |
|
* next line, and so on... |
| 3362 |
|
* </code> |
| 3363 |
|
* |
| 3364 |
|
* You can get full tables with encodings from http://www.unicode.org |
| 3365 |
|
* |
| 3366 |
|
* @param string $FirstEncoding Name of first encoding and first encoding filename (thay have to be the same) |
| 3367 |
|
* @param string $SecondEncoding Name of second encoding and second encoding filename (thay have to be the same). Optional for building a joined table. |
| 3368 |
|
* @return array Table necessary to change one encoding to another. |
| 3369 |
|
**/ |
| 3370 |
|
function MakeConvertTable ($FirstEncoding, $SecondEncoding = "") |
| 3371 |
|
{ |
| 3372 |
|
$ConvertTable = array(); |
| 3373 |
|
for($i = 0; $i < func_num_args(); $i++) |
| 3374 |
|
{ |
| 3375 |
|
/** |
| 3376 |
|
* Because func_*** can't be used inside of another function call |
| 3377 |
|
* we have to save it as a separate value. |
| 3378 |
|
**/ |
| 3379 |
|
$FileName = func_get_arg($i); |
| 3380 |
|
if (!is_file(CONVERT_TABLES_DIR . $FileName)) |
| 3381 |
|
{ |
| 3382 |
|
print $this->DebugOutput(0, 0, CONVERT_TABLES_DIR . $FileName); //Print an error message |
| 3383 |
|
exit; |
| 3384 |
|
} |
| 3385 |
|
$FileWithEncTabe = fopen(CONVERT_TABLES_DIR . $FileName, "r") or die(); //This die(); is just to make sure... |
| 3386 |
|
while(!feof($FileWithEncTabe)) |
| 3387 |
|
{ |
| 3388 |
|
/** |
| 3389 |
|
* We asume that line is not longer |
| 3390 |
|
* than 1024 which is the default value for fgets function |
| 3391 |
|
**/ |
| 3392 |
|
if($OneLine=trim(fgets($FileWithEncTabe, 1024))) |
| 3393 |
|
{ |
| 3394 |
|
/** |
| 3395 |
|
* We don't need all comment lines. I check only for "#" sign, because |
| 3396 |
|
* this is a way of making comments by unicode.org in thair encoding files |
| 3397 |
|
* and that's where the files are from :-) |
| 3398 |
|
**/ |
| 3399 |
|
if (substr($OneLine, 0, 1) != "#") |
| 3400 |
|
{ |
| 3401 |
|
/** |
| 3402 |
|
* Sometimes inside the charset file the hex walues are separated by |
| 3403 |
|
* "space" and sometimes by "tab", the below preg_split can also be used |
| 3404 |
|
* to split files where separator is a ",", "\r", "\n" and "\f" |
| 3405 |
|
**/ |
| 3406 |
|
$HexValue = preg_split ("/[\s,]+/", $OneLine, 3); //We need only first 2 values |
| 3407 |
|
/** |
| 3408 |
|
* Sometimes char is UNDEFINED, or missing so we can't use it for convertion |
| 3409 |
|
**/ |
| 3410 |
|
if (substr($HexValue[1], 0, 1) != "#") |
| 3411 |
|
{ |
| 3412 |
|
$ArrayKey = strtoupper(str_replace(strtolower("0x"), "", $HexValue[1])); |
| 3413 |
|
$ArrayValue = strtoupper(str_replace(strtolower("0x"), "", $HexValue[0])); |
| 3414 |
|
$ConvertTable[func_get_arg($i)][$ArrayKey] = $ArrayValue; |
| 3415 |
|
} |
| 3416 |
|
} //if (substr($OneLine,... |
| 3417 |
|
} //if($OneLine=trim(f... |
| 3418 |
|
} //while(!feof($FirstFileWi... |
| 3419 |
|
} //for($i = 0; $i < func_... |
| 3420 |
|
/** |
| 3421 |
|
* The last thing is to check if by any reason both encoding tables are not the same. |
| 3422 |
|
* For example, it will happen when you save the encoding table file with a wrong name |
| 3423 |
|
* - of another charset. |
| 3424 |
|
**/ |
| 3425 |
|
if ((func_num_args() > 1) && (count($ConvertTable[$FirstEncoding]) == count($ConvertTable[$SecondEncoding])) && (count(array_diff_assoc($ConvertTable[$FirstEncoding], $ConvertTable[$SecondEncoding])) == 0)) |
| 3426 |
|
{ |
| 3427 |
|
print $this->DebugOutput(1, 1, "$FirstEncoding, $SecondEncoding"); |
| 3428 |
|
} |
| 3429 |
|
return $ConvertTable; |
| 3430 |
|
} |
| 3431 |
|
|
| 3432 |
|
|
| 3433 |
|
|
| 3434 |
|
/** |
| 3435 |
|
* ConvertCharset::Convert() |
| 3436 |
|
* |
| 3437 |
|
* This is a basic function you are using. I hope that you can figure out this function syntax :-) |
| 3438 |
|
* |
| 3439 |
|
* @param string $StringToChange The string you want to change :) |
| 3440 |
|
* @param string $FromCharset Name of $StringToChange encoding, you have to know it. |
| 3441 |
|
* @param string $ToCharset Name of a charset you want to get for $StringToChange. |
| 3442 |
|
* @param boolean $TurnOnEntities Set to true or 1 if you want to use numeric entities insted of regular chars. |
| 3443 |
|
* @return string Converted string in brand new encoding :) |
| 3444 |
|
* @version 1.0 2004-07-27 01:09 |
| 3445 |
|
**/ |
| 3446 |
|
function Convert ($StringToChange, $FromCharset, $ToCharset, $TurnOnEntities = false) |
| 3447 |
|
{ |
| 3448 |
|
/** |
| 3449 |
|
* Check are there all variables |
| 3450 |
|
**/ |
| 3451 |
|
/*if ($StringToChange == "") |
| 3452 |
|
{ |
| 3453 |
|
print $this->DebugOutput(0, 3, "\$StringToChange"); |
| 3454 |
|
} |
| 3455 |
|
else*/ |
| 3456 |
|
if ($FromCharset == "") |
| 3457 |
|
{ |
| 3458 |
|
print $this->DebugOutput(0, 3, "\$FromCharset"); |
| 3459 |
|
} |
| 3460 |
|
else if ($ToCharset == "") |
| 3461 |
|
{ |
| 3462 |
|
print $this->DebugOutput(0, 3, "\$ToCharset"); |
| 3463 |
|
} |
| 3464 |
|
|
| 3465 |
|
/** |
| 3466 |
|
* Now a few variables need to be set. |
| 3467 |
|
**/ |
| 3468 |
|
$NewString = ""; |
| 3469 |
|
$this->Entities = $TurnOnEntities; |
| 3470 |
|
|
| 3471 |
|
/** |
| 3472 |
|
* For all people who like to use uppercase for charset encoding names :) |
| 3473 |
|
**/ |
| 3474 |
|
$FromCharset = strtolower($FromCharset); |
| 3475 |
|
$ToCharset = strtolower($ToCharset); |
| 3476 |
|
|
| 3477 |
|
/** |
| 3478 |
|
* Of course you can make a conversion from one charset to the same one :) |
| 3479 |
|
* but I feel obligate to let you know about it. |
| 3480 |
|
**/ |
| 3481 |
|
if ($FromCharset == $ToCharset) |
| 3482 |
|
{ |
| 3483 |
|
print $this->DebugOutput(1, 0, $FromCharset); |
| 3484 |
|
} |
| 3485 |
|
if (($FromCharset == $ToCharset) AND ($FromCharset == "utf-8")) |
| 3486 |
|
{ |
| 3487 |
|
print $this->DebugOutput(0, 4, $FromCharset); |
| 3488 |
|
exit; |
| 3489 |
|
} |
| 3490 |
|
|
| 3491 |
|
/** |
| 3492 |
|
* This divison was made to prevent errors during convertion to/from utf-8 with |
| 3493 |
|
* "entities" enabled, because we need to use proper destination(to)/source(from) |
| 3494 |
|
* encoding table to write proper entities. |
| 3495 |
|
* |
| 3496 |
|
* This is the first case. We are convertinf from 1byte chars... |
| 3497 |
|
**/ |
| 3498 |
|
if ($FromCharset != "utf-8") |
| 3499 |
|
{ |
| 3500 |
|
/** |
| 3501 |
|
* Now build table with both charsets for encoding change. |
| 3502 |
|
**/ |
| 3503 |
|
if ($ToCharset != "utf-8") |
| 3504 |
|
{ |
| 3505 |
|
$CharsetTable = $this->MakeConvertTable ($FromCharset, $ToCharset); |
| 3506 |
|
} |
| 3507 |
|
else |
| 3508 |
|
{ |
| 3509 |
|
$CharsetTable = $this->MakeConvertTable ($FromCharset); |
| 3510 |
|
} |
| 3511 |
|
/** |
| 3512 |
|
* For each char in a string... |
| 3513 |
|
**/ |
| 3514 |
|
for ($i = 0; $i < strlen($StringToChange); $i++) |
| 3515 |
|
{ |
| 3516 |
|
$HexChar = ""; |
| 3517 |
|
$UnicodeHexChar = ""; |
| 3518 |
|
$HexChar = strtoupper(dechex(ord($StringToChange[$i]))); |
| 3519 |
|
// This is fix from Mario Klingemann, it prevents |
| 3520 |
|
// droping chars below 16 because of missing leading 0 [zeros] |
| 3521 |
|
if (strlen($HexChar)==1) $HexChar = "0".$HexChar; |
| 3522 |
|
//end of fix by Mario Klingemann |
| 3523 |
|
// This is quick fix of 10 chars in gsm0338 |
| 3524 |
|
// Thanks goes to Andrea Carpani who pointed on this problem |
| 3525 |
|
// and solve it ;) |
| 3526 |
|
if (($FromCharset == "gsm0338") && ($HexChar == '1B')) { |
| 3527 |
|
$i++; |
| 3528 |
|
$HexChar .= strtoupper(dechex(ord($StringToChange[$i]))); |
| 3529 |
|
} |
| 3530 |
|
// end of workarround on 10 chars from gsm0338 |
| 3531 |
|
if ($ToCharset != "utf-8") |
| 3532 |
|
{ |
| 3533 |
|
if (in_array($HexChar, $CharsetTable[$FromCharset])) |
| 3534 |
|
{ |
| 3535 |
|
$UnicodeHexChar = array_search($HexChar, $CharsetTable[$FromCharset]); |
| 3536 |
|
$UnicodeHexChars = explode("+",$UnicodeHexChar); |
| 3537 |
|
for($UnicodeHexCharElement = 0; $UnicodeHexCharElement < count($UnicodeHexChars); $UnicodeHexCharElement++) |
| 3538 |
|
{ |
| 3539 |
|
if (array_key_exists($UnicodeHexChars[$UnicodeHexCharElement], $CharsetTable[$ToCharset])) |
| 3540 |
|
{ |
| 3541 |
|
if ($this->Entities == true) |
| 3542 |
|
{ |
| 3543 |
|
$NewString .= $this->UnicodeEntity($this->HexToUtf($UnicodeHexChars[$UnicodeHexCharElement])); |
| 3544 |
|
} |
| 3545 |
|
else |
| 3546 |
|
{ |
| 3547 |
|
$NewString .= chr(hexdec($CharsetTable[$ToCharset][$UnicodeHexChars[$UnicodeHexCharElement]])); |
| 3548 |
|
} |
| 3549 |
|
} |
| 3550 |
|
else |
| 3551 |
|
{ |
| 3552 |
|
print $this->DebugOutput(0, 1, $StringToChange[$i]); |
| 3553 |
|
} |
| 3554 |
|
} //for($UnicodeH... |
| 3555 |
|
} |
| 3556 |
|
else |
| 3557 |
|
{ |
| 3558 |
|
print $this->DebugOutput(0, 2,$StringToChange[$i]); |
| 3559 |
|
} |
| 3560 |
|
} |
| 3561 |
|
else |
| 3562 |
|
{ |
| 3563 |
|
if (in_array("$HexChar", $CharsetTable[$FromCharset])) |
| 3564 |
|
{ |
| 3565 |
|
$UnicodeHexChar = array_search($HexChar, $CharsetTable[$FromCharset]); |
| 3566 |
|
/** |
| 3567 |
|
* Sometimes there are two or more utf-8 chars per one regular char. |
| 3568 |
|
* Extream, example is polish old Mazovia encoding, where one char contains |
| 3569 |
|
* two lettes 007a (z) and 0142 (l slash), we need to figure out how to |
| 3570 |
|
* solve this problem. |
| 3571 |
|
* The letters are merge with "plus" sign, there can be more than two chars. |
| 3572 |
|
* In Mazowia we have 007A+0142, but sometimes it can look like this |
| 3573 |
|
* 0x007A+0x0142+0x2034 (that string means nothing, it just shows the possibility...) |
| 3574 |
|
**/ |
| 3575 |
|
$UnicodeHexChars = explode("+",$UnicodeHexChar); |
| 3576 |
|
for($UnicodeHexCharElement = 0; $UnicodeHexCharElement < count($UnicodeHexChars); $UnicodeHexCharElement++) |
| 3577 |
|
{ |
| 3578 |
|
if ($this->Entities == true) |
| 3579 |
|
{ |
| 3580 |
|
$NewString .= $this->UnicodeEntity($this->HexToUtf($UnicodeHexChars[$UnicodeHexCharElement])); |
| 3581 |
|
} |
| 3582 |
|
else |
| 3583 |
|
{ |
| 3584 |
|
$NewString .= $this->HexToUtf($UnicodeHexChars[$UnicodeHexCharElement]); |
| 3585 |
|
} |
| 3586 |
|
} // for |
| 3587 |
|
} |
| 3588 |
|
else |
| 3589 |
|
{ |
| 3590 |
|
print $this->DebugOutput(0, 2, $StringToChange[$i]); |
| 3591 |
|
} |
| 3592 |
|
} |
| 3593 |
|
} |
| 3594 |
|
} |
| 3595 |
|
/** |
| 3596 |
|
* This is second case. We are encoding from multibyte char string. |
| 3597 |
|
**/ |
| 3598 |
|
else if($FromCharset == "utf-8") |
| 3599 |
|
{ |
| 3600 |
|
$HexChar = ""; |
| 3601 |
|
$UnicodeHexChar = ""; |
| 3602 |
|
$CharsetTable = $this->MakeConvertTable ($ToCharset); |
| 3603 |
|
foreach ($CharsetTable[$ToCharset] as $UnicodeHexChar => $HexChar) |
| 3604 |
|
{ |
| 3605 |
|
if ($this->Entities == true) { |
| 3606 |
|
$EntitieOrChar = $this->UnicodeEntity($this->HexToUtf($UnicodeHexChar)); |
| 3607 |
|
} |
| 3608 |
|
else |
| 3609 |
|
{ |
| 3610 |
|
$EntitieOrChar = chr(hexdec($HexChar)); |
| 3611 |
|
} |
| 3612 |
|
$StringToChange = str_replace($this->HexToUtf($UnicodeHexChar), $EntitieOrChar, $StringToChange); |
| 3613 |
|
} |
| 3614 |
|
$NewString = $StringToChange; |
| 3615 |
|
} |
| 3616 |
|
|
| 3617 |
|
return $NewString; |
| 3618 |
|
} |
| 3619 |
|
|
| 3620 |
|
/** |
| 3621 |
|
* ConvertCharset::DebugOutput() |
| 3622 |
|
* |
| 3623 |
|
* This function is not really necessary, the debug output could stay inside of |
| 3624 |
|
* source code but like this, it's easier to manage and translate. |
| 3625 |
|
* Besides I couldn't find good coment/debug class :-) Maybe I'll write one someday... |
| 3626 |
|
* |
| 3627 |
|
* All messages depend on DEBUG_MODE level, as I was writing before you can set this value to: |
| 3628 |
|
* - -1 - No errors or notces are shown |
| 3629 |
|
* - 0 - Only error messages are shown, no notices |
| 3630 |
|
* - 1 - Error messages and notices are shown |
| 3631 |
|
* |
| 3632 |
|
* @param int $Group Message groupe: error - 0, notice - 1 |
| 3633 |
|
* @param int $Number Following message number |
| 3634 |
|
* @param mix $Value This walue is whatever you want, usualy it's some parameter value, for better message understanding. |
| 3635 |
|
* @return string String with a proper message. |
| 3636 |
|
**/ |
| 3637 |
|
function DebugOutput ($Group, $Number, $Value = false) |
| 3638 |
|
{ |
| 3639 |
|
//$Debug [$Group][$Number] = "Message, can by with $Value"; |
| 3640 |
|
//$Group[0] - Errors |
| 3641 |
|
//$Group[1] - Notice |
| 3642 |
|
$Debug[0][0] = "Error, can NOT read file: " . $Value . "<br />"; |
| 3643 |
|
$Debug[0][1] = "Error, can't find maching char \"". $Value ."\" in destination encoding table!" . "<br />"; |
| 3644 |
|
$Debug[0][2] = "Error, can't find maching char \"". $Value ."\" in source encoding table!" . "<br />"; |
| 3645 |
|
$Debug[0][3] = "Error, you did NOT set variable " . $Value . " in Convert() function." . "<br />"; |
| 3646 |
|
$Debug[0][4] = "You can NOT convert string from " . $Value . " to " . $Value . "!" . "<br />"; |
| 3647 |
|
$Debug[1][0] = "Notice, you are trying to convert string from ". $Value ." to ". $Value .", don't you feel it's strange? ;-)" . "<br />"; |
| 3648 |
|
$Debug[1][1] = "Notice, both charsets " . $Value . " are identical! Check encoding tables files." . "<br />"; |
| 3649 |
|
$Debug[1][2] = "Notice, there is no unicode char in the string you are trying to convert." . "<br />"; |
| 3650 |
|
|
| 3651 |
|
if (DEBUG_MODE >= $Group) |
| 3652 |
|
{ |
| 3653 |
|
return $Debug[$Group][$Number]; |
| 3654 |
|
} |
| 3655 |
|
} // function DebugOutput |
| 3656 |
|
|
| 3657 |
|
} //class ends here |
| 3658 |
|
|
| 3659 |
?> |
?> |