Changeset 324566
- Timestamp:
- 12/20/2010 10:52:27 AM (15 years ago)
- Location:
- noio-iconized-bookmarks/trunk
- Files:
-
- 2 edited
-
noio_iconized_bookmarks.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
noio-iconized-bookmarks/trunk/noio_iconized_bookmarks.php
r115083 r324566 1 1 <?php 2 2 /* 3 Plugin Name: Noio Iconized Bookmarks4 Plugin URI: http://www.noio.nl/2009/05/version-one-of-nib/5 Description: Plugin that creates a widget that displays favicon next to links6 Author: Thomas van den Berg7 Version: 1.0.08 Author URI: http://www.noio.nl/3 Plugin Name: Noio Iconized Bookmarks 4 Plugin URI: http://www.noio.nl/2009/05/version-one-of-nib/ 5 Description: Plugin that creates a widget that displays favicon next to links 6 Author: Thomas van den Berg 7 Version: 1.0.0 8 Author URI: http://www.noio.nl/ 9 9 */ 10 10 11 11 /* 12 I (Thomas van den Berg) do not take any responsibility for damage that might13 occur to your WordPress database or website from using this plugin.14 */12 I (Thomas van den Berg) do not take any responsibility for damage that might 13 occur to your WordPress database or website from using this plugin. 14 */ 15 15 16 16 /* Copyright 2008 Thomas van den Berg (email : [email protected]) 17 17 18 This program is free software: you can redistribute it and/or modify19 it under the terms of the GNU General Public License as published by20 the Free Software Foundation, either version 3 of the License, or21 (at your option) any later version.22 23 This program is distributed in the hope that it will be useful,24 but WITHOUT ANY WARRANTY; without even the implied warranty of25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the26 GNU General Public License for more details.27 28 You should have received a copy of the GNU General Public License29 along with this program. If not, see <http://www.gnu.org/licenses/>.30 31 */18 This program is free software: you can redistribute it and/or modify 19 it under the terms of the GNU General Public License as published by 20 the Free Software Foundation, either version 3 of the License, or 21 (at your option) any later version. 22 23 This program is distributed in the hope that it will be useful, 24 but WITHOUT ANY WARRANTY; without even the implied warranty of 25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 GNU General Public License for more details. 27 28 You should have received a copy of the GNU General Public License 29 along with this program. If not, see <http://www.gnu.org/licenses/>. 30 31 */ 32 32 33 33 /********* … … 35 35 *********/ 36 36 37 function widget_noio_iconized_bookmarks($args){ 38 extract($args); 39 40 $options = get_option("nib"); 41 if( !is_array($options)) { $options = array() ; } 42 if( !isset($options['widget_args']) ) 43 { 44 //$options['widget_args'] = 'title_li=Links&class=widget widget_noio_iconized_bookmarks'; 45 } 46 47 $r = wp_parse_args($options['widget_args']); 48 49 $r['title_before'] = $before_title; 50 $r['title_after'] = $after_title; 51 $r['category_before'] = $before_widget; 52 $r['category_after'] = $after_widget; 53 54 list_iconized_bookmarks($r); 55 } 56 57 function noio_iconized_bookmarks_control(){ 58 $options = get_option("nib"); 59 if( !is_array($options)) { $options = array() ; } 60 if( !isset($options['widget_args'])) 61 { 62 $options['widget_args'] = 'title_li=Links&class=widget widget_noio_iconized_bookmarks'; 63 } 64 65 if ($_POST['nib-widget-submit']) 66 { 67 $options['widget_args'] = $_POST['nib-args']; 68 update_option("nib", $options); 69 } 70 71 ?> 72 <p> 73 <label for="nib-args">list_iconized_bookmarks Arguments: </label> 74 <input type="text" id="nib-args" name="nib-args" value="<?php echo $options['widget_args'];?>" /> 75 <input type="hidden" id="nib-widget-submit" name="nib-widget-submit" value="1" /> 76 </p> 77 <?php 78 79 } 37 class IconizedBookmarksWidget extends WP_Widget{ 38 function IconizedBookmarksWidget(){ 39 parent::WP_Widget(false, $name = 'Iconized Bookmarks Widget'); 40 } 41 42 function widget($args, $instance){ 43 extract($args); 44 $r = $instance['widget_args']; 45 $r['title_before'] = $before_title; 46 $r['title_after'] = $after_title; 47 $r['category_before'] = $before_widget; 48 $r['category_after'] = $after_widget; 49 list_iconized_bookmarks($r); 50 } 51 52 function update($new_instance,$old_instance){ 53 $instance = $old_instance; 54 $instance['widget_args'] = $new_instance['widget_args']; 55 return $instance; 56 } 57 58 function form($instance){ 59 $widget_args = $instance['widget_args']; 60 ?> 61 <p> 62 <label for="<?php echo $this->get_field_id('widget_args');?>"><code>list_bookmarks()</code> options [<a href='http://codex.wordpress.org/Function_Reference/wp_list_bookmarks'>?</a>]: </label> 63 <input type="text" class="widefat" id="<?php echo $this->get_field_id('widget_args');?>" 64 name="<?php echo $this->get_field_name('widget_args');?>" value="<?php echo $widget_args;?>" /> 65 </p> 66 <?php 67 } 68 } 69 add_action('widgets_init', create_function('', 'return register_widget("IconizedBookmarksWidget");')); 80 70 81 71 /************************** … … 83 73 **************************/ 84 74 function list_iconized_bookmarks($args = '') { 85 $defaults = array(86 'orderby' => 'name', 'order' => 'ASC',87 'limit' => -1, 'category' => '', 'exclude_category' => '',88 'category_name' => '', 'hide_invisible' => 1,89 'show_updated' => 0, 'echo' => 1,90 'categorize' => 1, 'title_li' => __('Bookmarks'),91 'title_before' => '<h2>', 'title_after' => '</h2>',92 'category_orderby' => 'name', 'category_order' => 'ASC',93 'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',94 'category_after' => '</li>'95 );96 97 $r = wp_parse_args( $args, $defaults );98 extract( $r, EXTR_SKIP );99 $output = '';100 101 102 if ( $categorize ) {103 //Split the bookmarks into ul's for each category104 $cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0));105 106 foreach ( (array) $cats as $cat ) {107 $params = array_merge($r, array('category'=>$cat->term_id));108 $bookmarks = get_bookmarks($params);109 if ( empty($bookmarks) )110 continue;111 $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);112 $catname = apply_filters( "link_category", $cat->name );113 $output .= "$title_before$catname$title_after\n\t<ul class='iconized_bookmarks'>\n";114 $output .= _walk_iconized_bookmarks($bookmarks, $r);115 $output .= "\n\t</ul>\n$category_after\n";116 }117 } else {118 119 //output one single list using title_li for the title120 $bookmarks = get_bookmarks($r);121 122 if ( !empty($bookmarks) ) {123 if ( !empty( $title_li ) ){124 $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);125 $output .= "$title_before$title_li$title_after\n\t<ul class='iconized_bookmarks'>\n";126 $output .= _walk_iconized_bookmarks($bookmarks, $r);127 $output .= "\n\t</ul>\n$category_after\n";128 } else {129 $output .= _walk_iconized_bookmarks($bookmarks, $r);130 }131 }132 }133 134 $output = apply_filters( 'wp_list_bookmarks', $output );135 136 if ( !$echo )137 return $output;138 echo $output;75 $defaults = array( 76 'orderby' => 'name', 'order' => 'ASC', 77 'limit' => -1, 'category' => '', 'exclude_category' => '', 78 'category_name' => '', 'hide_invisible' => 1, 79 'show_updated' => 0, 'echo' => 1, 80 'categorize' => 1, 'title_li' => __('Bookmarks'), 81 'title_before' => '<h2>', 'title_after' => '</h2>', 82 'category_orderby' => 'name', 'category_order' => 'ASC', 83 'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">', 84 'category_after' => '</li>' 85 ); 86 87 $r = wp_parse_args( $args, $defaults ); 88 extract( $r, EXTR_SKIP ); 89 $output = ''; 90 91 92 if ( $categorize ) { 93 //Split the bookmarks into ul's for each category 94 $cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0)); 95 96 foreach ( (array) $cats as $cat ) { 97 $params = array_merge($r, array('category'=>$cat->term_id)); 98 $bookmarks = get_bookmarks($params); 99 if ( empty($bookmarks) ) 100 continue; 101 $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before); 102 $catname = apply_filters( "link_category", $cat->name ); 103 $output .= "$title_before$catname$title_after\n\t<ul class='iconized_bookmarks'>\n"; 104 $output .= _walk_iconized_bookmarks($bookmarks, $r); 105 $output .= "\n\t</ul>\n$category_after\n"; 106 } 107 } else { 108 109 //output one single list using title_li for the title 110 $bookmarks = get_bookmarks($r); 111 112 if ( !empty($bookmarks) ) { 113 if ( !empty( $title_li ) ){ 114 $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before); 115 $output .= "$title_before$title_li$title_after\n\t<ul class='iconized_bookmarks'>\n"; 116 $output .= _walk_iconized_bookmarks($bookmarks, $r); 117 $output .= "\n\t</ul>\n$category_after\n"; 118 } else { 119 $output .= _walk_iconized_bookmarks($bookmarks, $r); 120 } 121 } 122 } 123 124 $output = apply_filters( 'wp_list_bookmarks', $output ); 125 126 if ( !$echo ) 127 return $output; 128 echo $output; 139 129 } 140 130 141 131 function _walk_iconized_bookmarks($bookmarks, $r){ 142 foreach ($bookmarks as $bookmark){143 $output .= '<li>';144 $output .= '<img class="favicon" alt="'. $bookmark->link_name .' favicon" src="' . $bookmark->link_image .'"></img>';145 $output .= '<a href="' . $bookmark->link_url.'">';146 $output .= $bookmark->link_name;147 $output .= '</a></li>';148 }149 return $output;132 foreach ($bookmarks as $bookmark){ 133 $output .= '<li>'; 134 $output .= '<img class="favicon" alt="'. $bookmark->link_name .' favicon" src="' . $bookmark->link_image .'"></img>'; 135 $output .= '<a href="' . $bookmark->link_url.'">'; 136 $output .= $bookmark->link_name; 137 $output .= '</a></li>'; 138 } 139 return $output; 150 140 } 151 141 … … 154 144 ***************************/ 155 145 function noio_iconize_bookmarks_add_options_page() { 156 add_options_page("Iconized Bookmarks Settings", "N.I.B.", "manage_options", __FILE__, "noio_iconize_bookmarks_options_page");146 add_options_page("Iconized Bookmarks Settings", "N.I.B.", "manage_options", __FILE__, "noio_iconize_bookmarks_options_page"); 157 147 } 158 148 159 149 function noio_iconize_bookmarks_options_page() { 160 150 161 global $wpdb;162 $dir = get_settings('siteurl');163 $emptyimage = $dir . "/wp-content/plugins/noio-iconized-bookmarks/empty.png";164 $notfoundimage = $dir . "/wp-content/plugins/noio-iconized-bookmarks/notfound.png";165 $defaultimage = $dir . "/wp-content/plugins/noio-iconized-bookmarks/default.gif";166 $selectbutton = $dir . "/wp-content/plugins/noio-iconized-bookmarks/select.png";167 $icontable = array();168 169 //Set & Update options170 $options = get_option('nib');171 if( !is_array($options)) { $options = array() ; }172 if( isset($_POST['nib_settings_defaulticon'])){173 $options['default_icon'] = $_POST['nib_settings_defaulticon'];174 }175 if( !isset($options['default_icon']) || $options['default_icon'] == ""){176 $options['default_icon'] = $defaultimage;177 }178 update_option('nib',$options);179 180 //Update icons if form was submitted181 if (isset($_POST['nib_update_icons'])){182 $sql = "SELECT link_name, link_url , link_image183 FROM $wpdb->links";184 $links = $wpdb->get_results( $wpdb->prepare( $sql ));185 186 $i = 0;187 while( isset($_POST['nib_use_icon_'.$i] )){188 $newicon = $_POST['nib_use_icon_'.$i];189 if($newicon == $emptyimage){190 $newicon = "";191 }192 $linkid = $_POST['nib_link_id_'.$i];193 194 $singlereplace = "UPDATE $wpdb->links195 SET link_image = %s196 WHERE link_id = %s";197 $replaced = $wpdb->query( $wpdb->prepare($singlereplace, $newicon, $linkid));198 $i++;199 }200 201 $message = "Icons successfully updated.";202 203 }204 205 //Get a list of links and their current images.206 $sql = "SELECT link_name, link_url , link_image, link_id207 FROM $wpdb->links";208 $links = $wpdb->get_results( $wpdb->prepare( $sql ));209 210 foreach($links as $link){211 $iconinfo["name"] = $link->link_name;212 $iconinfo["curr"] = ($link->link_image != "") ? $link->link_image : $emptyimage;213 $iconinfo["url"] = $link->link_url;214 $iconinfo["id"] = $link->link_id;215 216 array_push($icontable, $iconinfo); 217 } 218 219 //FINDING ICONS 220 if(isset($_POST['nib_find_icons'])){ 221 222 $message = "Icons found, click update when you have selected the desired favicons. <em>Back up your database before updating your icons!</em>"; 223 224 foreach($icontable as $i => $iconinfo){225 $found = noio_locate_icon($iconinfo["url"]);226 $iconinfo["found"] = $found ? $found : $notfoundimage; 227 $iconinfo["use"] = $found ? $found : $options["default_icon"];228 229 $icontable[$i] = $iconinfo;230 } 231 232 //FIRST RUN, NOTHING SUBMITTED 233 } else { 234 if(!isset($_POST["nib_update_icons"])){235 $message = "Click <em>Find Icons</em> to find favicons for all your links. Then you can select the ones you want to use."; 236 } 237 238 foreach($icontable as $i => $iconinfo){ 239 $iconinfo["found"] = $notfoundimage; 240 $iconinfo["use"] = $iconinfo["curr"];241 242 $icontable[$i] = $iconinfo;243 }244 }245 246 //The panel itself.247 ?>248 <div class="wrap">249 <h2>Noio Iconized Bookmarks</h2>250 251 <?php if(isset($message)):?>252 <div class="updated">253 <strong>254 <p><?php echo $message; ?></p>255 </strong>256 </div>257 <?php endif;?>258 259 <form method="post" action="options-general.php?page=noio-iconized-bookmarks/noio_iconized_bookmarks.php">260 261 <table class="favicon-table"><tbody>262 <tr><th>Link Name</th><th>Current Image</th><th>Found Icon</th>263 <th>Default</th><th>Custom</th><th>Your Choice</th></tr>264 <?php for($i = 0; $i < count($icontable); $i++){265 $link = $icontable[$i];?>266 <tr valign="middle">267 <td> <strong><?php echo $link["name"];?></strong><br/><small><?php echo $link["url"];?></small></td>268 <td>269 <img class="icon" src="<?php echo $link["curr"];?>" alt=""></img>270 <a href="javascript:void();" onclick="nibUseIcon(<?php echo $i;?>, '<?php echo $link["curr"];?>');">select</a>271 </td>272 <td>273 <img class="icon" src="<?php echo $link["found"];?>" alt=""></img>274 <?php if($link["found"] != $notfoundimage):?>275 <a href="javascript:void();" onclick="nibUseIcon(<?php echo $i;?>, '<?php echo $link["found"];?>');">select</a><?php endif;?>276 </td>277 <td>278 <img class="icon" src="<?php echo $options['default_icon'];?>" alt=""></img>279 <a href="javascript:void();" onclick="nibUseIcon(<?php echo $i;?>, '<?php echo $options["default_icon"];?>');">select</a>280 </td>281 <td>282 <a href="javascript:void();" class="set-custom" onclick="getElementById('nib-custom-icon-<?php echo $i;?>').src = prompt('Enter Image Address', '')"/>set</a>283 <img class="icon" id="nib-custom-icon-<?php echo $i;?>" src="<?php echo $emptyimage;?>"></img>284 <a href="javascript:void();" onclick="nibUseIcon(<?php echo $i;?>, getElementById('nib-custom-icon-<?php echo $i;?>').src);">select</a>285 </td>286 <td>287 <img class="final icon" id="nib-use-icon-<?php echo $i;?>" src="<?php echo $link['use'];?>" alt=""></img>288 <input type="hidden" id="nib-use-icon-input-<?php echo $i;?>" name="nib_use_icon_<?php echo $i;?>" value="<?php echo $link['use'];?>"/>289 <input type="hidden" name="nib_link_id_<?php echo $i;?>" value="<?php echo $link['id'];?>"/>290 </td>291 </tr>292 <?php } ?>293 </table></tbody>294 295 <table class="form-table">296 <tbody>297 <tr>298 <td width="30px"><img class="icon" src="<?php echo $emptyimage;?>" alt=""/></td>299 <td class="setting-description">Image source is empty.</td>300 </tr>301 <tr>302 <td width="30px"><img class="icon" src="<?php echo $notfoundimage;?>" alt=""/></td>303 <td class="setting-description">An image was not found.</td>304 </tr>305 <tr>306 <td width="30px"><img class="icon" src="<?php echo $selectbutton;?>" alt=""/></td>307 <td class="setting-description">Click to use this icon.</td>308 <tr>309 <td width="30px"><img id="nib-default-icon-preview" class="icon" src="<?php echo $options['default_icon'];?>"alt=""/></td>310 <td width="200px">311 <input name="nib_settings_defaulticon" type="text" id="nib_settings_defaulticon" value="<?php echo $options['default_icon']?>" />312 </td>313 <td class="setting-description">Set the default icon here.</td>314 </tr>315 </tbody>316 </table>317 <p class="submit">318 <input name="nib_find_icons" class="button-secondary" value="Find Icons" type="submit" />319 320 <input name="nib_update_icons" class="button-primary" value="Update Icons" type="submit" />321 </p>322 </form>323 324 <?php151 global $wpdb; 152 $dir = get_settings('siteurl'); 153 $emptyimage = $dir . "/wp-content/plugins/noio-iconized-bookmarks/empty.png"; 154 $notfoundimage = $dir . "/wp-content/plugins/noio-iconized-bookmarks/notfound.png"; 155 $defaultimage = $dir . "/wp-content/plugins/noio-iconized-bookmarks/default.gif"; 156 $selectbutton = $dir . "/wp-content/plugins/noio-iconized-bookmarks/select.png"; 157 $icontable = array(); 158 159 //Set & Update options 160 $options = get_option('nib'); 161 if( !is_array($options)) { $options = array() ; } 162 if( isset($_POST['nib_settings_defaulticon'])){ 163 $options['default_icon'] = $_POST['nib_settings_defaulticon']; 164 } 165 if( !isset($options['default_icon']) || $options['default_icon'] == ""){ 166 $options['default_icon'] = $defaultimage; 167 } 168 update_option('nib',$options); 169 170 //Update icons if form was submitted 171 if (isset($_POST['nib_update_icons'])){ 172 $sql = "SELECT link_name, link_url , link_image 173 FROM $wpdb->links"; 174 $links = $wpdb->get_results( $wpdb->prepare( $sql )); 175 176 $i = 0; 177 while( isset($_POST['nib_use_icon_'.$i] )){ 178 $newicon = $_POST['nib_use_icon_'.$i]; 179 if($newicon == $emptyimage){ 180 $newicon = ""; 181 } 182 $linkid = $_POST['nib_link_id_'.$i]; 183 184 $singlereplace = "UPDATE $wpdb->links 185 SET link_image = %s 186 WHERE link_id = %s"; 187 $replaced = $wpdb->query( $wpdb->prepare($singlereplace, $newicon, $linkid)); 188 $i++; 189 } 190 191 $message = "Icons successfully updated."; 192 193 } 194 195 //Get a list of links and their current images. 196 $sql = "SELECT link_name, link_url , link_image, link_id 197 FROM $wpdb->links"; 198 $links = $wpdb->get_results( $wpdb->prepare( $sql )); 199 200 foreach($links as $link){ 201 $iconinfo["name"] = $link->link_name; 202 $iconinfo["curr"] = ($link->link_image != "") ? $link->link_image : $emptyimage; 203 $iconinfo["url"] = $link->link_url; 204 $iconinfo["id"] = $link->link_id; 205 array_push($icontable, $iconinfo); 206 } 207 208 //FINDING ICONS 209 if(isset($_POST['nib_find_icons'])){ 210 211 $message = "Icons found, click update when you have selected the desired favicons. <em>Back up your database before updating your icons!</em>"; 212 213 echo '<h4>Progress:</h4><p>'; 214 foreach($icontable as $i => $iconinfo){ 215 $found = noio_locate_icon($iconinfo["url"]); 216 echo ($found ? "<span style='color:#43951A;'>".$iconinfo["url"]." found.</span><br/>" : 217 "<span style='color:#FA2323;'>".$iconinfo["url"]." not found.</span><br/>"); 218 $iconinfo["found"] = $found ? $found : $notfoundimage; 219 $iconinfo["use"] = $found ? $found : $options["default_icon"]; 220 $icontable[$i] = $iconinfo; 221 } 222 223 //FIRST RUN, NOTHING SUBMITTED 224 } else { 225 if(!isset($_POST["nib_update_icons"])){ 226 $message = "Click <em>Find Icons</em> to find favicons for all your links. Then you can select the ones you want to use."; 227 } 228 229 foreach($icontable as $i => $iconinfo){ 230 $iconinfo["found"] = $notfoundimage; 231 $iconinfo["use"] = $iconinfo["curr"]; 232 $icontable[$i] = $iconinfo; 233 } 234 } 235 236 //The panel itself. 237 ?> 238 <div class="wrap"> 239 <h2>Noio Iconized Bookmarks</h2> 240 241 <?php if(isset($message)):?> 242 <div class="updated"> 243 <strong> 244 <p><?php echo $message; ?></p> 245 </strong> 246 </div> 247 <?php endif;?> 248 249 <form method="post" action="options-general.php?page=noio-iconized-bookmarks/noio_iconized_bookmarks.php"> 250 251 <table class="favicon-table"><tbody> 252 <tr><th>Link Name</th><th>Current Image</th><th>Found Icon</th> 253 <th>Default</th><th>Custom</th><th>Your Choice</th></tr> 254 <?php for($i = 0; $i < count($icontable); $i++){ 255 $link = $icontable[$i];?> 256 <tr valign="middle"> 257 <td> <strong><?php echo $link["name"];?></strong><br/><small><?php echo $link["url"];?></small></td> 258 <td> 259 <img class="icon" src="<?php echo $link["curr"];?>" alt=""></img> 260 <a href="javascript:void();" onclick="nibUseIcon(<?php echo $i;?>, '<?php echo $link["curr"];?>');">select</a> 261 </td> 262 <td> 263 <img class="icon" src="<?php echo $link["found"];?>" alt=""></img> 264 <?php if($link["found"] != $notfoundimage):?> 265 <a href="javascript:void();" onclick="nibUseIcon(<?php echo $i;?>, '<?php echo $link["found"];?>');">select</a> <?php endif;?> 266 </td> 267 <td> 268 <img class="icon" src="<?php echo $options['default_icon'];?>" alt=""></img> 269 <a href="javascript:void();" onclick="nibUseIcon(<?php echo $i;?>, '<?php echo $options["default_icon"];?>');">select</a> 270 </td> 271 <td> 272 <a href="javascript:void();" class="set-custom" onclick="getElementById('nib-custom-icon-<?php echo $i;?>').src = prompt('Enter Image Address', '')"/>set</a> 273 <img class="icon" id="nib-custom-icon-<?php echo $i;?>" src="<?php echo $emptyimage;?>"></img> 274 <a href="javascript:void();" onclick="nibUseIcon(<?php echo $i;?>, getElementById('nib-custom-icon-<?php echo $i;?>').src);">select</a> 275 </td> 276 <td> 277 <img class="final icon" id="nib-use-icon-<?php echo $i;?>" src="<?php echo $link['use'];?>" alt=""></img> 278 <input type="hidden" id="nib-use-icon-input-<?php echo $i;?>" name="nib_use_icon_<?php echo $i;?>" value="<?php echo $link['use'];?>"/> 279 <input type="hidden" name="nib_link_id_<?php echo $i;?>" value="<?php echo $link['id'];?>"/> 280 </td> 281 </tr> 282 <?php } ?> 283 </table></tbody> 284 285 <table class="form-table"> 286 <tbody> 287 <tr> 288 <td width="30px"><img class="icon" src="<?php echo $emptyimage;?>" alt=""/></td> 289 <td class="setting-description">Image source is empty.</td> 290 </tr> 291 <tr> 292 <td width="30px"><img class="icon" src="<?php echo $notfoundimage;?>" alt=""/></td> 293 <td class="setting-description">An image was not found.</td> 294 </tr> 295 <tr> 296 <td width="30px"><img class="icon" src="<?php echo $selectbutton;?>" alt=""/></td> 297 <td class="setting-description">Click to use this icon.</td> 298 <tr> 299 <td width="30px"><img id="nib-default-icon-preview" class="icon" src="<?php echo $options['default_icon'];?>"alt=""/></td> 300 <td width="200px"> 301 <input name="nib_settings_defaulticon" type="text" id="nib_settings_defaulticon" value="<?php echo $options['default_icon']?>" /> 302 </td> 303 <td class="setting-description">Set the default icon here.</td> 304 </tr> 305 </tbody> 306 </table> 307 <p class="submit"> 308 <input name="nib_find_icons" class="button-secondary" value="Find Icons" type="submit" /> 309 310 <input name="nib_update_icons" class="button-primary" value="Update Icons" type="submit" /> 311 </p> 312 </form> 313 314 <?php 325 315 } 326 316 … … 329 319 *****************/ 330 320 function noio_locate_icon($url) { 331 332 if( $html = @file_get_contents($url) ) { 333 334 if (preg_match('/<link[^>]+rel="(?:shortcut )?icon"[^>]+?href="([^"]+?)"/si', $html, $matches)) { 335 336 $linkUrl = html_entity_decode($matches[1]); 337 if (substr($linkUrl, 0, 1) == '/') { 338 $urlParts = parse_url($url); 339 $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].$linkUrl; 340 } else if (substr($linkUrl, 0, 7) == 'http://') { 341 $faviconURL = $linkUrl; 342 } else if (substr($url, -1, 1) == '/') { 343 $faviconURL = $url.$linkUrl; 344 } else { 345 $faviconURL = $url.'/'.$linkUrl; 346 } 347 348 } else { 349 350 $urlParts = parse_url($url); 351 $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].'/favicon.ico'; 352 353 } 354 if( $faviconURL_exists = noio_url_validate($faviconURL) ) 355 return $faviconURL; 356 } 357 return false; 321 // 322 // $context = stream_context_create(array( 323 // 'http' => array( 324 // 'timeout' => 3 // Timeout in seconds 325 // ) 326 // )); 327 // 328 // create curl resource 329 $ch = curl_init(); 330 curl_setopt($ch, CURLOPT_URL, $url); 331 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 332 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 333 curl_setopt($ch, CURLOPT_MAXREDIRS, 5); 334 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 335 $html = curl_exec($ch); 336 curl_close($ch); 337 338 // echo substr(strip_tags($html),0,20); 339 340 if( $html ) { //= file_get_contents($url, 0, $context) 341 342 if (preg_match('/<link[^>]+rel="(?:shortcut )?icon"[^>]+?href="([^"]+?)"/si', $html, $matches)) { 343 344 $linkUrl = trim(html_entity_decode($matches[1])); 345 if (substr($linkUrl, 0, 1) == '/') { 346 $urlParts = parse_url($url); 347 $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].$linkUrl; 348 } else if (substr($linkUrl, 0, 7) == 'http://') { 349 $faviconURL = $linkUrl; 350 } else if (substr($url, -1, 1) == '/') { 351 $faviconURL = $url.$linkUrl; 352 } else { 353 $faviconURL = $url.'/'.$linkUrl; 354 } 355 356 } else { 357 358 $urlParts = parse_url($url); 359 $faviconURL = $urlParts['scheme'].'://'.$urlParts['host'].'/favicon.ico'; 360 361 } 362 if( $faviconURL_exists = noio_url_validate($faviconURL) ) 363 return $faviconURL; 364 } 365 return false; 358 366 } 359 367 360 368 function noio_url_validate( $link ) { 361 362 $url_parts = @parse_url( $link );363 364 if ( empty( $url_parts["host"] ) )365 return false;366 367 if ( !empty( $url_parts["path"] ) ) {368 $documentpath = $url_parts["path"];369 } else {370 $documentpath = "/";371 }372 373 if ( !empty( $url_parts["query"] ) )374 $documentpath .= "?" . $url_parts["query"];375 376 $host = $url_parts["host"];377 $port = $url_parts["port"];378 379 if ( empty($port) )380 $port = "80";381 382 $socket = @fsockopen( $host, $port, $errno, $errstr, 30 );383 384 if ( !$socket )385 return false;386 387 fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n");388 389 $http_response = fgets( $socket, 22 );390 391 $responses = "/(200 OK)|(30[0-9] Moved)/";392 if ( preg_match($responses, $http_response) ) {393 fclose($socket);394 return true;395 } else {396 return false;397 }369 370 $url_parts = @parse_url( $link ); 371 372 if ( empty( $url_parts["host"] ) ) 373 return false; 374 375 if ( !empty( $url_parts["path"] ) ) { 376 $documentpath = $url_parts["path"]; 377 } else { 378 $documentpath = "/"; 379 } 380 381 if ( !empty( $url_parts["query"] ) ) 382 $documentpath .= "?" . $url_parts["query"]; 383 384 $host = $url_parts["host"]; 385 $port = $url_parts["port"]; 386 387 if ( empty($port) ) 388 $port = "80"; 389 390 $socket = @fsockopen( $host, $port, $errno, $errstr, 30 ); 391 392 if ( !$socket ) 393 return false; 394 395 fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n"); 396 397 $http_response = fgets( $socket, 22 ); 398 399 $responses = "/(200 OK)|(30[0-9] Moved)/"; 400 if ( preg_match($responses, $http_response) ) { 401 fclose($socket); 402 return true; 403 } else { 404 return false; 405 } 398 406 } 399 407 … … 401 409 INITIALIZATION 402 410 *****************/ 403 function widget_noio_iconized_bookmarks_init(){404 register_sidebar_widget(__('Iconized Bookmarks'), 'widget_noio_iconized_bookmarks');405 register_widget_control( 'Iconized Bookmarks', 'noio_iconized_bookmarks_control', 250, 200 );406 }407 411 408 412 function noio_iconized_bookmarks_head(){ 409 $dir = get_settings('siteurl') . '/wp-content/plugins/noio-iconized-bookmarks/';410 echo '<link rel="stylesheet" type="text/css" href="' . $dir . 'style.css" /> ';411 echo '<script type="text/javascript" src="'.$dir .'nib-script.js" charset="utf-8"></script>';413 $dir = get_settings('siteurl') . '/wp-content/plugins/noio-iconized-bookmarks/'; 414 echo '<link rel="stylesheet" type="text/css" href="' . $dir . 'style.css" /> '; 415 echo '<script type="text/javascript" src="'.$dir .'nib-script.js" charset="utf-8"></script>'; 412 416 } 413 417 414 418 add_action("admin_head","noio_iconized_bookmarks_head"); 415 add_action("plugins_loaded", "widget_noio_iconized_bookmarks_init");416 419 add_action('admin_menu', 'noio_iconize_bookmarks_add_options_page'); 417 420 ?> -
noio-iconized-bookmarks/trunk/readme.txt
r115081 r324566 3 3 Donate link: http://tinyurl.com/donatenoio 4 4 Tags: blogroll, bookmarks, favicons, icons, links, images 5 Requires at least: 2. 66 Tested up to: 2.7.17 Stable tag: 1.0. 05 Requires at least: 2.8 6 Tested up to: 3.0.1 7 Stable tag: 1.0.1 8 8 9 9 Plugin that allows you to automatically add favicons to your blog's links. … … 55 55 2. What bookmarks + favicons could look like. 56 56 57 == Changelog == 57 58 59 = 1.0.1 = 60 * Used the new class-based widget API to allow multiple instances of the Iconized Bookmarks Widget. 61 * Fixed timeouts occurring when finding favicons for nonexistent URLs. 62 63 == Upgrade Notice == 64 65 This small patch fixes timeouts when finding favicons. Also, the widget now allows multiple instances, but you will have to re-add it to your sidebars. 66 67
Note: See TracChangeset
for help on using the changeset viewer.