public static function load($tpl, $css_files = array(), $js_files = array()) { \CODOF\Util::inc_global_views(); //This sets all variables which will be used by the theme require CURR_THEME_PATH . 'theme.php'; $page = array(); \CODOF\Hook::call('before_site_head'); \CODOF\Hook::call('tpl_before_' . str_replace("/", "_", $tpl)); $asset = new \CODOF\Asset\Stream(); $page["head"]["css"] = $asset->dumpCSS(); //\CODOF\Theme\Js::sort_js(); $page["head"]["js"] = $asset->dumpJS('head'); $page["body"]["js"] = $asset->dumpJS('body'); $page["defer"] = json_encode($asset->deferred()); //after all modification its time for smarty to display the mod data $smarty = Single::get_instance(); $site_title = \CODOF\Util::get_opt('site_title'); $sub_title = \CODOF\Store::get('sub_title'); $smarty->assign('site_title', $site_title); $smarty->assign('sub_title', $sub_title); $smarty->assign('home_title', \CODOF\Store::get('home_title', _t('All topics'))); $smarty->assign('site_url', \CODOF\Util::get_opt('site_url')); $smarty->assign('logged_in', \CODOF\User\CurrentUser\CurrentUser::loggedIn()); $smarty->assign('login_url', \CODOF\User\User::getLoginUrl()); $smarty->assign('logout_url', \CODOF\User\User::getLogoutUrl()); $smarty->assign('register_url', \CODOF\User\User::getRegisterUrl()); $smarty->assign('profile_url', \CODOF\User\User::getProfileUrl()); $smarty->assign('page', $page); $smarty->assign('CSRF_token', \CODOF\Access\CSRF::get_token()); $smarty->assign('php_time_now', time()); $category = new \CODOF\Forum\Category(); $canCreateTopicInAtleastOneCategory = $category->canCreateTopicInAtleastOne(); $smarty->assign('canCreateTopicInAtleastOneCategory', $canCreateTopicInAtleastOneCategory); $page = \CODOF\Store::get('rel:canonical_page', isset($_GET['u']) ? $_GET['u'] : ''); $smarty->assign('canonical', rtrim(RURI, '/') . strip_tags($page)); if (\CODOF\Store::has('rel:prev')) { $smarty->assign('rel_prev', \CODOF\Store::get('rel:prev')); } if (\CODOF\Store::has('rel:next')) { $smarty->assign('rel_next', \CODOF\Store::get('rel:next')); } if (\CODOF\Store::has('meta:robots')) { $smarty->assign('meta_robots', \CODOF\Store::get('meta:robots')); } $og = array("type" => \CODOF\Store::get('og:type', 'website'), "title" => \CODOF\Store::get('og:title', $sub_title . ' | ' . $site_title)); if (\CODOF\Store::has('og:url')) { $og['url'] = \CODOF\Store::get('og:url'); } if (\CODOF\Store::has('og:desc')) { $og['desc'] = \CODOF\Store::get('og:desc'); } else { $og['desc'] = \CODOF\Util::get_opt('site_description'); } if (\CODOF\Store::has('og:image')) { $og['image'] = \CODOF\Store::get('og:image'); } $smarty->assign('og', $og); if (\CODOF\Store::has('article:published')) { $smarty->assign('article_published', \CODOF\Store::get('article:published')); } if (\CODOF\Store::has('article:modified')) { $smarty->assign('article_modified', \CODOF\Store::get('article:modified')); } $I = \CODOF\User\User::get(); //current user details $smarty->assign('I', $I); $smarty->assign('can_moderate_posts', $I->can('moderate posts')); if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) { $notifier = new \CODOF\Forum\Notification\Notifier(); $smarty->assign('unread_notifications', $notifier->getNoOfUnread()); } $html = $smarty->fetch("{$tpl}.tpl"); require_once SYSPATH . 'Ext/simplehtmldom/simple_html_dom.php'; $dom = new \simple_html_dom(); $dom->load($html, true, false); //let plugins modify html \CODOF\Hook::call('tpl_after_' . str_replace("/", "_", $tpl), $dom); \CODOF\Hook::call('after_site_head', $dom); echo $dom->save(); }
/** * this is called before smarty process html * you can add/remove resources like js/css here * you can also modify html using regex - but disabled * */ public function head() { $asset = new \CODOF\Asset\Stream(); $col = new \CODOF\Asset\Collection('head_col'); $col->addJS(PLUGIN_PATH . 'uni_login/assets/js/uni_login.js', array('name' => 'uni_login.js', 'type' => 'defer')); $asset->addCollection($col); add_css(PLUGIN_PATH . 'uni_login/assets/css/uni_login.css', array('name' => 'uni_login.css')); }
<?php /* Page dependent stylesheets */ $asset = new \CODOF\Asset\Stream(); $col = new \CODOF\Asset\Collection('head_col'); $col->addJS('jquery-1.10.2.min.js', array('type' => 'defer'))->addJS('fastclick.js', array('type' => 'defer'))->addJS('bootstrap.min.js', array('type' => 'defer'))->addJS('notify.js', array('type' => 'defer'))->addJS('app.js', array('type' => 'defer'))->addJS('jquery.mmenu.min.js', array('type' => 'defer'))->addJS('jquery.mmenu.dragopen.min.js', array('type' => 'defer'))->addJS('hammer.min.js', array('type' => 'defer')); $global_less = array('mixins', 'bootstrap', 'general', 'search', 'jquery.mmenu', 'jquery.mmenu.dragopen'); if ($css_files == null) { $css_files = array(); } //$css_files are page dependent less files $files = array_merge($global_less, $css_files); $path = DEF_THEME_DIR . 'less'; //Add global & page-dependent less files defined by controllers foreach ($files as $file) { $col->addCSS("{$path}/{$file}.less"); } $curr_theme_less = array('colors'); $path = CURR_THEME_PATH . 'less'; //Add custom less files foreach ($curr_theme_less as $file) { $col->addCSS("{$path}/{$file}.less"); } $asset->addCollection($col); $mycol = new \CODOF\Asset\Collection('head_mycol'); $mycol->prependURL = CURR_THEME; $mycol->addCSS("{$path}/colors.less")->addCSS("{$path}/custom.less"); $asset->addCollection($mycol); $colb = new \CODOF\Asset\Collection('head_col'); $colb->position = 'body'; $colb->addJS('handlebars-v1.1.2.js', array('type' => 'defer'));