[25617] | 1 | <?php |
---|
| 2 | defined('ADMINTOOLS_PATH') or die('Hacking attempt!'); |
---|
| 3 | |
---|
[25655] | 4 | /** |
---|
| 5 | * Add main toolbar to current page |
---|
| 6 | * @trigger loc_after_page_header |
---|
| 7 | */ |
---|
[25617] | 8 | function admintools_add_public_controller() |
---|
| 9 | { |
---|
[25845] | 10 | global $MultiView, $conf, $template, $page, $user, $picture; |
---|
[25617] | 11 | |
---|
[25915] | 12 | if (script_basename() == 'picture' and empty($picture['current'])) |
---|
| 13 | { |
---|
| 14 | return; |
---|
| 15 | } |
---|
| 16 | |
---|
[25845] | 17 | $url_root = get_root_url(); |
---|
| 18 | $tpl_vars = array(); |
---|
| 19 | |
---|
| 20 | if ($MultiView->is_admin()) |
---|
| 21 | { // full options for admin |
---|
| 22 | $tpl_vars['U_SITE_ADMIN'] = $url_root . 'admin.php?page='; |
---|
| 23 | $tpl_vars['MULTIVIEW'] = $MultiView->get_data(); |
---|
| 24 | $tpl_vars['USER'] = $MultiView->get_user(); |
---|
| 25 | $tpl_vars['CURRENT_USERNAME'] = $user['id']==$conf['guest_id'] ? l10n('guest') : $user['username']; |
---|
| 26 | $tpl_vars['DELETE_CACHE'] = isset($conf['multiview_invalidate_cache']); |
---|
| 27 | |
---|
[25979] | 28 | if (($admin_lang = $MultiView->get_user_language()) !== false) |
---|
| 29 | { |
---|
| 30 | include_once(PHPWG_ROOT_PATH . 'include/functions_mail.inc.php'); |
---|
| 31 | switch_lang_to($admin_lang); |
---|
| 32 | } |
---|
[25845] | 33 | } |
---|
[26061] | 34 | else if ($conf['AdminTools']['public_quick_edit'] and |
---|
| 35 | script_basename() == 'picture' and $picture['current']['added_by'] == $user['id'] |
---|
| 36 | ) |
---|
[25845] | 37 | { // only "edit" button for photo owner |
---|
| 38 | } |
---|
| 39 | else |
---|
[25617] | 40 | { |
---|
| 41 | return; |
---|
| 42 | } |
---|
| 43 | |
---|
[26061] | 44 | $tpl_vars['POSITION'] = $conf['AdminTools']['closed_position']; |
---|
| 45 | $tpl_vars['DEFAULT_OPEN'] = $conf['AdminTools']['default_open']; |
---|
[25845] | 46 | $tpl_vars['U_SELF'] = $MultiView->get_clean_url(true); |
---|
[25617] | 47 | |
---|
[25845] | 48 | // photo page |
---|
[25617] | 49 | if (script_basename() == 'picture') |
---|
| 50 | { |
---|
| 51 | $url_self = duplicate_picture_url(); |
---|
| 52 | $tpl_vars['IS_PICTURE'] = true; |
---|
| 53 | |
---|
[25845] | 54 | // admin can add to caddie and set representattive |
---|
| 55 | if ($MultiView->is_admin()) |
---|
| 56 | { |
---|
| 57 | $template->clear_assign(array( |
---|
| 58 | 'U_SET_AS_REPRESENTATIVE', |
---|
| 59 | 'U_PHOTO_ADMIN', |
---|
| 60 | 'U_CADDIE', |
---|
| 61 | )); |
---|
[25617] | 62 | |
---|
[25845] | 63 | $template->set_prefilter('picture', 'admintools_remove_privacy'); |
---|
[25654] | 64 | |
---|
[25845] | 65 | $tpl_vars['U_CADDIE'] = add_url_params( |
---|
| 66 | $url_self, |
---|
| 67 | array('action'=>'add_to_caddie') |
---|
| 68 | ); |
---|
| 69 | |
---|
| 70 | $query = ' |
---|
[25675] | 71 | SELECT element_id FROM ' . CADDIE_TABLE . ' |
---|
| 72 | WHERE element_id = ' . $page['image_id'] .' |
---|
| 73 | ;'; |
---|
[25845] | 74 | $tpl_vars['IS_IN_CADDIE'] = pwg_db_num_rows(pwg_query($query)) > 0; |
---|
[25629] | 75 | |
---|
[25845] | 76 | if (isset($page['category'])) |
---|
| 77 | { |
---|
| 78 | $tpl_vars['CATEGORY_ID'] = $page['category']['id']; |
---|
[25629] | 79 | |
---|
[25845] | 80 | $tpl_vars['U_SET_REPRESENTATIVE'] = add_url_params( |
---|
| 81 | $url_self, |
---|
| 82 | array('action'=>'set_as_representative') |
---|
| 83 | ); |
---|
[25629] | 84 | |
---|
[25979] | 85 | $tpl_vars['IS_REPRESENTATIVE'] = $page['category']['representative_picture_id'] == $page['image_id']; |
---|
[25845] | 86 | } |
---|
| 87 | |
---|
| 88 | $tpl_vars['U_ADMIN_EDIT'] = $url_root . 'admin.php?page=photo-' . $page['image_id'] |
---|
| 89 | .(isset($page['category']) ? '&cat_id=' . $page['category']['id'] : ''); |
---|
[25617] | 90 | } |
---|
| 91 | |
---|
[25845] | 92 | $tpl_vars['U_DELETE'] = add_url_params( |
---|
| 93 | $url_self, array( |
---|
| 94 | 'delete'=>'', |
---|
| 95 | 'pwg_token'=>get_pwg_token() |
---|
| 96 | ) |
---|
[25617] | 97 | ); |
---|
[25654] | 98 | |
---|
[25817] | 99 | // gets tags (full available list is loaded in ajax) |
---|
[25845] | 100 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php'); |
---|
| 101 | |
---|
[25654] | 102 | $query = ' |
---|
| 103 | SELECT id, name |
---|
| 104 | FROM '.IMAGE_TAG_TABLE.' AS it |
---|
| 105 | JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id |
---|
| 106 | WHERE image_id = '.$page['image_id'].' |
---|
| 107 | ;'; |
---|
| 108 | $tag_selection = get_taglist($query); |
---|
| 109 | |
---|
| 110 | $tpl_vars['QUICK_EDIT'] = array( |
---|
[25791] | 111 | 'img' => $picture['current']['derivatives']['square']->get_url(), |
---|
[25675] | 112 | 'name' => $picture['current']['name'], |
---|
| 113 | 'comment' => $picture['current']['comment'], |
---|
| 114 | 'author' => $picture['current']['author'], |
---|
| 115 | 'level' => $picture['current']['level'], |
---|
| 116 | 'date_creation' => substr($picture['current']['date_creation'], 0, 10), |
---|
[25654] | 117 | 'date_creation_time' => substr($picture['current']['date_creation'], 11, 5), |
---|
[25675] | 118 | 'tag_selection' => $tag_selection, |
---|
[25654] | 119 | ); |
---|
[25617] | 120 | } |
---|
[25845] | 121 | // album page (admin only) |
---|
| 122 | else if ($MultiView->is_admin() and @$page['section'] == 'categories' and isset($page['category'])) |
---|
[25617] | 123 | { |
---|
| 124 | $url_self = duplicate_index_url(); |
---|
| 125 | |
---|
| 126 | $tpl_vars['IS_CATEGORY'] = true; |
---|
| 127 | $tpl_vars['CATEGORY_ID'] = $page['category']['id']; |
---|
| 128 | |
---|
| 129 | $template->clear_assign(array( |
---|
| 130 | 'U_EDIT', |
---|
| 131 | 'U_CADDIE', |
---|
| 132 | )); |
---|
| 133 | |
---|
[25845] | 134 | $tpl_vars['U_ADMIN_EDIT'] = $url_root . 'admin.php?page=album-' . $page['category']['id']; |
---|
[25617] | 135 | |
---|
| 136 | if (!empty($page['items'])) |
---|
| 137 | { |
---|
| 138 | $tpl_vars['U_CADDIE'] = add_url_params( |
---|
| 139 | $url_self, |
---|
| 140 | array('caddie'=>1) |
---|
| 141 | ); |
---|
| 142 | } |
---|
[25655] | 143 | |
---|
[25791] | 144 | $tpl_vars['QUICK_EDIT'] = array( |
---|
| 145 | 'img' => null, |
---|
| 146 | 'name' => $page['category']['name'], |
---|
| 147 | 'comment' => $page['category']['comment'], |
---|
| 148 | ); |
---|
| 149 | |
---|
| 150 | if (!empty($page['category']['representative_picture_id'])) |
---|
| 151 | { |
---|
| 152 | $query = ' |
---|
[25675] | 153 | SELECT * FROM '.IMAGES_TABLE.' |
---|
| 154 | WHERE id = '. $page['category']['representative_picture_id'] .' |
---|
| 155 | ;'; |
---|
[25791] | 156 | $image_infos = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[25655] | 157 | |
---|
[25791] | 158 | $tpl_vars['QUICK_EDIT']['img'] = DerivativeImage::get_one(IMG_SQUARE, $image_infos)->get_url(); |
---|
| 159 | } |
---|
[25617] | 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | $template->assign(array( |
---|
[25916] | 164 | 'ADMINTOOLS_PATH' => './plugins/' . ADMINTOOLS_ID .'/', |
---|
[25617] | 165 | 'ato' => $tpl_vars, |
---|
| 166 | )); |
---|
| 167 | |
---|
[25675] | 168 | $template->set_filename('ato_public_controller', realpath(ADMINTOOLS_PATH . 'template/public_controller.tpl')); |
---|
| 169 | $template->parse('ato_public_controller'); |
---|
[25655] | 170 | |
---|
[25979] | 171 | if ($MultiView->is_admin() && @$admin_lang !== false) |
---|
[25845] | 172 | { |
---|
| 173 | switch_lang_back(); |
---|
| 174 | } |
---|
[25654] | 175 | } |
---|
| 176 | |
---|
[25655] | 177 | /** |
---|
| 178 | * Disable privacy level switchbox |
---|
| 179 | */ |
---|
[25654] | 180 | function admintools_remove_privacy($content) |
---|
| 181 | { |
---|
| 182 | $search = '{if $display_info.privacy_level and isset($available_permission_levels)}'; |
---|
| 183 | $replace = '{if false}'; |
---|
| 184 | return str_replace($search, $replace, $content); |
---|
| 185 | } |
---|
| 186 | |
---|
[25655] | 187 | /** |
---|
| 188 | * Save picture form |
---|
| 189 | * @trigger loc_begin_picture |
---|
| 190 | */ |
---|
[25654] | 191 | function admintools_save_picture() |
---|
| 192 | { |
---|
[25845] | 193 | global $page, $conf, $MultiView, $user, $picture; |
---|
[25654] | 194 | |
---|
[25916] | 195 | if (!isset($_GET['delete']) and !isset($_POST['action']) and @$_POST['action'] != 'quick_edit') |
---|
[25915] | 196 | { |
---|
| 197 | return; |
---|
| 198 | } |
---|
| 199 | |
---|
[25845] | 200 | $query = 'SELECT added_by FROM '. IMAGES_TABLE .' WHERE id = '. $page['image_id'] .';'; |
---|
| 201 | list($added_by) = pwg_db_fetch_row(pwg_query($query)); |
---|
| 202 | |
---|
[25915] | 203 | if (!$MultiView->is_admin() and $user['id'] != $added_by) |
---|
[25791] | 204 | { |
---|
| 205 | return; |
---|
| 206 | } |
---|
| 207 | |
---|
[25654] | 208 | if (isset($_GET['delete']) and get_pwg_token()==@$_GET['pwg_token']) |
---|
| 209 | { |
---|
| 210 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php'); |
---|
| 211 | |
---|
| 212 | delete_elements(array($page['image_id']), true); |
---|
| 213 | invalidate_user_cache(); |
---|
| 214 | |
---|
[27487] | 215 | if (isset($page['rank_of'][ $page['image_id'] ])) |
---|
[25654] | 216 | { |
---|
| 217 | redirect( |
---|
[27487] | 218 | duplicate_index_url( |
---|
[25654] | 219 | array( |
---|
[27487] | 220 | 'start' => |
---|
| 221 | floor($page['rank_of'][ $page['image_id'] ] / $page['nb_image_page']) |
---|
| 222 | * $page['nb_image_page'] |
---|
[25654] | 223 | ) |
---|
| 224 | ) |
---|
| 225 | ); |
---|
| 226 | } |
---|
[27487] | 227 | else |
---|
| 228 | { |
---|
| 229 | redirect(make_index_url()); |
---|
| 230 | } |
---|
[25654] | 231 | } |
---|
| 232 | |
---|
[25915] | 233 | if ($_POST['action'] == 'quick_edit') |
---|
[25654] | 234 | { |
---|
| 235 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php'); |
---|
| 236 | |
---|
| 237 | $data = array( |
---|
[25675] | 238 | 'name' => $_POST['name'], |
---|
[25654] | 239 | 'author' => $_POST['author'], |
---|
| 240 | ); |
---|
| 241 | |
---|
[25845] | 242 | if ($MultiView->is_admin()) |
---|
| 243 | { |
---|
| 244 | $data['level'] = $_POST['level']; |
---|
| 245 | } |
---|
| 246 | |
---|
[25654] | 247 | if ($conf['allow_html_descriptions']) |
---|
| 248 | { |
---|
| 249 | $data['comment'] = @$_POST['comment']; |
---|
| 250 | } |
---|
| 251 | else |
---|
| 252 | { |
---|
| 253 | $data['comment'] = strip_tags(@$_POST['comment']); |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | if (!empty($_POST['date_creation']) and strtotime($_POST['date_creation']) !== false) |
---|
| 257 | { |
---|
| 258 | $data['date_creation'] = $_POST['date_creation'] .' '. $_POST['date_creation_time']; |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | single_update( |
---|
| 262 | IMAGES_TABLE, |
---|
| 263 | $data, |
---|
| 264 | array('id' => $page['image_id']) |
---|
| 265 | ); |
---|
| 266 | |
---|
| 267 | $tag_ids = array(); |
---|
| 268 | if (!empty($_POST['tags'])) |
---|
| 269 | { |
---|
| 270 | $tag_ids = get_tag_ids($_POST['tags']); |
---|
| 271 | } |
---|
| 272 | set_tags($tag_ids, $page['image_id']); |
---|
| 273 | } |
---|
[25655] | 274 | } |
---|
| 275 | |
---|
| 276 | /** |
---|
| 277 | * Save category form |
---|
| 278 | * @trigger loc_begin_index |
---|
| 279 | */ |
---|
| 280 | function admintools_save_category() |
---|
| 281 | { |
---|
[25791] | 282 | global $page, $conf, $MultiView; |
---|
| 283 | |
---|
| 284 | if (!$MultiView->is_admin()) |
---|
| 285 | { |
---|
| 286 | return; |
---|
| 287 | } |
---|
[25845] | 288 | |
---|
[25655] | 289 | if (@$_POST['action'] == 'quick_edit') |
---|
| 290 | { |
---|
| 291 | $data = array( |
---|
| 292 | 'name' => $_POST['name'], |
---|
| 293 | ); |
---|
| 294 | |
---|
| 295 | if ($conf['allow_html_descriptions']) |
---|
| 296 | { |
---|
| 297 | $data['comment'] = @$_POST['comment']; |
---|
| 298 | } |
---|
| 299 | else |
---|
| 300 | { |
---|
| 301 | $data['comment'] = strip_tags(@$_POST['comment']); |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | single_update( |
---|
| 305 | CATEGORIES_TABLE, |
---|
| 306 | $data, |
---|
| 307 | array('id' => $page['category']['id']) |
---|
| 308 | ); |
---|
[25845] | 309 | |
---|
[25655] | 310 | redirect(duplicate_index_url()); |
---|
| 311 | } |
---|
[25617] | 312 | } |
---|