コード例 #1
0
ファイル: mail.php プロジェクト: sd-studio/sh
 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
0
ファイル: page.php プロジェクト: sd-studio/sh
 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
0
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
0
/**
 * 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
0
ファイル: user.php プロジェクト: sd-studio/or
    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
0
ファイル: followup.php プロジェクト: magsilva/dotproject
} 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 . " &lt;" . $from_email . "&gt;</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
0
/**
 * 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
0
/**
 * 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
0
/**
 * 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
0
ファイル: functions_tag.inc.php プロジェクト: donseba/Piwigo
/**
 * 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
0
ファイル: functions.inc.php プロジェクト: squidjam/Piwigo
/**
 * 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
0
/**
 * @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
0
    /**
     * 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
0
ファイル: password.php プロジェクト: squidjam/Piwigo
/**
 *  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
0
ファイル: section_init.inc.php プロジェクト: squidjam/Piwigo
    ' . $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';
コード例 #16
0
ファイル: album_notification.php プロジェクト: donseba/Piwigo
  WHERE group_id IN (' . implode(',', $group_ids) . ') 
';
        $user_ids_access_indirect = query2array($query, null, 'user_id');
    }
    $query = '
SELECT
    user_id
  FROM ' . USER_ACCESS_TABLE . '
  WHERE cat_id = ' . $category['id'] . '
;';
    $user_ids_access_direct = query2array($query, null, 'user_id');
    $user_ids_access = array_unique(array_merge($user_ids_access_direct, $user_ids_access_indirect));
    $user_ids = array_intersect($user_ids_access, $all_user_ids);
} else {
    $user_ids = $all_user_ids;
}
if (count($user_ids) > 0) {
    $query = '
SELECT
    ' . $conf['user_fields']['id'] . ' AS id,
    ' . $conf['user_fields']['username'] . ' AS username
  FROM ' . USERS_TABLE . '
  WHERE id IN (' . implode(',', $user_ids) . ')
;';
    $users = query2array($query, 'id', 'username');
    $template->assign('user_options', $users);
}
// +-----------------------------------------------------------------------+
// |                           sending html code                           |
// +-----------------------------------------------------------------------+
$template->assign_var_from_handle('ADMIN_CONTENT', 'album_notification');
コード例 #17
0
ファイル: functions.php プロジェクト: lcorbasson/Piwigo
/**
 * Return the list of image ids associated to no album
 *
 * @return int[] $image_ids
 */
function get_orphans()
{
    $query = '
SELECT
    id
  FROM ' . IMAGES_TABLE . '
    LEFT JOIN ' . IMAGE_CATEGORY_TABLE . ' ON id = image_id
  WHERE category_id is null
;';
    return query2array($query, null, 'id');
}
コード例 #18
0
ファイル: history.php プロジェクト: donseba/Piwigo
    } else {
        $form['user'] = null;
    }
    $form['image_id'] = @$page['search']['fields']['image_id'];
    $form['filename'] = @$page['search']['fields']['filename'];
    $form['ip'] = @$page['search']['fields']['ip'];
    $form['display_thumbnail'] = @$page['search']['fields']['display_thumbnail'];
} else {
    // by default, at page load, we want the selected date to be the current
    // date
    $form['start'] = $form['end'] = date('Y-m-d');
    $form['types'] = $types;
    // Hoverbox by default
    $form['display_thumbnail'] = pwg_get_cookie_var('display_thumbnail', 'no_display_thumbnail');
}
$template->assign(array('IMAGE_ID' => @$form['image_id'], 'FILENAME' => @$form['filename'], 'IP' => @$form['ip'], 'START' => @$form['start'], 'END' => @$form['end']));
$template->assign(array('type_option_values' => $types, 'type_option_selected' => $form['types']));
$query = '
SELECT
    ' . $conf['user_fields']['id'] . ' AS id,
    ' . $conf['user_fields']['username'] . ' AS username
  FROM ' . USERS_TABLE . '
  ORDER BY username ASC
