コード例 #1
0
ファイル: show_menu.php プロジェクト: ircoco/BlackCatCMS
function Dwoo_Plugin_show_menu(Dwoo $dwoo, $aMenu = 0, $aStart = SM2_ROOT, $aMaxLevel = -1999, $aOptions = SM2_TRIM, $aItemOpen = false, $aItemClose = false, $aMenuOpen = false, $aMenuClose = false, $aTopItemOpen = false, $aTopMenuOpen = false)
{
    if (CAT_Helper_Page::isMaintenance() && !CAT_Users::is_root()) {
        return false;
    }
    if (strpos($aOptions, 'SM2_PRETTY') !== false) {
        return "<strong>Error:</strong> show_menu() does not support the SM2_PRETTY Flag!";
    }
    // Set variables to replace strings with constants
    $search_values = array('SM2_ROOT', 'SM2_CURR', 'SM2_ALLMENU', 'SM2_START', 'SM2_MAX', 'SM2_ALLINFO', 'SM2_ALL', 'SM2_TRIM', 'SM2_CRUMB', 'SM2_SIBLING', 'SM2_NUMCLASS', 'SM2_NOCACHE', 'SM2_PRETTY', 'SM2_ESCAPE', 'SM2_NOESCAPE', 'SM2_BUFFER', 'SM2_CURRTREE', 'SM2_SHOWHIDDEN', 'SM2_XHTML_STRICT', 'SM2_NO_TITLE', 'SM2_ARRAY');
    $replace_values = array(SM2_ROOT, SM2_CURR, SM2_ALLMENU, SM2_START, SM2_MAX, SM2_ALLINFO, SM2_ALL, SM2_TRIM, SM2_CRUMB, SM2_SIBLING, SM2_NUMCLASS, SM2_NOCACHE, SM2_PRETTY, SM2_ESCAPE, SM2_NOESCAPE, SM2_BUFFER, SM2_CURRTREE, SM2_SHOWHIDDEN, SM2_XHTML_STRICT, SM2_NO_TITLE, '');
    // Check if function shall return an array or the menu
    $direct_output = strpos($aOptions, 'SM2_ARRAY') === false ? true : false;
    // Check if SM2_BUFFER is set, when SM2_ARRAY is set (otherwise simply replace SM2_ARRAY with SM2_BUFFER
    $aOptions = !$direct_output && strpos($aOptions, 'SM2_BUFFER') === false ? str_replace('SM2_ARRAY', 'SM2_BUFFER', $aOptions) : $aOptions;
    // Replace all Strings with constants
    $aStart = str_replace($search_values, $replace_values, $aStart);
    $aMaxLevel = str_replace($search_values, $replace_values, $aMaxLevel);
    $aOptions = str_replace($search_values, $replace_values, $aOptions);
    // Among all constants get to bit values
    $Menu = among_constants($aMenu);
    $Start = among_constants($aStart);
    $MaxLevel = among_constants($aMaxLevel);
    $Options = among_constants($aOptions);
    if ($direct_output) {
        show_menu2($Menu, $Start, $MaxLevel, $Options, $aItemOpen, $aItemClose, $aMenuOpen, $aMenuClose, $aTopItemOpen, $aTopMenuOpen);
    } else {
        $result = show_menu2($Menu, $Start, $MaxLevel, $Options);
        $search = array('</li><li', '</a><ul', '</li></ul>', '</ul></li>', '</a></li>');
        $replace = array('</li>|<li', '</a>|<ul', '</li>|</ul>', '</ul>|</li>', '</a>|</li>');
        $result = str_replace($search, $replace, $result);
        $walk = explode('|', $result);
        $menu = array();
        $level = 0;
        foreach ($walk as $index => $item) {
            trim($item);
            if ($item == '</li>') {
                $menu[] = array('type' => 'link_end', 'level' => $level);
                continue;
            }
            if ($item == '</ul>') {
                $menu[] = array('type' => 'level_end', 'level' => $level);
                $level--;
                continue;
            }
            if (strpos($item, '<ul') !== false) {
                $ul = substr($item, 0, strpos($item, '<li'));
                $level++;
                $link = array();
                $link['type'] = 'level_start';
                $link['level'] = $level;
                preg_match_all('/([a-zA-Z]*[a-zA-Z])\\s{0,3}[=]\\s{0,3}("[^"\\r\\n]*)"/', $ul, $attr);
                foreach ($attr as $attributes) {
                    foreach ($attributes as $attribut) {
                        if (strpos($attribut, "=") !== false) {
                            list($key, $value) = explode("=", $attribut);
                            $value = trim($value);
                            $value = trim(substr($value, 1, strlen($value) - 2));
                            if (!empty($value)) {
                                $link[$key] = $value;
                            }
                        }
                    }
                }
                $menu[] = $link;
                $item = trim(substr($item, strpos($item, '<li')));
            }
            if (strpos($item, '<li') !== false) {
                $link = array();
                $link['type'] = 'link_start';
                $link['level'] = $level;
                preg_match_all('/([a-zA-Z]*[a-zA-Z])\\s{0,3}[=]\\s{0,3}("[^"\\r\\n]*)"/', $item, $attr);
                foreach ($attr as $attributes) {
                    foreach ($attributes as $attribut) {
                        if (strpos($attribut, "=") !== false) {
                            list($key, $value) = explode("=", $attribut);
                            $value = trim($value);
                            $value = trim(substr($value, 1, strlen($value) - 2));
                            $link[$key] = $value;
                        }
                    }
                }
                $link['pagename'] = pathinfo($link['href'], PATHINFO_FILENAME);
                $menu[] = $link;
            }
        }
        return $menu;
    }
    // end loop for SM2_ARRAY
}
コード例 #2
0
ファイル: Page.php プロジェクト: ircoco/BlackCatCMS
 /**
  * shows the current page
  *
  * @access public
  * @return void
  **/
 public function show()
 {
     // ----- keep old modules happy -----
     global $wb, $admin, $database, $page_id, $section_id;
     global $TEXT;
     $admin =& $wb;
     if ($page_id == '') {
         $page_id = $this->_page_id;
     }
     // ----- keep old modules happy -----
     $this->log()->LogDebug(sprintf('showing page with ID [%s]', $page_id));
     // send appropriate header
     if (CAT_Helper_Page::isMaintenance() || CAT_Registry::get('MAINTENANCE_PAGE') == $page_id) {
         header('HTTP/1.1 503 Service Temporarily Unavailable');
         header('Status: 503 Service Temporarily Unavailable');
         header('Retry-After: 7200');
         // in seconds
     }
     // template engine
     global $parser;
     // page of type menu_link
     if (CAT_Sections::isMenuLink($this->_page_id)) {
         $this->showMenuLink();
     } else {
         $do_filter = false;
         // use output filter (if any)
         if (file_exists(CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/blackcatFilter/filter.php'))) {
             include_once CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/blackcatFilter/filter.php');
             if (function_exists('executeFilters')) {
                 $this->log()->LogDebug('enabling output filters');
                 $do_filter = true;
             }
         }
         $this->setTemplate();
         // including the template; it may calls different functions
         // like page_content() etc.
         ob_start();
         require CAT_TEMPLATE_DIR . '/index.php';
         $output = ob_get_contents();
         ob_clean();
         // droplets
         CAT_Helper_Droplet::process($output);
         // output filtering
         if ($do_filter) {
             $this->log()->LogDebug('executing output filters');
             executeFilters($output);
         }
         // use HTMLPurifier to clean up the output
         if (defined('ENABLE_HTMLPURIFIER') && true === ENABLE_HTMLPURIFIER) {
             $this->log()->LogDebug('executing HTML Purifier');
             $output = CAT_Helper_Protect::purify($output);
         }
         $this->log()->LogDebug('print output');
         if (!headers_sent()) {
             $properties = self::properties($page_id);
             echo header('content-type:text/html; charset=' . (isset($properties['default_charset']) ? $properties['default_charset'] : 'utf-8'));
         }
         echo $output;
     }
 }