This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
forked from tgardner/wordpress-flickr-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverlayLoader.php
116 lines (86 loc) · 2.61 KB
/
OverlayLoader.php
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
<?php
// Load Dependencies
require_once(dirname(__FILE__) . '/lib/inc.templater.php');
// Overlay extension loader
class OverlayLoader {
var $overlayDir;
var $plugins = array();
var $overlay;
function __construct($overlayDir)
{
$this->overlayDir = dirname(__FILE__) . "/" . $overlayDir;
$this->LoadPlugins();
add_action('plugins_loaded', array(&$this, 'Initialize'));
}
function Initialize() {
global $flickr_manager;
if(!empty($flickr_manager->settings['image_viewer'])) {
if($this->LoadOverlay($flickr_manager->settings['image_viewer'])) {
add_action('init', array(&$this, 'LoadCommonJavascript'));
add_action('wp_head', array(&$this, 'LoadWFMVariables'));
}
}
}
function LoadPlugins()
{
if($handle = opendir($this->overlayDir)) {
while(($file = readdir($handle)) !== false) {
if(!is_dir(realpath($this->overlayDir . '/' . $file)) && substr($file,0,1) != "." && $name = $this->GetName($file)) {
$this->plugins[strtolower($name)] = $file;
}
}
}
}
function GetName($plugin)
{
$includePath = $this->overlayDir . '/' . $plugin;
if(!file_exists($includePath) || substr($includePath, -4) != '.php')
return;
include_once($includePath);
$class = substr($plugin,0,strpos($plugin,".",0));
if(!class_exists($class))
return;
$instance = new $class(true);
return $instance->GetName();
}
function GetOverlays()
{
return array_keys($this->plugins);
}
function LoadOverlay($overlay)
{
$plugin = $this->plugins[$overlay];
$includePath = $this->overlayDir . '/' . $plugin;
if(empty($plugin) || !file_exists($includePath))
return false;
include_once($includePath);
$class = substr($plugin,0,strpos($plugin,".",0));
$this->overlay = new $class();
return true;
}
function LoadCommonJavascript() {
wp_enqueue_script('wfm-common',plugins_url('/js/wfm-common.js', __FILE__), array('jquery'),'20110429');
}
function LoadWFMVariables() {
global $flickr_manager;
$settings = array(
'WFM_PluginDir' => $flickr_manager->absoluteURL
,'WFM_ViewOnFlickr' => __('View on Flickr', 'flickr-manager')
,'WFM_CaptionLink' => $flickr_manager->settings['flickr_link']
);
echo "<script type='text/javascript'>\n//<![CDATA[\n";
foreach($settings as $k => $v) {
echo sprintf("var %s = '%s';\n", $k, $v);
}
echo "//]]>\n</script>";
}
function GetActiveOverlay()
{
if(!empty($this->overlay)) {
return $this->overlay->GetName();
} else {
return null;
}
}
}
?>