;';
$template->assign(array('user_options' => query2array($query, 'id', 'username'), 'user_options_selected' => array(@$form['user'])));
$template->assign('display_thumbnails', $display_thumbnails);
$template->assign('display_thumbnail_selected', $form['display_thumbnail']);
// +-----------------------------------------------------------------------+
// |                           html code display                           |
// +-----------------------------------------------------------------------+
$template->assign_var_from_handle('ADMIN_CONTENT', 'history');
コード例 #19
0
function ws_pfemail_mailbox_delete($params, &$service)
{
    $query = '
SELECT *
  FROM ' . PFEMAIL_MAILBOXES_TABLE . '
  WHERE id = ' . $params['id'] . '
;';
    $mailboxes = query2array($query, 'id');
    if (!isset($mailboxes[$params['id']])) {
        return new PwgError(404, 'id not found');
    }
    $query = '
DELETE
  FROM ' . PFEMAIL_MAILBOXES_TABLE . '
  WHERE id = ' . $params['id'] . '
;';
    pwg_query($query);
    return array('id' => $params['id']);
}
コード例 #20
0
    unset($image_id);
}
if ($conf['display_fromto']) {
    if (count($category_ids) > 0) {
        $query = '
SELECT
    category_id,
    MIN(date_creation) AS `from`,
    MAX(date_creation) AS `to`
  FROM ' . IMAGE_CATEGORY_TABLE . '
    INNER JOIN ' . IMAGES_TABLE . ' ON image_id = id
  WHERE category_id IN (' . implode(',', $category_ids) . ')
' . get_sql_condition_FandF(array('visible_categories' => 'category_id', 'visible_images' => 'id'), 'AND') . '
  GROUP BY category_id
;';
        $dates_of_category = query2array($query, 'category_id');
    }
}
if ($page['section'] == 'recent_cats') {
    usort($categories, 'global_rank_compare');
}
if (count($categories) > 0) {
    $infos_of_image = array();
    $new_image_ids = array();
    $query = '
SELECT *
  FROM ' . IMAGES_TABLE . '
  WHERE id IN (' . implode(',', $image_ids) . ')
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
コード例 #21
0
ファイル: user_list.php プロジェクト: donseba/Piwigo
while ($row = pwg_db_fetch_assoc($result)) {
    $users[] = $row;
    $user_ids[] = $row['id'];
}
$template->assign(array('users' => $users, 'all_users' => join(',', $user_ids), 'ACTIVATE_COMMENTS' => $conf['activate_comments'], 'Double_Password' => $conf['double_password_type_in_admin']));
$default_user = get_default_user_info(true);
$protected_users = array($user['id'], $conf['guest_id'], $conf['default_user_id'], $conf['webmaster_id']);
// an admin can't delete other admin/webmaster
if ('admin' == $user['status']) {
    $query = '
SELECT
    user_id
  FROM ' . USER_INFOS_TABLE . '
  WHERE status IN (\'webmaster\', \'admin\')
;';
    $protected_users = array_merge($protected_users, query2array($query, null, 'user_id'));
}
$template->assign(array('PWG_TOKEN' => get_pwg_token(), 'NB_IMAGE_PAGE' => $default_user['nb_image_page'], 'RECENT_PERIOD' => $default_user['recent_period'], 'theme_options' => get_pwg_themes(), 'theme_selected' => get_default_theme(), 'language_options' => get_languages(), 'language_selected' => get_default_language(), 'association_options' => $groups, 'protected_users' => implode(',', array_unique($protected_users)), 'guest_user' => $conf['guest_id']));
// Status options
foreach (get_enums(USER_INFOS_TABLE, 'status') as $status) {
    $label_of_status[$status] = l10n('user_status_' . $status);
}
$pref_status_options = $label_of_status;
// a simple "admin" can set/remove statuses webmaster/admin
if ('admin' == $user['status']) {
    unset($pref_status_options['webmaster']);
    unset($pref_status_options['admin']);
}
$template->assign('label_of_status', $label_of_status);
$template->assign('pref_status_options', $pref_status_options);
$template->assign('pref_status_selected', 'normal');
コード例 #22
0
ファイル: batch_manager.php プロジェクト: donseba/Piwigo
    $filter_sets[] = query2array($query, null, 'id');
}
if (isset($_SESSION['bulk_manager_filter']['filesize'])) {
    $where_clauses = array();
    if (isset($_SESSION['bulk_manager_filter']['filesize']['min'])) {
        $where_clause[] = 'filesize >= ' . $_SESSION['bulk_manager_filter']['filesize']['min'] * 1024;
    }
    if (isset($_SESSION['bulk_manager_filter']['filesize']['max'])) {
        $where_clause[] = 'filesize <= ' . $_SESSION['bulk_manager_filter']['filesize']['max'] * 1024;
    }
    $query = '
SELECT id
  FROM ' . IMAGES_TABLE . '
  WHERE ' . implode(' AND ', $where_clause) . '
  ' . $conf['order_by'];
    $filter_sets[] = query2array($query, null, 'id');
}
if (isset($_SESSION['bulk_manager_filter']['search']) && strlen($_SESSION['bulk_manager_filter']['search']['q'])) {
    include_once PHPWG_ROOT_PATH . 'include/functions_search.inc.php';
    $res = get_quick_search_results_no_cache($_SESSION['bulk_manager_filter']['search']['q'], array('permissions' => false));
    if (!empty($res['items']) && !empty($res['qs']['unmatched_terms'])) {
        $template->assign('no_search_results', array_map('htmlspecialchars', $res['qs']['unmatched_terms']));
    }
    $filter_sets[] = $res['items'];
}
$filter_sets = trigger_change('batch_manager_perform_filters', $filter_sets, $_SESSION['bulk_manager_filter']);
$current_set = array_shift($filter_sets);
foreach ($filter_sets as $set) {
    $current_set = array_intersect($current_set, $set);
}
$page['cat_elements_id'] = $current_set;
コード例 #23
0
  ORDER BY pm.id DESC
;';
$mailboxes = query2array($query);
foreach ($mailboxes as $idx => $mailbox) {
    $mailboxes[$idx]['album'] = get_cat_display_name_cache($mailbox['uppercats'], null, false);
    $mailboxes[$idx]['data'] = json_encode($mailbox);
}
$template->assign(array('mailboxes' => $mailboxes, 'PWG_TOKEN' => get_pwg_token()));
// list of albums
$query = '
SELECT id,name,uppercats,global_rank
  FROM ' . CATEGORIES_TABLE . '
;';
display_select_cat_wrapper($query, isset($category_options_selected) ? $category_options_selected : array(), 'category_options');
// groups
$query = '
SELECT id
  FROM ' . GROUPS_TABLE . '
;';
$group_ids = query2array($query, null, 'id');
$query = '
SELECT id
  FROM ' . GROUPS_TABLE . '
  WHERE pfemail_notify = \'true\'
;';
$groups_selected = query2array($query, null, 'id');
$template->assign(array('CACHE_KEYS' => get_admin_client_cache_keys(array('groups')), 'groups' => $group_ids, 'groups_selected' => $groups_selected));
// +-----------------------------------------------------------------------+
// | sending html code                                                     |
// +-----------------------------------------------------------------------+
$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
コード例 #24
0
        case 'ticket_company':
            $q = new DBQuery();
            $q->addTable('companies');
            $q->addQuery('companies.*');
            $q->addWhere('companies.company_id = ' . $value);
            $sql = $q->prepare();
            if (!db_loadObject($sql, $obj)) {
                // it all dies!
            }
            $output = '<a href="index.php?m=companies&a=view&company_id=' . $value . '">' . $obj->company_name . '</a>';
            break;
        case 'ticket_project':
            $q = new DBQuery();
            $q->addTable('projects');
            $q->addQuery('projects.*');
            $q->addWhere('projects.project_id = ' . $value);
            $sql = $q->prepare();
            if (!db_loadObject($sql, $obj)) {
                // it all dies!
            }
            $output = '<a href="index.php?m=projects&a=view&project_id=' . $value . '">' . $obj->project_name . '</a>';
            break;
        default:
            $output = $value ? htmlspecialchars($value) : "<em>" . $AppUI->_('none') . "</em>";
    }
    return $output;
}
/* figure out parent & type */
if (isset($ticket)) {
    list($ticket_type, $ticket_parent) = query2array("SELECT type, parent FROM tickets WHERE ticket = '{$ticket}'");
}
コード例 #25
0
ファイル: mail.php プロジェクト: sd-studio/or
 function __construct($id)
 {
     $tpl = query2array('SELECT subject,body FROM cf_mail_templates WHERE id=:id', array('id' => $id));
     $this->subject = $tpl['subject'];
     $this->body = $tpl['body'];
 }
