public function set($key, $value)
 {
     if ($key == 'lat' || $key == 'lng') {
         // if value isn't numeric, then it's not valid: make it blank
         if (strpos($value, ',') !== false) {
             $value = str_replace(',', '.', $value);
         }
         // convert 123,456 to 123.456
         if (!is_numeric($value)) {
             $value = '';
         }
     } else {
         if ($key == 'address') {
             $value = wire('sanitizer')->text($value);
         } else {
             if ($key == 'status') {
                 $value = (int) $value;
                 if (!isset($this->geocodeStatuses[$value])) {
                     $value = -1;
                 }
                 // -1 = unknown
             } else {
                 if ($key == 'zoom') {
                     $value = (int) $value;
                 }
             }
         }
     }
     return parent::set($key, $value);
 }
 /**
  * Set a native setting or a dynamic data property for this Field
  *
  */
 public function set($key, $value)
 {
     if ($key == 'name') {
         return $this->setName($value);
     } else {
         if ($key == 'type' && $value) {
             return $this->setFieldtype($value);
         } else {
             if ($key == 'prevTable') {
                 $this->prevTable = $value;
                 return $this;
             } else {
                 if ($key == 'prevFieldtype') {
                     $this->prevFieldtype = $value;
                     return $this;
                 } else {
                     if (in_array($key, array('id', 'flags'))) {
                         $value = (int) $value;
                     }
                 }
             }
         }
     }
     if (isset($this->settings[$key])) {
         $this->settings[$key] = $value;
     } else {
         return parent::set($key, $value);
     }
     return $this;
 }
Example #3
0
 public function set($key, $value)
 {
     if ($key == 'fieldChanges') {
         // convert string changes list of field names to array
         if (is_array($value)) {
             if (!trim(implode('', $value))) {
                 $value = array();
             }
         } else {
             $value = explode(' ', $value);
         }
         // sanitize
         foreach ($value as $k => $v) {
             $required = strpos($v, '+') === 0;
             if ($required) {
                 $v = ltrim($v, '+');
             }
             $v = $this->wire('sanitizer')->fieldName($v);
             if (empty($v)) {
                 continue;
             }
             $value[$k] = ($required ? '+' : '') . $v;
         }
     }
     return parent::set($key, $value);
 }
 public function set($key, $value)
 {
     if (strpos($key, 'title') === 0 || strpos($key, 'value') === 0) {
         if (strpos($value, '|') !== false) {
             $this->error("{$key} may not contain the character '|'");
             $value = str_replace('|', ' ', $value);
         }
     }
     return parent::set($key, $value);
 }
 public function set($key, $value)
 {
     if ($key == 'id' || $key == 'modules_id') {
         $value = (int) $value;
     } else {
         if ($key == 'name') {
             $value = $this->fuel('sanitizer')->name($value);
         }
     }
     return parent::set($key, $value);
 }
 /**
  * Set a value to the ImageMarker: date, location or notes
  *
  */
 public function set($key, $value)
 {
     if ($key == 'page') {
         $this->page = $value;
         return $this;
     } else {
         if ($key == 'info' || $key == 'x' || $key == 'y') {
             // int sanitizer
             $value = (int) $value;
         }
     }
     return parent::set($key, $value);
 }
 /**
  * Set a config field that is shared in Javascript, OR retrieve one or all params already set
  *
  * Specify only a $key and omit the $value in order to retrieve an existing set value.
  * Specify no params to retrieve in array of all existing set values.
  *
  * @param string $key 
  * @param mixed $value
  *
  */
 public function js($key = null, $value = null)
 {
     if (is_null($key)) {
         $data = array();
         foreach ($this->jsFields as $field) {
             $data[$field] = $this->get($field);
         }
         return $data;
     } else {
         if (is_null($value)) {
             return in_array($key, $this->jsFields) ? $this->get($key) : null;
         }
     }
     $this->jsFields[] = $key;
     return parent::set($key, $value);
 }
 /**
  * Set a user setting or data value
  *
  */
 public function set($key, $value)
 {
     if ($key == 'id') {
         $value = (int) $value;
     } else {
         if ($key == 'name') {
             $value = $this->fuel('sanitizer')->username($value);
         }
     }
     if (isset($this->settings[$key])) {
         if ($this->settings[$key] != $value) {
             $this->trackChange($key);
         }
         $this->settings[$key] = $value;
     } else {
         parent::set($key, $value);
     }
     return $this;
 }
