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