/products/photocrati_nextgen/modules/wpcli/module.wpcli.php

  1. <?php 
  2.  
  3. class M_WPCLI extends C_Base_Module 
  4. function define($id = 'pope-module',  
  5. $name = 'Pope Module',  
  6. $description = '',  
  7. $version = '',  
  8. $uri = '',  
  9. $author = '',  
  10. $author_uri = '',  
  11. $context = FALSE) 
  12. parent::define( 
  13. 'photocrati-wpcli',  
  14. 'WP-CLI Integration',  
  15. "Provides additional commands for WP-CLI (https://github.com/wp-cli/wp-cli",  
  16. '0.2',  
  17. 'https://www.imagely.com/wordpress-gallery-plugin/nextgen-gallery/',  
  18. 'Imagely',  
  19. 'https://www.imagely.com' 
  20. ); 
  21.  
  22. function initialize() 
  23. parent::initialize(); 
  24.  
  25. function get_type_list() 
  26. return array(); 
  27.  
  28. new M_WPCLI(); 
  29.  
  30. if (defined('WP_CLI') && WP_CLI && class_exists('WP_CLI_Command', FALSE)) { 
  31. /** 
  32. * Manage NextGen Gallery 
  33. */ 
  34. class C_NGG_WPCLI extends WP_CLI_Command 
  35. /** 
  36. * Flushes NextGen Gallery caches 
  37. */ 
  38. function flush_cache($args, $assoc_args) 
  39. C_Photocrati_Transient_Manager::flush(); 
  40. WP_CLI::success('Flushed all caches'); 
  41.  
  42. /** 
  43. * Create a new gallery 
  44. * 
  45. * @synopsis <gallery-name> --author=<user_login> 
  46. */ 
  47. function create_gallery($args, $assoc_args) 
  48. $mapper = C_Gallery_Mapper::get_instance(); 
  49.  
  50. $user = get_user_by('login', $assoc_args['author']); 
  51. if (!$user) 
  52. WP_CLI::error("Unable to find user {$assoc_args['author']}"); 
  53.  
  54. if (($gallery = $mapper->create(array('title' => $args[0], 'author' => $user->ID))) && $gallery->save()) 
  55. $gallery_id = $retval = $gallery->id(); 
  56. WP_CLI::success("Created gallery with id #{$gallery_id}"); 
  57. else { 
  58. WP_CLI::error("Unable to create gallery"); 
  59.  
  60. /** 
  61. * Import an image from the filesystem into NextGen 
  62. * 
  63. * @synopsis --filename=<absolute-path> --gallery=<gallery-id> 
  64. */ 
  65. function import_image($args, $assoc_args) 
  66. $mapper = C_Gallery_Mapper::get_instance(); 
  67. $storage = C_Gallery_Storage::get_instance(); 
  68.  
  69. if (($gallery = $mapper->find($assoc_args['gallery'], TRUE))) 
  70. $file_data = @file_get_contents($assoc_args['filename']); 
  71. $file_name = M_I18n::mb_basename($assoc_args['filename']); 
  72.  
  73. if (empty($file_data)) 
  74. WP_CLI::error('Could not load file'); 
  75.  
  76. $image = $storage->upload_base64_image($gallery, $file_data, $file_name); 
  77. $image_id = $image->{$image->id_field}; 
  78. if (!$image) 
  79. WP_CLI::error('Could not import image'); 
  80. else 
  81. WP_CLI::success("Imported image with id #{$image_id}"); 
  82. else { 
  83. WP_CLI::error("Gallery not found (with id #{$assoc_args['gallery']}"); 
  84.  
  85. /** 
  86. * Clear all dismissed notifications handled by C_Admin_Notification_Manager 
  87. * 
  88. * @synopsis 
  89. */ 
  90. function clear_dismissed_notifications($args, $assoc_args) 
  91. $settings = C_NextGen_Settings::get_instance(); 
  92. $settings->set('dismissed_notifications', array()); 
  93. $settings->set('gallery_created_after_reviews_introduced', FALSE); 
  94. $settings->save(); 
  95.  
  96. WP_CLI::add_command('ngg', 'C_NGG_WPCLI' ); 
.