function smarty_function_cms_set_language($params, &$template)
{
    $lang = null;
    if (isset($params['lang'])) {
        $lang = trim($params['lang']);
    }
    $res = CmsNlsOperations::set_language($lang);
}
function smarty_function_cms_get_language($params, &$template)
{
    $smarty = $template->smarty;
    $lang = CmsNlsOperations::get_current_language();
    if (isset($params['assign'])) {
        $smarty->assign(trim($params['assign']), $lang);
        return;
    }
    return $lang;
}
Пример #3
0
function smarty_function_cms_lang_info($params, &$template)
{
    $smarty = $template->smarty;
    $lang = CmsNlsOperations::get_current_language();
    if (isset($params['lang'])) {
        $lang = trim($params['lang']);
    }
    $info = CmsNlsOperations::get_language_info($lang);
    if (!$info) {
        return;
    }
    if (isset($params['assign'])) {
        $smarty->assign($params['assign'], $info);
        return;
    }
    return $info;
}
Пример #4
0
 public function postprocess($html)
 {
     $smarty = cmsms()->GetSmarty();
     $otd = $smarty->template_dir;
     $smarty->template_dir = dirname(__FILE__) . '/templates';
     $module_help_type = $this->get_value('module_help_type');
     // get a page title
     $title = $this->get_value('pagetitle');
     $alias = $this->get_value('pagetitle');
     if ($title) {
         if (!$module_help_type) {
             // if not doing module help, translate the string.
             $extra = $this->get_value('extra_lang_params');
             if (!$extra) {
                 $extra = array();
             }
             $title = lang($title, $extra);
         }
     } else {
         // no title, get one from the breadcrumbs.
         $bc = $this->get_breadcrumbs();
         if (is_array($bc) && count($bc)) {
             $title = $bc[count($bc) - 1]['title'];
         }
     }
     // page title and alias
     $smarty->assign('pagetitle', $title);
     $smarty->assign('pagealias', munge_string_to_url($alias));
     // module name?
     if ($module_name = $this->get_value('module_name')) {
         $smarty->assign('module_name', $module_name);
     }
     // module icon?
     if ($module_icon_url = $this->get_value('module_icon_url')) {
         $smarty->assign('module_icon_url', $module_icon_url);
     }
     // module_help_url
     if (!get_preference(get_userid(), 'hide_help_links', 0)) {
         if ($module_help_url = $this->get_value('module_help_url')) {
             $smarty->assign('module_help_url', $module_help_url);
         }
     }
     // if bookmarks
     if (get_preference(get_userid(), 'bookmarks')) {
         $marks = $this->get_bookmarks();
         $smarty->assign('marks', $marks);
     }
     $headtext = $this->get_value('headertext');
     $smarty->assign('headertext', $headtext);
     // and some other common variables,.
     $smarty->assign('content', str_replace('</body></html>', '', $html));
     $smarty->assign('config', cmsms()->GetConfig());
     $smarty->assign('theme', $this);
     $smarty->assign('secureparam', CMS_SECURE_PARAM_NAME . '=' . $_SESSION[CMS_USER_KEY]);
     $userops = cmsms()->GetUserOperations();
     $smarty->assign('user', $userops->LoadUserByID(get_userid()));
     // get user selected language
     $smarty->assign('lang', get_preference(get_userid(), 'default_cms_language'));
     // get language direction
     $lang = CmsNlsOperations::get_current_language();
     $info = CmsNlsOperations::get_language_info($lang);
     $smarty->assign('lang_dir', $info->direction());
     if (is_array($this->_errors) && count($this->_errors)) {
         $smarty->assign('errors', $this->_errors);
     }
     if (is_array($this->_messages) && count($this->_messages)) {
         $smarty->assign('messages', $this->_messages);
     }
     $_contents = $smarty->fetch('pagetemplate.tpl');
     $smarty->template_dir = $otd;
     return $_contents;
 }
