Пример #1
0
 /**
  * Re-reads config and refreshes cache.
  *
  * @return  Yaml
  * @throws  Exception\LoaderException
  */
 protected function refreshCache()
 {
     $ext = new Extension();
     $ext->load();
     try {
         $yaml = Yaml::load(self::YAML_FILE);
     } catch (\Exception $e) {
         throw new Exception\LoaderException(sprintf('Could not load config. %s', $e->getMessage()));
     }
     $refSet = new \ReflectionMethod($yaml, 'set');
     $refSet->setAccessible(true);
     $before = clone $yaml;
     foreach ($ext as $key => $obj) {
         if (property_exists($obj, 'default') && (!$yaml->defined($key) || $yaml($key) === null)) {
             //Set defaults only in the case it is provided in the Extension.
             //Set defaults only if they are not overriden in config and not null.
             $refSet->invoke($yaml, $key, $obj->default);
         }
         //Checks if at least one from all parents is not required.
         $token = $key;
         while (strpos($token, '.')) {
             $token = preg_replace('/\\.[^\\.]+$/', '', $token);
             //Parent bag is not required
             if (!$ext->defined($token)) {
                 //And it is not defined in config
                 if (!$before->defined($token)) {
                     continue 2;
                 } else {
                     //check presence of nodes if it is defined in config
                     break;
                 }
             }
         }
         if (!$yaml->defined($key)) {
             //If, after all, value has not been defined in the Extension, it is considered as user error.
             throw new Exception\LoaderException(sprintf('Parameter "%s" must be defined in the config', $key));
         }
     }
     unset($before);
     //serialize yaml
     file_put_contents(self::YAML_CACHE_FILE, serialize($yaml));
     @chmod(self::YAML_CACHE_FILE, 0666);
     return $yaml;
 }
 public function action()
 {
     if (isset($_POST['items'])) {
         $checked = array_keys($_POST['items']);
     }
     try {
         if (isset($_POST['action']['apply']) && isset($_POST['with-selected']) && is_array($checked) && !empty($checked)) {
             $action = $_POST['with-selected'];
             if (method_exists('Extension', $action)) {
                 ###
                 # Delegate: {name of the action} (enable|disable|uninstall)
                 # Description: Notifies of enabling, disabling or uninstalling of an Extension. Array of selected extensions is provided.
                 #              This can be modified.
                 Extension::notify($action, getCurrentPage(), array('extensions' => &$checked));
                 foreach ($checked as $handle) {
                     call_user_func(array('Extension', $action), $handle);
                 }
             }
             redirect(Administration::instance()->getCurrentPageURL());
         } elseif (isset($_POST['action'])) {
             $action = end(array_keys($_POST['action']));
             $handle = end(array_keys($_POST['action'][$action]));
             if (method_exists('Extension', $action)) {
                 ###
                 # Delegate: {name of the action} (enable|disable|uninstall)
                 # Description: Notifies of enabling, disabling or uninstalling of an Extension. Extension handle is provided
                 #              This can be modified.
                 Extension::notify($action, getCurrentPage(), array('extensions' => &$handle));
                 call_user_func(array('Extension', $action), $handle);
                 redirect(Administration::instance()->getCurrentPageURL());
             }
         }
     } catch (ExtensionException $e) {
         $extension = Extension::load($handle);
         $about = $extension->about();
         switch ($action) {
             case 'enable':
                 $message = "%s could not be enabled. <a class='more'>Show more information.</a>";
                 break;
             case 'disable':
                 $message = "%s could not be disabled. <a class='more'>Show more information.</a>";
                 break;
             case 'uninstall':
                 $message = "%s could not be uninstalled. <a class='more'>Show more information.</a>";
                 break;
         }
         $this->alerts()->append(__($message, array(isset($about) ? $about->{'name'} : $name)), AlertStack::ERROR, $e);
         return false;
     }
 }
Пример #3
0
 public function __construct()
 {
     $this->driver = Extension::load('members');
     $this->_about = new StdClass();
     $this->_parameters = (object) array('root-element' => null, 'section' => null, 'overrides' => array(), 'defaults' => array());
 }
Пример #4
0
 public function buildFilterQuery($filter, &$joins, array &$where, Register $parameter_output)
 {
     $driver = Extension::load('members');
     $filter = $this->processFilter($filter);
     $filter_join = DataSource::FILTER_OR;
     $db = Symphony::Database();
     $values = DataSource::prepareFilterValue($filter->value, $parameter_output, $filter_join);
     if (!is_array($values)) {
         $values = array();
     }
     // Exact matches:
     if ($filter->type == 'is' or $filter->type == 'is-not') {
         $statements = array();
         if ($filter_join == DataSource::FILTER_OR) {
             $handle = $this->buildFilterJoin($joins);
         }
         foreach ($values as $index => $value) {
             if ($filter_join != DataSource::FILTER_OR) {
                 $handle = $this->buildFilterJoin($joins);
             }
             $statements[] = $db->prepareQuery("{$handle}.password = '******' OR {$handle}.code = '%s'", array(sha1($value), $driver->extractToken($value, 'login')));
         }
         if (empty($statements)) {
             return true;
         }
         if ($filter_join == DataSource::FILTER_OR) {
             $statement = "(\n\t" . implode("\n\tOR ", $statements) . "\n)";
         } else {
             $statement = "(\n\t" . implode("\n\tAND ", $statements) . "\n)";
         }
         if ($filter->type == 'is-not') {
             $statement = 'NOT ' . $statement;
         }
         $where[] = $statement;
     }
     return true;
 }
