PluginProbe
Document Gallery / 2.0.2
Document Gallery v2.0.2
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.2, at document-gallery.php

131 lines 4.2 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.2
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_VERSION', '2.0.2');
16 define('DG_URL', plugin_dir_url(__FILE__));
17 define('DG_PATH', plugin_dir_path(__FILE__));
18 if(!defined('WP_INCLUDE_DIR')) {
19 define('WP_INCLUDE_DIR', preg_replace('/wp-content$/', 'wp-includes', WP_CONTENT_DIR));
20 }
21 if(!defined('WP_ADMIN_DIR')) {
22 define('WP_ADMIN_DIR', preg_replace('/wp-content$/', 'wp-admin', WP_CONTENT_DIR));
23 }
24
25 // init DG options for use throughout plugin
26 global $dg_options;
27 define('DG_OPTION_NAME', 'document_gallery');
28 $dg_options = get_option(DG_OPTION_NAME, null);
29
30 // handle activation and uninstallation
31 include_once DG_PATH . 'inc/class-setup.php';
32 DG_Setup::maybeUpdate();
33 register_uninstall_hook(__FILE__, array('DG_Setup', 'uninstall'));
34
35 // I18n
36 add_action('plugins_loaded', array('DocumentGallery', 'loadTextDomain'));
37
38 // cleanup cached data when thumbed attachment deleted
39 include_once DG_PATH . 'inc/class-thumber.php';
40 add_action('delete_attachment', array('DG_Thumber', 'deleteThumbMeta'));
41
42 if (is_admin()) {
43 // admin house keeping
44 include_once DG_PATH . 'admin/class-admin.php';
45
46 // add settings link
47 add_filter('plugin_action_links_' . plugin_basename(__FILE__),
48 array('DG_Admin', 'addSettingsLink'));
49
50 // build options page
51 add_action('admin_menu', array('DG_Admin', 'addAdminPage'));
52 if (!empty($GLOBALS['pagenow'])
53 && ('options-general.php' === $GLOBALS['pagenow'] // output
54 || 'options.php' === $GLOBALS['pagenow'])) { // validation
55 add_action('admin_init', array('DG_Admin', 'registerAdminStyle'));
56 add_action('admin_init', array('DG_Admin', 'registerSettings'));
57 }
58 } else {
59 // styling for gallery
60 add_action('wp_enqueue_scripts', array('DocumentGallery', 'enqueueGalleryStyle'));
61 }
62
63 // adds 'dg' shortcode
64 add_shortcode('dg', array('DocumentGallery', 'doShortcode'));
65
66 /**
67 * DocumentGallery wraps basic functionality to setup the plugin.
68 *
69 * @author drossiter
70 */
71 class DocumentGallery {
72
73 /*==========================================================================
74 * THE SHORTCODE
75 *=========================================================================*/
76
77 /**
78 * Takes values passed from attributes and returns sutable HTML to represent
79 * all valid attachments requested.
80 *
81 * @param array $atts Arguments from the user.
82 * @return string HTML for the Document Gallery.
83 */
84 public static function doShortcode($atts) {
85 include_once 'inc/class-gallery.php';
86 return new DG_Gallery($atts);
87 }
88
89 /**
90 * Enqueue standard DG CSS.
91 */
92 public static function enqueueGalleryStyle() {
93 global $dg_options;
94 wp_register_style('dg-main', DG_URL . 'assets/css/style.css', null,
95 DG_VERSION . ':' . $dg_options['css']['version']);
96 wp_enqueue_style('dg-main');
97 }
98
99 public static function updateUserGalleryStyle($css) {
100 $ret = false;
101
102 if ($css_file = file_get_contents(DG_PATH . 'assets/css/style.css')) {
103 $css_file = preg_replace('#/\* CUSTOM USER CSS \*/.*#s',
104 "/* CUSTOM USER CSS */\n" . $css, $css_file);
105 $ret = (bool)file_put_contents(DG_PATH . 'assets/css/style.css', $css_file, LOCK_EX);
106 }
107
108 return $ret;
109 }
110
111 /*==========================================================================
112 * I18n
113 *=========================================================================*/
114
115 public static function loadTextDomain() {
116 load_plugin_textdomain('document-gallery', false, dirname(plugin_basename(__FILE__ )) . '/languages/');
117 }
118
119 /*==========================================================================
120 * HELPER FUNCTIONS
121 *=========================================================================*/
122
123 /**
124 * Blocks instantiation. All functions are static.
125 */
126 private function __construct() {
127
128 }
129 }
130
131 ?>