Changeset 4055


Ignore:
Timestamp:
Oct 18, 2009, 12:03:27 PM (11 years ago)
Author:
vdigital
Message:

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

Candidate release.
TODO: readme.txt, .po files, the blog page.

Location:
extensions/Public_Piwigo_WordPress_Widget
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Public_Piwigo_WordPress_Widget/Public_WP_Piwigo_Widget.php

    r4039 r4055  
    22/*
    33Plugin Name: Public Piwigo WordPress Widget
    4 Version: auto
     4Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
    55Description: 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=
     6Version: 1.00
    77Author: VDigital
    8 Author URI: http://www.vdigital.org/
     8Author URI: http://www.vdigital.org/sharing/
    99*/
    10 if (defined('PHPWG_ROOT_PATH')) return;
     10if (defined('PHPWG_ROOT_PATH')) return; /* Avoid Automatic install under Piwigo */
     11/*  Copyright 2009  VDigital  (email : vpiwigo[at]gmail[dot]com)
     12
     13    This program is free software; you can redistribute it and/or modify
     14    it under the terms of the GNU General Public License as published by
     15    the Free Software Foundation; either version 2 of the License, or
     16    (at your option) any later version.
     17
     18    This program is distributed in the hope that it will be useful,
     19    but WITHOUT ANY WARRANTY; without even the implied warranty of
     20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     21    GNU General Public License for more details.
     22
     23    You should have received a copy of the GNU General Public License
     24    along with this program; if not, write to the Free Software
     25    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     26*/
     27if (!defined('PPW_NAME')) define('PPW_NAME','Public Piwigo WordPress ');
     28if (!defined('PPW_PFX')) define('PPW_PFX','Public_Piwigo_WordPress_');
    1129
    1230class Public_Piwigo_WordPress_Widget extends WP_Widget
    1331{
    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']) ? '&nbsp;' : $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 
     32        function Public_Piwigo_WordPress_Widget(){
     33                $widget_ops = array('classname' => PPW_PFX . 'Widget',
     34                        'description' => __( "Adds a thumbnail and its link (to the picture) inside your blog sidebar.") );
     35                $control_ops = array('width' => 300, 'height' => 300);
     36                $this->WP_Widget(PPW_PFX . 'Widget', PPW_NAME . 'Widget', $widget_ops, $control_ops);
     37        }
     38        // Code generator
     39        function widget($args, $gallery){
     40                include 'Public_WP_Piwigo_code.php';
     41        }
     42        function update($new_gallery, $old_gallery){
     43                $gallery = $old_gallery;
     44                $gallery['title'] = strip_tags(stripslashes($new_gallery['title']));
     45                $gallery['thumbnail'] = (strip_tags(stripslashes($new_gallery['thumbnail'])) == 'true') ? 'true':'false';
     46                $gallery['piwigo'] = strip_tags(stripslashes($new_gallery['piwigo']));
     47                $gallery['external'] = strip_tags(stripslashes($new_gallery['external']));
     48                $gallery['number'] = intval(strip_tags(stripslashes($new_gallery['number'])));
     49                $gallery['category'] = intval(strip_tags(stripslashes($new_gallery['category'])));
     50                $gallery['from'] = intval(strip_tags(stripslashes($new_gallery['from'])));
     51                $gallery['divclass'] = strip_tags(stripslashes($new_gallery['divclass']));
     52                $gallery['class'] = strip_tags(stripslashes($new_gallery['class']));
     53                $gallery['most_visited'] = (strip_tags(stripslashes($new_gallery['most_visited'])) == 'true') ? 'true':'false';
     54                $gallery['best_rated'] = (strip_tags(stripslashes($new_gallery['best_rated'])) == 'true') ? 'true':'false';
     55                $gallery['most_commented'] = (strip_tags(stripslashes($new_gallery['most_commented'])) == 'true') ? 'true':'false';
     56                $gallery['random'] = (strip_tags(stripslashes($new_gallery['random'])) == 'true') ? 'true':'false';
     57                $gallery['recent_pics'] = (strip_tags(stripslashes($new_gallery['recent_pics'])) == 'true') ? 'true':'false';
     58                $gallery['calendar'] = (strip_tags(stripslashes($new_gallery['calendar'])) == 'true') ? 'true':'false';
     59                $gallery['tags'] = (strip_tags(stripslashes($new_gallery['tags'])) == 'true') ? 'true':'false';
     60                $gallery['comments'] = (strip_tags(stripslashes($new_gallery['comments'])) == 'true') ? 'true':'false';
     61                $gallery['mbcategories'] = (strip_tags(stripslashes($new_gallery['mbcategories'])) == 'true') ? 'true':'false';
     62                return $gallery;
     63        }
     64        function form($gallery){
     65                // Options
     66                include 'Public_WP_Piwigo_options.php';
     67        }
    11468}
    11569
    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');
     70// Register
     71function Public_Piwigo_WordPress_Widget_Init() {
     72                        register_widget(PPW_PFX . 'Widget');
     73}
     74add_action('widgets_init', PPW_PFX . 'Widget_Init');
    12375?>
Note: See TracChangeset for help on using the changeset viewer.