Example #9
0
 /**
  * Set a value to the event: date, location or notes
  *
  */
 public function set($key, $value)
 {
     if ($key == 'page') {
         $this->page = $value;
         return $this;
     } else {
         if ($key == 'date') {
             // convert date string to unix timestamp
             if ($value && !ctype_digit("{$value}")) {
                 $value = strtotime($value);
             }
             // sanitized date value is always an integer
             $value = (int) $value;
         } else {
             if ($key == 'location' || $key == 'notes') {
                 // regular text sanitizer
                 $value = $this->sanitizer->text($value);
             }
         }
     }
     return parent::set($key, $value);
 }
 public function set($key, $value)
 {
     if ($key == 'action') {
         if (!in_array($value, array('+', '-'))) {
             throw new WireException("PageRole::action must be either '+' or '-'");
         }
     } else {
         if ($key == 'pages_id') {
             $value = (int) $value;
             $this->page = null;
         } else {
             if ($key == 'roles_id') {
                 $value = (int) $value;
                 $this->role = null;
             } else {
                 if ($key == 'page' && $value instanceof Page) {
                     if (!$this->page || !$this->page->id || $value->id != $this->page->id) {
                         $this->trackChange('page');
                     }
                     $this->page = $value;
                     return $this;
                 } else {
                     if ($key == 'role' && $value instanceof Role) {
                         if (!$this->role || !$this->role->id || $value->id != $this->role->id) {
                             $this->trackChange('role');
                         }
                         $this->role = $value;
                         return $this;
                     }
                 }
             }
         }
     }
     parent::set($key, $value);
 }
Example #11
0
 /**
  * Set the Inputfield's parent, set a new/existing attribute, or set a custom data value
  *
  */
 public function set($key, $value)
 {
     if ($key == 'parent' && $value instanceof Inputfield) {
         return $this->setParent($value);
     }
     if (array_key_exists($key, $this->attributes)) {
         return $this->setAttribute($key, $value);
     }
     if ($key == 'required' && $value) {
         $this->attr('class', 'required');
     }
     return parent::set($key, $value);
 }
Example #12
0
 /**
  * Sets a value in this Pagefile
  *
  * Externally, this would be used to set the file's basename or description
  *
  * @param string $key
  * @param mixed $value
  * @return this
  *
  */
 public function set($key, $value)
 {
     if ($key == 'basename') {
         $value = $this->pagefiles->cleanBasename($value, false);
     }
     if ($key == 'description') {
         $value = $this->fuel('sanitizer')->textarea($value);
     }
     return parent::set($key, $value);
 }
Example #13
0
 public function set($key, $value)
 {
     if (in_array($key, array('id', 'status', 'pages_id', 'created', 'created_users_id'))) {
         $value = (int) $value;
     } else {
         if ($key == 'text') {
             $value = $this->cleanCommentString($value);
         } else {
             if ($key == 'cite') {
                 $value = str_replace(array("\r", "\n", "\t"), ' ', substr(strip_tags($value), 0, 128));
             } else {
                 if ($key == 'email') {
                     $value = $this->sanitizer->email($value);
                 } else {
                     if ($key == 'ip') {
                         $value = filter_var($value, FILTER_VALIDATE_IP);
                     } else {
                         if ($key == 'user_agent') {
                             $value = str_replace(array("\r", "\n", "\t"), ' ', substr(strip_tags($value), 0, 255));
                         } else {
                             if ($key == 'website') {
                                 $value = wire('sanitizer')->url($value, array('allowRelative' => false, 'allowQuerystring' => false));
                             }
                         }
                     }
                 }
             }
         }
     }
     // save the state so that modules can identify when a comment that was identified as spam
     // is then set to not-spam, or when a misidentified 'approved' comment is actually spam
     if ($key == 'status') {
         $this->prevStatus = $this->status;
     }
     return parent::set($key, $value);
 }
Example #14
0
 /**
  * Set the Inputfield's parent, set a new/existing attribute, or set a custom data value
  *
  */
 public function set($key, $value)
 {
     if ($key == 'parent' && $value instanceof Inputfield) {
         return $this->setParent($value);
     }
     if (array_key_exists($key, $this->attributes)) {
         return $this->setAttribute($key, $value);
     }
     if ($key == 'required' && $value) {
         $this->attr('class', 'required');
     }
     if ($key == 'columnWidth') {
         $value = (int) $value;
         if ($value < 10 || $value > 99) {
             $value = '';
         }
     }
     return parent::set($key, $value);
 }
Example #15
0
 public function set($property, $value)
 {
     if ($property == 'halt') {
         $this->halt($value);
         return $this;
     }
     return parent::set($property, $value);
 }
