/** * Triggers an Elgg event. * * @see elgg_trigger_event * @see elgg_trigger_after_event * @access private */ public function trigger($event, $type, $object = null, array $options = array()) { $options = array_merge(array(self::OPTION_STOPPABLE => true, self::OPTION_DEPRECATION_MESSAGE => '', self::OPTION_DEPRECATION_VERSION => ''), $options); $events = $this->hasHandler($event, $type); if ($events && $options[self::OPTION_DEPRECATION_MESSAGE]) { elgg_deprecated_notice($options[self::OPTION_DEPRECATION_MESSAGE], $options[self::OPTION_DEPRECATION_VERSION], 2); } $events = $this->getOrderedHandlers($event, $type); $args = array($event, $type, $object); foreach ($events as $callback) { if (!is_callable($callback)) { if ($this->logger) { $this->logger->warn("handler for event [{$event}, {$type}] is not callable: " . $this->inspector->describeCallable($callback)); } continue; } if ($this->timer && $type === 'system' && $event !== 'shutdown') { $callback_as_string = $this->inspector->describeCallable($callback) . "()"; $this->timer->begin(["[{$event},{$type}]", $callback_as_string]); $return = call_user_func_array($callback, $args); $this->timer->end(["[{$event},{$type}]", $callback_as_string]); } else { $return = call_user_func_array($callback, $args); } if (!empty($options[self::OPTION_STOPPABLE]) && $return === false) { return false; } } return true; }
/** * Construct a new user entity, optionally from a given id value. * * @param mixed $guid If an int, load that GUID. * If a db row then will attempt to load the rest of the data. * @throws Exception if there was a problem creating the user. */ function __construct($guid = null) { $this->initialise_attributes(); if (!empty($guid)) { // Is $guid is a DB row - either a entity row, or a user table row. if ($guid instanceof stdClass) { // Load the rest if (!$this->load($guid->guid)) { throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid->guid)); } } else { if ($guid instanceof ElggGroup) { elgg_deprecated_notice('This type of usage of the ElggGroup constructor was deprecated. Please use the clone method.', 1.7); foreach ($guid->attributes as $key => $value) { $this->attributes[$key] = $value; } } else { if ($guid instanceof ElggEntity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggGroup')); } else { if (is_numeric($guid)) { if (!$this->load($guid)) { throw new IOException(sprintf(elgg_echo('IOException:FailedToLoadGUID'), get_class(), $guid)); } } else { throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue')); } } } } } }
function view_adm_permission($entities, $vars = array(), $offset = 0, $limit = 10, $full_view = true, $listTypeToggle = true, $pagination = true) { if (!is_int($offset)) { $offset = (int) get_input('offset', 0); } // list type can be passed as request parameter $listType = get_input('list_type', 'list'); if (get_input('listtype')) { elgg_deprecated_notice("'listtype' has been deprecated by 'list_type' for lists", 1.8); $listType = get_input('listtype'); } if (is_array($vars)) { // new function $defaults = array('items' => $entities, 'list_class' => 'elgg-list-entity', 'full_view' => true, 'pagination' => true, 'list_type' => $list_type, 'list_type_toggle' => false, 'offset' => $offset, 'limit' => null); $vars = array_merge($defaults, $vars); } else { // old function parameters elgg_deprecated_notice("Please update your use of elgg_view_entity_list()", 1.8); $vars = array('items' => $entities, 'count' => (int) $vars, 'offset' => $offset, 'limit' => (int) $limit, 'full_view' => $full_view, 'pagination' => $pagination, 'list_type' => $list_type, 'list_type_toggle' => $listTypeToggle, 'list_class' => 'elgg-list-entity'); } if (!$vars["limit"] && !$vars["offset"]) { // no need for pagination if listing is unlimited $vars["pagination"] = false; } if ($vars['view_path_list']) { return elgg_view($vars['view_path_list'], $vars); } if ($vars['list_type'] != 'list') { return elgg_view('page/components/gallery', $vars); } else { return elgg_view('page/components/list', $vars); } }
/** * Triggers a plugin hook * * @see elgg_trigger_plugin_hook * @access private */ public function trigger($hook, $type, $params = null, $returnvalue = null) { $hooks = $this->getOrderedHandlers($hook, $type); foreach ($hooks as $callback) { if (!is_callable($callback)) { if ($this->logger) { $inspector = new Inspector(); $this->logger->warn("handler for plugin hook [{$hook}, {$type}] is not callable: " . $inspector->describeCallable($callback)); } continue; } $exit_warning = function () use($hook, $type, $callback) { $inspector = new Inspector(); elgg_deprecated_notice("'{$hook}', '{$type}' plugin hook should not be used to serve a response. Instead return an " . "appropriate ResponseBuilder instance from an action or page handler. Do not terminate " . "code execution with exit() or die() in {$inspector->describeCallable($callback)}", '2.3'); }; if (in_array($hook, ['forward', 'action', 'route'])) { _elgg_services()->events->registerHandler('shutdown', 'system', $exit_warning); } $args = array($hook, $type, $returnvalue, $params); $temp_return_value = call_user_func_array($callback, $args); if (!is_null($temp_return_value)) { $returnvalue = $temp_return_value; } if (in_array($hook, ['forward', 'action', 'route'])) { _elgg_services()->events->unregisterHandler('shutdown', 'system', $exit_warning); } } return $returnvalue; }
/** * Routes the request to a registered page handler * * This function triggers a plugin hook `'route', $identifier` so that plugins can * modify the routing or handle a request. * * @param Elgg_Http_Request $request The request to handle. * @return boolean Whether the request was routed successfully. * @access private */ public function route(Elgg_Http_Request $request) { $segments = $request->getUrlSegments(); if ($segments) { $identifier = array_shift($segments); } else { $identifier = ''; // this plugin hook is deprecated. Use elgg_register_page_handler() // to register for the '' (empty string) handler. // allow plugins to override the front page (return true to indicate // that the front page has been served) $result = elgg_trigger_plugin_hook('index', 'system', null, false); if ($result === true) { elgg_deprecated_notice("The 'index', 'system' plugin has been deprecated. See elgg_front_page_handler()", 1.9); exit; } } // return false to stop processing the request (because you handled it) // return a new $result array if you want to route the request differently $result = array('identifier' => $identifier, 'handler' => $identifier, 'segments' => $segments); $result = $this->hooks->trigger('route', $identifier, null, $result); if ($result === false) { return true; } $identifier = $result['identifier']; $segments = $result['segments']; $handled = false; if (isset($this->handlers[$identifier]) && is_callable($this->handlers[$identifier])) { $function = $this->handlers[$identifier]; $handled = call_user_func($function, $segments, $identifier); } return $handled || headers_sent(); }
/** * Set an attribute * * @param string $name Name * @param mixed $value Value * @return void */ public function __set($name, $value) { if ($name === 'access_id' && $this instanceof ElggMetadata && $value != ACCESS_PUBLIC) { elgg_deprecated_notice('Setting ->access_id to a value other than ACCESS_PUBLIC is deprecated. ' . 'All metadata will be public in 3.0.', '2.3'); } $this->attributes[$name] = $value; if ($name == 'value') { $this->attributes['value_type'] = detect_extender_valuetype($value); } }
/** * Register a widget type * * This should be called by plugins in their init function. * * @param string $handler The identifier for the widget handler * @param string $name The name of the widget type * @param string $description A description for the widget type * @param array $context An array of contexts where this * widget is allowed (default: array('all')) * @param bool $multiple Whether or not multiple instances of this widget * are allowed in a single layout (default: false) * * @return bool * @since 1.8.0 */ function elgg_register_widget_type($handler, $name, $description, $context = array('all'), $multiple = false) { if (is_string($context)) { elgg_deprecated_notice('context parameters for elgg_register_widget_type() should be passed as an array())', 1.9); $context = explode(",", $context); } elseif (empty($context)) { $context = array('all'); } return _elgg_services()->widgets->registerType($handler, $name, $description, $context, $multiple); }
/** * Register a widget title * * @deprecated 1.8. Use elgg_register_plugin_hook_handler("widget_url", "widget_manager") * * @param $handler * @param $link */ function widget_manager_add_widget_title_link($handler, $link) { global $CONFIG; elgg_deprecated_notice("widget_manager_add_widget_title_link() was deprecated by elgg_register_plugin_hook_handler('widget_url', 'widget_manager')", "1.8"); if (!empty($handler) && !empty($link)) { if (isset($CONFIG->widgets) && isset($CONFIG->widgets->handlers) && isset($CONFIG->widgets->handlers[$handler])) { $CONFIG->widgets->handlers[$handler]->link = $link; } } }
/** * Delete river items * * @warning Does not fire permission hooks or delete, river events. * * @param array $options Parameters: * ids => INT|ARR River item id(s) * subject_guids => INT|ARR Subject guid(s) * object_guids => INT|ARR Object guid(s) * target_guids => INT|ARR Target guid(s) * annotation_ids => INT|ARR The identifier of the annotation(s) * action_types => STR|ARR The river action type(s) identifier * views => STR|ARR River view(s) * * types => STR|ARR Entity type string(s) * subtypes => STR|ARR Entity subtype string(s) * type_subtype_pairs => ARR Array of type => subtype pairs where subtype * can be an array of subtype strings * * posted_time_lower => INT The lower bound on the time posted * posted_time_upper => INT The upper bound on the time posted * * @return bool * @since 1.8.0 * @deprecated 2.3 Use elgg_get_river() and call delete() on the returned item(s) */ function elgg_delete_river(array $options = array()) { global $CONFIG; // allow core to use this in 2.x w/o warnings if (empty($options['__bypass_notice'])) { elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_get_river() and call delete() on the returned item(s)', '2.3'); } $defaults = array('ids' => ELGG_ENTITIES_ANY_VALUE, 'subject_guids' => ELGG_ENTITIES_ANY_VALUE, 'object_guids' => ELGG_ENTITIES_ANY_VALUE, 'target_guids' => ELGG_ENTITIES_ANY_VALUE, 'annotation_ids' => ELGG_ENTITIES_ANY_VALUE, 'views' => ELGG_ENTITIES_ANY_VALUE, 'action_types' => ELGG_ENTITIES_ANY_VALUE, 'types' => ELGG_ENTITIES_ANY_VALUE, 'subtypes' => ELGG_ENTITIES_ANY_VALUE, 'type_subtype_pairs' => ELGG_ENTITIES_ANY_VALUE, 'posted_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'posted_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'wheres' => array(), 'joins' => array()); $options = array_merge($defaults, $options); $singulars = array('id', 'subject_guid', 'object_guid', 'target_guid', 'annotation_id', 'action_type', 'view', 'type', 'subtype'); $options = _elgg_normalize_plural_options_array($options, $singulars); $wheres = $options['wheres']; $wheres[] = _elgg_get_guid_based_where_sql('rv.id', $options['ids']); $wheres[] = _elgg_get_guid_based_where_sql('rv.subject_guid', $options['subject_guids']); $wheres[] = _elgg_get_guid_based_where_sql('rv.object_guid', $options['object_guids']); $wheres[] = _elgg_get_guid_based_where_sql('rv.target_guid', $options['target_guids']); $wheres[] = _elgg_get_guid_based_where_sql('rv.annotation_id', $options['annotation_ids']); $wheres[] = _elgg_river_get_action_where_sql($options['action_types']); $wheres[] = _elgg_river_get_view_where_sql($options['views']); $wheres[] = _elgg_get_river_type_subtype_where_sql('rv', $options['types'], $options['subtypes'], $options['type_subtype_pairs']); if ($options['posted_time_lower'] && is_int($options['posted_time_lower'])) { $wheres[] = "rv.posted >= {$options['posted_time_lower']}"; } if ($options['posted_time_upper'] && is_int($options['posted_time_upper'])) { $wheres[] = "rv.posted <= {$options['posted_time_upper']}"; } // see if any functions failed // remove empty strings on successful functions foreach ($wheres as $i => $where) { if ($where === false) { return false; } elseif (empty($where)) { unset($wheres[$i]); } } // remove identical where clauses $wheres = array_unique($wheres); $query = "DELETE rv.* FROM {$CONFIG->dbprefix}river rv "; // remove identical join clauses $joins = array_unique($options['joins']); // add joins foreach ($joins as $j) { $query .= " {$j} "; } // add wheres $query .= ' WHERE '; foreach ($wheres as $w) { $query .= " {$w} AND "; } $query .= "1=1"; return delete_data($query); }
/** * Routes the request to a registered page handler * * This function triggers a plugin hook `'route', $identifier` so that plugins can * modify the routing or handle a request. * * @param \Elgg\Http\Request $request The request to handle. * @return boolean Whether the request was routed successfully. * @access private */ public function route(\Elgg\Http\Request $request) { $segments = $request->getUrlSegments(); if ($segments) { $identifier = array_shift($segments); } else { $identifier = ''; // this plugin hook is deprecated. Use elgg_register_page_handler() // to register for the '' (empty string) handler. // allow plugins to override the front page (return true to indicate // that the front page has been served) $result = _elgg_services()->hooks->trigger('index', 'system', null, false); if ($result === true) { elgg_deprecated_notice("The 'index', 'system' plugin has been deprecated. See elgg_front_page_handler()", 1.9); exit; } } // return false to stop processing the request (because you handled it) // return a new $result array if you want to route the request differently $result = array('identifier' => $identifier, 'handler' => $identifier, 'segments' => $segments); if ($this->timer) { $this->timer->begin(['build page']); } $result = $this->hooks->trigger('route', $identifier, $result, $result); if ($result === false) { return true; } if ($identifier != $result['identifier']) { $identifier = $result['identifier']; } else { if ($identifier != $result['handler']) { $identifier = $result['handler']; } } $segments = $result['segments']; $handled = false; ob_start(); if (isset($this->handlers[$identifier]) && is_callable($this->handlers[$identifier])) { $function = $this->handlers[$identifier]; $handled = call_user_func($function, $segments, $identifier); } $output = ob_get_clean(); $ajax_api = _elgg_services()->ajax; if ($ajax_api->isReady()) { $path = implode('/', $request->getUrlSegments()); $ajax_api->respondFromOutput($output, "path:{$path}"); return true; } echo $output; return $handled || headers_sent(); }
/** * Given a message key, returns an appropriately translated full-text string * * @param string $message_key The short message code * @param array $args An array of arguments to pass through vsprintf(). * @param string $language Optionally, the standard language code * (defaults to site/user default, then English) * * @return string Either the translated string, the English string, * or the original language string. */ function translate($message_key, $args = array(), $language = "") { static $CURRENT_LANGUAGE; // old param order is deprecated if (!is_array($args)) { elgg_deprecated_notice('As of Elgg 1.8, the 2nd arg to elgg_echo() is an array of string replacements and the 3rd arg is the language.', 1.8); $language = $args; $args = array(); } if (!isset($GLOBALS['_ELGG']->translations)) { // this means we probably had an exception before translations were initialized $this->registerTranslations($this->defaultPath); } if (!$CURRENT_LANGUAGE) { $CURRENT_LANGUAGE = $this->getLanguage(); } if (!$language) { $language = $CURRENT_LANGUAGE; } if (!isset($GLOBALS['_ELGG']->translations[$language])) { // The language being requested is not the same as the language of the // logged in user, so we will have to load it separately. (Most likely // we're sending a notification and the recipient is using a different // language than the logged in user.) _elgg_load_translations_for_language($language); } if (isset($GLOBALS['_ELGG']->translations[$language][$message_key])) { $string = $GLOBALS['_ELGG']->translations[$language][$message_key]; } else { if (isset($GLOBALS['_ELGG']->translations["en"][$message_key])) { $string = $GLOBALS['_ELGG']->translations["en"][$message_key]; _elgg_services()->logger->notice(sprintf('Missing %s translation for "%s" language key', $language, $message_key)); } else { $string = $message_key; _elgg_services()->logger->notice(sprintf('Missing English translation for "%s" language key', $message_key)); } } // only pass through if we have arguments to allow backward compatibility // with manual sprintf() calls. if ($args) { $string = vsprintf($string, $args); } return $string; }
/** * Construct a metadata object * * Plugin developers will probably never need to use this API. See \ElggEntity * for its API for setting and getting metadata. * * @param \stdClass $row Database row as \stdClass object */ public function __construct($row = null) { $this->initializeAttributes(); if (!empty($row)) { // Create from db row if ($row instanceof \stdClass) { $metadata = $row; $objarray = (array) $metadata; foreach ($objarray as $key => $value) { $this->attributes[$key] = $value; } } else { // get an \ElggMetadata object and copy its attributes elgg_deprecated_notice('Passing an ID to constructor is deprecated. Use elgg_get_metadata_from_id()', 1.9); $metadata = elgg_get_metadata_from_id($row); $this->attributes = $metadata->attributes; } } }
/** * Given a message key, returns an appropriately translated full-text string * * @param string $message_key The short message code * @param array $args An array of arguments to pass through vsprintf(). * @param string $language Optionally, the standard language code * (defaults to site/user default, then English) * * @return string Either the translated string, the English string, * or the original language string. */ function elgg_echo($message_key, $args = array(), $language = "") { global $CONFIG; static $CURRENT_LANGUAGE; // old param order is deprecated if (!is_array($args)) { elgg_deprecated_notice('As of Elgg 1.8, the 2nd arg to elgg_echo() is an array of string replacements and the 3rd arg is the language.', 1.8); $language = $args; $args = array(); } if (!$CURRENT_LANGUAGE) { $CURRENT_LANGUAGE = get_language(); } if (!$language) { $language = $CURRENT_LANGUAGE; } if (!isset($CONFIG->translations[$language])) { // The language being requested is not the same as the language of the // logged in user, so we will have to load it separately. (Most likely // we're sending a notification and the recipient is using a different // language than the logged in user.) _elgg_load_translations_for_language($language); } if (isset($CONFIG->translations[$language][$message_key])) { $string = $CONFIG->translations[$language][$message_key]; } else { if (isset($CONFIG->translations["en"][$message_key])) { $string = $CONFIG->translations["en"][$message_key]; elgg_log(sprintf('Missing %s translation for "%s" language key', $language, $message_key), 'NOTICE'); } else { $string = $message_key; elgg_log(sprintf('Missing English translation for "%s" language key', $message_key), 'NOTICE'); } } // only pass through if we have arguments to allow backward compatibility // with manual sprintf() calls. if ($args) { $string = vsprintf($string, $args); } return $string; }
/** * Triggers an Elgg event. * * @see elgg_trigger_event * @see elgg_trigger_after_event * @access private */ public function trigger($event, $type, $object = null, array $options = array()) { $options = array_merge(array(self::OPTION_STOPPABLE => true, self::OPTION_DEPRECATION_MESSAGE => '', self::OPTION_DEPRECATION_VERSION => ''), $options); $events = $this->getOrderedHandlers($event, $type); if ($events && $options[self::OPTION_DEPRECATION_MESSAGE]) { elgg_deprecated_notice($options[self::OPTION_DEPRECATION_MESSAGE], $options[self::OPTION_DEPRECATION_VERSION], 2); } $args = array($event, $type, $object); foreach ($events as $callback) { if (!is_callable($callback)) { if ($this->logger) { $this->logger->warn("handler for event [{$event}, {$type}] is not callable: " . $this->describeCallable($callback)); } continue; } $return = call_user_func_array($callback, $args); if (!empty($options[self::OPTION_STOPPABLE]) && $return === false) { return false; } } return true; }
/** * Request user validation email. * Send email out to the address and request a confirmation. * * @param int $user_guid The user's GUID * @param bool $admin_requested Was it requested by admin * @return mixed */ function uservalidationbyemail_request_validation($user_guid, $admin_requested = 'deprecated') { if ($admin_requested != 'deprecated') { elgg_deprecated_notice('Second param $admin_requested no more used in uservalidationbyemail_request_validation function', 1.9); } $site = elgg_get_site_entity(); $user_guid = (int) $user_guid; $user = get_entity($user_guid); if ($user && $user instanceof ElggUser) { // Work out validate link $code = uservalidationbyemail_generate_code($user_guid, $user->email); $link = "{$site->url}uservalidationbyemail/confirm?u={$user_guid}&c={$code}"; // Get email to show in the next page elgg_get_session()->set('emailsent', $user->email); $subject = elgg_echo('email:validate:subject', array($user->name, $site->name), $user->language); $body = elgg_echo('email:validate:body', array($user->name, $site->name, $link, $site->name, $site->url), $user->language); // Send validation email $result = notify_user($user->guid, $site->guid, $subject, $body, array(), 'email'); return $result; } return FALSE; }
/** * Given a message key, returns an appropriately translated full-text string * * @param string $message_key The short message code * @param array $args An array of arguments to pass through vsprintf(). * @param string $language Optionally, the standard language code * (defaults to site/user default, then English) * * @return string Either the translated string, the English string, * or the original language string. */ function elgg_echo($message_key, $args = array(), $language = "") { global $CONFIG; static $CURRENT_LANGUAGE; // old param order is deprecated if (!is_array($args)) { elgg_deprecated_notice('As of Elgg 1.8, the 2nd arg to elgg_echo() is an array of string replacements and the 3rd arg is the language.', 1.8); $language = $args; $args = array(); } if (!isset($CONFIG->translations)) { // this means we probably had an exception before translations were initialized register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/"); } if (!$CURRENT_LANGUAGE) { $CURRENT_LANGUAGE = get_language(); } if (!$language) { $language = $CURRENT_LANGUAGE; } if (isset($CONFIG->translations[$language][$message_key])) { $string = $CONFIG->translations[$language][$message_key]; } else { if (isset($CONFIG->translations["en"][$message_key])) { $string = $CONFIG->translations["en"][$message_key]; $lang = $CONFIG->translations["en"][$language]; elgg_log(sprintf('Missing %s translation for "%s" language key', $lang, $message_key), 'NOTICE'); } else { $string = $message_key; elgg_log(sprintf('Missing English translation for "%s" language key', $message_key), 'NOTICE'); } } // only pass through if we have arguments to allow backward compatibility // with manual sprintf() calls. if ($args) { $string = vsprintf($string, $args); } return $string; }
/** * Construct a new group entity, optionally from a given guid value. * * @param mixed $guid If an int, load that GUID. * If an entity table db row, then will load the rest of the data. * * @throws IOException|InvalidParameterException if there was a problem creating the group. */ function __construct($guid = null) { $this->initializeAttributes(); // compatibility for 1.7 api. $this->initialise_attributes(false); if (!empty($guid)) { // Is $guid is a entity table DB row if ($guid instanceof stdClass) { // Load the rest if (!$this->load($guid)) { $msg = elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid->guid)); throw new IOException($msg); } } else { if ($guid instanceof ElggGroup) { // $guid is an ElggGroup so this is a copy constructor elgg_deprecated_notice('This type of usage of the ElggGroup constructor was deprecated. Please use the clone method.', 1.7); foreach ($guid->attributes as $key => $value) { $this->attributes[$key] = $value; } } else { if ($guid instanceof ElggEntity) { // @todo why separate from else throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggGroup')); } else { if (is_numeric($guid)) { // $guid is a GUID so load entity if (!$this->load($guid)) { throw new IOException(elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid))); } } else { throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue')); } } } } } }
/** * Load or create a new ElggObject. * * If no arguments are passed, create a new entity. * * If an argument is passed attempt to load a full Object entity. Arguments * can be: * - The GUID of an object entity. * - A DB result object with a guid property * * @param mixed $guid If an int, load that GUID. If a db row then will attempt to * load the rest of the data. * * @throws IOException If passed an incorrect guid * @throws InvalidParameterException If passed an Elgg* Entity that isn't an ElggObject */ function __construct($guid = null) { $this->initializeAttributes(); // compatibility for 1.7 api. $this->initialise_attributes(false); if (!empty($guid)) { // Is $guid is a DB row - either a entity row, or a object table row. if ($guid instanceof stdClass) { // Load the rest if (!$this->load($guid->guid)) { $msg = elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid->guid)); throw new IOException($msg); } // Is $guid is an ElggObject? Use a copy constructor } else { if ($guid instanceof ElggObject) { elgg_deprecated_notice('This type of usage of the ElggObject constructor was deprecated. Please use the clone method.', 1.7); foreach ($guid->attributes as $key => $value) { $this->attributes[$key] = $value; } // Is this is an ElggEntity but not an ElggObject = ERROR! } else { if ($guid instanceof ElggEntity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggObject')); // We assume if we have got this far, $guid is an int } else { if (is_numeric($guid)) { if (!$this->load($guid)) { throw new IOException(elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid))); } } else { throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnrecognisedValue')); } } } } } }
/** * Create a new \ElggObject. * * Plugin developers should only use the constructor to create a new entity. * To retrieve entities, use get_entity() and the elgg_get_entities* functions. * * If no arguments are passed, it creates a new entity. * If a database result is passed as a \stdClass instance, it instantiates * that entity. * * @param \stdClass $row Database row result. Default is null to create a new object. * * @throws IOException If cannot load remaining data from db * @throws InvalidParameterException If not passed a db row result */ public function __construct($row = null) { $this->initializeAttributes(); if (!empty($row)) { // Is $row is a DB row from the entity table if ($row instanceof \stdClass) { // Load the rest if (!$this->load($row)) { $msg = "Failed to load new " . get_class() . " for GUID: " . $row->guid; throw new \IOException($msg); } } else { if (is_numeric($row)) { // $row is a GUID so load elgg_deprecated_notice('Passing a GUID to constructor is deprecated. Use get_entity()', 1.9); if (!$this->load($row)) { throw new \IOException("Failed to load new " . get_class() . " from GUID:" . $row); } } else { throw new \InvalidParameterException("Unrecognized value passed to constuctor."); } } } }
/** * Is someone using the deprecated override * * @param \Elgg\Notifications\Event $event Event * @return boolean */ protected function existsDeprecatedNotificationOverride(\Elgg\Notifications\Event $event) { $entity = $event->getObject(); if (!elgg_instanceof($entity)) { return false; } $params = array('event' => $event->getAction(), 'object_type' => $entity->getType(), 'object' => $entity); $hookresult = $this->hooks->trigger('object:notifications', $entity->getType(), $params, false); if ($hookresult === true) { elgg_deprecated_notice("Using the plugin hook 'object:notifications' has been deprecated by the hook 'send:before', 'notifications'", 1.9); return true; } else { return false; } }
/** * Set metadata on this entity. * * Plugin developers usually want to use the magic set method ($entity->name = 'value'). * Use this method if you want to explicitly set the owner or access of the metadata. * You cannot set the owner/access before the entity has been saved. * * @param string $name Name of the metadata * @param mixed $value Value of the metadata (doesn't support assoc arrays) * @param string $value_type 'text', 'integer', or '' for automatic detection * @param bool $multiple Allow multiple values for a single name. * Does not support associative arrays. * @param int $owner_guid GUID of entity that owns the metadata. * Default is owner of entity. * @param int $access_id Who can read the metadata relative to the owner (deprecated). * Default is the access level of the entity. Use ACCESS_PUBLIC for * compatibility with Elgg 3.0 * * @return bool * @throws InvalidArgumentException */ public function setMetadata($name, $value, $value_type = '', $multiple = false, $owner_guid = 0, $access_id = null) { // normalize value to an array that we will loop over // remove indexes if value already an array. if (is_array($value)) { $value = array_values($value); } else { $value = array($value); } // saved entity. persist md to db. if ($this->guid) { // if overwriting, delete first. if (!$multiple) { $options = array('guid' => $this->getGUID(), 'metadata_name' => $name, 'limit' => 0); // @todo in 1.9 make this return false if can't add metadata // https://github.com/elgg/elgg/issues/4520 // // need to remove access restrictions right now to delete // because this is the expected behavior $ia = elgg_set_ignore_access(true); if (false === elgg_delete_metadata($options)) { return false; } elgg_set_ignore_access($ia); } $owner_guid = $owner_guid ? (int) $owner_guid : $this->owner_guid; if ($access_id === null) { $access_id = $this->access_id; } elseif ($access_id != ACCESS_PUBLIC) { $access_id = (int) $access_id; elgg_deprecated_notice('Setting $access_id to a value other than ACCESS_PUBLIC is deprecated. ' . 'All metadata will be public in 3.0.', '2.3'); } // add new md $result = true; foreach ($value as $value_tmp) { // at this point $value is appended because it was cleared above if needed. $md_id = _elgg_services()->metadataTable->create($this->guid, $name, $value_tmp, $value_type, $owner_guid, $access_id, true); if (!$md_id) { return false; } } return $result; } else { // unsaved entity. store in temp array // returning single entries instead of an array of 1 element is decided in // getMetaData(), just like pulling from the db. if ($owner_guid != 0 || $access_id !== null) { $msg = "owner guid and access id cannot be used in \\ElggEntity::setMetadata() until entity is saved."; throw new \InvalidArgumentException($msg); } // if overwrite, delete first if (!$multiple || !isset($this->temp_metadata[$name])) { $this->temp_metadata[$name] = array(); } // add new md $this->temp_metadata[$name] = array_merge($this->temp_metadata[$name], $value); return true; } }
<?php /** * Profile widgets/tools * */ if (elgg_get_plugin_setting("group_enable", "widget_manager") == "yes" && $vars["entity"]->widget_manager_enable == "yes") { $params = array('num_columns' => 2, 'exact_match' => true); // need context = groups to fix the issue with the new group_profile context elgg_push_context("groups"); echo elgg_view_layout('widgets', $params); elgg_pop_context(); } else { // traditional view // tools widget area echo '<ul id="groups-tools" class="elgg-gallery elgg-gallery-fluid mtl clearfix">'; // enable tools to extend this area echo elgg_view("groups/tool_latest", $vars); // backward compatibility $right = elgg_view('groups/right_column', $vars); $left = elgg_view('groups/left_column', $vars); if ($right || $left) { elgg_deprecated_notice('The views groups/right_column and groups/left_column have been replaced by groups/tool_latest', 1.8); echo $left; echo $right; } echo "</ul>"; }
/** * Return a list of today's entities. * * @see list_notable_entities * * @param string $type The type of entity (eg "user", "object" etc) * @param string $subtype The arbitrary subtype of the entity * @param int $owner_guid The GUID of the owning user * @param int $limit The number of entities to return; 10 by default * @param boolean $fullview Whether or not to display the full view (default: true) * @param boolean $listtypetoggle Whether or not to allow gallery view * @param boolean $navigation Display pagination? Default: true * * @return string A viewable list of entities * @access private * @deprecated 1.9 */ function list_todays_entities($type = "", $subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $listtypetoggle = false, $navigation = true) { elgg_deprecated_notice('list_todays_entities() has been deprecated', 1.9); $day_start = get_day_start(); $day_end = get_day_end(); return list_notable_entities($day_start, $day_end, $type, $subtype, $owner_guid, $limit, $fullview, $listtypetoggle, $navigation); }
/** * Save a value as private setting or attribute. * * Attributes include title and description. * * @param string $name Name * @param mixed $value Value * @return bool */ public function set($name, $value) { elgg_deprecated_notice("Use -> instead of set()", 1.9); $this->__set($name, $value); return true; }
<?php /** * Elgg list view switcher * * @package Elgg * @subpackage Core * * @deprecated 1.8 See how file plugin adds a toggle in function file_register_toggle() */ elgg_deprecated_notice('navigation/viewtype was deprecated', 1.8);
<?php /** * Main content header * * Title and title menu * * @uses $vars['header_override'] HTML for overriding the default header (override) * @uses $vars['title'] Title text (override) * @uses $vars['context'] Page context (override) */ if (isset($vars['buttons'])) { // it was a bad idea to implement buttons with a pass through elgg_deprecated_notice("Use elgg_register_menu_item() to register for the title menu", 1.0); } if (isset($vars['header_override'])) { echo $vars['header_override']; return true; } $context = elgg_extract('context', $vars, elgg_get_context()); if (isset($vars['title']) && $vars['title'] != '') { $title = elgg_extract('title', $vars); $title = elgg_view_title($title, array('class' => 'zhaohu-heading-main')); echo '<div id="pg_id">' . $title . "</div>"; }
/** * Get popular tags and their frequencies * * Supports similar arguments as elgg_get_entities() * * @param array $options Array in format: * * threshold => INT minimum tag count * * tag_names => array() metadata tag names - must be registered tags * * limit => INT number of tags to return * * types => null|STR entity type (SQL: type = '$type') * * subtypes => null|STR entity subtype (SQL: subtype = '$subtype') * * type_subtype_pairs => null|ARR (array('type' => 'subtype')) * (SQL: type = '$type' AND subtype = '$subtype') pairs * * owner_guids => null|INT entity guid * * container_guids => null|INT container_guid * * site_guids => null (current_site)|INT site_guid * * created_time_lower => null|INT Created time lower boundary in epoch time * * created_time_upper => null|INT Created time upper boundary in epoch time * * modified_time_lower => null|INT Modified time lower boundary in epoch time * * modified_time_upper => null|INT Modified time upper boundary in epoch time * * wheres => array() Additional where clauses to AND together * * joins => array() Additional joins * * @return object[]|false If no tags or error, false * otherwise, array of objects with ->tag and ->total values * @since 1.7.1 */ function elgg_get_tags(array $options = array()) { global $CONFIG; $defaults = array('threshold' => 1, 'tag_names' => array(), 'limit' => 10, 'types' => ELGG_ENTITIES_ANY_VALUE, 'subtypes' => ELGG_ENTITIES_ANY_VALUE, 'type_subtype_pairs' => ELGG_ENTITIES_ANY_VALUE, 'owner_guids' => ELGG_ENTITIES_ANY_VALUE, 'container_guids' => ELGG_ENTITIES_ANY_VALUE, 'site_guids' => $CONFIG->site_guid, 'modified_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'modified_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'created_time_lower' => ELGG_ENTITIES_ANY_VALUE, 'created_time_upper' => ELGG_ENTITIES_ANY_VALUE, 'joins' => array(), 'wheres' => array()); $options = array_merge($defaults, $options); $singulars = array('type', 'subtype', 'owner_guid', 'container_guid', 'site_guid', 'tag_name'); $options = _elgg_normalize_plural_options_array($options, $singulars); $registered_tags = elgg_get_registered_tag_metadata_names(); if (!is_array($options['tag_names'])) { return false; } // empty array so use all registered tag names if (count($options['tag_names']) == 0) { $options['tag_names'] = $registered_tags; } $diff = array_diff($options['tag_names'], $registered_tags); if (count($diff) > 0) { elgg_deprecated_notice('Tag metadata names must be registered by elgg_register_tag_metadata_name()', 1.7); // return false; } $wheres = $options['wheres']; // catch for tags that were spaces $wheres[] = "msv.string != ''"; $sanitised_tags = array(); foreach ($options['tag_names'] as $tag) { $sanitised_tags[] = '"' . sanitise_string($tag) . '"'; } $tags_in = implode(',', $sanitised_tags); $wheres[] = "(msn.string IN ({$tags_in}))"; $wheres[] = _elgg_get_entity_type_subtype_where_sql('e', $options['types'], $options['subtypes'], $options['type_subtype_pairs']); $wheres[] = _elgg_get_guid_based_where_sql('e.site_guid', $options['site_guids']); $wheres[] = _elgg_get_guid_based_where_sql('e.owner_guid', $options['owner_guids']); $wheres[] = _elgg_get_guid_based_where_sql('e.container_guid', $options['container_guids']); $wheres[] = _elgg_get_entity_time_where_sql('e', $options['created_time_upper'], $options['created_time_lower'], $options['modified_time_upper'], $options['modified_time_lower']); // see if any functions failed // remove empty strings on successful functions foreach ($wheres as $i => $where) { if ($where === false) { return false; } elseif (empty($where)) { unset($wheres[$i]); } } // remove identical where clauses $wheres = array_unique($wheres); $joins = $options['joins']; $joins[] = "JOIN {$CONFIG->dbprefix}metadata md on md.entity_guid = e.guid"; $joins[] = "JOIN {$CONFIG->dbprefix}metastrings msv on msv.id = md.value_id"; $joins[] = "JOIN {$CONFIG->dbprefix}metastrings msn on md.name_id = msn.id"; // remove identical join clauses $joins = array_unique($joins); foreach ($joins as $i => $join) { if ($join === false) { return false; } elseif (empty($join)) { unset($joins[$i]); } } $query = "SELECT msv.string as tag, count(msv.id) as total "; $query .= "FROM {$CONFIG->dbprefix}entities e "; // add joins foreach ($joins as $j) { $query .= " {$j} "; } // add wheres $query .= ' WHERE '; foreach ($wheres as $w) { $query .= " {$w} AND "; } // Add access controls $query .= _elgg_get_access_where_sql(); $threshold = sanitise_int($options['threshold']); $query .= " GROUP BY msv.string HAVING total >= {$threshold} "; $query .= " ORDER BY total DESC "; $limit = sanitise_int($options['limit']); $query .= " LIMIT {$limit} "; return get_data($query); }
/** * Retrieve a entity from the cache. * * @param int $guid The guid * * @return ElggEntity|bool false if entity not cached, or not fully loaded * @access private * @deprecated 1.8 */ function retrieve_cached_entity($guid) { elgg_deprecated_notice('retrieve_cached_entity() is a private function and should not be used.', 1.8); return _elgg_retrieve_cached_entity($guid); }
* Elgg pageshell * The standard HTML page shell that everything else fits into * * @package Elgg * @subpackage Core * * @uses $vars['head'] Parameters for the <head> element * @uses $vars['body_attrs'] Attributes of the <body> tag * @uses $vars['body'] The main content of the page * @uses $vars['sysmessages'] A 2d array of various message registers, passed from system_messages() */ // backward compatability support for plugins that are not using the new approach // of routing through admin. See reportedcontent plugin for a simple example. if (elgg_get_context() == 'admin') { if (get_input('handler') != 'admin') { elgg_deprecated_notice("admin plugins should route through 'admin'.", 1.8); } _elgg_admin_add_plugin_settings_menu(); elgg_unregister_css('elgg'); echo elgg_view('page/admin', $vars); return true; } // render content before head so that JavaScript and CSS can be loaded. See #4032 $messages = elgg_view('page/elements/messages', array('object' => $vars['sysmessages'])); $header = elgg_view('page/elements/header', $vars); $content = elgg_view('page/elements/body', $vars); $footer = elgg_view('page/elements/footer', $vars); $body = <<<__BODY <div class="elgg-page elgg-page-default"> \t<div class="elgg-page-messages"> \t\t{$messages}
/** * Display or log a message. * * If $level is >= to the debug setting in {@link $CONFIG->debug}, the * message will be sent to {@link elgg_dump()}. Messages with lower * priority than {@link $CONFIG->debug} are ignored. * * Outputs all levels but NOTICE to screen by default. * * @note No messages will be displayed unless debugging has been enabled. * * @param string $message User message * @param string $level NOTICE | WARNING | ERROR * * @return bool * @since 1.7.0 */ function elgg_log($message, $level = 'NOTICE') { static $levels = array('INFO' => 200, 'NOTICE' => 250, 'WARNING' => 300, 'DEBUG' => 300, 'ERROR' => 400); if ($level == 'DEBUG') { elgg_deprecated_notice("The 'DEBUG' level for logging has been deprecated.", 1.9); } $level = $levels[$level]; return _elgg_services()->logger->log($message, $level); }