source: extensions/Public_Piwigo_WordPress_Widget/Public_WP_Piwigo_code.php @ 4082

Last change on this file since 4082 was 4082, checked in by vdigital, 14 years ago

[Public Piwigo WordPress Widget] Don't make any mistake it is a WordPress sidebar widget!

Set release 1.01
Co-Authors,
Link bug with some theme: solved

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1<?php
2if (defined('PHPWG_ROOT_PATH')) return; /* Avoid Automatic install under Piwigo */
3if (!defined('PPW_NAME')) return; /* Avoid Direct call */
4
5global $wpdb; /* Need for recent thumbnail access */
6extract($args);
7
8$title = apply_filters('widget_title', empty($gallery['title']) ? '&nbsp;' : $gallery['title']);
9if ( $title ) $title = $before_title . $title . $after_title;
10
11$piwigo = empty($gallery['piwigo']) ? '' : $gallery['piwigo'];
12$piwigo_url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $piwigo ;
13if (!empty($gallery['external'])) $piwigo_url = $gallery['external'];
14if (substr($piwigo_url,-1)!='/') $piwigo_url .= '/';
15
16$thumbnail = empty($gallery['thumbnail']) ? '' : $gallery['thumbnail'];
17
18$options = '';
19$number = empty($gallery['number']) ? 1 : intval($gallery['number']);
20$options .= '&per_page=' . intval($gallery['number']);
21if (!empty($gallery['category'])) $options .= '&cat_id=' . intval($gallery['category']);
22$from = empty($gallery['from']) ? '12' : intval($gallery['from']);
23$r = (array) $wpdb->get_results('SELECT date_sub( date( now( ) ) , INTERVAL ' . $from . ' MONTH ) as begin');
24$from = $r[0]->begin;
25if (!empty($gallery['from'])) $options .= '&f_min_date_created=' . $from;
26
27$PW2_divclass = empty($gallery['divclass']) ? '' : (' class="' . $gallery['divclass'] .'"');
28$PW2_class = empty($gallery['class']) ? '' : (' class="' . $gallery['class'] .'"');
29$mbcategories = empty($gallery['mbcategories']) ? '' : $gallery['mbcategories'];
30$most_visited = empty($gallery['most_visited']) ? '' : $gallery['most_visited'];
31$best_rated = empty($gallery['best_rated']) ? '' : $gallery['best_rated'];
32$most_commented = empty($gallery['most_commented']) ? '' : $gallery['most_commented'];
33$random = empty($gallery['random']) ? '' : $gallery['random'];
34$recent_pics = empty($gallery['recent_pics']) ? '' : $gallery['recent_pics'];
35$calendar = empty($gallery['calendar']) ? '' : $gallery['calendar'];
36$tags = empty($gallery['tags']) ? '' : $gallery['tags'];
37$comments = empty($gallery['comments']) ? '' : $gallery['comments'];
38
39echo $before_widget;
40echo $title;
41
42if ($thumbnail == 'true') {
43        // Make the Piwigo link
44        $response = file_get_contents( $piwigo_url 
45                        . 'ws.php?method=pwg.categories.getImages&format=php'
46                        . $options . '&recursive=true&order=random&f_with_thumbnail=true');
47        $thumbc = unserialize($response);
48        if ($thumbc["stat"] == 'ok') {
49                $pictures = $thumbc["result"]["images"]["_content"];
50                foreach ($pictures as $picture) {
51                        echo '<div' . $PW2_divclass . '><a title="' . htmlspecialchars($picture['name']) . '" href="' 
52                                . $piwigo_url . 'picture.php?/' . $picture['id'] . '"><img '
53                                . $PW2_class . ' src="' . $picture['tn_url'] . '" alt="" /></a></div>';
54                }
55        }
56}
57
58if ($mbcategories == 'true') {
59        // Make the Piwigo category list
60        $response = file_get_contents( $piwigo_url 
61                        . 'ws.php?method=pwg.categories.getList&format=php&public=true');
62        $cats = unserialize($response);
63        if ($cats["stat"] == 'ok') {
64                echo '<ul style="clear: both;"><li>' . __('Pictures categories','pwg') . '<ul>';
65                foreach ($cats["result"]["categories"] as $cat) {
66                        echo '<li><a title="' . $cat['name'] . '" href="' . $piwigo_url . 'index.php?category/' . $cat['id'] . '">' . $cat['name'] . '</a></li>';
67                }
68                echo '</ul></li></ul>';
69        }
70}
71
72if ($most_visited == 'true' or $best_rated == 'true' or 
73    $most_commented == 'true' or $random == 'true' or $recent_pics == 'true' or 
74    $calendar == 'true' or $tags == 'true' or $comments == 'true') echo '<ul style="clear: both;">';
75
76if ($most_visited == 'true') 
77        echo '<li><a title="' . __('Most visited','pwg') . '" href="' . $piwigo_url . 'index.php?most_visited' . '">' . __('Most visited','pwg') . '</a></li>';
78
79if ($best_rated == 'true') 
80        echo '<li><a title="' . __('Best rated','pwg') . '" href="' . $piwigo_url . 'index.php?best_rated' . '">' . __('Best rated','pwg') . '</a></li>';
81
82if ($most_commented == 'true') 
83        echo '<li><a title="' . __('Most commented','pwg') . '" href="' . $piwigo_url . 'index.php?most_commented' . '">' . __('Most commented','pwg') . '</a></li>';
84
85if ($random == 'true') 
86        echo '<li><a title="' . __('Random','pwg') . '" href="' . $piwigo_url . 'random.php' . '">' . __('Random','pwg') . '</a></li>';
87
88if ($recent_pics == 'true')
89        echo '<li><a title="' . __('Recent pics','pwg') . '" href="' . $piwigo_url . 'index.php?recent_pics' . '">' . __('Recent pics','pwg') . '</a></li>';
90
91if ($calendar == 'true') 
92        echo '<li><a title="' . __('Calendar','pwg') . '" href="' . $piwigo_url . 'index.php?created-monthly-calendar' . '">' . __('Calendar','pwg') . '</a></li>';
93
94if ($tags == 'true') 
95        echo '<li><a title="' . __('Tags','pwg') . '" href="' . $piwigo_url . 'tags.php' . '">' . __('Tags','pwg') . '</a></li>';
96
97if ($comments == 'true') 
98        echo '<li><a title="' . __('Comments','pwg') . '" href="' . $piwigo_url . 'comments.php' . '">' . __('Comments','pwg') . '</a></li>';
99
100
101if ($most_visited == 'true' or $best_rated == 'true' or 
102    $most_commented == 'true' or $random == 'true' or $recent_pics == 'true' or 
103    $calendar == 'true' or $tags == 'true' or $comments == 'true') echo '</ul>';
104
105echo $after_widget;
106
107?>
Note: See TracBrowser for help on using the repository browser.