Ejemplo n.º 1
0
 /**
  * Get the DI container.
  *
  * @return  Container
  *
  * @since   1.0
  *
  * @throws  \UnexpectedValueException May be thrown if the container has not been set.
  */
 public function getContainer()
 {
     if (!$this->container) {
         $this->container = Container::getInstance($this->getName());
     }
     return $this->container;
 }
Ejemplo n.º 2
0
 /**
  * Render the profiler log data, and echo it..
  *
  * @param   string   $namespace The JProfiler instance ID. Default is the core profiler "Application".
  * @param   boolean  $asString  Return as string.
  *
  * @return  string
  */
 public static function render($namespace = 'Windwalker', $asString = false)
 {
     $app = Container::getInstance()->get('app');
     if ($namespace == 'core' || !$namespace) {
         $namespace = 'Application';
     }
     $buffer = 'No Profiler data.';
     if (isset(self::$profiler[$namespace])) {
         $_PROFILER = self::$profiler[$namespace];
         $buffer = $_PROFILER->getBuffer();
         $buffer = implode("\n<br />\n", $buffer);
     } else {
         $buffer = $app->getUserState('windwalker.system.profiler.' . $namespace);
         $buffer = $buffer ? implode("\n<br />\n", $buffer) : '';
     }
     $buffer = $buffer ? $buffer : 'No Profiler data.';
     // Get last page logs
     $state_buffer = \JArrayHelper::getValue(self::$stateBuffer, $namespace);
     if ($state_buffer) {
         $state_buffer = implode("\n<br />\n", $state_buffer);
         $buffer = $state_buffer . "\n<br />---------<br />\n" . $buffer;
     }
     // Render
     $buffer = "<pre><h3>WindWalker Debug [namespace: {$namespace}]: </h3>" . $buffer . '</pre>';
     $app->setUserState('windwalker.system.profiler.' . $namespace, '');
     if ($asString) {
         return $buffer;
     }
     echo $buffer;
     return '';
 }
Ejemplo n.º 3
0
 /**
  * Refresh the list of include paths
  *
  * @return  void
  */
 protected function refreshIncludePaths()
 {
     $app = Container::getInstance()->get('app');
     // Reset includePaths
     $this->includePaths = array();
     // (1 - lower priority) Frontend base layouts
     $this->addIncludePaths(JPATH_ROOT . '/layouts');
     // (2) Windwalker layouts.
     $this->addIncludePaths(WINDWALKER . '/resource/layouts');
     // (3) Standard Joomla! template override
     $this->addIncludePaths(JPATH_THEMES . '/' . $app->getTemplate() . '/html/layouts');
     // Component layouts & overrides if exist
     $component = $this->options->get('component', null);
     if (!empty($component)) {
         // (4) Component path
         if ($this->options->get('client') == 0) {
             $this->addIncludePaths(JPATH_SITE . '/components/' . $component . '/layouts');
         } else {
             $this->addIncludePaths(JPATH_ADMINISTRATOR . '/components/' . $component . '/layouts');
         }
         // (5) Component template overrides path
         $this->addIncludePath(JPATH_THEMES . '/' . $app->getTemplate() . '/html/layouts/' . $component);
     }
     // (6 - highest priority) Received a custom high priority path ?
     if (!is_null($this->basePath)) {
         $this->addIncludePath(rtrim($this->basePath, DIRECTORY_SEPARATOR));
     }
 }
