本文整理汇总了PHP中_elgg_services函数的典型用法代码示例。如果您正苦于以下问题:PHP _elgg_services函数的具体用法?PHP _elgg_services怎么用?PHP _elgg_services使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_elgg_services函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
// required by \ElggEntity when setting the owner/container
_elgg_services()->setValue('session', new \ElggSession(new \Elgg\Http\MockSessionStorage()));
$this->obj = $this->getMockBuilder('\\ElggUpgrade')->setMethods(null)->getMock();
$this->obj->_callable_egefps = array($this, 'mock_egefps');
}
示例2: get_object_entity_as_row
/**
* Return the object specific details of a object by a row.
*
* @param int $guid The guid to retrieve
*
* @return bool
* @access private
*/
function get_object_entity_as_row($guid)
{
$dbprefix = elgg_get_config('dbprefix');
$sql = "SELECT * FROM {$dbprefix}objects_entity\n\t\tWHERE guid = :guid";
$params = [':guid' => (int) $guid];
return _elgg_services()->db->getDataRow($sql, null, $params);
}
示例3: handle
/**
* {@inheritdoc}
*/
protected function handle()
{
$uri = '/' . ltrim($this->argument('uri'), '/');
$method = $this->argument('method') ?: 'GET';
$add_csrf_tokens = $this->option('tokens');
$site_url = elgg_get_site_url();
$uri = substr(elgg_normalize_url($uri), strlen($site_url));
$path_key = Application::GET_PATH_KEY;
$parameters = [];
$query = trim((string) $this->option('query'), '?');
parse_str($query, $parameters);
if ($add_csrf_tokens) {
$ts = time();
$parameters['__elgg_ts'] = $ts;
$parameters['__elgg_token'] = _elgg_services()->actions->generateActionToken($ts);
}
$request = Request::create("?{$path_key}=" . urlencode($uri), $method, $parameters);
$cookie_name = _elgg_services()->config->getCookieConfig()['session']['name'];
$session_id = _elgg_services()->session->getId();
$request->cookies->set($cookie_name, $session_id);
$request->headers->set('Referer', elgg_normalize_url());
if ($this->option('export')) {
elgg_set_viewtype('json');
$request->headers->set('X-Elgg-Ajax-API', '2');
}
_elgg_services()->setValue('request', $request);
Application::index();
}
示例4: get
/**
* Get some input from variables passed submitted through GET or POST.
*
* If using any data obtained from get_input() in a web page, please be aware that
* it is a possible vector for a reflected XSS attack. If you are expecting an
* integer, cast it to an int. If it is a string, escape quotes.
*
* Note: this function does not handle nested arrays (ex: form input of param[m][n])
* because of the filtering done in htmlawed from the filter_tags call.
* @todo Is this ^ still true?
*
* @param string $variable The variable name we want.
* @param mixed $default A default value for the variable if it is not found.
* @param bool $filter_result If true, then the result is filtered for bad tags.
*
* @return mixed
*/
function get($variable, $default = null, $filter_result = true)
{
$result = $default;
elgg_push_context('input');
if (isset($this->CONFIG->input[$variable])) {
// a plugin has already set this variable
$result = $this->CONFIG->input[$variable];
if ($filter_result) {
$result = filter_tags($result);
}
} else {
$request = _elgg_services()->request;
$value = $request->get($variable);
if ($value !== null) {
$result = $value;
if (is_string($result)) {
// @todo why trim
$result = trim($result);
}
if ($filter_result) {
$result = filter_tags($result);
}
}
}
elgg_pop_context();
return $result;
}
示例5: getService
public static function getService()
{
$db = _elgg_services()->db;
$queue = new \Elgg\Queue\DatabaseQueue('bulk_user_admin', $db);
$entities = _elgg_services()->entityTable;
return new self($queue, $entities);
}
示例6: __construct
/**
* Constructor
*/
public function __construct()
{
$sp = _elgg_services();
$this->setValue('session', \ElggSession::getMock());
$this->setFactory('db', function (MockServiceProvider $m) use($sp) {
$config = $this->getTestingDatabaseConfig();
return new \Elgg\Mocks\Database($config, $sp->logger);
});
$this->setFactory('entityTable', function (MockServiceProvider $m) use($sp) {
return new \Elgg\Mocks\Database\EntityTable($sp->config, $m->db, $sp->entityCache, $sp->metadataCache, $m->subtypeTable, $sp->events, $sp->session, $sp->translator, $sp->logger);
});
$this->setFactory('metadataTable', function (MockServiceProvider $m) use($sp) {
return new \Elgg\Mocks\Database\MetadataTable($sp->metadataCache, $m->db, $m->entityTable, $sp->events, $m->session);
});
$this->setFactory('annotations', function (MockServiceProvider $m) use($sp) {
return new \Elgg\Mocks\Database\Annotations($m->db, $m->session, $sp->events);
});
$this->setFactory('relationshipsTable', function (MockServiceProvider $m) use($sp) {
return new \Elgg\Mocks\Database\RelationshipsTable($m->db, $m->entityTable, $m->metadataTable, $sp->events);
});
$this->setFactory('subtypeTable', function (MockServiceProvider $m) {
return new \Elgg\Mocks\Database\SubtypeTable($m->db);
});
$this->setFactory('accessCollections', function (MockServiceProvider $m) use($sp) {
return new \Elgg\Mocks\Database\AccessCollections($sp->config, $m->db, $m->entityTable, $sp->accessCache, $sp->hooks, $sp->session, $sp->translator);
});
$this->setFactory('privateSettings', function (MockServiceProvider $m) use($sp) {
return new \Elgg\Mocks\Database\PrivateSettingsTable($m->db, $m->entityTable, $sp->pluginSettingsCache);
});
}
示例7: testElggSendEmailBypass
function testElggSendEmailBypass()
{
_elgg_services()->hooks->registerHandler('email', 'system', [$this, 'handleEmailHookTrue']);
$this->assertTrue(elgg_send_email("from@elgg.org", "to@elgg.org", "Hello", "World", ['foo' => 1]));
_elgg_services()->hooks->unregisterHandler('email', 'system', [$this, 'handleEmailHookTrue']);
$this->assertNull($this->mailer->getLastMessage());
}
示例8: routeAll
/**
* Check if requested page is a static page
*
* @param string $hook name of the hook
* @param string $type type of the hook
* @param array $return_value return value
* @param array $params hook parameters
*
* @return array
*/
public static function routeAll($hook, $type, $return_value, $params)
{
if (!is_array($return_value)) {
// someone else already routed this page
return;
}
/**
* $return_value contains:
* $return_value['identifier'] => requested handler
* $return_value['segments'] => url parts ($page)
*/
$identifier = elgg_extract('identifier', $return_value);
if (empty($identifier)) {
return;
}
$handlers = _elgg_services()->router->getPageHandlers();
if (elgg_extract($identifier, $handlers)) {
return;
}
$ia = elgg_set_ignore_access(true);
$entities = elgg_get_entities_from_metadata(['type' => 'object', 'subtype' => \StaticPage::SUBTYPE, 'limit' => 1, 'metadata_name_value_pairs' => ['friendly_title' => $identifier], 'metadata_case_sensitive' => false]);
elgg_set_ignore_access($ia);
if (empty($entities)) {
return;
}
$entity = $entities[0];
if (!has_access_to_entity($entity) && !$entity->canEdit()) {
return;
}
$return_value['segments'] = ['view', $entity->getGUID()];
$return_value['identifier'] = 'static';
return $return_value;
}
示例9: testSqlAdditionalSelectsAsVolatileDataWithCache
/**
* Checks if additional select columns are readable as volatile data even if we hit the cache while fetching entity.
*
* https://github.com/Elgg/Elgg/issues/5544
*/
public function testSqlAdditionalSelectsAsVolatileDataWithCache()
{
// remove ignore access as it disables entity cache
$access = elgg_set_ignore_access(false);
// may not have groups in DB - let's create one
$group = new \ElggGroup();
$group->name = 'test_group';
$group->access_id = ACCESS_PUBLIC;
$this->assertTrue($group->save() !== false);
foreach (array('site', 'user', 'group', 'object') as $type) {
$entities = elgg_get_entities(array('type' => $type, 'selects' => array('42 as added_col3'), 'limit' => 1));
$this->assertFalse(empty($entities));
if ($entities) {
$entity = array_shift($entities);
$this->assertTrue($entity instanceof \ElggEntity);
$this->assertEqual($entity->added_col3, null, "Additional select columns are leaking to attributes for " . get_class($entity));
$this->assertEqual($entity->getVolatileData('select:added_col3'), 42);
// make sure we have cached the entity
$this->assertNotEqual(false, _elgg_services()->entityCache->get($entity->guid));
}
}
// run these again but with different value to make sure cache does not interfere
foreach (array('site', 'user', 'group', 'object') as $type) {
$entities = elgg_get_entities(array('type' => $type, 'selects' => array('64 as added_col3'), 'limit' => 1));
$this->assertFalse(empty($entities));
if ($entities) {
$entity = array_shift($entities);
$this->assertTrue($entity instanceof \ElggEntity);
$this->assertEqual($entity->added_col3, null, "Additional select columns are leaking to attributes for " . get_class($entity));
$this->assertEqual($entity->getVolatileData('select:added_col3'), 64, "Failed to overwrite volatile data in cached entity");
}
}
elgg_set_ignore_access($access);
$group->delete();
}
示例10: dbvalidate_get_bad_entities
/**
* Look for entities with an owner that cannot be loaded
*/
function dbvalidate_get_bad_entities()
{
global $ENTITY_CACHE;
$access_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
$db_prefix = elgg_get_config('dbprefix');
_elgg_services()->db->disableQueryCache();
$query = "SELECT COUNT(*) as total from {$db_prefix}entities WHERE type='object' OR type='group'";
$result = get_data_row($query);
$num_entities = $result->total;
$bad_guids = array();
// handle 1000 at time
$count = 0;
$step = 1000;
while ($count < $num_entities) {
// flush caches so that we don't have memory issues
$ENTITY_CACHE = array();
$query = "SELECT guid, owner_guid from {$db_prefix}entities WHERE type='object' OR type='group' LIMIT {$count}, {$step}";
$guids = get_data($query);
$count = $count += $step;
// looking for 0 owner or an owner that cannot be loaded
foreach ($guids as $guid) {
if ($guid->owner_guid == 0) {
$bad_guids[] = $guid->guid;
} else {
if (!get_entity($guid->owner_guid)) {
$bad_guids[] = $guid->guid;
}
}
}
}
_elgg_services()->db->enableQueryCache();
access_show_hidden_entities($access_status);
return $bad_guids;
}
示例11: saveUserNotificationsSettings
/**
* Save the wire_tools preferences for the user
*
* @param string $hook the name of the hook
* @param stirng $type the type of the hook
* @param array $return_value the current return value
* @param array $params supplied values
*
* @return void
*/
public static function saveUserNotificationsSettings($hook, $type, $return_value, $params)
{
$NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethods();
if (empty($NOTIFICATION_HANDLERS) || !is_array($NOTIFICATION_HANDLERS)) {
return;
}
$user_guid = (int) get_input('guid');
if (empty($user_guid)) {
return;
}
$user = get_user($user_guid);
if (empty($user) || !$user->canEdit()) {
return;
}
$methods = [];
foreach ($NOTIFICATION_HANDLERS as $method) {
$setting = get_input("thewire_tools_{$method}");
if (!empty($setting)) {
$methods[] = $method;
}
}
if (!empty($methods)) {
elgg_set_plugin_user_setting('notification_settings', implode(',', $methods), $user->getGUID(), 'thewire_tools');
} else {
elgg_unset_plugin_user_setting('notification_settings', $user->getGUID(), 'thewire_tools');
}
// set flag for correct fallback behaviour
elgg_set_plugin_user_setting('notification_settings_saved', '1', $user->getGUID(), 'thewire_tools');
}
示例12: registration_randomizer_tarpit
/**
* Sleep for a while to slow things down.
*
* @param int $multiplier A time multipler to tarpit repeat offending IPs
*/
function registration_randomizer_tarpit($wait = 5)
{
$ip = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
$setting_name = "{$ip}_tarpit_count";
$count = (int) elgg_get_plugin_setting($setting_name, 'registration_randomizer');
if ($count > 4) {
$wait = pow(4, 4);
} else {
$wait = pow($count, 4);
}
// now limit it to something reasonable, like 90% of max execution time
$max_execution_time = ini_get('max_execution_time');
if ($max_execution_time === false) {
$max_execution_time = 30;
}
$max_execution_time = floor(0.9 * $max_execution_time);
if ($max_execution_time && $wait > $max_execution_time) {
$wait = $max_execution_time;
}
elgg_set_plugin_setting($setting_name, $count + 1, 'registration_randomizer');
registration_randomizer_log("Tarpitting {$ip} for {$wait} seconds after {$count} failures.", false);
if ($wait > 0) {
// close mysql connections for the time of a sleep
mysql_close(_elgg_services()->db->getLink('read'));
mysql_close(_elgg_services()->db->getLink('write'));
sleep($wait);
//restore connections
_elgg_services()->db->setupConnections();
}
}
示例13: setIgnoreAccess
/**
* Set ignore access.
*
* @param bool $ignore Ignore access
*
* @return bool Previous setting
*/
public function setIgnoreAccess($ignore = true)
{
_elgg_services()->accessCache->clear();
$prev = $this->ignore_access;
$this->ignore_access = $ignore;
return $prev;
}
示例14: registerHandler
/**
* {@inheritdoc}
*/
public function registerHandler($name, $type, $callback, $priority = 500)
{
if (($name == 'view' || $name == 'view_vars') && $type !== 'all') {
$type = _elgg_services()->views->canonicalizeViewName($type);
}
return parent::registerHandler($name, $type, $callback, $priority);
}
示例15: getLoggerInstance
protected function getLoggerInstance()
{
$mock = $this->getMock('\\Elgg\\PluginHooksService', array('trigger'));
$mock->expects($this->never())->method('trigger');
$sp = _elgg_services();
return new \Elgg\Logger($mock, $sp->config, $sp->context);
}