nggManageGallery

The NextGEN Gallery nggManageGallery class.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/ngglegacy/admin/manage.php  
  1. class nggManageGallery { 
  2.  
  3. var $mode = 'main'; 
  4. var $gid = false; 
  5. var $gallery = NULL; 
  6. var $pid = false; 
  7. var $base_page = 'admin.php?page=nggallery-manage-gallery'; 
  8. var $search_result = false; 
  9.  
  10. // initiate the manage page 
  11. function __construct() 
  12. // GET variables 
  13. if( isset($_GET['gid']) ) { 
  14. $this->gid = (int) $_GET['gid']; 
  15. $this->gallery = C_Gallery_Mapper::get_instance()->find($this->gid); 
  16. if( isset($_GET['pid']) ) 
  17. $this->pid = (int) $_GET['pid']; 
  18. if( isset($_GET['mode']) ) 
  19. $this->mode = trim ($_GET['mode']); 
  20. // Check for pagination request, avoid post process of other submit button, exclude search results 
  21. if ( isset($_POST['post_paged']) && !isset($_GET['s'] ) ) { 
  22. if ( $_GET['paged'] != $_POST['post_paged'] ) { 
  23. $_GET['paged'] = absint( $_POST['post_paged'] ); 
  24. return; 
  25. // Should be only called via manage galleries overview 
  26. if ( isset($_POST['page']) && $_POST['page'] == 'manage-galleries' ) 
  27. $this->post_processor_galleries(); 
  28. // Should be only called via a edit single gallery page 
  29. if ( isset($_POST['page']) && $_POST['page'] == 'manage-images' ) 
  30. $this->post_processor_images(); 
  31. // Should be called via a publish dialog 
  32. if ( isset($_POST['page']) && $_POST['page'] == 'publish-post' ) 
  33. $this->publish_post(); 
  34.  
  35. //Look for other POST process 
  36. if ( !empty($_POST) || !empty($_GET) ) 
  37. $this->processor(); 
  38.  
  39. M_NextGen_Admin::emit_do_notices_action(); 
  40.  
  41. function controller() { 
  42.  
  43. switch($this->mode) { 
  44. case 'sort': 
  45. include_once (dirname (__FILE__) . '/manage-sort.php'); 
  46. nggallery_sortorder($this->gid); 
  47. break; 
  48. case 'edit': 
  49. $this->setup_gallery_fields(); 
  50. $this->setup_image_rows(); 
  51. include_once (dirname (__FILE__) . '/manage-images.php'); 
  52. nggallery_picturelist($this); 
  53. break; 
  54. case 'main': 
  55. default: 
  56. include_once (dirname (__FILE__) . '/manage-galleries.php'); 
  57. nggallery_manage_gallery_main(); 
  58. break; 
  59.  
  60. function processor() { 
  61.  
  62. global $wpdb, $ngg, $nggdb; 
  63.  
  64. // Delete a picture 
  65. if ($this->mode == 'delpic') { 
  66.  
  67. //TODO:Remove also Tag reference 
  68. check_admin_referer('ngg_delpicture'); 
  69. $image = $nggdb->find_image( $this->pid ); 
  70. if ($image) { 
  71. do_action('ngg_delete_picture', $this->pid, $image); 
  72. if ($ngg->options['deleteImg']) { 
  73. $storage = $storage = C_Gallery_Storage::get_instance(); 
  74. $storage->delete_image($this->pid); 
  75. $mapper = C_Image_Mapper::get_instance(); 
  76. $result = $mapper->destroy($this->pid); 
  77.  
  78. if ($result) 
  79. nggGallery::show_message( __('Picture', 'nggallery').' \''.$this->pid.'\' '.__('deleted successfully', 'nggallery') ); 
  80.  
  81. $this->mode = 'edit'; // show pictures 
  82.  
  83.  
  84. // Recover picture from backup 
  85. if ($this->mode == 'recoverpic') { 
  86.  
  87. check_admin_referer('ngg_recoverpicture'); 
  88.  
  89. // bring back the old image 
  90. nggAdmin::recover_image($this->pid); 
  91.  
  92. nggGallery::show_message(__('Operation successful. Please clear your browser cache.', "nggallery")); 
  93.  
  94. $this->mode = 'edit'; // show pictures 
  95.  
  96.  
  97. // will be called after a ajax operation 
  98. if (isset ($_POST['ajax_callback'])) { 
  99. if ($_POST['ajax_callback'] == 1) 
  100. nggGallery::show_message(__('Operation successful. Please clear your browser cache.', "nggallery")); 
  101.  
  102. // show sort order 
  103. if ( isset ($_POST['sortGallery']) ) 
  104. $this->mode = 'sort'; 
  105.  
  106. if ( isset ($_GET['s']) ) 
  107. $this->search_images(); 
  108.  
  109.  
  110. function setup_image_rows() 
  111. add_filter('ngg_manage_images_row', array(&$this, 'render_image_row'), 10, 2); 
  112. add_filter('ngg_manage_images_column_1_header', array(&$this, 'render_image_column_1_header')); 
  113. add_filter('ngg_manage_images_column_1_content', array(&$this, 'render_image_column_1'), 10, 2); 
  114.  
  115. add_filter('ngg_manage_images_column_2_header', array(&$this, 'render_image_column_2_header')); 
  116. add_filter('ngg_manage_images_column_2_content', array(&$this, 'render_image_column_2'), 10, 2); 
  117.  
  118. add_filter('ngg_manage_images_column_3_header', array(&$this, 'render_image_column_3_header')); 
  119. add_filter('ngg_manage_images_column_3_content', array(&$this, 'render_image_column_3'), 10, 2); 
  120.  
  121. add_filter('ngg_manage_images_column_4_header', array(&$this, 'render_image_column_4_header')); 
  122. add_filter('ngg_manage_images_column_4_content', array(&$this, 'render_image_column_4'), 10, 2); 
  123.  
  124. add_filter('ngg_manage_images_column_5_header', array(&$this, 'render_image_column_5_header')); 
  125. add_filter('ngg_manage_images_column_5_content', array(&$this, 'render_image_column_5'), 10, 2); 
  126.  
  127. add_filter('ngg_manage_images_column_6_header', array(&$this, 'render_image_column_6_header')); 
  128. add_filter('ngg_manage_images_column_6_content', array(&$this, 'render_image_column_6'), 10, 2); 
  129.  
  130. function render_image_column_1_header() 
  131. return '<input type="checkbox" id="cb-select-all-1" onclick="checkAll(document.getElementById(\'updategallery\'));">'; 
  132.  
  133. function render_image_column_2_header() 
  134. return __('ID', 'nggallery'); 
  135.  
  136. function render_image_column_3_header() 
  137. return __('Thumbnail', 'nggallery'); 
  138.  
  139. function render_image_column_4_header() 
  140. return __('Filename', 'nggallery'); 
  141.  
  142. function render_image_column_5_header() 
  143. return __('Alt & Title Text / Description', 'nggallery'); 
  144.  
  145. function render_image_column_6_header() 
  146. return __('Tags', 'nggallery'); 
  147.  
  148. function render_image_column_1($output='', $picture=array()) 
  149. return "<input type='checkbox' name='doaction[]' value='{$picture->pid}'/>"; 
  150.  
  151. function render_image_column_2($output='', $picture=array()) 
  152. return $picture->pid; 
  153.  
  154. function render_image_column_3($output='', $picture=array()) 
  155. $image_url = add_query_arg('i', mt_rand(), $picture->imageURL); 
  156. $thumb_url = add_query_arg('i', mt_rand(), $picture->thumbURL); 
  157. $filename = esc_attr($picture->filename); 
  158.  
  159. $output = array(); 
  160.  
  161. $output[] = "<a href='{$image_url}' class='shutter' title='{$filename}'>"; 
  162. $output[] = "<img class='thumb' src='{$thumb_url}' id='thumb{$picture->pid}'/>"; 
  163. $output[] = "</a>"; 
  164.  
  165. return ($output = implode("\n", $output)); 
  166.  
  167. function render_image_column_4($output='', $picture=array()) 
  168. $image_url = nextgen_esc_url($picture->imageURL); 
  169. $filename = esc_attr($picture->filename); 
  170. $caption = esc_html((empty($picture->alttext) ? $picture->filename: $picture->alttext)); 
  171. $date = mysql2date(get_option('date_format'), $picture->imagedate); 
  172. $width = $picture->meta_data['width']; 
  173. $height = $picture->meta_data['height']; 
  174. $pixels = "{$width} x {$height} pixels"; 
  175. $excluded = checked($picture->exclude, 1, false); 
  176. $exclude_label = __("Exclude ?", 'nggallery'); 
  177.  
  178. $output = array(); 
  179.  
  180. $output[] = "<div><strong><a href='{$image_url}' class='thickbox' title='{$caption}'>{$filename}</a></strong></div>"; 
  181. $output[] = '<div class="meta">'. esc_html($date) . '</div>'; 
  182. $output[] = "<div class='meta'>{$pixels}</div>"; 
  183. $output[] = "<label for='exclude_{$picture->pid}'>"; 
  184. $output[] = "<input type='checkbox' id='exclude_{$picture->pid}' value='1' name='images[{$picture->pid}][exclude]' {$excluded}/> {$exclude_label}"; 
  185. $output[] = "</label>"; 
  186.  
  187. return ($output = implode("\n", $output)); 
  188.  
  189. function render_image_column_5($output='', $picture=array()) 
  190. $alttext = esc_attr(stripslashes($picture->alttext)); 
  191. $desc = esc_html(stripslashes($picture->description)); 
  192.  
  193. $output = array(); 
  194.  
  195. $output[] = "<input title='Alt/Title Text' type='text' name='images[{$picture->pid}][alttext]' value='{$alttext}'/>"; 
  196. $output[] = "<textarea title='Description' rows='3' name='images[$picture->pid][description]'>{$desc}</textarea>"; 
  197.  
  198. return ($output = implode("\n", $output)); 
  199.  
  200. function render_image_column_6($output='', $picture=array()) 
  201. global $wp_version; 
  202. $fields = version_compare($wp_version, '4.6', '<=') ? 'fields=names' : array('fields' => 'names'); 
  203. $tags = wp_get_object_terms($picture->pid, 'ngg_tag', $fields); 
  204. if (is_array($tags)) $tags = implode(', ', $tags); 
  205. $tags = esc_html($tags); 
  206.  
  207. return "<textarea rows='4' name='images[{$picture->pid}][tags]'>{$tags}</textarea>"; 
  208.  
  209. function render_image_row($picture, $counter) 
  210. // Get number of columns 
  211. $class = !($counter % 2 == 0) ? '' : 'alternate'; 
  212. $columns = apply_filters('ngg_manage_images_number_of_columns', 6); 
  213.  
  214. // Get the valid row actions 
  215. $actions = array(); 
  216. $row_actions = apply_filters('ngg_manage_images_row_actions', array( 
  217. 'view' => array(&$this, 'render_view_action_link'),  
  218. 'meta' => array(&$this, 'render_meta_action_link'),  
  219. 'custom_thumb' => array(&$this, 'render_custom_thumb_action_link'),  
  220. 'rotate' => array(&$this, 'render_rotate_action_link'),  
  221. 'publish' => array(&$this, 'render_publish_action_link'),  
  222. 'recover' => array(&$this, 'render_recover_action_link'),  
  223. 'delete' => array(&$this, 'render_delete_action_link') 
  224. )); 
  225. foreach ($row_actions as $id => $callback) { 
  226. if (is_callable($callback)) { 
  227. $result = call_user_func($callback, $id, $picture); 
  228. if ($result) $actions[] = $result; 
  229.  
  230. // Output row columns 
  231. echo "<tr class='{$class} iedit' valign='top'>"; 
  232. for ($i=1; $i <= $columns; $i++) { 
  233. $rowspan = $i > 4 ? "rowspan='2'" : ''; 
  234. echo "<td class='column column-{$i}' {$rowspan}>"; 
  235. echo apply_filters("ngg_manage_images_column_{$i}_content", '', $picture); 
  236. echo '</td>'; 
  237. echo '</tr>'; 
  238.  
  239. // Actions row 
  240. echo "<tr class='{$class} row_actions'>"; 
  241. echo '<td colspan="2"></td>'; 
  242. echo "<td colspan='".($columns-2)."'>"; 
  243. echo "<div class='row-actions'>"; 
  244. echo implode(" | ", $actions); 
  245. echo "</div>"; 
  246. echo "</td>"; 
  247. echo '</tr>'; 
  248.  
  249.  
  250. function render_view_action_link($id, $picture) 
  251. $image_url = nextgen_esc_url($picture->imageURL); 
  252. $label = esc_html__('View', 'nggallery'); 
  253. $alt_text = empty($picture->alttext) ? $picture->filename: $picture->alttext; 
  254. $title = esc_attr(__('View', 'nggallery'). " \"{$alt_text}\""); 
  255.  
  256. return "<a href='{$image_url}' class='shutter' title='{$title}'>{$label}</a>"; 
  257.  
  258. function render_meta_action_link($id, $picture) 
  259. $url = nextgen_esc_url(NGGALLERY_URLPATH.'admin/showmeta.php?id='.$picture->pid); 
  260. $title = esc_attr__('Show meta data', 'nggallery'); 
  261. $label = esc_html__('Meta', 'nggallery'); 
  262.  
  263. return "<a href='{$url}' class='ngg-dialog' title='{$title}'>{$label}</a>"; 
  264.  
  265. function render_custom_thumb_action_link($id, $picture) 
  266. $url = nextgen_esc_url(NGGALLERY_URLPATH.'admin/edit-thumbnail.php?id='.$picture->pid); 
  267. $title = esc_attr__('Customize thumbnail', 'nggallery'); 
  268. $label = esc_html__("Edit thumb", 'nggallery'); 
  269.  
  270. return "<a href='{$url}' class='ngg-dialog' title='{$title}'>{$label}</a>"; 
  271.  
  272. function render_rotate_action_link($id, $picture) 
  273. $url = nextgen_esc_url(NGGALLERY_URLPATH.'admin/rotate.php?id='.$picture->pid); 
  274. $title = esc_attr__('Rotate', 'nggallery'); 
  275. $label = esc_html__('Rotate', 'nggallery'); 
  276.  
  277. return "<a href='{$url}' class='ngg-dialog' title='{$title}'>{$label}</a>"; 
  278.  
  279. function render_publish_action_link($id, $picture) 
  280. if (!current_user_can('publish_posts')) return FALSE; 
  281.  
  282. $url = nextgen_esc_url(NGGALLERY_URLPATH.'admin/publish.php?h=230&id='.$picture->pid); 
  283. $title = esc_attr__('Publish this image', 'nggallery'); 
  284. $label = esc_html__('Publish', 'nggallery'); 
  285.  
  286. return "<a href='{$url}' class='ngg-dialog' title='{$title}'>{$label}</a>"; 
  287.  
  288. function render_recover_action_link($id, $picture) 
  289. if ( !file_exists( $picture->imagePath . '_backup' )) return FALSE; 
  290.  
  291. $url = wp_nonce_url("admin.php?page=nggallery-manage-gallery&mode=recoverpic&gid={$picture->galleryid}&pid={$picture->pid}", 'ngg_recoverpicture'); 
  292. $title = esc_attr__('Recover image from backup', 'nggallery'); 
  293. $label = esc_html__('Recover', 'nggallery'); 
  294. $alttext = empty($picture->alttext) ? $picture->filename : $picture->alttext; 
  295. $confirm = addslashes(__("Recover", 'nggallery'). " \"{$alttext}\"?"); 
  296. $onclick = "javascript:if(!confirm(\"{$confirm}\")) return false"; 
  297.  
  298. return "<a href='{$url}' onclick='{$onclick}' class='confirmrecover' title='{$title}'>{$label}</a>"; 
  299.  
  300. function render_delete_action_link($id, $picture) 
  301. $url = wp_nonce_url("admin.php?page=nggallery-manage-gallery&mode=delpic&gid={$picture->galleryid}&pid={$picture->pid}", 'ngg_delpicture'); 
  302. $title = esc_attr__('Delete image', 'nggallery'); 
  303. $label = esc_html__('Delete', 'nggallery'); 
  304. $alttext = empty($picture->alttext) ? $picture->filename : $picture->alttext; 
  305. $confirm = addslashes(__("Delete", 'nggallery'). " \"{$alttext}\"?"); 
  306. $onclick = "javascript:if(!confirm(\"{$confirm}\")) return false;"; 
  307.  
  308. return "<a href='{$url}' onclick='{$onclick}' class='submitdelete delete' title='{$title}'>{$label}</a>"; 
  309.  
  310. function render_image_row_header() 
  311. $columns = apply_filters('ngg_manage_images_number_of_columns', 6); 
  312. echo '<tr>'; 
  313. for($i=1; $i<=$columns; $i++) { 
  314. echo "<th class='column column-{$i}'>"; 
  315. echo apply_filters('ngg_manage_images_column_'.$i.'_header', "Column #{$i}"); 
  316. echo '</th>'; 
  317. echo '</tr>'; 
  318.  
  319. function setup_gallery_fields() 
  320. add_filter('ngg_manage_gallery_fields', array(&$this, 'default_gallery_fields'), 10, 2); 
  321.  
  322. function default_gallery_fields($fields=array(), $gallery=NULL) 
  323. $fields['left'] = array( 
  324. 'title' => array( 
  325. 'callback' => array(&$this, 'render_gallery_title_field'),  
  326. 'label' => __('Title:', 'nggallery'),  
  327. 'tooltip' => NULL,  
  328. 'id' => 'gallery_title' 
  329. ),  
  330. 'description' => array( 
  331. 'callback' => array(&$this, 'render_gallery_desc_field'),  
  332. 'label' => __('Description:', 'nggallery'),  
  333. 'tooltip' => NULL,  
  334. 'id' => 'gallery_desc' 
  335. ),  
  336. 'path' => array( 
  337. 'callback' => array(&$this, 'render_gallery_path_field'),  
  338. 'label' => __('Gallery path:', 'nggallery'),  
  339. 'tooltip' => NULL,  
  340. 'id' => 'gallery_path' 
  341. ),  
  342. 'gallery_author'=> array( 
  343. 'callback' => array(&$this, 'render_gallery_author_field'),  
  344. 'label' => __('Author', 'nggallery'),  
  345. 'tooltip' => NULL,  
  346. 'id' => 'gallery_author' 
  347. ); 
  348.  
  349. $fields['right'] = array( 
  350. 'page_link_to' => array( 
  351. 'callback' => array(&$this, 'render_gallery_link_to_page_field'),  
  352. 'label' => __('Link to page:', 'nggallery'),  
  353. 'tooltip' => __('Albums will link this gallery to the selected page', 'nggallery'),  
  354. 'id' => 'gallery_page_link_to' 
  355. ),  
  356. 'preview_image' => array( 
  357. 'callback' => array(&$this, 'render_gallery_preview_image_field'),  
  358. 'label' => __('Preview image:', 'nggallery'),  
  359. 'tooltip' => NULL,  
  360. 'id' => 'gallery_preview_image',  
  361. ),  
  362. 'create_page' => array( 
  363. 'callback' => array(&$this, 'render_gallery_create_page_field'),  
  364. 'label' => __('Create new page:', 'nggallery'),  
  365. 'tooltip' => NULL,  
  366. 'id' => 'gallery_create_new_page' 
  367. ); 
  368.  
  369. return $fields; 
  370.  
  371. function render_gallery_field_label_column($text, $for, $tooltip = NULL) 
  372. $for = esc_attr($for); 
  373.  
  374. if (!empty($tooltip)) 
  375. $tooltip = "title='{$tooltip}' class='tooltip'"; 
  376.  
  377. echo "<td><label {$tooltip} for='{$for}'>{$text}</label></td>"; 
  378.  
  379. function render_gallery_fields() 
  380. // Get the gallery entity 
  381. $gallery = C_Gallery_Mapper::get_instance()->find($this->gid); 
  382.  
  383. // Get fields 
  384. $fields = apply_filters('ngg_manage_gallery_fields', array(), $gallery); 
  385. $left = isset($fields['left']) ? $fields['left'] : array(); 
  386. $right = isset($fields['right'])? $fields['right']: array(); 
  387.  
  388. // Output table 
  389. echo '<table id="gallery_fields">'; 
  390. $number_of_fields = max(count($left), count($right)); 
  391. $left_keys = array_keys($left); 
  392. $right_keys = array_keys($right); 
  393. for($i=0; $i<$number_of_fields; $i++) { 
  394. // Start row 
  395. echo '<tr>'; 
  396.  
  397. // Left column 
  398. if (isset($left_keys[$i])) { 
  399. extract($left[$left_keys[$i]]); 
  400.  
  401. // Label 
  402. $this->render_gallery_field_label_column($label, $id, $tooltip); 
  403.  
  404. // Input field 
  405. if (is_callable($callback)) { 
  406. echo '<td>'; 
  407. call_user_func($callback, $gallery); 
  408. echo '</td>'; 
  409. elseif (WP_DEBUG) echo "<p>Could not render {$left_keys[$i]} field. No callback exists</p>"; 
  410. else $output[] = '<td colspan="2"></td>'; 
  411.  
  412. // Right column 
  413. if (isset($right_keys[$i])) { 
  414. extract($right[$right_keys[$i]]); 
  415. // Label 
  416. $this->render_gallery_field_label_column($label, $id, $tooltip); 
  417.  
  418. // Input field 
  419. if (is_callable($callback)) { 
  420. echo '<td>'; 
  421. call_user_func($callback, $gallery); 
  422. echo '</td>'; 
  423. elseif (WP_DEBUG) echo "<p>Could not render {$right_keys[$i]} field. No callback exists</p>"; 
  424.  
  425. else $output[] = '<td colspan="2"></td>'; 
  426.  
  427. // End row 
  428. echo '</tr>'; 
  429. echo '</table>'; 
  430.  
  431. function render_gallery_title_field($gallery) 
  432. include('templates/manage_gallery/gallery_title_field.php'); 
  433.  
  434. function render_gallery_desc_field($gallery) 
  435. include('templates/manage_gallery/gallery_desc_field.php'); 
  436.  
  437. function render_gallery_path_field($gallery) 
  438. include('templates/manage_gallery/gallery_path_field.php'); 
  439.  
  440. function render_gallery_author_field($gallery) 
  441. $user = get_userdata($gallery->author); 
  442. $author = isset($user->display_name) ? $user->display_name : $user->user_nicename; 
  443. include('templates/manage_gallery/gallery_author_field.php'); 
  444.  
  445. function render_gallery_link_to_page_field($gallery) 
  446. $pages = get_pages(); 
  447. include('templates/manage_gallery/gallery_link_to_page_field.php'); 
  448.  
  449. function render_gallery_preview_image_field($gallery) 
  450. $images = array(); 
  451. foreach (C_Image_Mapper::get_instance()->find_all(array("galleryid = %s", $gallery->{$gallery->id_field})) as $image) { 
  452. $images[$image->{$image->id_field}] = "[{$image->{$image->id_field}}] {$image->filename}"; 
  453. include('templates/manage_gallery/gallery_preview_image_field.php'); 
  454.  
  455. function render_gallery_create_page_field($gallery) 
  456. $pages = get_pages(); 
  457. include('templates/manage_gallery/gallery_create_page_field.php'); 
  458.  
  459. function post_processor_galleries() { 
  460. global $wpdb, $ngg, $nggdb; 
  461.  
  462. // bulk update in a single gallery 
  463. if (isset ($_POST['bulkaction']) && isset ($_POST['doaction'])) { 
  464.  
  465. check_admin_referer('ngg_bulkgallery'); 
  466.  
  467. switch ($_POST['bulkaction']) { 
  468. case 'no_action'; 
  469. // No action 
  470. break; 
  471. case 'recover_images': 
  472. // Recover images from backup 
  473. // A prefix 'gallery_' will first fetch all ids from the selected galleries 
  474. nggAdmin::do_ajax_operation( 'gallery_recover_image' , $_POST['doaction'], __('Recover from backup', 'nggallery') ); 
  475. break; 
  476. case 'set_watermark': 
  477. // Set watermark 
  478. // A prefix 'gallery_' will first fetch all ids from the selected galleries 
  479. nggAdmin::do_ajax_operation( 'gallery_set_watermark' , $_POST['doaction'], __('Set watermark', 'nggallery') ); 
  480. break; 
  481. case 'import_meta': 
  482. // Import Metadata 
  483. // A prefix 'gallery_' will first fetch all ids from the selected galleries 
  484. nggAdmin::do_ajax_operation( 'gallery_import_metadata' , $_POST['doaction'], __('Import metadata', 'nggallery') ); 
  485. break; 
  486. case 'delete_gallery': 
  487. // Delete gallery 
  488. if (is_array($_POST['doaction'])) 
  489. $deleted = FALSE; 
  490. $mapper = C_Gallery_Mapper::get_instance(); 
  491. foreach ($_POST['doaction'] as $id) { 
  492.  
  493. $gallery = $mapper->find($id); 
  494. if ($gallery->path == '../' || FALSE !== strpos($gallery->path, '/../')) 
  495. nggGallery::show_message(sprintf(__('One or more "../" in Gallery paths could be unsafe and NextGen Gallery will not delete gallery %s automatically', 'nggallery'), $gallery->{$gallery->id_field})); 
  496. else { 
  497. if ($mapper->destroy($id, TRUE)) 
  498. $deleted = TRUE; 
  499.  
  500. if ($deleted) 
  501. nggGallery::show_message(__('Gallery deleted successfully ', 'nggallery')); 
  502. break; 
  503.  
  504. if (isset ($_POST['addgallery']) && isset ($_POST['galleryname'])) { 
  505.  
  506. check_admin_referer('ngg_addgallery'); 
  507.  
  508. if ( !nggGallery::current_user_can( 'NextGEN Add new gallery' )) 
  509. wp_die(__('Cheatin’ uh?', 'nggallery')); 
  510.  
  511. // get the default path for a new gallery 
  512. $defaultpath = $ngg->options['gallerypath']; 
  513. $newgallery = $_POST['galleryname']; 
  514. if ( !empty($newgallery) ) 
  515. nggAdmin::create_gallery($newgallery, $defaultpath); 
  516.  
  517. do_action( 'ngg_update_addgallery_page' ); 
  518.  
  519. if (isset ($_POST['TB_bulkaction']) && isset ($_POST['TB_ResizeImages'])) { 
  520.  
  521. check_admin_referer('ngg_thickbox_form'); 
  522.  
  523. //save the new values for the next operation 
  524. $ngg->options['imgWidth'] = (int) $_POST['imgWidth']; 
  525. $ngg->options['imgHeight'] = (int) $_POST['imgHeight']; 
  526. // What is in the case the user has no if cap 'NextGEN Change options' ? Check feedback 
  527. update_option('ngg_options', $ngg->options); 
  528.  
  529. $gallery_ids = explode(', ', $_POST['TB_imagelist']); 
  530. // A prefix 'gallery_' will first fetch all ids from the selected galleries 
  531. nggAdmin::do_ajax_operation( 'gallery_resize_image' , $gallery_ids, __('Resize images', 'nggallery') ); 
  532.  
  533. if (isset ($_POST['TB_bulkaction']) && isset ($_POST['TB_NewThumbnail'])) { 
  534.  
  535. check_admin_referer('ngg_thickbox_form'); 
  536.  
  537. // save the new values for the next operation 
  538. $settings = C_NextGen_Settings::get_instance(); 
  539. $settings->thumbwidth = (int)$_POST['thumbwidth']; 
  540. $settings->thumbheight = (int)$_POST['thumbheight']; 
  541. $settings->thumbfix = isset($_POST['thumbfix']) ? TRUE : FALSE; 
  542. $settings->save(); 
  543. ngg_refreshSavedSettings(); 
  544.  
  545. // What is in the case the user has no if cap 'NextGEN Change options' ? Check feedback 
  546. $gallery_ids = explode(', ', $_POST['TB_imagelist']); 
  547.  
  548. // A prefix 'gallery_' will first fetch all ids from the selected galleries 
  549. nggAdmin::do_ajax_operation( 'gallery_create_thumbnail' , $gallery_ids, __('Create new thumbnails', 'nggallery') ); 
  550.  
  551.  
  552. function post_processor_images() { 
  553. global $wpdb, $ngg, $nggdb; 
  554.  
  555. // bulk update in a single gallery 
  556. if (isset ($_POST['bulkaction']) && isset ($_POST['doaction'])) { 
  557.  
  558. check_admin_referer('ngg_updategallery'); 
  559.  
  560. switch ($_POST['bulkaction']) { 
  561. case 'no_action'; 
  562. break; 
  563. case 'rotate_cw': 
  564. nggAdmin::do_ajax_operation( 'rotate_cw' , $_POST['doaction'], __('Rotate images', 'nggallery') ); 
  565. break; 
  566. case 'rotate_ccw': 
  567. nggAdmin::do_ajax_operation( 'rotate_ccw' , $_POST['doaction'], __('Rotate images', 'nggallery') ); 
  568. break; 
  569. case 'recover_images': 
  570. nggAdmin::do_ajax_operation( 'recover_image' , $_POST['doaction'], __('Recover from backup', 'nggallery') ); 
  571. break; 
  572. case 'set_watermark': 
  573. nggAdmin::do_ajax_operation( 'set_watermark' , $_POST['doaction'], __('Set watermark', 'nggallery') ); 
  574. break; 
  575. case 'delete_images': 
  576. if ( is_array($_POST['doaction']) ) { 
  577. foreach ( $_POST['doaction'] as $imageID ) { 
  578. $image = $nggdb->find_image( $imageID ); 
  579. if ($image) { 
  580. do_action('ngg_delete_picture', $image->pid, $image); 
  581. if ($ngg->options['deleteImg']) { 
  582. $storage = C_Gallery_Storage::get_instance(); 
  583. $storage->delete_image($image->pid); 
  584. $delete_pic = C_Image_Mapper::get_instance()->destroy($image->pid); 
  585. if($delete_pic) 
  586. nggGallery::show_message(__('Pictures deleted successfully ', 'nggallery')); 
  587. break; 
  588. case 'import_meta': 
  589. nggAdmin::do_ajax_operation( 'import_metadata' , $_POST['doaction'], __('Import metadata', 'nggallery') ); 
  590. break; 
  591.  
  592. if (isset ($_POST['TB_bulkaction']) && isset ($_POST['TB_ResizeImages'])) { 
  593.  
  594. check_admin_referer('ngg_thickbox_form'); 
  595.  
  596. //save the new values for the next operation 
  597. $ngg->options['imgWidth'] = (int) $_POST['imgWidth']; 
  598. $ngg->options['imgHeight'] = (int) $_POST['imgHeight']; 
  599.  
  600. update_option('ngg_options', $ngg->options); 
  601.  
  602. $pic_ids = explode(', ', $_POST['TB_imagelist']); 
  603. nggAdmin::do_ajax_operation( 'resize_image' , $pic_ids, __('Resize images', 'nggallery') ); 
  604.  
  605. if (isset ($_POST['TB_bulkaction']) && isset ($_POST['TB_NewThumbnail'])) { 
  606.  
  607. check_admin_referer('ngg_thickbox_form'); 
  608.  
  609. // save the new values for the next operation 
  610. $settings = C_NextGen_Settings::get_instance(); 
  611. $settings->thumbwidth = (int)$_POST['thumbwidth']; 
  612. $settings->thumbheight = (int)$_POST['thumbheight']; 
  613. $settings->thumbfix = isset($_POST['thumbfix']) ? TRUE : FALSE; 
  614. $settings->save(); 
  615. ngg_refreshSavedSettings(); 
  616.  
  617. $pic_ids = explode(', ', $_POST['TB_imagelist']); 
  618. nggAdmin::do_ajax_operation( 'create_thumbnail' , $pic_ids, __('Create new thumbnails', 'nggallery') ); 
  619.  
  620. if (isset ($_POST['TB_bulkaction']) && isset ($_POST['TB_SelectGallery'])) { 
  621.  
  622. check_admin_referer('ngg_thickbox_form'); 
  623.  
  624. $pic_ids = explode(', ', $_POST['TB_imagelist']); 
  625. $dest_gid = (int) $_POST['dest_gid']; 
  626.  
  627. switch ($_POST['TB_bulkaction']) { 
  628. case 'copy_to': 
  629. C_Gallery_Storage::get_instance()->copy_images($pic_ids, $dest_gid); 
  630. break; 
  631. case 'move_to': 
  632. C_Gallery_Storage::get_instance()->move_images($pic_ids, $dest_gid); 
  633. break; 
  634.  
  635. if (isset ($_POST['TB_bulkaction']) && isset ($_POST['TB_EditTags'])) { 
  636. // do tags update 
  637.  
  638. check_admin_referer('ngg_thickbox_form'); 
  639.  
  640. // get the images list 
  641. $pic_ids = explode(', ', $_POST['TB_imagelist']); 
  642. $taglist = explode(', ', $_POST['taglist']); 
  643. $taglist = array_map('trim', $taglist); 
  644.  
  645. if (is_array($pic_ids)) { 
  646.  
  647. foreach($pic_ids as $pic_id) { 
  648.  
  649. // which action should be performed ? 
  650. switch ($_POST['TB_bulkaction']) { 
  651. case 'no_action'; 
  652. // No action 
  653. break; 
  654. case 'overwrite_tags': 
  655. // Overwrite tags 
  656. wp_set_object_terms($pic_id, $taglist, 'ngg_tag'); 
  657. break; 
  658. case 'add_tags': 
  659. // Add / append tags 
  660. wp_set_object_terms($pic_id, $taglist, 'ngg_tag', TRUE); 
  661. break; 
  662. case 'delete_tags': 
  663. // Delete tags 
  664. $oldtags = wp_get_object_terms($pic_id, 'ngg_tag', 'fields=names'); 
  665. // get the slugs, to vaoid case sensitive problems 
  666. $slugarray = array_map('sanitize_title', $taglist); 
  667. $oldtags = array_map('sanitize_title', $oldtags); 
  668. // compare them and return the diff 
  669. $newtags = array_diff($oldtags, $slugarray); 
  670. wp_set_object_terms($pic_id, $newtags, 'ngg_tag'); 
  671. break; 
  672.  
  673. nggGallery::show_message( __('Tags changed', 'nggallery') ); 
  674.  
  675. if (isset ($_POST['updatepictures']) ) { 
  676. // Update pictures 
  677.  
  678. check_admin_referer('ngg_updategallery'); 
  679.  
  680. if ( nggGallery::current_user_can( 'NextGEN Edit gallery options' ) && !isset ($_GET['s']) ) { 
  681. $tags = array('<a>', '<abbr>', '<acronym>', '<address>', '<b>', '<base>', '<basefont>', '<big>', '<blockquote>', '<br>', '<br/>', '<caption>', '<center>', '<cite>', '<code>', '<col>', '<colgroup>', '<dd>', '<del>', '<dfn>', '<dir>', '<div>', '<dl>', '<dt>', '<em>', '<fieldset>', '<font>', '<h1>', '<h2>', '<h3>', '<h4>', '<h5>', '<h6>', '<hr>', '<i>', '<img>', '<ins>', '<label>', '<legend>', '<li>', '<menu>', '<noframes>', '<noscript>', '<ol>', '<optgroup>', '<option>', '<p>', '<pre>', '<q>', '<s>', '<samp>', '<select>', '<small>', '<span>', '<strike>', '<strong>', '<sub>', '<sup>', '<table>', '<tbody>', '<td>', '<tfoot>', '<th>', '<thead>', '<tr>', '<tt>', '<u>', '<ul>'); 
  682. $fields = array('title', 'galdesc'); 
  683.  
  684. // Sanitize fields 
  685. foreach ($fields as $field) { 
  686. $html = stripslashes($_POST[$field]); 
  687. $html = preg_replace('/\\s+on\\w+=(["\']).*?\\1/i', '', $html); 
  688. $html = preg_replace('/(<\/[^>]+?>)(<[^>\/][^>]*?>)/', '$1 $2', $html); 
  689. $html = strip_tags($html, implode('', $tags)); 
  690. $_POST[$field] = $html; 
  691.  
  692. // Update the gallery 
  693. $mapper = C_Gallery_Mapper::get_instance(); 
  694. if ($entity = $mapper->find($this->gid)) { 
  695. foreach ($_POST as $key => $value) { 
  696. $entity->$key = $value; 
  697. $mapper->save($entity); 
  698.  
  699. if ($entity->path == '../' || FALSE !== strpos($entity->path, '/../')) 
  700. nggGallery::show_message(sprintf(__('One or more "../" in Gallery paths could be unsafe and NextGen Gallery will not delete this gallery automatically', 'nggallery'), $entity->{$entity->id_field})); 
  701.  
  702. wp_cache_delete($this->gid, 'ngg_gallery'); 
  703.  
  704.  
  705. $this->update_pictures(); 
  706.  
  707. //hook for other plugin to update the fields 
  708. do_action('ngg_update_gallery', $this->gid, $_POST); 
  709.  
  710. nggGallery::show_message(__('Update successful', 'nggallery')); 
  711.  
  712. if (isset ($_POST['scanfolder'])) { 
  713. // Rescan folder 
  714. check_admin_referer('ngg_updategallery'); 
  715.  
  716. $gallerypath = $wpdb->get_var("SELECT path FROM $wpdb->nggallery WHERE gid = '$this->gid' "); 
  717. nggAdmin::import_gallery($gallerypath, $this->gid); 
  718.  
  719. // Add a new page 
  720. if (isset ($_POST['addnewpage'])) 
  721. check_admin_referer('ngg_updategallery'); 
  722.  
  723. $parent_id = esc_attr($_POST['parent_id']); 
  724. $gallery_title = esc_attr($_POST['title']); 
  725. $mapper = C_Gallery_Mapper::get_instance(); 
  726. $gallery = $mapper->find($this->gid); 
  727. $gallery_name = $gallery->name; 
  728.  
  729. // Create a WP page 
  730. global $user_ID; 
  731.  
  732. $page['post_type'] = 'page'; 
  733. $page['post_content'] = apply_filters('ngg_add_page_shortcode', '[nggallery id="' . $this->gid . '"]' ); 
  734. $page['post_parent'] = $parent_id; 
  735. $page['post_author'] = $user_ID; 
  736. $page['post_status'] = 'publish'; 
  737. $page['post_title'] = $gallery_title == '' ? $gallery_name : $gallery_title; 
  738. $page = apply_filters('ngg_add_new_page', $page, $this->gid); 
  739.  
  740. $gallery_pageid = wp_insert_post ($page); 
  741. if ($gallery_pageid != 0) 
  742. $gallery->pageid = $gallery_pageid; 
  743. $mapper->save($gallery); 
  744. nggGallery::show_message(__('New gallery page ID', 'nggallery') . ' ' . $gallery_pageid . ' -> <strong>' . $gallery_title . '</strong> ' . __('created', 'nggallery')); 
  745.  
  746. do_action('ngg_gallery_addnewpage', $this->gid); 
  747.  
  748. /** 
  749. * Publish a new post with the shortcode from the selected image 
  750. * @since 1.7.0 
  751. * @return void 
  752. */ 
  753. function publish_post() { 
  754.  
  755. check_admin_referer('publish-post'); 
  756.  
  757. // Create a WP page 
  758. global $user_ID, $ngg; 
  759.  
  760. $ngg->options['publish_width'] = (int) $_POST['width']; 
  761. $ngg->options['publish_height'] = (int) $_POST['height']; 
  762. $ngg->options['publish_align'] = $_POST['align']; 
  763. $align = ( $ngg->options['publish_align'] == 'none') ? '' : 'float='.$ngg->options['publish_align']; 
  764.  
  765. //save the new values for the next operation 
  766. update_option('ngg_options', $ngg->options); 
  767.  
  768. $post['post_type'] = 'post'; 
  769. $post['post_content'] = '[singlepic id=' . intval($_POST['pid']) . ' w=' . $ngg->options['publish_width'] . ' h=' . $ngg->options['publish_height'] . ' ' . $align . ']'; 
  770. $post['post_author'] = $user_ID; 
  771. $post['post_status'] = isset ( $_POST['publish'] ) ? 'publish' : 'draft'; 
  772. $post['post_title'] = $_POST['post_title']; 
  773. $post = apply_filters('ngg_add_new_post', $post, $_POST['pid']); 
  774.  
  775. $post_id = wp_insert_post ($post); 
  776.  
  777. if ($post_id != 0) 
  778. nggGallery::show_message( __('Published a new post', 'nggallery') ); 
  779.  
  780. function can_user_manage_gallery() 
  781. $retval = FALSE; 
  782. $registry = C_Component_Registry::get_instance(); 
  783. $security = $registry->get_utility('I_Security_Manager'); 
  784. $actor = $security->get_current_actor(); 
  785.  
  786. if ($this->gallery && $actor->get_entity_id()== $this->gallery->author) { 
  787. $retval = TRUE; 
  788. elseif($actor->is_allowed('nextgen_edit_gallery_unowned')) { 
  789. $retval = TRUE; 
  790.  
  791. return $retval; 
  792.  
  793. function update_pictures() 
  794. $updated = 0; 
  795.  
  796. if (!$this->can_user_manage_gallery()) return $updated; 
  797.  
  798. if (isset($_POST['images']) && is_array($_POST['images'])) { 
  799. $image_mapper = C_Image_Mapper::get_instance(); 
  800.  
  801. foreach ($_POST['images'] as $pid => $data) { 
  802. if (!isset($data['exclude'])) $data['exclude'] = 0; 
  803. if (($image = $image_mapper->find($pid))) { 
  804. // Strip slashes from title/description/alttext fields 
  805. if (isset($data['description'])) { 
  806. $data['description'] = stripslashes($data['description']); 
  807. if (isset($data['alttext'])) { 
  808. $data['alttext'] = stripslashes($data['alttext']); 
  809. if (isset($data['title'])) { 
  810. $data['title'] = stripslashes($data['title']); 
  811.  
  812. // Generate new slug if the alttext has changed 
  813. if (isset($data['alttext']) && $image->alttext != $data['alttext']) { 
  814. $data['slug'] = NULL; // will cause a new slug to be generated 
  815.  
  816. // Update all fields 
  817. foreach ($data as $key => $value) { 
  818. $image->$key = $value; 
  819. if ($image_mapper->save($image)) { 
  820. $updated += 1; 
  821.  
  822. // Update the tags for the image 
  823. if (isset($data['tags'])) { 
  824. $tags = $data['tags']; 
  825. if (!is_array($tags)) $tags = explode(', ', $tags); 
  826. foreach ($tags as &$tag) $tag = trim($tag); 
  827. wp_set_object_terms($image->{$image->id_field}, $tags, 'ngg_tag'); 
  828.  
  829. // remove from cache 
  830. wp_cache_delete($image->pid, 'ngg_image'); 
  831.  
  832. // hook for other plugins after image is updated 
  833. do_action('ngg_image_updated', $image); 
  834. return $updated; 
  835.  
  836. // Check if user can select a author 
  837. function get_editable_user_ids( $user_id, $exclude_zeros = true ) { 
  838. global $wpdb; 
  839.  
  840. $user = new WP_User( $user_id ); 
  841.  
  842. if ( ! $user->has_cap('NextGEN Manage others gallery') ) { 
  843. if ( $user->has_cap('NextGEN Manage gallery') || $exclude_zeros == false ) 
  844. return array($user->id); 
  845. else 
  846. return false; 
  847.  
  848. $level_key = $wpdb->prefix . 'user_level'; 
  849. $query = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key'"; 
  850. if ( $exclude_zeros ) 
  851. $query .= " AND meta_value != '0'"; 
  852.  
  853. return $wpdb->get_col( $query ); 
  854.  
  855. function search_images() { 
  856. global $nggdb; 
  857.  
  858. if ( empty($_GET['s']) ) 
  859. return; 
  860. //on what ever reason I need to set again the query var 
  861. set_query_var('s', $_GET['s']); 
  862. $request = get_search_query(); 
  863.  
  864. // look now for the images 
  865. $search_for_images = (array) $nggdb->search_for_images( $request ); 
  866. $search_for_tags = (array) nggTags::find_images_for_tags( $request , 'ASC' ); 
  867.  
  868. // finally merge the two results together 
  869. $this->search_result = array_merge( $search_for_images , $search_for_tags ); 
  870.  
  871. // TODO: Currently we didn't support a proper pagination 
  872. $nggdb->paged['total_objects'] = $nggdb->paged['objects_per_page'] = count ($this->search_result) ; 
  873. $nggdb->paged['max_objects_per_page'] = 1; 
  874.  
  875. // show pictures page 
  876. $this->mode = 'edit'; 
  877.  
  878. /** 
  879. * Display the pagination. 
  880. * @since 1.8.0 
  881. * @author taken from WP core (see includes/class-wp-list-table.php) 
  882. * @return string echo the html pagination bar 
  883. */ 
  884. function pagination( $which, $current, $total_items, $per_page ) { 
  885.  
  886. $total_pages = ($per_page > 0) ? ceil( $total_items / $per_page ) : 1; 
  887.  
  888. $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>'; 
  889.  
  890. $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
  891.  
  892. $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url ); 
  893.  
  894. $page_links = array(); 
  895.  
  896. $disable_first = $disable_last = ''; 
  897. if ( $current == 1 ) 
  898. $disable_first = ' disabled'; 
  899. if ( $current == $total_pages ) 
  900. $disable_last = ' disabled'; 
  901.  
  902. $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",  
  903. 'first-page' . $disable_first,  
  904. esc_attr__( 'Go to the first page' ),  
  905. nextgen_esc_url( remove_query_arg( 'paged', $current_url ) ),  
  906. '«' 
  907. ); 
  908.  
  909. $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",  
  910. 'prev-page' . $disable_first,  
  911. esc_attr__( 'Go to the previous page' ),  
  912. nextgen_esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),  
  913. '‹' 
  914. ); 
  915.  
  916. if ( 'bottom' == $which ) 
  917. $html_current_page = $current; 
  918. else 
  919. $html_current_page = sprintf( "<input class='current-page' title='%s' type='text' name='%s' value='%s' size='%d' />",  
  920. esc_attr__( 'Current page' ),  
  921. esc_attr( 'post_paged' ),  
  922. $current,  
  923. strlen( $total_pages ) 
  924. ); 
  925.  
  926. $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) ); 
  927. $page_links[] = '<span class="paging-input">' . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . '</span>'; 
  928.  
  929. $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",  
  930. 'next-page' . $disable_last,  
  931. esc_attr__( 'Go to the next page' ),  
  932. nextgen_esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),  
  933. '›' 
  934. ); 
  935.  
  936. $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",  
  937. 'last-page' . $disable_last,  
  938. esc_attr__( 'Go to the last page' ),  
  939. nextgen_esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),  
  940. '»' 
  941. ); 
  942.  
  943. $output .= "\n<span class='pagination-links'>" . join( "\n", $page_links ) . '</span>'; 
  944.  
  945. if ( $total_pages ) 
  946. $page_class = $total_pages < 2 ? ' one-page' : ''; 
  947. else 
  948. $page_class = ' no-pages'; 
  949.  
  950. $pagination = "<div class='tablenav-pages{$page_class}'>$output</div>"; 
  951.  
  952. echo $pagination; 
  953.