Ejemplo n.º 4
0
 /**
  * Method to attach a JForm object to the field.
  *  Catch upload files when form setup.
  *
  * @param   SimpleXMLElement $element  The JXmlElement object representing the <field /> tag for the form field object.
  * @param   mixed            $value    The form field value to validate.
  * @param   string           $group    The field name group control value. This acts as as an array container for the field.
  *                                     For example if the field has name="foo" and the group value is set to "bar" then the
  *                                     full field name would end up being "bar[foo]".
  *
  * @return  boolean  True on success.
  */
 public function setup(SimpleXMLElement $element, $value, $group = null)
 {
     parent::setup($element, $value, $group);
     $container = \Windwalker\DI\Container::getInstance();
     $input = $container->get('input');
     $delete = isset($_REQUEST['jform']['profile'][$this->element['name'] . '_delete']) ? $_REQUEST['jform']['profile'][$this->element['name'] . '_delete'] : 0;
     if ($delete == 1) {
         $this->value = '';
     } else {
         // Upload Image
         // ===============================================
         if (isset($_FILES['jform']['name']['profile'])) {
             foreach ($_FILES['jform']['name']['profile'] as $key => $var) {
                 if (!$var) {
                     continue;
                 }
                 // Get Field Attr
                 $width = $this->element['save_width'] ? $this->element['save_width'] : 800;
                 $height = $this->element['save_height'] ? $this->element['save_height'] : 800;
                 // Build File name
                 $src = $_FILES['jform']['tmp_name']['profile'][$key];
                 $var = explode('.', $var);
                 $date = DateHelper::getDate();
                 $name = md5((string) $date . $width . $height . $src) . '.' . array_pop($var);
                 $url = "images/cck/{$date->year}/{$date->month}/{$date->day}/" . $name;
                 // A Event for extend.
                 $container->get('event.dispatcher')->trigger('onCCKEngineUploadImage', array(&$url, &$this, &$this->element));
                 $dest = JPATH_ROOT . '/' . $url;
                 // Upload First
                 JFile::upload($src, $dest);
                 // Resize image
                 $img = new JImage();
                 $img->loadFile(JPATH_ROOT . '/' . $url);
                 $img = $img->resize($width, $height);
                 switch (array_pop($var)) {
                     case 'gif':
                         $type = IMAGETYPE_GIF;
                         break;
                     case 'png':
                         $type = IMAGETYPE_PNG;
                         break;
                     default:
                         $type = IMAGETYPE_JPEG;
                         break;
                 }
                 // Save
                 $img->toFile($dest, $type, array('quality' => 85));
                 // Set in Value
                 $this->value = $url;
                 // Clean cache
                 $thumb = $this->getThumbPath();
                 if (is_file(JPATH_ROOT . '/' . $thumb)) {
                     \JFile::delete(JPATH_ROOT . '/' . $thumb);
                 }
             }
         }
     }
     return true;
 }
Ejemplo n.º 5
0
    /**
     * Add an quick add button & modal
     *
     * @return string The quickadd button.
     */
    public function quickadd()
    {
        // Prepare Element
        $readonly = $this->getElement('readonly', false);
        $disabled = $this->getElement('disabled', false);
        if ($readonly || $disabled) {
            return '';
        }
        $container = Container::getInstance();
        $input = $container->get('input');
        $quickadd = $this->getElement('quickadd', false);
        $table_name = $this->getElement('table', '#__' . $this->component . '_' . $this->view_list);
        $key_field = $this->getElement('key_field', 'id');
        $value_field = $this->getElement('value_field', 'title');
        $formpath = WINDWALKER_SOURCE . "/Form/Forms/quickadd/category.xml";
        $quickadd_handler = $this->getElement('quickadd_handler', $input->get('option'));
        $title = $this->getElement('quickadd_label', 'LIB_WINDWALKER_QUICKADD_TITLE');
        $qid = $this->id . '_quickadd';
        if (!$quickadd) {
            return '';
        }
        // Prepare Script & Styles
        /** @var Windwalker\Helper\AssetHelper $asset */
        $asset = Container::getInstance($quickadd_handler)->get('helper.asset');
        $asset->addJs('js/quickadd.js');
        // Set AKQuickAddOption
        $config['task'] = $this->view_item . '.ajax.legacyquickadd';
        $config['quickadd_handler'] = $quickadd_handler;
        $config['cat_extension'] = (string) $this->element['extension'];
        $config['extension'] = 'com_' . $this->component;
        $config['component'] = $this->component;
        $config['table'] = $table_name;
        $config['model_name'] = 'category';
        $config['key_field'] = $key_field;
        $config['value_field'] = $value_field;
        $config['joomla3'] = JVERSION >= 3;
        $config = HtmlHelper::getJSObject($config);
        $script = <<<QA
        window.addEvent('domready', function(){
            var AKQuickAddOption = {$config} ;
            AKQuickAdd.init('{$qid}', AKQuickAddOption);
        });
QA;
        $asset->internalJS($script);
        // Load Language & Form
        LanguageHelper::loadLanguage('com_' . $this->component, null);
        $formpath = str_replace(JPATH_ROOT, '', $formpath);
        $content = ModalHelper::getQuickaddForm($qid, $formpath, (string) $this->element['extension']);
        // Prepare HTML
        $html = '';
        $button_title = $title;
        $modal_title = $button_title;
        $button_class = 'btn btn-small btn-success delicious green light fltlft quickadd_button';
        $footer = "<button class=\"btn delicious\" type=\"button\" onclick=\"\$\$('#{$qid} input', '#{$qid} select').set('value', '');AKQuickAdd.closeModal('{$qid}');\" data-dismiss=\"modal\">" . JText::_('JCANCEL') . "</button>";
        $footer .= "<button class=\"btn btn-primary delicious blue\" type=\"submit\" onclick=\"AKQuickAdd.submit('{$qid}', event);\">" . JText::_('JSUBMIT') . "</button>";
        $html .= ModalHelper::modalLink(JText::_($button_title), $qid, array('class' => $button_class, 'icon' => 'icon-new icon-white'));
        $html .= ModalHelper::renderModal($qid, $content, array('title' => JText::_($modal_title), 'footer' => $footer));
        return $html;
    }
