/** * 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')); } }
/** * Build an unprepared menu. * * @param string $name Menu name * @param array $params Hook/view parameters * * @return UnpreparedMenu */ public function getUnpreparedMenu($name, array $params = []) { $menus = $this->config->getVolatile('menus'); $items = $this->prepareMenuItems(elgg_extract('items', $params, [])); unset($params['items']); if ($menus && isset($menus[$name])) { $registered_items = elgg_extract($name, $menus, []); $items = array_merge($items, $registered_items); } $params['name'] = $name; $params = $this->hooks->trigger('parameters', "menu:{$name}", $params, $params); if (!isset($params['sort_by'])) { $params['sort_by'] = 'priority'; } $items = $this->hooks->trigger('register', "menu:{$name}", $params, $items); return new UnpreparedMenu($params, $items); }
/** * @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); }
public function createRequest($uri = '', $method = 'POST', $parameters = [], $xhr = false) { $site_url = elgg_get_site_url(); $path = substr(elgg_normalize_url($uri), strlen($site_url)); $path_key = Application::GET_PATH_KEY; $request = Request::create("?{$path_key}={$path}", $method, $parameters); $cookie_name = $this->config->getCookieConfig()['session']['name']; $session_id = $this->session->getId(); $request->cookies->set($cookie_name, $session_id); if ($xhr) { $request->headers->set('X-Requested-With', 'XMLHttpRequest'); } return $request; }
/** * 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; }
/** * Render a view for caching. Language views are handled specially. * * @param string $view The view name * @param string $viewtype The viewtype * @return string */ protected function renderView($view, $viewtype) { elgg_set_viewtype($viewtype); if ($viewtype === 'default' && preg_match("#^languages/(.*?)\\.js\$#", $view, $matches)) { $view = "languages.js"; $vars = ['language' => $matches[1]]; } else { $vars = []; } if (!elgg_view_exists($view)) { $this->send403(); } // disable error reporting so we don't cache problems $this->config->set('debug', null); return elgg_view($view, $vars); }
/** * Initializes the simplecache lastcache variable and creates system cache files * when appropriate. * * @access private */ function init() { if (!$this->isEnabled()) { return; } // cache system data if enabled and not loaded if (!$this->config->getVolatile('system_cache_loaded')) { $this->save('view_types', serialize($GLOBALS['_ELGG']->view_types)); _elgg_services()->views->cacheConfiguration($this); } if (!$GLOBALS['_ELGG']->i18n_loaded_from_cache) { _elgg_services()->translator->reloadAllTranslations(); foreach ($GLOBALS['_ELGG']->translations as $lang => $map) { $this->save("{$lang}.lang", serialize($map)); } } }
/** * Render a view for caching * * @param string $view The view name * @param string $viewtype The viewtype * @return string */ protected function renderView($view, $viewtype) { elgg_set_viewtype($viewtype); if (!elgg_view_exists($view)) { $this->send403(); } // disable error reporting so we don't cache problems $this->config->set('debug', null); // @todo elgg_view() checks if the page set is done (isset($GLOBALS['_ELGG']->pagesetupdone)) and // triggers an event if it's not. Calling elgg_view() here breaks submenus // (at least) because the page setup hook is called before any // contexts can be correctly set (since this is called before page_handler()). // To avoid this, lie about $CONFIG->pagehandlerdone to force // the trigger correctly when the first view is actually being output. $GLOBALS['_ELGG']->pagesetupdone = true; return elgg_view($view); }
/** * 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")); }
/** * 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; }
/** * Get the session ID from the cookie * * @param Request $request Elgg request * @return string */ private function getCookieValue(Request $request) { $config = $this->config->getCookieConfig(); $session_name = $config['session']['name']; return $request->cookies->get($session_name, ''); }
/** * 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 ''; }