Changeset 4039


Ignore:
Timestamp:
Oct 15, 2009, 12:20:17 AM (11 years ago)
Author:
vdigital
Message:

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

Piwigo optional parameters:
External gallery URL / category id selection / Recent period in months
CSS DIV and/or IMG class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Public_Piwigo_WordPress_Widget/Public_WP_Piwigo_Widget.php

    r4031 r4039  
    2020
    2121    function widget($args, $gallery){
     22      global $wpdb;
    2223      extract($args);
    2324      $title = apply_filters('widget_title', empty($gallery['title']) ? ' ' : $gallery['title']);
     
    2930      if (!empty($gallery['category'])) $options = '&cat_id=' . intval($gallery['category']);
    3031
     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
    3140      echo $before_widget;
    3241      if ( $title ) echo $before_title . $title . $after_title;
    3342
    3443      # Make the Piwigo link
    35       $response = file_get_contents( $piwigo_url . 'ws.php?method=pwg.categories.getImages&format=php'
     44      $response = file_get_contents( $piwigo_url . 'ws.php?method=pwg.categories.getImages&format=php&per_page=1'
    3645        . $options . '&recursive=true&order=random&f_with_thumbnail=true');
    3746      $thumbc = unserialize($response);
    3847      if ($thumbc["stat"] == 'ok') {
    3948          $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>';
     49          echo '<div' . $divclass . '><a title="' . $title . '" href="' . $piwigo_url . 'picture.php?/' . $picture['id'] . '"><img '
     50            . $class . ' src="' . $picture['tn_url'] . '" alt="" /></a></div>';
    4151      }
    4252
     
    4959      $gallery['piwigo'] = strip_tags(stripslashes($new_gallery['piwigo']));
    5060      $gallery['external'] = strip_tags(stripslashes($new_gallery['external']));
    51       $gallery['category'] = strip_tags(stripslashes($new_gallery['category']));
     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']));
    5265
    5366    return $gallery;
     
    5770      //Defaults
    5871      $gallery = wp_parse_args( (array) $gallery, array('title'=>__('Random picture'),
    59         'piwigo'=>'piwigo', 'external'=>'', 'category'=>0, ) );
     72        'piwigo'=>'piwigo', 'external'=>'', 'category'=>0, 'from'=> 12, 'divclass'=>'', 'class'=>'', ) );
    6073
    6174      $title = htmlspecialchars($gallery['title']);
     
    6376      $external = htmlspecialchars($gallery['external']);
    6477      $category = intval($gallery['category']);
     78      $from = intval($gallery['from']);
     79      $divclass = htmlspecialchars($gallery['divclass']);
     80      $class = htmlspecialchars($gallery['class']);
    6581
    6682      # Options
     
    7288      . ' <input style="width: 200px;" id="' . $this->get_field_id('piwigo') . '" name="' . $this->get_field_name('piwigo')
    7389      . '" type="text" value="' . $piwigo . '" /></label></p>';
     90      # Optional parameters
     91      echo '<h5>' . __('Piwigo optional parameters') . '</h5>';
    7492      # External website
    75       echo '<p style="text-align:right;"><label for="' . $this->get_field_name('external') . '">' . __('Optional Piwigo gallery URL (external):')
     93      echo '<p style="text-align:right;"><label for="' . $this->get_field_name('external') . '">' . __('Piwigo gallery URL (external):')
    7694      . ' <input style="width: 200px;" id="' . $this->get_field_id('external') . '" name="' . $this->get_field_name('external')
    7795      . '" type="text" value="' . $external . '" /></label></p>';
    7896      # Category
    79       echo '<p style="text-align:right;"><label for="' . $this->get_field_name('category') . '">' . __('Select a category id (empty = all):')
     97      echo '<p style="text-align:right;"><label for="' . $this->get_field_name('category') . '">' . __('Piwigo category id (0=all):')
    8098      . ' <input style="width: 200px;" id="' . $this->get_field_id('category') . '" name="' . $this->get_field_name('category')
    8199      . '" type="text" value="' . $category . '" /></label></p>';
    82      }
     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    }
    83113
    84114}
Note: See TracChangeset for help on using the changeset viewer.