本文整理汇总了PHP中query2array函数的典型用法代码示例。如果您正苦于以下问题:PHP query2array函数的具体用法?PHP query2array怎么用?PHP query2array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了query2array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
function __construct($id)
{
$tpl = query2array('SELECT subject,body,recipient FROM cf_mail_templates WHERE id=:id', array('id' => $id));
$this->subject = $tpl['subject'];
$this->body = $tpl['body'];
$this->recipients = explode(',', trim($tpl['recipient']));
}
示例2: isHidden
public static function isHidden($id)
{
static $q = null;
createStaticQuery($q, "SELECT hidden,parent_id FROM cf_page WHERE id=:id");
$res = query2array($q, array('id' => $id));
return $res['hidden'] ? true : ($res['parent_id'] ? Page::isHidden($res['parent_id']) : false);
}
示例3: ws_extref_categories_get
function ws_extref_categories_get($params, &$service)
{
$where = array('1=1');
// always true
if (!empty($params['category_id'])) {
$where[] = 'id = ' . $params['category_id'];
}
if (!empty($params['external_reference'])) {
if ($params['exact_match']) {
$where[] = "external_reference = '" . $params['external_reference'] . "'";
} else {
$where[] = "external_reference LIKE '%" . $params['external_reference'] . "%'";
}
}
if (!$params['show_empty']) {
$where[] = 'external_reference IS NOT NULL';
}
$query = '
SELECT
id,
external_reference
FROM ' . CATEGORIES_TABLE . '
WHERE ' . implode(' AND ', $where) . '
;';
if ('rest' == $service->_responseFormat) {
$categories = query2array($query);
} else {
$categories = query2array($query, 'id', 'external_reference');
}
return array('categories' => $categories);
}
示例4: get_cat_display_name_cache
/**
* Generates breadcrumb from categories list using a cache.
* @see get_cat_display_name()
*
* @param string $uppercats
* @param string|null $url
* @param bool $single_link
* @param string|null $link_class
* @return string
*/
function get_cat_display_name_cache($uppercats, $url = '', $single_link = false, $link_class = null, $auth_key = null)
{
global $cache, $conf;
$add_url_params = array();
if (isset($auth_key)) {
$add_url_params['auth'] = $auth_key;
}
if (!isset($cache['cat_names'])) {
$query = '
SELECT id, name, permalink
FROM ' . CATEGORIES_TABLE . '
;';
$cache['cat_names'] = query2array($query, 'id');
}
$output = '';
if ($single_link) {
$single_url = add_url_params(get_root_url() . $url . array_pop(explode(',', $uppercats)), $add_url_params);
$output .= '<a href="' . $single_url . '"';
if (isset($link_class)) {
$output .= ' class="' . $link_class . '"';
}
$output .= '>';
}
$is_first = true;
foreach (explode(',', $uppercats) as $category_id) {
$cat = $cache['cat_names'][$category_id];
$cat['name'] = trigger_change('render_category_name', $cat['name'], 'get_cat_display_name_cache');
if ($is_first) {
$is_first = false;
} else {
$output .= $conf['level_separator'];
}
if (!isset($url) or $single_link) {
$output .= $cat['name'];
} elseif ($url == '') {
$output .= '
<a href="' . add_url_params(make_index_url(array('category' => $cat)), $add_url_params) . '">' . $cat['name'] . '</a>';
} else {
$output .= '
<a href="' . PHPWG_ROOT_PATH . $url . $category_id . '">' . $cat['name'] . '</a>';
}
}
if ($single_link and isset($single_url)) {
$output .= '</a>';
}
return $output;
}
示例5: __construct
function __construct($id)
{
$user = query2array("\r\n\t\t\tSELECT login, password, salt, name, email, descr, registered, last_login, status, image\r\n\t\t\tFROM cf_users\r\n\t\t\tWHERE id=:id", array('id' => $id));
if (empty($user)) {
throw new \Exception('Invalid user');
}
$this->id = (int) $id;
$this->login = $user['login'];
$this->password = $user['password'];
$this->salt = $user['salt'];
$this->name = $user['name'];
$this->email = $user['email'];
$this->descr = $user['descr'];
$this->registered = $user['registered'];
$this->last_login = $user['last_login'];
$this->status = $user['status'];
$this->image = $user['image'];
$this->roles = query2arrays('
SELECT cf_roles.id AS id, cf_roles.name, cf_roles.descr
FROM cf_roles
INNER JOIN cf_user_roles ON cf_roles.id = cf_user_roles.role_id
WHERE cf_user_roles.user_id=:uid
ORDER BY name', array('uid' => $this->id), false, 'id');
}
示例6: query2hash
} else {
/* start table */
print "<table class=std width=100%>\n";
print "<tr>\n";
print "<th colspan=2 align=center>\n";
print "<div class=heading> " . $AppUI->_($title) . "</div>\n";
print "</th>\n";
print "</tr>\n";
/* start form */
print "<form name='ticketform' action=\"index.php?m=ticketsmith&a=followup&ticket={$ticket}\" method=post>\n";
/* get ticket */
$ticket_info = query2hash("SELECT * FROM tickets WHERE ticket = {$ticket}");
/* output From: line */
print "<tr>\n";
print "<td align=left><strong>" . $AppUI->_('From') . "</strong></td>";
list($from_name, $from_email) = query2array("SELECT CONCAT_WS(' ',contact_first_name,contact_last_name) as name, contact_email as email FROM users u LEFT JOIN contacts ON u.user_contact = contact_id WHERE user_id = '{$AppUI->user_id}'");
print "<td align=left>" . $from_name . " <" . $from_email . "></td>\n";
print "</tr>\n";
/* output To: line */
print "<tr>\n";
print "<td align=left><strong>" . $AppUI->_('To') . "</strong></td>";
$recipient = query2result("SELECT author FROM tickets WHERE ticket = '{$ticket_parent}'");
print "<td align=left>" . format_field($recipient, "recipient") . "</td>\n";
print "</tr>\n";
/* output ticket */
for ($loop = 0; $loop < count($fields["headings"]); $loop++) {
print "<tr>\n";
// do not translate if heading is "<br />"
if ($fields["headings"][$loop] == "<br />") {
} else {
$fields["headings"][$loop] = $AppUI->_($fields["headings"][$loop]);
示例7: get_cat_id_from_permalinks
/**
* Finds a matching category id from a potential list of permalinks
*
* @param string[] $permalinks
* @param int &$idx filled with the index in $permalinks that matches
* @return int|null
*/
function get_cat_id_from_permalinks($permalinks, &$idx)
{
$in = '';
foreach ($permalinks as $permalink) {
if (!empty($in)) {
$in .= ', ';
}
$in .= '\'' . $permalink . '\'';
}
$query = '
SELECT cat_id AS id, permalink, 1 AS is_old
FROM ' . OLD_PERMALINKS_TABLE . '
WHERE permalink IN (' . $in . ')
UNION
SELECT id, permalink, 0 AS is_old
FROM ' . CATEGORIES_TABLE . '
WHERE permalink IN (' . $in . ')
;';
$perma_hash = query2array($query, 'permalink');
if (empty($perma_hash)) {
return null;
}
for ($i = count($permalinks) - 1; $i >= 0; $i--) {
if (isset($perma_hash[$permalinks[$i]])) {
$idx = $i;
$cat_id = $perma_hash[$permalinks[$i]]['id'];
if ($perma_hash[$permalinks[$i]]['is_old']) {
$query = '
UPDATE ' . OLD_PERMALINKS_TABLE . ' SET last_hit=NOW(), hit=hit+1
WHERE permalink=\'' . $permalinks[$i] . '\' AND cat_id=' . $cat_id . '
LIMIT 1';
pwg_query($query);
}
return $cat_id;
}
}
return null;
}
示例8: get_recent_post_dates
/**
* Returns information about recently published elements grouped by post date.
*
* @param int $max_dates maximum number of recent dates
* @param int $max_elements maximum number of elements per date
* @param int $max_cats maximum number of categories per date
* @return array
*/
function get_recent_post_dates($max_dates, $max_elements, $max_cats)
{
global $conf, $user, $persistent_cache;
$cache_key = $persistent_cache->make_key('recent_posts' . $user['id'] . $user['cache_update_time'] . $max_dates . $max_elements . $max_cats);
if ($persistent_cache->get($cache_key, $cached)) {
return $cached;
}
$where_sql = get_std_sql_where_restrict_filter('WHERE', 'i.id', true);
$query = '
SELECT
date_available,
COUNT(DISTINCT id) AS nb_elements,
COUNT(DISTINCT category_id) AS nb_cats
FROM ' . IMAGES_TABLE . ' i INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS ic ON id=image_id
' . $where_sql . '
GROUP BY date_available
ORDER BY date_available DESC
LIMIT ' . $max_dates . '
;';
$dates = query2array($query);
for ($i = 0; $i < count($dates); $i++) {
if ($max_elements > 0) {
// get some thumbnails ...
$query = '
SELECT DISTINCT i.*
FROM ' . IMAGES_TABLE . ' i
INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS ic ON id=image_id
' . $where_sql . '
AND date_available=\'' . $dates[$i]['date_available'] . '\'
ORDER BY ' . DB_RANDOM_FUNCTION . '()
LIMIT ' . $max_elements . '
;';
$dates[$i]['elements'] = query2array($query);
}
if ($max_cats > 0) {
// get some categories ...
$query = '
SELECT
DISTINCT c.uppercats,
COUNT(DISTINCT i.id) AS img_count
FROM ' . IMAGES_TABLE . ' i
INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS ic ON i.id=image_id
INNER JOIN ' . CATEGORIES_TABLE . ' c ON c.id=category_id
' . $where_sql . '
AND date_available=\'' . $dates[$i]['date_available'] . '\'
GROUP BY category_id, c.uppercats
ORDER BY img_count DESC
LIMIT ' . $max_cats . '
;';
$dates[$i]['categories'] = query2array($query);
}
}
$persistent_cache->set($cache_key, $dates);
return $dates;
}
示例9: ws_categories_getAdminList
/**
* API method
* Returns the list of categories as you can see them in administration
* @param mixed[] $params
*
* Only admin can run this method and permissions are not taken into
* account.
*/
function ws_categories_getAdminList($params, &$service)
{
$query = '
SELECT category_id, COUNT(*) AS counter
FROM ' . IMAGE_CATEGORY_TABLE . '
GROUP BY category_id
;';
$nb_images_of = query2array($query, 'category_id', 'counter');
$query = '
SELECT id, name, comment, uppercats, global_rank, dir
FROM ' . CATEGORIES_TABLE . '
;';
$result = pwg_query($query);
$cats = array();
while ($row = pwg_db_fetch_assoc($result)) {
$id = $row['id'];
$row['nb_images'] = isset($nb_images_of[$id]) ? $nb_images_of[$id] : 0;
$row['name'] = strip_tags(trigger_change('render_category_name', $row['name'], 'ws_categories_getAdminList'));
$row['fullname'] = strip_tags(get_cat_display_name_cache($row['uppercats'], null));
$row['comment'] = strip_tags(trigger_change('render_category_description', $row['comment'], 'ws_categories_getAdminList'));
$cats[] = $row;
}
usort($cats, 'global_rank_compare');
return array('categories' => new PwgNamedArray($cats, 'category', array('id', 'nb_images', 'name', 'uppercats', 'global_rank')));
}
示例10: find_tags
/**
* Return a list of tags corresponding to any of ids, url_names or names.
*
* @param int[] $ids
* @param string[] $url_names
* @param string[] $names
* @return array [id, name, url_name]
*/
function find_tags($ids = array(), $url_names = array(), $names = array())
{
$where_clauses = array();
if (!empty($ids)) {
$where_clauses[] = 'id IN (' . implode(',', $ids) . ')';
}
if (!empty($url_names)) {
$where_clauses[] = 'url_name IN (\'' . implode('\', \'', $url_names) . '\')';
}
if (!empty($names)) {
$where_clauses[] = 'name IN (\'' . implode('\', \'', $names) . '\')';
}
if (empty($where_clauses)) {
return array();
}
$query = '
SELECT *
FROM ' . TAGS_TABLE . '
WHERE ' . implode('
OR ', $where_clauses);
return query2array($query);
}
示例11: array_from_query
/**
* creates a numeric array based on a SQL query.
* if _$fieldname_ is empty the returned value will be an array of arrays
* if _$fieldname_ is provided the returned value will be a one dimension array
* @deprecated 2.6
*
* @param string $query
* @param string $fieldname
* @return array
*/
function array_from_query($query, $fieldname = false)
{
if (false === $fieldname) {
return query2array($query);
} else {
return query2array($query, null, $fieldname);
}
}
示例12: get_quick_search_results_no_cache
/**
* @see get_quick_search_results but without result caching
*/
function get_quick_search_results_no_cache($q, $options)
{
global $conf;
$q = trim(stripslashes($q));
$search_results = array('items' => array(), 'qs' => array('q' => $q));
$q = trigger_change('qsearch_pre', $q);
$scopes = array();
$scopes[] = new QSearchScope('tag', array('tags'));
$scopes[] = new QSearchScope('photo', array('photos'));
$scopes[] = new QSearchScope('file', array('filename'));
$scopes[] = new QSearchScope('author', array(), true);
$scopes[] = new QNumericRangeScope('width', array());
$scopes[] = new QNumericRangeScope('height', array());
$scopes[] = new QNumericRangeScope('ratio', array(), false, 0.001);
$scopes[] = new QNumericRangeScope('size', array());
$scopes[] = new QNumericRangeScope('filesize', array());
$scopes[] = new QNumericRangeScope('hits', array('hit', 'visit', 'visits'));
$scopes[] = new QNumericRangeScope('score', array('rating'), true);
$scopes[] = new QNumericRangeScope('id', array());
$createdDateAliases = array('taken', 'shot');
$postedDateAliases = array('added');
if ($conf['calendar_datefield'] == 'date_creation') {
$createdDateAliases[] = 'date';
} else {
$postedDateAliases[] = 'date';
}
$scopes[] = new QDateRangeScope('created', $createdDateAliases, true);
$scopes[] = new QDateRangeScope('posted', $postedDateAliases);
// allow plugins to add their own scopes
$scopes = trigger_change('qsearch_get_scopes', $scopes);
$expression = new QExpression($q, $scopes);
// get inflections for terms
$inflector = null;
$lang_code = substr(get_default_language(), 0, 2);
@(include_once PHPWG_ROOT_PATH . 'include/inflectors/' . $lang_code . '.php');
$class_name = 'Inflector_' . $lang_code;
if (class_exists($class_name)) {
$inflector = new $class_name();
foreach ($expression->stokens as $token) {
if (isset($token->scope) && !$token->scope->is_text) {
continue;
}
if (strlen($token->term) > 2 && ($token->modifier & (QST_QUOTED | QST_WILDCARD)) == 0 && strcspn($token->term, '\'0123456789') == strlen($token->term)) {
$token->variants = array_unique(array_diff($inflector->get_variants($token->term), array($token->term)));
}
}
}
trigger_notify('qsearch_expression_parsed', $expression);
//var_export($expression);
if (count($expression->stokens) == 0) {
return $search_results;
}
$qsr = new QResults();
qsearch_get_tags($expression, $qsr);
qsearch_get_images($expression, $qsr);
// allow plugins to evaluate their own scopes
trigger_notify('qsearch_before_eval', $expression, $qsr);
$ids = qsearch_eval($expression, $qsr, $tmp, $search_results['qs']['unmatched_terms']);
$debug[] = "<!--\nparsed: " . $expression;
$debug[] = count($expression->stokens) . ' tokens';
for ($i = 0; $i < count($expression->stokens); $i++) {
$debug[] = $expression->stokens[$i] . ': ' . count($qsr->tag_ids[$i]) . ' tags, ' . count($qsr->tag_iids[$i]) . ' tiids, ' . count($qsr->images_iids[$i]) . ' iiids, ' . count($qsr->iids[$i]) . ' iids' . ' modifier:' . dechex($expression->stoken_modifiers[$i]) . (!empty($expression->stokens[$i]->variants) ? ' variants: ' . implode(', ', $expression->stokens[$i]->variants) : '');
}
$debug[] = 'before perms ' . count($ids);
$search_results['qs']['matching_tags'] = $qsr->all_tags;
$search_results = trigger_change('qsearch_results', $search_results, $expression, $qsr);
global $template;
if (empty($ids)) {
$debug[] = '-->';
$template->append('footer_elements', implode("\n", $debug));
return $search_results;
}
$permissions = !isset($options['permissions']) ? true : $options['permissions'];
$where_clauses = array();
$where_clauses[] = 'i.id IN (' . implode(',', $ids) . ')';
if (!empty($options['images_where'])) {
$where_clauses[] = '(' . $options['images_where'] . ')';
}
if ($permissions) {
$where_clauses[] = get_sql_condition_FandF(array('forbidden_categories' => 'category_id', 'forbidden_images' => 'i.id'), null, true);
}
$query = '
SELECT DISTINCT(id) FROM ' . IMAGES_TABLE . ' i';
if ($permissions) {
$query .= '
INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS ic ON id = ic.image_id';
}
$query .= '
WHERE ' . implode("\n AND ", $where_clauses) . "\n" . $conf['order_by'];
$ids = query2array($query, null, 'id');
$debug[] = count($ids) . ' final photo count -->';
$template->append('footer_elements', implode("\n", $debug));
$search_results['items'] = $ids;
return $search_results;
}
示例13: build_next_prev
/**
* Assigns the next/previous link to the template with regards to
* the currently choosen date.
*/
protected function build_next_prev()
{
global $template, $page;
$prev = $next = null;
if (empty($page['chronology_date'])) {
return;
}
$sub_queries = array();
$nb_elements = count($page['chronology_date']);
for ($i = 0; $i < $nb_elements; $i++) {
if ('any' === $page['chronology_date'][$i]) {
$sub_queries[] = '\'any\'';
} else {
$sub_queries[] = pwg_db_cast_to_text($this->calendar_levels[$i]['sql']);
}
}
$query = 'SELECT ' . pwg_db_concat_ws($sub_queries, '-') . ' AS period';
$query .= $this->inner_sql . '
AND ' . $this->date_field . ' IS NOT NULL
GROUP BY period';
$current = implode('-', $page['chronology_date']);
$upper_items = query2array($query, null, 'period');
usort($upper_items, 'version_compare');
$upper_items_rank = array_flip($upper_items);
if (!isset($upper_items_rank[$current])) {
$upper_items[] = $current;
// just in case (external link)
usort($upper_items, 'version_compare');
$upper_items_rank = array_flip($upper_items);
}
$current_rank = $upper_items_rank[$current];
$tpl_var = array();
if ($current_rank > 0) {
// has previous
$prev = $upper_items[$current_rank - 1];
$chronology_date = explode('-', $prev);
$tpl_var['previous'] = array('LABEL' => $this->get_date_nice_name($prev), 'URL' => duplicate_index_url(array('chronology_date' => $chronology_date), array('start')));
}
if ($current_rank < count($upper_items) - 1) {
// has next
$next = $upper_items[$current_rank + 1];
$chronology_date = explode('-', $next);
$tpl_var['next'] = array('LABEL' => $this->get_date_nice_name($next), 'URL' => duplicate_index_url(array('chronology_date' => $chronology_date), array('start')));
}
if (!empty($tpl_var)) {
$existing = $template->smarty->getVariable('chronology_navigation_bars');
if (!$existing instanceof Undefined_Smarty_Variable) {
$existing->value[sizeof($existing->value) - 1] = array_merge($existing->value[sizeof($existing->value) - 1], $tpl_var);
} else {
$template->append('chronology_navigation_bars', $tpl_var);
}
}
}
示例14: check_password_reset_key
/**
* checks the activation key: does it match the expected pattern? is it
* linked to a user? is this user allowed to reset his password?
*
* @return mixed (user_id if OK, false otherwise)
*/
function check_password_reset_key($reset_key)
{
global $page, $conf;
list($key, $email) = explode('-', $reset_key, 2);
if (!preg_match('/^[a-z0-9]{20}$/i', $key)) {
$page['errors'][] = l10n('Invalid key');
return false;
}
$user_ids = array();
$query = '
SELECT
' . $conf['user_fields']['id'] . ' AS id
FROM ' . USERS_TABLE . '
WHERE ' . $conf['user_fields']['email'] . ' = \'' . pwg_db_real_escape_string($email) . '\'
;';
$user_ids = query2array($query, null, 'id');
if (count($user_ids) == 0) {
$page['errors'][] = l10n('Invalid username or email');
return false;
}
$user_id = null;
$query = '
SELECT
user_id,
status,
activation_key,
activation_key_expire,
NOW() AS dbnow
FROM ' . USER_INFOS_TABLE . '
WHERE user_id IN (' . implode(',', $user_ids) . ')
;';
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result)) {
if (pwg_password_verify($key, $row['activation_key'])) {
if (strtotime($row['dbnow']) > strtotime($row['activation_key_expire'])) {
// key has expired
$page['errors'][] = l10n('Invalid key');
return false;
}
if (is_a_guest($row['status']) or is_generic($row['status'])) {
$page['errors'][] = l10n('Password reset is not allowed for this user');
return false;
}
$user_id = $row['user_id'];
}
}
if (empty($user_id)) {
$page['errors'][] = l10n('Invalid key');
return false;
}
return $user_id;
}
示例15: array_merge
' . $forbidden . '
' . $conf['order_by'] . '
LIMIT ' . $conf['top_number'] . '
;';
$page = array_merge($page, array('title' => '<a href="' . duplicate_index_url(array('start' => 0)) . '">' . $conf['top_number'] . ' ' . l10n('Best rated') . '</a>', 'items' => query2array($query, null, 'id')));
} else {
if ($page['section'] == 'list') {
$query = '
SELECT DISTINCT(id)
FROM ' . IMAGES_TABLE . '
INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS ic ON id = ic.image_id
WHERE image_id IN (' . implode(',', $page['list']) . ')
' . $forbidden . '
' . $conf['order_by'] . '
;';
$page = array_merge($page, array('title' => '<a href="' . duplicate_index_url(array('start' => 0)) . '">' . l10n('Random photos') . '</a>', 'items' => query2array($query, null, 'id')));
}
}
}
}
}
}
}
}
}
// +-----------------------------------------------------------------------+
// | chronology |
// +-----------------------------------------------------------------------+
if (isset($page['chronology_field'])) {
unset($page['is_homepage']);
include_once PHPWG_ROOT_PATH . 'include/functions_calendar.inc.php';