1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Public Piwigo WordPress Widget |
---|
4 | Version: auto |
---|
5 | Description: Public Piwigo WordPress Widget (PW^2) is a WordPress 2.8 widget, it links a public picture in your Piwigo gallery (<a href="http://piwigo.org/">Piwigo</a>). In other words, it's a WordPress Sidebar Widget with some available public pictures in your Piwigo gallery as a prereq. |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid= |
---|
7 | Author: VDigital |
---|
8 | Author URI: http://www.vdigital.org/ |
---|
9 | */ |
---|
10 | if (defined('PHPWG_ROOT_PATH')) return; |
---|
11 | |
---|
12 | class Public_Piwigo_WordPress_Widget extends WP_Widget |
---|
13 | { |
---|
14 | function Public_Piwigo_WordPress_Widget(){ |
---|
15 | $widget_ops = array('classname' => 'Public_Piwigo_WordPress_Widget', |
---|
16 | 'description' => __( "Adds a thumbnail and its link (to the picture) inside your blog sidebar.") ); |
---|
17 | $control_ops = array('width' => 300, 'height' => 300); |
---|
18 | $this->WP_Widget('Public_Piwigo_WordPress_Widget', 'Public Piwigo WordPress Widget', $widget_ops, $control_ops); |
---|
19 | } |
---|
20 | |
---|
21 | function widget($args, $gallery){ |
---|
22 | global $wpdb; |
---|
23 | extract($args); |
---|
24 | $title = apply_filters('widget_title', empty($gallery['title']) ? ' ' : $gallery['title']); |
---|
25 | $piwigo = empty($gallery['piwigo']) ? '' : $gallery['piwigo']; |
---|
26 | $piwigo_url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $piwigo ; |
---|
27 | if (!empty($gallery['external'])) $piwigo_url = $gallery['external']; |
---|
28 | if (substr($piwigo_url,-1)!='/') $piwigo_url .= '/'; |
---|
29 | $options = ''; |
---|
30 | if (!empty($gallery['category'])) $options = '&cat_id=' . intval($gallery['category']); |
---|
31 | |
---|
32 | $from = empty($gallery['from']) ? '12' : intval($gallery['from']); |
---|
33 | $r = (array) $wpdb->get_results('SELECT date_sub( date( now( ) ) , INTERVAL ' . $from . ' MONTH ) as begin'); |
---|
34 | $from = $r[0]->begin; |
---|
35 | if (!empty($gallery['from'])) $options .= '&f_min_date_created=' . $from; |
---|
36 | |
---|
37 | $divclass = empty($gallery['divclass']) ? '' : ' class="' . $gallery['divclass'] .'"'; |
---|
38 | $class = empty($gallery['class']) ? '' : ' class="' . $gallery['class'] .'"'; |
---|
39 | |
---|
40 | echo $before_widget; |
---|
41 | if ( $title ) echo $before_title . $title . $after_title; |
---|
42 | |
---|
43 | # Make the Piwigo link |
---|
44 | $response = file_get_contents( $piwigo_url . 'ws.php?method=pwg.categories.getImages&format=php&per_page=1' |
---|
45 | . $options . '&recursive=true&order=random&f_with_thumbnail=true'); |
---|
46 | $thumbc = unserialize($response); |
---|
47 | if ($thumbc["stat"] == 'ok') { |
---|
48 | $picture = $thumbc["result"]["images"]["_content"][0]; |
---|
49 | echo '<div' . $divclass . '><a title="' . $title . '" href="' . $piwigo_url . 'picture.php?/' . $picture['id'] . '"><img ' |
---|
50 | . $class . ' src="' . $picture['tn_url'] . '" alt="" /></a></div>'; |
---|
51 | } |
---|
52 | |
---|
53 | echo $after_widget; |
---|
54 | } |
---|
55 | |
---|
56 | function update($new_gallery, $old_gallery){ |
---|
57 | $gallery = $old_gallery; |
---|
58 | $gallery['title'] = strip_tags(stripslashes($new_gallery['title'])); |
---|
59 | $gallery['piwigo'] = strip_tags(stripslashes($new_gallery['piwigo'])); |
---|
60 | $gallery['external'] = strip_tags(stripslashes($new_gallery['external'])); |
---|
61 | $gallery['category'] = intval(strip_tags(stripslashes($new_gallery['category']))); |
---|
62 | $gallery['from'] = intval(strip_tags(stripslashes($new_gallery['from']))); |
---|
63 | $gallery['divclass'] = strip_tags(stripslashes($new_gallery['divclass'])); |
---|
64 | $gallery['class'] = strip_tags(stripslashes($new_gallery['class'])); |
---|
65 | |
---|
66 | return $gallery; |
---|
67 | } |
---|
68 | |
---|
69 | function form($gallery){ |
---|
70 | //Defaults |
---|
71 | $gallery = wp_parse_args( (array) $gallery, array('title'=>__('Random picture'), |
---|
72 | 'piwigo'=>'piwigo', 'external'=>'', 'category'=>0, 'from'=> 12, 'divclass'=>'', 'class'=>'', ) ); |
---|
73 | |
---|
74 | $title = htmlspecialchars($gallery['title']); |
---|
75 | $piwigo = htmlspecialchars($gallery['piwigo']); |
---|
76 | $external = htmlspecialchars($gallery['external']); |
---|
77 | $category = intval($gallery['category']); |
---|
78 | $from = intval($gallery['from']); |
---|
79 | $divclass = htmlspecialchars($gallery['divclass']); |
---|
80 | $class = htmlspecialchars($gallery['class']); |
---|
81 | |
---|
82 | # Options |
---|
83 | echo '<p style="text-align:right;"><label for="' . $this->get_field_name('title') . '">' . __('Public Piwigo WordPress Widget Title:') |
---|
84 | . ' <input style="width: 250px;" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') |
---|
85 | . '" type="text" value="' . $title . '" /></label></p>'; |
---|
86 | # Piwigo directory |
---|
87 | echo '<p style="text-align:right;"><label for="' . $this->get_field_name('piwigo') . '">' . __('Your Piwigo directory (local):') |
---|
88 | . ' <input style="width: 200px;" id="' . $this->get_field_id('piwigo') . '" name="' . $this->get_field_name('piwigo') |
---|
89 | . '" type="text" value="' . $piwigo . '" /></label></p>'; |
---|
90 | # Optional parameters |
---|
91 | echo '<h5>' . __('Piwigo optional parameters') . '</h5>'; |
---|
92 | # External website |
---|
93 | echo '<p style="text-align:right;"><label for="' . $this->get_field_name('external') . '">' . __('Piwigo gallery URL (external):') |
---|
94 | . ' <input style="width: 200px;" id="' . $this->get_field_id('external') . '" name="' . $this->get_field_name('external') |
---|
95 | . '" type="text" value="' . $external . '" /></label></p>'; |
---|
96 | # Category |
---|
97 | echo '<p style="text-align:right;"><label for="' . $this->get_field_name('category') . '">' . __('Piwigo category id (0=all):') |
---|
98 | . ' <input style="width: 200px;" id="' . $this->get_field_id('category') . '" name="' . $this->get_field_name('category') |
---|
99 | . '" type="text" value="' . $category . '" /></label></p>'; |
---|
100 | # from |
---|
101 | echo '<p style="text-align:right;"><label for="' . $this->get_field_name('from') . '">' . __('for X months (empty=all):') |
---|
102 | . ' <input style="width: 200px;" id="' . $this->get_field_id('from') . '" name="' . $this->get_field_name('from') |
---|
103 | . '" type="text" value="' . $from . '" /></label></p>'; |
---|
104 | # divclass |
---|
105 | echo '<p style="text-align:right;"><label for="' . $this->get_field_name('divclass') . '">' . __('CSS DIV class:') |
---|
106 | . ' <input style="width: 200px;" id="' . $this->get_field_id('divclass') . '" name="' . $this->get_field_name('divclass') |
---|
107 | . '" type="text" value="' . $divclass . '" /></label></p>'; |
---|
108 | # class |
---|
109 | echo '<p style="text-align:right;"><label for="' . $this->get_field_name('class') . '">' . __('CSS IMG class:') |
---|
110 | . ' <input style="width: 200px;" id="' . $this->get_field_id('class') . '" name="' . $this->get_field_name('class') |
---|
111 | . '" type="text" value="' . $class . '" /></label></p>'; |
---|
112 | } |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | /** |
---|
117 | * Register Public Piwigo WordPress Widget |
---|
118 | */ |
---|
119 | function Public_Piwigo_WordPress_Widget_Init() { |
---|
120 | register_widget('Public_Piwigo_WordPress_Widget'); |
---|
121 | } |
---|
122 | add_action('widgets_init', 'Public_Piwigo_WordPress_Widget_Init'); |
---|
123 | ?> |
---|