Пример #5
0
 public function prepareTableValue(StdClass $data = null, DOMElement $wrapper = null, Entry $entry = null)
 {
     $result = (object) array('value' => null);
     if (isset($data->joined_id)) {
         try {
             $document = $wrapper->ownerDocument;
             $driver = Extension::load('field_join');
             $driver->addPublishHeaders($document);
             $joined = Entry::loadFromId($data->joined_id);
             $section = Section::loadFromHandle($joined->section);
             $wrapper->addClass('field-join');
             $wrapper->setValue($section->name);
             /*
             $more = $document->createElement('span');
             $more->addClass('more');
             $more->setValue(__('More'));
             $wrapper->appendChild($more);
             
             // Build data array:
             $content = $document->createElement('div');
             $more->appendChild($content);
             
             foreach ($section->layout as $column) {
             	foreach ($column->fieldsets as $fieldset) {
             		$group = $document->createElement('div');
             		$group->addClass('list');
             		$content->appendChild($group);
             		
             		if ($fieldset->name) $group->appendChild(
             			$document->createElement('h5', $fieldset->name)
             		);
             		
             		$list = $document->createElement('dl');
             		$group->appendChild($list);
             		
             		foreach ($fieldset->fields as $field_handle) {
             			$field = $section->fetchFieldByHandle($field_handle);
             			
             			$title = $document->createElement('dt', $field->{'publish-label'});
             			$list->appendChild($title);
             			$item = $document->createElement('dd');
             			$list->appendChild($item);
             			
             			$value = $field->prepareTableValue(
             				$joined->data()->{$field_handle},
             				$item, $joined
             			);
             		}
             	}
             }
             */
             return $wrapper;
         } catch (Exception $e) {
             // Keep the null value set above.
         }
     }
     return parent::prepareTableValue($result, $link, $entry);
 }
Пример #6
0
 public function appendFormattedElement(&$wrapper, $data, $mode = null)
 {
     $driver = Extension::load('members');
     if ($mode == 'unformatted') {
         $value = trim($data->value);
     } else {
         $mode = 'formatted';
         $value = trim($data->value_formatted);
     }
     $result = $wrapper->ownerDocument->createElement($this->{'element-name'});
     if ($mode == 'unformatted') {
         $value = $wrapper->ownerDocument->createCDATASection($value);
         $result->appendChild($value);
     } else {
         if ($value) {
             $value = $driver->repairEntities($value);
             $fragment = $wrapper->ownerDocument->createDocumentFragment();
             $fragment->appendXML($value);
             $result->appendChild($fragment);
         }
     }
     $attributes = array('mode' => $mode, 'handle' => $data->handle);
     if ($this->{'text-handle'} != 'yes') {
         unset($attributes['handle']);
     }
     foreach ($attributes as $name => $value) {
         $result->setAttribute($name, $value);
     }
     $wrapper->appendChild($result);
 }
Пример #7
0
 public function appendFormattedElement(&$wrapper, $data, $mode = null)
 {
     $driver = Extension::load('members');
     $result = $wrapper->ownerDocument->createElement($this->{'element-name'});
     $value = $driver->repairEntities(trim($data->value));
     if ($value) {
         $fragment = $wrapper->ownerDocument->createDocumentFragment();
         $fragment->appendXML($value);
         $result->appendChild($fragment);
     }
     $wrapper->appendChild($result);
 }