Ejemplo n.º 6
0
 /**
  * Return the {@link JDate} object
  *
  * @param   mixed  $time      The initial time for the JDate object
  * @param   mixed  $tzOffset  The timezone offset.
  *
  * @return  \JDate object
  */
 public static function getDate($time = 'now', $tzOffset = null)
 {
     if (!$tzOffset) {
         $config = Container::getInstance()->get('joomla.config');
         $tzOffset = $config->get('offset');
     }
     return \JFactory::getDate($time, $tzOffset);
 }
 /**
  * Restore original Application instance
  *
  * @return  void
  */
 public static function restoreApplication()
 {
     $container = Container::getInstance();
     $className = get_class(static::$originalApplication);
     $container->alias('app', $className);
     $container->share($className, static::$originalApplication);
     \JFactory::$application = static::$originalApplication;
 }
Ejemplo n.º 8
0
 /**
  * Get a query string to filter the publishing items now.
  *
  * Will return: '( publish_up < 'xxxx-xx-xx' OR publish_up = '0000-00-00' )
  *   AND ( publish_down > 'xxxx-xx-xx' OR publish_down = '0000-00-00' )'
  *
  * @param   string $prefix Prefix to columns name, eg: 'a.' will use `a`.`publish_up`.
  *
  * @return  string Query string.
  */
 public static function publishingPeriod($prefix = '')
 {
     $db = Container::getInstance()->get('db');
     $nowDate = $date = DateHelper::getDate()->toSQL();
     $nullDate = $db->getNullDate();
     $date_where = " ( {$prefix}publish_up < '{$nowDate}' OR  {$prefix}publish_up = '{$nullDate}') AND " . " ( {$prefix}publish_down > '{$nowDate}' OR  {$prefix}publish_down = '{$nullDate}') ";
     return $date_where;
 }