Example #16
0
 /**
  * Set the icon for this field
  * 
  * @param string $icon Icon name
  * @return $this
  * 
  */
 public function setIcon($icon)
 {
     // store the non-prefixed version
     if (strpos($icon, 'icon-') === 0) {
         $icon = str_replace('icon-', '', $icon);
     }
     if (strpos($icon, 'fa-') === 0) {
         $icon = str_replace('fa-', '', $icon);
     }
     $icon = $this->wire('sanitizer')->pageName($icon);
     parent::set('icon', $icon);
     return $this;
 }
 /**
  * Set a Template property
  *
  * @param string $key
  * @param mixed $value
  * @return this
  *
  */
 public function set($key, $value)
 {
     if (isset($this->settings[$key])) {
         if ($key == 'id') {
             $value = (int) $value;
         } else {
             if ($key == 'name') {
                 $value = $this->fuel('sanitizer')->name($value);
             } else {
                 if ($key == 'fieldgroups_id') {
                     return $this->setFieldgroup($this->getFuel('fieldgroups')->get($value));
                 } else {
                     if ($key == 'cache_time' || $key == 'cacheTime') {
                         $value = (int) $value;
                     } else {
                         $value = '';
                     }
                 }
             }
         }
         if ($this->settings[$key] != $value) {
             $this->trackChange($key);
         }
         $this->settings[$key] = $value;
     } else {
         if ($key == 'fieldgroup' || $key == 'fields') {
             $this->setFieldgroup($value);
         } else {
             if ($key == 'filename') {
                 $this->filename = $value;
             } else {
                 parent::set($key, $value);
             }
         }
     }
     return $this;
 }
Example #18
0
 /**
  * Initialize/create the $options array for executeNavJSON() in Process modules
  * 
  * @param array $options
  * @return array
  *
  */
 public function initNavJSON(array $options = array())
 {
     $page = $this->wire('page');
     $templatesArray = array();
     $bookmarkFields = array();
     $bookmarksArray = array();
     $rolesArray = array();
     $data = $this->wire('modules')->getModuleConfigData($this->process);
     $iconKey = isset($options['iconKey']) ? $options['iconKey'] : '_icon';
     $classKey = isset($options['classKey']) ? $options['classKey'] : '_class';
     $options['classKey'] = $classKey;
     $options['iconKey'] = $iconKey;
     if (!isset($options['defaultIcon'])) {
         $options['defaultIcon'] = 'arrow-circle-right';
     }
     foreach ($this->wire('user')->roles as $role) {
         if ($role->name == 'guest') {
             continue;
         }
         $value = isset($data["bookmarks"]["_{$role->id}"]) ? $data["bookmarks"]["_{$role->id}"] : array();
         if (empty($value)) {
             continue;
         }
         $bookmarkFields[$role->name] = $value;
         $rolesArray[$role->name] = $role;
     }
     $bookmarkFields['bookmarks'] = isset($data['bookmarks']["_0"]) ? $data['bookmarks']["_0"] : array();
     $n = 0;
     foreach ($bookmarkFields as $name => $bookmarkIDs) {
         $bookmarks = count($bookmarkIDs) ? $this->wire('pages')->getById($bookmarkIDs) : array();
         // $className = "separator";
         $role = isset($rolesArray[$name]) ? $rolesArray[$name] : null;
         foreach ($bookmarks as $page) {
             if ($this->process == 'ProcessPageEdit' && !$page->editable()) {
                 continue;
             } else {
                 if ($this->process == 'ProcessPageAdd' && !$page->addable()) {
                     continue;
                 } else {
                     if (!$page->listable()) {
                         continue;
                     }
                 }
             }
             if (isset($bookmarksArray[$page->id])) {
                 continue;
             }
             $icon = $page->template->getIcon();
             if (!$icon) {
                 $icon = $options['defaultIcon'];
             }
             $page->setQuietly($iconKey, $icon);
             // $page->setQuietly($classKey, $className);
             $page->setQuietly('_roleName', $role ? $role->name : $this->labels['all']);
             $className = '';
             $bookmarksArray[$page->id] = $page;
         }
         $n++;
     }
     if (empty($options['add'])) {
         if ($this->wire('user')->isSuperuser()) {
             $options['add'] = 'bookmarks/?role=0';
             $options['addLabel'] = $this->labels['bookmarks'];
             $options['addIcon'] = 'bookmark-o';
         } else {
             $options['add'] = null;
         }
     } else {
         if ($this->wire('user')->isSuperuser()) {
             $add = new WireData();
             $add->set('_icon', 'bookmark-o');
             $add->set('title', $this->labels['bookmarks']);
             $add->set('id', 'bookmark');
             $add->set($classKey, 'highlight separator');
             array_unshift($bookmarksArray, $add);
         }
     }
     if (isset($options['items'])) {
         $options['items'] = $options['items'] + $bookmarksArray;
     } else {
         $options['items'] = $bookmarksArray;
     }
     if (!isset($options['itemLabel'])) {
         $options['itemLabel'] = 'title|name';
     }
     if (!isset($options['sort'])) {
         $options['sort'] = false;
     }
     if (!isset($options['iconKey'])) {
         $options['iconKey'] = '_icon';
     }
     if (empty($options['edit'])) {
         $options['edit'] = $this->wire('config')->urls->admin . 'page/edit/?id={id}';
     }
     return $options;
 }
