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 again

nolith / About Me http://abisso.org/index.php/projects/about-me/

Put in a widget all your social network links with this amazing Worpress plugin ;) (based on social-link http://blog.maybe5.com/?page_id=94)

Clone this repository (size: 313.2 KB): HTTPS / SSH
hg clone https://bitbucket.org/nolith/about-me
hg clone ssh://hg@bitbucket.org/nolith/about-me

About Me / aboutme.php

commit
280089e56e58
parent
02c1a383b072
branch
default

fixes wrong version number

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