-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFpPostEvent.php
208 lines (188 loc) · 8.6 KB
/
FpPostEvent.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
require_once(dirname(__FILE__).'/FlickrPress.php');
class FpPostEvent {
private function __construct() {
}
public static function loadJSStrings($strings, $post) {
$strings['wpfpTitle'] = __('FlickrPress', FlickrPress::TEXT_DOMAIN);
$strings['wpfpSearchButton'] = __('Search', FlickrPress::TEXT_DOMAIN);
$strings['wpfpSearchTypeFilterRecent'] = __('Recent', FlickrPress::TEXT_DOMAIN);
$strings['wpfpSearchTypeFilterAlbum'] = __('Album', FlickrPress::TEXT_DOMAIN);
$strings['wpfpSearchTypeFilterAdvanced'] = __('Advanced', FlickrPress::TEXT_DOMAIN);
$strings['wpfpSearchSortFilterPostedASC'] = __('Posted ASC', FlickrPress::TEXT_DOMAIN);
$strings['wpfpSearchSortFilterPostedDESC'] = __('Posted DESC', FlickrPress::TEXT_DOMAIN);
$strings['wpfpSearchSortFilterTakenASC'] = __('Taken ASC', FlickrPress::TEXT_DOMAIN);
$strings['wpfpSearchSortFilterTakenDESC'] = __('Taken DESC', FlickrPress::TEXT_DOMAIN);
$strings['wpfpSearchSortFilterInterestingnessASC'] = __('Interestingness ASC', FlickrPress::TEXT_DOMAIN);
$strings['wpfpSearchSortFilterInterestingnessDESC'] = __('Interestingness DESC', FlickrPress::TEXT_DOMAIN);
$strings['wpfpSearchTagFilterPlaceholder'] = __('Tags', FlickrPress::TEXT_DOMAIN);
$strings['wpfpSearchKeywordFilterPlaceholder'] = __('Keyword', FlickrPress::TEXT_DOMAIN);
$strings['wpfpMultipleInsertMode'] = __('Multiple Mode', FlickrPress::TEXT_DOMAIN);
return $strings;
}
public static function loadUIScripts() {
wp_enqueue_style("select2", FlickrPress::getPluginUrl("libs/select2/css/select2.min.css"), array(), FlickrPress::VERSION);
wp_enqueue_style("wpfp", FlickrPress::getPluginUrl("css/media-views.css"), array(), FlickrPress::VERSION);
wp_enqueue_script('jquery.md5', FlickrPress::getPluginUrl('js/jquery.md5.js'), array(), FlickrPress::VERSION);
wp_enqueue_script('jquery.flickr-client', FlickrPress::getPluginUrl('js/jquery.flickr-client.js'), array(), FlickrPress::VERSION);
wp_enqueue_script('wpfp', FlickrPress::getPluginUrl('js/media-views.js'), array('media-views'), false, FlickrPress::VERSION);
wp_enqueue_script('select2', FlickrPress::getPluginUrl('libs/select2/js/select2.full.min.js'), array(), FlickrPress::VERSION);
}
public static function loadJSBridgeParams() {
$params = array(
'debugMode' => FlickrPress::isDebugMode() ? '1' : '0',
'apiKey' => FlickrPress::getApiKey(),
'apiSecret' => FlickrPress::getApiSecret(),
'userId' => FlickrPress::getUserId(),
'oauthToken' => FlickrPress::getOAuthToken(),
'enablePathAlias' => FlickrPress::enablePathAlias() ? '1' : '0',
'defaultLink' => FlickrPress::getDefaultLink(),
'defaultTarget' => FlickrPress::getDefaultTarget(),
'defaultSize' => FlickrPress::getDefaultSize(),
'defaultAlign' => FlickrPress::getDefaultAlign(),
'defaultFileUrlSize' => FlickrPress::getDefaultFileURLSize(),
'defaultEmbedHeader' => FlickrPress::getDefaultEmbedHeader(),
'defaultEmbedFooter' => FlickrPress::getDefaultEmbedHeader(),
'defaultEmbedSlideshow' => FlickrPress::getDefaultEmbedSlideshow(),
'insertTemplate' => FlickrPress::getInsertTemplate(),
);
$params_json = json_encode($params);
$html = <<< HTML
<script type="text/javascript">
// wp-flickr-press bridge params
window.wpfp = window.wpfp || {};
window.wpfp.bridge_params = $params_json;
</script>
HTML;
echo $html;
}
public static function addButtons() {
echo self::_media_button(__('Add flickr media', FlickrPress::TEXT_DOMAIN), FlickrPress::getPluginUrl().'/images/icon-flickr.gif', FlickrPress::MEDIA_BUTTON_TYPE);
}
public static function addButtonsFullScreen($buttons) {
$buttons['wpfp'] = array(
'title' => __('Insert/Flickr Media'),
'onclick' => "jQuery('#add_flickr_media').click();",
'both' => true,
);
return $buttons;
}
public static function loadScripts() {
$html = '';
$html .= '<script src="'.FlickrPress::getPluginUrl().'/js/media_upload.js'.'" type="text/javascript"></script>'."\n";
$html .= '<link rel="stylesheet" href="'.FlickrPress::getPluginUrl().'/css/admin_post.css" type="text/css" media="all" />' . "\n";
echo $html;
self::printTemplate();
self::loadJSBridgeParams();
}
public static function printTemplate() {
$linkTos= array(
'None' =>'urlnone',
'File URL'=>'urlfile',
'Page URL'=>'urlpage',
);
$alignes = array(
'None'=>'none',
'Left'=>'left',
'Center'=>'center',
'Right'=>'right',
);
$targets = array(
'None'=>'',
'New Window'=>'_blank',
);
?>
<script type="text/html" id="tmpl-wpfp-photo-container">
<div class="result-container">
<div class="result">
<ul class="photos ui-sortable ui-sortable-disabled"></ul>
<div class="buttons">
<div class="error">SEARCH ERROR. Please retry.</div>
<div class="loader">Loading...</div>
<button class="more-btn button button-primary">More</button>
</div>
</div>
</div>
</script>
<script type="text/html" id="tmpl-wpfp-photo-result">
<# _.each(data.photos.photo, function(photo, i){ #>
<li class="photo" data-idx="{{data.fp.lastIndex + i}}">
<div class="thumbnail-container">
<div class="thumbnail">
<img src="{{photo["url_" + data.fp.thumbnailSize]}}"/>
</div>
<a class="order-container" href="#"><div class="order"></div></a>
</div>
</li>
<# }); #>
</script>
<script type="text/html" id="tmpl-wpfp-photo-detail">
<h3>PHOTO DETAIL</h3>
<p>{{data.title}}</p>
<label class="setting">
<span>Link To</span>
<select name="to">
<?php foreach($linkTos as $label => $to) { ?>
<option value="<?php echo $to ?>" <# if("<?php echo $to ?>" == "url"+data.params.defaultLink){ #>selected="selected"<# } #>><?php echo __($label, FlickrPress::TEXT_DOMAIN) ?></option>
<?php } ?>
</select>
</label>
<label class="setting">
<span>Alignment</span>
<select name="alignment">
<?php foreach($alignes as $label => $align) { ?>
<option value="<?php echo $align ?>" <# if("<?php echo $align ?>" == data.params.defaultAlign){ #>selected="selected"<# } #>><?php echo __($label, FlickrPress::TEXT_DOMAIN) ?></option>
<?php } ?>
</select>
</label>
<label class="setting">
<span>Link Target</span>
<select name="target">
<?php foreach($targets as $label => $target) { ?>
<option value="<?php echo $target ?>" <# if("<?php echo $target ?>" == data.params.defaultTarget){ #>selected="selected"<# } #>><?php echo __($label, FlickrPress::TEXT_DOMAIN) ?></option>
<?php } ?>
</select>
</label>
<label class="setting">
<span>Size</span>
<select name="size">
<# _.each(data.fp.size_keys, function(size){ #>
<# if (data["url_"+size]) { #>
<option value="{{size}}" <# if(size == data.params.defaultSize){ #>selected="selected"<# } #>>{{ data.fp.size_labels[size] + " (" + data["width_"+size] + "x" + data["height_"+size] + ")" }}</option>
<# } #>
<# }); #>
</select>
</label>
<h4>Embed Option</h4>
<label class="setting">
<span>Header</span>
<input type="checkbox" name="embed_header" value="1" <# if("1" == data.params.defaultEmbedHeader){ #>checked="checked"<# } #>/>
</label>
<label class="setting">
<span>Footer</span>
<input type="checkbox" name="embed_footer" value="1" <# if("1" == data.params.defaultEmbedFooter){ #>checked="checked"<# } #>/>
</label>
<label class="setting">
<span>Slideshow</span>
<input type="checkbox" name="embed_slideshow" value="1" <# if("1" == data.params.defaultEmbedSlideshow){ #>checked="checked"<# } #>/>
</label>
</script>
<?php
}
public static function getUploadIframeSrc($uploadIframeSrc) {
if (FlickrPress::getDefaulSearchType() == 'thumbnail') {
return $uploadIframeSrc.'&mode=search_thumbnail';
} else {
return $uploadIframeSrc.'&mode=search';
}
}
private static function _media_button($title, $icon, $type) {
$buttons = '<button type="button" id="wpfp-action-media-library-button" class="button insert-media add_media" data-editor="content"><span class="wp-media-buttons-icon"></span> Add Flickr</button>';
$buttons .= "<a href='" . esc_url( get_upload_iframe_src($type) ) . "' id='add_$type' class='thickbox' title='$title'><img src='" . esc_url( $icon ) . "' alt='$title' /></a>";
return $buttons;
}
public static function mediaUploadFlickrMedia() {
require_once dirname(__FILE__) . '/media-upload.php';
}
}
?>