Ejemplo n.º 9
0
    /**
     * Method to get the user field input markup.
     *
     * @return  string  The field input markup.
     */
    protected function getInput()
    {
        $html = array();
        $groups = $this->getGroups();
        $excluded = $this->getExcluded();
        $link = 'index.php?option=com_users&amp;view=users&amp;layout=modal&amp;tmpl=component&amp;field=' . $this->id . (isset($groups) ? '&amp;groups=' . base64_encode(json_encode($groups)) : '') . (isset($excluded) ? '&amp;excluded=' . base64_encode(json_encode($excluded)) : '');
        // Initialize some field attributes.
        $attr = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
        $attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
        // Initialize JavaScript field attributes.
        $onchange = (string) $this->element['onchange'];
        // Load the modal behavior script.
        WindwalkerScript::modal('.hasUserModal');
        JQueryScript::ui(array('effect'));
        // Build the script.
        $js = <<<JS
function jSelectUser_{$this->id}(id, title) {
\tvar input = jQuery('#{$this->id}_id');
\tvar oldId = input.val();

\tif (oldId != id) {
\t\tinput.val(id);
\t\tjQuery('#{$this->id}_name').val(title).removeClass('invalid').delay(300).effect('highlight');
\t}

\t{$onchange};

\tWindwalker.Modal.hide();
};
JS;
        // Add the script to the document head.
        $asset = Container::getInstance()->get('helper.asset');
        $asset->internalJS($js);
        // Load the current username if available.
        $table = JTable::getInstance('user');
        if ($this->value) {
            $table->load($this->value);
        } elseif (strtoupper($this->value) == 'CURRENT') {
            // 'CURRENT' is not a reasonable value to be placed in the html
            $this->value = JFactory::getUser()->id;
            $table->load($this->value);
        } else {
            $table->name = JText::_('JLIB_FORM_SELECT_USER');
        }
        // Create a dummy text field with the user name.
        $html[] = '<div class="input-append">';
        $html[] = '	<input type="text" id="' . $this->id . '_name" value="' . htmlspecialchars($table->name, ENT_COMPAT, 'UTF-8') . '"' . ' readonly' . $attr . ' />';
        // Create the user select button.
        if (!XmlHelper::getBool($this->element, 'readonly', false)) {
            $html[] = '		<a class="btn btn-primary hasUserModal modal_' . $this->id . '" title="' . JText::_('JLIB_FORM_CHANGE_USER') . '" href="' . $link . '"' . ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
            $html[] = '<i class="icon-user"></i></a>';
        }
        $html[] = '</div>';
        // Create the real field, hidden, that stored the user id.
        $html[] = '<input type="hidden" id="' . $this->id . '_id" name="' . $this->name . '" value="' . $this->value . '" />';
        return implode("\n", $html);
    }
Ejemplo n.º 10
0
 /**
  * Object constructor to set table and key fields.  In most cases this will
  * be overridden by child classes to explicitly set the table and key fields
  * for a particular database table.
  *
  * @param   string           $table  Name of the table to model.
  * @param   mixed            $key    Name of the primary key field in the table or array of field names that compose the primary key.
  * @param   \JDatabaseDriver $db     JDatabaseDriver object.
  */
 public function __construct($table, $key = 'id', $db = null)
 {
     $db = $db ?: Container::getInstance()->get('db');
     parent::__construct($table, $key, $db);
     // Prepare Relation handler
     $this->_relation = new Relation($this, $this->getPrefix());
     RelationObserver::createObserver($this);
     $this->configure();
     $this->_observers->update('onAfterConstruction', array());
 }
Ejemplo n.º 11
0
 /**
  * executeSql
  *
  * @param string $sql
  *
  * @return  void
  */
 protected function executeSql($sql)
 {
     $db = Container::getInstance()->get('db');
     $queries = $db->splitSql($sql);
     foreach ($queries as $query) {
         if (!trim($query)) {
             continue;
         }
         $db->setQuery($query)->execute();
     }
 }
Ejemplo n.º 12
0
 /**
  * constructor.
  *
  * @param Command     $command
  * @param Container   $container
  * @param IOInterface $io
  */
 public function __construct(Command $command, Container $container = null, IOInterface $io = null)
 {
     $this->command = $command;
     $container = $container ?: Container::getInstance();
     $this->container = $container;
     $container->registerServiceProvider(new GeneratorBundleProvider($command));
     $io = $io ?: $container->get('io');
     $io->setCommand($command);
     parent::__construct($container, $io);
     $container->registerServiceProvider(new OperatorProvider($command));
 }
Ejemplo n.º 13
0
 /**
  * Detach a listener.
  *
  * @param \JEvent|string|array $listener   The listener name to detach.
  * @param \JEventDispatcher    $dispatcher The EventDispatcher.
  *
  * @return  boolean True if the observer object was detached.
  */
 protected static function detach($listener, $dispatcher = null)
 {
     $dispatcher = $dispatcher ?: Container::getInstance()->get('event.dispatcher');
     if (is_string($listener) && class_exists($listener)) {
         if (empty(static::$listener[$listener])) {
             static::$listener[$listener] = $listener = new $listener($dispatcher);
         } else {
             $listener = static::$listener[$listener];
         }
     }
     return $dispatcher->detach($listener);
 }
