| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Link Library |
| 4 |
Plugin URI: https://ylefebvre.github.io/wordpress-plugins/link-library/ |
| 5 |
Description: Display links on pages with a variety of options |
| 6 |
Version: 7.9.7 |
| 7 |
Author: Yannick Lefebvre |
| 8 |
Author URI: http://ylefebvre.github.io/ |
| 9 |
Text Domain: link-library |
| 10 |
|
| 11 |
A plugin for the blogging MySQL/PHP-based WordPress. |
| 12 |
Copyright 2026 Yannick Lefebvre |
| 13 |
|
| 14 |
Translations: |
| 15 |
French Translation courtesy of Michel G. et Luc Capronnier |
| 16 |
Danish Translation courtesy of GeorgWP (http://wordpress.blogos.dk) |
| 17 |
Italian Translation courtesy of Gianni Diurno |
| 18 |
Serbian Translation courtesy of Ogi Djuraskovic (firstsiteguide.com) |
| 19 |
|
| 20 |
This program is free software; you can redistribute it and/or |
| 21 |
modify it under the terms of the GNUs General Public License |
| 22 |
as published by the Free Software Foundation; either version 2 |
| 23 |
of the License, or (at your option) any later version. |
| 24 |
|
| 25 |
This program is distributed in the hope that it will be useful, |
| 26 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 |
GNU General Public License for more details. |
| 29 |
|
| 30 |
You should have received a copy of the GNU General Public License |
| 31 |
along with this program; if not, write to the Free Software |
| 32 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 33 |
|
| 34 |
You can also view a copy of the HTML version of the GNU General Public |
| 35 |
License at http://www.gnu.org/copyleft/gpl.html |
| 36 |
|
| 37 |
I, Yannick Lefebvre, can be contacted via e-mail at ylefebvre@gmail.com |
| 38 |
*/ |
| 39 |
|
| 40 |
// Exit if login page |
| 41 |
if ( !function_exists( 'is_login' ) || ( function_exists( 'is_login' ) && !is_login() ) ) { |
| 42 |
update_option( 'link_manager_enabled', 0 ); |
| 43 |
|
| 44 |
require_once(ABSPATH . '/wp-admin/includes/bookmark.php'); |
| 45 |
require_once plugin_dir_path( __FILE__ ) . 'link-library-defaults.php'; |
| 46 |
require_once plugin_dir_path( __FILE__ ) . 'rssfeed.php'; |
| 47 |
require_once plugin_dir_path( __FILE__ ) . '/upvote-downvote/thumbs-rating.php'; |
| 48 |
|
| 49 |
global $my_link_library_plugin; |
| 50 |
global $my_link_library_plugin_admin; |
| 51 |
|
| 52 |
function link_library_validate_settings_number( $settings ) { |
| 53 |
if ( is_numeric( $settings ) ) { |
| 54 |
$settings = intval( $settings ); |
| 55 |
$settingsname = 'LinkLibraryPP' . $settings; |
| 56 |
$options = get_option( $settingsname ); |
| 57 |
if ( false === $options ) { |
| 58 |
$settings = 1; |
| 59 |
} |
| 60 |
} else { |
| 61 |
$settings = 1; |
| 62 |
} |
| 63 |
|
| 64 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 65 |
if ( $settings > $genoptions['numberstylesets'] ) { |
| 66 |
$settings = 1; |
| 67 |
} |
| 68 |
|
| 69 |
return $settings; |
| 70 |
} |
| 71 |
|
| 72 |
function link_library_tweak_plugins_http_filter( $response, $r, $url ) { |
| 73 |
if ( stristr( $url, 'api.wordpress.org/plugins/update-check/1.1' ) ) { |
| 74 |
$wpapi_response = json_decode( $response['body'] ); |
| 75 |
$wpapi_response->plugins = link_library_modify_http_response( $wpapi_response->plugins ); |
| 76 |
$response['body'] = json_encode( $wpapi_response ); |
| 77 |
} |
| 78 |
|
| 79 |
return $response; |
| 80 |
} |
| 81 |
|
| 82 |
function link_library_get_terms_filter_only_publish( $terms, $taxonomies, $args ) { |
| 83 |
global $wpdb; |
| 84 |
global $hide_if_empty_filter; |
| 85 |
|
| 86 |
$taxonomy = $taxonomies[0]; |
| 87 |
if ( ! is_array( $terms ) && count( $terms ) < 1 ) { |
| 88 |
return $terms; |
| 89 |
} |
| 90 |
|
| 91 |
$filtered_terms = array(); |
| 92 |
|
| 93 |
foreach ( $terms as $term ) { |
| 94 |
$result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts p JOIN $wpdb->term_relationships rl ON p.ID = rl.object_id WHERE rl.term_taxonomy_id = $term->term_id AND p.post_status = 'publish' LIMIT 1" ); |
| 95 |
|
| 96 |
if ( intval( $result ) > 0 || ( !$hide_if_empty_filter && 0 == intval( $result ) ) ) { |
| 97 |
$filtered_terms[] = $term; |
| 98 |
} |
| 99 |
} |
| 100 |
return $filtered_terms; |
| 101 |
} |
| 102 |
|
| 103 |
function link_library_get_terms_filter_publish_pending( $terms, $taxonomies, $args ) { |
| 104 |
global $wpdb; |
| 105 |
global $hide_if_empty_filter; |
| 106 |
|
| 107 |
$taxonomy = $taxonomies[0]; |
| 108 |
if ( ! is_array( $terms ) && count( $terms ) < 1 ) { |
| 109 |
return $terms; |
| 110 |
} |
| 111 |
|
| 112 |
$filtered_terms = array(); |
| 113 |
|
| 114 |
foreach ( $terms as $term ) { |
| 115 |
$result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts p JOIN $wpdb->term_relationships rl ON p.ID = rl.object_id WHERE rl.term_taxonomy_id = $term->term_id AND ( p.post_status = 'publish' or p.post_status = 'pending' ) LIMIT 1" ); |
| 116 |
if ( intval( $result ) > 0 || ( !$hide_if_empty_filter && 0 == intval( $result ) ) ) { |
| 117 |
$filtered_terms[] = $term; |
| 118 |
} |
| 119 |
} |
| 120 |
return $filtered_terms; |
| 121 |
} |
| 122 |
|
| 123 |
function link_library_get_terms_filter_publish_draft( $terms, $taxonomies, $args ) { |
| 124 |
global $wpdb; |
| 125 |
global $hide_if_empty_filter; |
| 126 |
|
| 127 |
$taxonomy = $taxonomies[0]; |
| 128 |
if ( ! is_array( $terms ) && count( $terms ) < 1 ) { |
| 129 |
return $terms; |
| 130 |
} |
| 131 |
|
| 132 |
$filtered_terms = array(); |
| 133 |
|
| 134 |
foreach ( $terms as $term ) { |
| 135 |
$result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts p JOIN $wpdb->term_relationships rl ON p.ID = rl.object_id WHERE rl.term_taxonomy_id = $term->term_id AND ( p.post_status = 'publish' or p.post_status = 'draft' ) LIMIT 1" ); |
| 136 |
if ( intval( $result ) > 0 || ( !$hide_if_empty_filter && 0 == intval( $result ) ) ) { |
| 137 |
$filtered_terms[] = $term; |
| 138 |
} |
| 139 |
} |
| 140 |
return $filtered_terms; |
| 141 |
} |
| 142 |
|
| 143 |
function link_library_get_terms_filter_publish_draft_pending( $terms, $taxonomies, $args ) { |
| 144 |
global $wpdb; |
| 145 |
global $hide_if_empty_filter; |
| 146 |
|
| 147 |
$taxonomy = $taxonomies[0]; |
| 148 |
if ( ! is_array( $terms ) && count( $terms ) < 1 ) { |
| 149 |
return $terms; |
| 150 |
} |
| 151 |
|
| 152 |
$filtered_terms = array(); |
| 153 |
|
| 154 |
foreach ( $terms as $term ) { |
| 155 |
$result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts p JOIN $wpdb->term_relationships rl ON p.ID = rl.object_id WHERE rl.term_taxonomy_id = $term->term_id AND ( p.post_status = 'publish' or p.post_status = 'draft' or p.post_status = 'pending' ) LIMIT 1" ); |
| 156 |
if ( intval( $result ) > 0 || ( !$hide_if_empty_filter && 0 == intval( $result ) ) ) { |
| 157 |
$filtered_terms[] = $term; |
| 158 |
} |
| 159 |
} |
| 160 |
return $filtered_terms; |
| 161 |
} |
| 162 |
|
| 163 |
function link_library_strposX( $haystack, $needle, $number ) { |
| 164 |
if( $number == '1' ){ |
| 165 |
return strpos($haystack, $needle); |
| 166 |
} elseif( $number > '1' ){ |
| 167 |
return strpos( $haystack, $needle, link_library_strposX( $haystack, $needle, $number - 1 ) + strlen( $needle ) ); |
| 168 |
} else { |
| 169 |
return error_log( 'Error: Value for parameter $number is out of range' ); |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
function link_library_modify_http_response( $plugins_response ) { |
| 174 |
|
| 175 |
foreach ( $plugins_response as $response_key => $plugin_response ) { |
| 176 |
if ( plugin_basename(__FILE__) == $plugin_response->plugin ) { |
| 177 |
if ( 3 <= substr_count( $plugin_response->new_version, '.' ) ) { |
| 178 |
$plugin_info = get_plugin_data( __FILE__ ); |
| 179 |
$period_position = link_library_strposX( $plugin_info['Version'], '.', 3 ); |
| 180 |
if ( false !== $period_position ) { |
| 181 |
$current_version = substr( $plugin_info['Version'], 0, $period_position ); |
| 182 |
} else { |
| 183 |
$current_version = $plugin_info['Version']; |
| 184 |
} |
| 185 |
|
| 186 |
$period_position2 = link_library_strposX( $plugin_response->new_version, '.', 3 ); |
| 187 |
if ( false !== $period_position ) { |
| 188 |
$new_version = substr( $plugin_response->new_version, 0, $period_position2 ); |
| 189 |
} else { |
| 190 |
$new_version = $plugin_response->new_version; |
| 191 |
} |
| 192 |
|
| 193 |
$version_diff = version_compare( $current_version, $new_version ); |
| 194 |
|
| 195 |
if ( -1 < $version_diff ) { |
| 196 |
unset( $plugins_response->$response_key ); |
| 197 |
} |
| 198 |
} |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
return $plugins_response; |
| 203 |
} |
| 204 |
|
| 205 |
function ll_expand_posts_search( $search, $query ) { |
| 206 |
global $wpdb; |
| 207 |
|
| 208 |
if ( $query->query_vars['post_type'] == 'link_library_links' && !empty( $query->query['s'] ) ) { |
| 209 |
|
| 210 |
$query_words = explode( ' ', $query->query['s'] ); |
| 211 |
if ( ! empty( $query_words ) ) { |
| 212 |
$number_of_words = sizeof( $query_words ); |
| 213 |
if ( $number_of_words > 5 ) { |
| 214 |
$number_of_words = 5; |
| 215 |
} |
| 216 |
|
| 217 |
$sql = " |
| 218 |
or exists ( |
| 219 |
select * from {$wpdb->postmeta} where post_id={$wpdb->posts}.ID |
| 220 |
and meta_key in ( 'link_description', 'link_notes', 'link_textfield', 'link_url' ) |
| 221 |
"; |
| 222 |
|
| 223 |
for ( $counter = 0; $counter < $number_of_words; $counter ++ ) { |
| 224 |
$sql .= 'and meta_value like %s '; |
| 225 |
} |
| 226 |
|
| 227 |
$sql .= " |
| 228 |
) |
| 229 |
"; |
| 230 |
|
| 231 |
$like = array(); |
| 232 |
|
| 233 |
foreach ( $query_words as $index => $query_word ) { |
| 234 |
$like[ $index ] = '%' . $wpdb->esc_like( $query_words[ $index ] ) . '%'; |
| 235 |
} |
| 236 |
|
| 237 |
if ( 1 == $number_of_words ) { |
| 238 |
$search = preg_replace( "#\({$wpdb->posts}.post_title LIKE [^)]+\)\K#", $wpdb->prepare( $sql, $like[0] ), $search ); |
| 239 |
} elseif ( 2 == $number_of_words ) { |
| 240 |
$search = preg_replace( "#\({$wpdb->posts}.post_title LIKE [^)]+\)\K#", $wpdb->prepare( $sql, $like[0], $like[1] ), $search ); |
| 241 |
} elseif ( 3 == $number_of_words ) { |
| 242 |
$search = preg_replace( "#\({$wpdb->posts}.post_title LIKE [^)]+\)\K#", $wpdb->prepare( $sql, $like[0], $like[1], $like[2] ), $search ); |
| 243 |
} elseif ( 4 == $number_of_words ) { |
| 244 |
$search = preg_replace( "#\({$wpdb->posts}.post_title LIKE [^)]+\)\K#", $wpdb->prepare( $sql, $like[0], $like[1], $like[2], $like[3] ), $search ); |
| 245 |
} elseif ( 5 == $number_of_words ) { |
| 246 |
$search = preg_replace( "#\({$wpdb->posts}.post_title LIKE [^)]+\)\K#", $wpdb->prepare( $sql, $like[0], $like[1], $like[2], $like[3], $like[4] ), $search ); |
| 247 |
} |
| 248 |
|
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
return $search; |
| 253 |
} |
| 254 |
|
| 255 |
/*********************************** Link Library Class *****************************************************************************/ |
| 256 |
class link_library_plugin { |
| 257 |
|
| 258 |
//constructor of class, PHP4 compatible construction for backward compatibility |
| 259 |
function __construct() { |
| 260 |
|
| 261 |
// Functions to be called when plugin is activated and deactivated |
| 262 |
register_activation_hook( __FILE__, array( $this, 'll_install' ) ); |
| 263 |
register_deactivation_hook( __FILE__, array( $this, 'll_uninstall' ) ); |
| 264 |
|
| 265 |
add_action( 'init', array( $this, 'll_init' ) ); |
| 266 |
add_action( 'wp_loaded', array( $this, 'll_update_60' ) ); |
| 267 |
|
| 268 |
$newoptions = get_option( 'LinkLibraryPP1', '' ); |
| 269 |
|
| 270 |
if ( empty( $newoptions ) ) { |
| 271 |
global $my_link_library_plugin_admin; |
| 272 |
|
| 273 |
if ( empty( $my_link_library_plugin_admin ) ) { |
| 274 |
require plugin_dir_path( __FILE__ ) . 'link-library-admin.php'; |
| 275 |
$my_link_library_plugin_admin = new link_library_plugin_admin(); |
| 276 |
} |
| 277 |
|
| 278 |
ll_reset_options( 1, 'list', 'return_and_set' ); |
| 279 |
ll_reset_gen_settings( 'return_and_set' ); |
| 280 |
} |
| 281 |
|
| 282 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 283 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 284 |
|
| 285 |
// Add short codes |
| 286 |
add_shortcode( 'link-library', array( $this, 'link_library_func' ) ); |
| 287 |
add_shortcode( 'link-library-cats', array( $this, 'link_library_cats_func' ) ); |
| 288 |
add_shortcode( 'cats-link-library', array( $this, 'link_library_cats_func' ) ); |
| 289 |
add_shortcode( 'link-library-search', array( $this, 'link_library_search_func' ) ); |
| 290 |
add_shortcode( 'search-link-library', array( $this, 'link_library_search_func' ) ); |
| 291 |
add_shortcode( 'link-library-addlink', array( $this, 'link_library_addlink_func' ) ); |
| 292 |
add_shortcode( 'addlink-link-library', array( $this, 'link_library_addlink_func' ) ); |
| 293 |
add_shortcode( 'link-library-addlinkcustommsg', array( $this, 'link_library_addlink_func' ) ); |
| 294 |
add_shortcode( 'addlinkcustommsg-link-library', array( $this, 'link_library_addlink_func' ) ); |
| 295 |
add_shortcode( 'link-library-count', array( $this, 'link_library_count_func' ) ); |
| 296 |
add_shortcode( 'link-library-filters', array( $this, 'link_library_filters' ) ); |
| 297 |
add_shortcode( 'link-library-tagcloud', array( $this, 'link_library_tagcloud' ) ); |
| 298 |
add_shortcode( 'rss-library', array( $this, 'rss_library_func' ) ); |
| 299 |
|
| 300 |
// Function to determine if Link Library is used on a page before printing headers |
| 301 |
// the_posts gets triggered before wp_head |
| 302 |
add_filter( 'the_posts', array( $this, 'conditionally_add_scripts_and_styles' ) ); |
| 303 |
|
| 304 |
// Function to print information in page header when plugin present |
| 305 |
add_action( 'wp_head', array( $this, 'll_rss_link' ) ); |
| 306 |
|
| 307 |
add_filter( 'wp_title', array( $this, 'll_title_creator' ) ); |
| 308 |
|
| 309 |
add_filter( 'get_the_excerpt', array( $this, 'll_display_single_link' ) ); |
| 310 |
add_filter( 'the_excerpt', array( $this, 'll_display_single_link' ) ); |
| 311 |
add_filter( 'post_type_link', array( $this, 'll_get_permalink' ), 10, 4 ); |
| 312 |
add_filter( 'the_title', array( $this, 'll_get_title' ), 10, 2 ); |
| 313 |
|
| 314 |
add_filter( 'block_categories_all', array( $this, 'll_block_categories' ), 10, 2 ); |
| 315 |
add_action( 'rest_api_init', array( $this, 'll_rest_api_init' ) ); |
| 316 |
|
| 317 |
|
| 318 |
// Re-write rules filters to allow for custom permalinks |
| 319 |
add_filter( 'rewrite_rules_array', array( $this, 'll_insertMyRewriteRules' ) ); |
| 320 |
add_filter( 'query_vars', array( $this, 'll_insertMyRewriteQueryVars' ) ); |
| 321 |
|
| 322 |
add_action( 'template_redirect', array( $this, 'll_template_redirect' ) ); |
| 323 |
add_filter( 'template_include', array( $this, 'll_template_include' ) ); |
| 324 |
add_action( 'wp_ajax_link_library_tracker', array( $this, 'link_library_ajax_tracker' ) ); |
| 325 |
add_action( 'wp_ajax_nopriv_link_library_tracker', array( $this, 'link_library_ajax_tracker' ) ); |
| 326 |
add_action( 'wp_ajax_link_library_ajax_update', array( $this, 'link_library_func') ); |
| 327 |
add_action( 'wp_ajax_nopriv_link_library_ajax_update', array( $this, 'link_library_func') ); |
| 328 |
add_action( 'wp_ajax_link_library_generate_image', array( $this, 'link_library_generate_image') ); |
| 329 |
add_action( 'wp_ajax_nopriv_link_library_generate_image', array( $this, 'link_library_generate_image') ); |
| 330 |
add_action( 'wp_ajax_link_library_popup_content', array( $this, 'll_popup_content') ); |
| 331 |
add_action( 'wp_ajax_nopriv_link_library_popup_content', array( $this, 'll_popup_content') ); |
| 332 |
|
| 333 |
add_action( 'wp_enqueue_scripts', array( $this, 'll_register_script' ) ); |
| 334 |
|
| 335 |
add_filter( 'posts_where', array( $this, 'll_posts_where' ), 10, 2 ); |
| 336 |
|
| 337 |
// Load text domain for translation of admin pages and text strings |
| 338 |
load_plugin_textdomain( 'link-library', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
| 339 |
|
| 340 |
add_filter( 'kses_allowed_protocols', array( $this, 'll_add_protocols' ) ); |
| 341 |
|
| 342 |
add_filter( 'wp_feed_cache_transient_lifetime' , array( $this, 'feed_cache_filter_handler' ) ); |
| 343 |
|
| 344 |
add_filter( 'post_type_link', array( $this, 'permalink_structure' ), 10, 4 ); |
| 345 |
|
| 346 |
add_action('auth_redirect', array( $this, 'add_pending_count_filter') ); // modify esc_attr on auth_redirect |
| 347 |
add_action('admin_menu', array( $this, 'esc_attr_restore' ) ); // restore on admin_menu (very soon) |
| 348 |
|
| 349 |
if ( $genoptions['add_to_main_rss'] ) { |
| 350 |
add_action( 'request', array( $this, 'link_library_rss_feed_request' ) ); |
| 351 |
add_filter( 'the_content_feed', array( $this, 'll_display_single_link' ) ); |
| 352 |
} |
| 353 |
|
| 354 |
add_action( 'link_library_import_links', array( $this, 'll_import_links' ), 10, 0 ); |
| 355 |
add_action( 'link_library_gen_thumbs', array( $this, 'll_gen_thumbs' ), 10, 0 ); |
| 356 |
} |
| 357 |
|
| 358 |
function ll_import_links() { |
| 359 |
require_once plugin_dir_path( __FILE__ ) . 'link-library-link-importer.php'; |
| 360 |
|
| 361 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 362 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 363 |
|
| 364 |
$row = 0; |
| 365 |
$successfulimport = 0; |
| 366 |
$successfulupdate = 0; |
| 367 |
|
| 368 |
link_library_import_links( $genoptions, $row, $successfulimport, $successfulupdate ); |
| 369 |
} |
| 370 |
|
| 371 |
function ll_gen_thumbs() { |
| 372 |
require_once plugin_dir_path( __FILE__ ) . 'link-library-image-generator.php'; |
| 373 |
|
| 374 |
$options = array(); |
| 375 |
$options['categorylist_cpt'] = ''; |
| 376 |
$options['uselocalimagesoverthumbshots'] = true; |
| 377 |
|
| 378 |
link_library_image_generator( $this, $options, true ); |
| 379 |
} |
| 380 |
|
| 381 |
function ll_rest_api_init() { |
| 382 |
register_rest_route( 'link-library/v1', '/settingslist', array( |
| 383 |
'methods' => 'GET', |
| 384 |
'callback' => array( $this, 'll_rest_settings_list' ), |
| 385 |
'permission_callback' => '__return_true' |
| 386 |
) ); |
| 387 |
} |
| 388 |
|
| 389 |
function ll_rest_settings_list( WP_REST_Request $request ) { |
| 390 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 391 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 392 |
|
| 393 |
if ( empty( $genoptions['numberstylesets'] ) ) { |
| 394 |
$numberofsets = 1; |
| 395 |
} else { |
| 396 |
$numberofsets = $genoptions['numberstylesets']; |
| 397 |
} |
| 398 |
$settings_array = array(); |
| 399 |
for ( $counter = 1; $counter <= $numberofsets; $counter ++ ) { |
| 400 |
$tempoptionname = "LinkLibraryPP" . $counter; |
| 401 |
$tempoptions = get_option( $tempoptionname ); |
| 402 |
|
| 403 |
if ( ! empty( $tempoptions ) && isset( $tempoptions['settingssetname'] ) ) { |
| 404 |
$settings_array[$counter] = $tempoptions['settingssetname']; |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
$response = new WP_REST_Response( $settings_array ); |
| 409 |
|
| 410 |
return $response; |
| 411 |
} |
| 412 |
|
| 413 |
function ll_block_categories( $categories, $post ) { |
| 414 |
return array_merge( |
| 415 |
$categories, |
| 416 |
array( |
| 417 |
array( |
| 418 |
'slug' => 'link-library', |
| 419 |
'title' => __( 'Link Library', 'link-library' ), |
| 420 |
'icon' => 'wordpress', |
| 421 |
), |
| 422 |
) |
| 423 |
); |
| 424 |
} |
| 425 |
|
| 426 |
function ll_posts_where( $where, $query ) { |
| 427 |
global $wpdb; |
| 428 |
|
| 429 |
$starts_with = $query->get( 'link_starts_with' ); |
| 430 |
|
| 431 |
if ( $starts_with ) { |
| 432 |
$where .= " AND $wpdb->posts.post_title LIKE '$starts_with%'"; |
| 433 |
} |
| 434 |
|
| 435 |
return $where; |
| 436 |
} |
| 437 |
|
| 438 |
function link_library_rss_feed_request( $qv ) { |
| 439 |
|
| 440 |
if ( isset( $qv['feed'] ) && !isset( $qv['post_type'] ) ) { |
| 441 |
$qv['post_type'] = array( 'post', 'link_library_links' ); |
| 442 |
} elseif ( isset( $qv['feed'] ) && isset( $qv['post_type'] ) ) { |
| 443 |
$qv['post_type'][] = 'link_library_links'; |
| 444 |
} |
| 445 |
|
| 446 |
return $qv; |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
function add_pending_count_filter() { |
| 451 |
add_filter('attribute_escape', array( $this, 'remove_esc_attr_and_count' ), 20, 2); |
| 452 |
} |
| 453 |
|
| 454 |
function esc_attr_restore() { |
| 455 |
remove_filter('attribute_escape', array( $this, 'remove_esc_attr_and_count' ), 20, 2); |
| 456 |
} |
| 457 |
|
| 458 |
function remove_esc_attr_and_count( $safe_text = '', $text = '' ) { |
| 459 |
if ( substr_count($text, '%%PENDING_COUNT%%') ) { |
| 460 |
$text = trim( str_replace('%%PENDING_COUNT%%', '', $text) ); |
| 461 |
// run only once! |
| 462 |
remove_filter('attribute_escape', 'remove_esc_attr_and_count', 20, 2); |
| 463 |
$safe_text = esc_attr($text); |
| 464 |
// remember to set the right cpt name below |
| 465 |
$linkmoderatecount = 0; |
| 466 |
|
| 467 |
$args = array( |
| 468 |
'numberposts' => -1, |
| 469 |
'post_type' => 'link_library_links', |
| 470 |
'post_status' => array( 'pending' ) |
| 471 |
); |
| 472 |
$linkmoderatecount = count( get_posts( $args ) ); |
| 473 |
if ( $linkmoderatecount > 0 ) { |
| 474 |
// we have pending, add the count |
| 475 |
$text = esc_attr($text) . '<span class="awaiting-mod count-' . $linkmoderatecount . '"><span class="pending-count">' . $linkmoderatecount . '</span></span>'; |
| 476 |
return $text; |
| 477 |
} |
| 478 |
} |
| 479 |
return $safe_text; |
| 480 |
} |
| 481 |
|
| 482 |
function feed_cache_filter_handler( $seconds ) { |
| 483 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 484 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 485 |
|
| 486 |
return $genoptions['rsscachedelay']; |
| 487 |
} |
| 488 |
|
| 489 |
function ll_init() { |
| 490 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 491 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 492 |
|
| 493 |
$post_type_args = array( |
| 494 |
'labels' => array( |
| 495 |
'name' => __( 'Link Library', 'link-library' ), |
| 496 |
'singular_name' => __( 'Link', 'link-library' ), |
| 497 |
'add_new' => __( 'Add New', 'link-library' ), |
| 498 |
'add_new_item' => __( 'Add New Link', 'link-library' ), |
| 499 |
'edit' => __( 'Edit', 'link-library' ), |
| 500 |
'edit_item' => __( 'Edit Link', 'link-library' ), |
| 501 |
'new_item' => __( 'New Link', 'link-library' ), |
| 502 |
'view' => __( 'View', 'link-library' ), |
| 503 |
'view_item' => __( 'View Link', 'link-library' ), |
| 504 |
'search_items' => __( 'Search Links', 'link-library' ), |
| 505 |
'not_found' => __( 'No Links found', 'link-library' ), |
| 506 |
'not_found_in_trash' => __( 'No Links found in Trash', 'link-library' ), |
| 507 |
'parent' => __( 'Parent Link', 'link-library' ), |
| 508 |
'all_items' => __( 'All Links', 'link-library' ), |
| 509 |
'menu_name' => _x('Link Library %%PENDING_COUNT%%', 'Link Library', 'link-library'), |
| 510 |
), |
| 511 |
'show_in_nav_menu' => true, |
| 512 |
'show_ui' => true, |
| 513 |
'exclude_from_search' => !$genoptions['exclude_from_search'], |
| 514 |
'publicly_queryable' => $genoptions['publicly_queryable'], |
| 515 |
'menu_position' => 10, |
| 516 |
'supports' => |
| 517 |
array( 'title', 'editor', 'comments' ), |
| 518 |
'taxonomies' => array( $genoptions['cattaxonomy'], $genoptions['tagtaxonomy'] ), |
| 519 |
'menu_icon' => |
| 520 |
'dashicons-admin-links', |
| 521 |
'has_archive' => false, |
| 522 |
'rewrite' => array( 'slug' => $genoptions['cptslug'] . '/%' . $genoptions['cattaxonomy'] . '%' ) |
| 523 |
); |
| 524 |
|
| 525 |
if ( class_exists( 'WPGraphQL' ) ) { |
| 526 |
$post_type_args['show_in_graphql'] = true; |
| 527 |
$post_type_args['hierarchical'] = true; |
| 528 |
$post_type_args['graphql_single_name'] = 'linklibrary'; |
| 529 |
$post_type_args['graphql_plural_name'] = 'linklibrary'; |
| 530 |
} |
| 531 |
|
| 532 |
if ( $genoptions['exclude_from_search'] && $genoptions['publicly_queryable'] ) { |
| 533 |
unset( $post_type_args['exclude_from_search'] ); |
| 534 |
unset( $post_type_args['publicly_queryable'] ); |
| 535 |
$post_type_args['public'] = true; |
| 536 |
} |
| 537 |
|
| 538 |
if ( $genoptions['showexcerpt'] ) { |
| 539 |
$post_type_args['supports'][] = 'excerpt'; |
| 540 |
} |
| 541 |
|
| 542 |
register_post_type( 'link_library_links', $post_type_args ); |
| 543 |
|
| 544 |
register_taxonomy( |
| 545 |
'link_library_category', |
| 546 |
'link_library_links', |
| 547 |
array( |
| 548 |
'labels' => array( |
| 549 |
'name' => __( 'Link Library Categories', 'link-library' ), |
| 550 |
'add_new_item' => __( 'Add New Link Library Category', 'link-library' ), |
| 551 |
'new_item_name' => __( 'New Link Library Category', 'link-library' ) |
| 552 |
), |
| 553 |
'show_ui' => ( $genoptions['cattaxonomy'] == 'link_library_category' ? true : false ), |
| 554 |
'show_tagcloud' => false, |
| 555 |
'hierarchical' => true, |
| 556 |
'rewrite' => $genoptions['publicly_queryable'], |
| 557 |
'show_in_rest' => true |
| 558 |
) |
| 559 |
); |
| 560 |
|
| 561 |
register_taxonomy( |
| 562 |
'link_library_tags', |
| 563 |
'link_library_links', |
| 564 |
array( |
| 565 |
'hierarchical' => false, |
| 566 |
'labels' => array( 'name' => __( 'Tags', 'link-library' ), |
| 567 |
'add_new_item' => __( 'Add New Link Library Tag', 'link-library' ), |
| 568 |
'new_item_name' => __( 'New Link Library Tag', 'link-library' ) ), |
| 569 |
'show_ui' => ( $genoptions['tagtaxonomy'] == 'link_library_tags' ? true : false ), |
| 570 |
'rewrite' => false, |
| 571 |
'show_in_rest' => true |
| 572 |
) |
| 573 |
); |
| 574 |
|
| 575 |
add_feed( 'linklibraryfeed', 'link_library_generate_rss_feed' ); |
| 576 |
|
| 577 |
if ( function_exists( 'register_block_type' ) ) { |
| 578 |
$asset_file = include( plugin_dir_path( __FILE__ ) . 'build/index.asset.php'); |
| 579 |
|
| 580 |
wp_register_script( |
| 581 |
'link-library-block', |
| 582 |
plugins_url( 'build/index.js', __FILE__ ), |
| 583 |
$asset_file['dependencies'], |
| 584 |
$asset_file['version'] |
| 585 |
); |
| 586 |
|
| 587 |
register_block_type( 'link-library/link-block', array( |
| 588 |
'editor_script' => 'link-library-block', |
| 589 |
'render_callback' => array( $this, 'link_library_func' ), |
| 590 |
'attributes' => array( |
| 591 |
'settings' => array( |
| 592 |
'type' => 'string', |
| 593 |
'default' => '1', |
| 594 |
), |
| 595 |
'linkorderoverride' => array( |
| 596 |
'type' => 'string', |
| 597 |
'default' => '', |
| 598 |
), |
| 599 |
'linkdirectionoverride' => array( |
| 600 |
'type' => 'string', |
| 601 |
'default' => '', |
| 602 |
), |
| 603 |
'categorylistoverride' => array( |
| 604 |
'type' => 'array', |
| 605 |
'default' => array(), |
| 606 |
'items' => array( |
| 607 |
'type' => 'string', |
| 608 |
), |
| 609 |
), |
| 610 |
'excludecategoryoverride' => array( |
| 611 |
'type' => 'array', |
| 612 |
'default' => array(), |
| 613 |
'items' => array( |
| 614 |
'type' => 'string', |
| 615 |
), |
| 616 |
), |
| 617 |
'taglistoverride' => array( |
| 618 |
'type' => 'array', |
| 619 |
'default' => array(), |
| 620 |
'items' => array( |
| 621 |
'type' => 'string', |
| 622 |
), |
| 623 |
), |
| 624 |
'maxlinksoverride' => array( |
| 625 |
'type' => 'string', |
| 626 |
'default' => '', |
| 627 |
), |
| 628 |
'notesoverride' => array( |
| 629 |
'type' => 'boolean', |
| 630 |
'default' => false, |
| 631 |
), |
| 632 |
'descoverride' => array( |
| 633 |
'type' => 'boolean', |
| 634 |
'default' => false, |
| 635 |
), |
| 636 |
'rssoverride' => array( |
| 637 |
'type' => 'boolean', |
| 638 |
'default' => false, |
| 639 |
), |
| 640 |
'categorylistoverrideCSV' => array( |
| 641 |
'type' => 'string', |
| 642 |
'default' => '', |
| 643 |
), |
| 644 |
'excludecategoryoverrideCSV' => array( |
| 645 |
'type' => 'string', |
| 646 |
'default' => '', |
| 647 |
), |
| 648 |
'taglistoverrideCSV' => array( |
| 649 |
'type' => 'string', |
| 650 |
'default' => '', |
| 651 |
), |
| 652 |
), |
| 653 |
) ); |
| 654 |
|
| 655 |
register_block_type( 'link-library/cats-block', array( |
| 656 |
'editor_script' => 'link-library-block', |
| 657 |
'render_callback' => array( $this, 'link_library_cats_func' ), |
| 658 |
'attributes' => array( |
| 659 |
'settings' => array( |
| 660 |
'type' => 'string', |
| 661 |
'default' => '1', |
| 662 |
), |
| 663 |
'categorylistoverride' => array( |
| 664 |
'type' => 'array', |
| 665 |
'default' => array(), |
| 666 |
'items' => array( |
| 667 |
'type' => 'string', |
| 668 |
), |
| 669 |
), |
| 670 |
'excludecategoryoverride' => array( |
| 671 |
'type' => 'array', |
| 672 |
'default' => array(), |
| 673 |
'items' => array( |
| 674 |
'type' => 'string', |
| 675 |
), |
| 676 |
), |
| 677 |
'taglistoverride' => array( |
| 678 |
'type' => 'array', |
| 679 |
'default' => array(), |
| 680 |
'items' => array( |
| 681 |
'type' => 'string', |
| 682 |
), |
| 683 |
), |
| 684 |
'targetlibrary' => array( |
| 685 |
'type' => 'string', |
| 686 |
'default' => '', |
| 687 |
), |
| 688 |
'categorylistoverrideCSV' => array( |
| 689 |
'type' => 'string', |
| 690 |
'default' => '', |
| 691 |
), |
| 692 |
'excludecategoryoverrideCSV' => array( |
| 693 |
'type' => 'string', |
| 694 |
'default' => '', |
| 695 |
), |
| 696 |
'taglistoverrideCSV' => array( |
| 697 |
'type' => 'string', |
| 698 |
'default' => '', |
| 699 |
), |
| 700 |
), |
| 701 |
) ); |
| 702 |
|
| 703 |
register_block_type( 'link-library/addlink-block', array( |
| 704 |
'editor_script' => 'link-library-block', |
| 705 |
'render_callback' => array( $this, 'link_library_addlink_func' ), |
| 706 |
'attributes' => array( |
| 707 |
'settings' => array( |
| 708 |
'type' => 'string', |
| 709 |
'default' => '1', |
| 710 |
), |
| 711 |
), |
| 712 |
) ); |
| 713 |
|
| 714 |
register_block_type( 'link-library/search-block', array( |
| 715 |
'editor_script' => 'link-library-block', |
| 716 |
'render_callback' => array( $this, 'link_library_search_func' ), |
| 717 |
'attributes' => array( |
| 718 |
'settings' => array( |
| 719 |
'type' => 'string', |
| 720 |
'default' => '1', |
| 721 |
), |
| 722 |
), |
| 723 |
) ); |
| 724 |
|
| 725 |
register_block_type( 'link-library/count-block', array( |
| 726 |
'editor_script' => 'link-library-block', |
| 727 |
'render_callback' => array( $this, 'link_library_count_func' ), |
| 728 |
'attributes' => array( |
| 729 |
'settings' => array( |
| 730 |
'type' => 'string', |
| 731 |
'default' => '1', |
| 732 |
), |
| 733 |
), |
| 734 |
) ); |
| 735 |
} |
| 736 |
} |
| 737 |
|
| 738 |
function link_library_block_callback( $attributes ) { |
| 739 |
$settings = 1; |
| 740 |
|
| 741 |
if ( isset( $attributes['settingsid']) && !empty( $attributes['settingsid'] ) ) { |
| 742 |
$settings = $attributes['settingsid']; |
| 743 |
$settings = link_library_validate_settings_number( $settings ); |
| 744 |
} |
| 745 |
|
| 746 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 747 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 748 |
|
| 749 |
$linkcount = 1; |
| 750 |
|
| 751 |
$settingsname = 'LinkLibraryPP' . $settings; |
| 752 |
$options = get_option( $settingsname ); |
| 753 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 754 |
|
| 755 |
if ( isset( $attributes['categoryOverrideArray'] ) && !empty( $attributes['categoryOverrideArray'] ) ) { |
| 756 |
$options['categorylist_cpt'] = implode( ',', $attributes['categoryOverrideArray'] ); |
| 757 |
} |
| 758 |
|
| 759 |
require_once plugin_dir_path( __FILE__ ) . 'render-link-library-sc.php'; |
| 760 |
|
| 761 |
return RenderLinkLibrary( $linkcount, $this, $genoptions, $options, $settings, false, 0, 0, true, false ); |
| 762 |
} |
| 763 |
|
| 764 |
function link_library_cats_block_callback( $attributes ) { |
| 765 |
$settings = 1; |
| 766 |
|
| 767 |
if ( isset( $attributes['settingsid']) && !empty( $attributes['settingsid'] ) ) { |
| 768 |
$settings = $attributes['settingsid']; |
| 769 |
$settings = link_library_validate_settings_number( $settings ); |
| 770 |
} |
| 771 |
|
| 772 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 773 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 774 |
|
| 775 |
$linkcount = 1; |
| 776 |
|
| 777 |
$settingsname = 'LinkLibraryPP' . $settings; |
| 778 |
$options = get_option( $settingsname ); |
| 779 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 780 |
|
| 781 |
if ( isset( $attributes['categoryOverrideArray'] ) && !empty( $attributes['categoryOverrideArray'] ) ) { |
| 782 |
$options['categorylist_cpt'] = implode( ',', $attributes['categoryOverrideArray'] ); |
| 783 |
} |
| 784 |
$targetlibrary = $settings; |
| 785 |
|
| 786 |
require_once plugin_dir_path( __FILE__ ) . 'render-link-library-cats-sc.php'; |
| 787 |
|
| 788 |
return RenderLinkLibraryCategories( $this, $genoptions, $options, $settings, $targetlibrary ); |
| 789 |
} |
| 790 |
|
| 791 |
function ll_update_60() { |
| 792 |
|
| 793 |
$link_library_60_update = get_option( 'LinkLibrary60Update' ); |
| 794 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 795 |
|
| 796 |
if ( isset( $_GET['ll60reupdate'] ) ) { |
| 797 |
if ( !current_user_can( 'manage_options' ) ) { |
| 798 |
return; |
| 799 |
} |
| 800 |
|
| 801 |
check_admin_referer( 'll60reupdate' ); |
| 802 |
|
| 803 |
global $wpdb; |
| 804 |
|
| 805 |
$wpdb->get_results ( 'DELETE a,b,c |
| 806 |
FROM wp_posts a |
| 807 |
LEFT JOIN wp_term_relationships b |
| 808 |
ON (a.ID = b.object_id) |
| 809 |
LEFT JOIN wp_postmeta c |
| 810 |
ON (a.ID = c.post_id) |
| 811 |
WHERE a.post_type = \'link_library_links\';' ); |
| 812 |
|
| 813 |
$link_category_terms = get_terms( 'link_library_category', array( 'fields' => 'ids', 'hide_empty' => false ) ); |
| 814 |
foreach ( $link_category_terms as $value ) { |
| 815 |
wp_delete_term( $value, 'link_library_category' ); |
| 816 |
} |
| 817 |
|
| 818 |
require plugin_dir_path( __FILE__ ) . 'link-library-update-60.php'; |
| 819 |
link_library_60_update( $this ); |
| 820 |
} elseif ( isset( $_GET['continue60update'] ) ) { |
| 821 |
if ( !current_user_can( 'manage_options' ) ) { |
| 822 |
return; |
| 823 |
} |
| 824 |
|
| 825 |
require plugin_dir_path( __FILE__ ) . 'link-library-update-60.php'; |
| 826 |
link_library_60_update( $this, true ); |
| 827 |
} else { |
| 828 |
if ( ( false == $link_library_60_update && !empty( $genoptions ) ) ) { |
| 829 |
if ( !current_user_can( 'manage_options' ) ) { |
| 830 |
return; |
| 831 |
} |
| 832 |
|
| 833 |
require plugin_dir_path( __FILE__ ) . 'link-library-update-60.php'; |
| 834 |
link_library_60_update( $this ); |
| 835 |
} |
| 836 |
} |
| 837 |
} |
| 838 |
|
| 839 |
function permalink_structure( $post_link, $post, $leavename, $sample ) { |
| 840 |
|
| 841 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 842 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 843 |
|
| 844 |
if ( $post->post_type == 'link_library_links' ) { |
| 845 |
if ( !$genoptions['publicly_queryable'] ) { |
| 846 |
$link_url = get_post_meta( $post->ID, 'link_url', true ); |
| 847 |
|
| 848 |
if ( !empty( $link_url ) ) { |
| 849 |
$post_link = $link_url; |
| 850 |
} |
| 851 |
} else { |
| 852 |
if ( !empty( $post_link ) && false !== strpos( $post_link, '%' . $genoptions['cattaxonomy'] . '%' ) ) { |
| 853 |
$link_cat_type_term = get_the_terms( $post->ID, $genoptions['cattaxonomy'] ); |
| 854 |
if ( !empty( $link_cat_type_term ) ) { |
| 855 |
$post_link = str_replace( '%' . $genoptions['cattaxonomy'] . '%', array_pop( $link_cat_type_term )->slug, $post_link ); |
| 856 |
} |
| 857 |
} |
| 858 |
} |
| 859 |
} |
| 860 |
|
| 861 |
return $post_link; |
| 862 |
} |
| 863 |
|
| 864 |
/************************** Link Library Installation Function **************************/ |
| 865 |
function ll_install() { |
| 866 |
global $wpdb; |
| 867 |
|
| 868 |
if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
| 869 |
if ( isset( $_GET['networkwide'] ) && ( $_GET['networkwide'] == 1 ) ) { |
| 870 |
$originalblog = $wpdb->blogid; |
| 871 |
|
| 872 |
$bloglist = $wpdb->get_col( 'SELECT blog_id FROM ' . $wpdb->blogs ); |
| 873 |
foreach ( $bloglist as $blog ) { |
| 874 |
switch_to_blog( $blog ); |
| 875 |
$this->create_table_and_settings(); |
| 876 |
} |
| 877 |
switch_to_blog( $originalblog ); |
| 878 |
return; |
| 879 |
} |
| 880 |
} |
| 881 |
$this->create_table_and_settings(); |
| 882 |
} |
| 883 |
|
| 884 |
function new_network_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) { |
| 885 |
global $wpdb; |
| 886 |
|
| 887 |
if ( ! function_exists( 'is_plugin_active_for_network' ) ) |
| 888 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
| 889 |
|
| 890 |
if ( is_plugin_active_for_network( 'link-library/link-library.php' ) ) { |
| 891 |
$originalblog = $wpdb->blogid; |
| 892 |
switch_to_blog( $blog_id ); |
| 893 |
$this->create_table_and_settings(); |
| 894 |
switch_to_blog( $originalblog ); |
| 895 |
} |
| 896 |
} |
| 897 |
|
| 898 |
function create_table_and_settings() { |
| 899 |
global $wpdb; |
| 900 |
|
| 901 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 902 |
|
| 903 |
if ( !empty( $genoptions ) ) { |
| 904 |
if ( empty( $genoptions['schemaversion'] ) || floatval( $genoptions['schemaversion'] ) < 3.5 ) { |
| 905 |
$genoptions['schemaversion'] = '3.5'; |
| 906 |
update_option( 'LinkLibraryGeneral', $genoptions ); |
| 907 |
} elseif ( floatval( $genoptions['schemaversion'] ) < '4.6' ) { |
| 908 |
$genoptions['schemaversion'] = '4.6'; |
| 909 |
update_option( 'LinkLibraryGeneral', $genoptions ); |
| 910 |
} elseif ( floatval( $genoptions['schemaversion'] ) < '4.7' ) { |
| 911 |
$genoptions['schemaversion'] = '4.7'; |
| 912 |
update_option( 'LinkLibraryGeneral', $genoptions ); |
| 913 |
} elseif ( floatval( $genoptions['schemaversion'] ) < '4.9' ) { |
| 914 |
$genoptions['schemaversion'] = '4.9'; |
| 915 |
update_option( 'LinkLibraryGeneral', $genoptions ); |
| 916 |
} |
| 917 |
|
| 918 |
for ( $i = 1; $i <= $genoptions['numberstylesets']; $i++ ) { |
| 919 |
$settingsname = 'LinkLibraryPP' . $i; |
| 920 |
$options = get_option( $settingsname ); |
| 921 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 922 |
|
| 923 |
if ( !empty( $options ) ) { |
| 924 |
if ( empty( $options['showname'] ) ) { |
| 925 |
$options['showname'] = true; |
| 926 |
} |
| 927 |
|
| 928 |
if ( isset( $options['show_image_and_name'] ) && $options['show_image_and_name'] == true ) { |
| 929 |
$options['showname'] = true; |
| 930 |
$options['show_images'] = true; |
| 931 |
} |
| 932 |
|
| 933 |
if ( empty( $options['sourcename'] ) ) { |
| 934 |
$options['sourcename'] = 'primary'; |
| 935 |
} |
| 936 |
|
| 937 |
if ( empty( $options['sourceimage'] ) ) { |
| 938 |
$options['sourceimage'] = 'primary'; |
| 939 |
} |
| 940 |
|
| 941 |
if ( empty( $options['dragndroporder'] ) ) { |
| 942 |
if ( $options['imagepos'] == 'beforename' ) { |
| 943 |
$options['dragndroporder'] = '1,2,3,4,5,6,7,8,9,10,11,12'; |
| 944 |
} elseif ( $options['imagepos'] == 'aftername' ) { |
| 945 |
$options['dragndroporder'] = '2,1,3,4,5,6,7,8,9,10,11,12'; |
| 946 |
} elseif ( $options['imagepos'] == 'afterrssicons' ) { |
| 947 |
$options['dragndroporder'] = '2,3,4,5,6,1,7,8,9,10,11,12'; |
| 948 |
} |
| 949 |
} else if ( !empty( $options['dragndroporder'] ) ) { |
| 950 |
$elementarray = explode( ',', $options['dragndroporder'] ); |
| 951 |
|
| 952 |
$allelements = array( '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12' ); |
| 953 |
foreach ( $allelements as $element ) { |
| 954 |
if ( !in_array( $element, $elementarray ) ) { |
| 955 |
$elementarray[] = $element; |
| 956 |
$options['dragndroporder'] = implode( ',', $elementarray ); |
| 957 |
} |
| 958 |
} |
| 959 |
} |
| 960 |
|
| 961 |
if ( $options['flatlist'] === true ) { |
| 962 |
$options['flatlist'] = 'unordered'; |
| 963 |
} elseif ( $options['flatlist'] === false ) { |
| 964 |
$options['flatlist'] = 'table'; |
| 965 |
} |
| 966 |
} |
| 967 |
|
| 968 |
update_option( $settingsname, $options ); |
| 969 |
} |
| 970 |
} else { |
| 971 |
update_option( 'LinkLibrary60Update', true ); |
| 972 |
} |
| 973 |
|
| 974 |
$genoptions['schemaversion'] = '5.0'; |
| 975 |
update_option( 'LinkLibraryGeneral', $genoptions ); |
| 976 |
} |
| 977 |
|
| 978 |
function remove_querystring_var( $url, $key ) { |
| 979 |
|
| 980 |
$keypos = strpos( $url, $key ); |
| 981 |
if ( $keypos ) { |
| 982 |
$ampersandpos = strpos( $url, '&', $keypos ); |
| 983 |
$newurl = substr( $url, 0, $keypos - 1 ); |
| 984 |
|
| 985 |
if ( $ampersandpos ) { |
| 986 |
$newurl .= substr($url, $ampersandpos); |
| 987 |
} |
| 988 |
} else { |
| 989 |
$newurl = $url; |
| 990 |
} |
| 991 |
|
| 992 |
return $newurl; |
| 993 |
} |
| 994 |
|
| 995 |
/************************** Link Library Uninstall Function **************************/ |
| 996 |
function ll_uninstall() { |
| 997 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 998 |
|
| 999 |
if ( !empty( $genoptions ) ) { |
| 1000 |
if ( isset( $genoptions['stylesheet'] ) && isset( $genoptions['fullstylesheet'] ) && !empty( $genoptions['stylesheet'] ) && empty( $genoptions['fullstylesheet'] ) ) { |
| 1001 |
$stylesheetlocation = plugins_url( $genoptions['stylesheet'], __FILE__ ); |
| 1002 |
if ( file_exists( $stylesheetlocation ) ) |
| 1003 |
$genoptions['fullstylesheet'] = file_get_contents( $stylesheetlocation ); |
| 1004 |
|
| 1005 |
update_option( 'LinkLibraryGeneral', $genoptions ); |
| 1006 |
} |
| 1007 |
} |
| 1008 |
} |
| 1009 |
|
| 1010 |
function ll_register_script() { |
| 1011 |
wp_register_script( 'form-validator', plugins_url( '/form-validator/jquery.form-validator.min.js' , __FILE__ ), array( 'jquery' ), '1.0.0', true ); |
| 1012 |
wp_register_script( 'tiptip', plugins_url( '/tiptip/jquery.tipTip.minified.js' , __FILE__ ), array( 'jquery' ), '1.0.0', true ); |
| 1013 |
} |
| 1014 |
|
| 1015 |
function db_prefix() { |
| 1016 |
global $wpdb; |
| 1017 |
if ( method_exists( $wpdb, 'get_blog_prefix' ) ) { |
| 1018 |
return $wpdb->get_blog_prefix(); |
| 1019 |
} else { |
| 1020 |
return $wpdb->prefix; |
| 1021 |
} |
| 1022 |
} |
| 1023 |
|
| 1024 |
function ll_add_protocols( $protocols ) { |
| 1025 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 1026 |
|
| 1027 |
if ( isset( $genoptions['extraprotocols'] ) && !empty( $genoptions['extraprotocols'] ) ) { |
| 1028 |
$extra_protocol_array = explode( ',', $genoptions['extraprotocols'] ); |
| 1029 |
|
| 1030 |
if ( !empty( $extra_protocol_array ) ) { |
| 1031 |
foreach( $extra_protocol_array as $extra_protocol ) { |
| 1032 |
$protocols[] = $extra_protocol; |
| 1033 |
} |
| 1034 |
} |
| 1035 |
} |
| 1036 |
|
| 1037 |
return $protocols; |
| 1038 |
} |
| 1039 |
|
| 1040 |
/******************************************** Print style data to header *********************************************/ |
| 1041 |
|
| 1042 |
function ll_rss_link() { |
| 1043 |
global $llstylesheet, $rss_settings, $settingssetsids; |
| 1044 |
|
| 1045 |
if ( !empty( $rss_settings ) ) { |
| 1046 |
$settingsname = 'LinkLibraryPP' . $rss_settings; |
| 1047 |
$options = get_option( $settingsname ); |
| 1048 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1049 |
|
| 1050 |
$feedtitle = ( empty( $options['rssfeedtitle'] ) ? __('Link Library Generated Feed', 'link-library') : $options['rssfeedtitle'] ); |
| 1051 |
|
| 1052 |
$xpath = $this->relativePath( dirname( __FILE__ ), ABSPATH ); |
| 1053 |
echo '<link rel="alternate" type="application/rss+xml" title="' . esc_html( stripslashes( $feedtitle ) ) . '" href="' . home_url('/feed/linklibraryfeed?settingsset=' . $rss_settings/* . '&xpath=' . $xpath*/) . '" />'; |
| 1054 |
unset( $xpath ); |
| 1055 |
} |
| 1056 |
|
| 1057 |
if ( $llstylesheet ) { |
| 1058 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 1059 |
if ( isset( $genoptions['fullstylesheet'] ) ) { |
| 1060 |
echo "<style id='LinkLibraryStyle' type='text/css'>\n"; |
| 1061 |
echo stripslashes( sanitize_text_field( $genoptions['fullstylesheet'] ) ); |
| 1062 |
echo "</style>\n"; |
| 1063 |
} |
| 1064 |
} |
| 1065 |
|
| 1066 |
if ( !empty( $settingssetsids ) ) { |
| 1067 |
$processedsettings = array(); |
| 1068 |
foreach ( $settingssetsids as $setting ) { |
| 1069 |
if ( !in_array( $setting, $processedsettings ) ) { |
| 1070 |
$setting = link_library_validate_settings_number( $setting ); |
| 1071 |
$processedsettings[] = $setting; |
| 1072 |
$settingsname = 'LinkLibraryPP' . $setting; |
| 1073 |
$options = get_option( $settingsname ); |
| 1074 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1075 |
|
| 1076 |
if ( !empty( $options['stylesheet'] ) ) { |
| 1077 |
echo "<style id='LinkLibrarySettings" . $setting . "Style' type='text/css'>\n"; |
| 1078 |
echo stripslashes( sanitize_text_field( $options['stylesheet'] ) ) . "\n"; |
| 1079 |
echo "</style>\n"; |
| 1080 |
} |
| 1081 |
} |
| 1082 |
} |
| 1083 |
} |
| 1084 |
} |
| 1085 |
|
| 1086 |
/****************************************** Add Link Category name to page title when option is present ********************************/ |
| 1087 |
function ll_title_creator( $title ) { |
| 1088 |
global $wp_query; |
| 1089 |
global $wpdb; |
| 1090 |
global $llstylesheet; |
| 1091 |
|
| 1092 |
if ( $llstylesheet ) { |
| 1093 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 1094 |
|
| 1095 |
$categoryname = ( isset( $wp_query->query_vars['cat_name'] ) ? $wp_query->query_vars['cat_name'] : '' ); |
| 1096 |
$catid = ( isset( $_GET['cat_id'] ) ? intval( $_GET['cat_id'] ) : '' ); |
| 1097 |
|
| 1098 |
$linkcatquery = 'SELECT t.name '; |
| 1099 |
$linkcatquery .= 'FROM ' . $this->db_prefix() . 'terms t LEFT JOIN ' . $this->db_prefix(). 'term_taxonomy tt ON (t.term_id = tt.term_id) '; |
| 1100 |
$linkcatquery .= 'LEFT JOIN ' . $this->db_prefix() . 'term_relationships tr ON (tt.term_taxonomy_id = tr.term_taxonomy_id) '; |
| 1101 |
$linkcatquery .= 'WHERE tt.taxonomy = "link_category" AND '; |
| 1102 |
|
| 1103 |
if ( !empty( $categoryname ) ) { |
| 1104 |
$linkcatquery .= 't.slug = "' . $categoryname . '"'; |
| 1105 |
$nicecatname = sanitize_text_field( $wpdb->get_var( $linkcatquery ) ); |
| 1106 |
return $title . $genoptions['pagetitleprefix'] . esc_html( $nicecatname ) . $genoptions['pagetitlesuffix']; |
| 1107 |
} elseif ( !empty( $catid ) ) { |
| 1108 |
$linkcatquery .= 't.term_id = "' . $catid . '"'; |
| 1109 |
$nicecatname = $wpdb->get_var( $linkcatquery ); |
| 1110 |
return $title . $genoptions['pagetitleprefix'] . $nicecatname . $genoptions['pagetitlesuffix']; |
| 1111 |
} |
| 1112 |
} |
| 1113 |
|
| 1114 |
return $title; |
| 1115 |
} |
| 1116 |
|
| 1117 |
function ll_get_permalink( $url, $post_id, $sample, $type ) { |
| 1118 |
if ( !is_admin() && is_search() && 'link_library_links' == get_post_type() ) { |
| 1119 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 1120 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 1121 |
|
| 1122 |
if ( $genoptions['globalsearchresultslinkurl'] ) { |
| 1123 |
$link_url = get_post_meta( get_the_ID(), 'link_url', true ); |
| 1124 |
|
| 1125 |
if ( !empty( $link_url ) ) { |
| 1126 |
return $link_url; |
| 1127 |
} |
| 1128 |
} |
| 1129 |
} |
| 1130 |
|
| 1131 |
return $url; |
| 1132 |
} |
| 1133 |
|
| 1134 |
function ll_get_title( $title, $id = null ) { |
| 1135 |
if ( !is_admin() && is_search() && 'link_library_links' == get_post_type() ) { |
| 1136 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 1137 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 1138 |
|
| 1139 |
$post = get_post( $id ); |
| 1140 |
if ( $post instanceof WP_Post && !empty( $genoptions['globalsearchresultstitleprefix'] ) ) { |
| 1141 |
return $genoptions['globalsearchresultstitleprefix'] . $title; |
| 1142 |
} |
| 1143 |
} |
| 1144 |
|
| 1145 |
return $title; |
| 1146 |
} |
| 1147 |
|
| 1148 |
/************************************* Function to add to rewrite rules for permalink support **********************************/ |
| 1149 |
function ll_insertMyRewriteRules( $rules ) { |
| 1150 |
$newrules = array(); |
| 1151 |
|
| 1152 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 1153 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 1154 |
|
| 1155 |
if ( !empty( $genoptions ) ) { |
| 1156 |
for ( $i = 1; $i <= $genoptions['numberstylesets']; $i++ ) { |
| 1157 |
$settingsname = 'LinkLibraryPP' . $i; |
| 1158 |
$options = get_option( $settingsname ); |
| 1159 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1160 |
|
| 1161 |
if ( $options['enablerewrite'] && !empty( $options['rewritepage'] ) ) { |
| 1162 |
if ( is_multisite() ) { |
| 1163 |
$newrules['(' . $options['rewritepage'] . ')/(.+?)$'] = 'index.php?pagename=$matches[2]&cat_name=$matches[3]'; |
| 1164 |
} else { |
| 1165 |
$newrules['(' . $options['rewritepage'] . ')/(.+?)$'] = 'index.php?pagename=$matches[1]&cat_name=$matches[2]'; |
| 1166 |
} |
| 1167 |
} |
| 1168 |
|
| 1169 |
if ( $options['publishrssfeed'] ) { |
| 1170 |
$xpath = $this->relativePath( dirname( __FILE__ ), ABSPATH ); |
| 1171 |
|
| 1172 |
if ( !empty( $options['rssfeedaddress'] ) ) { |
| 1173 |
$newrules['(' . $options['rssfeedaddress'] . ')/(.+?)$'] = home_url() . '/feed/linklibraryfeed?settingsset=$matches[1]'; |
| 1174 |
} |
| 1175 |
unset( $xpath ); |
| 1176 |
} |
| 1177 |
} |
| 1178 |
} |
| 1179 |
|
| 1180 |
return $newrules + $rules; |
| 1181 |
} |
| 1182 |
|
| 1183 |
// Adding the id var so that WP recognizes it |
| 1184 |
function ll_insertMyRewriteQueryVars( $vars ) { |
| 1185 |
array_push( $vars, 'cat_name' ); |
| 1186 |
return $vars; |
| 1187 |
} |
| 1188 |
|
| 1189 |
function relativePath( $from, $to, $ps = DIRECTORY_SEPARATOR ) { |
| 1190 |
$arFrom = explode( $ps, rtrim( $from, $ps ) ); |
| 1191 |
$arTo = explode( $ps, rtrim( $to, $ps ) ); |
| 1192 |
while( count( $arFrom ) && count( $arTo ) && ( $arFrom[0] == $arTo[0] ) ) { |
| 1193 |
array_shift( $arFrom ); |
| 1194 |
array_shift( $arTo ); |
| 1195 |
} |
| 1196 |
$return = str_pad( '', count($arFrom) * 3, '..'.$ps ) . implode( $ps, $arTo ); |
| 1197 |
|
| 1198 |
// Don't disclose anything about the path is it's not needed, i.e. is the standard |
| 1199 |
if( $return === '../../../' ) { |
| 1200 |
$return = ''; |
| 1201 |
} |
| 1202 |
|
| 1203 |
return $return; |
| 1204 |
} |
| 1205 |
|
| 1206 |
function CheckReciprocalLink( $RecipCheckAddress = '', $external_link = '', $request_type = 'reciprocal' ) { |
| 1207 |
|
| 1208 |
$response = wp_safe_remote_get( $external_link, array( 'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36', 'timeout' => 10 ) ); |
| 1209 |
|
| 1210 |
if( is_wp_error( $response ) ) { |
| 1211 |
return 'error_403'; |
| 1212 |
} elseif ( $response['response']['code'] == '200' ) { |
| 1213 |
|
| 1214 |
$original_protocol = ''; |
| 1215 |
$actual_protocol = ''; |
| 1216 |
|
| 1217 |
if ( false !== strpos( $external_link, 'http://' ) ) { |
| 1218 |
$original_protocol = 'http://'; |
| 1219 |
} else if ( false !== strpos( $external_link, 'https://' ) ) { |
| 1220 |
$original_protocol = 'https://'; |
| 1221 |
} |
| 1222 |
|
| 1223 |
if ( false !== strpos( $response['http_response']->get_response_object()->url, 'http://' ) ) { |
| 1224 |
$actual_protocol = 'http://'; |
| 1225 |
} else if ( false !== strpos( $response['http_response']->get_response_object()->url, 'https://' ) ) { |
| 1226 |
$actual_protocol = 'https://'; |
| 1227 |
} |
| 1228 |
|
| 1229 |
$link_url_without_protocol = str_replace( 'http://', '', $external_link ); |
| 1230 |
$link_url_without_protocol = str_replace( 'https://', '', $link_url_without_protocol ); |
| 1231 |
$link_url_without_protocol = rtrim( $link_url_without_protocol, '/' ); |
| 1232 |
|
| 1233 |
$response_url_without_protocol = str_replace( 'http://', '', $response['http_response']->get_response_object()->url ); |
| 1234 |
$response_url_without_protocol = str_replace( 'https://', '', $response_url_without_protocol ); |
| 1235 |
$response_url_without_protocol = rtrim( $response_url_without_protocol, '/' ); |
| 1236 |
|
| 1237 |
$parse_original_url = parse_url( $external_link ); |
| 1238 |
$parse_actual_url = parse_url( $response['http_response']->get_response_object()->url ); |
| 1239 |
|
| 1240 |
if ( ( 'broken' == $request_type || 'rss' == $request_type || 'secondary' == $request_type || 'image' == $request_type ) && $parse_original_url['host'] != $parse_actual_url['host'] ) { |
| 1241 |
$original_host_segments = explode( '.', $parse_original_url['host'] ); |
| 1242 |
$actual_host_segments = explode( '.', $parse_actual_url['host'] ); |
| 1243 |
|
| 1244 |
if ( sizeof( $actual_host_segments ) > sizeof( $original_host_segments ) ) { |
| 1245 |
if ( $original_host_segments[ sizeof( $original_host_segments ) - 1 ] == $actual_host_segments[ sizeof( $actual_host_segments ) - 1] && $original_host_segments[ sizeof( $original_host_segments ) - 2 ] == $actual_host_segments[ sizeof( $actual_host_segments ) - 2] ) { |
| 1246 |
return 'exists_subdomain_redirect'; |
| 1247 |
} |
| 1248 |
} |
| 1249 |
} |
| 1250 |
|
| 1251 |
if ( ( 'broken' == $request_type || 'rss' == $request_type || 'secondary' == $request_type || 'image' == $request_type ) && $parse_original_url['host'] == $parse_actual_url['host'] && $link_url_without_protocol != $response_url_without_protocol ) { |
| 1252 |
$basename = basename( $parse_actual_url['path'] ); |
| 1253 |
if ( false !== strpos( $basename, '.' ) ) { |
| 1254 |
return 'exists_redirected_fileurl'; |
| 1255 |
} else { |
| 1256 |
return 'exists_redirected_subfolder'; |
| 1257 |
} |
| 1258 |
} |
| 1259 |
|
| 1260 |
if ( ( 'broken' == $request_type || 'rss' == $request_type || 'secondary' == $request_type || 'image' == $request_type ) && $link_url_without_protocol != $response_url_without_protocol ) { |
| 1261 |
return 'exists_redirected'; |
| 1262 |
} elseif ( ( 'broken' == $request_type || 'rss' == $request_type || 'secondary' == $request_type || 'image' == $request_type ) && !empty( $original_protocol ) && !empty( $actual_protocol ) && $original_protocol != $actual_protocol ) { |
| 1263 |
return 'exists_protocol_redirect'; |
| 1264 |
} elseif ( ( 'broken' == $request_type || 'rss' == $request_type || 'secondary' == $request_type || 'image' == $request_type ) && empty( $RecipCheckAddress ) ) { |
| 1265 |
return 'exists_notfound'; |
| 1266 |
} else { |
| 1267 |
return 'exists_found'; |
| 1268 |
} |
| 1269 |
|
| 1270 |
if ( 'reciprocal' == $request_type && strpos( $response['body'], $RecipCheckAddress ) === false ) { |
| 1271 |
return 'exists_notfound'; |
| 1272 |
} elseif ( 'reciprocal' == $request_type && strpos( $response['body'], $RecipCheckAddress ) !== false ) { |
| 1273 |
return 'exists_found'; |
| 1274 |
} |
| 1275 |
} |
| 1276 |
|
| 1277 |
return 'unreachable'; |
| 1278 |
} |
| 1279 |
|
| 1280 |
/* Output for users trying to directly call Link Library function, as was possible in pre-1.0 versions */ |
| 1281 |
|
| 1282 |
function LinkLibraryCategories() { |
| 1283 |
return __( 'Link Library no longer supports calling this function with individual arguments. Please use the admin panel to configure Link Library and the do_shortcode function to use Link Library output in your code.', 'link-library' ); |
| 1284 |
} |
| 1285 |
|
| 1286 |
function LinkLibrary() { |
| 1287 |
return __( 'Link Library no longer supports calling this function with individual arguments. Please use the admin panel to configure Link Library and the do_shortcode function to use Link Library output in your code.', 'link-library' ); |
| 1288 |
} |
| 1289 |
|
| 1290 |
/********************************************** Function to Process [link-library-cats] shortcode *********************************************/ |
| 1291 |
|
| 1292 |
function link_library_cats_func( $atts ) { |
| 1293 |
$categorylistoverride = ''; |
| 1294 |
$excludecategoryoverride = ''; |
| 1295 |
$settings = ''; |
| 1296 |
$targetlibrary = ''; |
| 1297 |
|
| 1298 |
if ( isset( $atts['categorylistoverride'] ) && !empty( $atts['categorylistoverride'] ) && is_array( $atts['categorylistoverride'] ) ) { |
| 1299 |
$atts['categorylistoverride'] = implode( ',', $atts['categorylistoverride'] ); |
| 1300 |
} |
| 1301 |
|
| 1302 |
if ( isset( $atts['categorylistoverrideCSV'] ) && !empty( $atts['categorylistoverrideCSV'] ) ) { |
| 1303 |
$atts['categorylistoverride'] = $atts['categorylistoverrideCSV']; |
| 1304 |
} |
| 1305 |
|
| 1306 |
if ( isset( $atts['excludecategoryoverride'] ) && !empty( $atts['excludecategoryoverride'] ) && is_array( $atts['excludecategoryoverride'] ) ) { |
| 1307 |
$atts['excludecategoryoverride'] = implode( ',', $atts['excludecategoryoverride'] ); |
| 1308 |
} |
| 1309 |
|
| 1310 |
if ( isset( $atts['excludecategoryoverrideCSV'] ) && !empty( $atts['excludecategoryoverrideCSV'] ) ) { |
| 1311 |
$atts['excludecategoryoverride'] = $atts['excludecategoryoverrideCSV']; |
| 1312 |
} |
| 1313 |
|
| 1314 |
if ( isset( $atts['taglistoverride'] ) && !empty( $atts['taglistoverride'] ) && is_array( $atts['taglistoverride'] ) ) { |
| 1315 |
$atts['taglistoverride'] = implode( ',', $atts['taglistoverride'] ); |
| 1316 |
} |
| 1317 |
|
| 1318 |
if ( isset( $atts['taglistoverrideCSV'] ) && !empty( $atts['taglistoverrideCSV'] ) ) { |
| 1319 |
$atts['taglistoverrideCSV'] = $atts['taglistoverrideCSV']; |
| 1320 |
} |
| 1321 |
|
| 1322 |
extract( shortcode_atts( array ( |
| 1323 |
'categorylistoverride' => '', |
| 1324 |
'excludecategoryoverride' => '', |
| 1325 |
'settings' => '', |
| 1326 |
'targetlibrary' => '', |
| 1327 |
'taglistoverride' => '', |
| 1328 |
'parent_cat_id' => 0 |
| 1329 |
), $atts ) ); |
| 1330 |
|
| 1331 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 1332 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 1333 |
|
| 1334 |
if ( empty( $settings ) ) { |
| 1335 |
$settings = 1; |
| 1336 |
} |
| 1337 |
|
| 1338 |
if ( $settings > $genoptions['numberstylesets'] ) { |
| 1339 |
$settings = 1; |
| 1340 |
} |
| 1341 |
|
| 1342 |
$settings = link_library_validate_settings_number( $settings ); |
| 1343 |
$settingsname = 'LinkLibraryPP' . $settings; |
| 1344 |
$options = get_option( $settingsname ); |
| 1345 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1346 |
|
| 1347 |
if ( empty( $options ) ) { |
| 1348 |
$settingsname = 'LinkLibraryPP1'; |
| 1349 |
$options = get_option( $settingsname ); |
| 1350 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1351 |
} |
| 1352 |
|
| 1353 |
if ( !empty( $categorylistoverride ) ) { |
| 1354 |
$options['categorylist_cpt'] = $categorylistoverride; |
| 1355 |
|
| 1356 |
$update_list = false; |
| 1357 |
$category_list_array = explode( ',', $categorylistoverride ); |
| 1358 |
foreach( $category_list_array as $index => $category_text ) { |
| 1359 |
if ( !is_numeric( $category_text ) ) { |
| 1360 |
$update_list = true; |
| 1361 |
$matched_term = get_term_by( 'slug', $category_text, $genoptions['cattaxonomy'] ); |
| 1362 |
|
| 1363 |
if ( $matched_term ) { |
| 1364 |
$category_list_array[$index] = $matched_term->term_id; |
| 1365 |
} else { |
| 1366 |
unset( $category_list_array[$index] ); |
| 1367 |
} |
| 1368 |
} |
| 1369 |
} |
| 1370 |
if ( $update_list ) { |
| 1371 |
$options['categorylist_cpt'] = implode( ',', $category_list_array ); |
| 1372 |
} |
| 1373 |
} |
| 1374 |
|
| 1375 |
if ( !empty( $excludecategoryoverride ) ) { |
| 1376 |
$options['excludecategorylist_cpt'] = $excludecategoryoverride; |
| 1377 |
|
| 1378 |
$update_list = false; |
| 1379 |
$exclude_category_list_array = explode( ',', $excludecategoryoverride ); |
| 1380 |
foreach( $exclude_category_list_array as $index => $category_text ) { |
| 1381 |
if ( !is_numeric( $category_text ) ) { |
| 1382 |
$update_list = true; |
| 1383 |
$matched_term = get_term_by( 'slug', $category_text, $genoptions['cattaxonomy'] ); |
| 1384 |
|
| 1385 |
if ( $matched_term ) { |
| 1386 |
$exclude_category_list_array[$index] = $matched_term->term_id; |
| 1387 |
} else { |
| 1388 |
unset( $exclude_category_list_array[$index] ); |
| 1389 |
} |
| 1390 |
} |
| 1391 |
} |
| 1392 |
if ( $update_list ) { |
| 1393 |
$options['categorylist_cpt'] = implode( ',', $exclude_category_list_array ); |
| 1394 |
} |
| 1395 |
} |
| 1396 |
|
| 1397 |
if ( !empty( $taglistoverride ) ) { |
| 1398 |
$options['taglist_cpt'] = $taglistoverride; |
| 1399 |
|
| 1400 |
$update_list = false; |
| 1401 |
$tag_list_array = explode( ',', $taglistoverride ); |
| 1402 |
foreach( $tag_list_array as $index => $tag_text ) { |
| 1403 |
if ( !is_numeric( $tag_text ) ) { |
| 1404 |
$update_list = true; |
| 1405 |
$matched_term = get_term_by( 'slug', $tag_text, $genoptions['tagtaxonomy'] ); |
| 1406 |
|
| 1407 |
if ( $matched_term ) { |
| 1408 |
$tag_list_array[$index] = $matched_term->term_id; |
| 1409 |
} else { |
| 1410 |
unset( $tag_list_array[$index] ); |
| 1411 |
} |
| 1412 |
} |
| 1413 |
} |
| 1414 |
if ( $update_list ) { |
| 1415 |
$options['taglist_cpt'] = implode( ',', $tag_list_array ); |
| 1416 |
} |
| 1417 |
} |
| 1418 |
|
| 1419 |
if ( !empty( $excludetagoverride ) ) { |
| 1420 |
$options['excludetaglist_cpt'] = $excludetagoverride; |
| 1421 |
|
| 1422 |
$update_list = false; |
| 1423 |
$exclude_tag_list_array = explode( ',', $excludetagoverride ); |
| 1424 |
foreach( $exclude_tag_list_array as $index => $tag_text ) { |
| 1425 |
if ( !is_numeric( $tag_text ) ) { |
| 1426 |
$update_list = true; |
| 1427 |
$matched_term = get_term_by( 'slug', $tag_text, $genoptions['tagtaxonomy'] ); |
| 1428 |
|
| 1429 |
if ( $matched_term ) { |
| 1430 |
$exclude_tag_list_array[$index] = $matched_term->term_id; |
| 1431 |
} else { |
| 1432 |
unset( $exclude_tag_list_array[$index] ); |
| 1433 |
} |
| 1434 |
} |
| 1435 |
} |
| 1436 |
if ( $update_list ) { |
| 1437 |
$options['excludetaglist_cpt'] = implode( ',', $exclude_tag_list_array ); |
| 1438 |
} |
| 1439 |
} |
| 1440 |
|
| 1441 |
if ( $genoptions['debugmode'] ) { |
| 1442 |
$mainoutputstarttime = microtime( true ); |
| 1443 |
$timeoutputstart = "\n<!-- Start Link Library Cats Time: " . $mainoutputstarttime . "-->\n"; |
| 1444 |
} |
| 1445 |
|
| 1446 |
require_once plugin_dir_path( __FILE__ ) . 'render-link-library-cats-sc.php'; |
| 1447 |
|
| 1448 |
if ( $genoptions['debugmode'] ) { |
| 1449 |
$timeoutput = "\n<!-- [link-library-cats] shortcode execution time: " . ( microtime( true ) - $mainoutputstarttime ) . "-->\n"; |
| 1450 |
} |
| 1451 |
|
| 1452 |
|
| 1453 |
$parent_id_array = array(); |
| 1454 |
return ( true == $genoptions['debugmode'] ? $timeoutputstart : '' ) . RenderLinkLibraryCategories( $this, $genoptions, $options, intval( $settings ), $targetlibrary, $parent_cat_id, 0, $parent_id_array ) . ( true == $genoptions['debugmode'] ? $timeoutput : '' ); |
| 1455 |
} |
| 1456 |
|
| 1457 |
/********************************************** Function to Process [link-library-search] shortcode *********************************************/ |
| 1458 |
|
| 1459 |
function link_library_search_func($atts) { |
| 1460 |
$settings = ''; |
| 1461 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 1462 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 1463 |
|
| 1464 |
extract(shortcode_atts(array( |
| 1465 |
'settings' => '' |
| 1466 |
), $atts)); |
| 1467 |
|
| 1468 |
if ( empty( $settings ) ) { |
| 1469 |
$settings = 1; |
| 1470 |
} |
| 1471 |
|
| 1472 |
if ( $settings > $genoptions['numberstylesets'] ) { |
| 1473 |
$settings = 1; |
| 1474 |
} |
| 1475 |
|
| 1476 |
$settings = link_library_validate_settings_number( $settings ); |
| 1477 |
$settingsname = 'LinkLibraryPP' . $settings; |
| 1478 |
$options = get_option( $settingsname ); |
| 1479 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1480 |
|
| 1481 |
if ( empty( $options ) ) { |
| 1482 |
$settingsname = 'LinkLibraryPP1'; |
| 1483 |
$options = get_option( $settingsname ); |
| 1484 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1485 |
} |
| 1486 |
|
| 1487 |
require_once plugin_dir_path( __FILE__ ) . 'render-link-library-search-sc.php'; |
| 1488 |
return RenderLinkLibrarySearchForm( $options ); |
| 1489 |
} |
| 1490 |
|
| 1491 |
/********************************************** Function to Process [link-library-add-link] shortcode *********************************************/ |
| 1492 |
|
| 1493 |
function link_library_addlink_func( $atts, $content, $code ) { |
| 1494 |
$settings = ''; |
| 1495 |
$categorylistoverride = ''; |
| 1496 |
$excludecategoryoverride = ''; |
| 1497 |
$addlinkdefaultcatoverride = ''; |
| 1498 |
|
| 1499 |
extract(shortcode_atts(array( |
| 1500 |
'settings' => '', |
| 1501 |
'categorylistoverride' => '', |
| 1502 |
'excludecategoryoverride' => '', |
| 1503 |
'addlinkdefaultcatoverride' => '' |
| 1504 |
), $atts)); |
| 1505 |
|
| 1506 |
if ( empty( $code ) || is_object( $code ) ) { |
| 1507 |
$code = 'link-library-addlink'; |
| 1508 |
} |
| 1509 |
|
| 1510 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 1511 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 1512 |
|
| 1513 |
if ( empty( $settings ) ) { |
| 1514 |
$settings = 1; |
| 1515 |
} else if ( isset( $_POST['settings'] ) ) { |
| 1516 |
$settings = intval( $_POST['settings'] ); |
| 1517 |
} |
| 1518 |
|
| 1519 |
if ( $settings > $genoptions['numberstylesets'] ) { |
| 1520 |
$settings = 1; |
| 1521 |
} |
| 1522 |
|
| 1523 |
$settings = link_library_validate_settings_number( $settings ); |
| 1524 |
$settingsname = 'LinkLibraryPP' . $settings; |
| 1525 |
$options = get_option( $settingsname ); |
| 1526 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1527 |
|
| 1528 |
if ( empty( $options ) ) { |
| 1529 |
$settingsname = 'LinkLibraryPP1'; |
| 1530 |
$options = get_option( $settingsname ); |
| 1531 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1532 |
} |
| 1533 |
|
| 1534 |
if ( !empty( $categorylistoverride ) ) { |
| 1535 |
$options['categorylist_cpt'] = $categorylistoverride; |
| 1536 |
} elseif ( !empty( $options['addlinkcatlistoverride'] ) ) { |
| 1537 |
$options['categorylist_cpt'] = $options['addlinkcatlistoverride']; |
| 1538 |
} |
| 1539 |
|
| 1540 |
if ( !empty( $excludecategoryoverride ) ) { |
| 1541 |
$options['excludecategorylist_cpt'] = $excludecategoryoverride; |
| 1542 |
} |
| 1543 |
|
| 1544 |
if ( !empty( $addlinkdefaultcatoverride ) ) { |
| 1545 |
$options['addlinkdefaultcat'] = $addlinkdefaultcatoverride; |
| 1546 |
} |
| 1547 |
|
| 1548 |
require_once plugin_dir_path( __FILE__ ) . 'render-link-library-addlink-sc.php'; |
| 1549 |
if ( 'inline' == $options['addlinkformdisplaymode'] ) { |
| 1550 |
return RenderLinkLibraryAddLinkForm( $this, $genoptions, $options, intval( $settings ), $code ); |
| 1551 |
} elseif ( 'popup' == $options['addlinkformdisplaymode'] ) { |
| 1552 |
return RenderLinkLibraryAddLinkButton( $this, $genoptions, $options, intval( $settings ), $code ); |
| 1553 |
} |
| 1554 |
|
| 1555 |
} |
| 1556 |
|
| 1557 |
/********************************************** Function to Process [link-library-count] shortcode ***************************************/ |
| 1558 |
|
| 1559 |
function link_library_count_func( $atts ) { |
| 1560 |
extract( shortcode_atts( array( |
| 1561 |
'categorylistoverride' => '', |
| 1562 |
'excludecategoryoverride' => '', |
| 1563 |
'settings' => '' |
| 1564 |
), $atts ) ); |
| 1565 |
|
| 1566 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 1567 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 1568 |
|
| 1569 |
if ( empty( $settings ) ) { |
| 1570 |
$settings = 1; |
| 1571 |
} else if ( isset( $_POST['settings'] ) ) { |
| 1572 |
$settings = intval( $_POST['settings'] ); |
| 1573 |
} |
| 1574 |
|
| 1575 |
if ( $settings > $genoptions['numberstylesets'] ) { |
| 1576 |
$settings = 1; |
| 1577 |
} |
| 1578 |
|
| 1579 |
$settings = link_library_validate_settings_number( $settings ); |
| 1580 |
$settingsname = 'LinkLibraryPP' . $settings; |
| 1581 |
$options = get_option( $settingsname ); |
| 1582 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1583 |
|
| 1584 |
if ( empty( $options ) ) { |
| 1585 |
$settingsname = 'LinkLibraryPP1'; |
| 1586 |
$options = get_option( $settingsname ); |
| 1587 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1588 |
} |
| 1589 |
|
| 1590 |
$linkeditoruser = current_user_can( 'manage_options' ); |
| 1591 |
|
| 1592 |
if ( !empty( $categorylistoverride ) ) { |
| 1593 |
$options['categorylist_cpt'] = $categorylistoverride; |
| 1594 |
} |
| 1595 |
|
| 1596 |
if ( !empty( $excludecategoryoverride ) ) { |
| 1597 |
$options['excludecategorylist_cpt'] = $excludecategoryoverride; |
| 1598 |
} |
| 1599 |
|
| 1600 |
$link_query_args = array( 'post_type' => 'link_library_links', 'posts_per_page' => -1 ); |
| 1601 |
$link_query_args['post_status'] = array( 'publish' ); |
| 1602 |
|
| 1603 |
if ( !empty( $options['categorylist_cpt'] ) ) { |
| 1604 |
$catlistarray = explode( ',', $options['categorylist_cpt'] ); |
| 1605 |
$link_query_args['tax_query'] = array( array( 'taxonomy' => $genoptions['cattaxonomy'], |
| 1606 |
'field' => 'term_id', |
| 1607 |
'terms' => $catlistarray, |
| 1608 |
'operator' => 'IN' ) ); |
| 1609 |
} |
| 1610 |
|
| 1611 |
if ( !empty( $options['excludecategorylist_cpt'] ) ) { |
| 1612 |
$catlistexcludearray = explode( ',', $options['excludecategorylist_cpt'] ); |
| 1613 |
$link_query_args['tax_query'] = array( array( 'taxonomy' => $genoptions['cattaxonomy'], |
| 1614 |
'field' => 'term_id', |
| 1615 |
'terms' => $catlistexcludearray, |
| 1616 |
'operator' => 'NOT IN' ) ); |
| 1617 |
} |
| 1618 |
|
| 1619 |
if ( $options['showuserlinks'] ) { |
| 1620 |
$link_query_args['post_status'][] = 'pending'; |
| 1621 |
} |
| 1622 |
|
| 1623 |
if ( $options['showinvisible'] || ( $options['showinvisibleadmin'] && $linkeditoruser ) ) { |
| 1624 |
$link_query_args['post_status'][] = 'draft'; |
| 1625 |
} |
| 1626 |
|
| 1627 |
if ( $options['showscheduledlinks'] ) { |
| 1628 |
$link_query_args['post_status'][] = 'future'; |
| 1629 |
} |
| 1630 |
|
| 1631 |
$the_link_query = new WP_Query( $link_query_args ); |
| 1632 |
|
| 1633 |
wp_reset_postdata(); |
| 1634 |
|
| 1635 |
return $the_link_query->found_posts; |
| 1636 |
} |
| 1637 |
|
| 1638 |
/********************************************** Function to Process [link-library-filters] shortcode ***************************************/ |
| 1639 |
|
| 1640 |
function link_library_filters( $atts ) { |
| 1641 |
extract( shortcode_atts( array( |
| 1642 |
'includetagsids' => '', |
| 1643 |
'excludetagsids' => '', |
| 1644 |
'showtagfilters' => true, |
| 1645 |
'taglabel' => __( 'Tag', 'link-library' ), |
| 1646 |
'showpricefilters' => true, |
| 1647 |
'pricelabel' => __( 'Price', 'link-library' ), |
| 1648 |
'alphabeticlabel' => __( 'Link Name', 'link-library' ), |
| 1649 |
'showalphabeticfilters' => true, |
| 1650 |
'showapplybutton' => false, |
| 1651 |
'settings' => '' |
| 1652 |
), $atts ) ); |
| 1653 |
|
| 1654 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 1655 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 1656 |
|
| 1657 |
if ( empty( $settings ) ) { |
| 1658 |
$settings = 1; |
| 1659 |
} else if ( isset( $_POST['settings'] ) ) { |
| 1660 |
$settings = intval( $_POST['settings'] ); |
| 1661 |
} |
| 1662 |
|
| 1663 |
if ( $settings > $genoptions['numberstylesets'] ) { |
| 1664 |
$settings = 1; |
| 1665 |
} |
| 1666 |
|
| 1667 |
$settings = link_library_validate_settings_number( $settings ); |
| 1668 |
$settingsname = 'LinkLibraryPP' . $settings; |
| 1669 |
$options = get_option( $settingsname ); |
| 1670 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1671 |
|
| 1672 |
if ( empty( $options ) ) { |
| 1673 |
$settingsname = 'LinkLibraryPP1'; |
| 1674 |
$options = get_option( $settingsname ); |
| 1675 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1676 |
} |
| 1677 |
|
| 1678 |
require_once plugin_dir_path( __FILE__ ) . 'render-link-library-tag-filter-sc.php'; |
| 1679 |
return RenderLinkLibraryFilterBox( $this, $genoptions, $options, intval( $settings ), $includetagsids, $excludetagsids, $showtagfilters, $taglabel, $showpricefilters, $pricelabel, $showalphabeticfilters, $alphabeticlabel, $showapplybutton ); |
| 1680 |
} |
| 1681 |
|
| 1682 |
/********************************************** Function to Process [link-library] shortcode *********************************************/ |
| 1683 |
|
| 1684 |
function link_library_func( $atts = '' ) { |
| 1685 |
if ( isset( $_POST['ajaxupdate'] ) ) { |
| 1686 |
check_ajax_referer( 'link_library_ajax_refresh' ); |
| 1687 |
} |
| 1688 |
|
| 1689 |
$settings = ''; |
| 1690 |
$notesoverride = ''; |
| 1691 |
$descoverride = ''; |
| 1692 |
$rssoverride = ''; |
| 1693 |
$categorylistoverride = ''; |
| 1694 |
$excludecategoryoverride = ''; |
| 1695 |
$tableoverride = ''; |
| 1696 |
$singlelinkid = ''; |
| 1697 |
$showonecatonlyoverride = false; |
| 1698 |
$taglistoverride = ''; |
| 1699 |
$maxlinksoverride = ''; |
| 1700 |
$linkorderoverride = ''; |
| 1701 |
$linkdirectionoverride = ''; |
| 1702 |
$addlinkdefaultcatoverride = ''; |
| 1703 |
$urltextfilteroverride = ''; |
| 1704 |
|
| 1705 |
if ( isset( $atts['categorylistoverride'] ) && !empty( $atts['categorylistoverride'] ) && is_array( $atts['categorylistoverride'] ) ) { |
| 1706 |
$atts['categorylistoverride'] = implode( ',', $atts['categorylistoverride'] ); |
| 1707 |
} |
| 1708 |
|
| 1709 |
if ( isset( $atts['categorylistoverrideCSV'] ) && !empty( $atts['categorylistoverrideCSV'] ) ) { |
| 1710 |
$atts['categorylistoverride'] = $atts['categorylistoverrideCSV']; |
| 1711 |
} |
| 1712 |
|
| 1713 |
if ( isset( $atts['excludecategoryoverride'] ) && !empty( $atts['excludecategoryoverride'] ) && is_array( $atts['excludecategoryoverride'] ) ) { |
| 1714 |
$atts['excludecategoryoverride'] = implode( ',', $atts['excludecategoryoverride'] ); |
| 1715 |
} |
| 1716 |
|
| 1717 |
if ( isset( $atts['excludecategoryoverrideCSV'] ) && !empty( $atts['excludecategoryoverrideCSV'] ) ) { |
| 1718 |
$atts['excludecategoryoverride'] = $atts['excludecategoryoverrideCSV']; |
| 1719 |
} |
| 1720 |
|
| 1721 |
if ( isset( $atts['taglistoverride'] ) && !empty( $atts['taglistoverride'] ) && is_array( $atts['taglistoverride'] ) ) { |
| 1722 |
$atts['taglistoverride'] = implode( ',', $atts['taglistoverride'] ); |
| 1723 |
} |
| 1724 |
|
| 1725 |
if ( isset( $atts['taglistoverrideCSV'] ) && !empty( $atts['taglistoverrideCSV'] ) ) { |
| 1726 |
$atts['taglistoverride'] = $atts['taglistoverrideCSV']; |
| 1727 |
} |
| 1728 |
|
| 1729 |
extract( shortcode_atts( array( |
| 1730 |
'categorylistoverride' => '', |
| 1731 |
'excludecategoryoverride' => '', |
| 1732 |
'notesoverride' => '', |
| 1733 |
'descoverride' => '', |
| 1734 |
'rssoverride' => '', |
| 1735 |
'tableoverride' => '', |
| 1736 |
'settings' => '', |
| 1737 |
'singlelinkid' => '', |
| 1738 |
'showonecatonlyoverride' => '', |
| 1739 |
'taglistoverride' => '', |
| 1740 |
'excludetagoverride' => '', |
| 1741 |
'maxlinksoverride' => '', |
| 1742 |
'linkorderoverride' => '', |
| 1743 |
'linkdirectionoverride' => '', |
| 1744 |
'addlinkdefaultcatoverride' => '', |
| 1745 |
'urltextfilteroverride' => '', |
| 1746 |
), $atts ) ); |
| 1747 |
|
| 1748 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 1749 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 1750 |
|
| 1751 |
if ( floatval( $genoptions['schemaversion'] ) < '5.0' ) { |
| 1752 |
$this->ll_install(); |
| 1753 |
} |
| 1754 |
|
| 1755 |
if ( empty( $settings ) && !isset( $_POST['settings'] ) ) { |
| 1756 |
$settings = 1; |
| 1757 |
} else if ( isset( $_POST['settings'] ) ) { |
| 1758 |
$settings = intval( $_POST['settings'] ); |
| 1759 |
} |
| 1760 |
|
| 1761 |
if ( $settings > $genoptions['numberstylesets'] ) { |
| 1762 |
$settings = 1; |
| 1763 |
} |
| 1764 |
|
| 1765 |
$settings = link_library_validate_settings_number( $settings ); |
| 1766 |
$settingsname = 'LinkLibraryPP' . $settings; |
| 1767 |
$options = get_option( $settingsname ); |
| 1768 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1769 |
|
| 1770 |
if ( empty( $options ) ) { |
| 1771 |
$settingsname = 'LinkLibraryPP1'; |
| 1772 |
$options = get_option( $settingsname ); |
| 1773 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 1774 |
} |
| 1775 |
|
| 1776 |
$options['AJAXcatid'] = ''; |
| 1777 |
$options['AJAXpageid'] = ''; |
| 1778 |
|
| 1779 |
if ( !empty( $notesoverride ) ) { |
| 1780 |
$options['shownotes'] = $notesoverride; |
| 1781 |
} |
| 1782 |
|
| 1783 |
if ( !empty( $descoverride ) ) { |
| 1784 |
$options['showdescription'] = $descoverride; |
| 1785 |
} |
| 1786 |
|
| 1787 |
if ( !empty( $rssoverride ) ) { |
| 1788 |
$options['show_rss'] = $rssoverride; |
| 1789 |
} |
| 1790 |
|
| 1791 |
if ( !empty( $maxlinksoverride ) ) { |
| 1792 |
$options['maxlinks'] = intval( $maxlinksoverride ); |
| 1793 |
} |
| 1794 |
|
| 1795 |
if ( !empty( $urltextfilteroverride ) ) { |
| 1796 |
$options['urltextfilter'] = $urltextfilteroverride; |
| 1797 |
} |
| 1798 |
|
| 1799 |
if ( !empty( $linkorderoverride ) ) { |
| 1800 |
$validlinkorder = array( 'name', 'id', 'random', 'date', 'hits', 'scpo', 'pubdate', 'uservotes' ); |
| 1801 |
if ( in_array( $linkorderoverride, $validlinkorder ) ) { |
| 1802 |
$options['linkorder'] = $linkorderoverride; |
| 1803 |
} |
| 1804 |
} |
| 1805 |
|
| 1806 |
if ( !empty( $linkdirectionoverride ) ) { |
| 1807 |
$validlinkdirection = array( 'ASC', 'DESC' ); |
| 1808 |
if ( in_array( $linkdirectionoverride, $validlinkdirection ) ) { |
| 1809 |
$options['linkdirection'] = $linkdirectionoverride; |
| 1810 |
} |
| 1811 |
} |
| 1812 |
|
| 1813 |
if ( !empty( $categorylistoverride ) ) { |
| 1814 |
$options['categorylist_cpt'] = $categorylistoverride; |
| 1815 |
|
| 1816 |
$update_list = false; |
| 1817 |
$category_list_array = explode( ',', $categorylistoverride ); |
| 1818 |
foreach( $category_list_array as $index => $category_text ) { |
| 1819 |
if ( !is_numeric( $category_text ) ) { |
| 1820 |
$update_list = true; |
| 1821 |
$matched_term = get_term_by( 'slug', $category_text, $genoptions['cattaxonomy'] ); |
| 1822 |
|
| 1823 |
if ( $matched_term ) { |
| 1824 |
$category_list_array[$index] = $matched_term->term_id; |
| 1825 |
} else { |
| 1826 |
unset( $category_list_array[$index] ); |
| 1827 |
} |
| 1828 |
} |
| 1829 |
} |
| 1830 |
if ( $update_list ) { |
| 1831 |
$options['categorylist_cpt'] = implode( ',', $category_list_array ); |
| 1832 |
} |
| 1833 |
} |
| 1834 |
|
| 1835 |
if ( !empty( $excludecategoryoverride ) ) { |
| 1836 |
$options['excludecategorylist_cpt'] = $excludecategoryoverride; |
| 1837 |
|
| 1838 |
$update_list = false; |
| 1839 |
$exclude_category_list_array = explode( ',', $excludecategoryoverride ); |
| 1840 |
foreach( $exclude_category_list_array as $index => $category_text ) { |
| 1841 |
if ( !is_numeric( $category_text ) ) { |
| 1842 |
$update_list = true; |
| 1843 |
$matched_term = get_term_by( 'slug', $category_text, $genoptions['cattaxonomy'] ); |
| 1844 |
|
| 1845 |
if ( $matched_term ) { |
| 1846 |
$exclude_category_list_array[$index] = $matched_term->term_id; |
| 1847 |
} else { |
| 1848 |
unset( $exclude_category_list_array[$index] ); |
| 1849 |
} |
| 1850 |
} |
| 1851 |
} |
| 1852 |
if ( $update_list ) { |
| 1853 |
$options['excludecategorylist_cpt'] = implode( ',', $exclude_category_list_array ); |
| 1854 |
} |
| 1855 |
} |
| 1856 |
|
| 1857 |
if ( !empty( $taglistoverride ) ) { |
| 1858 |
$options['taglist_cpt'] = $taglistoverride; |
| 1859 |
|
| 1860 |
$update_list = false; |
| 1861 |
$tag_list_array = explode( ',', $taglistoverride ); |
| 1862 |
foreach( $tag_list_array as $index => $tag_text ) { |
| 1863 |
if ( !is_numeric( $tag_text ) ) { |
| 1864 |
$update_list = true; |
| 1865 |
$matched_term = get_term_by( 'slug', $tag_text, $genoptions['tagtaxonomy'] ); |
| 1866 |
|
| 1867 |
if ( $matched_term ) { |
| 1868 |
$tag_list_array[$index] = $matched_term->term_id; |
| 1869 |
} else { |
| 1870 |
unset( $tag_list_array[$index] ); |
| 1871 |
} |
| 1872 |
} |
| 1873 |
} |
| 1874 |
if ( $update_list ) { |
| 1875 |
$options['taglist_cpt'] = implode( ',', $tag_list_array ); |
| 1876 |
} |
| 1877 |
} |
| 1878 |
|
| 1879 |
if ( !empty( $excludecategoryoverride ) ) { |
| 1880 |
$options['excludetaglist_cpt'] = $excludetagoverride; |
| 1881 |
|
| 1882 |
$update_list = false; |
| 1883 |
$exclude_tag_list_array = explode( ',', $excludetagoverride ); |
| 1884 |
foreach( $exclude_tag_list_array as $index => $tag_text ) { |
| 1885 |
if ( !is_numeric( $tag_text ) ) { |
| 1886 |
$update_list = true; |
| 1887 |
$matched_term = get_term_by( 'slug', $tag_text, $genoptions['tagtaxonomy'] ); |
| 1888 |
|
| 1889 |
if ( $matched_term ) { |
| 1890 |
$exclude_tag_list_array[$index] = $matched_term->term_id; |
| 1891 |
} else { |
| 1892 |
unset( $exclude_tag_list_array[$index] ); |
| 1893 |
} |
| 1894 |
} |
| 1895 |
} |
| 1896 |
if ( $update_list ) { |
| 1897 |
$options['excludetaglist_cpt'] = implode( ',', $exclude_category_list_array ); |
| 1898 |
} |
| 1899 |
} |
| 1900 |
|
| 1901 |
if ( !empty( $singlelinkid ) ) { |
| 1902 |
$options['singlelinkid'] = $singlelinkid; |
| 1903 |
} |
| 1904 |
|
| 1905 |
if ( $showonecatonlyoverride == 'false' || $showonecatonlyoverride == 'true' ) { |
| 1906 |
if ( $showonecatonlyoverride == 'false' ) { |
| 1907 |
$options['showonecatonly'] = false; |
| 1908 |
} elseif ( $showonecatonlyoverride == 'true' ) { |
| 1909 |
$options['showonecatonly'] = true; |
| 1910 |
} |
| 1911 |
} |
| 1912 |
|
| 1913 |
if ( $options['showonecatonly'] ) { |
| 1914 |
if ( !empty( $categorylistoverride ) && !empty( $options['defaultsinglecat_cpt'] ) ) { |
| 1915 |
if ( !str_contains( $categorylistoverride, ',' ) ) { |
| 1916 |
$options['defaultsinglecat_cpt'] = $categorylistoverride; |
| 1917 |
} |
| 1918 |
} |
| 1919 |
} |
| 1920 |
|
| 1921 |
if ( !empty( $tableoverride ) ) { |
| 1922 |
$options['displayastable'] = $tableoverride; |
| 1923 |
} |
| 1924 |
|
| 1925 |
if ( isset( $_POST['ajaxupdate'] ) ) { |
| 1926 |
if ( isset( $_POST['id'] ) ) { |
| 1927 |
$catID = intval( $_POST['id'] ); |
| 1928 |
$options['AJAXcatid'] = $catID; |
| 1929 |
} |
| 1930 |
|
| 1931 |
if ( isset( $_POST['linkresultpage'] ) ) { |
| 1932 |
$pageID = intval( $_POST['linkresultpage'] ); |
| 1933 |
$options['AJAXpageid'] = $pageID; |
| 1934 |
} |
| 1935 |
} |
| 1936 |
|
| 1937 |
$linklibraryoutput = ''; |
| 1938 |
|
| 1939 |
if ( $genoptions['debugmode'] ) { |
| 1940 |
$linklibraryoutput .= "\n<!-- Library Settings Info:" . print_r( $options, true ) . "-->\n"; |
| 1941 |
$mainoutputstarttime = microtime( true ); |
| 1942 |
$linklibraryoutput .= "\n<!-- Start Time: " . $mainoutputstarttime . "-->\n"; |
| 1943 |
} |
| 1944 |
|
| 1945 |
require_once plugin_dir_path( __FILE__ ) . 'render-link-library-sc.php'; |
| 1946 |
$linkcount = 1; |
| 1947 |
$linklibraryoutput .= RenderLinkLibrary( $linkcount, $this, $genoptions, $options, intval( $settings ), false, 0, 0, true, false ); |
| 1948 |
|
| 1949 |
if ( isset( $_POST['ajaxupdate'] ) ) { |
| 1950 |
echo $linklibraryoutput; |
| 1951 |
|
| 1952 |
if ( $genoptions['debugmode'] ) { |
| 1953 |
echo "\n<!-- Execution Time: " . ( microtime( true ) - $mainoutputstarttime ) . "-->\n"; |
| 1954 |
} |
| 1955 |
exit; |
| 1956 |
} else { |
| 1957 |
if ( $genoptions['debugmode'] ) { |
| 1958 |
$timeoutput = "\n<!-- [link-library] shortcode execution time: " . ( microtime( true ) - $mainoutputstarttime ) . "-->\n"; |
| 1959 |
} |
| 1960 |
return $linklibraryoutput . ( true == $genoptions['debugmode'] ? $timeoutput : '' ); |
| 1961 |
} |
| 1962 |
} |
| 1963 |
|
| 1964 |
/********************************************** Function to Process [link-library] shortcode *********************************************/ |
| 1965 |
|
| 1966 |
function rss_library_func( $atts = '' ) { |
| 1967 |
$settings = ''; |
| 1968 |
$categorylistoverride = ''; |
| 1969 |
$excludecategoryoverride = ''; |
| 1970 |
$taglistoverride = ''; |
| 1971 |
|
| 1972 |
if ( isset( $atts['categorylistoverride'] ) && !empty( $atts['categorylistoverride'] ) && is_array( $atts['categorylistoverride'] ) ) { |
| 1973 |
$atts['categorylistoverride'] = implode( ',', $atts['categorylistoverride'] ); |
| 1974 |
} |
| 1975 |
|
| 1976 |
if ( isset( $atts['categorylistoverrideCSV'] ) && !empty( $atts['categorylistoverrideCSV'] ) ) { |
| 1977 |
$atts['categorylistoverride'] = $atts['categorylistoverrideCSV']; |
| 1978 |
} |
| 1979 |
|
| 1980 |
if ( isset( $atts['excludecategoryoverride'] ) && !empty( $atts['excludecategoryoverride'] ) && is_array( $atts['excludecategoryoverride'] ) ) { |
| 1981 |
$atts['excludecategoryoverride'] = implode( ',', $atts['excludecategoryoverride'] ); |
| 1982 |
} |
| 1983 |
|
| 1984 |
if ( isset( $atts['excludecategoryoverrideCSV'] ) && !empty( $atts['excludecategoryoverrideCSV'] ) ) { |
| 1985 |
$atts['excludecategoryoverride'] = $atts['excludecategoryoverrideCSV']; |
| 1986 |
} |
| 1987 |
|
| 1988 |
if ( isset( $atts['taglistoverride'] ) && !empty( $atts['taglistoverride'] ) && is_array( $atts['taglistoverride'] ) ) { |
| 1989 |
$atts['taglistoverride'] = implode( ',', $atts['taglistoverride'] ); |
| 1990 |
} |
| 1991 |
|
| 1992 |
if ( isset( $atts['taglistoverrideCSV'] ) && !empty( $atts['taglistoverrideCSV'] ) ) { |
| 1993 |
$atts['taglistoverride'] = $atts['taglistoverrideCSV']; |
| 1994 |
} |
| 1995 |
|
| 1996 |
extract( shortcode_atts( array( |
| 1997 |
'settings' => '', |
| 1998 |
'categorylistoverride' => '', |
| 1999 |
'excludecategoryoverride' => '', |
| 2000 |
'taglistoverride' => '', |
| 2001 |
), $atts ) ); |
| 2002 |
|
| 2003 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 2004 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 2005 |
|
| 2006 |
if ( floatval( $genoptions['schemaversion'] ) < '5.0' ) { |
| 2007 |
$this->ll_install(); |
| 2008 |
} |
| 2009 |
|
| 2010 |
if ( empty( $settings ) && !isset( $_POST['settings'] ) ) { |
| 2011 |
$settings = 1; |
| 2012 |
} else if ( isset( $_POST['settings'] ) ) { |
| 2013 |
$settings = intval( $_POST['settings'] ); |
| 2014 |
} |
| 2015 |
|
| 2016 |
if ( $settings > $genoptions['numberstylesets'] ) { |
| 2017 |
$settings = 1; |
| 2018 |
} |
| 2019 |
|
| 2020 |
$settings = link_library_validate_settings_number( $settings ); |
| 2021 |
$settingsname = 'LinkLibraryPP' . $settings; |
| 2022 |
$options = get_option( $settingsname ); |
| 2023 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 2024 |
|
| 2025 |
if ( !empty( $categorylistoverride ) ) { |
| 2026 |
$options['categorylist_cpt'] = $categorylistoverride; |
| 2027 |
|
| 2028 |
$update_list = false; |
| 2029 |
$category_list_array = explode( ',', $categorylistoverride ); |
| 2030 |
foreach( $category_list_array as $index => $category_text ) { |
| 2031 |
if ( !is_numeric( $category_text ) ) { |
| 2032 |
$update_list = true; |
| 2033 |
$matched_term = get_term_by( 'slug', $category_text, $genoptions['cattaxonomy'] ); |
| 2034 |
|
| 2035 |
if ( $matched_term ) { |
| 2036 |
$category_list_array[$index] = $matched_term->term_id; |
| 2037 |
} else { |
| 2038 |
unset( $category_list_array[$index] ); |
| 2039 |
} |
| 2040 |
} |
| 2041 |
} |
| 2042 |
if ( $update_list ) { |
| 2043 |
$options['categorylist_cpt'] = implode( ',', $category_list_array ); |
| 2044 |
} |
| 2045 |
} |
| 2046 |
|
| 2047 |
if ( !empty( $excludecategoryoverride ) ) { |
| 2048 |
$options['excludecategorylist_cpt'] = $excludecategoryoverride; |
| 2049 |
|
| 2050 |
$update_list = false; |
| 2051 |
$exclude_category_list_array = explode( ',', $excludecategoryoverride ); |
| 2052 |
foreach( $exclude_category_list_array as $index => $category_text ) { |
| 2053 |
if ( !is_numeric( $category_text ) ) { |
| 2054 |
$update_list = true; |
| 2055 |
$matched_term = get_term_by( 'slug', $category_text, $genoptions['cattaxonomy'] ); |
| 2056 |
|
| 2057 |
if ( $matched_term ) { |
| 2058 |
$exclude_category_list_array[$index] = $matched_term->term_id; |
| 2059 |
} else { |
| 2060 |
unset( $exclude_category_list_array[$index] ); |
| 2061 |
} |
| 2062 |
} |
| 2063 |
} |
| 2064 |
if ( $update_list ) { |
| 2065 |
$options['excludecategorylist_cpt'] = implode( ',', $exclude_category_list_array ); |
| 2066 |
} |
| 2067 |
} |
| 2068 |
|
| 2069 |
if ( !empty( $taglistoverride ) ) { |
| 2070 |
$options['taglist_cpt'] = $taglistoverride; |
| 2071 |
|
| 2072 |
$update_list = false; |
| 2073 |
$tag_list_array = explode( ',', $taglistoverride ); |
| 2074 |
foreach( $tag_list_array as $index => $tag_text ) { |
| 2075 |
if ( !is_numeric( $tag_text ) ) { |
| 2076 |
$update_list = true; |
| 2077 |
$matched_term = get_term_by( 'slug', $tag_text, $genoptions['tagtaxonomy'] ); |
| 2078 |
|
| 2079 |
if ( $matched_term ) { |
| 2080 |
$tag_list_array[$index] = $matched_term->term_id; |
| 2081 |
} else { |
| 2082 |
unset( $tag_list_array[$index] ); |
| 2083 |
} |
| 2084 |
} |
| 2085 |
} |
| 2086 |
if ( $update_list ) { |
| 2087 |
$options['taglist_cpt'] = implode( ',', $tag_list_array ); |
| 2088 |
} |
| 2089 |
} |
| 2090 |
|
| 2091 |
if ( !empty( $excludecategoryoverride ) ) { |
| 2092 |
$options['excludetaglist_cpt'] = $excludetagoverride; |
| 2093 |
|
| 2094 |
$update_list = false; |
| 2095 |
$exclude_tag_list_array = explode( ',', $excludetagoverride ); |
| 2096 |
foreach( $exclude_tag_list_array as $index => $tag_text ) { |
| 2097 |
if ( !is_numeric( $tag_text ) ) { |
| 2098 |
$update_list = true; |
| 2099 |
$matched_term = get_term_by( 'slug', $tag_text, $genoptions['tagtaxonomy'] ); |
| 2100 |
|
| 2101 |
if ( $matched_term ) { |
| 2102 |
$exclude_tag_list_array[$index] = $matched_term->term_id; |
| 2103 |
} else { |
| 2104 |
unset( $exclude_tag_list_array[$index] ); |
| 2105 |
} |
| 2106 |
} |
| 2107 |
} |
| 2108 |
if ( $update_list ) { |
| 2109 |
$options['excludetaglist_cpt'] = implode( ',', $exclude_category_list_array ); |
| 2110 |
} |
| 2111 |
} |
| 2112 |
|
| 2113 |
$linklibraryoutput = ''; |
| 2114 |
|
| 2115 |
if ( $genoptions['debugmode'] ) { |
| 2116 |
$linklibraryoutput .= "\n<!-- RSS Library Settings Info:" . print_r( $options, true ) . "-->\n"; |
| 2117 |
$mainoutputstarttime = microtime( true ); |
| 2118 |
$linklibraryoutput .= "\n<!-- Start Time: " . $mainoutputstarttime . "-->\n"; |
| 2119 |
} |
| 2120 |
|
| 2121 |
require_once plugin_dir_path( __FILE__ ) . 'render-rss-library-sc.php'; |
| 2122 |
$linkcount = 1; |
| 2123 |
$rss_array_items = array(); |
| 2124 |
$linklibraryoutput .= RenderRSSLibrary( $this, $genoptions, $options, intval( $settings ), 0, 0, false, $linkcount, $rss_array_items ); |
| 2125 |
|
| 2126 |
if ( $genoptions['debugmode'] ) { |
| 2127 |
$timeoutput = "\n<!-- [link-library] shortcode execution time: " . ( microtime( true ) - $mainoutputstarttime ) . "-->\n"; |
| 2128 |
} |
| 2129 |
return $linklibraryoutput . ( true == $genoptions['debugmode'] ? $timeoutput : '' ); |
| 2130 |
} |
| 2131 |
|
| 2132 |
function link_library_tagcloud( $atts = '' ) { |
| 2133 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 2134 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 2135 |
|
| 2136 |
$link_library_terms = get_terms( array( 'taxonomy' => $genoptions['cattaxonomy'] ) ); |
| 2137 |
$output = wp_generate_tag_cloud( $link_library_terms ); |
| 2138 |
return $output; |
| 2139 |
} |
| 2140 |
|
| 2141 |
function conditionally_add_scripts_and_styles( $posts ) { |
| 2142 |
if ( empty( $posts ) ) { |
| 2143 |
return $posts; |
| 2144 |
} |
| 2145 |
|
| 2146 |
global $llstylesheet; |
| 2147 |
global $settingssetsids; |
| 2148 |
$settingssetsids = array(); |
| 2149 |
$load_jquery = false; |
| 2150 |
$load_thickbox = false; |
| 2151 |
$load_colorbox = false; |
| 2152 |
$load_recaptcha = false; |
| 2153 |
$load_masonry = false; |
| 2154 |
$load_style = ''; |
| 2155 |
$has_block = false; |
| 2156 |
|
| 2157 |
if ( $llstylesheet ) { |
| 2158 |
$load_style = true; |
| 2159 |
} else { |
| 2160 |
$load_style = false; |
| 2161 |
} |
| 2162 |
|
| 2163 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 2164 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 2165 |
|
| 2166 |
if ( is_admin() ) { |
| 2167 |
$load_jquery = false; |
| 2168 |
$load_thickbox = false; |
| 2169 |
$load_colorbox = false; |
| 2170 |
$load_style = false; |
| 2171 |
} else { |
| 2172 |
foreach ( $posts as $post ) { |
| 2173 |
if ( 'link_library_links' != get_post_type( $post->ID ) ) { |
| 2174 |
$tag_array = array( 'link-library', 'link-library-cats', 'link-library-addlink', 'link-library-search', 'link-library-count', 'rss-library' ); |
| 2175 |
preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches ); |
| 2176 |
if( isset( $matches[2] ) ) { |
| 2177 |
foreach( ( array ) $matches[2] as $key => $value ) { |
| 2178 |
$load_style = true; |
| 2179 |
foreach( $tag_array as $tag ) { |
| 2180 |
if( $tag === $value ) { |
| 2181 |
if ( 'link-library-addlink' == $tag ) { |
| 2182 |
$load_recaptcha = true; |
| 2183 |
} |
| 2184 |
$atts_list = shortcode_parse_atts( $matches[3][$key] ); |
| 2185 |
if ( !empty( $atts_list ) ) { |
| 2186 |
foreach ( $atts_list as $key => $value ) { |
| 2187 |
if ( $key = 'settings' && ( empty( $settingssetsids ) || false === array_search( $value, $settingssetsids ) ) ) { |
| 2188 |
$settingssetsids[] = intval( $value ); |
| 2189 |
} |
| 2190 |
} |
| 2191 |
} else { |
| 2192 |
$settingssetsids[] = 1; |
| 2193 |
} |
| 2194 |
|
| 2195 |
} |
| 2196 |
} |
| 2197 |
} |
| 2198 |
} |
| 2199 |
|
| 2200 |
if ( function_exists( 'has_blocks' ) && function_exists( 'parse_blocks' ) ) { |
| 2201 |
if ( has_blocks( $post->ID ) ) { |
| 2202 |
$blocks = parse_blocks( $post->post_content ); |
| 2203 |
|
| 2204 |
foreach ( $blocks as $block ) { |
| 2205 |
if ( in_array( $block['blockName'], array( 'link-library/link-block', 'link-library/cat-block', 'link-library/search-block', 'link-library/addlink-block', 'link-library/count-block' ) ) ) { |
| 2206 |
$load_style = true; |
| 2207 |
} |
| 2208 |
|
| 2209 |
if ( in_array( $block['blockName'], array( 'link-library/addlink-block' ) ) ) { |
| 2210 |
$load_recaptcha = true; |
| 2211 |
} |
| 2212 |
|
| 2213 |
if ( isset( $block['attr']['settings'] ) && false === array_search( $block['attr']['settings'], $settingssetsids ) ) { |
| 2214 |
$settingssetsids[] = $block['attr']['settings']; |
| 2215 |
} elseif ( !isset( $block['attr']['settings'] ) ) { |
| 2216 |
$settingssetsids[] = 1; |
| 2217 |
} |
| 2218 |
} |
| 2219 |
} |
| 2220 |
} |
| 2221 |
} |
| 2222 |
} |
| 2223 |
|
| 2224 |
if ( empty( $settingssetsids ) ) { |
| 2225 |
$settingssetsids[] = 1; |
| 2226 |
} |
| 2227 |
|
| 2228 |
if ( $settingssetsids ) { |
| 2229 |
foreach ( $settingssetsids as $settingsetid ) { |
| 2230 |
$settingsetid = link_library_validate_settings_number( $settingsetid ); |
| 2231 |
$settingsname = 'LinkLibraryPP' . $settingsetid; |
| 2232 |
$options = get_option( $settingsname ); |
| 2233 |
$options = wp_parse_args( $options, ll_reset_options( 1, 'list', 'return' ) ); |
| 2234 |
|
| 2235 |
if ( $options['showonecatonly'] ) { |
| 2236 |
$load_jquery = true; |
| 2237 |
} |
| 2238 |
|
| 2239 |
if ( 'linkmasonrygrid' == $options['displayastable'] || 'categorymasonrygrid' == $options['displayastable'] ) { |
| 2240 |
$load_masonry = true; |
| 2241 |
} |
| 2242 |
|
| 2243 |
if ( $options['rsspreview'] || ( isset( $options['enable_link_popup'] ) && $options['enable_link_popup'] ) ) { |
| 2244 |
$load_thickbox = true; |
| 2245 |
} |
| 2246 |
|
| 2247 |
if ( $options['publishrssfeed'] == true ) { |
| 2248 |
global $rss_settings; |
| 2249 |
$rss_settings = $settingsetid; |
| 2250 |
} |
| 2251 |
|
| 2252 |
if ( $options['addlinkformdisplaymode'] ) { |
| 2253 |
$load_colorbox = true; |
| 2254 |
} |
| 2255 |
} |
| 2256 |
} |
| 2257 |
|
| 2258 |
if ( !empty( $genoptions['includescriptcss'] ) ) { |
| 2259 |
$pagelist = explode ( ',', $genoptions['includescriptcss'] ); |
| 2260 |
$loadscripts = false; |
| 2261 |
foreach( $pagelist as $pageid ) { |
| 2262 |
if ( ( $pageid == 'front' && is_front_page() ) || |
| 2263 |
( $pageid == 'category' && is_category() ) || |
| 2264 |
( $pageid == 'all') || |
| 2265 |
( is_page( $pageid ) ) ) { |
| 2266 |
$load_jquery = true; |
| 2267 |
$load_thickbox = true; |
| 2268 |
$load_style = true; |
| 2269 |
} |
| 2270 |
} |
| 2271 |
} |
| 2272 |
} |
| 2273 |
|
| 2274 |
if ( $load_style ) { |
| 2275 |
$llstylesheet = true; |
| 2276 |
} else { |
| 2277 |
$llstylesheet = false; |
| 2278 |
} |
| 2279 |
|
| 2280 |
if ( $load_jquery ) { |
| 2281 |
wp_enqueue_script( 'jquery' ); |
| 2282 |
} |
| 2283 |
|
| 2284 |
if ( $load_thickbox ) { |
| 2285 |
wp_enqueue_script( 'thickbox' ); |
| 2286 |
wp_enqueue_style ( 'thickbox' ); |
| 2287 |
} |
| 2288 |
|
| 2289 |
if ( $load_colorbox ) { |
| 2290 |
wp_enqueue_script( 'colorbox', plugins_url( 'colorbox/jquery.colorbox-min.js', __FILE__ ), array( 'jquery' ), "1.3.9" ); |
| 2291 |
wp_enqueue_style( 'colorboxstyle', plugins_url( 'colorbox/colorbox.css', __FILE__ ) ); |
| 2292 |
} |
| 2293 |
|
| 2294 |
if ( $load_recaptcha && $genoptions['captchagenerator'] ) { |
| 2295 |
wp_enqueue_script( 'google_recaptcha', 'https://www.google.com/recaptcha/api.js', array(), false, true ); |
| 2296 |
} |
| 2297 |
|
| 2298 |
if ( $load_masonry ) { |
| 2299 |
wp_enqueue_script( 'jquery-masonry' ); |
| 2300 |
} |
| 2301 |
|
| 2302 |
return $posts; |
| 2303 |
} |
| 2304 |
|
| 2305 |
function ll_popup_content() { |
| 2306 |
require_once plugin_dir_path( __FILE__ ) . 'linkpopup.php'; |
| 2307 |
link_library_popup_content( $this ); |
| 2308 |
} |
| 2309 |
|
| 2310 |
function ll_template_redirect( $template ) { |
| 2311 |
if ( !empty( $_POST['link_library_user_link_submission'] ) ) { |
| 2312 |
require_once plugin_dir_path( __FILE__ ) . 'usersubmission.php'; |
| 2313 |
link_library_process_user_submission( $this ); |
| 2314 |
return ''; |
| 2315 |
} elseif ( !empty( $_GET['link_library_rss_preview'] ) ) { |
| 2316 |
require_once plugin_dir_path( __FILE__ ) . 'rsspreview.php'; |
| 2317 |
link_library_generate_rss_preview( $this ); |
| 2318 |
return ''; |
| 2319 |
} elseif( !empty( $_GET['link_library_css'] ) ) { |
| 2320 |
require_once plugin_dir_path( __FILE__ ) . 'cssgenerator.php'; |
| 2321 |
link_library_generate_css( $this ); |
| 2322 |
return ''; |
| 2323 |
} elseif ( !empty( $_GET['link_library_popup_content'] ) ) { |
| 2324 |
require_once plugin_dir_path( __FILE__ ) . 'render-link-library-addlink-sc.php'; |
| 2325 |
link_library_link_submission_popup_form( $this ); |
| 2326 |
exit(); |
| 2327 |
} else { |
| 2328 |
return $template; |
| 2329 |
} |
| 2330 |
} |
| 2331 |
|
| 2332 |
function ll_template_include( $template_path ) { |
| 2333 |
if ( get_post_type() == 'link_library_links' && is_single() && !is_admin() ) { |
| 2334 |
// checks if the file exists in the theme first, |
| 2335 |
// otherwise serve the file from the plugin |
| 2336 |
if ( $theme_file = locate_template( array ( 'single-link_library_links.php' ) ) ) { |
| 2337 |
$template_path = $theme_file; |
| 2338 |
} else { |
| 2339 |
add_filter( 'the_content', array( $this, 'll_display_single_link' ), 20 ); |
| 2340 |
} |
| 2341 |
} |
| 2342 |
return $template_path; |
| 2343 |
} |
| 2344 |
|
| 2345 |
function ll_get_string_between($string, $start, $end){ |
| 2346 |
$string = ' ' . $string; |
| 2347 |
$ini = strpos($string, $start); |
| 2348 |
if ($ini == 0) return ''; |
| 2349 |
$ini += strlen($start); |
| 2350 |
$len = strpos($string, $end, $ini) - $ini; |
| 2351 |
return substr($string, $ini, $len); |
| 2352 |
} |
| 2353 |
|
| 2354 |
function ll_replace_all_between( $beginning, $end, $string, $replace ) { |
| 2355 |
$beginningPos = strpos($string, $beginning); |
| 2356 |
$endPos = strpos($string, $end); |
| 2357 |
if ($beginningPos === false || $endPos === false) { |
| 2358 |
return $string; |
| 2359 |
} |
| 2360 |
|
| 2361 |
$textToDelete = substr($string, $beginningPos, ($endPos + strlen($end)) - $beginningPos); |
| 2362 |
|
| 2363 |
return str_replace($textToDelete, $replace, $string); |
| 2364 |
} |
| 2365 |
|
| 2366 |
function ll_display_single_link( $content ) { |
| 2367 |
|
| 2368 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 2369 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 2370 |
|
| 2371 |
if ( ( is_search() || is_feed() ) && 'link_library_links' == get_post_type() ) { |
| 2372 |
$content = htmlspecialchars_decode( stripslashes( $genoptions['global_search_results_layout'] ) ); |
| 2373 |
} elseif ( is_single() && 'link_library_links' == get_post_type() ) { |
| 2374 |
$content = htmlspecialchars_decode( stripslashes( $genoptions['single_link_layout'] ) ); |
| 2375 |
} else { |
| 2376 |
return $content; |
| 2377 |
} |
| 2378 |
|
| 2379 |
$item_id = get_the_ID(); |
| 2380 |
if ( !empty( $item_id ) ) { |
| 2381 |
$link = get_post( get_the_ID() ); |
| 2382 |
if ( !empty( $link ) ) { |
| 2383 |
$link_url = esc_url( get_post_meta( get_the_ID(), 'link_url', true ) ); |
| 2384 |
$link_description = esc_html( get_post_meta( get_the_ID(), 'link_description', true ) ); |
| 2385 |
$link_large_description = get_post_meta( get_the_ID(), 'link_textfield', true ); |
| 2386 |
$link_image = esc_url( get_post_meta( get_the_ID(), 'link_image', true ) ); |
| 2387 |
$link_price = number_format( floatval( get_post_meta( get_the_ID(), 'link_price', true ) ), 2 ); |
| 2388 |
$link_price_currency = $this->ll_get_string_between( $content, '[currency]', '[/currency]' ); |
| 2389 |
$link_price_currency_or_free = $this->ll_get_string_between( $content, '[currency_or_free]', '[/currency_or_free]' ); |
| 2390 |
$link_email = esc_html( get_post_meta( get_the_ID(), 'link_email', true ) ); |
| 2391 |
$link_phone_number = esc_html( get_post_meta( get_the_ID(), 'link_telephone', true ) ); |
| 2392 |
|
| 2393 |
$link_terms = wp_get_post_terms( get_the_ID(), $genoptions['cattaxonomy'] ); |
| 2394 |
$link_terms_list = ''; |
| 2395 |
$link_terms_array = array(); |
| 2396 |
if ( is_array( $link_terms ) ) { |
| 2397 |
foreach( $link_terms as $link_term ) { |
| 2398 |
$link_terms_array[] = $link_term->name; |
| 2399 |
} |
| 2400 |
|
| 2401 |
if ( !empty( $link_terms_array ) ) { |
| 2402 |
$link_terms_list = implode( ', ', $link_terms_array ); |
| 2403 |
} |
| 2404 |
} |
| 2405 |
|
| 2406 |
if ( false !== strpos( $content, '[if_link_address]' ) && false !== strpos( $content, '[/if_link_address]' ) ) { |
| 2407 |
if ( empty( $link_url ) ) { |
| 2408 |
$content = preg_replace( '/\[if_link_address].*\[\/if_link_address\]?/', '', $content ); |
| 2409 |
} else { |
| 2410 |
$content = str_replace( '[if_link_address]', '', $content ); |
| 2411 |
$content = str_replace( '[/if_link_address]', '', $content ); |
| 2412 |
} |
| 2413 |
} |
| 2414 |
|
| 2415 |
if ( false !== strpos( $content, '[if_link_image]' ) && false !== strpos( $content, '[/if_link_image]' ) ) { |
| 2416 |
if ( empty( $link_image ) ) { |
| 2417 |
$content = preg_replace( '/\[if_link_image].*\[\/if_link_image\]?/', '', $content ); |
| 2418 |
} else { |
| 2419 |
$content = str_replace( '[if_link_image]', '', $content ); |
| 2420 |
$content = str_replace( '[/if_link_image]', '', $content ); |
| 2421 |
} |
| 2422 |
} |
| 2423 |
|
| 2424 |
$content = str_replace( '[link_title]', $link->post_title, $content ); |
| 2425 |
$content = str_replace( '[link_content]', $link->post_content, $content ); |
| 2426 |
$content = str_replace( '[link_description]', $link_description, $content ); |
| 2427 |
$content = str_replace( '[link_large_description]', $link_large_description, $content ); |
| 2428 |
$content = str_replace( '[link_image]', $link_image, $content ); |
| 2429 |
$content = str_replace( '[link_email]', $link_email, $content ); |
| 2430 |
$content = str_replace( '[link_telephone]', $link_phone_number, $content ); |
| 2431 |
|
| 2432 |
$content = str_replace( '[link_price]', $link_price, $content ); |
| 2433 |
$content = $this->ll_replace_all_between( '[currency]', '[/currency]', $content, $link_price_currency ); |
| 2434 |
|
| 2435 |
if ( floatval( $link_price ) > 0.0 ) { |
| 2436 |
$content = str_replace( '[link_price_or_free]', $link_price, $content ); |
| 2437 |
$content = $this->ll_replace_all_between( '[currency_or_free]', '[/currency_or_free]', $content, $link_price_currency_or_free ); |
| 2438 |
} else { |
| 2439 |
$content = str_replace( '[link_price_or_free]', __( 'Free', 'link-library' ), $content ); |
| 2440 |
$content = $this->ll_replace_all_between( '[currency_or_free]', '[/currency_or_free]', $content, '' ); |
| 2441 |
} |
| 2442 |
|
| 2443 |
$content = str_replace( '[link_address]', $link_url, $content ); |
| 2444 |
$content = str_replace( '[link]', '<a href="' . $link_url . '">' . $link->post_title . '</a>', $content ); |
| 2445 |
$content = str_replace( '[link_category]', $link_terms_list, $content ); |
| 2446 |
} |
| 2447 |
} |
| 2448 |
|
| 2449 |
global $wp_embed; |
| 2450 |
$content = $wp_embed->run_shortcode( $content ); |
| 2451 |
|
| 2452 |
$content = do_shortcode( $content ); |
| 2453 |
|
| 2454 |
//return nl2br( $content ); |
| 2455 |
return $content; |
| 2456 |
} |
| 2457 |
|
| 2458 |
function link_library_ajax_tracker() { |
| 2459 |
require_once plugin_dir_path( __FILE__ ) . 'tracker.php'; |
| 2460 |
link_library_process_ajax_tracker( $this ); |
| 2461 |
} |
| 2462 |
|
| 2463 |
function link_library_generate_image() { |
| 2464 |
global $my_link_library_plugin_admin; |
| 2465 |
|
| 2466 |
if ( empty( $my_link_library_plugin_admin ) ) { |
| 2467 |
require_once plugin_dir_path( __FILE__ ) . 'link-library-admin.php'; |
| 2468 |
$my_link_library_plugin_admin = new link_library_plugin_admin(); |
| 2469 |
} |
| 2470 |
|
| 2471 |
require_once plugin_dir_path( __FILE__ ) . 'link-library-image-generator.php'; |
| 2472 |
link_library_ajax_image_generator( $my_link_library_plugin_admin ); |
| 2473 |
} |
| 2474 |
} |
| 2475 |
|
| 2476 |
global $my_link_library_plugin; |
| 2477 |
$my_link_library_plugin = new link_library_plugin(); |
| 2478 |
|
| 2479 |
if ( is_admin() ) { |
| 2480 |
|
| 2481 |
/* Determine update method selected by user under General Settings or under Network Settings */ |
| 2482 |
$updatechannel = 'standard'; |
| 2483 |
|
| 2484 |
if ( ( function_exists( 'is_multisite' ) && !is_multisite() ) || !function_exists( 'is_multisite' ) ) { |
| 2485 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 2486 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 2487 |
|
| 2488 |
if ( !empty( $genoptions['updatechannel'] ) ) { |
| 2489 |
$updatechannel = $genoptions['updatechannel']; |
| 2490 |
} |
| 2491 |
} else if ( function_exists( 'is_multisite' ) && function_exists( 'is_network_admin' ) && is_multisite() && is_network_admin() ) { |
| 2492 |
$networkoptions = get_site_option( 'LinkLibraryNetworkOptions' ); |
| 2493 |
|
| 2494 |
if ( isset( $networkoptions ) && !empty( $networkoptions['updatechannel'] ) ) { |
| 2495 |
$updatechannel = $networkoptions['updatechannel']; |
| 2496 |
} |
| 2497 |
} |
| 2498 |
|
| 2499 |
/* Install filter is user selected monthly updates to filter out dot dot dot minor releases (e.g. 5.8.8.x) */ |
| 2500 |
if ( 'monthly' == $updatechannel ) { |
| 2501 |
add_filter( 'http_response', 'link_library_tweak_plugins_http_filter', 10, 3 ); |
| 2502 |
} |
| 2503 |
|
| 2504 |
if ( empty( $my_link_library_plugin_admin ) ) { |
| 2505 |
global $my_link_library_plugin_admin; |
| 2506 |
require plugin_dir_path( __FILE__ ) . 'link-library-admin.php'; |
| 2507 |
$my_link_library_plugin_admin = new link_library_plugin_admin(); |
| 2508 |
} |
| 2509 |
} |
| 2510 |
|
| 2511 |
add_action( 'widgets_init', 'll_create_widgets' ); |
| 2512 |
|
| 2513 |
function ll_create_widgets() { |
| 2514 |
register_widget( 'Link_Library_Widget' ); |
| 2515 |
} |
| 2516 |
|
| 2517 |
class Link_Library_Widget extends WP_Widget { |
| 2518 |
// Construction function |
| 2519 |
function __construct () { |
| 2520 |
parent::__construct( 'link_library', 'Link Library', |
| 2521 |
array( 'description' => |
| 2522 |
'Displays links as configured under Link Library configurations' ) ); |
| 2523 |
} |
| 2524 |
|
| 2525 |
function form( $instance ) { |
| 2526 |
$genoptions = get_option( 'LinkLibraryGeneral' ); |
| 2527 |
$genoptions = wp_parse_args( $genoptions, ll_reset_gen_settings( 'return' ) ); |
| 2528 |
|
| 2529 |
$selected_library = ( !empty( $instance['selected_library'] ) ? $instance['selected_library'] : 1 ); |
| 2530 |
$widget_title = ( !empty( $instance['widget_title'] ) ? esc_attr( $instance['widget_title'] ) : 'Links' ); |
| 2531 |
$category_list_override = ( !empty( $instance['cat_list_override'] ) ? esc_attr( $instance['cat_list_override'] ) : '' ); |
| 2532 |
?> |
| 2533 |
<p> |
| 2534 |
<label for="<?php echo $this->get_field_id( 'widget_title' ); ?>"> |
| 2535 |
<?php echo 'Widget Title:'; ?> |
| 2536 |
<input type="text" |
| 2537 |
id="<?php echo $this->get_field_id( 'widget_title' );?>" |
| 2538 |
name="<?php echo $this->get_field_name( 'widget_title' ); ?>" |
| 2539 |
value="<?php echo $widget_title; ?>" /> |
| 2540 |
</label> |
| 2541 |
</p> |
| 2542 |
<p> |
| 2543 |
<label for="<?php echo $this->get_field_id( 'selected_library' ); ?>"> |
| 2544 |
<?php echo 'Select library configuration to display:'; ?> |
| 2545 |
<select id="<?php echo $this->get_field_id( 'selected_library' ); ?>" |
| 2546 |
name="<?php echo $this->get_field_name( 'selected_library' ); ?>"> |
| 2547 |
<?php if ( empty( $genoptions['numberstylesets'] ) ) { |
| 2548 |
$numberofsets = 1; |
| 2549 |
} else { |
| 2550 |
$numberofsets = $genoptions['numberstylesets']; |
| 2551 |
} |
| 2552 |
|
| 2553 |
for ( $counter = 1; $counter <= $numberofsets; $counter ++ ) { |
| 2554 |
$tempoptionname = "LinkLibraryPP" . $counter; |
| 2555 |
$tempoptions = get_option( $tempoptionname ); |
| 2556 |
$tempoptions = wp_parse_args( $tempoptions, ll_reset_options( 1, 'list', 'return' ) ); |
| 2557 |
|
| 2558 |
echo '<option value="' . $counter . '" ' . selected( $selected_library, $counter ) . '>' . $tempoptions['settingssetname'] . '</option>'; |
| 2559 |
} |
| 2560 |
?> |
| 2561 |
</select> |
| 2562 |
</label> |
| 2563 |
</p> |
| 2564 |
<p> |
| 2565 |
<label for="<?php echo $this->get_field_id( 'cat_list_override' ); ?>"> |
| 2566 |
<?php echo 'Comma-separated list of categories to display:'; ?> |
| 2567 |
<input type="text" |
| 2568 |
id="<?php echo $this->get_field_id( 'cat_list_override' );?>" |
| 2569 |
name="<?php echo $this->get_field_name( 'cat_list_override' ); ?>" |
| 2570 |
value="<?php echo $category_list_override; ?>" /> |
| 2571 |
</label> |
| 2572 |
</p> |
| 2573 |
<?php } |
| 2574 |
|
| 2575 |
function widget( $args, $instance ) { |
| 2576 |
// Extract members of args array as individual variables |
| 2577 |
extract( $args ); |
| 2578 |
// Retrieve widget configuration options |
| 2579 |
$selected_library = ( !empty( $instance['selected_library'] ) ? $instance['selected_library'] : 1 ); |
| 2580 |
$widget_title = ( !empty( $instance['widget_title'] ) ? esc_attr( $instance['widget_title'] ) : 'Links' ); |
| 2581 |
$category_list_override = ( !empty( $instance['cat_list_override'] ) ? esc_attr( $instance['cat_list_override'] ) : '' ); |
| 2582 |
|
| 2583 |
// Display widget title |
| 2584 |
echo $before_widget . $before_title; |
| 2585 |
echo apply_filters( 'widget_title', $widget_title ); |
| 2586 |
echo $after_title; |
| 2587 |
|
| 2588 |
$shortcode_string = '[link-library settings="' . $selected_library . '"'; |
| 2589 |
|
| 2590 |
if ( !empty( $category_list_override ) ) { |
| 2591 |
$shortcode_string .= ' categorylistoverride="' . $category_list_override . '"'; |
| 2592 |
} |
| 2593 |
|
| 2594 |
$shortcode_string .= ']'; |
| 2595 |
|
| 2596 |
echo do_shortcode( $shortcode_string ); |
| 2597 |
|
| 2598 |
echo $after_widget; |
| 2599 |
} |
| 2600 |
} |
| 2601 |
|
| 2602 |
if ( ! function_exists('linklibrary_write_log')) { |
| 2603 |
function linklibrary_write_log ( $log ) { |
| 2604 |
if ( is_array( $log ) || is_object( $log ) ) { |
| 2605 |
error_log( print_r( $log, true ) ); |
| 2606 |
} else { |
| 2607 |
error_log( $log ); |
| 2608 |
} |
| 2609 |
} |
| 2610 |
} |
| 2611 |
} |
| 2612 |
|
| 2613 |
add_filter('wp_get_object_terms', function($terms, $object_ids, $taxonomies, $args) |
| 2614 |
{ |
| 2615 |
if ( !$terms && basename( $_SERVER['PHP_SELF'] ) == 'post-new.php' ) { |
| 2616 |
|
| 2617 |
// Category - note: only 1 category is supported currently |
| 2618 |
if ( $taxonomies == "'link_library_category'" && isset( $_REQUEST['link_library_cat'] ) ) { |
| 2619 |
$id = intval( $_REQUEST['link_library_cat'] ); |
| 2620 |
|
| 2621 |
if ( $id ) { |
| 2622 |
return array( $id ); |
| 2623 |
} |
| 2624 |
} |
| 2625 |
} |
| 2626 |
return $terms; |
| 2627 |
}, 10, 4); |
| 2628 |
|