public function __construct()
 {
     parent::__construct();
     $this->errors = new MessageStack();
     $this->fields = array();
     $this->editing = $this->failed = false;
     $this->datasource = $this->handle = $this->status = $this->type = NULL;
     $this->types = array();
     foreach (new ExtensionIterator(ExtensionIterator::FLAG_TYPE, array('Data Source')) as $extension) {
         $path = Extension::getPathFromClass(get_class($extension));
         $handle = Extension::getHandleFromPath($path);
         if (Extension::status($handle) != Extension::STATUS_ENABLED) {
             continue;
         }
         if (!method_exists($extension, 'getDataSourceTypes')) {
             continue;
         }
         foreach ($extension->getDataSourceTypes() as $type) {
             $this->types[$type->class] = $type;
         }
     }
     if (empty($this->types)) {
         $this->alerts()->append(__('There are no Data Source types currently available. You will not be able to create or edit Data Sources.'), AlertStack::ERROR);
     }
 }
 public function view()
 {
     $this->lists = (object) array('status' => array(Extension::STATUS_ENABLED => array(), Extension::STATUS_DISABLED => array(), Extension::STATUS_NOT_INSTALLED => array(), Extension::STATUS_REQUIRES_UPDATE => array()), 'type' => array(), 'extensions' => array());
     ## Setup page
     $filter = $this->_context[0] == 'type' || $this->_context[0] == 'status' ? $this->_context[0] : NULL;
     $value = isset($this->_context[1]) ? $this->_context[1] : NULL;
     $this->setTitle(__('%1$s – %2$s', array(__('Symphony'), __('Extensions'))));
     $this->appendSubheading(__('Extensions'));
     $path = ADMIN_URL . '/system/extensions/';
     $this->Form->setAttribute('action', Administration::instance()->getCurrentPageURL());
     ## Define layout
     $layout = new Layout();
     $left = $layout->createColumn(Layout::SMALL);
     $left->setAttribute('class', 'column small filters');
     $right = $layout->createColumn(Layout::LARGE);
     ## Process extensions and build lists
     foreach (new ExtensionIterator() as $extension) {
         $pathname = Extension::getPathFromClass(get_class($extension));
         $handle = Extension::getHandleFromPath($pathname);
         $status = Extension::status($handle);
         // List of extensions
         $this->lists->extensions[$handle] = array('object' => $extension, 'path' => $path, 'handle' => $handle, 'status' => $status);
         // List of extension handles grouped by status
         if (!is_array($this->lists->status[$status])) {
             $this->lists->status[$status] = array();
         }
         $this->lists->status[$status][] = $handle;
         // List of extension handles grouped by type
         if (isset($extension->about()->type) && is_array($extension->about()->type) && !empty($extension->about()->type)) {
             foreach ($extension->about()->type as $t) {
                 if (!isset($this->lists->type[$t])) {
                     $this->lists->type[$t] = array();
                 }
                 $this->lists->type[$t][] = $handle;
             }
         }
     }
     ## Build status filter menu
     $h4 = $this->createElement('h4', __('Filter by Status'));
     $left->appendChild($h4);
     $ul = $this->createElement('ul');
     ## Main status overview
     $li = $this->createElement('li', Widget::Anchor(__('Overview'), $path));
     if (is_null($filter)) {
         $li->setAttribute('class', 'active');
     }
     $ul->appendChild($li);
     foreach ($this->lists->status as $status => $extensions) {
         if (!empty($extensions)) {
             $li = $this->createElement('li', Widget::Anchor(self::$status_translation[$status], "{$path}status/{$status}"));
             if ($value == $status) {
                 $li->setAttribute('class', 'active');
             }
             $count = $this->createElement('span', (string) count($extensions));
             $li->appendChild($count);
             $ul->appendChild($li);
         }
     }
     $left->appendChild($ul);
     ## Build type filter menu
     $h4 = $this->createElement('h4', __('Filter by Type'));
     $left->appendChild($h4);
     $ul = $this->createElement('ul');
     foreach ($this->lists->type as $type => $extensions) {
         if (!empty($extensions)) {
             $li = $this->createElement('li', Widget::Anchor(ucwords($type), "{$path}type/{$type}"));
             if ($value == $type) {
                 $li->setAttribute('class', 'active');
             }
             $count = $this->createElement('span', (string) count($extensions));
             $li->appendChild($count);
             $ul->appendChild($li);
         }
     }
     $left->appendChild($ul);
     ## If a filter and value are specified...
     if (!is_null($filter) && !is_null($value)) {
         ## If there are extensions in the list, build the table
         if (isset($this->lists->{$filter}[$value])) {
             $right->appendChild($this->buildTable($this->lists->{$filter}[$value]));
         } else {
             ## Otherwise pass an empty array so we get the
             ## 'No Records Found' message
             $right->appendChild($this->buildTable());
         }
         ## and append table actions
         $tableActions = $this->createElement('div');
         $tableActions->setAttribute('class', 'actions');
         $options = array(array(NULL, false, __('With Selected...')), array('enable', false, __('Enable')), array('disable', false, __('Disable')), array('uninstall', false, __('Uninstall'), 'confirm'));
         $tableActions->appendChild(Widget::Select('with-selected', $options));
         $tableActions->appendChild(Widget::Input('action[apply]', __('Apply'), 'submit'));
         $right->appendChild($tableActions);
         ## Otherwise, build the overview
     } else {
         ## Requires Update
         if (!empty($this->lists->status[Extension::STATUS_REQUIRES_UPDATE])) {
             $count = count($this->lists->status[Extension::STATUS_REQUIRES_UPDATE]);
             $div = $this->createElement('div');
             $div->setAttribute('class', 'tools');
             $h4 = $this->createElement('h4', __('Updates'));
             $message = __('%s %s %s updates available.', array($count, $count > 1 ? 'extensions' : 'extension', $count > 1 ? 'have' : 'has'));
             $p = $this->createElement('p', $message);
             $view = Widget::Anchor(__('View Details'), sprintf('%sstatus/%s/', $path, Extension::STATUS_REQUIRES_UPDATE));
             $view->setAttribute('class', 'button');
             $div->appendChild($view);
             $div->appendChild($h4);
             $div->appendChild($p);
             $right->appendChild($div);
         }
         ## Not Installed
         if (!empty($this->lists->status[Extension::STATUS_NOT_INSTALLED])) {
             $count = count($this->lists->status[Extension::STATUS_NOT_INSTALLED]);
             $div = $this->createElement('div');
             $div->setAttribute('class', 'tools');
             $h4 = $this->createElement('h4', __('Not Installed'));
             $message = __('%s %s %s not installed.', array($count, $count > 1 ? 'extensions' : 'extension', $count > 1 ? 'are' : 'is'));
             $p = $this->createElement('p', $message);
             $install = $this->createElement('button', __('Install All'));
             $install->setAttribute('class', 'create');
             $view = Widget::Anchor(__('View Details'), sprintf('%sstatus/%s/', $path, Extension::STATUS_NOT_INSTALLED));
             $view->setAttribute('class', 'button');
             $div->appendChild($install);
             $div->appendChild($view);
             $div->appendChild($h4);
             $div->appendChild($p);
             $right->appendChild($div);
         }
         ## Disabled
         if (!empty($this->lists->status[Extension::STATUS_DISABLED])) {
             $count = count($this->lists->status[Extension::STATUS_DISABLED]);
             $div = $this->createElement('div');
             $div->setAttribute('class', 'tools');
             $h4 = $this->createElement('h4', __('Disabled'));
             $message = __('%s %s %s disabled.', array($count, $count > 1 ? 'extensions' : 'extension', $count > 1 ? 'are' : 'is'));
             $p = $this->createElement('p', $message);
             $install = $this->createElement('button', __('Install All'));
             $install->setAttribute('class', 'create');
             $uninstall = $this->createElement('button', __('Uninstall All'));
             $uninstall->setAttribute('class', 'delete');
             $view = Widget::Anchor(__('View Details'), sprintf('%sstatus/%s/', $path, Extension::STATUS_DISABLED));
             $view->setAttribute('class', 'button');
             $div->appendChild($install);
             $div->appendChild($uninstall);
             $div->appendChild($view);
             $div->appendChild($h4);
             $div->appendChild($p);
             $right->appendChild($div);
         }
         ## Nothing to show
         if (empty($this->lists->status[Extension::STATUS_DISABLED]) && empty($this->lists->status[Extension::STATUS_NOT_INSTALLED])) {
             $div = $this->createElement('div');
             $div->setAttribute('class', 'tools');
             $p = $this->createElement('p', __('All of your extensions are installed and enabled.'));
             $view = $this->createElement('button', __('View Details'));
             $div->appendChild($view);
             $div->appendChild($p);
             $right->appendChild($div);
         }
     }
     $layout->appendTo($this->Form);
 }
Exemplo n.º 3
0
 public function __construct($flag = NULL, $value = NULL)
 {
     $this->position = 0;
     $key = null;
     if ($flag != null and $value != null) {
         $key = "{$flag}.{$value}";
     }
     if (!isset(self::$extensions_by_flag[$key])) {
         if (!is_array(self::$extensions_by_flag)) {
             self::$extensions_by_flag = array();
         }
         foreach (new DirectoryIterator(EXTENSIONS) as $d) {
             if (!$d->isDir() || $d->isDot() || !file_exists($d->getPathname() . '/extension.driver.php')) {
                 continue;
             }
             $extension = Extension::load($d->getFileName());
             if (!is_null($flag) && !is_null($value)) {
                 switch ($flag) {
                     case self::FLAG_STATUS:
                         if (!in_array(Extension::status($d->getFileName()), (array) $value)) {
                             continue 2;
                         }
                         break;
                     case self::FLAG_TYPE:
                         if (!isset($extension->about()->type) || (bool) array_intersect((array) $value, (array) $extension->about()->type) === false) {
                             continue 2;
                         }
                         break;
                 }
             }
             self::$extensions_by_flag[$key][] = $extension;
         }
     }
     $this->extensions = self::$extensions_by_flag[$key];
 }