get() public method

public get ( $name )
Beispiel #1
0
 /**
  * Set up config appropriately on engine boot.
  *
  * @return void
  */
 function init()
 {
     $lastcache = $this->config->get('lastcache');
     if (!defined('UPGRADING') && empty($lastcache)) {
         $this->config->set('lastcache', (int) $this->datalist->get('simplecache_lastupdate'));
     }
 }
Beispiel #2
0
 /**
  * @see ActionsService::validateActionToken
  * @access private
  * @since 1.9.0
  * @return int number of seconds that action token is valid
  */
 public function getActionTokenTimeout()
 {
     if (($timeout = $this->config->get('action_token_timeout')) === null) {
         // default to 2 hours
         $timeout = 2;
     }
     $hour = 60 * 60;
     return (int) ((double) $timeout * $hour);
 }
Beispiel #3
0
 /**
  * Upgrades Elgg Database and code
  *
  * @return bool
  */
 protected function processUpgrades()
 {
     $dbversion = (int) $this->config->get('version');
     if ($this->upgradeCode($dbversion)) {
         system_message($this->translator->translate('upgrade:core'));
         // Now we trigger an event to give the option for plugins to do something
         $upgrade_details = new \stdClass();
         $upgrade_details->from = $dbversion;
         $upgrade_details->to = elgg_get_version();
         $this->events->trigger('upgrade', 'upgrade', $upgrade_details);
         return true;
     }
     return false;
 }
Beispiel #4
0
 /**
  * Return users (or the number of them) who have been active within a recent period.
  *
  * @param array $options Array of options with keys:
  *
  *   seconds (int)  => Length of period (default 600 = 10min)
  *   limit   (int)  => Limit (default 10)
  *   offset  (int)  => Offset (default 0)
  *   count   (bool) => Return a count instead of users? (default false)
  *
  * @return \ElggUser[]|int
  */
 public function findActive(array $options = [])
 {
     $options = array_merge(array('seconds' => 600, 'limit' => $this->config->get('default_limit')), $options);
     // cast options we're sending to hook
     foreach (array('seconds', 'limit', 'offset') as $key) {
         $options[$key] = (int) $options[$key];
     }
     $options['count'] = (bool) $options['count'];
     // allow plugins to override
     $params = array('seconds' => $options['seconds'], 'limit' => $options['limit'], 'offset' => $options['offset'], 'count' => $options['count'], 'options' => $options);
     $data = _elgg_services()->hooks->trigger('find_active_users', 'system', $params, null);
     // check null because the handler could legitimately return falsey values.
     if ($data !== null) {
         return $data;
     }
     $dbprefix = $this->config->get('dbprefix');
     $time = $this->getCurrentTime()->getTimestamp() - $options['seconds'];
     return elgg_get_entities(array('type' => 'user', 'limit' => $options['limit'], 'offset' => $options['offset'], 'count' => $options['count'], 'joins' => array("join {$dbprefix}users_entity u on e.guid = u.guid"), 'wheres' => array("u.last_action >= {$time}"), 'order_by' => "u.last_action desc"));
 }
Beispiel #5
0
 /**
  * Returns a configuration array of icon sizes
  *
  * @param string $entity_type    Entity type
  * @param string $entity_subtype Entity subtype
  * @param string $type           The name of the icon. e.g., 'icon', 'cover_photo'
  * @return array
  * @throws InvalidParameterException
  */
 public function getSizes($entity_type = null, $entity_subtype = null, $type = 'icon')
 {
     $sizes = [];
     if (!$type) {
         $type = 'icon';
     }
     if ($type == 'icon') {
         $sizes = $this->config->get('icon_sizes');
     }
     $params = ['type' => $type, 'entity_type' => $entity_type, 'entity_subtype' => $entity_subtype];
     if ($entity_type) {
         $sizes = $this->hooks->trigger("entity:{$type}:sizes", $entity_type, $params, $sizes);
     }
     if (!is_array($sizes)) {
         throw new InvalidParameterException("The icon size configuration for image type '{$type}' " . "must be an associative array of image size names and their properties");
     }
     if (empty($sizes)) {
         $this->logger->error("Failed to find size configuration for image of type '{$type}' for entity type " . "'{$entity_type}'. Use the 'entity:{$type}:sizes, {$entity_type}' hook to define the icon sizes");
     }
     return $sizes;
 }
