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);
     }
 }
Ejemplo n.º 2
0
 protected static function __find($name)
 {
     if (is_file(DATASOURCES . "/{$name}.php")) {
         return DATASOURCES;
     } else {
         foreach (new ExtensionIterator(ExtensionIterator::FLAG_STATUS, Extension::STATUS_ENABLED) as $extension) {
             $path = Extension::getPathFromClass(get_class($extension));
             $handle = Extension::getHandleFromPath($path);
             if (is_file(EXTENSIONS . "/{$handle}/data-sources/{$name}.php")) {
                 return EXTENSIONS . "/{$handle}/data-sources";
             }
         }
         /*
         $extensions = ExtensionManager::instance()->listInstalledHandles();
         
         if(is_array($extensions) && !empty($extensions)){
         	foreach($extensions as $e){
         		if(is_file(EXTENSIONS . "/{$e}/data-sources/{$name}.php")) return EXTENSIONS . "/{$e}/data-sources";
         	}
         }
         */
     }
     return false;
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 protected static function __find($type)
 {
     if (array_key_exists($type, self::$find_cache)) {
         return self::$find_cache[$type];
     }
     foreach (new ExtensionIterator(ExtensionIterator::FLAG_STATUS, Extension::STATUS_ENABLED) as $e) {
         $path = Extension::getPathFromClass(get_class($e));
         if (is_file("{$path}/fields/field.{$type}.php")) {
             self::$find_cache[$type] = "{$path}/fields";
             return self::$find_cache[$type];
         }
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * Get codes of available languages
  *
  * Return all available languages (core and extensions)
  * @return array language codes, e. g. 'en'
  */
 public static function getAvailableLanguages($includeExtensions = false)
 {
     $languages = array();
     // Get core translation files
     $languages = self::getLanguageCodes(LANG, $languages);
     // Get extension translation files
     if ($includeExtensions) {
         foreach (new ExtensionIterator(ExtensionIterator::FLAG_STATUS, Extension::STATUS_ENABLED) as $extension) {
             $path = Extension::getPathFromClass(get_class($extension)) . '/lang';
             if (file_exists($path)) {
                 $languages = self::getLanguageCodes($path, $languages);
             }
         }
         /*				foreach (ExtensionManager::instance()->listAll() as $extension => $about) {
         					$path = EXTENSIONS . '/' . $about['handle'] . '/lang';
         					if(file_exists($path)) $languages = self::getLanguageCodes($path, $languages);
         				}
         */
     }
     // Return languages codes
     return $languages;
 }
Ejemplo n.º 6
0
 protected static function __find($type)
 {
     //		$extensions = ExtensionManager::instance()->listInstalledHandles();
     //		if(is_array($extensions) && !empty($extensions)){
     //			foreach($extensions as $e){
     //				if(is_file(EXTENSIONS . "/{$e}/fields/field.{$type}.php")) return EXTENSIONS . "/{$e}/fields";
     //			}
     //		}
     foreach (new ExtensionIterator(ExtensionIterator::FLAG_STATUS, Extension::STATUS_ENABLED) as $e) {
         $path = Extension::getPathFromClass(get_class($e));
         if (is_file("{$path}/fields/field.{$type}.php")) {
             return "{$path}/fields";
         }
     }
     return false;
 }
Ejemplo n.º 7
0
 protected function __buildNavigation()
 {
     $nav = array();
     $xml = simplexml_load_file(ASSETS . '/navigation.xml');
     foreach ($xml->xpath('/navigation/group') as $n) {
         $index = (string) $n->attributes()->index;
         $children = $n->xpath('children/item');
         $content = $n->attributes();
         if (isset($nav[$index])) {
             do {
                 $index++;
             } while (isset($nav[$index]));
         }
         $nav[$index] = array('name' => __(strval($content->name)), 'index' => $index, 'children' => array());
         if (strlen(trim((string) $content->limit)) > 0) {
             $nav[$index]['limit'] = (string) $content->limit;
         }
         if (count($children) > 0) {
             foreach ($children as $child) {
                 $limit = (string) $child->attributes()->limit;
                 $item = array('link' => (string) $child->attributes()->link, 'name' => __(strval($child->attributes()->name)), 'visible' => (string) $child->attributes()->visible == 'no' ? 'no' : 'yes');
                 if (strlen(trim($limit)) > 0) {
                     $item['limit'] = $limit;
                 }
                 $nav[$index]['children'][] = $item;
             }
         }
     }
     foreach (new SectionIterator() as $s) {
         $group_index = self::__navigationFindGroupIndex($nav, $s->{'navigation-group'});
         if ($group_index === false) {
             $group_index = General::array_find_available_index($nav, 0);
             $nav[$group_index] = array('name' => $s->{'navigation-group'}, 'index' => $group_index, 'children' => array(), 'limit' => NULL);
         }
         $nav[$group_index]['children'][] = array('link' => '/publish/' . $s->handle . '/', 'name' => $s->name, 'type' => 'section', 'section' => array('id' => $s->guid, 'handle' => $s->handle), 'visible' => $s->{'hidden-from-publish-menu'} == 'no' ? 'yes' : 'no');
     }
     //			$extensions = ExtensionManager::instance()->listInstalledHandles();
     foreach (new ExtensionIterator(ExtensionIterator::FLAG_STATUS, Extension::STATUS_ENABLED) as $e) {
         if (!method_exists($e, 'fetchNavigation')) {
             continue;
         }
         $e_navigation = $e->fetchNavigation();
         if (isset($e_navigation) && is_array($e_navigation) && !empty($e_navigation)) {
             foreach ($e_navigation as $item) {
                 $type = isset($item['children']) ? Extension::NAVIGATION_GROUP : Extension::NAVIGATION_CHILD;
                 switch ($type) {
                     case Extension::NAVIGATION_GROUP:
                         $index = General::array_find_available_index($nav, $item['location']);
                         $nav[$index] = array('name' => $item['name'], 'index' => $index, 'children' => array(), 'limit' => !is_null($item['limit']) ? $item['limit'] : NULL);
                         foreach ($item['children'] as $child) {
                             if (!isset($child['relative']) || $child['relative'] == true) {
                                 $link = '/extension/' . Extension::getHandleFromPath(Extension::getPathFromClass(get_class($e))) . '/' . ltrim($child['link'], '/');
                             } else {
                                 $link = '/' . ltrim($child['link'], '/');
                             }
                             $nav[$index]['children'][] = array('link' => $link, 'name' => $child['name'], 'visible' => $child['visible'] == 'no' ? 'no' : 'yes', 'limit' => !is_null($child['limit']) ? $child['limit'] : NULL);
                         }
                         break;
                     case Extension::NAVIGATION_CHILD:
                         if (!isset($item['relative']) || $item['relative'] == true) {
                             $link = '/extension/' . Extension::getHandleFromPath(Extension::getPathFromClass(get_class($e))) . '/' . ltrim($item['link'], '/');
                         } else {
                             $link = '/' . ltrim($item['link'], '/');
                         }
                         if (!is_numeric($item['location'])) {
                             // is a navigation group
                             $group_name = $item['location'];
                             $group_index = $this->__findLocationIndexFromName($nav, $item['location']);
                         } else {
                             // is a legacy numeric index
                             $group_index = $item['location'];
                         }
                         $child = array('link' => $link, 'name' => $item['name'], 'visible' => $item['visible'] == 'no' ? 'no' : 'yes', 'limit' => !is_null($item['limit']) ? $item['limit'] : NULL);
                         if ($group_index === false) {
                             // add new navigation group
                             $nav[] = array('name' => $group_name, 'index' => $group_index, 'children' => array($child), 'limit' => !is_null($item['limit']) ? $item['limit'] : NULL);
                         } else {
                             // add new location by index
                             $nav[$group_index]['children'][] = $child;
                         }
                         break;
                 }
             }
         }
     }
     ####
     # Delegate: ExtensionsAddToNavigation
     # Description: After building the Navigation properties array. This is specifically
     # 			for extentions to add their groups to the navigation or items to groups,
     # 			already in the navigation. Note: THIS IS FOR ADDING ONLY! If you need
     #			to edit existing navigation elements, use the 'NavigationPreRender' delegate.
     # Global: Yes
     Extension::notify('ExtensionsAddToNavigation', '/administration/', array('navigation' => &$nav));
     $pageCallback = Administration::instance()->getPageCallback();
     $pageRoot = $pageCallback['pageroot'] . (isset($pageCallback['context'][0]) ? $pageCallback['context'][0] . '/' : '');
     $found = $this->__findActiveNavigationGroup($nav, $pageRoot);
     ## Normal searches failed. Use a regular expression using the page root. This is less
     ## efficent and should never really get invoked unless something weird is going on
     if (!$found) {
         $this->__findActiveNavigationGroup($nav, '/^' . str_replace('/', '\\/', $pageCallback['pageroot']) . '/i', true);
     }
     ksort($nav);
     $this->_navigation = $nav;
 }
Ejemplo n.º 8
0
 protected static function __find($name)
 {
     if (is_file(SECTIONS . "/{$name}.xml")) {
         return SECTIONS;
     } else {
         foreach (new ExtensionIterator(ExtensionIterator::FLAG_STATUS, Extension::STATUS_ENABLED) as $extension) {
             $path = Extension::getPathFromClass(get_class($extension));
             $handle = Extension::getHandleFromPath($path);
             if (!is_file(EXTENSIONS . "/{$handle}/sections/{$name}.xml")) {
                 continue;
             }
             return EXTENSIONS . "/{$handle}/sections";
         }
     }
     return false;
 }