Ejemplo n.º 14
0
 /**
  * init
  *
  * @param   \JDocument $template JDcoument object.
  * @param   \JRegistry $params   Template params.
  *
  * @return  Template
  */
 public function init(\JDocument $template, \JRegistry $params)
 {
     include_once static::windwalkerPath();
     static::$template = $template;
     static::$params = $params;
     static::$asset = Container::getInstance('tpl_' . static::$name)->get('helper.asset');
     // Reset AssetHelper
     static::$asset->resetPaths();
     static::$asset->setDoc($template);
     static::registerStylesheet($template);
     static::registerScript($template);
     return $this;
 }
 /**
  * testGetInstance
  *
  * @covers \Windwalker\DI\Container::getInstance()
  */
 public function testGetInstance()
 {
     $backup = Container::getInstance();
     $stub = new StubContainer(Container::getInstance());
     $this->assertInstanceOf('Joomla\\DI\\Container', $stub::getInstance());
     $this->assertInstanceOf('Joomla\\DI\\Container', $stub::getInstance('foo'));
     // Test parent
     $this->assertSame(StubContainer::getInstance(), StubContainer::getInstance('stub')->getParent());
     // Put backup instance back
     $ref = new \ReflectionProperty('Windwalker\\DI\\Container', 'instance');
     $ref->setAccessible(true);
     $ref->setValue($backup);
 }
 /**
  * Pass Relation object to Parent Table.
  *
  * @return  void
  */
 public function onAfterConstruction()
 {
     $relation = $this->mapper->getRelation();
     $this->parentTable = $relation->getParent();
     $this->parentTable->_relation = $relation;
     // Pass global relation configuration into parent.
     $relations = Container::getInstance()->get('relation.container')->getRelation($this->mapper->getTable());
     /** @var Relation $relations */
     foreach ($relations->getRelations() as $relation) {
         /** @var AbstractRelationHandler $relation */
         $relation->setParent($this->parentTable);
         $this->parentTable->_relation->setRelation($relation->getField(), $relation);
     }
 }
 /**
  * Pass Relation object to Parent Table.
  *
  * @return  void
  */
 public function onAfterConstruction()
 {
     if (!$this->table instanceof Table) {
         return;
     }
     // Pass global relation configuration into parent.
     $relations = Container::getInstance()->get('relation.container')->getRelation($this->table->getTableName());
     /** @var Relation $relations */
     foreach ($relations->getRelations() as $relation) {
         /** @var AbstractRelationHandler $relation */
         $relation->setParent($this->table);
         $this->table->_relation->setRelation($relation->getField(), $relation);
     }
 }
