HybridGallery.php
4.22 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
<?php
//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/
*/
class HybridGallery {
public static $defaults;
public static $WP_Settings;
public static $widget_dir;
public static $upload_dir;
const SETTINGS_NS = 'hybridgallery';
const ADMIN_PAGE = 'hybridgallery-settings';
const CAPABILITY = 'hybridgallery_admin';
public static function cInit() {
$role = get_role('administrator');
$role->add_cap(self::CAPABILITY);
self::$widget_dir = TzTools::tools_url('./', __FILE__);
self::$upload_dir = dirname(__FILE__).'/uploads/';
require('inc/config.php');
self::$defaults = $config;
$mArr = array();
foreach(self::$defaults as $option => $items) {
$mArr[$option] = $items[0];
}
self::$WP_Settings = new WP_Option(self::SETTINGS_NS, $mArr);
ShortCodes::registerClass('HybridGallery_ShortCodes');
add_actions('HybridGallery_Actions');
}
public static function adminDisplay() {
$defaults = self::$defaults;
require(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'settings.php');
}
}
class HybridGallery_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', HybridGallery::CAPABILITY, HybridGallery::ADMIN_PAGE, Array('HybridGallery', 'adminDisplay'));
}
public static function admin_init() {
register_setting(HybridGallery::SETTINGS_NS, HybridGallery::SETTINGS_NS);
}
public static function wp_print_scripts() {
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-form');
_enqueue_script('swfobject', TzTools::tools_url('assets/uploadify/swfobject.js', __FILE__), array('jquery'));
_enqueue_script('jquery-uploadify', TzTools::tools_url('assets/uploadify/jquery.uploadify.v2.1.0.js', __FILE__), array('jquery','swfobject'));
}
}
class HybridGallery_ShortCodes {
public static $defaults;
public static function HybridGallery($args = array(), $content, $tag) {
$WP_Settings = new WP_Option(HybridGallery::SETTINGS_NS);
foreach (HybridGallery::$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;
}
}
HybridGallery::cInit();
?>