Пример #8
0
 public function displayPublishPanel(SymphonyDOMElement $wrapper, MessageStack $errors, Entry $entry = null, $data = null)
 {
     /*if (!$errors->valid() and !is_writable(DOCROOT . $this->destination . '/')) {
     			$errors->append(
     				null, (object)array(
     				 	'message' => __(
     				 		'Destination folder, "%s", is not writable. Please check permissions.',
     				 		array(trim($this->destination, '/'))
     				 	),
     					'code' => self::ERROR_INVALID
     				)
     			);
     		}*/
     $driver = Extension::load('field_upload');
     $driver->addHeaders();
     $handle = $this->{'element-name'};
     $document = $wrapper->ownerDocument;
     $filepath = null;
     if (isset($data->path, $data->file)) {
         $filepath = DOCROOT . '/' . trim($data->path, '/') . '/' . $data->file;
     }
     // Preview ------------------------------------------------------------
     $label = $document->createElement('div', isset($this->{'publish-label'}) && strlen(trim($this->{'publish-label'})) > 0 ? $this->{'publish-label'} : $this->name);
     $label->setAttribute('class', 'label');
     if ($this->required != 'yes') {
         $label->appendChild($document->createElement('em', 'Optional'));
     }
     if (!$errors->valid() and $data->file) {
         $file = $document->createElement('div');
         $file->setAttribute('class', 'file');
         $path = substr($filepath, strlen(DOCROOT));
         ###
         # Delegate: UploadField_PreviewFile
         # Description: Allow other extensions to add media previews.
         Extension::notify('UploadField_PreviewFile', '/publish/', array('data' => $data, 'field' => $this, 'entry' => $entry, 'wrapper' => $wrapper));
         if (!is_file($filepath)) {
             $errors->append(null, (object) array('message' => __('Destination file could not be found.'), 'code' => self::ERROR_MISSING));
         }
         $name = $document->createElement('p');
         $link = Widget::Anchor($data->{'name'}, URL . $path);
         $name->appendChild($link);
         $file->appendChild($name);
         $list = $document->createElement('dl');
         $list->appendChild($document->createElement('dt', __('Size:')));
         $list->appendChild($document->createElement('dd', General::formatFilesize($data->size)));
         $list->appendChild($document->createElement('dt', __('Type:')));
         $list->appendChild($document->createElement('dd', $data->type));
         // Meta data:
         if ($meta = unserialize($data->meta) and is_array($meta)) {
             $meta = (object) $meta;
         }
         if (isset($meta->width, $meta->height)) {
             $list->appendChild($document->createElement('dt', __('Width:')));
             $list->appendChild($document->createElement('dd', sprintf('%dpx', $meta->width)));
             $list->appendChild($document->createElement('dt', __('Height:')));
             $list->appendChild($document->createElement('dd', sprintf('%dpx', $meta->height)));
         }
         $file->appendChild($list);
         $label->appendChild($file);
     }
     // Upload -------------------------------------------------------------
     $upload = $document->createElement('div');
     $upload->setAttribute('class', 'upload');
     if (!is_writable(DOCROOT . $this->destination . '/')) {
         $upload->setValue(__('Destination folder, "%s", is not writable. Please check permissions.', array(trim($this->destination, '/'))));
     } else {
         $input = Widget::Input("fields[{$handle}]", $filepath, $filepath ? 'hidden' : 'file');
         $upload->appendChild($input);
     }
     $label->appendChild($upload);
     if ($errors->valid()) {
         $label = Widget::wrapFormElementWithError($label, $errors->current()->message);
     }
     $wrapper->appendChild($label);
 }
Пример #9
0
 public function displayPublishPanel(SymphonyDOMElement $wrapper, MessageStack $errors, Entry $entry = NULL, $data = NULL)
 {
     $document = $wrapper->ownerDocument;
     $driver = Extension::load('field_textbox');
     $driver->addPublishHeaders($document);
     $sortorder = $this->{'sortorder'};
     $element_name = $this->{'element-name'};
     $classes = array();
     $label = Widget::Label(isset($this->{'publish-label'}) && strlen(trim($this->{'publish-label'})) > 0 ? $this->{'publish-label'} : $this->name);
     $optional = '';
     if ($this->{'required'} != 'yes') {
         if ((int) $this->{'text-length'} > 0) {
             $optional = $document->createDocumentFragment();
             $optional->appendChild($document->createTextNode(__('$1 of $2 remaining') . ' '));
             $optional->appendChild($document->createEntityReference('ndash'));
             $optional->appendChild($document->createTextNode(' ' . __('Optional')));
         } else {
             $optional = __('Optional');
         }
     } else {
         if ((int) $this->{'text-length'} > 0) {
             $optional = __('$1 of $2 remaining');
         }
     }
     if ($optional) {
         $label->appendChild($wrapper->ownerDocument->createElement('em', $optional));
     }
     // Input box:
     if ($this->{'text-size'} == 'single') {
         $input = Widget::Input("fields[{$element_name}]", $data->value);
         ###
         # Delegate: ModifyTextBoxInlineFieldPublishWidget
         # Description: Allows developers modify the textbox before it is rendered in the publish forms
         $delegate = 'ModifyTextBoxInlineFieldPublishWidget';
     } else {
         $input = Widget::Textarea("fields[{$element_name}]", $data->value, array('rows' => 20, 'cols' => 50));
         ###
         # Delegate: ModifyTextBoxFullFieldPublishWidget
         # Description: Allows developers modify the textbox before it is rendered in the publish forms
         $delegate = 'ModifyTextBoxFullFieldPublishWidget';
     }
     // Add classes:
     $classes[] = 'size-' . $this->{'text-size'};
     if ($this->{'text-formatter'} != 'none') {
         $classes[] = $this->{'text-formatter'};
     }
     $input->setAttribute('class', implode(' ', $classes));
     $input->setAttribute('length', (int) $this->{'text-length'});
     Extension::notify($delegate, '/administration/', array('field' => &$this, 'label' => &$label, 'input' => &$input));
     if (is_null($label)) {
         return;
     }
     $label->appendChild($input);
     if ($errors->valid()) {
         $label = Widget::wrapFormElementWithError($label, $errors->current()->message);
     }
     $wrapper->appendChild($label);
 }
Пример #10
0
 public function __construct()
 {
     parent::__construct();
     $this->driver = Extension::load('aac');
     $this->errors = new MessageStack();
 }
Пример #11
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];
 }