Ejemplo n.º 18
0
 /**
  * Add an quick add button & modal
  *
  * @return string The quickadd button.
  */
 public function quickadd()
 {
     // Prepare Element
     $readonly = $this->getElement('readonly', false);
     $disabled = $this->getElement('disabled', false);
     if ($readonly || $disabled) {
         return '';
     }
     $container = Container::getInstance();
     $input = $container->get('input');
     $quickadd = $this->getElement('quickadd', false);
     $table_name = $this->getElement('table', '#__' . $this->component . '_' . $this->view_list);
     $key_field = $this->getElement('key_field', 'id');
     $value_field = $this->getElement('value_field', 'title');
     $formpath = WINDWALKER_SOURCE . "/Form/Forms/quickadd/category.xml";
     $quickadd_handler = $this->getElement('quickadd_handler', $input->get('option'));
     $title = $this->getElement('quickadd_label', 'LIB_WINDWALKER_QUICKADD_TITLE');
     $qid = $this->id . '_quickadd';
     if (!$quickadd) {
         return '';
     }
     // Set AKQuickAddOption
     $config['task'] = $this->view_item . '.ajax.legacyquickadd';
     $config['quickadd_handler'] = $quickadd_handler;
     $config['cat_extension'] = (string) $this->element['extension'];
     $config['extension'] = 'com_' . $this->component;
     $config['component'] = $this->component;
     $config['table'] = $table_name;
     $config['model_name'] = 'category';
     $config['key_field'] = $key_field;
     $config['value_field'] = $value_field;
     $config['joomla3'] = JVERSION >= 3;
     WindwalkerScript::quickadd('#' . $qid, $config);
     // Load Language & Form
     LanguageHelper::loadLanguage('com_' . $this->component, null);
     $formpath = str_replace(JPATH_ROOT, '', $formpath);
     $content = ModalHelper::getQuickaddForm($qid, $formpath, (string) $this->element['extension']);
     // Prepare HTML
     $html = '';
     $button_title = $title;
     $modal_title = $button_title;
     $button_class = 'btn btn-small btn-success quickadd_button';
     $footer = "<button class=\"btn\" type=\"button\" data-dismiss=\"modal\">" . JText::_('JCANCEL') . "</button>";
     $footer .= "<button class=\"btn btn-primary\" type=\"submit\">" . JText::_('JSUBMIT') . "</button>";
     $html .= ModalHelper::modalLink(JText::_($button_title), $qid, array('class' => $button_class, 'icon' => 'icon-new icon-white'));
     $html .= ModalHelper::renderModal($qid, $content, array('title' => JText::_($modal_title), 'footer' => $footer));
     return $html;
 }
 /**
  * viewLevel
  *
  * @param Data       $item
  * @param Data       $category
  * @param \JRegistry $state
  * @param \JRegistry $params
  *
  * @return  void
  */
 public static function viewLevel(Data $item, Data $category, \JRegistry $state, \JRegistry $params)
 {
     $user = Container::getInstance()->get('user');
     if ($access = $state->get('filter.access')) {
         // If the access filter has been set, we already know this user can view.
         $params->set('access-view', true);
     } else {
         // If no access filter is set, the layout takes some responsibility for display of limited information.
         $groups = $user->getAuthorisedViewLevels();
         if (!$item->catid || empty($category->access)) {
             $params->set('access-view', in_array($item->access, $groups));
         } else {
             $params->set('access-view', in_array($item->access, $groups) && in_array($category->access, $groups));
         }
     }
 }
