source: extensions/Public_Piwigo_WordPress_Widget/Public_WP_Piwigo_Widget.php @ 4031

Last change on this file since 4031 was 4031, checked in by vdigital, 15 years ago

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

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1<?php
2/*
3Plugin Name: Public Piwigo WordPress Widget
4Version: auto
5Description: 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.
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
7Author: VDigital
8Author URI: http://www.vdigital.org/
9*/
10if (defined('PHPWG_ROOT_PATH')) return;
11
12class 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      extract($args);
23      $title = apply_filters('widget_title', empty($gallery['title']) ? '&nbsp;' : $gallery['title']);
24      $piwigo = empty($gallery['piwigo']) ? '' : $gallery['piwigo'];
25      $piwigo_url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $piwigo ;
26      if (!empty($gallery['external'])) $piwigo_url = $gallery['external'];
27      if (substr($piwigo_url,-1)!='/') $piwigo_url .= '/';
28      $options = '';
29      if (!empty($gallery['category'])) $options = '&cat_id=' . intval($gallery['category']);
30
31      echo $before_widget;
32      if ( $title ) echo $before_title . $title . $after_title;
33
34      # Make the Piwigo link
35      $response = file_get_contents( $piwigo_url . 'ws.php?method=pwg.categories.getImages&format=php'
36        . $options . '&recursive=true&order=random&f_with_thumbnail=true');
37      $thumbc = unserialize($response);
38      if ($thumbc["stat"] == 'ok') {
39          $picture = $thumbc["result"]["images"]["_content"][0];
40          echo '<a title="' . $title . '" href="' . $piwigo_url . 'picture.php?/' . $picture['id'] . '"><img src="' . $picture['tn_url'] . '" alt="" /></a>';
41      }
42
43      echo $after_widget;
44    }
45
46    function update($new_gallery, $old_gallery){
47      $gallery = $old_gallery;
48      $gallery['title'] = strip_tags(stripslashes($new_gallery['title']));
49      $gallery['piwigo'] = strip_tags(stripslashes($new_gallery['piwigo']));
50      $gallery['external'] = strip_tags(stripslashes($new_gallery['external']));
51      $gallery['category'] = strip_tags(stripslashes($new_gallery['category']));
52
53    return $gallery;
54    }
55
56    function form($gallery){
57      //Defaults
58      $gallery = wp_parse_args( (array) $gallery, array('title'=>__('Random picture'), 
59        'piwigo'=>'piwigo', 'external'=>'', 'category'=>0, ) );
60
61      $title = htmlspecialchars($gallery['title']);
62      $piwigo = htmlspecialchars($gallery['piwigo']);
63      $external = htmlspecialchars($gallery['external']);
64      $category = intval($gallery['category']);
65
66      # Options
67      echo '<p style="text-align:right;"><label for="' . $this->get_field_name('title') . '">' . __('Public Piwigo WordPress Widget Title:') 
68      . ' <input style="width: 250px;" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title')
69      . '" type="text" value="' . $title . '" /></label></p>';
70      # Piwigo directory
71      echo '<p style="text-align:right;"><label for="' . $this->get_field_name('piwigo') . '">' . __('Your Piwigo directory (local):') 
72      . ' <input style="width: 200px;" id="' . $this->get_field_id('piwigo') . '" name="' . $this->get_field_name('piwigo')
73      . '" type="text" value="' . $piwigo . '" /></label></p>';
74      # External website
75      echo '<p style="text-align:right;"><label for="' . $this->get_field_name('external') . '">' . __('Optional Piwigo gallery URL (external):') 
76      . ' <input style="width: 200px;" id="' . $this->get_field_id('external') . '" name="' . $this->get_field_name('external')
77      . '" type="text" value="' . $external . '" /></label></p>';
78      # Category
79      echo '<p style="text-align:right;"><label for="' . $this->get_field_name('category') . '">' . __('Select a category id (empty = all):') 
80      . ' <input style="width: 200px;" id="' . $this->get_field_id('category') . '" name="' . $this->get_field_name('category')
81      . '" type="text" value="' . $category . '" /></label></p>';
82     }
83
84}
85
86/**
87  * Register Public Piwigo WordPress Widget
88  */
89  function Public_Piwigo_WordPress_Widget_Init() {
90        register_widget('Public_Piwigo_WordPress_Widget');
91  }
92  add_action('widgets_init', 'Public_Piwigo_WordPress_Widget_Init');
93?>
Note: See TracBrowser for help on using the repository browser.