Beispiel #6
0
 /**
  * Returns SQL where clause for type and subtype on main entity table
  *
  * @param string     $table    Entity table prefix as defined in SELECT...FROM entities $table
  * @param null|array $types    Array of types or null if none.
  * @param null|array $subtypes Array of subtypes or null if none
  * @param null|array $pairs    Array of pairs of types and subtypes
  *
  * @return false|string
  * @access private
  */
 public function getEntityTypeSubtypeWhereSql($table, $types, $subtypes, $pairs)
 {
     // subtype depends upon type.
     if ($subtypes && !$types) {
         $this->logger->warn("Cannot set subtypes without type.");
         return false;
     }
     // short circuit if nothing is requested
     if (!$types && !$subtypes && !$pairs) {
         return '';
     }
     // these are the only valid types for entities in elgg
     $valid_types = $this->config->get('entity_types');
     // pairs override
     $wheres = array();
     if (!is_array($pairs)) {
         if (!is_array($types)) {
             $types = array($types);
         }
         if ($subtypes && !is_array($subtypes)) {
             $subtypes = array($subtypes);
         }
         // decrementer for valid types.  Return false if no valid types
         $valid_types_count = count($types);
         $valid_subtypes_count = 0;
         // remove invalid types to get an accurate count of
         // valid types for the invalid subtype detection to use
         // below.
         // also grab the count of ALL subtypes on valid types to decrement later on
         // and check against.
         //
         // yes this is duplicating a foreach on $types.
         foreach ($types as $type) {
             if (!in_array($type, $valid_types)) {
                 $valid_types_count--;
                 unset($types[array_search($type, $types)]);
             } else {
                 // do the checking (and decrementing) in the subtype section.
                 $valid_subtypes_count += count($subtypes);
             }
         }
         // return false if nothing is valid.
         if (!$valid_types_count) {
             return false;
         }
         // subtypes are based upon types, so we need to look at each
         // type individually to get the right subtype id.
         foreach ($types as $type) {
             $subtype_ids = array();
             if ($subtypes) {
                 foreach ($subtypes as $subtype) {
                     // check that the subtype is valid
                     if (!$subtype && ELGG_ENTITIES_NO_VALUE === $subtype) {
                         // subtype value is 0
                         $subtype_ids[] = ELGG_ENTITIES_NO_VALUE;
                     } elseif (!$subtype) {
                         // subtype is ignored.
                         // this handles ELGG_ENTITIES_ANY_VALUE, '', and anything falsy that isn't 0
                         continue;
                     } else {
                         $subtype_id = get_subtype_id($type, $subtype);
                         if ($subtype_id) {
                             $subtype_ids[] = $subtype_id;
                         } else {
                             $valid_subtypes_count--;
                             $this->logger->notice("Type-subtype '{$type}:{$subtype}' does not exist!");
                             continue;
                         }
                     }
                 }
                 // return false if we're all invalid subtypes in the only valid type
                 if ($valid_subtypes_count <= 0) {
                     return false;
                 }
             }
             if (is_array($subtype_ids) && count($subtype_ids)) {
                 $subtype_ids_str = implode(',', $subtype_ids);
                 $wheres[] = "({$table}.type = '{$type}' AND {$table}.subtype IN ({$subtype_ids_str}))";
             } else {
                 $wheres[] = "({$table}.type = '{$type}')";
             }
         }
     } else {
         // using type/subtype pairs
         $valid_pairs_count = count($pairs);
         $valid_pairs_subtypes_count = 0;
         // same deal as above--we need to know how many valid types
         // and subtypes we have before hitting the subtype section.
         // also normalize the subtypes into arrays here.
         foreach ($pairs as $paired_type => $paired_subtypes) {
             if (!in_array($paired_type, $valid_types)) {
                 $valid_pairs_count--;
                 unset($pairs[array_search($paired_type, $pairs)]);
             } else {
                 if ($paired_subtypes && !is_array($paired_subtypes)) {
                     $pairs[$paired_type] = array($paired_subtypes);
                 }
                 $valid_pairs_subtypes_count += count($paired_subtypes);
             }
         }
         if ($valid_pairs_count <= 0) {
             return false;
         }
         foreach ($pairs as $paired_type => $paired_subtypes) {
             // this will always be an array because of line 2027, right?
             // no...some overly clever person can say pair => array('object' => null)
             if (is_array($paired_subtypes)) {
                 $paired_subtype_ids = array();
                 foreach ($paired_subtypes as $paired_subtype) {
                     if (ELGG_ENTITIES_NO_VALUE === $paired_subtype || ($paired_subtype_id = get_subtype_id($paired_type, $paired_subtype))) {
                         $paired_subtype_ids[] = ELGG_ENTITIES_NO_VALUE === $paired_subtype ? ELGG_ENTITIES_NO_VALUE : $paired_subtype_id;
                     } else {
                         $valid_pairs_subtypes_count--;
                         $this->logger->notice("Type-subtype '{$paired_type}:{$paired_subtype}' does not exist!");
                         // return false if we're all invalid subtypes in the only valid type
                         continue;
                     }
                 }
                 // return false if there are no valid subtypes.
                 if ($valid_pairs_subtypes_count <= 0) {
                     return false;
                 }
                 if ($paired_subtype_ids_str = implode(',', $paired_subtype_ids)) {
                     $wheres[] = "({$table}.type = '{$paired_type}'" . " AND {$table}.subtype IN ({$paired_subtype_ids_str}))";
                 }
             } else {
                 $wheres[] = "({$table}.type = '{$paired_type}')";
             }
         }
     }
     // pairs override the above.  return false if they don't exist.
     if (is_array($wheres) && count($wheres)) {
         $where = implode(' OR ', $wheres);
         return "({$where})";
     }
     return '';
 }