Ejemplo n.º 20
0
 /**
  * Method to get the user field input markup.
  *
  * @return  string  The field input markup.
  */
 protected function getInput()
 {
     $html = array();
     $groups = $this->getGroups();
     $excluded = $this->getExcluded();
     $link = 'index.php?option=com_users&amp;view=users&amp;layout=modal&amp;tmpl=component&amp;field=' . $this->id . (isset($groups) ? '&amp;groups=' . base64_encode(json_encode($groups)) : '') . (isset($excluded) ? '&amp;excluded=' . base64_encode(json_encode($excluded)) : '');
     // Initialize some field attributes.
     $attr = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
     $attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
     // Initialize JavaScript field attributes.
     $onchange = (string) $this->element['onchange'];
     // Load the modal behavior script.
     JHtml::_('behavior.modal', 'a.modal_' . $this->id);
     // Build the script.
     $script = array();
     $script[] = '	function jSelectUser_' . $this->id . '(id, title) {';
     $script[] = '		var old_id = document.getElementById("' . $this->id . '_id").value;';
     $script[] = '		if (old_id != id) {';
     $script[] = '			document.getElementById("' . $this->id . '_id").value = id;';
     $script[] = '			document.getElementById("' . $this->id . '_name").value = title;';
     $script[] = '			' . $onchange;
     $script[] = '		}';
     $script[] = '		SqueezeBox.close();';
     $script[] = '	}';
     // Add the script to the document head.
     $asset = Container::getInstance()->get('helper.asset');
     $asset->internalJS(implode("\n", $script));
     // Load the current username if available.
     $table = JTable::getInstance('user');
     if ($this->value) {
         $table->load($this->value);
     } else {
         $table->name = JText::_('JLIB_FORM_SELECT_USER');
     }
     // Create a dummy text field with the user name.
     $html[] = '<div class="input-append">';
     $html[] = '	<input type="text" id="' . $this->id . '" value="' . htmlspecialchars($table->name, ENT_COMPAT, 'UTF-8') . '"' . ' readonly' . $attr . ' />';
     // Create the user select button.
     if (!XmlHelper::getBool($this->element, 'readonly', false)) {
         $html[] = '		<a class="btn btn-primary modal_' . $this->id . '" title="' . JText::_('JLIB_FORM_CHANGE_USER') . '" href="' . $link . '"' . ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
         $html[] = '<i class="icon-user"></i></a>';
     }
     $html[] = '</div>';
     // Create the real field, hidden, that stored the user id.
     $html[] = '<input type="hidden" id="' . $this->id . '_id" name="' . $this->name . '" value="' . $this->value . '" />';
     return implode("\n", $html);
 }
 public function testGlobalRelationConfig()
 {
     /** @var RelationContainer $relations */
     $relations = Container::getInstance()->get('relation.container');
     $relation = $relations->getRelation(static::TABLE_LOCATIONS);
     $relation->addOneToMany('sakuras', new StubTableSakura(), array('id' => 'location'));
     $relation->addOneToMany('roses', new StubTableRose(), array('id' => 'location'));
     $location = new Table(static::TABLE_LOCATIONS, 'id', \JFactory::getDbo());
     $location->load(3);
     $sakuras = $location->sakuras;
     $roses = $location->roses;
     $this->assertInstanceOf('Windwalker\\Data\\Data', $sakuras[0]);
     $this->assertInstanceOf('Windwalker\\Data\\DataSet', $sakuras);
     $this->assertInstanceOf('Windwalker\\Data\\DataSet', $roses);
     $this->assertEquals(array(11, 12, 13, 14, 15), $sakuras->id);
     $this->assertEquals(array(11, 12, 13, 14, 15), $roses->id);
     $relations->setRelation(static::TABLE_LOCATIONS, new Relation());
 }
 /**
  * Method to test mark().
  *
  * @return void
  *
  * @covers \Windwalker\Helper\ProfilerHelper::mark
  */
 public function testMark()
 {
     $namespace = 'unit-test';
     ProfilerHelper::mark('foo', $namespace);
     ProfilerHelper::mark('bar', $namespace);
     ProfilerHelper::mark('foobar', $namespace);
     $app = Container::getInstance()->get('app');
     $buffer = $app->getUserState('windwalker.system.profiler.' . $namespace);
     $regexpPattern = '/^unit-test [0-9]+\\.[0-9]{3} seconds \\([0-9]+\\.[0-9]{3}\\); [0-9]+\\.[0-9]{2} MB \\([0-9]+\\.[0-9]{3}\\) - %s/';
     // Assert $buffer[0]
     $regexp = sprintf($regexpPattern, 'foo');
     $this->assertTrue((bool) preg_match($regexp, $buffer[0]));
     // Assert $buffer[1]
     $regexp = sprintf($regexpPattern, 'bar');
     $this->assertTrue((bool) preg_match($regexp, $buffer[1]));
     // Assert $buffer[2]
     $regexp = sprintf($regexpPattern, 'foobar');
     $this->assertTrue((bool) preg_match($regexp, $buffer[2]));
 }
Ejemplo n.º 23
0
 /**
  * Init windalkwer.
  *
  * @throws \Exception
  * @return  void
  */
 public function init()
 {
     $version = new \JVersion();
     if (!$version->isCompatible('3.2')) {
         throw new \Exception('Windwalker need Joomla! 3.2 or higher.');
     }
     // Import Windwalker autoload.
     $this->autoload();
     include_once __DIR__ . '/PHP/methods.php';
     define('WINDWALKER', dirname(__DIR__));
     define('WINDWALKER_SOURCE', __DIR__);
     define('WINDWALKER_BUNDLE', dirname(WINDWALKER) . '/windwalker-bundles');
     // Register global provider
     $container = Container::getInstance();
     $container->registerServiceProvider(new \Windwalker\Provider\SystemProvider());
     // Register bundles
     $this->registerBundles($container);
     // Load language
     $lang = $container->get('language');
     $lang->load('lib_windwalker', JPATH_BASE, null, false, false) || $lang->load('lib_windwalker', WINDWALKER, null, false, false) || $lang->load('lib_windwalker', JPATH_BASE, $lang->getDefault(), false, false) || $lang->load('lib_windwalker', WINDWALKER, $lang->getDefault(), false, false);
 }
