Пример #1
0
 /**
  * Constructor
  *
  * @return XoopsMailerLocal
  */
 public function __construct()
 {
     parent::__construct();
     // It is supposed no need to change the charset
     $this->charSet = strtolower(XoopsLocale::getCharset());
     // You MUST specify the language code value so that the file exists: XOOPS_ROOT_PAT/class/mail/phpmailer/language/lang-["your-language-code"].php
     $this->multimailer->SetLanguage("en");
 }
 function execute()
 {
     $xoops = Xoops::getInstance();
     // use HTMLPurifier inside Protector
     //require_once $xoops->path('lib/HTMLPurifier/HTMLPurifier.auto.php');
     $config = HTMLPurifier_Config::createDefault();
     $config->set('Cache', 'SerializerPath', \XoopsBaseConfig::get('lib-path'));
     $config->set('Core', 'Encoding', XoopsLocale::getCharset());
     //$config->set('HTML', 'Doctype', 'HTML 4.01 Transitional');
     $this->purifier = new HTMLPurifier($config);
     $this->method = 'purify';
     $_POST = $this->purify_recursive($_POST);
 }
Пример #3
0
 public function __construct()
 {
     parent::__construct();
     // SMARTY_PLUGINS_DIR is initialized into parent
     $xoops = Xoops::getInstance();
     $xoops->preload()->triggerEvent('core.template.construct.start', array($this));
     $this->left_delimiter = '<{';
     $this->right_delimiter = '}>';
     $this->setTemplateDir(\XoopsBaseConfig::get('themes-path'));
     $this->setCacheDir(\XoopsBaseConfig::get('smarty-cache'));
     $this->setCompileDir(\XoopsBaseConfig::get('smarty-compile'));
     $this->compile_check = $xoops->getConfig('theme_fromfile') == 1;
     $this->setPluginsDir(\XoopsBaseConfig::get('smarty-xoops-plugins'));
     $this->addPluginsDir(SMARTY_PLUGINS_DIR);
     $this->setCompileId();
     $this->assign(array('xoops_url' => \XoopsBaseConfig::get('url'), 'xoops_rootpath' => \XoopsBaseConfig::get('root-path'), 'xoops_langcode' => XoopsLocale::getLangCode(), 'xoops_charset' => XoopsLocale::getCharset(), 'xoops_version' => \Xoops::VERSION, 'xoops_upload_url' => \XoopsBaseConfig::get('uploads-url')));
 }
Пример #4
0
 public function test__construct()
 {
     $xoops = \Xoops::getInstance();
     $this->assertSame('{', $this->object->left_delimiter);
     $this->assertSame('}', $this->object->right_delimiter);
     $this->assertTrue(in_array(\XoopsBaseConfig::get('themes-path') . DIRECTORY_SEPARATOR, $this->object->getTemplateDir()));
     $this->assertSame(\XoopsBaseConfig::get('var-path') . '/caches/smarty_cache' . DIRECTORY_SEPARATOR, $this->object->getCacheDir());
     $this->assertSame(\XoopsBaseConfig::get('var-path') . '/caches/smarty_compile' . DIRECTORY_SEPARATOR, $this->object->getCompileDir());
     $this->assertSame($xoops->getConfig('theme_fromfile') == 1, $this->object->compile_check);
     $this->assertSame(array(\XoopsBaseConfig::get('lib-path') . '/smarty/xoops_plugins' . DIRECTORY_SEPARATOR, SMARTY_DIR . 'plugins' . DS), $this->object->plugins_dir);
     $this->assertSame(\XoopsBaseConfig::get('url'), $this->object->getTemplateVars('xoops_url'));
     $this->assertSame(\XoopsBaseConfig::get('root-path'), $this->object->getTemplateVars('xoops_rootpath'));
     $this->assertSame(\XoopsLocale::getLangCode(), $this->object->getTemplateVars('xoops_langcode'));
     $this->assertSame(\XoopsLocale::getCharset(), $this->object->getTemplateVars('xoops_charset'));
     $this->assertSame(\Xoops::VERSION, $this->object->getTemplateVars('xoops_version'));
     $this->assertSame(\XoopsBaseConfig::get('uploads-url'), $this->object->getTemplateVars('xoops_upload_url'));
 }
