Capability.php
9 years ago
LoginRedirect.php
9 years ago
Menu.php
9 years ago
Metabox.php
9 years ago
Post.php
9 years ago
Redirect.php
9 years ago
Teaser.php
9 years ago
Teaser.php
124 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Teaser object |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @author Vasyl Martyniuk <vasyl@vasyltech.com> |
| 15 | */ |
| 16 | class AAM_Core_Object_Teaser extends AAM_Core_Object { |
| 17 | |
| 18 | /** |
| 19 | * Constructor |
| 20 | * |
| 21 | * @param AAM_Core_Subject $subject |
| 22 | * |
| 23 | * @return void |
| 24 | * |
| 25 | * @access public |
| 26 | */ |
| 27 | public function __construct(AAM_Core_Subject $subject) { |
| 28 | parent::__construct($subject); |
| 29 | |
| 30 | $this->read(); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * |
| 35 | * @return void |
| 36 | * |
| 37 | * @access public |
| 38 | */ |
| 39 | public function read() { |
| 40 | $option = $this->getSubject()->readOption('teaser'); |
| 41 | |
| 42 | //inherit from default Administrator role |
| 43 | if (empty($option)) { |
| 44 | //inherit from parent subject |
| 45 | $option = $this->getSubject()->inheritFromParent('teaser'); |
| 46 | if (empty($option)) { |
| 47 | $option = array(); |
| 48 | $this->readByArea('frontend', $option); |
| 49 | } |
| 50 | } elseif (method_exists($this, 'setOverwritten')) { //TODO - Support legacy |
| 51 | $this->setOverwritten(true); |
| 52 | } |
| 53 | |
| 54 | $this->setOption($option); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * |
| 59 | * @param type $area |
| 60 | * @param type $option |
| 61 | */ |
| 62 | protected function readByArea($area, &$option) { |
| 63 | $message = AAM_Core_Config::get("{$area}.teaser.message"); |
| 64 | $excerpt = AAM_Core_Config::get("{$area}.teaser.excerpt"); |
| 65 | if ($message || $excerpt) { |
| 66 | $option["{$area}.teaser.message"] = $message; |
| 67 | $option["{$area}.teaser.excerpt"] = $excerpt; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Save options |
| 73 | * |
| 74 | * @param string $property |
| 75 | * @param boolean $value |
| 76 | * |
| 77 | * @return boolean |
| 78 | * |
| 79 | * @access public |
| 80 | */ |
| 81 | public function save($property, $value) { |
| 82 | $option = $this->getOption(); |
| 83 | $option[$property] = $value; |
| 84 | |
| 85 | return $this->getSubject()->updateOption($option, 'teaser'); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * |
| 90 | * @return type |
| 91 | */ |
| 92 | public function reset() { |
| 93 | return $this->getSubject()->deleteOption('teaser'); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * |
| 98 | * @param string $param |
| 99 | * |
| 100 | * @return boolean |
| 101 | * |
| 102 | * @access public |
| 103 | */ |
| 104 | public function has($param) { |
| 105 | $option = $this->getOption(); |
| 106 | |
| 107 | return isset($option[$param]); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * |
| 112 | * @param string $param |
| 113 | * |
| 114 | * @return boolean |
| 115 | * |
| 116 | * @access public |
| 117 | */ |
| 118 | public function get($param) { |
| 119 | $option = $this->getOption(); |
| 120 | |
| 121 | return !empty($option[$param]) ? $option[$param] : null; |
| 122 | } |
| 123 | |
| 124 | } |