本文整理汇总了PHP中get_access_sql_suffix函数的典型用法代码示例。如果您正苦于以下问题:PHP get_access_sql_suffix函数的具体用法?PHP get_access_sql_suffix怎么用?PHP get_access_sql_suffix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_access_sql_suffix函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_number_users
/**
* Return the number of users registered in the system.
*
* @param bool $show_deactivated
* @return int
*/
function get_number_users($show_deactivated = false)
{
global $CONFIG;
$access = "";
if (!$show_deactivated) {
$access = "and " . get_access_sql_suffix();
}
$result = get_data_row("SELECT count(*) as count from {$CONFIG->dbprefix}entities where type='user' {$access}");
if ($result) {
return $result->count;
}
return false;
}
开发者ID:ashwiniravi,项目名称:Elgg-Social-Network-Single-Sign-on-and-Web-Statistics,代码行数:19,代码来源:statistics.php
示例2: hj_framework_get_order_by_descendant_count_clauses
/**
* Add sql clauses to order entities by descendants count
*
* @param array $subtypes Array of descendant subtypes
* @param str $direction Order by direction
* @param array $options Original options array
*/
function hj_framework_get_order_by_descendant_count_clauses($subtypes, $direction, $options)
{
foreach ($subtypes as $st) {
if ($id = get_subtype_id('object', $st)) {
$subtype_ids[] = $id;
}
}
$subtype_ids_str = implode(',', $subtype_ids);
if (empty($subtype_ids_str)) {
return $options;
}
$dbprefix = elgg_get_config('dbprefix');
$options['selects'][] = "COUNT(r_descendant.guid_one)";
$options['joins'][] = "JOIN {$dbprefix}entities e_descendant ON (e_descendant.subtype IN ({$subtype_ids_str}))";
$options['joins'][] = "LEFT JOIN {$dbprefix}entity_relationships r_descendant ON (e.guid = r_descendant.guid_two AND r_descendant.relationship = 'descendant' AND r_descendant.guid_one = e_descendant.guid)";
$options['wheres'][] = get_access_sql_suffix('e_descendant');
$options['group_by'] = 'e.guid';
$options['order_by'] = "count(r_descendant.guid_one) {$direction}, e.time_created DESC";
return $options;
}
示例3: get_entities_from_metadata_by_value
function get_entities_from_metadata_by_value($meta_array, $entity_type = "", $entity_subtype = "", $count = false, $owner_guid = 0, $container_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0)
{
global $CONFIG;
// ORDER BY
if ($order_by == "") {
$order_by = "e.time_created desc";
}
$order_by = sanitise_string($order_by);
$where = array();
// Filetr by metadata
$mindex = 1;
// Starting index of joined metadata/metastring tables
$join_meta = "";
$query_access = "";
foreach ($meta_array as $meta) {
$join_meta .= "JOIN {$CONFIG->dbprefix}metadata m{$mindex} on e.guid = m{$mindex}.entity_guid ";
$join_meta .= "JOIN {$CONFIG->dbprefix}metastrings v{$mindex} on v{$mindex}.id = m{$mindex}.value_id ";
$meta_n = get_metastring_id($meta['name']);
$where[] = "m{$mindex}.name_id='{$meta_n}'";
if (strtolower($meta['operand']) == "like") {
// "LIKE" search
$where[] = "v{$mindex}.string LIKE ('" . $meta['value'] . "') ";
} elseif (strtolower($meta['operand']) == "in") {
// TO DO - "IN" search
} elseif ($meta['operand'] != '') {
// Simple operand search
$where[] = "v{$mindex}.string" . $meta['operand'] . "'" . $meta['value'] . "'";
}
$query_access .= ' and ' . get_access_sql_suffix("m{$mindex}");
// Add access controls
$mindex++;
}
$limit = (int) $limit;
$offset = (int) $offset;
if (is_array($owner_guid) && count($owner_guid)) {
foreach ($owner_guid as $key => $guid) {
$owner_guid[$key] = (int) $guid;
}
} else {
$owner_guid = (int) $owner_guid;
}
if (is_array($container_guid) && count($container_guid)) {
foreach ($container_guid as $key => $guid) {
$container_guid[$key] = (int) $guid;
}
} else {
$container_guid = (int) $container_guid;
}
$site_guid = (int) $site_guid;
if ($site_guid == 0) {
$site_guid = $CONFIG->site_guid;
}
$entity_type = sanitise_string($entity_type);
if ($entity_type != "") {
$where[] = "e.type='{$entity_type}'";
}
$entity_subtype = get_subtype_id($entity_type, $entity_subtype);
if ($entity_subtype) {
$where[] = "e.subtype={$entity_subtype}";
}
if ($site_guid > 0) {
$where[] = "e.site_guid = {$site_guid}";
}
if (is_array($owner_guid)) {
$where[] = "e.owner_guid in (" . implode(",", $owner_guid) . ")";
} else {
if ($owner_guid > 0) {
$where[] = "e.owner_guid = {$owner_guid}";
}
}
if (is_array($container_guid)) {
$where[] = "e.container_guid in (" . implode(",", $container_guid) . ")";
} else {
if ($container_guid > 0) {
$where[] = "e.container_guid = {$container_guid}";
}
}
if (!$count) {
$query = "SELECT distinct e.* ";
} else {
$query = "SELECT count(distinct e.guid) as total ";
}
$query .= "FROM {$CONFIG->dbprefix}entities e ";
$query .= $join_meta;
$query .= " WHERE ";
foreach ($where as $w) {
$query .= " {$w} and ";
}
$query .= get_access_sql_suffix("e");
// Add access controls
$query .= $query_access;
if (!$count) {
$query .= " order by {$order_by} limit {$offset}, {$limit}";
// Add order and limit
return get_data($query, "entity_row_to_elggstar");
} else {
$row = get_data_row($query);
//echo $query.mysql_error().__FILE__.__LINE__;
if ($row) {
return $row->total;
//.........这里部分代码省略.........
示例4: foreach
}
// limit to current site
$join .= " JOIN {$CONFIG->dbprefix}entity_relationships site_relation ON e.guid = site_relation.guid_one";
$where[] = "site_relation.relationship='member_of_site'";
$where[] = "site_relation.guid_two = " . $CONFIG->site_guid;
// build where clauses
if (count($where) > 0) {
foreach ($where as $w) {
$where_clause .= " {$w} and ";
}
}
// add access
$access_suffix .= get_access_sql_suffix("e");
// Add access controls
for ($mindex = 1; $mindex <= count($meta_array); $mindex++) {
$access_suffix .= ' and ' . get_access_sql_suffix("m{$mindex}");
// Add access controls
}
if (empty($select)) {
$select = "distinct e.*";
}
// extend with hooks
$join = trigger_plugin_hook("extend_join", "profile_manager_member_search", null, $join);
$order = trigger_plugin_hook("extend_order", "profile_manager_member_search", null, $order);
$select = trigger_plugin_hook("extend_select", "profile_manager_member_search", null, $select);
$where_clause = trigger_plugin_hook("extend_where", "profile_manager_member_search", null, $where_clause);
// build query
$query = "from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}users_entity u on e.guid = u.guid {$join} where " . $where_clause . $access_suffix;
// execute query and retrieve entities
$count = get_data_row("SELECT count(distinct e.guid) as total " . $query);
$count = $count->total;
示例5: search_comments_hook
/**
* Get comments that match the search parameters.
*
* @param string $hook Hook name
* @param string $type Hook type
* @param array $value Empty array
* @param array $params Search parameters
* @return array
*/
function search_comments_hook($hook, $type, $value, $params)
{
$db_prefix = elgg_get_config('dbprefix');
$query = sanitise_string($params['query']);
$limit = sanitise_int($params['limit']);
$offset = sanitise_int($params['offset']);
$params['annotation_names'] = array('generic_comment', 'group_topic_post');
$params['joins'] = array("JOIN {$db_prefix}annotations a on e.guid = a.entity_guid", "JOIN {$db_prefix}metastrings msn on a.name_id = msn.id", "JOIN {$db_prefix}metastrings msv on a.value_id = msv.id");
$fields = array('string');
// force IN BOOLEAN MODE since fulltext isn't
// available on metastrings (and boolean mode doesn't need it)
$search_where = search_get_where_sql('msv', $fields, $params, FALSE);
$container_and = '';
if ($params['container_guid'] && $params['container_guid'] !== ELGG_ENTITIES_ANY_VALUE) {
$container_and = 'AND e.container_guid = ' . sanitise_int($params['container_guid']);
}
$e_access = get_access_sql_suffix('e');
$a_access = get_access_sql_suffix('a');
// @todo this can probably be done through the api..
$q = "SELECT count(DISTINCT a.id) as total FROM {$db_prefix}annotations a\n\t\tJOIN {$db_prefix}metastrings msn ON a.name_id = msn.id\n\t\tJOIN {$db_prefix}metastrings msv ON a.value_id = msv.id\n\t\tJOIN {$db_prefix}entities e ON a.entity_guid = e.guid\n\t\tWHERE msn.string IN ('generic_comment', 'group_topic_post')\n\t\t\tAND ({$search_where})\n\t\t\tAND {$e_access}\n\t\t\tAND {$a_access}\n\t\t\t{$container_and}\n\t\t";
if (!($result = get_data($q))) {
return FALSE;
}
$count = $result[0]->total;
// don't continue if nothing there...
if (!$count) {
return array('entities' => array(), 'count' => 0);
}
// no full text index on metastrings table
if ($params['sort'] == 'relevance') {
$params['sort'] = 'created';
}
$order_by = search_get_order_by_sql('a', null, $params['sort'], $params['order']);
if ($order_by) {
$order_by = "ORDER BY {$order_by}";
}
$q = "SELECT DISTINCT a.*, msv.string as comment FROM {$db_prefix}annotations a\n\t\tJOIN {$db_prefix}metastrings msn ON a.name_id = msn.id\n\t\tJOIN {$db_prefix}metastrings msv ON a.value_id = msv.id\n\t\tJOIN {$db_prefix}entities e ON a.entity_guid = e.guid\n\t\tWHERE msn.string IN ('generic_comment', 'group_topic_post')\n\t\t\tAND ({$search_where})\n\t\t\tAND {$e_access}\n\t\t\tAND {$a_access}\n\t\t\t{$container_and}\n\t\t\n\t\t{$order_by}\n\t\tLIMIT {$offset}, {$limit}\n\t\t";
$comments = get_data($q);
// @todo if plugins are disabled causing subtypes
// to be invalid and there are comments on entities of those subtypes,
// the counts will be wrong here and results might not show up correctly,
// especially on the search landing page, which only pulls out two results.
// probably better to check against valid subtypes than to do what I'm doing.
// need to return actual entities
// add the volatile data for why these entities have been returned.
$entities = array();
foreach ($comments as $comment) {
$entity = get_entity($comment->entity_guid);
// hic sunt dracones
if (!$entity) {
//continue;
$entity = new ElggObject();
$entity->setVolatileData('search_unavailable_entity', TRUE);
}
$comment_str = search_get_highlighted_relevant_substrings($comment->comment, $query);
$comments_data = $entity->getVolatileData('search_comments_data');
if (!$comments_data) {
$comments_data = array();
}
$comments_data[] = array('annotation_id' => $comment->id, 'text' => $comment_str, 'owner_guid' => $comment->owner_guid, 'time_created' => $comment->time_created);
$entity->setVolatileData('search_comments_data', $comments_data);
$entities[] = $entity;
}
return array('entities' => $entities, 'count' => $count);
}
示例6: elgg_river_get_access_sql
/**
* Get the river's access where clause
*
* @return string
* @since 1.8.0
* @access private
*/
function elgg_river_get_access_sql()
{
// rewrite default access where clause to work with river table
return str_replace("and enabled='yes'", '', str_replace('owner_guid', 'rv.subject_guid', str_replace('access_id', 'rv.access_id', get_access_sql_suffix())));
}
示例7: delete_annotation
/**
* Delete a given annotation.
*
* @param $id int The id
*/
function delete_annotation($id)
{
global $CONFIG;
$id = (int) $id;
$access = get_access_sql_suffix();
$annotation = get_annotation($id);
if (trigger_elgg_event('delete', 'annotation', $annotation)) {
return delete_data("DELETE from {$CONFIG->dbprefix}annotations where id={$id} and {$access}");
}
return false;
}
示例8: elseif
}
} elseif (substr($q, 0, 1) == "#") {
$tag = substr($q, 1);
$tags_id = elgg_get_metastring_id("tags");
$thewire_id = get_subtype_id("object", "thewire");
$query = "SELECT DISTINCT *";
$query .= " FROM (SELECT ms1.string as value";
$query .= " FROM " . elgg_get_config("dbprefix") . "entities e";
$query .= " JOIN " . elgg_get_config("dbprefix") . "metadata m ON e.guid = m.entity_guid";
$query .= " JOIN " . elgg_get_config("dbprefix") . "metastrings ms1 ON m.value_id = ms1.id";
$query .= " WHERE (e.type = 'object' AND e.subtype = " . $thewire_id . ")";
$query .= " AND (e.owner_guid = " . elgg_get_logged_in_user_guid() . ")";
$query .= " AND (m.name_id = " . $tags_id . ")";
$query .= " AND (ms1.string LIKE '%" . sanitise_string($tag) . "%')";
$query .= " AND " . get_access_sql_suffix("e");
$query .= " AND " . get_access_sql_suffix("m");
$query .= " ORDER BY m.time_created DESC) a";
$query .= " LIMIT 0, " . $limit;
$rows = get_data($query);
if (!empty($rows)) {
$metadata = array();
foreach ($rows as $row) {
if (!empty($row->value) || $row->value == 0) {
$metadata[] = $row->value;
}
}
natcasesort($metadata);
foreach ($metadata as $md) {
$result[] = array("type" => "hashtag", "value" => $md);
}
}
示例9: array
$site_options = array("type" => "site", "relationship" => "member_of_site", "relationship_guid" => $user->getGUID(), "limit" => false, "site_guids" => false);
if ($sites = elgg_get_entities_from_relationship($site_options)) {
$site_guids = array();
foreach ($sites as $row) {
$site_guids[] = $row->guid;
}
$count_query .= "e.site_guid IN (" . implode(", ", $site_guids) . ") ";
} else {
$count_query .= "e.site_guid = " . elgg_get_site_entity()->getGUID() . " ";
}
} else {
$count_query .= "e.site_guid = " . elgg_get_site_entity()->getGUID() . " ";
}
$count_query .= " AND ";
// Add access controls
$count_query .= get_access_sql_suffix('e');
$count_query .= " GROUP BY e.subtype";
$totals = get_data($count_query);
if ($totals) {
foreach ($totals as $row) {
$search_result_counters["item:object:" . $row->subtype] = $row->total;
}
}
}
}
}
// call custom searches
if ($search_type != 'entities' || $search_type == 'all') {
if (is_array($custom_types)) {
foreach ($custom_types as $type) {
if ($search_type != 'all' && $search_type != $type) {
示例10: elgg_get_tags
//.........这里部分代码省略.........
*
* 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 false/array - 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_normalise_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 != ''";
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']);
// remove identical where clauses
$wheres = array_unique($wheres);
// 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]);
}
}
$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 .= get_access_sql_suffix('e');
$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);
}
示例11: input_livesearch_page_handler
/**
* Page handler for autocomplete endpoint.
*
* @param $page
* @return unknown_type
*/
function input_livesearch_page_handler($page)
{
global $CONFIG;
// only return results to logged in users.
if (!($user = get_loggedin_user())) {
exit;
}
if (!($q = get_input('q'))) {
exit;
}
$q = mysql_real_escape_string($q);
// replace mysql vars with escaped strings
$q = str_replace(array('_', '%'), array('\\_', '\\%'), $q);
$match_on = get_input('match_on', 'all');
if ($match_on == 'all' || $match_on[0] == 'all') {
$match_on = array('users', 'groups');
}
if (!is_array($match_on)) {
$match_on = array($match_on);
}
if (get_input('match_owner', false)) {
$owner_guid = $user->getGUID();
$owner_where = 'AND e.owner_guid = ' . $user->getGUID();
} else {
$owner_guid = null;
$owner_where = '';
}
$limit = get_input('limit', 10);
// grab a list of entities and send them in json.
$results = array();
foreach ($match_on as $type) {
switch ($type) {
case 'all':
// only need to pull up title from objects.
if (!($entities = elgg_get_entities(array('owner_guid' => $owner_guid, 'limit' => $limit))) and is_array($entities)) {
$results = array_merge($results, $entities);
}
break;
case 'users':
$query = "SELECT * FROM {$CONFIG->dbprefix}users_entity as ue, {$CONFIG->dbprefix}entities as e\n\t\t\t\t\tWHERE e.guid = ue.guid\n\t\t\t\t\t\tAND e.enabled = 'yes'\n\t\t\t\t\t\tAND ue.banned = 'no'\n\t\t\t\t\t\tAND (ue.name LIKE '{$q}%' OR ue.username LIKE '{$q}%')\n\t\t\t\t\tLIMIT {$limit}\n\t\t\t\t";
if ($entities = get_data($query)) {
foreach ($entities as $entity) {
$json = json_encode(array('type' => 'user', 'name' => $entity->name, 'desc' => $entity->username, 'icon' => '<img class="livesearch_icon" src="' . get_entity($entity->guid)->getIcon('tiny') . '" />', 'guid' => $entity->guid));
$results[$entity->name . rand(1, 100)] = $json;
}
}
break;
case 'groups':
// don't return results if groups aren't enabled.
if (!is_plugin_enabled('groups')) {
continue;
}
$query = "SELECT * FROM {$CONFIG->dbprefix}groups_entity as ge, {$CONFIG->dbprefix}entities as e\n\t\t\t\t\tWHERE e.guid = ge.guid\n\t\t\t\t\t\tAND e.enabled = 'yes'\n\t\t\t\t\t\t{$owner_where}\n\t\t\t\t\t\tAND (ge.name LIKE '{$q}%' OR ge.description LIKE '%{$q}%')\n\t\t\t\t\tLIMIT {$limit}\n\t\t\t\t";
if ($entities = get_data($query)) {
foreach ($entities as $entity) {
$json = json_encode(array('type' => 'group', 'name' => $entity->name, 'desc' => strip_tags($entity->description), 'icon' => '<img class="livesearch_icon" src="' . get_entity($entity->guid)->getIcon('tiny') . '" />', 'guid' => $entity->guid));
//$results[$entity->name . rand(1,100)] = "$json|{$entity->guid}";
$results[$entity->name . rand(1, 100)] = $json;
}
}
break;
case 'friends':
$access = get_access_sql_suffix();
$query = "SELECT * FROM {$CONFIG->dbprefix}users_entity as ue, {$CONFIG->dbprefix}entity_relationships as er, {$CONFIG->dbprefix}entities as e\n\t\t\t\t\tWHERE er.relationship = 'friend'\n\t\t\t\t\t\tAND er.guid_one = {$user->getGUID()}\n\t\t\t\t\t\tAND er.guid_two = ue.guid\n\t\t\t\t\t\tAND e.guid = ue.guid\n\t\t\t\t\t\tAND e.enabled = 'yes'\n\t\t\t\t\t\tAND ue.banned = 'no'\n\t\t\t\t\t\tAND (ue.name LIKE '{$q}%' OR ue.username LIKE '{$q}%')\n\t\t\t\t\tLIMIT {$limit}\n\t\t\t\t";
if ($entities = get_data($query)) {
foreach ($entities as $entity) {
$json = json_encode(array('type' => 'user', 'name' => $entity->name, 'desc' => $entity->username, 'icon' => '<img class="livesearch_icon" src="' . get_entity($entity->guid)->getIcon('tiny') . '" />', 'guid' => $entity->guid));
$results[$entity->name . rand(1, 100)] = $json;
}
}
break;
default:
// arbitrary subtype.
//@todo you cannot specify a subtype without a type.
// did this ever work?
elgg_get_entities(array('subtype' => $type, 'owner_guid' => $owner_guid));
break;
}
}
ksort($results);
echo implode($results, "\n");
exit;
}
示例12: get_entities_replies
//.........这里部分代码省略.........
if (sizeof($subtype)) {
foreach ($subtype as $typekey => $subtypearray) {
foreach ($subtypearray as $subtypeval) {
$typekey = sanitise_string($typekey);
if (!empty($subtypeval)) {
$subtypeval = (int) get_subtype_id($typekey, $subtypeval);
} else {
$subtypeval = 0;
}
if (!empty($tempwhere)) {
$tempwhere .= " or ";
}
$tempwhere .= "(e.type = '{$typekey}' and e.subtype = {$subtypeval})";
}
}
}
if (!empty($tempwhere)) {
$where[] = "({$tempwhere})";
}
} else {
$type = sanitise_string($type);
if ($subtype !== "") {
$subtype = get_subtype_id($type, $subtype);
}
if ($type != "") {
$where[] = "e.type='{$type}'";
}
if ($subtype !== "") {
$where[] = "e.subtype={$subtype}";
}
}
if ($owner_guid != "") {
if (!is_array($owner_guid)) {
$owner_array = array($owner_guid);
$owner_guid = (int) $owner_guid;
// $where[] = "owner_guid = '$owner_guid'";
} else {
if (sizeof($owner_guid) > 0) {
$owner_array = array_map('sanitise_int', $owner_guid);
// Cast every element to the owner_guid array to int
// $owner_guid = array_map("sanitise_int", $owner_guid);
// $owner_guid = implode(",",$owner_guid);
// $where[] = "owner_guid in ({$owner_guid})";
}
}
if (is_null($container_guid)) {
$container_guid = $owner_array;
}
}
if ($site_guid > 0) {
$where[] = "e.site_guid = {$site_guid}";
}
if (!is_null($container_guid)) {
if (is_array($container_guid)) {
foreach ($container_guid as $key => $val) {
$container_guid[$key] = (int) $val;
}
$where[] = "e.container_guid in (" . implode(",", $container_guid) . ")";
} else {
$container_guid = (int) $container_guid;
$where[] = "e.container_guid = {$container_guid}";
}
}
if ($timelower) {
$where[] = "e.time_created >= {$timelower}";
}
if ($timeupper) {
$where[] = "e.time_created <= {$timeupper}";
}
if (!$count) {
$query = "SELECT e.*,o.* from {$CONFIG->dbprefix}entities e, {$CONFIG->dbprefix}objects_entity o where ";
} else {
$query = "SELECT count(e.guid) as total from {$CONFIG->dbprefix}entities e, {$CONFIG->dbprefix}objects_entity o where ";
}
foreach ($where as $w) {
$query .= " {$w} and ";
}
$query .= get_access_sql_suffix();
// Add access controls
$query .= " and e.guid=o.guid AND o.description LIKE '%{$username}%' ";
if (!$count) {
$query .= " order by {$order_by}";
if ($limit) {
$query .= " limit {$offset}, {$limit}";
}
// Add order and limit
$dt = get_data($query, "entity_row_to_elggstar");
return $dt;
} else {
$total = get_data_row($query);
return $total->total;
}
/*
SELECT e.*,o.* from elggentities e, elggobjects_entity o
where e.type='object' and e.subtype=8 and e.site_guid = 1 and ( (1 = 1) and e.enabled='yes') AND e.guid=o.guid AND o.description LIKE '%admin%'
order by time_created desc limit 0, 10
* */
}
示例13: AND
if ($tags_option == "and") {
// AND
$joins[] = "JOIN {$CONFIG->dbprefix}metadata n_table{$i} on e.guid = n_table{$i}.entity_guid";
$joins[] = "JOIN {$CONFIG->dbprefix}metastrings msn{$i} on n_table{$i}.name_id = msn{$i}.id";
$joins[] = "JOIN {$CONFIG->dbprefix}metastrings msv{$i} on n_table{$i}.value_id = msv{$i}.id";
$values_where .= " AND (msn{$i}.string IN ({$names_str}) AND msv{$i}.string = {$value})";
} else {
$values_where .= " OR (msv.string = {$value})";
}
} else {
$values_where .= "(msv.string = {$value})";
}
}
$values_where .= ")";
}
$access = get_access_sql_suffix('n_table');
if ($names_where && $values_where) {
$wheres[] = "({$names_where} AND {$values_where} AND {$access})";
} elseif ($names_where) {
$wheres[] = "({$names_where} AND {$access})";
} elseif ($values_where) {
$wheres[] = "({$values_where} AND {$access})";
}
// owner_guids
if (!empty($widget->owner_guids)) {
$owner_guids = string_to_tag_array($widget->owner_guids);
if (!empty($owner_guids)) {
foreach ($owner_guids as $key => $guid) {
$owner_guids[$key] = sanitise_int($guid);
}
}
示例14: get_entities_from_private_setting_multi
//.........这里部分代码省略.........
$tempwhere = "";
if (sizeof($type)) {
foreach ($type as $typekey => $subtypearray) {
foreach ($subtypearray as $subtypeval) {
$typekey = sanitise_string($typekey);
if (!empty($subtypeval)) {
if (!($subtypeval = (int) get_subtype_id($typekey, $subtypeval))) {
return false;
}
} else {
$subtypeval = 0;
}
if (!empty($tempwhere)) {
$tempwhere .= " or ";
}
$tempwhere .= "(e.type = '{$typekey}' and e.subtype = {$subtypeval})";
}
}
}
if (!empty($tempwhere)) {
$where[] = "({$tempwhere})";
}
} else {
$type = sanitise_string($type);
if ($subtype and !($subtype = get_subtype_id($type, $subtype))) {
return false;
}
if ($type != "") {
$where[] = "e.type='{$type}'";
}
if ($subtype !== "") {
$where[] = "e.subtype={$subtype}";
}
}
if ($owner_guid != "") {
if (!is_array($owner_guid)) {
$owner_array = array($owner_guid);
$owner_guid = (int) $owner_guid;
// $where[] = "owner_guid = '$owner_guid'";
} else {
if (sizeof($owner_guid) > 0) {
$owner_array = array_map('sanitise_int', $owner_guid);
// Cast every element to the owner_guid array to int
// $owner_guid = array_map("sanitise_int", $owner_guid);
// $owner_guid = implode(",",$owner_guid);
// $where[] = "owner_guid in ({$owner_guid})";
}
}
if (is_null($container_guid)) {
$container_guid = $owner_array;
}
}
if ($site_guid > 0) {
$where[] = "e.site_guid = {$site_guid}";
}
if (!is_null($container_guid)) {
if (is_array($container_guid)) {
foreach ($container_guid as $key => $val) {
$container_guid[$key] = (int) $val;
}
$where[] = "e.container_guid in (" . implode(",", $container_guid) . ")";
} else {
$container_guid = (int) $container_guid;
$where[] = "e.container_guid = {$container_guid}";
}
}
if ($name) {
$s_join = "";
$i = 1;
foreach ($name as $k => $n) {
$k = sanitise_string($k);
$s_join .= " JOIN {$CONFIG->dbprefix}private_settings s{$i} ON e.guid=s{$i}.entity_guid";
$where[] = "s{$i}.name = '{$k}'";
$where[] = "s{$i}.value = '{$n}'";
$i++;
}
}
if (!$count) {
$query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e {$s_join} where ";
} else {
$query = "SELECT count(distinct e.guid) as total from {$CONFIG->dbprefix}entities e {$s_join} where ";
}
foreach ($where as $w) {
$query .= " {$w} and ";
}
$query .= get_access_sql_suffix('e');
// Add access controls
if (!$count) {
$query .= " order by {$order_by}";
if ($limit) {
$query .= " limit {$offset}, {$limit}";
}
// Add order and limit
$dt = get_data($query, "entity_row_to_elggstar");
return $dt;
} else {
$total = get_data_row($query);
return $total->total;
}
}
示例15: tp_get_entities_from_annotations_calculate_x
function tp_get_entities_from_annotations_calculate_x($sum = "sum", $entity_type = "", $entity_subtype = "", $name = "", $mdname = '', $mdvalue = '', $owner_guid = 0, $limit = 10, $offset = 0, $orderdir = 'desc', $count = false)
{
global $CONFIG;
$sum = sanitise_string($sum);
$entity_type = sanitise_string($entity_type);
$entity_subtype = get_subtype_id($entity_type, $entity_subtype);
$name = get_metastring_id($name);
$limit = (int) $limit;
$offset = (int) $offset;
$owner_guid = (int) $owner_guid;
if (!empty($mdname) && !empty($mdvalue)) {
$meta_n = get_metastring_id($mdname);
$meta_v = get_metastring_id($mdvalue);
}
if (empty($name)) {
return 0;
}
$where = array();
if ($entity_type != "") {
$where[] = "e.type='{$entity_type}'";
}
if ($owner_guid > 0) {
$where[] = "e.owner_guid = {$owner_guid}";
}
if ($entity_subtype) {
$where[] = "e.subtype={$entity_subtype}";
}
if ($name != "") {
$where[] = "a.name_id='{$name}'";
}
if (!empty($mdname) && !empty($mdvalue)) {
if ($mdname != "") {
$where[] = "m.name_id='{$meta_n}'";
}
if ($mdvalue != "") {
$where[] = "m.value_id='{$meta_v}'";
}
}
if ($sum != "count") {
$where[] = "a.value_type='integer'";
}
// Limit on integer types
if (!$count) {
$query = "SELECT distinct e.*, {$sum}(ms.string) as sum ";
} else {
$query = "SELECT count(distinct e.guid) as num, {$sum}(ms.string) as sum ";
}
$query .= " from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}annotations a on a.entity_guid = e.guid JOIN {$CONFIG->dbprefix}metastrings ms on a.value_id=ms.id ";
if (!empty($mdname) && !empty($mdvalue)) {
$query .= " JOIN {$CONFIG->dbprefix}metadata m on m.entity_guid = e.guid ";
}
$query .= " WHERE ";
foreach ($where as $w) {
$query .= " {$w} and ";
}
$query .= get_access_sql_suffix("a");
// now add access
$query .= ' and ' . get_access_sql_suffix("e");
// now add access
if (!$count) {
$query .= ' group by e.guid';
}
if (!$count) {
$query .= ' order by sum ' . $orderdir;
$query .= ' limit ' . $offset . ' , ' . $limit;
return get_data($query, "entity_row_to_elggstar");
} else {
if ($row = get_data_row($query)) {
return $row->num;
}
}
return false;
}