Example #19
0
 /**
  * Set the given path key
  *
  * @param string $key
  * @param mixed $value If the first character of the provided path is a slash, then that specific path will be used without modification.
  * 	If the first character is anything other than a slash, then the 'root' variable will be prepended to the path.
  * @return this
  *
  */
 public function set($key, $value)
 {
     $value = self::normalizeSeparators($value);
     if ($key == 'root') {
         $this->_root = $value;
         return $this;
     }
     return parent::set($key, $value);
 }
Example #20
0
 /**
  * Set a Template property
  *
  * @param string $key
  * @param mixed $value
  * @return $this
  * @throws WireException
  *
  */
 public function set($key, $value)
 {
     if ($key == 'flags') {
         $this->setFlags($value);
     } else {
         if (isset($this->settings[$key])) {
             if ($key == 'id') {
                 $value = (int) $value;
             } else {
                 if ($key == 'name') {
                     $value = $this->fuel('sanitizer')->name($value);
                 } else {
                     if ($key == 'fieldgroups_id') {
                         return $this->setFieldgroup($this->getFuel('fieldgroups')->get($value));
                     } else {
                         if ($key == 'cache_time' || $key == 'cacheTime') {
                             $value = (int) $value;
                         } else {
                             $value = '';
                         }
                     }
                 }
             }
             if ($this->settings[$key] != $value) {
                 if ($this->settings[$key] && $this->settings['flags'] & Template::flagSystem && in_array($key, array('id', 'name'))) {
                     throw new WireException("Template '{$this}' has the system flag and you may not change it's 'id' or 'name' fields. ");
                 }
                 $this->trackChange($key);
             }
             $this->settings[$key] = $value;
         } else {
             if ($key == 'fieldgroup' || $key == 'fields') {
                 $this->setFieldgroup($value);
             } else {
                 if ($key == 'filename') {
                     $this->setFilename($value);
                 } else {
                     if ($key == 'roles') {
                         $this->setRoles($value);
                     } else {
                         if ($key == 'childrenTemplatesID') {
                             // this can eventaully be removed
                             if ($value < 0) {
                                 parent::set('noChildren', 1);
                             } else {
                                 if ($value) {
                                     $v = $this->childTemplates;
                                     $v[] = (int) $value;
                                     parent::set('childTemplates', $v);
                                 }
                             }
                         } else {
                             if ($key == 'sortfield') {
                                 $value = $this->fuel('pages')->sortfields()->decode($value, '');
                                 parent::set($key, $value);
                             } else {
                                 if (in_array($key, array('addRoles', 'editRoles', 'createRoles', 'childTemplates', 'parentTemplates'))) {
                                     if (!is_array($value)) {
                                         $value = array();
                                     }
                                     foreach ($value as $k => $v) {
                                         $value[(int) $k] = (int) $v;
                                     }
                                     parent::set($key, $value);
                                 } else {
                                     if (in_array($key, array('noChildren', 'noParents'))) {
                                         $value = (int) $value;
                                         if (!$value) {
                                             $value = null;
                                         }
                                         // enforce null over 0
                                         parent::set($key, $value);
                                     } else {
                                         parent::set($key, $value);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
 /**
  * Set the given path key
  *
  * If the first character of the provided path is a slash, then that specific path will be used without modification. 
  * If the first character is anything other than a slash, then the 'root' variable will be prepended to the path. 
  *
  */
 public function set($key, $value)
 {
     $value = self::normalizeSeparators($value);
     return parent::set($key, $value);
 }
 /**
  * Set a value to the booking: date and user
  *
  */
 public function set($key, $value)
 {
     //we don't need to do much here + our values are already sanitized in sanitizeValue()
     return parent::set($key, $value);
 }
Example #23
0
 /**
  * Set a Template property
  *
  * @param string $key
  * @param mixed $value
  * @return $this
  * @throws WireException
  *
  */
 public function set($key, $value)
 {
     if ($key == 'flags') {
         $this->setFlags($value);
     } else {
         if (isset($this->settings[$key])) {
             if ($key == 'id') {
                 $value = (int) $value;
             } else {
                 if ($key == 'name') {
                     $value = $this->wire('sanitizer')->name($value);
                 } else {
                     if ($key == 'fieldgroups_id' && $value) {
                         $fieldgroup = $this->wire('fieldgroups')->get($value);
                         if ($fieldgroup) {
                             $this->setFieldgroup($fieldgroup);
                         } else {
                             $this->error("Unable to load fieldgroup '{$value}' for template {$this->name}");
                         }
                         return $this;
                     } else {
                         if ($key == 'cache_time' || $key == 'cacheTime') {
                             $value = (int) $value;
                         } else {
                             $value = '';
                         }
                     }
                 }
             }
             if ($this->settings[$key] != $value) {
                 if ($this->settings[$key] && $this->settings['flags'] & Template::flagSystem && in_array($key, array('id', 'name'))) {
                     throw new WireException("Template '{$this}' has the system flag and you may not change it's 'id' or 'name' fields. ");
                 }
                 $this->trackChange($key, $this->settings[$key], $value);
             }
             $this->settings[$key] = $value;
         } else {
             if ($key == 'fieldgroup' || $key == 'fields') {
                 $this->setFieldgroup($value);
             } else {
                 if ($key == 'filename') {
                     $this->setFilename($value);
                 } else {
                     if ($key == 'roles') {
                         $this->setRoles($value);
                     } else {
                         if ($key == 'childrenTemplatesID') {
                             // this can eventaully be removed
                             if ($value < 0) {
                                 parent::set('noChildren', 1);
                             } else {
                                 if ($value) {
                                     $v = $this->childTemplates;
                                     $v[] = (int) $value;
                                     parent::set('childTemplates', $v);
                                 }
                             }
                         } else {
                             if ($key == 'sortfield') {
                                 $value = $this->wire('pages')->sortfields()->decode($value, '');
                                 parent::set($key, $value);
                             } else {
                                 if (in_array($key, array('addRoles', 'editRoles', 'createRoles'))) {
                                     if (!is_array($value)) {
                                         $value = array();
                                     }
                                     foreach ($value as $k => $v) {
                                         if (!is_int($v)) {
                                             if (is_object($v)) {
                                                 $v = $v->id;
                                             } else {
                                                 if (is_string($v) && !ctype_digit("{$v}")) {
                                                     $role = $this->wire('roles')->get($v);
                                                     if (!$role->id && $this->_importMode && $this->useRoles) {
                                                         $this->error("Unable to load role: {$v}");
                                                     }
                                                     $v = $role->id;
                                                 }
                                             }
                                         }
                                         if ($v) {
                                             $value[(int) $k] = (int) $v;
                                         }
                                     }
                                     parent::set($key, $value);
                                 } else {
                                     if (in_array($key, array('childTemplates', 'parentTemplates'))) {
                                         if (!is_array($value)) {
                                             $value = array();
                                         }
                                         foreach ($value as $k => $v) {
                                             if (!is_int($v)) {
                                                 if (is_object($v)) {
                                                     $v = $v->id;
                                                 } else {
                                                     if (!ctype_digit("{$v}")) {
                                                         $t = $this->wire('templates')->get($v);
                                                         if (!$t && $this->_importMode) {
                                                             $this->error("Unable to load template '{$v}' for '{$this->name}.{$key}'");
                                                         }
                                                         $v = $t ? $t->id : 0;
                                                     }
                                                 }
                                             }
                                             if ($v) {
                                                 $value[(int) $k] = (int) $v;
                                             }
                                         }
                                         parent::set($key, $value);
                                     } else {
                                         if (in_array($key, array('noChildren', 'noParents'))) {
                                             $value = (int) $value;
                                             if (!$value) {
                                                 $value = null;
                                             }
                                             // enforce null over 0
                                             parent::set($key, $value);
                                         } else {
                                             if ($key == 'cacheExpirePages') {
                                                 if (!is_array($value)) {
                                                     $value = array();
                                                 }
                                                 foreach ($value as $k => $v) {
                                                     if (is_object($v)) {
                                                         $v = $v->id;
                                                     } else {
                                                         if (!ctype_digit("{$v}")) {
                                                             $p = $this->wire('pages')->get($v);
                                                             if (!$p->id) {
                                                                 $this->error("Unable to load page: {$v}");
                                                             }
                                                             $v = $p->id;
                                                         }
                                                     }
                                                     $value[(int) $k] = (int) $v;
                                                 }
                                                 parent::set($key, $value);
                                             } else {
                                                 parent::set($key, $value);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
Example #24
0
 /**
  * Set a value to the Notification
  * 
  * Note: setting the 'expires' value accepts either a future date, or a quantity of seconds 
  * in the future relative to now. 
  * 
  * @param string $key
  * @param mixed $value
  * @return this
  *
  */
 public function set($key, $value)
 {
     if ($key == 'page') {
         $this->page = $value;
         return $this;
     } else {
         if ($key == 'created' || $key == 'modified' || $key == 'expires') {
             // convert date string to unix timestamp
             if ($value && !ctype_digit("{$value}")) {
                 $value = strtotime($value);
             }
             // sanitized date value is always an integer
             $value = (int) $value;
             if ($key == 'expires' && $value > 0 && $value < strtotime("-10 YEARS")) {
                 // assume this is a time relative to now
                 $value = time() + $value;
             }
         } else {
             if ($key == 'title') {
                 if ($this->flags & self::flagAllowMarkup) {
                     // accept value as-is
                 } else {
                     // regular text sanitizer
                     $value = $this->sanitizer->text($value);
                 }
             } else {
                 if ($key == 'from') {
                     // regular text sanitizer
                     $value = $this->sanitizer->text($value);
                 } else {
                     if ($key == 'text') {
                         // regular text sanitizer
                         $value = $this->sanitizer->textarea($value);
                     } else {
                         if (in_array($key, array('pages_id', 'sort', 'src_id', 'flags', 'progress'))) {
                             $value = (int) $value;
                         }
                     }
                 }
             }
         }
     }
     return parent::set($key, $value);
 }
Example #25
0
 /**
  * Get a value from this Pagefile
  *
  * @param string $key
  * @return mixed Returns null if value does not exist
  *
  */
 public function get($key)
 {
     $value = null;
     if ($key == 'name') {
         $key = 'basename';
     }
     if ($key == 'pathname') {
         $key = 'filename';
     }
     switch ($key) {
         case 'url':
         case 'httpUrl':
         case 'filename':
         case 'description':
         case 'tags':
         case 'ext':
         case 'hash':
         case 'filesize':
         case 'filesizeStr':
             // 'basename' property intentionally excluded
             $value = $this->{$key}();
             break;
         case 'pagefiles':
             $value = $this->pagefiles;
             break;
         case 'page':
             $value = $this->pagefiles->getPage();
             break;
         case 'field':
             $value = $this->pagefiles->getField();
             break;
         case 'modified':
         case 'created':
             $value = parent::get($key);
             if (empty($value)) {
                 $value = filemtime($this->filename());
                 parent::set($key, $value);
             }
             break;
     }
     if (is_null($value)) {
         return parent::get($key);
     }
     return $value;
 }
Example #26
0
 /**
  * Set a Template property
  *
  * @param string $key
  * @param mixed $value
  * @return $this
  * @throws WireException
  *
  */
 public function set($key, $value)
 {
     if ($key == 'flags') {
         $this->setFlags($value);
     } else {
         if (isset($this->settings[$key])) {
             if ($key == 'id') {
                 $value = (int) $value;
             } else {
                 if ($key == 'name') {
                     $value = $this->wire('sanitizer')->name($value);
                 } else {
                     if ($key == 'fieldgroups_id' && $value) {
                         $fieldgroup = $this->wire('fieldgroups')->get($value);
                         if ($fieldgroup) {
                             $this->setFieldgroup($fieldgroup);
                         } else {
                             $this->error("Unable to load fieldgroup '{$value}' for template {$this->name}");
                         }
                         return $this;
                     } else {
                         if ($key == 'cache_time' || $key == 'cacheTime') {
                             $value = (int) $value;
                         } else {
                             $value = '';
                         }
                     }
                 }
             }
             if ($this->settings[$key] != $value) {
                 if ($this->settings[$key] && $this->settings['flags'] & Template::flagSystem && in_array($key, array('id', 'name'))) {
                     throw new WireException("Template '{$this}' has the system flag and you may not change it's 'id' or 'name' fields. ");
                 }
                 $this->trackChange($key, $this->settings[$key], $value);
             }
             $this->settings[$key] = $value;
         } else {
             if ($key == 'fieldgroup' || $key == 'fields') {
                 $this->setFieldgroup($value);
             } else {
                 if ($key == 'filename') {
                     $this->setFilename($value);
                 } else {
                     if ($key == 'roles') {
                         $this->setRoles($value);
                     } else {
                         if ($key == 'childrenTemplatesID') {
                             // this can eventaully be removed
                             if ($value < 0) {
                                 parent::set('noChildren', 1);
                             } else {
                                 if ($value) {
                                     $v = $this->childTemplates;
                                     $v[] = (int) $value;
                                     parent::set('childTemplates', $v);
                                 }
                             }
                         } else {
                             if ($key == 'sortfield') {
                                 $value = $this->wire('pages')->sortfields()->decode($value, '');
                                 parent::set($key, $value);
                             } else {
                                 if (in_array($key, array('addRoles', 'editRoles', 'createRoles'))) {
                                     if (!is_array($value)) {
                                         $value = array();
                                     }
                                     foreach ($value as $k => $v) {
                                         if (!is_int($v)) {
                                             if (is_object($v)) {
                                                 $v = $v->id;
                                             } else {
                                                 if (is_string($v) && !ctype_digit("{$v}")) {
                                                     $role = $this->wire('roles')->get($v);
                                                     if (!$role->id && $this->_importMode && $this->useRoles) {
                                                         $this->error("Unable to load role: {$v}");
                                                     }
                                                     $v = $role->id;
                                                 }
                                             }
                                         }
                                         if ($v) {
                                             $value[(int) $k] = (int) $v;
                                         }
                                     }
                                     parent::set($key, $value);
                                 } else {
                                     if ($key == 'rolesPermissions') {
                                         if (!is_array($value)) {
                                             $value = array();
                                         }
                                         $_value = array();
                                         foreach ($value as $roleID => $permissionIDs) {
                                             // if any one of these happend to be a role name or permission name, convert to IDs
                                             if (!ctype_digit("{$roleID}")) {
                                                 $roleID = $this->wire('roles')->get("name={$roleID}")->id;
                                             }
                                             if (!$roleID) {
                                                 continue;
                                             }
                                             foreach ($permissionIDs as $permissionID) {
                                                 if (!ctype_digit(ltrim($permissionID, '-'))) {
                                                     $revoke = strpos($permissionID, '-') === 0;
                                                     $permissionID = $this->wire('permissions')->get("name=" . ltrim($permissionID, '-'))->id;
                                                     if (!$permissionID) {
                                                         continue;
                                                     }
                                                     if ($revoke) {
                                                         $permissionID = "-{$permissionID}";
                                                     }
                                                 }
                                                 // we force these as strings so that they can portable in JSON
                                                 $roleID = (string) (int) $roleID;
                                                 $permissionID = (string) (int) $permissionID;
                                                 if (!isset($_value[$roleID])) {
                                                     $_value[$roleID] = array();
                                                 }
                                                 $_value[$roleID][] = $permissionID;
                                             }
                                         }
                                         parent::set($key, $_value);
                                     } else {
                                         if (in_array($key, array('childTemplates', 'parentTemplates'))) {
                                             if (!is_array($value)) {
                                                 $value = array();
                                             }
                                             foreach ($value as $k => $v) {
                                                 if (!is_int($v)) {
                                                     if (is_object($v)) {
                                                         $v = $v->id;
                                                     } else {
                                                         if (!ctype_digit("{$v}")) {
                                                             $t = $this->wire('templates')->get($v);
                                                             if (!$t && $this->_importMode) {
                                                                 $this->error("Unable to load template '{$v}' for '{$this->name}.{$key}'");
                                                             }
                                                             $v = $t ? $t->id : 0;
                                                         }
                                                     }
                                                 }
                                                 if ($v) {
                                                     $value[(int) $k] = (int) $v;
                                                 }
                                             }
                                             parent::set($key, $value);
                                         } else {
                                             if (in_array($key, array('noChildren', 'noParents'))) {
                                                 $value = (int) $value;
                                                 if (!$value) {
                                                     $value = null;
                                                 }
                                                 // enforce null over 0
                                                 parent::set($key, $value);
                                             } else {
                                                 if ($key == 'cacheExpirePages') {
                                                     if (!is_array($value)) {
                                                         $value = array();
                                                     }
                                                     foreach ($value as $k => $v) {
                                                         if (is_object($v)) {
                                                             $v = $v->id;
                                                         } else {
                                                             if (!ctype_digit("{$v}")) {
                                                                 $p = $this->wire('pages')->get($v);
                                                                 if (!$p->id) {
                                                                     $this->error("Unable to load page: {$v}");
                                                                 }
                                                                 $v = $p->id;
                                                             }
                                                         }
                                                         $value[(int) $k] = (int) $v;
                                                     }
                                                     parent::set($key, $value);
                                                 } else {
                                                     if ($key == 'icon') {
                                                         $this->setIcon($value);
                                                     } else {
                                                         if ($key == 'urlSegments') {
                                                             $this->urlSegments($value);
                                                         } else {
                                                             parent::set($key, $value);
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
Example #27
0
 /**
  * Prepare the page and it's fields for removal from runtime memory, called primarily by Pages::uncache()
  *
  */
 public function uncache()
 {
     $trackChanges = $this->trackChanges();
     if ($trackChanges) {
         $this->setTrackChanges(false);
     }
     if ($this->template) {
         foreach ($this->template->fieldgroup as $field) {
             $value = parent::get($field->name);
             if ($value != null && is_object($value)) {
                 if (method_exists($value, 'uncache') && $value !== $this) {
                     $value->uncache();
                 }
                 parent::set($field->name, null);
             }
         }
     }
     if ($this->filesManager) {
         $this->filesManager->uncache();
     }
     $this->filesManager = null;
     if ($trackChanges) {
         $this->setTrackChanges(true);
     }
 }
Example #28
0
 public function set($key, $value)
 {
     if ($key == 'fields') {
         return parent::set('field', $value);
     }
     if ($key == 'values') {
         return parent::set('value', $value);
     }
     if ($key == 'operator') {
         $this->error("You cannot set the operator on a Selector: {$this}");
         return $this;
     }
     return parent::set($key, $value);
 }
 /**
  * Set a webmention key
  * @param string $key
  * @param string $value
  * @access public
  */
 public function set($key, $value)
 {
     switch ($key) {
         case 'id':
         case 'status':
         case 'pages_id':
         case 'is_like':
         case 'is_repost':
         case 'is_rsvp':
             $value = (int) $value;
             break;
         case 'source_url':
         case 'target_url':
         case 'vouch_url':
         case 'url':
         case 'author_photo':
         case 'author_logo':
         case 'author_url':
             $value = wire('sanitizer')->url($value, array('allowRelative' => FALSE));
             break;
     }
     if ($key == 'status') {
         $this->prevStatus = $this->status;
     }
     return parent::set($key, $value);
 }
 /**
  * Set or retrieve a config value to be shared with javascript
  * 
  * 1. Specify a $key and $value to set a JS config value. 
  *
  * 2. Specify only a $key and omit the $value in order to retrieve an existing set value.
  *    The $key may also be an array of properties, which will return an array of values. 
  * 
  * 3. Specify boolean true for $value to share the $key with the JS side. If the $key 
  *    specified does not exist then $key=true will be added to the JS config (which can later 
  *    be overwritten with another value, which will still be shared with the JS config). 
  *    The $key property may also be an array of properties to specify multiple. 
  * 
  * 4. Specify no params to retrieve in array of all existing set values.
  *
  * @param string|array $key Property or array of properties
  * @param mixed $value
  * @return array|mixed|null|this
  *
  */
 public function js($key = null, $value = null)
 {
     if (is_null($key)) {
         // return array of all keys and values
         $data = array();
         foreach ($this->jsFields as $field) {
             $data[$field] = $this->get($field);
         }
         return $data;
     } else {
         if (is_null($value)) {
             // return a value or values
             if (is_array($key)) {
                 // return values for multiple keys
                 $a = array();
                 foreach ($key as $k) {
                     $a[$k] = $this->js($k);
                 }
                 return $a;
             } else {
                 // return value for just one key
                 return in_array($key, $this->jsFields) ? $this->get($key) : null;
             }
         } else {
             if ($value === true) {
                 // share an already present value or set a key=true
                 if (is_array($key)) {
                     // sharing multiple keys
                     foreach ($key as $k) {
                         $this->js($k, true);
                     }
                     return $this;
                 } else {
                     if ($this->get($key) !== null) {
                         // share existing config $key with JS side
                         $this->jsFields[] = $key;
                         return $this;
                     } else {
                         // will set $key=true to JS config, which may be overwritten
                         // with a different value during runtime, or maybe true is the
                         // literal value they want stored, in which case it will remain.
                     }
                 }
             }
         }
     }
     $this->jsFields[] = $key;
     return parent::set($key, $value);
 }