"Fossies" - the Fresh Open Source Software Archive

Member "papayacms-core-6.9.4/src/modules/_base/Article.php" (13 Dec 2019, 4609 Bytes) of package /linux/www/papayacms-core-6.9.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Article.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Papaya\Modules\Core {
    4 
    5   use Papaya\Administration\Plugin\Editor\Dialog as PluginDialog;
    6   use Papaya\Cache\Identifier\Definition\Page as PageCacheDefinition;
    7   use Papaya\Plugin;
    8   use Papaya\Plugin\Appendable as AppendablePlugin;
    9   use Papaya\Plugin\Cacheable as CacheablePlugin;
   10   use Papaya\Plugin\Configurable\Context as ContextAwarePlugin;
   11   use Papaya\Plugin\Configurable\Options as ConfigurableOptionsPlugin;
   12   use Papaya\Plugin\Editable as EditablePlugin;
   13   use Papaya\Template\Tag\Image as ImageTag;
   14   use Papaya\UI\Dialog\Field as DialogField;
   15   use Papaya\Plugin\Editor as PluginEditor;
   16   use Papaya\Plugin\Filter as PluginFilter;
   17   use Papaya\UI\Text\Translated as TranslatedText;
   18   use Papaya\UI\Text\Translated\Collection as TranslatedList;
   19   use Papaya\XML\Element as XMLElement;
   20 
   21   class Article
   22     extends Partials\Teaser
   23     implements AppendablePlugin, ContextAwarePlugin, CacheablePlugin, ConfigurableOptionsPlugin {
   24 
   25     use ContextAwarePlugin\Aggregation;
   26     use CacheablePlugin\Aggregation;
   27     use PluginFilter\Aggregation;
   28     use EditablePlugin\Options\Aggregation;
   29 
   30     const FIELD_TEXT = 'text';
   31     const FIELD_CATCH_LINE_TITLE = 'catch-line-title';
   32     const FIELD_CATCH_LINE_TEXT = 'catch-line-text';
   33 
   34     const OPTION_CATCH_LINE_ENABLED = 'OPTION_CATCH_LINE_ENABLED';
   35 
   36     const _DEFAULTS = [
   37       self::FIELD_TITLE => '',
   38       self::FIELD_SUBTITLE => '',
   39       self::FIELD_OVERLINE => '',
   40       self::FIELD_IMAGE => '',
   41       self::FIELD_TEASER => '',
   42       self::FIELD_TEXT => '',
   43       self::FIELD_CATCH_LINE_TITLE => '',
   44       self::FIELD_CATCH_LINE_TEXT => ''
   45     ];
   46 
   47     /**
   48      * @param EditablePlugin\Content $content
   49      *
   50      * @return PluginEditor|PluginDialog
   51      */
   52     public function createEditor(EditablePlugin\Content $content) {
   53       $editor = parent::createEditor($content);
   54       $dialog = $editor->dialog();
   55       $dialog->fields[] = new DialogField\Textarea\Richtext(
   56         new TranslatedText('Text'),
   57         self::FIELD_TEXT,
   58         20,
   59         self::_DEFAULTS[self::FIELD_TEXT]
   60       );
   61       if ($this->options()->get(self::OPTION_CATCH_LINE_ENABLED, FALSE)) {
   62         $dialog->fields[] = $group = new DialogField\Group(new TranslatedText('Catch-Line'));
   63         $group->fields[] = new DialogField\Input(
   64           new TranslatedText('Title'),
   65           self::FIELD_CATCH_LINE_TITLE,
   66           -1,
   67           self::_DEFAULTS[self::FIELD_CATCH_LINE_TITLE]
   68         );
   69         $group->fields[] = new DialogField\Input(
   70           new TranslatedText('Text'),
   71           self::FIELD_CATCH_LINE_TEXT,
   72           -1,
   73           self::_DEFAULTS[self::FIELD_CATCH_LINE_TEXT]
   74         );
   75       }
   76       return $editor;
   77     }
   78 
   79     /**
   80      * Create dom node structure of the given object and append it to the given xml
   81      * element node.
   82      *
   83      * @param XMLElement $parent
   84      */
   85     public function appendTo(XMLElement $parent) {
   86       $content = $this->content()->withDefaults(self::_DEFAULTS);
   87       $filters = $this->filters();
   88       $filters->prepare(
   89         $content[self::FIELD_TEXT],
   90         $this->configuration()
   91       );
   92       $parent->appendElement('overline', $content[self::FIELD_OVERLINE]);
   93       $parent->appendElement('title', $content[self::FIELD_TITLE]);
   94       $parent->appendElement('subtitle', $content[self::FIELD_SUBTITLE]);
   95       $parent->appendElement('teaser')->appendXML($content[self::FIELD_TEASER]);
   96       $parent->appendElement('image')->append(new ImageTag($content[self::FIELD_IMAGE]));
   97       if ($this->options()->get(self::OPTION_CATCH_LINE_ENABLED, FALSE)) {
   98         $catchLine = $parent->appendElement('catch-line');
   99         $catchLine->appendElement('title', $content[self::FIELD_CATCH_LINE_TITLE]);
  100         $catchLine->appendElement('text', $content[self::FIELD_CATCH_LINE_TEXT]);
  101       }
  102       $parent->appendElement('text')->appendXML(
  103         $filters->applyTo($content[self::FIELD_TEXT])
  104       );
  105       $parent->append($filters);
  106     }
  107 
  108     public function createCacheDefinition() {
  109       return new PageCacheDefinition();
  110     }
  111 
  112     /**
  113      * @param EditablePlugin\Options $options
  114      *
  115      * @return PluginEditor
  116      */
  117     public function createOptionsEditor(Plugin\Editable\Options $options) {
  118       $editor = new PluginDialog($options);
  119       $dialog = $editor->dialog();
  120       $dialog->fields[] = $field = new DialogField\Select\Radio(
  121         new TranslatedText('Enable Catch-Line'),
  122         self::OPTION_CATCH_LINE_ENABLED,
  123           new TranslatedList([TRUE => 'Yes', FALSE => 'No']
  124         )
  125       );
  126       $field->setDefaultValue(FALSE);
  127       return $editor;
  128     }
  129   }
  130 }