Пример #5
0
 cmsms()->set_variable('page_id', $page);
 cmsms()->set_variable('page_name', $contentobj->Alias());
 cmsms()->set_variable('position', $contentobj->Hierarchy());
 cmsms()->set_variable('friendly_position', $contentops->CreateFriendlyHierarchyPosition($contentobj->Hierarchy()));
 $smarty->assign('content_obj', $contentobj);
 $smarty->assign('content_id', $contentobj->Id());
 $smarty->assign('page', $page);
 $smarty->assign('page_id', $page);
 $smarty->assign('page_name', $contentobj->Alias());
 $smarty->assign('page_alias', $contentobj->Alias());
 $smarty->assign('position', $contentobj->Hierarchy());
 $smarty->assign('friendly_position', $gCms->variables['friendly_position']);
 CmsNlsOperations::set_language();
 // <- NLS detection for frontend
 $smarty->assign('lang', CmsNlsOperations::get_current_language());
 $smarty->assign('encoding', CmsNlsOperations::get_encoding());
 $html = '';
 $showtemplate = true;
 if (isset($_REQUEST['showtemplate']) && $_REQUEST['showtemplate'] == 'false' || isset($smarty->id) && $smarty->id != '' && isset($_REQUEST[$smarty->id . 'showtemplate']) && $_REQUEST[$smarty->id . 'showtemplate'] == 'false') {
     $showtemplate = false;
 }
 $smarty->set_global_cacheid('p' . $contentobj->Id());
 $uid = get_userid(FALSE);
 if ($contentobj->Cachable() && $showtemplate && !$uid && get_site_preference('use_smartycache', 0)) {
     if (version_compare(phpversion(), '5.3') >= 0) {
         // this content is cachable...  so enable smarty caching of this page data, for this user.
         $smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
     }
 }
 if (!$showtemplate) {
     $smarty->setCaching(false);
Пример #6
0
                cms_cookies::set("cms_language", $_POST["change_cms_lang"]);
            }
        }
    } else {
        if (isset($_SESSION['login_cms_language'])) {
            debug_buffer('Setting language to: ' . $_SESSION['login_cms_language']);
            $current_language = $_SESSION['login_cms_language'];
            cms_cookies::set('cms_language', $_SESSION['login_cms_language']);
            unset($_SESSION['login_cms_language']);
        } else {
            if (isset($_COOKIE["cms_language"])) {
                $current_language = $_COOKIE["cms_language"];
            }
        }
    }
    #First load the english one so that we have strings to fall back on
    $base_lang = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR;
    @(include $base_lang . 'en_US.php');
    #Now load the real file
    if ($current_language != 'en_US') {
        $file = $base_lang . 'ext' . DIRECTORY_SEPARATOR . $current_language . '.php';
        if (!is_file($file)) {
            $file = $base_lang . $current_language . '.php';
        }
        if (is_file($file) && strlen($current_language) == 5 && strpos($current_language, ".") === false) {
            include $file;
        }
    }
    $info = CmsNlsOperations::set_language($current_language);
}
# vim:ts=4 sw=4 noet
Пример #7
0
            // put mention into the admin log
            $ip_login_failed = cms_utils::get_real_ip();
            if ($ip_login_failed) {
                // <- Silently ignore audit if return values is not ture, had admin XSS vulne.
                audit('', '(IP: ' . $ip_login_failed . ') ' . "Admin Username: "******"loginsubmit"]);
        }
    }
}
// Language shizzle
cms_admin_sendheaders();
header("Content-Language: " . CmsNlsOperations::get_current_language());
//CHANGED
debug_buffer('debug is:' . $error);
$themeObject = cms_utils::get_theme_object();
$vars = array('error' => $error);
if (isset($warningLogin)) {
    $vars['warningLogin'] = $warningLogin;
}
if (isset($acceptLogin)) {
    $vars['acceptLogin'] = $acceptLogin;
}
if (isset($changepwhash)) {
    $vars['changepwhash'] = $changepwhash;
}
$themeObject->do_login($vars);
?>
Пример #8
0
 /**
  * Test to see if a language key exists in the current lang file.
  * This function uses the current language.
  *
  * @param string The language key
  * @return boolean
  */
 public static function key_exists($key)
 {
     self::_load_realm('admin');
     $curlang = CmsNlsOperations::get_current_language();
     if (isset(self::$_langdata[$curlang]['admin'][$key])) {
         return TRUE;
     }
     return FALSE;
 }
