PluginProbe
ManageWP Worker / 3.9.23
ManageWP Worker v3.9.23
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / link.class.php

link.class.php in ManageWP Worker 3.9.23, at link.class.php

182 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*************************************************************
3 *
4 * link.class.php
5 *
6 * Manage/Add Links
7 *
8 *
9 * Copyright (c) 2011 Prelovac Media
10 * www.prelovac.com
11 **************************************************************/
12 if(basename($_SERVER['SCRIPT_FILENAME']) == "link.class.php"):
13 exit;
14 endif;
15 class MMB_Link extends MMB_Core
16 {
17 function __construct()
18 {
19 parent::__construct();
20 }
21
22 function add_link($args)
23 {
24 extract($args);
25
26 $params['link_url'] = esc_html($url);
27 $params['link_url'] = esc_url($params['link_url']);
28 $params['link_name'] = esc_html($name);
29 $params['link_id'] = '';
30 $params['link_description'] = $description;
31 $params['link_target'] = $link_target;
32 $params['link_category'] = array();
33
34 //Add Link category
35 if(is_array($link_category) && !empty($link_category)){
36 $terms = get_terms('link_category',array('hide_empty' => 0));
37
38 if($terms){
39 foreach($terms as $term){
40 if(in_array($term->name,$link_category)){
41 $params['link_category'][] = $term->term_id;
42 $link_category = $this->remove_element($link_category, $term->name);
43 }
44 }
45 }
46 if(!empty($link_category)){
47 foreach($link_category as $linkkey => $linkval){
48 if(!empty($linkval)){
49 $link = wp_insert_term($linkval,'link_category');
50
51 if(isset($link['term_id']) && !empty($link['term_id'])){
52 $params['link_category'][] = $link['term_id'];
53 }
54 }
55 }
56 }
57 }
58
59 //Add Link Owner
60 $user_obj = get_userdatabylogin($user);
61 if($user_obj && $user_obj->ID){
62 $params['link_owner'] = $user_obj->ID;
63 }
64
65
66 if(!function_exists('wp_insert_link'))
67 include_once (ABSPATH . 'wp-admin/includes/bookmark.php');
68
69 $is_success = wp_insert_link($params);
70
71 return $is_success ? true : array('error' => 'Failed to add link.');
72 }
73
74 function remove_element($arr, $val){
75 foreach ($arr as $key => $value){
76 if ($value == $val){
77 unset($arr[$key]);
78 }
79 }
80 return $arr = array_values($arr);
81 }
82
83 function get_links($args){
84 global $wpdb;
85
86 $where='';
87
88 extract($args);
89
90 if(!empty($filter_links))
91 {
92 $where.=" AND (link_name LIKE '%".mysql_real_escape_string($filter_links)."%' OR link_url LIKE '%".mysql_real_escape_string($filter_links)."%')";
93 }
94
95 $linkcats = $this->getLinkCats();
96 $sql_query = "$wpdb->links WHERE 1=1 ".$where;
97
98 $links_total = $wpdb->get_results("SELECT count(*) as total_links FROM ".$sql_query);
99 $total=$links_total[0]->total_links;
100
101 $query_links = $wpdb->get_results("SELECT link_id, link_url, link_name, link_target, link_visible, link_rating, link_rel FROM ".$sql_query." ORDER BY link_name ASC LIMIT 500");
102 $links = array();
103 foreach ( $query_links as $link_info )
104 {
105 $link_cat = $linkcats[$link_info->link_id];
106 $cats = array();
107 foreach($link_cat as $catkey=>$catval)
108 {
109 $cats[] = $catval;
110 }
111
112 $links[$link_info->link_id] = array(
113 "link_url" => $link_info->link_url,
114 "link_name" => $link_info->link_name,
115 "link_target" => $link_info->link_target,
116 "link_visible" => $link_info->link_visible,
117 "link_rating" => $link_info->link_rating,
118 "link_rel" => $link_info->link_rel,
119 "link_cats" => $cats
120 );
121 }
122
123 return array('links' => $links, 'total' => $total);
124 }
125
126 function getLinkCats($taxonomy = 'link_category')
127 {
128 global $wpdb;
129
130 $cats = $wpdb->get_results("SELECT l.link_id, $wpdb->terms.name
131 FROM $wpdb->links AS l
132 INNER JOIN $wpdb->term_relationships ON ( l.link_id = $wpdb->term_relationships.object_id )
133 INNER JOIN $wpdb->term_taxonomy ON ( $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
134 AND $wpdb->term_taxonomy.taxonomy = '".$taxonomy."' )
135 INNER JOIN $wpdb->terms ON ( $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id )");
136
137 foreach ( $cats as $post_val )
138 {
139
140 $post_cats[$post_val->link_id][] = $post_val->name;
141 }
142
143 return $post_cats;
144 }
145
146 function delete_link($args){
147 global $wpdb;
148
149 if(!empty($args['link_id']))
150 {
151 $delete_query = "DELETE FROM $wpdb->links WHERE link_id = ".$args['link_id'];
152 $wpdb->get_results($delete_query);
153
154 return 'Link deleted.';
155 }
156 else
157 {
158 return 'No ID...';
159 }
160 }
161
162 function delete_links($args){
163 global $wpdb;
164 extract($args);
165
166 if($deleteaction=='delete'){
167 $delete_query_intro = "DELETE FROM $wpdb->links WHERE link_id = ";
168 }
169 foreach($args as $key=>$val){
170
171 if(!empty($val) && is_numeric($val))
172 {
173 $delete_query = $delete_query_intro.$val;
174
175 $wpdb->query($delete_query);
176 }
177 }
178 return "Link deleted";
179 }
180
181 }
182 ?>