HybridGallery.php
4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
namespace Tz\WordPress\Tools\HybridGallery;
use Tz\WordPress\Tools;
use Tz\WordPress\Tools\ShortCodes as SC;
//error_reporting(E_ALL);
/*
Plugin Name: Hybrid Gallery
Version: 0.0.1
Description: Mix of photos and videos into one Media Gallery Plugin
Author: Kevin Burton
Author URI: http://www.gotenzing.com/
*/
const SETTINGS_NS = 'hybridgallery';
const ADMIN_PAGE = 'hybridgallery-settings';
const CAPABILITY = 'hybridgallery_admin';
$role = get_role('administrator');
$role->add_cap(CAPABILITY);
Vars::$widget_dir = Tools\url('./', __FILE__);
Vars::$upload_dir = __DIR__.'/uploads/';
require('inc/config.php');
Vars::$defaults = $config;
unset($config);
$mArr = array();
foreach(Vars::$defaults as $option => $items) {
$mArr[$option] = $items[0];
}
Vars::$WP_Settings = new Tools\WP_Option(SETTINGS_NS, $mArr);
SC\registerClass(__NAMESPACE__ . '\ShortCodes');
Tools\add_actions(__NAMESPACE__ . '\Actions');
function adminDisplay() {
$defaults = Vars::$defaults;
require(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'settings.php');
}
class Vars {
public static $defaults;
public static $WP_Settings;
public static $widget_dir;
public static $upload_dir;
}
class Actions {
public static function init() {
global $wpdb;
$wpdb->show_errors();
register_post_type( 'gallery', array(
'label' => __('Gallery Entries')
, 'public' => true
, 'show_ui' => false
, 'hierarchical' => false
, 'supports' => array('category')
) );
register_taxonomy( 'hbGalleries', 'gallery', array( 'hierarchical' => true, 'label' => __('Galleries') ) );
// create a default gallery:
$tablename = $wpdb->prefix . 'terms';
$query = $wpdb->get_row("SELECT * FROM `$tablename` WHERE `slug`='hg-gallery-general' LIMIT 1",'ARRAY_A');
if ($wpdb->num_rows == 0) {
// doesn't exist, need to create default
$wpdb->query("INSERT INTO $tablename (name,slug) VALUES ('HG General Gallery','hg-gallery-general')");
$term_id = $wpdb->insert_id;
$tablename = $wpdb->prefix . 'term_taxonomy';
$wpdb->query("INSERT INTO $tablename (term_id,taxonomy,parent,count) VALUES ($term_id,'hbGalleries',0,0)");
}
}
public static function admin_menu() {
add_options_page('HybridGallery Settings', 'HybridGallery Settings', CAPABILITY, ADMIN_PAGE, __NAMESPACE__ . '\adminDisplay');
}
public static function admin_init() {
register_setting(SETTINGS_NS, SETTINGS_NS);
}
public static function wp_print_scripts() {
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-form');
_enqueue_script('swfobject', Tools\url('assets/uploadify/swfobject.js', __FILE__), array('jquery'));
_enqueue_script('jquery-uploadify', Tools\url('assets/uploadify/jquery.uploadify.v2.1.0.js', __FILE__), array('jquery','swfobject'));
}
}
class ShortCodes {
public static $defaults;
public static function HybridGallery($args = array(), $content, $tag) {
$WP_Settings = new Tools\WP_Option(SETTINGS_NS);
foreach (Vars::$defaults as $key => $val) {
if (isset($WP_Settings[$key])) {
self::$defaults[$key] = $WP_Settings[$key];
}
}
self::$defaults = shortcode_atts(self::$defaults, $args);
ob_start();
include('views/gallery.php');
$output = ob_get_contents();
ob_end_clean();
return $output;
}
}
?>