diff options
author | rvelices <rv-github@modusoptimus.com> | 2014-02-16 07:39:19 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2014-02-16 07:39:19 +0000 |
commit | 656ac54090c1cc516955c59ac752bf99ac7abf6f (patch) | |
tree | 551b78c5de2fd46cd5fd8b0fd5b3dd451ac069e9 | |
parent | 09764af8ff3b54aa47ab3dd9da00fab2279f3dc5 (diff) |
more query2array and remove unnecessary tests in often called url functions
git-svn-id: http://piwigo.org/svn/trunk@27388 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r-- | comments.php | 18 | ||||
-rw-r--r-- | include/functions_url.inc.php | 25 | ||||
-rw-r--r-- | include/functions_user.inc.php | 20 |
3 files changed, 22 insertions, 41 deletions
diff --git a/comments.php b/comments.php index a41e0c57a..9230d41ca 100644 --- a/comments.php +++ b/comments.php @@ -69,7 +69,7 @@ if (!in_array($conf['comments_page_nb_comments'], $items_number)) $items_number_new[] = $conf['comments_page_nb_comments']; $is_inserted = true; } - + $items_number_new[] = $number; } @@ -88,7 +88,7 @@ $since_options = array( 4 => array('label' => l10n('the beginning'), 'clause' => '1=1') // stupid but generic ); - + trigger_action('loc_begin_comments'); if (!empty($_GET['since']) && is_numeric($_GET['since'])) @@ -265,7 +265,7 @@ if (isset($action)) ), $_POST['key'] ); - + switch ($comment_action) { case 'moderate': @@ -281,7 +281,7 @@ if (isset($action)) trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING); } } - + $edit_comment = $_GET['edit']; } @@ -437,13 +437,13 @@ SELECT * FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', $element_ids).') ;'; - $elements = hash_from_query($query, 'id'); + $elements = query2array($query, 'id'); // retrieving category informations - $query = 'SELECT id, name, permalink, uppercats + $query = 'SELECT id, name, permalink, uppercats FROM '.CATEGORIES_TABLE.' WHERE id IN ('.implode(',', $category_ids).')'; - $categories = hash_from_query($query, 'id'); + $categories = query2array($query, 'id'); foreach ($comments as $comment) { @@ -467,7 +467,7 @@ SELECT * 'image_file' => $elements[$comment['image_id']]['file'], ) ); - + $email = null; if (!empty($comment['user_email'])) { @@ -488,7 +488,7 @@ SELECT * 'DATE'=>format_date($comment['date'], true), 'CONTENT'=>trigger_event('render_comment_content',$comment['content']), ); - + if (is_admin()) { $tpl_comment['EMAIL'] = $email; diff --git a/include/functions_url.inc.php b/include/functions_url.inc.php index d8c49f372..5a471bc10 100644 --- a/include/functions_url.inc.php +++ b/include/functions_url.inc.php @@ -132,7 +132,7 @@ function make_index_url($params = array()) } $url_before_params = $url; - + $url.= make_section_in_url($params); $url = add_well_known_params_in_url($url, $params); @@ -140,7 +140,7 @@ function make_index_url($params = array()) { $url = get_absolute_root_url( url_is_remote($url) ); } - + return $url; } @@ -216,8 +216,6 @@ function make_picture_url($params) { global $conf; - isset($params['image_id']) or fatal_error('make_picture_url: image_id is a required parameter'); - $url = get_root_url().'picture'; if ($conf['php_extension_in_urls']) { @@ -337,12 +335,6 @@ function make_section_in_url($params) } else { - is_array($params['category']) or trigger_error( - 'make_section_in_url wrong type for category', E_USER_WARNING - ); - is_numeric($params['category']['id']) or trigger_error( - 'make_section_in_url category id not numeric', E_USER_WARNING - ); isset($params['category']['name']) or trigger_error( 'make_section_in_url category name not set', E_USER_WARNING ); @@ -370,11 +362,6 @@ function make_section_in_url($params) } case 'tags' : { - if (!isset($params['tags']) or count($params['tags']) == 0) - { - fatal_error('make_section_in_url: require at least one tag'); - } - $section_string.= '/tags'; foreach ($params['tags'] as $tag) @@ -403,13 +390,11 @@ function make_section_in_url($params) } case 'search' : { - isset($params['search']) or fatal_error('make_section_in_url: require a search identifier'); $section_string.= '/search/'.$params['search']; break; } case 'list' : { - isset($params['list']) or fatal_error('make_section_in_url: require a list of items'); $section_string.= '/list/'.implode(',', $params['list']); break; } @@ -470,7 +455,7 @@ function parse_section_url( $tokens, &$next_token) } else { - $maybe_permalinks[] = + $maybe_permalinks[] = $maybe_permalinks[count($maybe_permalinks)-1] . '/' . $tokens[$current_token]; } @@ -678,7 +663,7 @@ function get_action_url($id, $what_part, $download) { $params['download'] = null; } - + return add_url_params(get_root_url().'action.php', $params); } @@ -812,7 +797,7 @@ function get_query_string_diff($rejects=array(), $escape=true) parse_str($_SERVER['QUERY_STRING'], $vars); $vars = array_diff_key($vars, array_flip($rejects)); - + return '?' . http_build_query($vars, '', $escape ? '&' : '&'); } diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index 5bd06c3be..e364b8214 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -426,7 +426,7 @@ SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id WHERE category_id NOT IN ('.$userdata['forbidden_categories'].') AND level>'.$userdata['level']; - $forbidden_ids = array_from_query($query, 'id'); + $forbidden_ids = query2array($query,null, 'id'); if ( empty($forbidden_ids) ) { @@ -544,14 +544,14 @@ SELECT DISTINCT f.image_id 'AND' ).' ;'; - $authorizeds = array_from_query($query, 'image_id'); + $authorizeds = query2array($query,null, 'image_id'); $query = ' SELECT image_id FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id'].' ;'; - $favorites = array_from_query($query, 'image_id'); + $favorites = query2array($query,null, 'image_id'); $to_deletes = array_diff($favorites, $authorizeds); if (count($to_deletes) > 0) @@ -584,7 +584,7 @@ SELECT id FROM '.CATEGORIES_TABLE.' WHERE status = \'private\' ;'; - $private_array = array_from_query($query, 'id'); + $private_array = query2array($query,null, 'id'); // retrieve category ids directly authorized to the user $query = ' @@ -592,7 +592,7 @@ SELECT cat_id FROM '.USER_ACCESS_TABLE.' WHERE user_id = '.$user_id.' ;'; - $authorized_array = array_from_query($query, 'cat_id'); + $authorized_array = query2array($query,null, 'cat_id'); // retrieve category ids authorized to the groups the user belongs to $query = ' @@ -604,7 +604,7 @@ SELECT cat_id $authorized_array = array_merge( $authorized_array, - array_from_query($query, 'cat_id') + query2array($query,null, 'cat_id') ); // uniquify ids : some private categories might be authorized for the @@ -622,11 +622,7 @@ SELECT id FROM '.CATEGORIES_TABLE.' WHERE visible = \'false\' ;'; - $result = pwg_query($query); - while ($row = pwg_db_fetch_assoc($result)) - { - $forbidden_array[] = $row['id']; - } + $forbidden_array = array_merge($forbidden_array, query2array($query, null, 'id') ); $forbidden_array = array_unique($forbidden_array); } @@ -868,7 +864,7 @@ function create_user_infos($user_ids, $override_values=null) $status = 'webmaster'; $level = max( $conf['available_permission_levels'] ); } - else if (($user_id == $conf['guest_id']) or + elseif (($user_id == $conf['guest_id']) or ($user_id == $conf['default_user_id'])) { $status = 'guest'; |