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