PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/wp-content/plugins/nextgen-gallery/widgets/media-rss-widget.php

https://bitbucket.org/dkrzos/phc
PHP | 140 lines | 95 code | 30 blank | 15 comment | 5 complexity | 0105abc228f718c962ce2fbaa830327a MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * Widget to show Media RSS icons and links
  4. *
  5. * @author Vincent Prat
  6. */
  7. // Stop direct call
  8. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
  9. class nggMediaRssWidget extends WP_Widget {
  10. var $options;
  11. /**
  12. * Constructor
  13. */
  14. function nggMediaRssWidget() {
  15. $widget_ops = array('classname' => 'ngg_mrssw', 'description' => __( 'Widget that displays Media RSS links for NextGEN Gallery.', 'nggallery') );
  16. $this->WP_Widget('ngg-mrssw', __('NextGEN Media RSS', 'nggallery'), $widget_ops);
  17. }
  18. function widget( $args, $instance ) {
  19. extract( $args );
  20. $ngg_options = nggGallery::get_option('ngg_options');
  21. $title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title'], $instance, $this->id_base);
  22. $show_global_mrss = $instance['show_global_mrss'];
  23. $show_icon = $instance['show_icon'];
  24. $mrss_text = stripslashes($instance['mrss_text']);
  25. $mrss_title = strip_tags(stripslashes($instance['mrss_title']));
  26. echo $before_widget;
  27. echo $before_title . $title . $after_title;
  28. echo "<ul class='ngg-media-rss-widget'>\n";
  29. if ($show_global_mrss) {
  30. echo " <li>";
  31. echo $this->get_mrss_link(nggMediaRss::get_mrss_url(), $show_icon,
  32. stripslashes($mrss_title), stripslashes($mrss_text),
  33. $ngg_options['usePicLens']);
  34. echo "</li>\n";
  35. }
  36. echo "</ul>\n";
  37. echo $after_widget;
  38. }
  39. function update( $new_instance, $old_instance ) {
  40. $instance = $old_instance;
  41. $instance['title'] = strip_tags($new_instance['title']);
  42. $instance['show_global_mrss'] = $new_instance['show_global_mrss'];
  43. $instance['show_icon'] = $new_instance['show_icon'];
  44. $instance['mrss_text'] = $new_instance['mrss_text'];
  45. $instance['mrss_title'] = $new_instance['mrss_title'];
  46. return $instance;
  47. }
  48. function form( $instance ) {
  49. //Defaults
  50. $instance = wp_parse_args( (array) $instance, array(
  51. 'title' => 'Media RSS',
  52. 'show_global_mrss' => true,
  53. 'mrss_text' => __('Media RSS', 'nggallery'),
  54. 'mrss_title' => __('Link to the main image feed', 'nggallery'),
  55. 'show_icon' => true ) );
  56. $title = esc_attr( $instance['title'] );
  57. $mrss_text = esc_attr( $instance['mrss_text'] );
  58. $mrss_title = esc_attr( $instance['mrss_title'] );
  59. // The widget form
  60. ?>
  61. <p>
  62. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title :','nggallery'); ?><br />
  63. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title');?>" type="text" value="<?php echo $title; ?>" />
  64. </label>
  65. </p>
  66. <p>
  67. <label for="<?php echo $this->get_field_id('show_icon'); ?>">
  68. <input id="<?php echo $this->get_field_id('show_icon'); ?>" name="<?php echo $this->get_field_name('show_icon'); ?>" type="checkbox" value="1" <?php checked(true , $instance['show_icon']); ?> />
  69. <?php _e('Show Media RSS icon', 'nggallery'); ?>
  70. </label>
  71. </p>
  72. <p>
  73. <label for="<?php echo $this->get_field_id('show_global_mrss'); ?>">
  74. <input id="<?php echo $this->get_field_id('show_global_mrss'); ?>" name="<?php echo $this->get_field_name('show_global_mrss'); ?>" type="checkbox" value="1" <?php checked(true , $instance['show_global_mrss']); ?> /> <?php _e('Show the Media RSS link', 'nggallery'); ?>
  75. </label>
  76. </p>
  77. <p>
  78. <label for="<?php echo $this->get_field_id('mrss_text'); ?>"><?php _e('Text for Media RSS link:', 'nggallery'); ?><br />
  79. <input class="widefat" id="<?php echo $this->get_field_id('mrss_text'); ?>" name="<?php echo $this->get_field_name('mrss_text'); ?>" type="text" value="<?php echo $mrss_text; ?>" /></label>
  80. </label>
  81. </p>
  82. <p>
  83. <label for="<?php echo $this->get_field_id('mrss_title'); ?>"><?php _e('Tooltip text for Media RSS link:', 'nggallery'); ?><br />
  84. <input class="widefat" id="<?php echo $this->get_field_id('mrss_title'); ?>" name="<?php echo $this->get_field_name('mrss_title'); ?>" type="text" value="<?php echo $mrss_title; ?>" /></label>
  85. </label>
  86. </p>
  87. <?php
  88. }
  89. /**
  90. * Get a link to a Media RSS
  91. */
  92. function get_mrss_link($mrss_url, $show_icon = true, $title, $text, $use_piclens) {
  93. $out = '';
  94. if ($show_icon) {
  95. $icon_url = NGGALLERY_URLPATH . 'images/mrss-icon.gif';
  96. $out .= "<a href='$mrss_url' title='$title' class='ngg-media-rss-link'" . ($use_piclens ? ' onclick="PicLensLite.start({feedUrl:\'' . $mrss_url . '\'}); return false;"' : "") . " >";
  97. $out .= "<img src='$icon_url' alt='MediaRSS Icon' title='" . (!$use_piclens ? $title : __('[View with PicLens]','nggallery')). "' class='ngg-media-rss-icon' />";
  98. $out .= "</a> ";
  99. }
  100. if ($text != '') {
  101. $out .= "<a href='$mrss_url' title='$title' class='ngg-media-rss-link'>";
  102. $out .= $text;
  103. $out .= "</a>";
  104. }
  105. return $out;
  106. }
  107. } // class nggMediaRssWidget
  108. // let's start it
  109. add_action('widgets_init', create_function('', 'return register_widget("nggMediaRssWidget");'));
  110. ?>