Ejemplo n.º 24
0
 /**
  * Get item link.
  *
  * @return string The link string.
  */
 public function getLink()
 {
     // Avoid self
     $input = Container::getInstance()->get('input');
     $id = $input->get('id');
     $option = $input->get('option');
     $view = $input->get('view');
     $layout = $input->getString('layout');
     $params = '';
     if (isset($this->element['show_root'])) {
         $params .= '&show_root=1';
     }
     if ($view == $this->view_item && $option == $this->extension && $layout == 'edit' && $id) {
         $params .= '&avoid=' . $id;
     }
     return 'index.php?option=' . $this->extension . '&view=' . $this->view_list . $params . '&layout=modal&tmpl=component&function=jSelect' . ucfirst($this->component) . '_' . $this->id;
 }
Ejemplo n.º 25
0
 /**
  * Constructor.
  *
  * @param string           $name        The Component name.
  * @param \JInput          $input       The Input object.
  * @param \JApplicationCms $application The Application object.
  * @param Container        $container   The DI container.
  *
  * @throws \Exception
  */
 public function __construct($name = null, $input = null, $application = null, $container = null)
 {
     $this->application = $application ?: \JFactory::getApplication();
     $this->input = $input ?: $this->application->input;
     $this->name = $name;
     // Guess component name.
     if (!$this->name) {
         $reflection = $this->getReflection();
         $this->name = $reflection->getShortName();
         $this->name = str_replace('Component', '', $this->name);
         if (!$this->name) {
             throw new \Exception('Component need name.');
         }
     }
     $this->option = 'com_' . strtolower($this->name);
     $this->container = $container ?: Container::getInstance($this->option);
     $this->init();
 }
Ejemplo n.º 26
0
<?php

/**
 * Part of Component Userxtd files.
 *
 * @copyright   Copyright (C) 2014 Asikart. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
// No direct access
defined('_JEXEC') or die;
include_once JPATH_LIBRARIES . '/windwalker/src/init.php';
JLoader::registerPrefix('Userxtd', JPATH_BASE . '/components/com_userxtd');
JLoader::registerNamespace('Userxtd', JPATH_ADMINISTRATOR . '/components/com_userxtd/src');
JLoader::registerNamespace('Windwalker', __DIR__);
JLoader::register('UserxtdComponent', JPATH_BASE . '/components/com_userxtd/component.php');
// UserXTD API
\JLoader::register('UXFactory', __DIR__ . '/Class/factory.php');
// CCK
$container = \Windwalker\DI\Container::getInstance('com_userxtd');
$container->registerServiceProvider(new \Windwalker\CCK\CCKProvider());
Ejemplo n.º 27
0
 /**
  * getContainer
  *
  * @return  \Windwalker\DI\Container
  */
 public function getContainer()
 {
     if (!$this->container) {
         $this->initComponent();
         $this->container = \Windwalker\DI\Container::getInstance('com_userxtd');
     }
     return $this->container;
 }
Ejemplo n.º 28
0
 /**
  * Load language from an extension.
  *
  * @param   string $ext    Extension element name, eg: com_content, plg_group_name.
  * @param   string $client site or admin.
  *
  * @return  boolean
  */
 public static function loadLanguage($ext, $client = 'site')
 {
     $lang = Container::getInstance()->get('language');
     return $lang->load($ext, JPATH_BASE, null, false, false) || $lang->load($ext, PathHelper::get($ext, $client), null, false, false) || $lang->load($ext, JPATH_BASE, null, true) || $lang->load($ext, PathHelper::get($ext, $client), null, true);
 }
Ejemplo n.º 29
0
 /**
  * Constructor.
  *
  * @param Container $container
  */
 public function __construct(Container $container = null)
 {
     $this->container = $container ?: Container::getInstance();
 }
Ejemplo n.º 30
0
 /**
  * setDb
  *
  * @param   DatabaseDriver $db
  *
  * @return  void
  *
  * @deprecated  3.0
  */
 public static function setDbo(DatabaseDriver $db)
 {
     Container::getInstance()->share('db', $db);
 }