Пример #5
0
function buildRssFeedCache($rssurl)
{
    $snoopy = new Snoopy();
    $cnt = 0;
    foreach ($rssurl as $url) {
        if ($snoopy->fetch($url)) {
            $rssdata = $snoopy->results;
            $rss2parser = new XoopsXmlRss2Parser($rssdata);
            if (false != $rss2parser->parse()) {
                $_items = $rss2parser->getItems();
                $count = count($_items);
                for ($i = 0; $i < $count; $i++) {
                    $_items[$i]['title'] = XoopsLocale::convert_encoding($_items[$i]['title'], XoopsLocale::getCharset(), 'UTF-8');
                    $_items[$i]['description'] = XoopsLocale::convert_encoding($_items[$i]['description'], XoopsLocale::getCharset(), 'UTF-8');
                    $items[(string) strtotime($_items[$i]['pubdate']) . "-" . (string) ++$cnt] = $_items[$i];
                }
            } else {
                echo $rss2parser->getErrors();
            }
        }
    }
    krsort($items);
    return $items;
}
Пример #6
0
if (function_exists('mb_http_output')) {
    mb_http_output('pass');
}
$categoryid = isset($_GET['categoryid']) ? $_GET['categoryid'] : -1;
if ($categoryid != -1) {
    /* @var $categoryObj PublisherCategory */
    $categoryObj = $publisher->getCategoryHandler()->get($categoryid);
}
header('Content-Type:text/xml; charset=' . XoopsLocale::getCharset());
$tpl = new XoopsTpl();
$tpl->caching = 2;
$tpl->cache_lifetime = 0;
$myts = MyTextSanitizer::getInstance();
if (!$tpl->isCached('module:publisher/publisher_rss.tpl')) {
    $channel_category = $publisher->getModule()->getVar('name');
    $tpl->assign('channel_charset', XoopsLocale::getCharset());
    $tpl->assign('channel_title', htmlspecialchars($xoops->getConfig('sitename'), ENT_QUOTES));
    $tpl->assign('channel_link', PUBLISHER_URL);
    $tpl->assign('channel_desc', htmlspecialchars($xoops->getConfig('slogan'), ENT_QUOTES));
    $tpl->assign('channel_lastbuild', XoopsLocale::formatTimestamp(time(), 'rss'));
    $tpl->assign('channel_webmaster', $xoops->getConfig('adminmail'));
    $tpl->assign('channel_editor', $xoops->getConfig('adminmail'));
    if ($categoryid != -1) {
        $channel_category .= " > " . $categoryObj->getVar('name');
    }
    $tpl->assign('channel_category', htmlspecialchars($channel_category));
    $tpl->assign('channel_generator', $publisher->getModule()->getVar('name'));
    $tpl->assign('channel_language', XoopsLocale::getLangCode());
    $tpl->assign('image_url', \XoopsBaseConfig::get('url') . '/images/logo.gif');
    $dimention = getimagesize(\XoopsBaseConfig::get('root-path') . '/images/logo.gif');
    if (empty($dimention[0])) {
Пример #7
0
 /**
  * Render Simple Header
  *
  * @param bool $closehead true to close the HTML head element
  *
  * @return void
  */
 public function simpleHeader($closehead = true)
 {
     $this->events()->triggerEvent('core.header.start');
     $this->theme();
     $xoopsConfigMetaFooter = $this->getConfigs();
     if (!headers_sent()) {
         header('Content-Type:text/html; charset=' . XoopsLocale::getCharset());
         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
         header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
         header('Cache-Control: no-store, no-cache, max-age=1, s-maxage=1, must-revalidate, post-check=0, pre-check=0');
         header("Pragma: no-cache");
     }
     echo "<!DOCTYPE html>\n";
     $xoops_url = \XoopsBaseConfig::get('url');
     echo '<html lang="' . XoopsLocale::getLangCode() . '">
           <head>
           <meta http-equiv="content-type" content="text/html; charset=' . XoopsLocale::getCharset() . '" />
           <meta name="robots" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_robots']) . '" />
           <meta name="keywords" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_keywords']) . '" />
           <meta name="description" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_description']) . '" />
           <meta name="rating" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_rating']) . '" />
           <meta name="author" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_author']) . '" />
           <meta name="generator" content="XOOPS" />
           <title>' . htmlspecialchars($this->getConfig('sitename')) . '</title>
           <script type="text/javascript" src="' . $xoops_url . '/include/xoops.js"></script>
           <script type="text/javascript" src="' . $xoops_url . '/media/jquery/jquery.js"></script>
           <script type="text/javascript" src="' . $xoops_url . '/media/bootstrap/js/bootstrap.min.js"></script>';
     $themecss = $this->getCss($this->getConfig('theme_set'));
     echo '<link rel="stylesheet" type="text/css" media="all" href="' . $xoops_url . '/xoops.css" />';
     $locale = $this->getConfig('locale');
     if (XoopsLoad::fileExists($this->path('locale/' . $locale . '/style.css'))) {
         echo '<link rel="stylesheet" type="text/css" media="all" href="' . $xoops_url . '/locale/' . $locale . '/style.css" />';
     }
     if ($themecss) {
         echo '<link rel="stylesheet" type="text/css" media="all" href="' . $themecss . '" />';
         echo '<link rel="stylesheet" type="text/css" media="screen" href="' . $this->url('themes/' . $this->getConfig('theme_set') . '/media/bootstrap/css/xoops.bootstrap.css') . '" />';
     }
     if ($closehead) {
         echo '</head><body>';
     }
 }
Пример #8
0
 /**
  * get language
  *
  * @return    string
  */
 function getLanguage()
 {
     if ($this->language) {
         return $this->language;
     }
     if (defined("_XOOPS_EDITOR_TINYMCE_LANGUAGE")) {
         $this->language = strtolower(constant("_XOOPS_EDITOR_TINYMCE_LANGUAGE"));
     } else {
         $this->language = str_replace('_', '-', strtolower(XoopsLocale::getLangCode()));
         if (strtolower(XoopsLocale::getCharset()) == "utf-8") {
             $this->language .= "_utf8";
         }
     }
     return $this->language;
 }
Пример #9
0
$path = '/path/to/xoops/directory';
include $path . '/mainfile.php';
if (!defined('XOOPS_ROOT_PATH')) {
    exit;
}
include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/user.php';
$op = isset($_POST['op']) && $_POST['op'] == 'dologin' ? 'dologin' : 'login';
$username = isset($_POST['username']) ? trim($_POST['username']) : '';
$password = isset($_POST['userpass']) ? trim($_POST['userpass']) : '';
if ($username == '' || $password == '') {
    $op = 'login';
}
echo '
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=' . XoopsLocale::getCharset() . '" />
    <meta http-equiv="content-language" content="' . XoopsLocale::getLangCode() . '" />
    <title>' . $xoopsConfig['sitename'] . '</title>
    <link rel="stylesheet" type="text/css" media="all" href="' . XOOPS_URL . '/xoops.css" />
';
$style = xoops_getcss($xoopsConfig['theme_set']);
if ($style == '') {
    $style = xoops_getcss($xoopsConfig['theme_set']);
}
if ($style != '') {
    echo '<link rel="stylesheet" type="text/css" media="all" href="' . $style . '" />';
}
echo '
  </head>
  <body>
';
Пример #10
0
 /**
  * @param string $source
  * @param string $language
  * @return bool
  */
 public function geshi($source, $language)
 {
     if (!@XoopsLoad::load("geshi", "framework")) {
         return false;
     }
     // Create the new XoopsGeshi object, passing relevant stuff
     // XoopsGeshi should be extending geSHi in Frameworks/geshi/xoopsgeshi.php
     $geshi = new XoopsGeshi($source, $language);
     // Enclose the code in a <div>
     $geshi->set_header_type(GESHI_HEADER_NONE);
     // Sets the proper encoding charset other than "ISO-8859-1"
     $geshi->set_encoding(XoopsLocale::getCharset());
     $geshi->set_link_target("_blank");
     // Parse the code
     $code = $geshi->parse_code();
     return $code;
 }
Пример #11
0
 /**
  * init - called by parent::_construct
  *
  * @return void
  */
 protected function init()
 {
     $this->setTemplate('module:xmf/xmf_feed.tpl');
     //$this->disableLogger();
     global $xoopsConfig;
     $this->_title = $xoopsConfig['sitename'];
     $this->_url = \XoopsBaseConfig::get('url');
     $this->_description = $xoopsConfig['slogan'];
     $this->_language = \XoopsLocale::getLangCode();
     $this->_charset = \XoopsLocale::getCharset();
     $this->_pubdate = \XoopsLocale::formatTimestamp(time(), 'short');
     $this->_lastbuild = \XoopsLocale::formatTimestamp(time(), 'D, d M Y H:i:s');
     $this->_webmaster = $xoopsConfig['adminmail'];
     $this->_editor = $xoopsConfig['adminmail'];
     $this->_generator = \Xoops::VERSION;
     $this->_copyright = 'Copyright ' . \XoopsLocale::formatTimestamp(time(), 'Y') . ' ' . $xoopsConfig['sitename'];
     $this->_image_title = $this->_title;
     $this->_image_url = \XoopsBaseConfig::get('url') . '/images/logo.gif';
     $this->_image_link = $this->_url;
 }
Пример #12
0
 /**
  * Convert special characters to HTML entities
  *
  * @param string $text string being converted
  * @param int $quote_style
  * @param string $charset character set used in conversion
  * @param bool $double_encode
  * @return string
  */
 public function htmlSpecialChars($text, $quote_style = ENT_QUOTES, $charset = null, $double_encode = true)
 {
     if (version_compare(phpversion(), '5.2.3', '>=')) {
         $text = htmlspecialchars($text, $quote_style, $charset ? $charset : (class_exists('xoopslocale', false) ? XoopsLocale::getCharset() : 'UTF-8'), $double_encode);
     } else {
         $text = htmlspecialchars($text, $quote_style);
     }
     return preg_replace(array('/&amp;/i', '/&nbsp;/i'), array('&', '&amp;nbsp;'), $text);
 }
Пример #13
0
    /**
     * Dump output
     * 
     * @param string $mode unused
     * 
     * @return string output
     */
    public function dump($mode = '')
    {
        $ret = '';
        // -------------------------------------------------------------
        $xoops = Xoops::getInstance();
        /* @var $this LoggerLegacy */
        $ret = '';
        if ($mode == 'popup') {
            $dump = $this->dump('');
            $content = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
    <meta http-equiv="content-language" content="' . XoopsLocale::getLangCode() . '" />
    <meta http-equiv="content-type" content="text/html; charset=' . XoopsLocale::getCharset() . '" />
    <title>' . $xoops->getConfig('sitename') . ' - ' . _MD_LOGGER_DEBUG . ' </title>
    <meta name="generator" content="XOOPS" />
    <link rel="stylesheet" type="text/css" media="all" href="' . $xoops->getCss($xoops->getConfig('theme_set')) . '" />
</head>
<body>' . $dump . '
    <div style="text-align:center;">
        <input class="formButton" value="' . XoopsLocale::A_CLOSE . '" type="button" onclick="javascript:window.close();" />
    </div>
';
            $ret .= '
<script type="text/javascript">
    debug_window = openWithSelfMain("about:blank", "popup", 680, 450, true);
    debug_window.document.clear();
';
            $lines = preg_split("/(\r\n|\r|\n)( *)/", $content);
            foreach ($lines as $line) {
                $ret .= "\n" . 'debug_window.document.writeln("' . str_replace(array('"', '</'), array('\\"', '<\\/'), $line) . '");';
            }
            $ret .= '
    debug_window.focus();
    debug_window.document.close();
</script>
';
        }
        $this->addExtra(_MD_LOGGER_INCLUDED_FILES, sprintf(_MD_LOGGER_FILES, count(get_included_files())));
        /*
        $included_files = get_included_files();
        foreach ($included_files as $filename) {
            $this->addExtra('files',$filename);
        }
        
        if (function_exists('memory_get_peak_usage')) {
            $this->addExtra('Peak memory',memory_get_peak_usage());
        }
        */
        $memory = 0;
        if (function_exists('memory_get_usage')) {
            $memory = memory_get_usage() . ' bytes';
        } else {
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                $out = array();
                exec('tasklist /FI "PID eq ' . getmypid() . '" /FO LIST', $out);
                if (isset($out[5])) {
                    $memory = sprintf(_MD_LOGGER_MEM_ESTIMATED, substr($out[5], strpos($out[5], ':') + 1));
                }
            }
        }
        if ($memory) {
            $this->addExtra(_MD_LOGGER_MEM_USAGE, $memory);
        }
        if (empty($mode)) {
            $views = array('errors', 'deprecated', 'queries', 'blocks', 'extra');
            $ret .= "\n<div id=\"xo-logger-output\">\n<div id='xo-logger-tabs'>\n";
            $ret .= "<a href='javascript:xoSetLoggerView(\"none\")'>" . _MD_LOGGER_NONE . "</a>\n";
            $ret .= "<a href='javascript:xoSetLoggerView(\"\")'>" . _MD_LOGGER_ALL . "</a>\n";
            foreach ($views as $view) {
                $count = count($this->{$view});
                $ret .= "<a href='javascript:xoSetLoggerView(\"{$view}\")'>" . constant('_MD_LOGGER_' . strtoupper($view)) . " ({$count})</a>\n";
            }
            $count = count($this->logstart);
            $ret .= "<a href='javascript:xoSetLoggerView(\"timers\")'>" . _MD_LOGGER_TIMERS . "({$count})</a>\n";
            $ret .= "</div>\n";
        }
        if (empty($mode) || $mode == 'errors') {
            $class = 'even';
            $ret .= '<table id="xo-logger-errors" class="outer"><thead><tr><th>' . _MD_LOGGER_ERRORS . '</th></tr></thead><tbody>';
            foreach ($this->errors as $error) {
                $ret .= "\n<tr><td class='{$class}'>";
                $ret .= $error;
                $ret .= "<br />\n</td></tr>";
                $class = $class == 'odd' ? 'even' : 'odd';
            }
            $ret .= "\n</tbody></table>\n";
        }
        if (empty($mode) || $mode == 'deprecated') {
            $class = 'even';
            $ret .= '<table id="xo-logger-deprecated" class="outer"><thead><tr><th>' . _MD_LOGGER_DEPRECATED . '</th></tr></thead><tbody>';
            foreach ($this->deprecated as $message) {
                $ret .= "\n<tr><td class='{$class}'>";
                $ret .= $message;
                $ret .= "<br />\n</td></tr>";
                $class = $class == 'odd' ? 'even' : 'odd';
            }
            $ret .= "\n</tbody></table>\n";
        }
        if (empty($mode) || $mode == 'queries') {
            $class = 'even';
            $ret .= '<table id="xo-logger-queries" class="outer"><thead><tr><th>' . _MD_LOGGER_QUERIES . '</th></tr></thead><tbody>';
            $pattern = '/\\b' . preg_quote(\XoopsBaseConfig::get('db-prefix')) . '\\_/i';
            foreach ($this->queries as $q) {
                $sql = preg_replace($pattern, '', $q['sql']);
                $query_time = isset($q['query_time']) ? sprintf('%0.6f - ', $q['query_time']) : '';
                if (isset($q['error'])) {
                    $ret .= '<tr class="' . $class . '"><td><span style="color:#ff0000;">' . $query_time . htmlentities($sql) . '<br /><strong>Error number:</strong> ' . $q['errno'] . '<br /><strong>Error message:</strong> ' . $q['error'] . '</span></td></tr>';
                } else {
                    $ret .= '<tr class="' . $class . '"><td>' . $query_time . htmlentities($sql) . '</td></tr>';
                }
                $class = $class == 'odd' ? 'even' : 'odd';
            }
            $ret .= '</tbody><tfoot><tr class="foot"><td>' . _MD_LOGGER_TOTAL . ': <span style="color:#ff0000;">' . count($this->queries) . '</span></td></tr></tfoot></table>';
        }
        if (empty($mode) || $mode == 'blocks') {
            $class = 'even';
            $ret .= '<table id="xo-logger-blocks" class="outer"><thead><tr><th>' . _MD_LOGGER_BLOCKS . '</th></tr></thead><tbody>';
            foreach ($this->blocks as $b) {
                if ($b['cached']) {
                    $ret .= '<tr><td class="' . $class . '"><strong>' . $b['name'] . ':</strong> ' . sprintf(_MD_LOGGER_CACHED, (int) $b['cachetime']) . '</td></tr>';
                } else {
                    $ret .= '<tr><td class="' . $class . '"><strong>' . $b['name'] . ':</strong> ' . _MD_LOGGER_NOT_CACHED . '</td></tr>';
                }
                $class = $class == 'odd' ? 'even' : 'odd';
            }
            $ret .= '</tbody><tfoot><tr class="foot"><td>' . _MD_LOGGER_TOTAL . ': <span style="color:#ff0000;">' . count($this->blocks) . '</span></td></tr></tfoot></table>';
        }
        if (empty($mode) || $mode == 'extra') {
            $class = 'even';
            $ret .= '<table id="xo-logger-extra" class="outer"><thead><tr><th>' . _MD_LOGGER_EXTRA . '</th></tr></thead><tbody>';
            foreach ($this->extra as $ex) {
                $ret .= '<tr><td class="' . $class . '"><strong>';
                $ret .= htmlspecialchars($ex['name']) . ':</strong> ' . htmlspecialchars($ex['msg']);
                $ret .= '</td></tr>';
                $class = $class == 'odd' ? 'even' : 'odd';
            }
            $ret .= '</tbody></table>';
        }
        if (empty($mode) || $mode == 'timers') {
            $class = 'even';
            $ret .= '<table id="xo-logger-timers" class="outer"><thead><tr><th>' . _MD_LOGGER_TIMERS . '</th></tr></thead><tbody>';
            foreach ($this->logstart as $k => $v) {
                $ret .= '<tr><td class="' . $class . '"><strong>';
                $ret .= sprintf(_MD_LOGGER_TIMETOLOAD, htmlspecialchars($k) . '</strong>', '<span style="color:#ff0000;">' . sprintf("%.03f", $this->dumpTime($k)) . '</span>');
                $ret .= '</td></tr>';
                $class = $class == 'odd' ? 'even' : 'odd';
            }
            $ret .= '</tbody></table>';
        }
        if (empty($mode)) {
            $ret .= <<<EOT
</div>
<script type="text/javascript">
    function xoLogCreateCookie(name,value,days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }
    function xoLogReadCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }
    function xoLogEraseCookie(name) {
        createCookie(name,"",-1);
    }
    function xoSetLoggerView( name ) {
        var log = document.getElementById( "xo-logger-output" );
        if ( !log ) return;
        var i, elt;
        for ( i=0; i!=log.childNodes.length; i++ ) {
            elt = log.childNodes[i];
            if ( elt.tagName && elt.tagName.toLowerCase() != 'script' && elt.id != "xo-logger-tabs" ) {
                elt.style.display = ( !name || elt.id == "xo-logger-" + name ) ? "block" : "none";
            }
        }
        xoLogCreateCookie( 'XOLOGGERVIEW', name, 1 );
    }
    xoSetLoggerView( xoLogReadCookie( 'XOLOGGERVIEW' ) );
</script>

EOT;
        }
        // -------------------------------------------------------------
        return $ret;
    }
