This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 
<?php

defined('C5_EXECUTE') or die("Access Denied.");
class ConcreteInterfaceMenuHelper {

    protected $pageHeaderMenuItems = array();
    
    /** 
     * Adds a menu item to the header menu area 
     * <code>
     *  $bh->addMenuItem($menuItemID, $menuItemName, $positionInMenu, $linkAttributes, $pkgHandle = false);
     * </code>
     */
    public function addPageHeaderMenuItem($menuItemID, $menuItemName, $positionInMenu, $linkAttributes, $pkgHandle = false) {
        $obj = new ConcreteInterfaceHelperMenuItem($menuItemID, $menuItemName, $positionInMenu, $linkAttributes, $pkgHandle);
        $this->pageHeaderMenuItems[] = $obj;
    }
    
    /** 
     * Returns current menu items
     */
    public function getPageHeaderMenuItems($position = false) {
        if ($position) {
            $tmpItems = array();
            foreach($this->pageHeaderMenuItems as $mi) {
                if ($mi->getPosition() == $position) {
                    $tmpItems[] = $mi;
                }
            }
            return $tmpItems;
        } else {
            return $this->pageHeaderMenuItems;
        }
    }

}

class ConcreteInterfaceHelperMenuItem {

    public function __construct($handle, $name, $position, $linkAttributes, $pkgHandle = false) {
        $this->handle = $handle;
        $this->name = $name;
        $this->position = $position;
        $this->linkAttributes = $linkAttributes;
        $this->pkgHandle = $pkgHandle;
    }
    
    protected $controller;
    
    public function getHandle() {return $this->handle;}
    public function getName() {return $this->name;}
    public function setName($name) {$this->name = $name;}
    public function getPosition() {return $this->position;}
    public function getLinkAttributes() {return $this->linkAttributes;}
    public function getPackageObject() {return $this->pkgHandle;}
    
    public function getController() {
        if (isset($this->controller)) {
            return $this->controller;
        } else {
            $class = Object::camelcase($this->handle . 'ConcreteInterfaceMenuItemController');
            if (!class_exists($class)) {
                $file1 = DIR_FILES_ELEMENTS . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $this->handle . '/' . FILENAME_MENU_ITEM_CONTROLLER;
                if ($this->pkgHandle) {
                    $pkgHandle = $this->pkgHandle;
                    $dir = (is_dir(DIR_PACKAGES . '/' . $pkgHandle)) ? DIR_PACKAGES : DIR_PACKAGES_CORE;
                    $file2 = $dir . '/' . $pkgHandle . '/' . DIRNAME_ELEMENTS . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $this->handle . '/' . FILENAME_MENU_ITEM_CONTROLLER;
                }
                $file3 = DIR_FILES_ELEMENTS_CORE . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $this->handle . '/' . FILENAME_MENU_ITEM_CONTROLLER;
                if (file_exists($file1)) {
                    include($file1);
                } else if (isset($file2) && file_exists($file2)) {
                    include($file2);
                } else {
                    include($file3);
                }
            }

            $this->controller = new $class();
            $this->controller->setMenuItem($this);
            return $this->controller;
        }
    }
    
    public function getMenuItemFilePath($_file) {
        $f = $this->mapMenuItemFilePath($_file);
        if (is_object($f)) {
            return $f->file;
        }
    }
    
    public function getMenuItemFileURL($_file) {
        $f = $this->mapMenuItemFilePath($_file);
        if (is_object($f)) {
            return $f->url;
        }
    }
    
    protected function mapMenuItemFilePath($_file) {
        $handle = $this->handle;
        if (file_exists(DIR_FILES_ELEMENTS . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $handle . '/' . $_file)) {
            $file = DIR_FILES_ELEMENTS . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $handle . '/' . $_file;
            $url = DIR_REL . '/' . DIRNAME_ELEMENTS . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $handle . '/' . $_file;
        }
        
        if ($this->pkgHandle) {
            if (!isset($file)) {
                $pkgHandle = $this->pkgHandle;
                $dirp = is_dir(DIR_PACKAGES . '/' . $pkgHandle) ? DIR_PACKAGES . '/' . $pkgHandle : DIR_PACKAGES_CORE . '/' . $pkgHandle;
                if (file_exists($dirp . '/' . DIRNAME_ELEMENTS . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $handle . '/' . $_file)) {
                    $file = $dirp . '/' . DIRNAME_ELEMENTS . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $handle . '/' . $_file;
                    $url = DIR_REL . '/' .DIRNAME_PACKAGES. '/' . $pkgHandle . '/' . DIRNAME_ELEMENTS . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $handle . '/' . $_file;
                }
            }
        }
        
        if (!isset($file)) {
            if (file_exists(DIR_FILES_ELEMENTS_CORE . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' .  $handle . '/' . $_file)) {
                $file = DIR_FILES_ELEMENTS_CORE . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' .  $handle . '/' . $_file;
                $url = ASSETS_URL . '/' . DIRNAME_ELEMENTS . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $handle . '/' . $_file;
            }
        }
        
        if (isset($file)) {
            $obj = new stdClass;
            $obj->file = $file;
            $obj->url = $url;
            return $obj;
        } else {
            return false;
        }
    }
}

class ConcreteInterfaceMenuItemController extends Controller {
    
    protected $menuItem;
    protected $headerItemsToCheck = array(
        'CSS' => 'view.css', 
        'JAVASCRIPT' => 'view.js'
    );

    public function setMenuItem($obj) {
        $this->menuItem = $obj;
    }

    public function outputAutoHeaderItems() {
        $h = Loader::helper('html');
        if ($this->menuItem->getController()->displayItem()) {
            foreach($this->headerItemsToCheck as $t => $i) {
                $o = $this->menuItem->getMenuItemFilePath($i);
                if ($o) {
                    $this->menuItem->getMenuItemFileURL($i);
                    switch($t) {
                        case 'CSS':
                            $this->addHeaderItem($h->css($this->menuItem->getMenuItemFileURL($i)));
                            break;
                        case 'JAVASCRIPT':
                            $this->addFooterItem($h->javascript($this->menuItem->getMenuItemFileURL($i)));
                            break;
                    }
                }
            }
        }
    }
    
    public function displayItem() {
        return true;
    }
    
    public function getMenuLinkHTML() {
        $attribs = '';
        if (is_array($this->menuItem->getLinkAttributes())) {
            foreach($this->menuItem->getLinkAttributes() as $key => $value) {
                if ($key == 'class') {
                    $value = 'ccm-header-nav-package-item ' . $value;
                }
                $attribs .= $key . '="' . $value . '" ';
            }
        }
        $html = '<a id="ccm-page-edit-nav-' . $this->menuItem->getHandle() . '" ' . $attribs . '>' . $this->menuItem->getName() . '</a>';
        return $html;
    }
}