コード例 #26
0
/**
 * Returns an array of plugins defined in the database.
 *
 * @param string $state optional filter
 * @param string $id returns only data about given plugin
 * @return array
 */
function get_db_plugins($state = '', $id = '')
{
    $query = '
SELECT * FROM ' . PLUGINS_TABLE;
    $clauses = array();
    if (!empty($state)) {
        $clauses[] = 'state=\'' . $state . '\'';
    }
    if (!empty($id)) {
        $clauses[] = 'id="' . $id . '"';
    }
    if (count($clauses)) {
        $query .= '
  WHERE ' . implode(' AND ', $clauses);
    }
    return query2array($query);
}
コード例 #27
0
/**
 * Calculates the list of forbidden categories for a given user.
 *
 * Calculation is based on private categories minus categories authorized to
 * the groups the user belongs to minus the categories directly authorized
 * to the user. The list contains at least 0 to be compliant with queries
 * such as "WHERE category_id NOT IN ($forbidden_categories)"
 *
 * @param int $user_id
 * @param string $user_status
 * @return string comma separated ids
 */
function calculate_permissions($user_id, $user_status)
{
    $query = '
SELECT id
  FROM ' . CATEGORIES_TABLE . '
  WHERE status = \'private\'
;';
    $private_array = query2array($query, null, 'id');
    // retrieve category ids directly authorized to the user
    $query = '
SELECT cat_id
  FROM ' . USER_ACCESS_TABLE . '
  WHERE user_id = ' . $user_id . '
;';
    $authorized_array = query2array($query, null, 'cat_id');
    // retrieve category ids authorized to the groups the user belongs to
    $query = '
SELECT cat_id
  FROM ' . USER_GROUP_TABLE . ' AS ug INNER JOIN ' . GROUP_ACCESS_TABLE . ' AS ga
    ON ug.group_id = ga.group_id
  WHERE ug.user_id = ' . $user_id . '
;';
    $authorized_array = array_merge($authorized_array, query2array($query, null, 'cat_id'));
    // uniquify ids : some private categories might be authorized for the
    // groups and for the user
    $authorized_array = array_unique($authorized_array);
    // only unauthorized private categories are forbidden
    $forbidden_array = array_diff($private_array, $authorized_array);
    // if user is not an admin, locked categories are forbidden
    if (!is_admin($user_status)) {
        $query = '
SELECT id
  FROM ' . CATEGORIES_TABLE . '
  WHERE visible = \'false\'
;';
        $forbidden_array = array_merge($forbidden_array, query2array($query, null, 'id'));
        $forbidden_array = array_unique($forbidden_array);
    }
    if (empty($forbidden_array)) {
        // at least, the list contains 0 value. This category does not exists so
        // where clauses such as "WHERE category_id NOT IN(0)" will always be
        // true.
        $forbidden_array[] = 0;
    }
    return implode(',', $forbidden_array);
}
コード例 #28
0
ファイル: functions.php プロジェクト: ejegg/piwigo-stereo
function Stereo_perform_batch_manager_prefilters($filter_sets, $prefilter)
{
    if ($prefilter === 'stereo0') {
        $query = "SELECT id FROM " . IMAGES_TABLE . " WHERE UPPER( RIGHT( file, 3 ) ) = 'MPO'";
        $filter_sets[] = query2array($query, null, 'id');
    }
    return $filter_sets;
}
コード例 #29
0
ファイル: cat_list.php プロジェクト: lcorbasson/Piwigo
function get_categories_ref_date($ids, $field = 'date_available', $minmax = 'max')
{
    // we need to work on the whole tree under each category, even if we don't
    // want to sort sub categories
    $category_ids = get_subcat_ids($ids);
    // search for the reference date of each album
    $query = '
SELECT
    category_id,
    ' . $minmax . '(' . $field . ') as ref_date
  FROM ' . IMAGE_CATEGORY_TABLE . '
    JOIN ' . IMAGES_TABLE . ' ON image_id = id
  WHERE category_id IN (' . implode(',', $category_ids) . ')
  GROUP BY category_id
;';
    $ref_dates = query2array($query, 'category_id', 'ref_date');
    // the iterate on all albums (having a ref_date or not) to find the
    // reference_date, with a search on sub-albums
    $query = '
SELECT
    id,
    uppercats
  FROM ' . CATEGORIES_TABLE . '
  WHERE id IN (' . implode(',', $category_ids) . ')
;';
    $uppercats_of = query2array($query, 'id', 'uppercats');
    foreach (array_keys($uppercats_of) as $cat_id) {
        // find the subcats
        $subcat_ids = array();
        foreach ($uppercats_of as $id => $uppercats) {
            if (preg_match('/(^|,)' . $cat_id . '(,|$)/', $uppercats)) {
                $subcat_ids[] = $id;
            }
        }
        $to_compare = array();
        foreach ($subcat_ids as $id) {
            if (isset($ref_dates[$id])) {
                $to_compare[] = $ref_dates[$id];
            }
        }
        if (count($to_compare) > 0) {
            $ref_dates[$cat_id] = 'max' == $minmax ? max($to_compare) : min($to_compare);
        } else {
            $ref_dates[$cat_id] = null;
        }
    }
    // only return the list of $ids, not the sub-categories
    $return = array();
    foreach ($ids as $id) {
        $return[$id] = $ref_dates[$id];
    }
    return $return;
}
コード例 #30
0
ファイル: picture_modify.php プロジェクト: donseba/Piwigo
//    linked category
// 4. if no category reachable, no jumpto link
$query = '
SELECT category_id
  FROM ' . IMAGE_CATEGORY_TABLE . '
  WHERE image_id = ' . $_GET['image_id'] . '
;';
$authorizeds = array_diff(array_from_query($query, 'category_id'), explode(',', calculate_permissions($user['id'], $user['status'])));
if (isset($_GET['cat_id']) and in_array($_GET['cat_id'], $authorizeds)) {
    $url_img = make_picture_url(array('image_id' => $_GET['image_id'], 'image_file' => $image_file, 'category' => $cache['cat_names'][$_GET['cat_id']]));
} else {
    foreach ($authorizeds as $category) {
        $url_img = make_picture_url(array('image_id' => $_GET['image_id'], 'image_file' => $image_file, 'category' => $cache['cat_names'][$category]));
        break;
    }
}
if (isset($url_img)) {
    $template->assign('U_JUMPTO', $url_img);
}
// associate to albums
$query = '
SELECT id
  FROM ' . CATEGORIES_TABLE . '
    INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' ON id = category_id
  WHERE image_id = ' . $_GET['image_id'] . '
;';
$associated_albums = query2array($query, null, 'id');
$template->assign(array('associated_albums' => $associated_albums, 'represented_albums' => $represented_albums, 'STORAGE_ALBUM' => $storage_category_id, 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags', 'categories'))));
trigger_notify('loc_end_picture_modify');
//----------------------------------------------------------- sending html code
$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');