PluginProbe
Document Gallery / 2.0
Document Gallery v2.0
trunk 0.8 0.8.5 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 2.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 94 releases
document-gallery / document-gallery.php

document-gallery.php in Document Gallery 2.0, at document-gallery.php

150 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('WPINC') OR exit;
3
4 /*
5 Plugin Name: Document Gallery
6 Description: Display non-images (and images) in gallery format on a page or post with the [dg] shortcode.
7 Version: 2.0
8 Author: Dan Rossiter
9 Author URI: http://danrossiter.org/
10 License: GPLv2
11 Text Domain: document-gallery
12 */
13
14 // 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 }
23
24 // init DG options for use throughout plugin
25 global $dg_options;
26 define('DG_OPTION_NAME', 'document_gallery');
27 $dg_options = get_option(DG_OPTION_NAME);
28
29 // handle activation and uninstallation
30 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'));
33
34 // I18n
35 add_action('plugins_loaded', array('DocumentGallery', 'loadTextDomain'));
36
37 // cleanup cached data when thumbed attachment deleted
38 include_once DG_PATH . 'inc/class-thumber.php';
39 add_action('delete_attachment', array('DG_Thumber', 'deleteThumbMeta'));
40
41 if (is_admin()) {
42 // admin house keeping
43 include_once DG_PATH . 'admin/class-admin.php';
44
45 // add settings link
46 add_filter('plugin_action_links_' . plugin_basename(__FILE__),
47 array('DG_Admin', 'addSettingsLink'));
48
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 }
61
62 // adds 'dg' shortcode
63 add_shortcode('dg', array('DocumentGallery', 'doShortcode'));
64
65 /**
66 * DocumentGallery wraps basic functionality to setup the plugin.
67 *
68 * @author drossiter
69 */
70 class DocumentGallery {
71
72 /*==========================================================================
73 * THE SHORTCODE
74 *=========================================================================*/
75
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 }
87
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 }
97
98 public static function updateUserGalleryStyle($css) {
99 $ret = false;
100
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 ?>