Image.php000064400000003707150212476640006315 0ustar00 --gallery= */ public function import( $args, $assoc_args ) { $mapper = GalleryMapper::get_instance(); $storage = StorageManager::get_instance(); if ( ( $gallery = $mapper->find( $assoc_args['gallery'], true ) ) ) { $file_data = @file_get_contents( $assoc_args['filename'] ); $file_name = I18N::mb_basename( $assoc_args['filename'] ); if ( empty( $file_data ) ) { \WP_CLI::error( 'Could not load file' ); } $image_id = $storage->upload_base64_image( $gallery, $file_data, $file_name ); if ( ! $image_id ) { \WP_CLI::error( 'Could not import image' ); } else { \WP_CLI::success( "Imported image with id #{$image_id}" ); } } else { \WP_CLI::error( "Gallery not found (with id #{$assoc_args['gallery']}" ); } } /** * Change image attributes * * @param $args * @param $assoc_args * @synopsis [--description=] [--title=] */ public function edit( $args, $assoc_args ) { $mapper = ImageMapper::get_instance(); $image = $mapper->find( $args[0] ); if ( ! $image ) { \WP_CLI::error( "Unable to find image {$args[0]}" ); } if ( empty( $assoc_args['description'] ) && empty( $assoc_args['title'] ) ) { \WP_CLI::error( 'You must provide a new description or title' ); } if ( ! empty( $assoc_args['description'] ) ) { $image->description = $assoc_args['description']; } if ( ! empty( $assoc_args['title'] ) ) { $image->alttext = $assoc_args['title']; } $mapper->save( $image ); \WP_CLI::success( "Image with id #{$image->pid} has been modified" ); } } ���������������������������������������������������������Manager.php�����������������������������������������������������������������������������������������0000644�����������������00000001503�15021247664�0006635 0����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?php namespace Imagely\NGG\WPCLI; class Manager { public static function register() { /** @noinspection PhpUndefinedClassInspection */ \WP_CLI::add_command( 'ngg album', '\Imagely\NGG\WPCLI\Album' ); /** @noinspection PhpUndefinedClassInspection */ \WP_CLI::add_command( 'ngg cache', '\Imagely\NGG\WPCLI\Cache' ); /** @noinspection PhpUndefinedClassInspection */ \WP_CLI::add_command( 'ngg gallery', '\Imagely\NGG\WPCLI\Gallery' ); /** @noinspection PhpUndefinedClassInspection */ \WP_CLI::add_command( 'ngg image', '\Imagely\NGG\WPCLI\Image' ); /** @noinspection PhpUndefinedClassInspection */ \WP_CLI::add_command( 'ngg notifications', '\Imagely\NGG\WPCLI\Notifications' ); /** @noinspection PhpUndefinedClassInspection */ \WP_CLI::add_command( 'ngg settings', '\Imagely\NGG\WPCLI\Settings' ); } } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Notifications.php�����������������������������������������������������������������������������������0000644�����������������00000000763�15021247664�0010103 0����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?php namespace Imagely\NGG\WPCLI; use Imagely\NGG\Settings\Settings; class Notifications { /** * Clear all dismissed notifications handled by C_Admin_Notification_Manager * * @param array $args * @param array $assoc_args * @synopsis */ public function clear_dismissed( $args, $assoc_args ) { $settings = Settings::get_instance(); $settings->set( 'dismissed_notifications', [] ); $settings->set( 'gallery_created_after_reviews_introduced', false ); $settings->save(); } } �������������Album.php�������������������������������������������������������������������������������������������0000644�����������������00000015601�15021247664�0006327 0����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?php namespace Imagely\NGG\WPCLI; use Imagely\NGG\DataMappers\Album as AlbumMapper; use Imagely\NGG\DataMappers\Gallery as GalleryMapper; class Album { /** * Create a new album * * @param array $args * @param array $assoc_args * @synopsis <album_name> [--description=<description>] --author=<user_login> */ public function create( $args, $assoc_args ) { $mapper = AlbumMapper::get_instance(); $user = get_user_by( 'login', $assoc_args['author'] ); if ( ! $user ) { \WP_CLI::error( "Unable to find user {$assoc_args['author']}" ); } $description = ! empty( $assoc_args['description'] ) ? $assoc_args['description'] : ''; $album = $mapper->create( [ 'name' => $args[0], 'albumdesc' => $description, 'author' => $user->ID, ] ); if ( $album && $album->save() ) { $album_id = $retval = $album->id(); \WP_CLI::success( "Created album with id #{$album_id}" ); } else { \WP_CLI::error( 'Unable to create album' ); } } /** * Deletes the requested album * * @param $args * @param $assoc_args * @synopsis <album_id> */ public function delete( $args, $assoc_args ) { $mapper = AlbumMapper::get_instance(); $album = $mapper->find( $args[0] ); if ( ! $album ) { \WP_CLI::error( "Unable to find album {$args[0]}" ); } $mapper->destroy( $album ); \WP_CLI::success( "Album with id #{$album->id} has been deleted" ); } /** * Change album attributes * * @param $args * @param $assoc_args * @synopsis <album_id> [--description=<description>] [--name=<name>] */ public function edit( $args, $assoc_args ) { $mapper = AlbumMapper::get_instance(); $album = $mapper->find( $args[0] ); if ( ! $album ) { \WP_CLI::error( "Unable to find album {$args[0]}" ); } if ( empty( $assoc_args['description'] ) && empty( $assoc_args['name'] ) ) { \WP_CLI::error( 'You must provide a new description or title' ); } if ( ! empty( $assoc_args['description'] ) ) { $album->albumdesc = $assoc_args['description']; } if ( ! empty( $assoc_args['name'] ) ) { $album->name = $assoc_args['name']; } $mapper->save( $album ); \WP_CLI::success( "Album with id #{$album->id} has been modified" ); } /** * @param array $args * @param array $assoc_args * @subcommand list */ public function _list( $args, $assoc_args ) { $mapper = AlbumMapper::get_instance(); $display = []; foreach ( $mapper->find_all() as $album ) { $display[] = [ 'id' => $album->id, 'name' => $album->name, '# of children' => count( $album->sortorder ), 'description' => $album->albumdesc, ]; } \WP_CLI\Utils\format_items( 'table', $display, [ 'id', 'name', '# of children', 'description' ] ); } /** * Adds child galleries or albums to an album * * @param $args * @param $assoc_args * @synopsis <album_id> [--galleries=<galleries>] [--albums=<albums>] */ public function add_children( $args, $assoc_args ) { $album_mapper = AlbumMapper::get_instance(); $album = $album_mapper->find( $args[0] ); if ( ! $album ) { \WP_CLI::error( "Unable to find album {$args[0]}" ); } if ( empty( $assoc_args['galleries'] ) && empty( $assoc_args['albums'] ) ) { \WP_CLI::error( 'You must provide new child galleries or albums' ); } if ( ! empty( $assoc_args['galleries'] ) ) { $new = explode( ',', $assoc_args['galleries'] ); $gallery_mapper = GalleryMapper::get_instance(); foreach ( $new as $gallery_id ) { $gallery = $gallery_mapper->find( $gallery_id ); if ( ! $gallery ) { \WP_CLI::error( "Unable to find gallery {$gallery_id}" ); } if ( in_array( $gallery_id, $album->sortorder ) ) { \WP_CLI::error( "Gallery with id {$gallery_id} already belongs to this album" ); } $album->sortorder[] = $gallery_id; } } if ( ! empty( $assoc_args['albums'] ) ) { $new = explode( ',', $assoc_args['albums'] ); foreach ( $new as $album_id ) { $new_album = $album_mapper->find( $album_id ); if ( ! $new_album ) { \WP_CLI::error( "Unable to find album {$album_id}" ); } if ( in_array( $album_id, $album->sortorder ) ) { \WP_CLI::error( "Album with id {$album_id} already belongs to this album" ); } if ( $album_id == $args[0] ) { \WP_CLI::error( 'Cannot add an album to itself' ); } $album->sortorder[] = 'a' . $album_id; } } $album_mapper->save( $album ); \WP_CLI::success( "Album with id #{$album->id} has been modified" ); } /** * Removes child galleries or albums attached to an album * * @param $args * @param $assoc_args * @synopsis <album_id> [--galleries=<galleries>] [--albums=<albums>] */ public function delete_children( $args, $assoc_args ) { $album_mapper = AlbumMapper::get_instance(); $parent_album = $album_mapper->find( $args[0] ); if ( ! $parent_album ) { \WP_CLI::error( "Unable to find album {$args[0]}" ); } if ( empty( $assoc_args['galleries'] ) && empty( $assoc_args['albums'] ) ) { \WP_CLI::error( 'You must provide a child gallery or album to remove' ); } $galleries = []; $albums = []; if ( ! empty( $assoc_args['galleries'] ) ) { $galleries = explode( ',', $assoc_args['galleries'] ); } if ( ! empty( $assoc_args['albums'] ) ) { $albums = explode( ',', $assoc_args['albums'] ); } foreach ( $parent_album->sortorder as $ndx => $child ) { foreach ( $galleries as $gallery ) { if ( $gallery == $child ) { unset( $parent_album->sortorder[ $ndx ] ); } } foreach ( $albums as $album ) { if ( 'a' . $album == $child ) { unset( $parent_album->sortorder[ $ndx ] ); } } } $album_mapper->save( $parent_album ); \WP_CLI::success( "Album with id #{$parent_album->id} has been modified" ); } /** * Lists all child galleries and albums belonging to an album * * @param $args * @param $assoc_args * @synopsis <album_id> */ public function list_children( $args, $assoc_args ) { $album_mapper = AlbumMapper::get_instance(); $gallery_mapper = GalleryMapper::get_instance(); $album = $album_mapper->find( $args[0] ); if ( ! $album ) { \WP_CLI::error( "Unable to find album {$args[0]}" ); } $display = []; foreach ( $album->sortorder as $child ) { $is_album = ( strpos( $child, 'a' ) === 0 ) ? true : false; if ( $is_album ) { $child = str_replace( 'a', '', $child ); $child_album = $album_mapper->find( $child ); $display[] = [ 'id' => $child_album->id, 'type' => 'album', 'title' => $child_album->name, 'description' => $child_album->albumdesc, ]; } else { $child_gallery = $gallery_mapper->find( $child ); $display[] = [ 'id' => $child_gallery->gid, 'type' => 'gallery', 'title' => $child_gallery->title, 'description' => $child_gallery->galdesc, ]; } } \WP_CLI\Utils\format_items( 'table', $display, [ 'id', 'type', 'title', 'description' ] ); } } �������������������������������������������������������������������������������������������������������������������������������Cache.php�������������������������������������������������������������������������������������������0000644�����������������00000000617�15021247664�0006273 0����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?php namespace Imagely\NGG\WPCLI; use Imagely\NGG\Util\Transient; class Cache { /** * Flushes NextGen Gallery caches * * @param array $args * @param array $assoc_args * @synopsis [--expired] */ public function flush( $args, $assoc_args ) { $expired = ! empty( $assoc_args['expired'] ) ? true : false; Transient::flush( $expired ); \WP_CLI::success( 'Flushed caches' ); } } �����������������������������������������������������������������������������������������������������������������Gallery.php�����������������������������������������������������������������������������������������0000644�����������������00000007316�15021247664�0006672 0����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?php namespace Imagely\NGG\WPCLI; use Imagely\NGG\DataMappers\Gallery as GalleryMapper; use Imagely\NGG\DataMappers\Image as ImageMapper; class Gallery { /** * Create a new gallery * * @param array $args * @param array $assoc_args * @synopsis <gallery_name> [--description=<description>] --author=<user_login> */ public function create( $args, $assoc_args ) { $mapper = GalleryMapper::get_instance(); $user = get_user_by( 'login', $assoc_args['author'] ); if ( ! $user ) { \WP_CLI::error( "Unable to find user {$assoc_args['author']}" ); } $description = ! empty( $assoc_args['description'] ) ? $assoc_args['description'] : ''; $gallery = $mapper->create( [ 'title' => $args[0], 'galdesc' => $description, 'author' => $user->ID, ] ); if ( $gallery && $gallery->save() ) { $gallery_id = $retval = $gallery->id(); \WP_CLI::success( "Created gallery with id #{$gallery_id}" ); } else { \WP_CLI::error( 'Unable to create gallery' ); } } /** * Deletes the requested gallery * * @param $args * @param $assoc_args * @synopsis <gallery_id> [--delete-files] */ public function delete( $args, $assoc_args ) { $mapper = GalleryMapper::get_instance(); $gallery = $mapper->find( $args[0] ); if ( ! $gallery ) { \WP_CLI::error( "Unable to find gallery {$args[0]}" ); } $remove_files = ! empty( $assoc_args['delete-files'] ) ? true : false; $mapper->destroy( $gallery, $remove_files ); \WP_CLI::success( "Gallery with id #{$gallery->gid} has been deleted" ); } /** * Change gallery attributes * * @param $args * @param $assoc_args * @synopsis <gallery_id> [--description=<description>] [--title=<title>] */ public function edit( $args, $assoc_args ) { $mapper = GalleryMapper::get_instance(); $gallery = $mapper->find( $args[0] ); if ( ! $gallery ) { \WP_CLI::error( "Unable to find gallery {$args[0]}" ); } if ( empty( $assoc_args['description'] && empty( $assoc_args['title'] ) ) ) { \WP_CLI::error( 'You must provide a new description or title' ); } if ( ! empty( $assoc_args['description'] ) ) { $gallery->galdesc = $assoc_args['description']; } if ( ! empty( $assoc_args['title'] ) ) { $gallery->name = $assoc_args['title']; } $mapper->save( $gallery ); \WP_CLI::success( "Gallery with id #{$gallery->gid} has been modified" ); } /** * @param array $args * @param array $assoc_args * @subcommand list */ public function _list( $args, $assoc_args ) { $mapper = GalleryMapper::get_instance(); $display = []; foreach ( $mapper->find_all() as $gallery ) { $display[] = [ 'id' => $gallery->gid, 'title' => $gallery->name, 'path' => $gallery->path, 'description' => $gallery->galdesc, ]; } \WP_CLI\Utils\format_items( 'table', $display, [ 'id', 'title', 'path', 'description' ] ); } /** * @param $args * @param $assoc_args * @synopsis <gallery_id> */ public function list_children( $args, $assoc_args ) { $gallery_mapper = GalleryMapper::get_instance(); $image_mapper = ImageMapper::get_instance(); $gallery = $gallery_mapper->find( $args[0] ); if ( ! $gallery ) { \WP_CLI::error( "Unable to find gallery {$args[0]}" ); } $images = $image_mapper->select()->where( [ 'galleryid = %s', $gallery->gid ] )->run_query(); $display = []; foreach ( $images as $image ) { $display[] = [ 'id' => $image->pid, 'title' => $image->alttext, 'excluded' => 0 === boolval( $image->exclude ) ? 'no' : 'yes', 'sort order' => $image->sortorder, 'description' => $image->description, ]; } \WP_CLI\Utils\format_items( 'table', $display, [ 'id', 'title', 'excluded', 'sort order', 'description' ] ); } } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Settings.php����������������������������������������������������������������������������������������0000644�����������������00000005523�15021247664�0007071 0����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?php namespace Imagely\NGG\WPCLI; use Imagely\NGG\Util\Transient; use Imagely\NGG\Util\Installer; use Imagely\NGG\Settings\Settings as SettingsManager; class Settings { /** * @param array $args * @param array $assoc_args * @subcommand list */ public function _list( $args, $assoc_args ) { $settings = SettingsManager::get_instance(); $temporary = $settings->to_array(); $display = []; foreach ( $temporary as $key => $val ) { $display[] = [ 'key' => $key, 'value' => $val, ]; } \WP_CLI\Utils\format_items( 'table', $display, [ 'key', 'value' ] ); } /** * @param array $args * @param array $assoc_args * @synopsis <key> <value> */ public function edit( $args, $assoc_args ) { $settings = SettingsManager::get_instance(); $settings->set( $args[0], $args[1] ); $settings->save(); \WP_CLI::success( 'Setting has been updated' ); } /** * Export all NextGen settings to a file in JSON format * * @param $args * @param $assoc_args * @synopsis <json-file-path> */ public function export( $args, $assoc_args ) { $settings = SettingsManager::get_instance(); file_put_contents( $args[0], $settings->to_json() ); \WP_CLI::success( "Settings have been stored in {$args[0]}" ); } /** * Import settings from a JSON file * * @param array $args * @param array $assoc_args * @synopsis <json-file-path> */ public function import( $args, $assoc_args ) { $settings = SettingsManager::get_instance(); $file_content = file_get_contents( $args[0] ); $json = json_decode( $file_content ); if ( null === $json ) { \WP_CLI::error( 'Could not parse JSON file' ); } foreach ( $json as $key => $value ) { $settings->set( $key, $value ); } $settings->save(); \WP_CLI::success( "Settings have been imported from {$args[0]}" ); } /** * Deactivates NextGen and NextGen Pro and resets all settings to their default state * * @param array $args * @param array $assoc_args */ public function reset( $args, $assoc_args ) { \WP_CLI::confirm( 'Are you sure you want to reset all NextGen settings?', $assoc_args ); $settings = SettingsManager::get_instance(); Transient::flush(); if ( defined( 'NGG_PRO_PLUGIN_VERSION' ) || defined( 'NEXTGEN_GALLERY_PRO_VERSION' ) ) { Installer::uninstall( 'photocrati-nextgen-pro' ); } if ( defined( 'NGG_PLUS_PLUGIN_VERSION' ) ) { Installer::uninstall( 'photocrati-nextgen-plus' ); } Installer::uninstall( 'photocrati-nextgen' ); // removes all ngg_options entry in wp_options. $settings->reset(); $settings->destroy(); global $wpdb; $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->posts} WHERE post_type = %s", 'display_type' ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->posts} WHERE post_type = %s", 'lightbox_library' ) ); \WP_CLI::success( 'All NextGen settings have been reset' ); } } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������