Your IP : 216.73.216.170


Current Path : /var/www/iplanru/data/www/i-plan.ru/media/zoo/applications/jbuniversal/framework/
Upload File :
Current File : /var/www/iplanru/data/www/i-plan.ru/media/zoo/applications/jbuniversal/framework/jbzoo.php

<?php
/**
 * JBZoo is universal CCK, application for YooTheme Zoo component
 * @package     JBZoo
 * @author      JBZoo App http://jbzoo.com
 * @copyright   Copyright (C) JBZoo.com
 * @license     http://www.gnu.org/licenses/gpl.html GNU/GPL
 */
// no direct access
defined('_JEXEC') or die('Restricted access');
!defined('JBZOO_APP_GROUP') && define('JBZOO_APP_GROUP', 'jbuniversal');
!defined('DIRECTORY_SEPERATOR') && define('DIRECTORY_SEPERATOR', '/');
!defined('DS') && define('DS', DIRECTORY_SEPARATOR);
/**
 * JBZoo bootstarp class
 */
class JBZoo
{
    /**
     * @var Application
     */
    public $app = null;
    /**
     * App group name
     * @var string
     */
    private $_group = JBZOO_APP_GROUP;
    /**
     * Init JBZoo application
     * @static
     * @return JBZoo
     */
    public static function init()
    {
        static $jbzoo;
        if (!isset($jbzoo)) {
            $jbzoo = new self();
        }
        return $jbzoo;
    }
    /**
     * Initialization JBZoo App
     */
    private function __construct()
    {
        $this->app = App::getInstance('zoo');
        $this->_initPaths();
        $this->_initLanguages();
        $this->_initEvents();
        $this->_initAssets();
        
        if (!$this->app->jbenv->isSite()) {
            $toolbar = JToolBar::getInstance('toolbar');
            $toolbar->appendButton('Link', 'jbzoosupport', 'JBZOO_BUTTON_SUPPORT', 'http://forum.jbzoo.com');
            $toolbar->appendButton('Separator', 'spacer', '60');
        }
    }
    /**
     * Add directory path
     */
    private function _initPaths()
    {
        $this->_addPath('applications:' . $this->_getGroup(), 'jbapp');
        $this->_addPath('jbapp:framework', 'jbzoo');
        $this->_addPath('jbapp:assets', 'jbassets');
        $this->_addPath('jbassets:zoo', 'assets');
        $this->_addPath('jbapp:config', 'jbconfig');
        $this->_addPath('jbapp:types', 'jbtypes');
        $this->_addPath('jbzoo:helpers', 'helpers');
        $this->_addPath('jbzoo:helpers-std', 'helpers');
        $this->_addPath('jbzoo:render', 'renderer');
        $this->_addPath('jbzoo:events', 'jbevents');
        $this->_addPath('jbapp:config', 'jbxml');
        $this->_addPath('jbapp:joomla/elements', 'fields');
        $this->_addPath('plugins:/system/jbzoo', 'plugin_jbzoo');
        $this->_addPath('jbapp:templates', 'jbtmpl');
        if ($this->app->jbenv->isSite()) {
            $this->_addPath('jbzoo:controllers', 'controllers');
        }
    }
    /**
     * Load lang files
     */
    private function _initLanguages()
    {
        $languagePath = $this->app->path->path('jbapp:');
        $this->app->system->language->load('com_zoo');
        $this->app->system->language->load('com_jbzoo', $languagePath, null, true);
        $this->app->system->language->load('com_zoo', JPATH_ADMINISTRATOR);
        $this->app->jbdebug->mark('init::languages');
    }
    /**
     * Register and connect events
     */
    private function _initEvents()
    {
        $this->_addClass('JBEvent', 'jbevents:jbevent.php');
        $eventFiles = JFolder::files($this->app->path->path('jbevents:'), '\.php$');
        foreach ($eventFiles as $eventFile) {
            $className = str_replace('.', '', pathinfo($eventFile, PATHINFO_FILENAME));
            $this->_addClass($className, 'jbevents:' . $eventFile);
        }
        $event      = $this->app->event;
        $dispatcher = $event->dispatcher;
        //$event->register('JBEventApplication');
        //$dispatcher->connect('application:init', array('JBEventApplication', 'init'));
        //$dispatcher->connect('application:saved', array('JBEventApplication', 'saved'));
        //$dispatcher->connect('application:deleted', array('JBEventApplication', 'deleted'));
        //$event->register('JBEventCategory');
        //$dispatcher->connect('category:init', array('JBEventCategory', 'init'));
        //$dispatcher->connect('category:saved', array('JBEventCategory', 'saved'));
        //$dispatcher->connect('category:deleted', array('JBEventCategory', 'deleted'));
        //$dispatcher->connect('category:stateChanged', array('JBEventCategory', 'stateChanged'));
        //$event->register('JBEventItem');
        //$dispatcher->connect('item:init', array('JBEventItem', 'init'));
        //$dispatcher->connect('item:saved', array('JBEventItem', 'saved'));
        //$dispatcher->connect('item:deleted', array('JBEventItem', 'deleted'));
        //$dispatcher->connect('item:stateChanged', array('JBEventItem', 'stateChanged'));
        //$dispatcher->connect('item:beforedisplay', array('JBEventItem', 'beforeDisplay'));
        //$dispatcher->connect('item:afterdisplay', array('JBEventItem', 'afterDisplay'));
        //$event->register('JBEventComment');
        //$dispatcher->connect('comment:init', array('JBEventComment', 'init'));
        //$dispatcher->connect('comment:saved', array('JBEventComment', 'saved'));
        //$dispatcher->connect('comment:deleted', array('JBEventComment', 'deleted'));
        //$dispatcher->connect('comment:stateChanged', array('JBEventComment', 'stateChanged'));
        //$event->register('JBEventSubmission');
        //$dispatcher->connect('submission:init', array('JBEventSubmission', 'init'));
        //$dispatcher->connect('submission:saved', array('JBEventSubmission', 'saved'));
        //$dispatcher->connect('submission:deleted', array('JBEventSubmission', 'deleted'));
        //$dispatcher->connect('submission:beforesave', array('JBEventSubmission', 'beforeSave'));
        //$event->register('JBEventElement');
        //$dispatcher->connect('element:download', array('JBEventElement', 'download'));
        //$dispatcher->connect('element:configform', array('JBEventElement', 'configForm'));
        //$dispatcher->connect('element:configparams', array('JBEventElement', 'configParams'));
        //$dispatcher->connect('element:configxml', array('JBEventElement', 'configXML'));
        //$dispatcher->connect('element:afterdisplay', array('JBEventElement', 'afterDisplay'));
        //$dispatcher->connect('element:beforedisplay', array('JBEventElement', 'beforeDisplay'));
        //$dispatcher->connect('element:aftersubmissiondisplay', array('JBEventElement', 'afterSubmissionDisplay'));
        //$dispatcher->connect('element:beforesubmissiondisplay', array('JBEventElement', 'beforeSubmissionDisplay'));
        //$dispatcher->connect('element:afteredit', array('JBEventElement', 'afterEdit'));
        //$event->register('JBEventLayout');
        //$dispatcher->connect('layout:init', array('JBEventLayout', 'init'));
        //$event->register('JBEventTag');
        //$dispatcher->connect('tag:saved', array('JBEventTag', 'saved'));
        //$dispatcher->connect('tag:deleted', array('JBEventTag', 'deleted'));
        //$event->register('JBEventType');
        //$dispatcher->connect('type:beforesave', array('JBEventType', 'beforesave'));
        //$dispatcher->connect('type:aftersave', array('JBEventType', 'aftersave'));
        //$dispatcher->connect('type:copied', array('JBEventType', 'copied'));
        //$dispatcher->connect('type:deleted', array('JBEventType', 'deleted'));
        //$dispatcher->connect('type:editdisplay', array('JBEventType', 'editDisplay'));
        $this->app->jbdebug->mark('init::events');
    }
    /**
     * Init assets for admin path
     */
    private function _initAssets()
    {
        if (!$this->app->jbenv->isSite()) {
            $this->app->jbassets->admin();
        }
    }
    /**
     * Get group name
     * @return string
     */
    private function _getGroup()
    {
        return $this->_group;
    }
    /**
     * Register new path in system
     * @param string $path
     * @param string $pathName
     * @return mixed
     */
    private function _addPath($path, $pathName)
    {
        if ($fullPath = $this->app->path->path($path)) {
            return $this->app->path->register($fullPath, $pathName);
        }
        return null;
    }
    /**
     * Register new class in system
     * @param string $className
     * @param string $classPath
     */
    private function _addClass($className, $classPath)
    {
        return $this->app->loader->register($className, $classPath);
    }
}