Пример #9
0
  cmsms()->set_variable('pageinfo',new PageInfo());
  $contentops = cmsms()->GetContentOperations();
  $contentops->register_routes();
  debug_buffer('','End of Loading Routes');
}
*/
#Load all installed module code
if (!isset($CMS_INSTALL_PAGE)) {
    debug_buffer('', 'Loading Modules');
    $modops = cmsms()->GetModuleOperations();
    $modops->LoadModules(isset($LOAD_ALL_MODULES), !isset($CMS_ADMIN_PAGE));
    debug_buffer('', 'End of Loading Modules');
}
#Setup language stuff.... will auto-detect languages (Launch only to admin at this point)
if (isset($CMS_ADMIN_PAGE)) {
    CmsNlsOperations::set_language();
}
$CMS_LAZYLOAD_MODULES = 1;
// still used ??
#Do auto task stuff.
if (!isset($CMS_INSTALL_PAGE)) {
    CmsRegularTaskHandler::handle_tasks();
}
$smarty->assign('sitename', get_site_preference('sitename', 'CMSMS Site'));
function sanitize_input_array(&$value, $key)
{
    $value = preg_replace('/\\<\\/?script[^\\>]*\\>/i', '', $value);
    //the i makes it caseinsensitive
    $value = preg_replace('/javascript\\:/i', '', $value);
    //the i makes it caseinsensitive
}
Пример #10
0
 /**
  * Convert a unix timestamp to a locale specific format
  * (currently only support US and non US).
  *
  * @param int $ts The unix timestamp
  * @param bool $time_too Wether or not to include time in the output string
  * @param string $sep The separator between fields.  Default is '/'
  * @return string
  */
 public static function to_locale_str($ts, $time_too = TRUE, $sep = '/')
 {
     $lang = CmsNlsOperations::get_current_language();
     $fmt = "%d{$sep}%m{$sep}%Y";
     if ($lang == 'en_US') {
         $fmt = "%m{$sep}%d{$sep}%Y";
     }
     if ($time_too) {
         $fmt .= " %T";
     }
     return strftime($fmt, $ts);
 }
Пример #11
0
                    $errors[] = lang('errordeletingdirectory');
                } else {
                    // put mention into the admin log
                    audit(-1, 'Directory: ' . $reldir . "/" . $_GET['file'], 'Deleted');
                }
            } else {
                $errors[] = lang('norealdirectory');
            }
        } else {
            $errors[] = lang('needpermissionto', array('Modify Files'));
        }
    }
}
include_once "header.php";
$current_language = CmsNlsOperations::get_current_language();
$langinfo = CmsNlsOperations::get_language_info($current_language);
?>

