source: trunk/www.guidonia.net/wp/wp-content/plugins/webtv/webtv_Admin.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 14.4 KB
Line 
1<?php
2
3/*
4Author: Edgar de Le&oacute;n - edeleon
5Author URI: http://www.webstratega.com/about/
6Description: Lets you attach a video to a post and upload to most popular video distribution sites like YouTube, Vimeo and Blip.tv, after video is uploaded and processed get and inserts the embed code from the sites into custom fields on the post. The plugin has de possibility to extend any other distribution site creating extra drivers
7License: GPL (http://www.fsf.org/licensing/licenses/info/GPLv2.html)
8*/
9
10class Webtv_Admin {
11
12 function Webtv_Admin() {
13 register_activation_hook(dirname(__FILE__) . '/webtv.php', array(&$this, 'activate_me'));
14 }
15
16 public function activate_me() {
17 foreach (glob(dirname (__FILE__).'/Drivers/*.php') as $file) {
18 include_once $file;
19 $path_parts = pathinfo($file);
20 $service_name = $path_parts['filename'];
21 if (function_exists($service_name.'_settings')) {
22 $service_config = call_user_func($service_name.'_settings');
23 if (isset($service_config)) {
24 $provider = $service_config['service'];
25 if ( $options = get_option("webtv") ) {
26 if (!(isset($options['services'][$provider]))) {
27 $options['services'][$provider] = $provider;
28 $options['order'][] = $provider;
29 update_option("webtv", $options);
30 }
31 } else {
32 $options = array();
33 $options['attemps'] = 3;
34 $options['services'][$provider] = $provider;
35 $options['order'][] = $provider;
36 add_option("webtv",$options);
37 }
38
39 $settings = "webtv_".$service_config['service'];
40 $service_name = $service_config['service'];
41 unset($service_config['service']);
42 if ( !get_option($settings) ) {
43 $options = array();
44 foreach ($service_config as $option => $value) {
45 $options[$option] = $value;
46 }
47 add_option($settings,$options);
48 }
49 unset($service_config);
50 }
51 }
52 if (function_exists($service_name.'_extras')) {
53 $extras = call_user_func($service_name.'_extras');
54 if ( get_option($service_name.'_extras') ) {
55 update_option('webtv_'.$service_name.'_extras', $extras);
56 } else {
57 add_option('webtv_'.$service_name.'_extras', $extras);
58 }
59 }
60 }
61 } //Activate_me
62
63 function add_config_page() {
64 if ( function_exists('add_submenu_page') ) {
65 add_options_page('WebTV for WordPress Configuration', 'WebTV', 8, basename(__FILE__), array(&$this,'config_page'));
66 add_filter( 'plugin_action_links', array( &$this, 'filter_plugin_actions'), 10, 2 ); }
67 }
68
69 function filter_plugin_actions( $links, $file ){
70 //Static so we don't call plugin_basename on every plugin row.
71 static $this_plugin;
72 if ( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
73
74 if ( dirname($file) == dirname($this_plugin) ){
75 $settings_link = '<a href="options-general.php?page=webtv_Admin.php">' . __('Settings') . '</a>';
76 array_unshift( $links, $settings_link ); // before other links
77 }
78 return $links;
79 }
80
81 function config_page() {
82 if (!current_user_can('manage_options')) die(__('You cannot edit the WebTV options.'));
83 $options = get_option("webtv");
84 //print_r($options);
85
86 if (!is_array($options)) {
87 $options = array();
88 $options['attemps'] = 3;
89 add_option("webtv",$options);
90 }
91 if (!is_array($options['order'])) {
92 foreach ($options['services'] as $service) {
93 $options['order'][] = $service;
94 }
95 update_option("webtv",$options);
96 }
97
98 if ( isset($_POST['submit']) ) {
99 check_admin_referer('webtv-config');
100 //print_r($_POST);
101 if (isset($_POST['attemps']) && is_numeric($_POST['attemps'])) {
102 $options['attemps'] = $_POST['attemps'];
103 if ($options['attemps'] < 1) {
104 $options['attemps'] = 3;
105 }
106 if ($options['attemps'] > 6) {
107 $options['attemps'] = 6;
108 }
109 }
110 if (isset($_POST['attemps']) && $_POST['attemps'] == "") {
111 $options['attemps'] = 3;
112 }
113 if (isset($_POST['orderedlist'])) {
114 $service_order = split("\|", $_POST['orderedlist']);
115 $options['order'] = $service_order;
116 }
117 update_option("webtv",$options);
118 $services = $_POST['service'];
119 foreach ($services as $service_name => $service) {
120 $service_settings = get_option("webtv_".$service_name);
121 $enabled = false;
122 if ($service['enabled'] == 'true') {
123 $enabled = true;
124 }
125 unset($service['enabled']);
126 foreach ($service as $option => $value) {
127 if ($value == "") $enabled = false;
128 $service_settings[$option] = $value;
129 }
130 $service_settings['enabled'] = $enabled;
131 update_option("webtv_".$service_name,$service_settings);
132
133 }
134
135 }
136 if ( isset($_POST['cleanupsubmit']) ) {
137 check_admin_referer('webtv-cleanup');
138 global $wpdb, $table_prefix;
139
140 $query = 'DELETE FROM '.$table_prefix.'options WHERE option_name like "webtv%"';
141 $wpdb->query($query);
142
143 if (isset($_POST['cleanup'])) {
144
145 $query = 'DELETE FROM '.$table_prefix.'postmeta WHERE meta_key like "webtv%"';
146 $wpdb->query($query);
147 echo "<div id=\"message\" class=\"updated fade\"><p>WebTV ha eliminado toda la informaci&oacute;n.</p></div>\n";
148 }
149 echo "<div id=\"message\" class=\"updated fade\"><p>WebTV ha sido desinstalado.</p></div>\n";
150 }
151 ?>
152 <div class="wrap">
153 <h2>WebTV Configuration</h2>
154 <form action="<?php $PHP_SELF ?>" method="post" id="webtv-conf">
155 <table class="form-table" style="width:100%;">
156 <?php
157 if ( function_exists('wp_nonce_field') )
158 wp_nonce_field('webtv-config');
159 ?>
160 <tr>
161 <th>
162 <label for="attemps"><strong><?=_("How many times do you want to try to publish the video")?>:</strong></label><br/>
163 <small><?=_("Define how many times do you want to try to publish a file to each service configured below. Default value is 3 times and the maximum number you can use is 6.")?></small>
164 </th>
165 <td valign="top"><input style="width:60px;" type="text" name="attemps" value="<?php if (isset($options['attemps'])) { echo $options['attemps']; } ?>" id="attemps"/>
166 </td>
167 </tr>
168
169<!-- Service Settings -->
170 <?php foreach ($options['services'] as $service) {
171 $settings = get_option("webtv_".$service);
172 if (isset($settings['service_url'])) {
173 $service_name = $settings['service_url'];
174 unset($settings['service_url']);
175 }
176 ?>
177 <tr>
178 <th>
179 <label for="<?=$service_name?>"><strong><?=_("Publish to")?> <?=$service_name?>:</strong></label><br/>
180 <small><?=_("Insert your account settings, all the fields are required.")?></small>
181 </th>
182 <td valign="top">
183 <select name="service[<?=$service?>][enabled]">
184 <?php
185 $yes = "selected";
186 if (!$settings['enabled']) {
187 $yes = ""; $no = "selected";
188 }
189 unset($settings['enabled']);
190 ?>
191 <option <?=$no?> label="no" value="false">No</option>
192 <option <?=$yes?> label="yes" value="true">Yes</option>
193 </select><br/>
194 <?php
195 $extras = get_option("webtv_".$service."_extras");
196 if ($extras) {
197 foreach ($extras as $type => $extraoptions) { ?>
198 <select name="service[<?=$service?>][<?=$type?>]">
199 <?php foreach($extraoptions as $idextra => $valueextra) {
200 if ((isset($settings[$type])) && ($idextra == $settings[$type])) { $selected = "selected"; } else $selected = ""; ?>
201 <option <?=$selected?> label="<?=$valueextra?>" value="<?=$idextra?>"><?=$valueextra?></option>
202 <?php } ?>
203 </select>
204 <?php
205 echo $type.'<BR/>';
206 unset($settings[$type]);
207 }
208 }
209 foreach ($settings as $option => $value) {
210 $type = "text"; if ($option == "password") { $type = "password"; }
211 ?>
212 <input style="width:100px;" type="<?=$type?>" name="service[<?=$service?>][<?=$option?>]" value="<?=$value?>" id="<?=$option?>_<?=$option?>"/><span class="setting-description"><?=$option?></span><br/>
213 <?php } ?>
214 </td>
215 </tr>
216 <?php } ?>
217<!-- End Service Settings -->
218
219 <tr>
220 <th>
221 <label for="attemps"><strong><?=_("Priority on TemplateTag")?>:</strong></label><br/>
222 <small><?=_("If you want to use the webtv_embedcode() template tag into your template, you need to define the order to display the embed code from the different video providers.")?></small>
223 </th>
224 <td valign="top">
225
226 <table>
227 <tr>
228 <td align="middle">
229 <input type="hidden" name="orderedlist" id="orderedlist" value="" />
230 <?php $j = count($options['services']); ?>
231 <select name="list" id="list" size="<?=$j?>" style="height:<?php echo ($j*2)?>em">
232 <?php
233 foreach ($options['order'] as $order => $service) {
234 ?>
235 <option value="<?=$order?>"><?=$service?></option>
236 <?php } ?>
237 </select><br><br>
238
239 </td>
240
241 <td valign="top">
242 <input type="button" value="↑"
243 onClick="move(document.getElementById('list').selectedIndex,-1)"><br><br>
244 <input type="button" value="↓"
245 onClick="move(document.getElementById('list').selectedIndex,+1)">
246 </td>
247 </tr>
248 </table>
249
250
251 </td>
252 </tr>
253
254
255
256
257
258
259
260 </table>
261 <p style="border:0;" class="submit"><input type="submit" name="submit" value="<?=_("Save")?>" onClick="submitForm()" /></p>
262 </form>
263
264 <h2><?=_("Uninstall")?></h2>
265 <form action="" method="post" id="webtv-cleanup">
266 <?php if ( function_exists('wp_nonce_field') )
267 wp_nonce_field('webtv-cleanup'); ?>
268
269 <table class="form-table" style="width:100%;">
270 <tr>
271 <th scope="row" style="width:400px;" valign="top">
272 <p><label for="uninstall"><?=_("Without leaving any data? Use this option to delete all the data stored on Custom Fields")?></label></p>
273 </th>
274 <td>
275 <input type="checkbox" name="cleanup" id="cleanup"/><?=_("Clean")?><br/>
276 </td>
277 </tr>
278 </table>
279 <p style="border:0;" class="submit"><input type="submit" name="cleanupsubmit" value="<?=_("Clean Up!")?>" /></p>
280 </form>
281
282
283 </div>
284 <?php
285 }
286
287 private function webtv_is_admin_page($names) {
288 foreach ( $names as $url )
289 if ( FALSE !== stripos($_SERVER['SCRIPT_NAME'], '/wp-admin/'.$url) )
290 return true;
291
292 return false;
293 }
294
295 function orderlist_js() {
296
297 ?>
298 <script type="text/javascript">
299 /* <![CDATA[ */
300
301 function move(index,to) {
302 var list = document.getElementById('list');
303 var total = list.options.length-1;
304 if (index == -1) return false;
305 if (to == +1 && index == total) return false;
306 if (to == -1 && index == 0) return false;
307 var items = new Array;
308 var values = new Array;
309 for (i = total; i >= 0; i--) {
310 items[i] = list.options[i].text;
311 values[i] = list.options[i].value;
312 }
313
314 for (i = total; i >= 0; i--) {
315 if (index == i) {
316 list.options[i + to] = new Option(items[i],values[i + to], 0, 1);
317 list.options[i] = new Option(items[i + to], values[i]);
318 i--;
319 } else {
320 list.options[i] = new Option(items[i], values[i]);
321 }
322 }
323
324 list.focus();
325 }
326
327 function submitForm() {
328 var list = document.getElementById('list');
329 var orderedlist = document.getElementById('orderedlist');
330
331 for (i = 0; i <= list.options.length-1; i++) {
332 orderedlist.value += list.options[i].text;
333 if (i != list.options.length-1) orderedlist.value += "|";
334 }
335 document.getElementById('sendform').submit();
336 }
337 /* ]]> */
338 </script>
339
340 <?php
341 if ( $this->webtv_is_admin_page(array('post.php', 'post-new.php', 'page.php', 'page-new.php')) ) {
342 $url = get_option('siteurl');
343 $url .= '/wp-content/plugins/'. dirname(plugin_basename(__FILE__)).'/includes/';
344 wp_enqueue_script('webtv-insert',$url. 'webtvhandlers.js',array('swfupload') );
345 global $post_ID, $temp_ID;
346 $post_id = (int) (0 == $post_ID ? $temp_ID : $post_ID);
347 $maxsize = $this->return_formatbytes(ini_get('post_max_size'));
348 ?>
349 <script type="text/javascript">
350 var swfu;
351
352 window.onload = function load_swfupload() {
353
354 var settings = {
355 flash_url : "<?php echo get_settings('siteurl') . '/wp-includes/js/swfupload/swfupload.swf'?>",
356 upload_url: "<?php echo $url . 'upload.php'?>",
357 post_params: { "auth_cookie" : "<?php if ( is_ssl() ) echo $_COOKIE[SECURE_AUTH_COOKIE]; else echo $_COOKIE[AUTH_COOKIE]; ?>",
358 "_wpnonce" : "<?php echo wp_create_nonce('webtv-upload'); ?>",
359 "id" : "<?=$post_id?>" },
360 file_size_limit : "<?=$maxsize; ?>",
361 file_types : "*.mp4;*.flv;*.mpg;*.mpeg;*.mov;*.avi;*.3gp;*.wmv;*.m4v;*.qt;*.mpe;*.f4v",
362 file_types_description : "Video Files",
363 file_upload_limit : 5,
364 //custom_settings : {
365 //progressTarget : "fsUploadProgress",
366 //cancelButtonId : "btnCancel"
367 //},
368 debug: false,
369
370 // Button settings
371 button_image_url: "<?php echo $url . 'SmallSpyGlassWithTransperancy_17x18.png'?>",
372 button_placeholder_id: "spanButtonPlaceHolder",
373 button_width: 140,
374 button_height: 19,
375 button_text : '<span class="button">Select Video <span class="buttonSmall">(<?= $maxsize; ?> Max)</span></span>',
376 button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }',
377 button_text_top_padding: 0,
378 button_text_left_padding: 14,
379 button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
380 button_cursor: SWFUpload.CURSOR.HAND,
381 //handlers
382 file_dialog_complete_handler : webtvfileDialogComplete,
383 upload_start_handler : webtvuploadStart,
384 upload_progress_handler : webtvuploadProgress,
385 upload_error_handler : webtvuploadError,
386 upload_success_handler : webtvuploadSuccess,
387 upload_complete_handler : webtvuploadComplete,
388
389 };
390
391 swfu = new SWFUpload(settings);
392 };
393
394 </script>
395
396 <?php
397
398 }
399 }
400
401 function return_formatbytes($val) {
402 $val = trim($val);
403 $last = strtolower(substr($val, -1));
404 $val = substr($val,0,-1);
405 switch($last) {
406 // The 'G' modifier is available since PHP 5.1.0
407 case 'g':
408 $val .= ' GB';
409 break;
410 case 'm':
411 $val .= ' MB';
412 break;
413 case 'k':
414 $val .= ' KB';
415 break;
416 }
417
418 return $val;
419 }
420
421
422}
423
424?>
Note: See TracBrowser for help on using the repository browser.