templates/themes/blank/includes/view_helpers.php in pave-0.12.0.rc3 vs templates/themes/blank/includes/view_helpers.php in pave-0.12.0

- old
+ new

@@ -1,26 +1,45 @@ <? + function pretty_r($var, $die=true) { + echo "<pre>"; + var_dump($var); + echo "<pre>"; + if($die) { + die(); + }; + } function is_edit_mode() { global $c; - if ($c->isEditMode()) { - echo "edit-mode"; - } + return $c->isEditMode(); } function is_logged_in() { global $u; - if ($u -> isLoggedIn ()) { - echo "logged-in"; - } + return $u->isLoggedIn(); } function has_blocks($area) { global $c; return $area->getTotalBlocksInArea($c) > 0; } + function is_admin() { + $u = new User(); + $g = Group::getByName('Administrators'); + return $u->isSuperUser()||$u->inGroup($g); + } + + function current_url() { + Loader::helper('navigation'); + return NavigationHelper::getLinkToCollection(Page::getCurrentPage(), true); + } + + function page_classes($c) { + return $c->getCollectionTypeHandle() . " " . $c->getCollectionHandle() . " " . (is_admin() ? 'admin' : ''); + } + function image_tag($t, $img, $html_options = false) { $imgPath = ($t->getThemePath()) . "/images/"; if ($html_options) { $options = " alt='" . explode(".", $img, 2)[0] . "'"; foreach ($html_options as $k => $v) { @@ -28,8 +47,30 @@ } } else { $options = " alt='" . explode(".", $img, 2)[0] . "'"; }; echo "<img src='" . $imgPath . $img . "'" . $options . " />"; + } + + function page_specific_scripts($page, $t) { + $script_html = ""; + + $handle = $page->getCollectionTypeHandle(); + if (isset($handle) === true) { + $script_path = __DIR__ . "/../js/template_" . $handle . ".js"; + if (file_exists($script_path) === true) { + $script_html .= "<script src='" . $t->getThemePath() . "/js/template_" . $handle . ".js'></script>"; + } + } + + $page_name = $page->getCollectionHandle(); + if (isset($page_name) === true) { + $script_path = __DIR__ . "/../js/page_" . $page_name . ".js"; + if (file_exists($script_path) === true) { + $script_html .= "<script src='" . $t->getThemePath() . "/js/page_" . $page_name . ".js'></script>"; + } + } + + return $script_html; } ?>