<script type="text/javascript" src="../lib/filemanager/ImageManager/assets/dialog.js"></script>
<script type="text/javascript" src="../lib/filemanager/ImageManager/IMEStandalone.js"></script>
<script type="text/javascript" src="../lib/filemanager/ImageManager/lang/<?php 
echo $langinfo->htmlarea();
?>
.js"></script>
<script type="text/javascript">
//<![CDATA[
//Create a new Image Manager, needs the directory where the manager is
//and which language translation to use.
var manager = new ImageManager('../lib/filemanager/ImageManager','en');
var thumbdir = "<?php 
echo $IMConfig['thumbnail_dir'];
Пример #12
0
                 $header .= '<span class="helptext"><a href="listmodules.php?' . CMS_SECURE_PARAM_NAME . '=' . $_SESSION[CMS_USER_KEY] . '&amp;action=showmodulehelp&amp;module=' . $module . '&amp;lang=en_US">' . lang('modulehelp_english') . '</a></span>';
             }
         }
         $header .= '</div>';
         echo $header;
         // this is ugly hacky stuff to ajust the language temporarily.
         $mod_old_lang = $modinstance->curlang;
         $modinstance->params = array(array('name' => 'lang', 'default' => 'en_US', 'optional' => true));
         if (isset($_GET['lang'])) {
             $modinstance->curlang = trim($_GET['lang']);
         }
         echo @$modinstance->GetHelpPage();
         $modinstance->params = array(array('name' => 'lang', 'default' => 'en_US', 'optional' => true));
         $modinstance->curlang = $mod_old_lang;
         echo "</div>";
         CmsNlsOperations::set_language($orig_lang);
     }
     echo '<p class="pageback"><a class="pageback" href="' . $thisurl . '">&#171; ' . lang('back') . '</a></p>';
 } else {
     if ($action == 'missingdeps') {
         echo '<div class="pagecontainer">';
         echo '<p class="pageheader">' . lang('depsformodule', array($module)) . '</p>';
         echo '<table cellspacing="0" class="AdminTable">';
         echo '<thead>';
         echo '<tr><th>' . lang('name') . '</th><th>' . lang('minimumversion') . '</th><th>' . lang('installed') . '</th></tr>';
         echo '</thead>';
         echo '<tbody>';
         $modinstance = $modops->get_module_instance($module, '', true);
         if (is_object($modinstance)) {
             if (count($modinstance->GetDependencies()) > 0) {
                 $curclass = 'row1';
Пример #13
0
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#$Id: style.php 8272 2012-08-28 17:35:32Z calguy1000 $
$CMS_ADMIN_PAGE = TRUE;
$CMS_STYLESHEET = TRUE;
require_once "../include.php";
$themeObject = cms_utils::get_theme_object();
$theme = $themeObject->themeName;
$style = "style";
cms_admin_sendheaders('text/css');
$thelang = CmsNlsOperations::get_language_info(CmsNlsOperations::get_current_language());
if (is_object($thelang) && $thelang->direction() == 'rtl') {
    $style .= "-rtl";
}
if (isset($_GET['ie'])) {
    $style .= "_ie";
}
$style .= ".css";
if (file_exists(dirname(__FILE__) . "/themes/" . $theme . "/css/" . $style)) {
    cms_readfile(dirname(__FILE__) . "/themes/" . $theme . "/css/" . $style);
}
if (file_exists(dirname(__FILE__) . "/themes/" . $theme . "/extcss/" . $style)) {
    cms_readfile(dirname(__FILE__) . "/themes/" . $theme . "/extcss/" . $style);
}
// else if (file_exists(dirname(__FILE__)."/themes/default/css/".$style))
//   {
Пример #14
0
 /**
  * Used to allow third party software to override the language detection mechanism for frontend requests
  * the module can provide an object derived from CmsLanguageDetector to this method.
  *
  * Note, this module must return a language for which there is an available NLS file.
  *
  * @param CmsLanguageDetector Object containing methods to detect a compatible, desired language
  * @return void
  */
 public static function set_language_detector(CmsLanguageDetector &$obj)
 {
     if (is_object(self::$_fe_language_detector)) {
         die('language detector already set');
     }
     self::$_fe_language_detector = $obj;
 }
Пример #15
0
function get_language_list($allow_none = true)
{
    $tmp = array();
    if ($allow_none) {
        $tmp = array('' => lang('nodefault'));
    }
    $langs = CmsNlsOperations::get_installed_languages();
    asort($langs);
    foreach ($langs as $key) {
        $obj = CmsNlsOperations::get_language_info($key);
        $value = $obj->display();
        if ($obj->fullname()) {
            $value .= ' (' . $obj->fullname() . ')';
        }
        $tmp[$key] = $value;
    }
    return $tmp;
}
Пример #16
0
 /**
  * Render the output javascript and stylesheets into cachable files
  * and output the appropriate HTML tags.
  *
  * @param array $opts Options for this method (for further reference, see the {cgjs_render} smarty tag.
  * @return string HTML output code.
  */
 public static function render($opts = null)
 {
     if (count(self::$_rlibs) == 0 && count(self::$_required) == 0) {
         return;
     }
     // nothing to do.
     // process options
     $options = array();
     $options['excludes'] = array();
     if (!cmsms()->is_frontend_request()) {
         // the cmsms admin console includes versions of these.
         $excludes = array();
         $excludes[] = 'jquery';
         $excludes[] = 'ui';
         $excludes[] = 'fileupload';
         $options['excludes'] = $excludes;
     }
     if (is_array($opts)) {
         $options = array_merge_recursive($options, $opts);
     }
     if (isset($options['no_jquery']) && !in_array('jquery', $options['excludes'])) {
         $options['excludes'][] = 'jquery';
     }
     if (isset($options['excludes']) && count($options['excludes'])) {
         // clean up the excludes
         $out = array();
         foreach ($options['excludes'] as &$str) {
             $str = strtolower(trim($str));
             if (!$str) {
                 continue;
             }
             if (!in_array($str, $out)) {
                 $out[] = $str;
             }
         }
         $options['excludes'] = $out;
     }
     $options['lang'] = \CmsNlsOperations::get_current_language();
     // expand some options to simple variables.
     $config = \cms_config::get_instance();
     $cache_lifetime = isset($options['cache_lifetime']) ? (int) $options['cache_lifetime'] : 24;
     $cache_lifetime = (int) \cge_utils::get_param($config, 'cgejs_cachelife', $cache_lifetime);
     $cache_lifetime = max($cache_lifetime, 1);
     $nocache = isset($options['no_cache']) ? TRUE : FALSE;
     $nocache = \cge_utils::get_param($config, 'cgejs_nocache', $nocache);
     $nominify = isset($options['nominify']) ? TRUE : FALSE;
     // overrides anything in libs.
     $nominify = \cge_utils::get_param($config, 'cgejs_nominify', $nominify);
     $nocsssmarty = isset($options['nocsssmarty']) || $nominify ? TRUE : $nocache;
     $addkey = \cge_utils::get_param($options, 'addkey', '');
     $do_js = isset($options['no_js']) ? FALSE : TRUE;
     $do_css = isset($options['no_css']) ? FALSE : TRUE;
     $js_fmt = '<script type="text/javascript" src="%s"></script>';
     $css_fmt = '<link type="text/css" rel="stylesheet" href="%s"/>';
     if ($nocache) {
         $nominify = true;
     }
     if (!$nominify) {
         require_once dirname(__DIR__) . '/jsmin.php';
     }
     $get_relative_url = function ($filename) {
         $config = \cms_config::get_instance();
         $relative_url = '';
         if (startswith($filename, $config['root_path'])) {
             $relative_url = str_replace($config['root_path'], $config['root_url'], dirname($filename));
             if (!endswith($relative_url, '/')) {
                 $relative_url .= '/';
             }
             if (startswith($relative_url, 'http:')) {
                 $relative_url = substr($relative_url, 5);
             }
             if (startswith($relative_url, 'https:')) {
                 $relative_url = substr($relative_url, 6);
             }
         }
         return $relative_url;
     };
     $fix_css_urls = function ($css, $url_prefix) {
         $css_search = '#url\\(\\s*[\'"]?(.*?)[\'"]?\\s*\\)#';
         $css_url_fix = function ($matches) use($url_prefix) {
             if (startswith($matches[1], 'data:')) {
                 return $matches[0];
             }
             if (startswith($matches[1], 'http:')) {
                 return $matches[0];
             }
             if (startswith($matches[1], 'https:')) {
                 return $matches[0];
             }
             if (startswith($matches[1], '//')) {
                 return $matches[0];
             }
             //$str = substr($matches[1],0,-1);
             $str = $matches[1];
             return "url('{$url_prefix}{$str}')";
         };
         $out = preg_replace_callback($css_search, $css_url_fix, $css);
         return $out;
     };
     $get_code = function ($rec, $type) use(&$get_relative_url, &$fix_css_urls) {
         $config = \cms_config::get_instance();
         if ($type == "js") {
             $js = null;
             if (isset($rec->jsfile)) {
                 $jsfile = $rec->jsfile;
                 if (!is_array($jsfile)) {
                     $jsfile = array($jsfile);
                 }
                 $js = null;
                 foreach ($jsfile as $one_file) {
                     $one_file = self::_expand_filename($one_file);
                     $js .= "/* jsloader // javascript file {$one_file} */\n";
                     if (is_file($one_file)) {
                         $js .= @file_get_contents($one_file);
                     }
                 }
             } else {
                 if (isset($rec->jsurl)) {
                     // cache this for at least 24 hours
                     if (startswith($rec->jsurl, $config['root_url'])) {
                         $fn = str_replace($config['root_url'], $config['root_path'], $rec->jsurl);
                         if (is_file($fn)) {
                             if (!endswith($js, "\n")) {
                                 $js .= "\n";
                             }
                             $js .= "/* jsloader // javascript local file from url {$fn} */\n";
                             $js .= file_get_contents($fn);
                         }
                     } else {
                         $crf = new \cge_cached_remote_file($rec->jsurl, 48 * 60);
                         if ($crf->size()) {
                             if (!endswith($js, "\n")) {
                                 $js .= "\n";
                             }
                             $js .= "/* jsloader // javascript remote {$rec->jsurl} */\n";
                             $js .= $crf->file_get_contents();
                         }
                     }
                 } else {
                     if (isset($rec->code)) {
                         $js .= "/* jsloader // javascript inline code */\n";
                         $js .= $rec->code;
                     }
                 }
             }
             return $js;
         } else {
             // css
             $css = null;
             if (isset($rec->cssfile)) {
                 $cssfile = $rec->cssfile;
                 if (!is_array($cssfile)) {
                     $cssfile = array($cssfile);
                 }
                 foreach ($cssfile as $one_file) {
                     $one_file = self::_expand_filename($one_file);
                     $tmp = file_get_contents($one_file);
                     $css .= "/* jsloader//css file: {$one_file} */\n";
                     $relative_url = $get_relative_url($one_file);
                     $tmp = $fix_css_urls($tmp, $relative_url);
                     $css .= $tmp;
                 }
             } else {
                 if (isset($rec->cssname)) {
                     if (version_compare(CMS_VERSION, '1.99-alpha0') < 0) {
                         $query = 'SELECT css_id, css_name, css_text FROM ' . cms_db_prefix() . 'css WHERE css_name = ?';
                         $db = CmsApp::get_instance()->GetDb();
                         $row = $db->GetRow($query, array($rec->cssname));
                         if (!is_array($row)) {
                             return;
                         }
                         $css = trim($row['css_text']);
                     } else {
                         $css = CmsLayoutStylesheet::load($rec->cssname)->get_content();
                     }
                 } else {
                     if (isset($rec->cssurl)) {
                         if (startswith($rec->cssurl, $config['root_url'])) {
                             $fn = str_replace($config['root_url'], $config['root_path'], $rec->cssurl);
                             if (is_file($fn)) {
                                 $relative_url = $get_relative_url($fn);
                                 $tmp .= file_get_contents($fn);
                                 $tmp = $fix_css_urls($tmp, $relative_url);
                                 if (!endswith($css, "\n")) {
                                     $css .= "\n";
                                 }
                                 $css .= "/* jsloader //css local file from url {$fn} */\n";
                                 $css .= $tmp;
                             }
                         } else {
                             $crf = new \cge_cached_remote_file($rec->cssurl, 48 * 60);
                             if ($crf->size()) {
                                 if (!endswith($css, "\n")) {
                                     $css .= "\n";
                                 }
                                 $css .= "/* jsloader//css remote {$rec->cssurl} */\n";
                                 $css .= $crf->file_get_contents();
                             }
                         }
                     } else {
                         if (isset($rec->styles)) {
                             $css .= "/* jsloader//css inline code */\n";
                             $css .= $rec->styles;
                         }
                     }
                 }
             }
             return $css;
         }
     };
     $get_minified_code = function ($rec, $type) use(&$get_code) {
         /* check for a cached version of this code */
         $fn = TMP_CACHE_LOCATION . '/cgejs_' . md5(__FILE__ . serialize($rec) . $type) . '.cache';
         if (is_file($fn)) {
             return file_get_contents($fn);
         }
         // not in cache
         // calculate a prefix to go on top of the cache file, and test if we are really minifying
         $code = $prefix = null;
         $do_minify = TRUE;
         if ($type == 'js') {
             if (isset($rec->js_nominify) && $rec->js_nominify) {
                 $do_minify = FALSE;
             }
             if ($do_minify && isset($rec->jsfile)) {
                 $jsfile = $rec->jsfile;
                 if (!is_array($jsfile)) {
                     $jsfile = array($jsfile);
                 }
                 foreach ($jsfile as $one) {
                     if (strpos($one, '.min') !== FALSE || strpos($one, '.pack') !== FALSE) {
                         $do_minify = FALSE;
                         break;
                     }
                 }
             }
             if ($do_minify && isset($rec->jsurl)) {
                 if (strpos($rec->jsurl, '.min') !== FALSE || strpos($rec->jsurl, '.pack') !== FALSE) {
                     $do_minify = FALSE;
                 }
             }
             $prefix = "/* jsloader // cached javascript // ";
             if (isset($rec->name)) {
                 $prefix .= $rec->name;
             } else {
                 if (isset($rec->jsfile)) {
                     if (is_string($rec->jsfile)) {
                         $prefix .= $rec->jsfile;
                     } else {
                         $prefix .= $rec->jsfile[0];
                     }
                 } else {
                     if (isset($rec->code)) {
                         $prefix .= 'inline code';
                     }
                 }
             }
             $prefix .= " */\n";
         } else {
             // CSS
             if (isset($rec->css_nominify) && $rec->css_nominify) {
                 $do_minify = FALSE;
             }
             if ($do_minify && isset($rec->cssfile)) {
                 $cssfile = $rec->cssfile;
                 if (!is_array($cssfile)) {
                     $cssfile = array($cssfile);
                 }
                 foreach ($cssfile as $one) {
                     if (strpos($one, '.min') !== FALSE || strpos($one, '.pack') !== FALSE) {
                         $do_minify = FALSE;
                         break;
                     }
                 }
             }
             if ($do_minify && isset($rec->cssurl)) {
                 if (strpos($rec->cssurl, '.min') !== FALSE || strpos($rec->cssurl, '.pack') !== FALSE) {
                     $do_minify = FALSE;
                 }
             }
             $prefix = "/* jsloader // cached css // ";
             if (isset($rec->name)) {
                 $prefix .= $rec->name;
             } else {
                 if (isset($rec->cssfile)) {
                     if (is_string($rec->cssfile)) {
                         $prefix .= $rec->cssfile;
                     } else {
                         $prefix .= $rec->cssfile[0];
                     }
                 } else {
                     $prefix .= 'inline code';
                 }
             }
             $prefix .= " */\n";
         }
         // get the code.
         $code = $get_code($rec, $type);
         if ($code) {
             // got code... are we minifying and caching it?
             if ($do_minify) {
                 $code = \JSMin::minify($code);
                 $code = $prefix . $code;
                 file_put_contents($fn, $code);
             }
             return $code;
         }
     };
     // determine if we have to process all this cruft (which could potentially be very expensive)
     $sig = md5(serialize(self::$_rlibs) . serialize(self::$_required) . serialize($options) . $nocache . $nominify . $cache_lifetime);
     $cache_js = TMP_CACHE_LOCATION . "/cgejs_{$sig}.js";
     $cache_css = TMP_CACHE_LOCATION . "/cgejs_{$sig}.css";
     $do_js_tag = $do_css_tag = FALSE;
     $do_js2 = $do_css2 = FALSE;
     $do_processing = TRUE;
     if ($nocache) {
         // forced to rejenerate.
         $do_js2 = $do_css2 = TRUE;
     } else {
         /* we can cache */
         $etime = time() - $cache_lifetime * 3600;
         if (is_file($cache_js)) {
             $mtime1 = @filemtime($cache_js);
             $do_js_tag = TRUE;
             if ($mtime1 < $etime) {
                 // cache too olo, forced to rebuild
                 $do_js2 = FALSE;
             }
         } else {
             // no file, gotta process.
             $do_js2 = TRUE;
         }
         if (is_file($cache_css)) {
             $mtime2 = @filemtime($cache_css);
             $do_css_tag = TRUE;
             if ($mtime2 < $etime) {
                 // cache too old, forced to rebuild
                 $do_css2 = FALSE;
             }
         } else {
             // no file, gotta process.
             $do_css2 = TRUE;
         }
     }
     if ($do_js2 || $do_css2) {
         // okay, we have work to do.
         static $list = null;
         if (is_null($list)) {
             // now expand all our dependencies.
             $list_0 = array();
             $required = array_merge(self::$_rlibs, self::$_required);
             foreach ($required as $rec) {
                 if (isset($rec->depends)) {
                     self::_resolve_dependencies($rec, $list_0, $options['excludes']);
                 } else {
                     $sig = md5(serialize($rec));
                     $list_0[$sig] = $rec;
                 }
             }
             // now check for callback items
             // and get their code... this may be an expensive process
             // note: may also have dependencies
             $list = array();
             foreach ($list_0 as $rec) {
                 if (isset($rec->callback)) {
                     $tmp = call_user_func($rec->callback, $rec->name);
                     if (is_object($tmp) && (isset($tmp->code) || isset($tmp->styles))) {
                         $list[] = $tmp;
                     }
                 } else {
                     $list[] = $rec;
                 }
             }
             unset($required, $list_0);
         }
         //
         // process js
         //
         if ($do_js && $do_js2 && $list && count($list)) {
             $txt = null;
             foreach ($list as $rec) {
                 if ($nominify) {
                     $txt .= $get_code($rec, 'js');
                 } else {
                     $txt .= $get_minified_code($rec, 'js');
                 }
             }
             if ($txt) {
                 $do_js_tag = TRUE;
                 file_put_contents($cache_js, $txt);
             }
         }
         //
         // process css
         //
         if ($do_css && $do_css2 && $list && count($list)) {
             $txt = null;
             foreach ($list as $rec) {
                 if ($nominify) {
                     $txt .= $get_code($rec, 'css');
                 } else {
                     $txt .= $get_minified_code($rec, 'css');
                 }
             }
             if ($txt) {
                 $do_css_tag = TRUE;
                 file_put_contents($cache_css, $txt);
             }
         }
         // do_css
     }
     // do processing
     // do the output.
     if ($nocache) {
         $cache_js .= '?_t=' . time();
         $cache_css .= '?_t=' . time();
     }
     $out = null;
     if ($do_js_tag) {
         $cache_url = $config['root_url'] . '/tmp/cache/' . basename($cache_js);
         $out .= trim(sprintf($js_fmt, $cache_url)) . "\n";
     }
     if ($do_css_tag) {
         $cache_url = $config['root_url'] . '/tmp/cache/' . basename($cache_css);
         $out .= trim(sprintf($css_fmt, $cache_url)) . "\n";
     }
     // all freaking done
     return $out;
 }
Пример #17
0
 /**
  * DisplayHTMLStartTag
  * Outputs the html open tag. Override at your own risk :)
  */
 function DisplayHTMLStartTag()
 {
     $info = CmsNlsOperations::get_language_info(CmsNlsOperations::get_current_language());
     echo $info->direction() == 'rtl' ? "<html dir=\"rtl\"\n>" : "<html>\n";
 }
 /**
 ProcessTemplate:
 @mod: reference to current StripeGate module object
 @tplname: template identifier
 @tplvars: associative array of template variables
 @cache: optional boolean, default TRUE
 Returns: string, processed template
 */
 public static function ProcessTemplate(&$mod, $tplname, $tplvars, $cache = TRUE)
 {
     global $smarty;
     if ($mod->before20) {
         $smarty->assign($tplvars);
         return $mod->ProcessTemplate($tplname);
     } else {
         if ($cache) {
             $cache_id = md5('sgt' . $tplname . serialize(array_keys($tplvars)));
             $lang = CmsNlsOperations::get_current_language();
             $compile_id = md5('sgt' . $tplname . $lang);
             $tpl = $smarty->CreateTemplate($mod->GetFileResource($tplname), $cache_id, $compile_id, $smarty);
             if (!$tpl->isCached()) {
                 $tpl->assign($tplvars);
             }
         } else {
             $tpl = $smarty->CreateTemplate($mod->GetFileResource($tplname), NULL, NULL, $smarty, $tplvars);
         }
         return $tpl->fetch();
     }
 }