| @@ -1,11 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | -defined('WPINC') OR exit; | |
| 2 | +defined( 'WPINC' ) OR exit; | |
| 3 | 3 | |
| 4 | 4 | /* |
| 5 | 5 | Plugin Name: Document Gallery |
| 6 | + Plugin URI: http://wordpress.org/extend/plugins/document-gallery/ | |
| 6 | 7 | Description: Display non-images (and images) in gallery format on a page or post with the [dg] shortcode. |
| 7 | - Version: 2.0 | |
| 8 | + Version: 3.5.3 | |
| 8 | 9 | Author: Dan Rossiter |
| 9 | 10 | Author URI: http://danrossiter.org/ |
| 10 | 11 | License: GPLv2 |
| 11 | 12 | Text Domain: document-gallery |
| @@ -10,141 +11,87 @@ | ||
| 10 | 11 | License: GPLv2 |
| 11 | 12 | Text Domain: document-gallery |
| 12 | 13 | */ |
| 13 | 14 | |
| 15 | +define( 'DG_VERSION', '3.5.3' ); | |
| 16 | + | |
| 14 | 17 | // define helper paths & URLs |
| 15 | -define('DG_URL', plugin_dir_url(__FILE__)); | |
| 16 | -define('DG_PATH', plugin_dir_path(__FILE__)); | |
| 17 | -if(!defined('WP_INCLUDE_DIR')) { | |
| 18 | - define('WP_INCLUDE_DIR', preg_replace('/wp-content$/', 'wp-includes', WP_CONTENT_DIR)); | |
| 19 | -} | |
| 20 | -if(!defined('WP_ADMIN_DIR')) { | |
| 21 | - define('WP_ADMIN_DIR', preg_replace('/wp-content$/', 'wp-admin', WP_CONTENT_DIR)); | |
| 22 | -} | |
| 18 | +define( 'DG_BASENAME', plugin_basename( __FILE__ ) ); | |
| 19 | +define( 'DG_URL', plugin_dir_url( __FILE__ ) ); | |
| 20 | +define( 'DG_PATH', plugin_dir_path( __FILE__ ) ); | |
| 21 | +define( 'DG_WPINC_PATH', ABSPATH . WPINC . '/' ); | |
| 22 | +define( 'DG_WPADMIN_PATH', ABSPATH . 'wp-admin/' ); | |
| 23 | 23 | |
| 24 | 24 | // init DG options for use throughout plugin |
| 25 | 25 | global $dg_options; |
| 26 | -define('DG_OPTION_NAME', 'document_gallery'); | |
| 27 | -$dg_options = get_option(DG_OPTION_NAME); | |
| 26 | +define( 'DG_OPTION_NAME', 'document_gallery' ); | |
| 27 | +$dg_options = get_option( DG_OPTION_NAME, null ); | |
| 28 | 28 | |
| 29 | -// handle activation and uninstallation | |
| 29 | +// core functionality | |
| 30 | +include_once DG_PATH . 'inc/class-document-gallery.php'; | |
| 31 | + | |
| 32 | +// DG general utility functions | |
| 33 | +include_once DG_PATH . 'inc/class-util.php'; | |
| 34 | + | |
| 35 | +// logging functionality | |
| 36 | +include_once DG_PATH . 'inc/class-logger.php'; | |
| 37 | +add_action( DG_Logger::PurgeLogsAction, array( 'DG_Logger', 'purgeExpiredEntries' ) ); | |
| 38 | + | |
| 39 | +// handle activation, updates, and uninstallation | |
| 30 | 40 | include_once DG_PATH . 'inc/class-setup.php'; |
| 31 | -register_activation_hook(__FILE__, array('DG_Setup', 'activation')); | |
| 32 | -register_uninstall_hook(__FILE__, array('DG_Setup', 'uninstall')); | |
| 41 | +register_activation_hook( __FILE__, array( 'DG_Setup', 'activate' ) ); | |
| 42 | +add_action( 'wpmu_new_blog', array( 'DG_Setup', 'activateNewBlog' ) ); | |
| 43 | +register_uninstall_hook( __FILE__, array( 'DG_Setup', 'uninstall' ) ); | |
| 44 | +DG_Setup::maybeUpdate(); | |
| 33 | 45 | |
| 46 | +// ensure we don't allow invalid option structure | |
| 47 | +add_action( 'init', array( 'DocumentGallery', 'addValidation' ) ); | |
| 48 | + | |
| 34 | 49 | // I18n |
| 35 | -add_action('plugins_loaded', array('DocumentGallery', 'loadTextDomain')); | |
| 50 | +add_action( 'plugins_loaded', array( 'DocumentGallery', 'loadTextDomain' ) ); | |
| 36 | 51 | |
| 37 | 52 | // cleanup cached data when thumbed attachment deleted |
| 38 | 53 | include_once DG_PATH . 'inc/class-thumber.php'; |
| 39 | -add_action('delete_attachment', array('DG_Thumber', 'deleteThumbMeta')); | |
| 54 | +add_action( 'delete_attachment', array( 'DG_Thumber', 'deleteThumbMeta' ) ); | |
| 40 | 55 | |
| 41 | -if (is_admin()) { | |
| 42 | - // admin house keeping | |
| 43 | - include_once DG_PATH . 'admin/class-admin.php'; | |
| 56 | +if ( is_admin() ) { | |
| 57 | + // admin house keeping | |
| 58 | + include_once DG_PATH . 'admin/class-admin.php'; | |
| 44 | 59 | |
| 45 | - // add settings link | |
| 46 | - add_filter('plugin_action_links_' . plugin_basename(__FILE__), | |
| 47 | - array('DG_Admin', 'addSettingsLink')); | |
| 60 | + // add links to plugin index | |
| 61 | + add_filter( 'plugin_action_links_' . DG_BASENAME, array( 'DG_Admin', 'addSettingsLink' ) ); | |
| 62 | + add_filter( 'plugin_row_meta', array( 'DG_Admin', 'addDonateLink' ), 10, 2 ); | |
| 48 | 63 | |
| 49 | - // build options page | |
| 50 | - add_action('admin_menu', array('DG_Admin', 'addAdminPage')); | |
| 51 | - if (!empty($GLOBALS['pagenow']) | |
| 52 | - && ('options-general.php' === $GLOBALS['pagenow'] // output | |
| 53 | - || 'options.php' === $GLOBALS['pagenow'])) { // validation | |
| 54 | - add_action('admin_init', array('DG_Admin', 'registerAdminStyle')); | |
| 55 | - add_action('admin_init', array('DG_Admin', 'registerSettings')); | |
| 56 | - } | |
| 57 | -} else { | |
| 58 | - // styling for gallery | |
| 59 | - add_action('wp_enqueue_scripts', array('DocumentGallery', 'enqueueGalleryStyle')); | |
| 60 | -} | |
| 64 | + // build options page | |
| 65 | + add_action( 'admin_menu', array( 'DG_Admin', 'addAdminPage' ) ); | |
| 61 | 66 | |
| 62 | -// adds 'dg' shortcode | |
| 63 | -add_shortcode('dg', array('DocumentGallery', 'doShortcode')); | |
| 67 | + // add meta box for managing thumbnail generation to attachment Edit Media page | |
| 68 | + add_action( 'add_meta_boxes', array( 'DG_Admin', 'addMetaBox' ) ); | |
| 69 | + add_action( 'wp_ajax_dg_upload_thumb', array( 'DG_Admin', 'saveMetaBox' ) ); | |
| 64 | 70 | |
| 65 | -/** | |
| 66 | - * DocumentGallery wraps basic functionality to setup the plugin. | |
| 67 | - * | |
| 68 | - * @author drossiter | |
| 69 | - */ | |
| 70 | -class DocumentGallery { | |
| 71 | + // Media Manager integration | |
| 72 | + add_action( 'admin_print_footer_scripts', array( | |
| 73 | + 'DG_Admin', | |
| 74 | + 'loadCustomTemplates' | |
| 75 | + ) ); //wp_print_scripts || wp_footer | |
| 71 | 76 | |
| 72 | - /*========================================================================== | |
| 73 | - * THE SHORTCODE | |
| 74 | - *=========================================================================*/ | |
| 77 | + if ( DG_Admin::doRegisterSettings() ) { | |
| 78 | + add_action( 'admin_init', array( 'DG_Admin', 'registerSettings' ) ); | |
| 79 | + } | |
| 75 | 80 | |
| 76 | - /** | |
| 77 | - * Takes values passed from attributes and returns sutable HTML to represent | |
| 78 | - * all valid attachments requested. | |
| 79 | - * | |
| 80 | - * @param array $atts Arguments from the user. | |
| 81 | - * @return string HTML for the Document Gallery. | |
| 82 | - */ | |
| 83 | - public static function doShortcode($atts) { | |
| 84 | - include_once 'inc/class-gallery.php'; | |
| 85 | - return new DG_Gallery($atts); | |
| 86 | - } | |
| 81 | + add_action( 'wp_ajax_dg_generate_icons', array( 'DocumentGallery', 'ajaxGenerateIcons' ) ); | |
| 82 | + add_action( 'wp_ajax_nopriv_dg_generate_icons', array( 'DocumentGallery', 'ajaxGenerateIcons' ) ); | |
| 83 | +} else { | |
| 84 | + // styling for gallery | |
| 85 | + if ( apply_filters( 'dg_use_default_gallery_style', true ) ) { | |
| 86 | + add_action( 'wp_enqueue_scripts', array( 'DocumentGallery', 'enqueueGalleryStyle' ) ); | |
| 87 | + } | |
| 88 | + add_action( 'wp_print_scripts', array( 'DocumentGallery', 'printCustomStyle' ) ); | |
| 87 | 89 | |
| 88 | - /** | |
| 89 | - * Enqueue standard DG CSS. | |
| 90 | - */ | |
| 91 | - public static function enqueueGalleryStyle() { | |
| 92 | - global $dg_options; | |
| 93 | - wp_register_style('dg-main', DG_URL . 'assets/css/style.css', null, | |
| 94 | - self::version() . ':' . $dg_options['css']['version']); | |
| 95 | - wp_enqueue_style('dg-main'); | |
| 96 | - } | |
| 90 | + add_action( 'wp_enqueue_scripts', array( 'DocumentGallery', 'enqueueGalleryScript' ) ); | |
| 91 | +} | |
| 97 | 92 | |
| 98 | - public static function updateUserGalleryStyle($css) { | |
| 99 | - $ret = false; | |
| 93 | +// adds 'dg' shortcode | |
| 94 | +add_shortcode( 'dg', array( 'DocumentGallery', 'doShortcode' ) ); | |
| 100 | 95 | |
| 101 | - if ($css_file = file_get_contents(DG_PATH . 'assets/css/style.css')) { | |
| 102 | - $css_file = preg_replace('#/\* CUSTOM USER CSS \*/.*#s', | |
| 103 | - "/* CUSTOM USER CSS */\n" . $css, $css_file); | |
| 104 | - $ret = (bool)file_put_contents(DG_PATH . 'assets/css/style.css', $css_file, LOCK_EX); | |
| 105 | - } | |
| 106 | - | |
| 107 | - return $ret; | |
| 108 | - } | |
| 109 | - | |
| 110 | - /*========================================================================== | |
| 111 | - * I18n | |
| 112 | - *=========================================================================*/ | |
| 113 | - | |
| 114 | - public static function loadTextDomain() { | |
| 115 | - load_plugin_textdomain('document-gallery', false, DG_PATH . 'languages'); | |
| 116 | - } | |
| 117 | - | |
| 118 | - /*========================================================================== | |
| 119 | - * HELPER FUNCTIONS | |
| 120 | - *=========================================================================*/ | |
| 121 | - | |
| 122 | - /** | |
| 123 | - * Gets the current version of the plugin. | |
| 124 | - * @param bool recalculate Whether to re-read the file for version number. | |
| 125 | - * @return str DG version installed. | |
| 126 | - */ | |
| 127 | - public static function version($recalculate = false) { | |
| 128 | - static $version = null; | |
| 129 | - | |
| 130 | - if ($recalculate) { | |
| 131 | - include_once WP_ADMIN_DIR . '/includes/plugin.php'; | |
| 132 | - $data = get_plugin_data(__FILE__, false); | |
| 133 | - $version = $data['Version']; | |
| 134 | - } elseif(is_null($version)) { | |
| 135 | - global $dg_options; | |
| 136 | - $version = $dg_options['version']; | |
| 137 | - } | |
| 138 | - | |
| 139 | - return $version; | |
| 140 | - } | |
| 141 | - | |
| 142 | - /** | |
| 143 | - * Blocks instantiation. All functions are static. | |
| 144 | - */ | |
| 145 | - private function __construct() { | |
| 146 | - | |
| 147 | - } | |
| 148 | -} | |
| 149 | - | |
| 150 | -?> | |
| 96 | +// public API for developers | |
| 97 | +include_once DG_PATH . 'inc/class-api.php'; | |