Changeset 904231
- Timestamp:
- 04/28/2014 04:51:02 PM (11 years ago)
- Location:
- simple-link-list-widget
- Files:
-
- 20 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
simple-link-list-widget/trunk/readme.txt
r599083 r904231 1 1 === Simple Link List Widget === 2 Contributors: jimmywb , frankieroberto2 Contributors: jimmywb 3 3 Tags: links, list, lists, widget 4 4 Requires at least: 2.8 5 Tested up to: 3. 4.26 Stable tag: 0. 25 Tested up to: 3.9 6 Stable tag: 0.3 7 7 8 8 This plugin makes a widget available which allows you to add a simple link list (bulleted or numbered) to a sidebar. … … 32 32 == Screenshots == 33 33 34 1. Widget editing interface. 34 1. Widget editing interface with closed items. 35 2. Widget editing interface with open item. 35 36 36 37 == Changelog == 38 = 0.3 = 39 * Added drag and drop support 40 * Added the ability to add unlimited items without resaving 41 * Added reverse output option 42 * Added support for Accessibility mode 43 * Added admin interface styles 37 44 38 45 = 0.2 = -
simple-link-list-widget/trunk/simple-link-list-widget.php
r599083 r904231 2 2 /* 3 3 Plugin Name: Simple Link List Widget 4 Description: Enables a link list widget, in which you can display items in an ordered or unordered list. Based on Frankie Roberto's List Widget4 Description: Enables a link list widget, in which you can display items in an ordered or unordered list. 5 5 Author: James Bowles 6 Author URI: http:// mesacc.edu/~jamul767517 Version: 0. 26 Author URI: http://thebowles.org 7 Version: 0.3 8 8 */ 9 9 10 10 class SimpleLinkListWidget extends WP_Widget { 11 12 function SimpleLinkListWidget() {11 12 public function __construct() { 13 13 $widget_ops = array('classname' => 'widget_link_list', 'description' => __('A link list.')); 14 $this->WP_Widget('list', __('Simple Link List'), $widget_ops, $control_ops); 15 } 16 17 function widget( $args, $instance ) { 14 parent::__construct( 15 'list', // Base ID 16 __('Simple Link List'), // Name 17 $widget_ops 18 ); 19 20 add_action('admin_enqueue_scripts', array($this,'sllw_load_scripts')); 21 } 22 23 public function widget( $args, $instance ) { 18 24 extract($args); 19 25 $title = apply_filters('widget_title', empty($instance['title']) ? __('List') : $instance['title']); 20 26 $type = empty($instance['type']) ? 'unordered' : $instance['type'] ; 27 $reverse = isset($instance['reverse']) ? $instance['reverse'] : false; 21 28 $amount = empty($instance['amount']) ? 3 : $instance['amount']; 22 29 23 30 for ($i = 1; $i <= $amount; $i++) { 24 $items[$i] = $instance['item' . $i]; 25 $item_links[$i] = $instance['item_link' . $i]; 26 $item_classes[$i] = $instance['item_class' . $i]; 27 $item_targets[$i] = isset($instance['item_target' . $i]) ? $instance['item_target' . $i] : false; 28 } 29 30 echo $before_widget . $before_title . $title . $after_title; ?> 31 <?php if ($type == "ordered") { echo "<ol ";} else { echo("<ul "); } ?> class="list"> 32 33 <?php foreach ($items as $num => $item) : 34 if (!empty($item)) : 35 if (empty($item_links[$num])) : 36 echo("<li class='" . $item_classes[$num] . "'>" . $item . "</li>"); 37 else : 38 if($item_targets[$num]) : 39 echo("<li class='" . $item_classes[$num] . "'><a href='" . $item_links[$num] . "' target='_blank'>" . $item . "</a></li>"); 40 else : 41 echo("<li class='" . $item_classes[$num] . "'><a href='" . $item_links[$num] . "'>" . $item . "</a></li>"); 42 endif; 43 endif; 31 $items[$i-1] = $instance['item'.$i]; 32 $item_links[$i-1] = $instance['item_link'.$i]; 33 $item_classes[$i-1] = $instance['item_class'.$i]; 34 $item_targets[$i-1] = isset($instance['item_target'.$i]) ? $instance['item_target'.$i] : false; 35 } 36 37 if($reverse){ 38 $items = array_reverse($items); 39 $item_links = array_reverse($item_links); 40 $item_classes = array_reverse($item_classes); 41 $item_targets = array_reverse($item_targets); 42 } 43 44 echo $before_widget . $before_title . $title . $after_title; 45 if ($type == "ordered") { echo "<ol ";} else { echo("<ul "); } ?> class="list"> 46 47 <?php foreach ($items as $num => $item) : 48 if (!empty($item)) : 49 if (empty($item_links[$num])) : 50 echo("<li class='" . $item_classes[$num] . "'>" . $item . "</li>"); 51 else : 52 if($item_targets[$num]) : 53 echo("<li class='" . $item_classes[$num] . "'><a href='" . $item_links[$num] . "' target='_blank'>" . $item . "</a></li>"); 54 else : 55 echo("<li class='" . $item_classes[$num] . "'><a href='" . $item_links[$num] . "'>" . $item . "</a></li>"); 44 56 endif; 45 endforeach; ?> 46 <?php if ($type == "ordered") { echo "</ol>";} else { echo("</ul>"); } ?> 47 <?php 57 endif; 58 endif; 59 endforeach; 60 61 if ($type == "ordered") { echo "</ol>";} else { echo("</ul>"); } 62 48 63 echo $after_widget; 49 64 } 50 65 51 function update( $new_instance, $old_instance) {52 $instance = $old_instance;66 public function update( $new_instance, $old_instance) { 67 //$instance = $old_instance; 53 68 $instance['title'] = strip_tags($new_instance['title']); 54 $instance['title_link'] = $new_instance['title_link']; 55 if (empty($new_instance['item' . $new_instance['new_amount']])){ 56 $instance['amount'] = $new_instance['amount']; 69 $amount = $new_instance['amount']; 70 $new_item = empty($new_instance['new_item']) ? false : strip_tags($new_instance['new_item']); 71 72 if ( isset($new_instance['position1'])) { 73 for($i=1; $i<= $new_instance['amount']; $i++){ 74 if($new_instance['position'.$i] != -1){ 75 $position[$i] = $new_instance['position'.$i]; 76 }else{ 77 $amount--; 78 } 79 } 80 if($position){ 81 asort($position); 82 $order = array_keys($position); 83 if(strip_tags($new_instance['new_item'])){ 84 $amount++; 85 array_push($order, $amount); 86 } 87 } 88 57 89 }else{ 58 $instance['amount'] = $new_instance['new_amount']; 59 } 60 $j=0; //index to skip over blank items 61 for ($i = 1; $i <= $instance['amount']; $i++) { 62 if(empty($new_instance['item' . $i])){ $j++; } 63 $instance['item' . $i] = strip_tags($new_instance['item' . ($j+$i)]); 64 $instance['item_link' . $i] = $new_instance['item_link' . ($j+$i)]; 65 $instance['item_class' . $i] = strip_tags($new_instance['item_class' . ($j+$i)]); 66 $instance['item_target' . $i] = $new_instance['item_target' . ($j+$i)]; 67 } 68 $instance['amount'] = $instance['amount'] - $j; 69 $instance['type'] = $new_instance['type']; 70 90 $order = explode(',',$new_instance['order']); 91 foreach($order as $key => $order_str){ 92 $order[$key] = substr($order_str,-1); 93 } 94 } 95 96 if($order){ 97 foreach ($order as $i => $item_num) { 98 $instance['item'.($i+1)] = empty($new_instance['item'.$item_num]) ? '' : strip_tags($new_instance['item'.$item_num]); 99 $instance['item_link'.($i+1)] = empty($new_instance['item_link'.$item_num]) ? '' : strip_tags($new_instance['item_link'.$item_num]); 100 $instance['item_class'.($i+1)] = empty($new_instance['item_class'.$item_num]) ? '' : strip_tags($new_instance['item_class'.$item_num]); 101 $instance['item_target'.($i+1)] = empty($new_instance['item_target'.$item_num]) ? '' : strip_tags($new_instance['item_target'.$item_num]); 102 } 103 } 104 105 $instance['amount'] = $amount; 106 $instance['type'] = strip_tags($new_instance['type']); 107 $instance['reverse'] = empty($new_instance['reverse']) ? '' : strip_tags($new_instance['reverse']); 108 71 109 return $instance; 72 110 } 73 111 74 function form( $instance ) {112 public function form( $instance ) { 75 113 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '', 'title_link' => '' ) ); 76 114 $title = strip_tags($instance['title']); 77 115 $amount = empty($instance['amount']) ? 3 : $instance['amount']; 78 $new_amount = $amount + 1;116 79 117 for ($i = 1; $i <= $amount; $i++) { 80 $items[$i] = $instance['item' .$i];81 $item_links[$i] = $instance['item_link' .$i];82 $item_classes[$i] = $instance['item_class' .$i];83 $item_targets[$i] = $instance['item_target' .$i];118 $items[$i] = empty($instance['item'.$i]) ? '' : $instance['item'.$i]; 119 $item_links[$i] = empty($instance['item_link'.$i]) ? '' : $instance['item_link'.$i]; 120 $item_classes[$i] = empty($instance['item_class'.$i]) ? '' : $instance['item_class'.$i]; 121 $item_targets[$i] = empty($instance['item_target'.$i]) ? '' : $instance['item_target'.$i]; 84 122 } 85 123 $title_link = $instance['title_link']; 86 124 $type = empty($instance['type']) ? 'unordered' : $instance['type'] ; 87 $ text = format_to_edit($instance['text']);125 $reverse = empty($instance['reverse']) ? '' : $instance['reverse']; 88 126 ?> 89 127 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> 90 128 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> 91 <p><small>Leave the Link and Custom Style Class fields blank if not desired. Click Save for additional blank fields. To remove an item simply delete the "Text:" field content.</small></p> 92 <ol> 93 <?php foreach ($items as $num => $item) : ?> 94 95 <li> 96 <label for="<?php echo $this->get_field_id('item' . $num); ?>">Text:</label> 97 <input class="widefat" id="<?php echo $this->get_field_id('item' . $num); ?>" name="<?php echo $this->get_field_name('item' . $num); ?>" type="text" value="<?php echo esc_attr($item); ?>" /> 98 <label for="<?php echo $this->get_field_id('item_link' . $num); ?>">Link:</label> 99 <input class="widefat" id="<?php echo $this->get_field_id('item_link' . $num); ?>" name="<?php echo $this->get_field_name('item_link' . $num); ?>" type="text" value="<?php echo esc_attr($item_links[$num]); ?>" /> 100 <label for="<?php echo $this->get_field_id('item_class' . $num); ?>">Custom Style Class:</label> 101 <input class="widefat" id="<?php echo $this->get_field_id('item_class' . $num); ?>" name="<?php echo $this->get_field_name('item_class' . $num); ?>" type="text" value="<?php echo esc_attr($item_classes[$num]); ?>" /> 102 <label for="<?php echo $this->get_field_id('item_target' . $num); ?>"><input type="checkbox" name="<?php echo $this->get_field_name('item_target' . $num); ?>" id="<?php echo $this->get_field_id('item_target' . $num); ?>" <?php checked($item_targets[$num], 'on'); ?> /> Open in new window</label> 103 </li> 104 <?php endforeach; ?> 105 106 <?php //Additional form fields to add one more item ?> 107 108 <li> 109 <label for="<?php echo $this->get_field_id('item' . $new_amount); ?>">Text:</label> 110 <input class="widefat" id="<?php echo $this->get_field_id('item' . $new_amount); ?>" name="<?php echo $this->get_field_name('item' . $new_amount); ?>" type="text" value="" /> 111 <label for="<?php echo $this->get_field_id('item_link' . $new_amount); ?>">Link:</label> 112 <input class="widefat" id="<?php echo $this->get_field_id('item_link' . $new_amount); ?>" name="<?php echo $this->get_field_name('item_link' . $new_amount); ?>" type="text" value="" /> 113 <label for="<?php echo $this->get_field_id('item_class' . $new_amount); ?>">Custom Style Class:</label> 114 <input class="widefat" id="<?php echo $this->get_field_id('item_class' . $new_amount); ?>" name="<?php echo $this->get_field_name('item_class' . $new_amount); ?>" type="text" value="" /> 115 <label for="<?php echo $this->get_field_id('item_target' . $new_amount); ?>"><input type="checkbox" name="<?php echo $this->get_field_name('item_target' . $new_amount); ?>" id="<?php echo $this->get_field_id('item_target' . $new_amount); ?>" /> Open in new window</label> 116 </li> 117 </ol> 118 <input type="hidden" id="<?php echo $this->get_field_id('amount'); ?>" name="<?php echo $this->get_field_name('amount'); ?>" value="<?php echo $amount ?>" /> 119 <input type="hidden" id="<?php echo $this->get_field_id('new_amount'); ?>" name="<?php echo $this->get_field_name('new_amount'); ?>" value="<?php echo $new_amount ?>" /> 120 121 <label for="<?php echo $this->get_field_id('ordered'); ?>"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" value="ordered" id="<?php echo $this->get_field_id('ordered'); ?>" <?php checked($type, "ordered"); ?> /> Ordered</label> 122 <label for="<?php echo $this->get_field_id('unordered'); ?>"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" value="unordered" id="<?php echo $this->get_field_id('unordered'); ?>" <?php checked($type, "unordered"); ?> /> Unordered</label> 129 <ul class="sllw-instructions"> 130 <li><?php echo __("If an item is left blank it will not be output."); ?></li> 131 <li><?php echo __("The Link and Custom Style Class fields are optional and can be left blank."); ?></li> 132 <li><?php echo __("Be sure to include http:// before external links."); ?></li> 133 <li class="hide-if-no-js"><?php echo __("Reorder the list items by clicking and dragging the item number."); ?></li> 134 <li class="hide-if-no-js"><?php echo __("To remove an item, simply click the 'Remove' button."); ?></li> 135 <li class="hide-if-js"><?php echo __("Reorder or delete an item by using the 'Position/Action' table below."); ?></li> 136 <li class="hide-if-js"><?php echo __("To add a new item, check the 'Add New Item' box and save the widget."); ?></li> 137 </ul> 138 <div class="simple-link-list"> 139 <?php foreach ($items as $num => $item) : 140 $item = esc_attr($item); 141 $item_link = esc_attr($item_links[$num]); 142 $item_class = esc_attr($item_classes[$num]); 143 $checked = checked($item_targets[$num], 'on', false); 144 ?> 145 146 <div id="<?php echo $this->get_field_id($num); ?>" class="list-item"> 147 <h5 class="moving-handle"><span class="number"><?php echo $num; ?></span>. <span class="item-title"><?php echo $item; ?></span><a class="sllw-action hide-if-no-js"></a></h5> 148 <div class="sllw-edit-item"> 149 <label for="<?php echo $this->get_field_id('item'.$num); ?>"><?php echo __("Text:"); ?></label> 150 <input class="widefat" id="<?php echo $this->get_field_id('item'.$num); ?>" name="<?php echo $this->get_field_name('item'.$num); ?>" type="text" value="<?php echo $item; ?>" /> 151 <label for="<?php echo $this->get_field_id('item_link'.$num); ?>"><?php echo __("Link:"); ?></label> 152 <input class="widefat" id="<?php echo $this->get_field_id('item_link'.$num); ?>" name="<?php echo $this->get_field_name('item_link'.$num); ?>" type="text" value="<?php echo $item_link; ?>" /> 153 <label for="<?php echo $this->get_field_id('item_class'.$num); ?>"><?php echo __("Custom Style Class:"); ?></label> 154 <input class="widefat" id="<?php echo $this->get_field_id('item_class'.$num); ?>" name="<?php echo $this->get_field_name('item_class'.$num); ?>" type="text" value="<?php echo $item_class; ?>" /> 155 <input type="checkbox" name="<?php echo $this->get_field_name('item_target'.$num); ?>" id="<?php echo $this->get_field_id('item_target'.$num); ?>" <?php echo $checked; ?> /> <label for="<?php echo $this->get_field_id('item_target'.$num); ?>"><?php echo __("Open in new window"); ?></label> 156 <a class="sllw-delete hide-if-no-js"><img src="<?php echo plugins_url('images/delete.png', __FILE__ ); ?>" /> <?php echo __("Remove"); ?></a> 157 </div> 158 </div> 159 160 <?php endforeach; 161 162 if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) : ?> 163 <table class='widefat'> 164 <thead><tr><th><?php echo __("Item"); ?></th><th><?php echo __("Position/Action"); ?></th></tr></thead> 165 <tbody> 166 <?php foreach ($items as $num => $item) : ?> 167 <tr> 168 <td><?php echo esc_attr($item); ?></td> 169 <td> 170 <select id="<?php echo $this->get_field_id('position'.$num); ?>" name="<?php echo $this->get_field_name('position'.$num); ?>"> 171 <option><?php echo __('— Select —'); ?></option> 172 <?php for($i=1; $i<=count($items); $i++) { 173 if($i==$num){ 174 echo "<option value='$i' selected>$i</option>"; 175 }else{ 176 echo "<option value='$i'>$i</option>"; 177 } 178 } ?> 179 <option value="-1"><?php echo __("Delete"); ?></option> 180 </select> 181 </td> 182 </tr> 183 <?php endforeach; ?> 184 </tbody> 185 </table> 186 187 <div class="sllw-row"> 188 <input type="checkbox" name="<?php echo $this->get_field_name('new_item'); ?>" id="<?php echo $this->get_field_id('new_item'); ?>" /> <label for="<?php echo $this->get_field_id('new_item'); ?>"><?php echo __("Add New Item"); ?></label> 189 </div> 190 <?php endif; ?> 191 192 </div> 193 <div class="sllw-row hide-if-no-js"> 194 <a class="sllw-add button-secondary"><img src="<?php echo plugins_url('images/add.png', __FILE__ )?>" /> <?php echo __("Add Item"); ?></a> 195 </div> 196 197 <input type="hidden" id="<?php echo $this->get_field_id('amount'); ?>" class="amount" name="<?php echo $this->get_field_name('amount'); ?>" value="<?php echo $amount ?>" /> 198 <input type="hidden" id="<?php echo $this->get_field_id('order'); ?>" class="order" name="<?php echo $this->get_field_name('order'); ?>" value="<?php echo implode(',',range(1,$amount)); ?>" /> 199 200 <div class="sllw-row"> 201 <label for="<?php echo $this->get_field_id('ordered'); ?>"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" value="ordered" id="<?php echo $this->get_field_id('ordered'); ?>" <?php checked($type, "ordered"); ?> /> <?php echo __("Ordered"); ?></label> 202 <label for="<?php echo $this->get_field_id('unordered'); ?>"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" value="unordered" id="<?php echo $this->get_field_id('unordered'); ?>" <?php checked($type, "unordered"); ?> /> <?php echo __("Unordered"); ?></label> 203 </div> 204 205 <div class="sllw-row"> 206 <input type="checkbox" name="<?php echo $this->get_field_name('reverse'); ?>" id="<?php echo $this->get_field_id('reverse'); ?>" <?php checked($reverse, 'on'); ?> /> <label for="<?php echo $this->get_field_id('reverse'); ?>"><?php echo __("Reverse output order"); ?></label> 207 </div> 123 208 124 209 <?php 125 210 } 211 212 public function sllw_load_scripts($hook) { 213 if( $hook != 'widgets.php') 214 return; 215 if ( !isset($_GET['editwidget'])) { 216 wp_enqueue_script( 'sllw-sort-js', plugin_dir_url(__FILE__) .'js/sllw-sort.js'); 217 } 218 wp_enqueue_style( 'sllw-css', plugin_dir_url(__FILE__) .'css/sllw.css'); 219 } 126 220 } 127 221 128 222 add_action('widgets_init', create_function('', 'return register_widget("SimpleLinkListWidget");')); 129 130 223 ?>
Note: See TracChangeset
for help on using the changeset viewer.