Alessio Caiazza is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this againAbout Me / aboutme.php
- commit
- b017b58d9ece
- parent
- 50c112310e9e
- branch
- default
Anobii, DeviantART, LibraryThingand and Songza support. Closes #17 and #18 and #19 and #20 and #22
1 |
d0811661659f
|
<?php |
2 |
d0811661659f
|
/* |
3 |
d0811661659f
|
Plugin Name: About Me |
4 |
d0811661659f
|
Plugin URI: http://abisso.org/index.php/projects/about-me/ |
5 |
d0811661659f
|
Description: About Me is a sidebar widget that displays icon links to your profile pages on other social networking sites. Forked from <a href="http://blog.maybe5.com/?page_id=94">Social Links</a> |
6 |
d0811661659f
|
Author: Alessio Caiazza |
7 |
16c353b7df55
|
Version: 1.0.6 |
8 |
d0811661659f
|
Author URI: http://alessiocaiazza.info |
9 |
d0811661659f
|
|
10 |
d0811661659f
|
/* Social Links Copyright 2008 Kareem Sultan (email : kareemsultan@gmail.com) */ |
11 |
d0811661659f
|
/* |
12 |
7bbb9825c407
|
(c) 2009 Alessio Caiazza |
13 |
7bbb9825c407
|
This program is free software; you can redistribute it and/or modify |
14 |
7bbb9825c407
|
it under the terms of the GNU General Public License as published by |
15 |
7bbb9825c407
|
the Free Software Foundation; either version 2 of the License, or |
16 |
7bbb9825c407
|
(at your option) any later version. |
17 |
d0811661659f
|
|
18 |
7bbb9825c407
|
This program is distributed in the hope that it will be useful, |
19 |
7bbb9825c407
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 |
7bbb9825c407
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 |
7bbb9825c407
|
GNU General Public License for more details. |
22 |
d0811661659f
|
|
23 |
7bbb9825c407
|
You should have received a copy of the GNU General Public License |
24 |
7bbb9825c407
|
along with this program; if not, write to the Free Software |
25 |
7bbb9825c407
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
26 |
d0811661659f
|
|
27 |
7bbb9825c407
|
http://www.gnu.org/licenses/gpl.txt |
28 |
d0811661659f
|
|
29 |
d0811661659f
|
*/ |
30 |
d0811661659f
|
|
31 |
d0811661659f
|
//call install function upon activation |
32 |
6536221ffa83
|
register_activation_hook(__FILE__,'social_links_install'); |
33 |
6536221ffa83
|
|
34 |
d0811661659f
|
//TO DO use these definitions instead |
35 |
16c353b7df55
|
define('SOCIAL_LINKS_VERSION', '1.0.6'); |
36 |
d0811661659f
|
define('SOCIAL_LINKS_DB_VERSION', '1.1'); |
37 |
d0811661659f
|
|
38 |
d0811661659f
|
define('KEY_SITE_ID',0); |
39 |
d0811661659f
|
define('KEY_IMAGE',1); |
40 |
d0811661659f
|
define('KEY_URL_TEMPLATE',2); |
41 |
d0811661659f
|
define('KEY_INSTRUCTION',3); |
42 |
d0811661659f
|
define('KEY_DISPLAY_NAME',4); |
43 |
7bbb9825c407
|
|
44 |
6536221ffa83
|
//$sl_db_version = "1.0"; |
45 |
38f374c63b59
|
$plugindir = get_bloginfo('wpurl').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__)); |
46 |
d0811661659f
|
|
47 |
6536221ffa83
|
$definitions = array( |
48 |
7bbb9825c407
|
array(0,'facebook.png','%userid%','Enter your complete Facebook profile URL','Facebook'), |
49 |
7bbb9825c407
|
array(1,'myspace.png','%userid%','Enter your complete MySpace URL.','MySpace'), |
50 |
7bbb9825c407
|
array(2,'linkedin.png','%userid%','Enter your complete LinkedIn URL.','LinkedIn'), |
51 |
7bbb9825c407
|
array(3,'picasa.png','http://picasaweb.google.com/%userid%','Enter your Picasa(Google) username.','Picasa Web Album'), |
52 |
7bbb9825c407
|
array(4,'flickr.png','http://flickr.com/photos/%userid%','Enter your flickr username','Flickr'), |
53 |
7bbb9825c407
|
array(5,'youtube.png','http://www.youtube.com/%userid%','Enter your YouTube username','YouTube'), |
54 |
7bbb9825c407
|
array(6,'twitter.png','http://twitter.com/%userid%','Enter your Twitter username','Twitter'), |
55 |
7bbb9825c407
|
array(7,'pownce.png','http://pownce.com/%userid%','Enter your Pownce username','Pownce'), |
56 |
7bbb9825c407
|
array(8,'plurk.png','http://www.plurk.com/user/%userid%','Enter your Plurk username','Plurk'), |
57 |
7bbb9825c407
|
array(9,'digg.png','http://www.digg.com/users/%userid%','Enter your Digg username.','Digg'), |
58 |
7bbb9825c407
|
array(10,'delicious.png','http://delicious.com/%userid%','Enter your Delicious username','Delicious'), |
59 |
7bbb9825c407
|
array(11,'blogmarks.png','http://blogmarks.net/user/%userid%','Enter your BlogMarks username.','BlogMarks'), |
60 |
7bbb9825c407
|
array(12,'stumbleupon.png','http://%userid%.stumbleupon.com','Enter your Stumble Upon username','Stumble Upon'), |
61 |
7bbb9825c407
|
array(13,'lastfm.png','http://www.last.fm/user/%userid%','Enter your Last.fm username','Last.fm'), |
62 |
7bbb9825c407
|
array(14,'amazon.png','%userid%','Enter your complete Amazon Wishlist URL','Amazon Wishlist'), |
63 |
7bbb9825c407
|
array(15,'blog.png','%userid%','Enter the complete blog URL.','Blog'), |
64 |
7bbb9825c407
|
array(16,'jeqq.png','http://www.jeqq.com/user/view/profile/%userid%','Enter your Jeqq username','Jeqq'), |
65 |
7bbb9825c407
|
array(17,'dapx.png','%userid%','Enter your complete Dapx URL.','Dapx'), |
66 |
7bbb9825c407
|
array(18,'xing.jpg','%userid%','Enter your complete Xing URL.','Xing'), |
67 |
7bbb9825c407
|
array(19,'sixent.png','http://%userid%.sixent.com/','Enter your Sixent username','Sixent'), |
68 |
7bbb9825c407
|
array(20,'technorati.jpg','http://technorati.com/people/technorati/%userid%/','Enter your Technorati username.','Technorati'), |
69 |
7bbb9825c407
|
array(21,'friendfeed.png','http://friendfeed.com/%userid%','Enter your FriendFeed username.','FriendFeed'), |
70 |
7bbb9825c407
|
array(22,'identica.png','http://identi.ca/%userid%','Enter your Identi.ca username.','Identi.ca'), |
71 |
7bbb9825c407
|
array(23,'bitbucket.png','http://bitbucket.org/%userid%','Enter your Bitbucket username.','Bitbucket'), |
72 |
7bbb9825c407
|
array(24,'github.png','http://github.com/%userid%','Enter your Github username.','Github'), |
73 |
7bbb9825c407
|
array(25,'hellotxt.gif','http://hellotxt.com/user/%userid%','Enter your Hellotxt username.','Hellotxt'), |
74 |
7bbb9825c407
|
array(26,'hyves.png','http://%userid%.hyves.nl','Enter your Hyves.nl username.','Hyves.nl'), |
75 |
7bbb9825c407
|
array(27,'disqus.png','http://disqus.com/people/%userid%','Enter your Disqus username.','Disqus'), |
76 |
e0a831f2e6cc
|
array(28,'redgage.png','http://www.redgage.com/%userid%','Enter your RedGage username.','RedGage'), |
77 |
a7740ab344f9
|
array(29,'goodreads.png','http://goodreads.com/%userid%','Enter your GoodReads username','GoodReads'), |
78 |
a7740ab344f9
|
array(30,'qype.png','http://www.qype.com/people/%userid%','Enter your Qype username.','Qype'), |
79 |
a7740ab344f9
|
array(31,'orkut.png','http://www.orkut.com/Main#Profile.aspx?uid=%userid%','Enter your Orkut numeric uid.','Orkut'), |
80 |
a7740ab344f9
|
array(32,'google.png','http://www.google.com/profiles/%userid%','Enter your Google username (without @google.com).','Google Profile'), |
81 |
bc475f73a498
|
array(33,'googlereader.png','http://www.google.com/reader/shared/%userid%','Enter your Google Reader shared number.','Google Reader'), |
82 |
866ae0efe9b2
|
array(34,'ebay.png','http://myworld.ebay.com/%userid%','Enter your Ebay username.','Ebay'), |
83 |
b017b58d9ece
|
array(35,'qik.png','http://qik.com/%userid%','Enter your Qik username.','Qik'), |
84 |
b017b58d9ece
|
array(36,'anobii.png','http://www.anobii.com/%userid%','Enter your Anobii username.','Anobii'), |
85 |
b017b58d9ece
|
array(37,'deviantart.png','http://%userid%.deviantart.com','Enter your deviantART username.','DeviantART'), |
86 |
b017b58d9ece
|
array(38,'songza.png','http://songza.fm/%userid%','Enter your songza username.','Songza'), |
87 |
b017b58d9ece
|
array(39,'librarything.png','http://www.librarything.com/profile/%userid%','Enter your LibraryThing username.','LibraryThing'), |
88 |
b017b58d9ece
|
|
89 |
6536221ffa83
|
); |
90 |
d0811661659f
|
|
91 |
29335354181d
|
//comparison based on socialnetwok name |
92 |
29335354181d
|
function compare_social($s1, $s2) { |
93 |
7bbb9825c407
|
return strcmp($s1[KEY_DISPLAY_NAME], $s2[KEY_DISPLAY_NAME]); |
94 |
29335354181d
|
} |
95 |
d0811661659f
|
|
96 |
29335354181d
|
//Sorts socialnetworks in alphabetical order |
97 |
29335354181d
|
uasort($definitions, "compare_social"); |
98 |
d0811661659f
|
|
99 |
d0811661659f
|
|
100 |
d0811661659f
|
function social_links_wrapper(){ |
101 |
d0811661659f
|
|
102 |
7bbb9825c407
|
// This only works if the widget api is installed |
103 |
7bbb9825c407
|
if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') ) |
104 |
7bbb9825c407
|
return; // ...and if not, exit gracefully from the script. |
105 |
d0811661659f
|
|
106 |
7bbb9825c407
|
//WPD_print('Filename: '.__FILE__); |
107 |
7bbb9825c407
|
//WPD_print('DB version: '.get_option( "SOCIAL_LINKS_DB_VERSION" )); |
108 |
7bbb9825c407
|
// Displays the icons in the sidebar |
109 |
7bbb9825c407
|
function widget_social_links($args) { |
110 |
7bbb9825c407
|
global $definitions; |
111 |
7bbb9825c407
|
extract($args); |
112 |
6536221ffa83
|
|
113 |
7bbb9825c407
|
$options = get_option('widget_social_links'); |
114 |
7bbb9825c407
|
$title = empty($options['title']) ? 'About Me' : $options['title']; |
115 |
7bbb9825c407
|
$width = empty($options['width']) ? 20 : $options['width']; |
116 |
6536221ffa83
|
|
117 |
7bbb9825c407
|
echo $before_widget; |
118 |
7bbb9825c407
|
echo $before_title . $title . $after_title ; |
119 |
6536221ffa83
|
|
120 |
7bbb9825c407
|
echo '<!-- About Me Version: '. SOCIAL_LINKS_VERSION .' -->'; |
121 |
7bbb9825c407
|
echo "<div id='socialLinksContainer' style='width:$width"."px;'>"; |
122 |
7bbb9825c407
|
echo generateSocialLinksInnerHTML(); |
123 |
7bbb9825c407
|
echo '</div>'; |
124 |
7bbb9825c407
|
echo $after_widget; |
125 |
6536221ffa83
|
|
126 |
7bbb9825c407
|
} |
127 |
6536221ffa83
|
|
128 |
7bbb9825c407
|
//Config Panel |
129 |
7bbb9825c407
|
function widget_social_links_control() { |
130 |
7bbb9825c407
|
global $definitions; |
131 |
7bbb9825c407
|
$options = get_option('widget_social_links'); |
132 |
6536221ffa83
|
|
133 |
7bbb9825c407
|
if ( $_POST['social-links-submit'] ) { |
134 |
7bbb9825c407
|
// Clean up control form submission options |
135 |
7bbb9825c407
|
$newoptions['title'] = strip_tags(stripslashes($_POST['social-links-title'])); |
136 |
7bbb9825c407
|
$newoptions['width'] = strip_tags(stripslashes($_POST['social-links-width'])); |
137 |
d0811661659f
|
|
138 |
7bbb9825c407
|
|
139 |
7bbb9825c407
|
if ( $options != $newoptions ) { |
140 |
7bbb9825c407
|
$options = $newoptions; |
141 |
7bbb9825c407
|
update_option('widget_social_links', $options); |
142 |
7bbb9825c407
|
} |
143 |
7bbb9825c407
|
} |
144 |
7bbb9825c407
|
|
145 |
7bbb9825c407
|
$title = empty($options['title']) ? 'About Me' : $options['title']; |
146 |
7bbb9825c407
|
$width = empty($options['width']) ? 100 : $options['width']; |
147 |
7bbb9825c407
|
|
148 |
7bbb9825c407
|
?> |
149 |
7bbb9825c407
|
|
150 |
7bbb9825c407
|
<table> |
151 |
7bbb9825c407
|
<tr><td> |
152 |
7bbb9825c407
|
<label for="social-links-title">Widget title: <input type="text" id="social-links-title" name="social-links-title" value="<?php echo $title; ?>" /></label> |
153 |
7bbb9825c407
|
</td></tr> |
154 |
7bbb9825c407
|
<tr><td> |
155 |
7bbb9825c407
|
<label for="social-links-width">Width: <input type="text" id="social-links-width" name="social-links-width" size="8" value="<?php echo $width; ?>" /> pixels</label> |
156 |
7bbb9825c407
|
</td></tr> |
157 |
7bbb9825c407
|
</table> |
158 |
7bbb9825c407
|
<input type="hidden" name="social-links-submit" id="social-links-submit" value="1" /> |
159 |
7bbb9825c407
|
|
160 |
7bbb9825c407
|
<?php |
161 |
7bbb9825c407
|
}//End of widget_social_links_control |
162 |
7bbb9825c407
|
|
163 |
7bbb9825c407
|
|
164 |
7bbb9825c407
|
function wp_ajax_social_links_add_network(){ |
165 |
7bbb9825c407
|
// read submitted information |
166 |
7bbb9825c407
|
global $definitions; |
167 |
7bbb9825c407
|
|
168 |
7bbb9825c407
|
$siteID = $_POST['siteID']; |
169 |
7bbb9825c407
|
$data = $_POST['value']; |
170 |
7bbb9825c407
|
$messageId = $_POST['responseDiv']; |
171 |
7bbb9825c407
|
|
172 |
7bbb9825c407
|
$result = insertNetwork($siteID,$data); |
173 |
7bbb9825c407
|
if($result == 1) |
174 |
7bbb9825c407
|
$result = 'Link added.'; |
175 |
7bbb9825c407
|
else |
176 |
7bbb9825c407
|
$result = 'There was a problem adding the link. Refresh the page and try again.'; |
177 |
7bbb9825c407
|
|
178 |
7bbb9825c407
|
$innerHTML = generateSocialLinksPreviewInnerHTML(''); |
179 |
7bbb9825c407
|
die(' |
180 |
7bbb9825c407
|
$("message").innerHTML = "'.$result.'"; |
181 |
7bbb9825c407
|
$("message").className="updated fade"; |
182 |
7bbb9825c407
|
$("message").style.visibility = "visible"; |
183 |
7bbb9825c407
|
document.getElementById("displayDiv").innerHTML = "'.$innerHTML.'"; |
184 |
7bbb9825c407
|
createSortables(); |
185 |
7bbb9825c407
|
'); |
186 |
7bbb9825c407
|
|
187 |
7bbb9825c407
|
//Add this line to the above javascript to show the complete table. |
188 |
7bbb9825c407
|
//document.getElementById("editDiv").innerHTML = "' . generateSocialLinksEditInnerHTML(). '"; |
189 |
7bbb9825c407
|
} |
190 |
7bbb9825c407
|
|
191 |
7bbb9825c407
|
//TODO: Implement the add ajax process to send data and let the javascript add child elements |
192 |
7bbb9825c407
|
//This is to avoid using innerHTML replacement and will then allow for more advanced client side effects |
193 |
7bbb9825c407
|
/* function wp_ajax_social_links_add_network_send_data(){ |
194 |
7bbb9825c407
|
// read submitted information |
195 |
7bbb9825c407
|
global $definitions; |
196 |
7bbb9825c407
|
|
197 |
7bbb9825c407
|
$selectedIndex = $_POST['networkIndex']; |
198 |
7bbb9825c407
|
$data = $_POST['value']; |
199 |
7bbb9825c407
|
|
200 |
7bbb9825c407
|
$result = insertNetwork($selectedIndex,$data); |
201 |
7bbb9825c407
|
$data = generateSocialLinksData(); |
202 |
7bbb9825c407
|
//$result = 'fake insert'; |
203 |
7bbb9825c407
|
die("$result |
204 |
7bbb9825c407
|
$('message').innerHTML = 'Database result is $result.'; |
205 |
7bbb9825c407
|
$('message').class='updated fade'; |
206 |
7bbb9825c407
|
$('message').style.visibility = 'visible'; |
207 |
7bbb9825c407
|
updateSocialLinks($data); |
208 |
7bbb9825c407
|
"); |
209 |
7bbb9825c407
|
|
210 |
7bbb9825c407
|
} |
211 |
7bbb9825c407
|
*/ |
212 |
7bbb9825c407
|
function wp_ajax_social_links_delete_network(){ |
213 |
7bbb9825c407
|
global $wpdb; |
214 |
7bbb9825c407
|
global $definitions; |
215 |
7bbb9825c407
|
|
216 |
7bbb9825c407
|
$linkId = $_POST['linkId']; |
217 |
7bbb9825c407
|
//WPD_print('deleting linkID='. $linkId); |
218 |
7bbb9825c407
|
$table_name = $wpdb->prefix . "social_links"; |
219 |
7bbb9825c407
|
$sql = 'delete from ' . $table_name . ' where id='.$linkId; |
220 |
7bbb9825c407
|
$result = $wpdb->query($wpdb->prepare($sql)); |
221 |
7bbb9825c407
|
|
222 |
7bbb9825c407
|
if($result == 1) |
223 |
7bbb9825c407
|
$result = 'Removed link.'; |
224 |
7bbb9825c407
|
else |
225 |
7bbb9825c407
|
$result = 'There was a problem deleting the link. Refresh the page and try again.'.$sql; |
226 |
7bbb9825c407
|
//WPD_print($result); |
227 |
7bbb9825c407
|
die(' |
228 |
7bbb9825c407
|
$("message").innerHTML = "'.$result.'"; |
229 |
7bbb9825c407
|
$("message").className="updated fade"; |
230 |
7bbb9825c407
|
$("message").style.visibility = "visible"; |
231 |
7bbb9825c407
|
'); |
232 |
7bbb9825c407
|
} |
233 |
7bbb9825c407
|
|
234 |
7bbb9825c407
|
|
235 |
7bbb9825c407
|
|
236 |
7bbb9825c407
|
|
237 |
7bbb9825c407
|
|
238 |
7bbb9825c407
|
function insertNetwork($id,$value){ |
239 |
7bbb9825c407
|
|
240 |
7bbb9825c407
|
|
241 |
7bbb9825c407
|
//WPD_print('Inserting new network'); |
242 |
7bbb9825c407
|
global $wpdb; |
243 |
7bbb9825c407
|
|
244 |
7bbb9825c407
|
//WPD_print('networkID='.$id.' data='.$value); |
245 |
7bbb9825c407
|
$table_name = $wpdb->prefix . "social_links"; |
246 |
7bbb9825c407
|
$sql = 'Insert into ' . $table_name . ' (network_id,user_info,sort_order) VALUES ("'.$id.'","'.$value.'",1000)'; |
247 |
7bbb9825c407
|
$result = $wpdb->query($wpdb->prepare($sql)); |
248 |
7bbb9825c407
|
//WPD_print($sql); |
249 |
7bbb9825c407
|
return $result; |
250 |
7bbb9825c407
|
} |
251 |
7bbb9825c407
|
|
252 |
7bbb9825c407
|
function getSocialLinks(){ |
253 |
7bbb9825c407
|
global $wpdb; |
254 |
7bbb9825c407
|
$table_name = $wpdb->prefix . "social_links"; |
255 |
7bbb9825c407
|
$sql = 'Select * from ' . $table_name . ' order by sort_order'; |
256 |
7bbb9825c407
|
$results = $wpdb->get_results($sql,ARRAY_N); |
257 |
7bbb9825c407
|
////WPD_print("Select networks results: ".$results); |
258 |
7bbb9825c407
|
return $results; |
259 |
7bbb9825c407
|
|
260 |
7bbb9825c407
|
} |
261 |
7bbb9825c407
|
|
262 |
7bbb9825c407
|
function generateSocialLinksInnerHTML(){ |
263 |
7bbb9825c407
|
global $definitions; |
264 |
7bbb9825c407
|
global $plugindir; |
265 |
7bbb9825c407
|
|
266 |
7bbb9825c407
|
$rows = getSocialLinks(); |
267 |
7bbb9825c407
|
if(count($rows)==0) |
268 |
7bbb9825c407
|
return; |
269 |
7bbb9825c407
|
////WPD_print("Found".count($rows)." networks."); |
270 |
7bbb9825c407
|
|
271 |
7bbb9825c407
|
foreach ($rows as $row) { |
272 |
7bbb9825c407
|
//WPD_print("SiteID: " . $row[1]); |
273 |
7bbb9825c407
|
$linkInfoArray = $definitions[$row[1]]; |
274 |
7bbb9825c407
|
//WPD_print('network info '. $linkInfoArray); |
275 |
7bbb9825c407
|
$url = str_replace("%userid%",$row[2],$linkInfoArray[KEY_URL_TEMPLATE]); |
276 |
7bbb9825c407
|
$innerHTML = $innerHTML . "<a id='link_$row[0]' href='$url' rel='me'><img src='$plugindir/images/".$linkInfoArray[KEY_IMAGE]."' alt='".$linkInfoArray[KEY_DISPLAY_NAME]."' title='".$linkInfoArray[KEY_DISPLAY_NAME]."'/></a>"; |
277 |
7bbb9825c407
|
if($row != $rows[count($rows)-1]){ |
278 |
7bbb9825c407
|
$innerHTML = $innerHTML."\n"; |
279 |
7bbb9825c407
|
} |
280 |
7bbb9825c407
|
} |
281 |
7bbb9825c407
|
|
282 |
7bbb9825c407
|
return $innerHTML; |
283 |
7bbb9825c407
|
} |
284 |
7bbb9825c407
|
|
285 |
7bbb9825c407
|
function generateSocialLinksPreviewInnerHTML($delimiter){ |
286 |
7bbb9825c407
|
global $definitions; |
287 |
7bbb9825c407
|
global $plugindir; |
288 |
7bbb9825c407
|
|
289 |
7bbb9825c407
|
$rows = getSocialLinks(); |
290 |
7bbb9825c407
|
if(count($rows)==0) |
291 |
7bbb9825c407
|
return; |
292 |
7bbb9825c407
|
//WPD_print("Found ".count($rows)." networks."); |
293 |
7bbb9825c407
|
|
294 |
7bbb9825c407
|
foreach ($rows as $row) { |
295 |
7bbb9825c407
|
//WPD_print("SiteID: " . $row[2]); |
296 |
7bbb9825c407
|
//var_dump($row); |
297 |
7bbb9825c407
|
$linkInfoArray = $definitions[$row[1]]; |
298 |
7bbb9825c407
|
//var_dump($linkInfoArray); |
299 |
7bbb9825c407
|
//WPD_print('network info '. $linkInfoArray); |
300 |
7bbb9825c407
|
$url = str_replace("%userid%",$row[2],$linkInfoArray[KEY_URL_TEMPLATE]); |
301 |
7bbb9825c407
|
$innerHTML = $innerHTML . "<span id='link_$row[0]' title='$url'><img style='margin:2px' src='$plugindir/images/".$linkInfoArray[KEY_IMAGE]."' alt='".$linkInfoArray[KEY_DISPLAY_NAME]."' title='".$linkInfoArray[KEY_DISPLAY_NAME]."'/></span>"; |
302 |
7bbb9825c407
|
if($row != $rows[count($rows)-1]){ |
303 |
7bbb9825c407
|
$innerHTML = $innerHTML.$delimiter; |
304 |
7bbb9825c407
|
} |
305 |
7bbb9825c407
|
} |
306 |
7bbb9825c407
|
|
307 |
7bbb9825c407
|
return $innerHTML; |
308 |
7bbb9825c407
|
} |
309 |
7bbb9825c407
|
|
310 |
7bbb9825c407
|
/* |
311 |
7bbb9825c407
|
function generateSocialLinksData(){ |
312 |
7bbb9825c407
|
global $definitions; |
313 |
7bbb9825c407
|
|
314 |
7bbb9825c407
|
$rows = getSocialLinks(); |
315 |
7bbb9825c407
|
if(count($rows)==0) |
316 |
7bbb9825c407
|
return; |
317 |
7bbb9825c407
|
////WPD_print("Found".count($rows)." networks."); |
318 |
7bbb9825c407
|
$data = ''; |
319 |
7bbb9825c407
|
foreach ($rows as $row) { |
320 |
7bbb9825c407
|
$linkInfoArray = $definitions[$row[2]]; |
321 |
7bbb9825c407
|
$data += "link_$row[0],$linkInfoArray[0],$linkInfoArray[1],$linkInfoArray[4]\n"; |
322 |
7bbb9825c407
|
} |
323 |
7bbb9825c407
|
return $data; |
324 |
7bbb9825c407
|
|
325 |
7bbb9825c407
|
} |
326 |
7bbb9825c407
|
*/ |
327 |
7bbb9825c407
|
|
328 |
7bbb9825c407
|
function social_links_admin_menu(){ |
329 |
38f374c63b59
|
|
330 |
7bbb9825c407
|
add_management_page('Social Links Settings - About Me', 'About Me', 8,__FILE__,'widget_social_links_settings'); |
331 |
7bbb9825c407
|
|
332 |
7bbb9825c407
|
global $plugindir; |
333 |
7bbb9825c407
|
wp_enqueue_script('about-me', $plugindir . '/javascript.js',array('sack')); |
334 |
7bbb9825c407
|
wp_enqueue_script('scriptaculous'); |
335 |
7bbb9825c407
|
} |
336 |
7bbb9825c407
|
|
337 |
7bbb9825c407
|
function addHeaderCode(){ |
338 |
7bbb9825c407
|
//WPD_print("header code"); |
339 |
7bbb9825c407
|
global $plugindir; |
340 |
7bbb9825c407
|
echo '<link type="text/css" rel="stylesheet" href="' . $plugindir . '/stylesheet.css" />' . "\n"; |
341 |
7bbb9825c407
|
|
342 |
7bbb9825c407
|
} |
343 |
7bbb9825c407
|
|
344 |
7bbb9825c407
|
|
345 |
7bbb9825c407
|
|
346 |
7bbb9825c407
|
////WPD_print("Registering plugin"); |
347 |
7bbb9825c407
|
|
348 |
7bbb9825c407
|
add_action('wp_head','addHeaderCode'); |
349 |
7bbb9825c407
|
|
350 |
7bbb9825c407
|
|
351 |
7bbb9825c407
|
|
352 |
7bbb9825c407
|
//Add action to load sub menu |
353 |
7bbb9825c407
|
add_action('admin_menu', 'social_links_admin_menu'); |
354 |
7bbb9825c407
|
|
355 |
7bbb9825c407
|
|
356 |
7bbb9825c407
|
|
357 |
7bbb9825c407
|
|
358 |
7bbb9825c407
|
//Add ajax callback action called from client side javascript |
359 |
7bbb9825c407
|
add_action('wp_ajax_social_links_add_network', 'wp_ajax_social_links_add_network' ); |
360 |
7bbb9825c407
|
add_action('wp_ajax_social_links_delete_network', 'wp_ajax_social_links_delete_network' ); |
361 |
7bbb9825c407
|
|
362 |
7bbb9825c407
|
register_sidebar_widget('About Me - Social Links', 'widget_social_links'); |
363 |
7bbb9825c407
|
register_widget_control('About Me - Social Links', 'widget_social_links_control'); |
364 |
7bbb9825c407
|
|
365 |
7bbb9825c407
|
}//End of SocialLinks class |
366 |
d0811661659f
|
|
367 |
d0811661659f
|
|
368 |
d0811661659f
|
add_action('plugins_loaded','social_links_wrapper'); |
369 |
d0811661659f
|
|
370 |
d0811661659f
|
//todo handle auto db table update |
371 |
d0811661659f
|
function social_links_install(){ |
372 |
7bbb9825c407
|
//require_once('datastore.php'); |
373 |
7bbb9825c407
|
//sl_install(); |
374 |
d0811661659f
|
|
375 |
7bbb9825c407
|
global $wpdb; |
376 |
7bbb9825c407
|
|
377 |
7bbb9825c407
|
//WPD_print("Installing Social Links Plugin"); |
378 |
7bbb9825c407
|
//echo '<div>Activation social links</div>'; |
379 |
7bbb9825c407
|
|
380 |
7bbb9825c407
|
$table_name = $wpdb->prefix . "social_links"; |
381 |
7bbb9825c407
|
|
382 |
7bbb9825c407
|
// $installed_ver = get_option( "SOCIAL_LINKS_DB_VERSION" ); |
383 |
7bbb9825c407
|
|
384 |
7bbb9825c407
|
if($wpdb->get_var("show tables like '$table_name'") != $table_name ) { |
385 |
7bbb9825c407
|
|
386 |
7bbb9825c407
|
$sql = "CREATE TABLE " . $table_name . " ( |
387 |
7bbb9825c407
|
id mediumint(9) NOT NULL AUTO_INCREMENT, |
388 |
7bbb9825c407
|
network_id int not null, |
389 |
7bbb9825c407
|
user_info VARCHAR(55) NOT NULL, |
390 |
7bbb9825c407
|
sort_order int not null DEFAULT 0, |
391 |
7bbb9825c407
|
UNIQUE KEY id (id) |
392 |
7bbb9825c407
|
);"; |
393 |
7bbb9825c407
|
|
394 |
7bbb9825c407
|
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
395 |
7bbb9825c407
|
dbDelta($sql); |
396 |
7bbb9825c407
|
|
397 |
7bbb9825c407
|
|
398 |
7bbb9825c407
|
add_option("SOCIAL_LINKS_DB_VERSION", SOCIAL_LINKS_DB_VERSION); |
399 |
7bbb9825c407
|
} |
400 |
7bbb9825c407
|
} |
401 |
d0811661659f
|
|
402 |
d0811661659f
|
|
403 |
d0811661659f
|
//Administration page |
404 |
d0811661659f
|
$message; |
405 |
d0811661659f
|
$messageClass; |
406 |
d0811661659f
|
function widget_social_links_settings(){ |
407 |
d0811661659f
|
|
408 |
7bbb9825c407
|
if (isset($_POST['saveorder'])) |
409 |
7bbb9825c407
|
{ |
410 |
7bbb9825c407
|
saveSortOrder(); |
411 |
7bbb9825c407
|
} |
412 |
d0811661659f
|
|
413 |
d0811661659f
|
|
414 |
7bbb9825c407
|
global $definitions; |
415 |
7bbb9825c407
|
global $message; |
416 |
7bbb9825c407
|
global $messageClass; |
417 |
7bbb9825c407
|
global $plugindir; |
418 |
d0811661659f
|
|
419 |
7bbb9825c407
|
$visibility = 'hidden'; |
420 |
7bbb9825c407
|
if(!empty($messageClass)) |
421 |
7bbb9825c407
|
$visibility = 'visible'; |
422 |
7bbb9825c407
|
|
423 |
7bbb9825c407
|
?> |
424 |
7bbb9825c407
|
|
425 |
7bbb9825c407
|
|
426 |
7bbb9825c407
|
<div class="wrap"> |
427 |
7bbb9825c407
|
<h2>About Me</h2> |
428 |
7bbb9825c407
|
|
429 |
7bbb9825c407
|
|
430 |
7bbb9825c407
|
<div id="message" class="<?php echo $messageClass; ?>" style="background-color: rgb(255, 251, 204);margin-top:10px;display:block;visibility:<?php echo $visibility; ?>;width:300px"><?php echo $message; ?></div> |
431 |
7bbb9825c407
|
<div style="position:relative;float:left;margin-right:20px;"> |
432 |
7bbb9825c407
|
<h3>Add New Social Link</h3> |
433 |
7bbb9825c407
|
<select id='networkDropdown' onchange='selectionChanged()'> |
434 |
7bbb9825c407
|
<option>Select network...</option> |
435 |
7bbb9825c407
|
|
436 |
7bbb9825c407
|
<?php |
437 |
7bbb9825c407
|
|
438 |
7bbb9825c407
|
foreach ($definitions as $key => $linkInfoArray){ |
439 |
7bbb9825c407
|
echo "<option value='$linkInfoArray[0]' instruction='$linkInfoArray[3]'>$linkInfoArray[4]</option>"; |
440 |
7bbb9825c407
|
} |
441 |
7bbb9825c407
|
?> |
442 |
7bbb9825c407
|
</select> |
443 |
7bbb9825c407
|
|
444 |
7bbb9825c407
|
<label id='instruction'></label> |
445 |
7bbb9825c407
|
<br/> |
446 |
7bbb9825c407
|
<input type="text" id="addSettingInput" style="width:400px;" onkeydown="if(event.keyCode == 13){social_links_ajax_addNetwork(document.getElementById('networkDropdown').selectedIndex,document.getElementById('addSettingInput'),document.getElementById('responseDiv'));}"> |
447 |
7bbb9825c407
|
<input type="button" id="addButton" value="Add" disabled=true |
448 |
7bbb9825c407
|
onclick="social_links_ajax_addNetwork(document.getElementById('networkDropdown').selectedIndex,document.getElementById('addSettingInput'),document.getElementById('responseDiv'));" /> |
449 |
7bbb9825c407
|
<br/> |
450 |
7bbb9825c407
|
</div> |
451 |
7bbb9825c407
|
|
452 |
7bbb9825c407
|
<form method="post" onSubmit="social_links_ajax_saveOrder()" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>"> |
453 |
7bbb9825c407
|
|
454 |
7bbb9825c407
|
<div style="float:left;"> |
455 |
7bbb9825c407
|
<h3>Preview</h3> |
456 |
7bbb9825c407
|
<div id="displayDiv" style="width:100px;cursor:move;" class="drop_target"> |
457 |
7bbb9825c407
|
<?php echo generateSocialLinksPreviewInnerHTML("\n"); ?> |
458 |
7bbb9825c407
|
</div> |
459 |
7bbb9825c407
|
|
460 |
7bbb9825c407
|
<input type="submit" id="saveOrderButton" name="saveorder" value="Save Order" style="margin-top:20px"/> |
461 |
7bbb9825c407
|
<input type="hidden" name="sortOrderData" id="sortOrderData"/> |
462 |
7bbb9825c407
|
<input type="hidden" name="callBackUrl" id="callBackUrl" value="<?php echo $plugindir ?>"/> |
463 |
d0811661659f
|
</div> |
464 |
7bbb9825c407
|
<div id="trash" style="float:left;position:relative;top:45px;left:25px;width:50px;height:50px;" class="drop_target"> |
465 |
7bbb9825c407
|
<img src="<?php echo $plugindir ?>/images/trash.jpg"/> |
466 |
7bbb9825c407
|
</div> |
467 |
7bbb9825c407
|
</form> |
468 |
7bbb9825c407
|
<div style="clear: both;"> </div> |
469 |
7bbb9825c407
|
<div> |
470 |
7bbb9825c407
|
<p> |
471 |
7bbb9825c407
|
To add a new link select the network from the drop down, fill in the appropriate information and press enter.<br/> |
472 |
7bbb9825c407
|
To change the order they appear, rearrange the icons in the preview and click 'Save Order'. <br/> |
473 |
7bbb9825c407
|
To delete a link, simply drag it to the trash can. |
474 |
7bbb9825c407
|
</p> |
475 |
7bbb9825c407
|
</div> |
476 |
7bbb9825c407
|
</div> |
477 |
7bbb9825c407
|
<script language="JavaScript"> |
478 |
7bbb9825c407
|
createSortables(); |
479 |
7bbb9825c407
|
</script> |
480 |
7bbb9825c407
|
<?php |
481 |
7bbb9825c407
|
|
482 |
7bbb9825c407
|
|
483 |
7bbb9825c407
|
}//End of widget_social_links_settings |
484 |
d0811661659f
|
|
485 |
d0811661659f
|
function saveSortOrder(){ |
486 |
7bbb9825c407
|
global $wpdb; |
487 |
7bbb9825c407
|
global $message; |
488 |
7bbb9825c407
|
global $messageClass; |
489 |
7bbb9825c407
|
//WPD_print("Action: " . $action); |
490 |
7bbb9825c407
|
//WPD_print("Sort Data: " . $sortDataOrder); |
491 |
7bbb9825c407
|
$sortDataOrder = !empty($_POST['sortOrderData']) ? $_POST['sortOrderData'] : ''; |
492 |
7bbb9825c407
|
if(!empty($sortDataOrder)) |
493 |
7bbb9825c407
|
{ |
494 |
7bbb9825c407
|
//WPD_print("Saving order"); |
495 |
7bbb9825c407
|
parse_str($sortDataOrder,$newSortorderArray); |
496 |
7bbb9825c407
|
if(count($newSortorderArray) != 0){ |
497 |
7bbb9825c407
|
//WPD_print("List size: " . count($newSortorderArray)); |
498 |
7bbb9825c407
|
$table_name = $wpdb->prefix . "social_links"; |
499 |
7bbb9825c407
|
foreach($newSortorderArray["displayDiv"] as $order => $id){ |
500 |
7bbb9825c407
|
//WPD_print('Order: '.$order.' Value: '.$id); |
501 |
7bbb9825c407
|
|
502 |
7bbb9825c407
|
$sql = 'Update ' . $table_name . ' Set sort_order='.$order.' where id='.$id; |
503 |
7bbb9825c407
|
$result = $wpdb->query($wpdb->prepare($sql)); |
504 |
7bbb9825c407
|
//WPD_print('Result for '.$sql.' is '.$result); |
505 |
7bbb9825c407
|
|
506 |
7bbb9825c407
|
} |
507 |
7bbb9825c407
|
$message = 'Saved links\' order.'; |
508 |
7bbb9825c407
|
} |
509 |
7bbb9825c407
|
else{ |
510 |
7bbb9825c407
|
$message = 'No items to save.'; |
511 |
7bbb9825c407
|
} |
512 |
7bbb9825c407
|
$messageClass = 'updated fade'; |
513 |
7bbb9825c407
|
} |
514 |
d0811661659f
|
} |
515 |
d0811661659f
|
|
516 |
7bbb9825c407
|
|
517 |
6f118e1bf4fc
|
?> |