Пример #14
0
 /**
  * @param mixed  $text
  * @param string $to
  * @param string $from
  *
  * @return string
  */
 public static function convert_encoding($text, $to = 'utf-8', $from = '')
 {
     $xoops = Xoops::getInstance();
     $xlanguage = $xoops->registry()->get('XLANGUAGE', array());
     $charset = false;
     if (isset($xlanguage['charset_base'])) {
         $charset = $xlanguage['charset_base'];
     }
     if (empty($text)) {
         return $text;
     }
     if (empty($from)) {
         $from = $charset ? $charset : XoopsLocale::getCharset();
     }
     if (empty($to) || !strcasecmp($to, $from)) {
         return $text;
     }
     if (self::isMultiByte() && function_exists('mb_convert_encoding')) {
         $converted_text = @mb_convert_encoding($text, $to, $from);
     } elseif (function_exists('iconv')) {
         $converted_text = @iconv($from, $to . "//TRANSLIT", $text);
     } elseif ('utf-8' == $to) {
         $converted_text = utf8_encode($text);
     }
     $text = empty($converted_text) ? $text : $converted_text;
     return $text;
 }
Пример #15
0
 /**
  * @param string $item
  *
  * @return string
  */
 public static function convertCharset($item)
 {
     if (XoopsLocale::getCharset() == 'UTF-8') {
         return $item;
     }
     if (XoopsLocale::getCharset() != 'windows-1256') {
         return utf8_encode($item);
     }
     if ($unserialize = unserialize($item)) {
         foreach ($unserialize as $key => $value) {
             $unserialize[$key] = @iconv('windows-1256', 'UTF-8', $value);
         }
         $serialize = serialize($unserialize);
         return $serialize;
     } else {
         return @iconv('windows-1256', 'UTF-8', $item);
     }
 }