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
5b1561d68c04
parent
bc475f73a498
branch
default
tags
1.0.5

1.0.5 released as stable

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
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
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
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
bc475f73a498
array(34,'ebay.png','http://myworld.ebay.com/%userid%','Enter your Ebay username.','Ebay')
83
6536221ffa83
);
84
d0811661659f
85
29335354181d
//comparison based on socialnetwok name
86
29335354181d
function compare_social($s1, $s2) {
87
7bbb9825c407
   return strcmp($s1[KEY_DISPLAY_NAME], $s2[KEY_DISPLAY_NAME]);
88
29335354181d
}
89
d0811661659f
90
29335354181d
//Sorts socialnetworks in alphabetical order
91
29335354181d
uasort($definitions, "compare_social");
92
d0811661659f
93
d0811661659f
94
d0811661659f
function social_links_wrapper(){
95
d0811661659f
96
7bbb9825c407
   // This only works if the widget api is installed
97
7bbb9825c407
   if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
98
7bbb9825c407
      return; // ...and if not, exit gracefully from the script.
99
d0811661659f
100
7bbb9825c407
   //WPD_print('Filename: '.__FILE__);
101
7bbb9825c407
   //WPD_print('DB version: '.get_option( "SOCIAL_LINKS_DB_VERSION" ));
102
7bbb9825c407
   // Displays the icons in the sidebar
103
7bbb9825c407
   function widget_social_links($args) {
104
7bbb9825c407
      global $definitions;
105
7bbb9825c407
      extract($args);
106
6536221ffa83
107
7bbb9825c407
      $options = get_option('widget_social_links');
108
7bbb9825c407
      $title = empty($options['title']) ? 'About Me' : $options['title'];
109
7bbb9825c407
      $width =  empty($options['width']) ? 20 : $options['width'];
110
6536221ffa83
111
7bbb9825c407
      echo $before_widget;
112
7bbb9825c407
      echo $before_title . $title . $after_title ;
113
6536221ffa83
114
7bbb9825c407
      echo '<!-- About Me Version: '. SOCIAL_LINKS_VERSION .' -->';
115
7bbb9825c407
      echo "<div id='socialLinksContainer' style='width:$width"."px;'>";
116
7bbb9825c407
      echo generateSocialLinksInnerHTML();
117
7bbb9825c407
      echo '</div>';
118
7bbb9825c407
      echo $after_widget;
119
6536221ffa83
120
7bbb9825c407
   }
121
6536221ffa83
122
7bbb9825c407
   //Config Panel
123
7bbb9825c407
   function widget_social_links_control() {
124
7bbb9825c407
      global $definitions;
125
7bbb9825c407
      $options = get_option('widget_social_links');
126
6536221ffa83
127
7bbb9825c407
      if ( $_POST['social-links-submit'] ) {
128
7bbb9825c407
         // Clean up control form submission options
129
7bbb9825c407
         $newoptions['title'] = strip_tags(stripslashes($_POST['social-links-title']));
130
7bbb9825c407
         $newoptions['width'] = strip_tags(stripslashes($_POST['social-links-width']));
131
d0811661659f
132
7bbb9825c407
133
7bbb9825c407
         if ( $options != $newoptions ) {
134
7bbb9825c407
            $options = $newoptions;
135
7bbb9825c407
            update_option('widget_social_links', $options);
136
7bbb9825c407
         }
137
7bbb9825c407
      }
138
7bbb9825c407
139
7bbb9825c407
      $title = empty($options['title']) ? 'About Me' : $options['title'];
140
7bbb9825c407
      $width = empty($options['width']) ? 100 : $options['width'];
141
7bbb9825c407
142
7bbb9825c407
      ?>
143
7bbb9825c407
144
7bbb9825c407
      <table>
145
7bbb9825c407
         <tr><td>
146
7bbb9825c407
            <label for="social-links-title">Widget title: <input type="text" id="social-links-title" name="social-links-title" value="<?php echo $title; ?>" /></label>
147
7bbb9825c407
         </td></tr>
148
7bbb9825c407
         <tr><td>
149
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>
150
7bbb9825c407
         </td></tr>
151
7bbb9825c407
      </table>
152
7bbb9825c407
      <input type="hidden" name="social-links-submit" id="social-links-submit" value="1" />
153
7bbb9825c407
154
7bbb9825c407
      <?php
155
7bbb9825c407
   }//End of widget_social_links_control
156
7bbb9825c407
157
7bbb9825c407
158
7bbb9825c407
   function wp_ajax_social_links_add_network(){
159
7bbb9825c407
      // read submitted information
160
7bbb9825c407
      global $definitions;
161
7bbb9825c407
   
162
7bbb9825c407
      $siteID = $_POST['siteID'];
163
7bbb9825c407
      $data = $_POST['value'];
164
7bbb9825c407
      $messageId = $_POST['responseDiv'];
165
7bbb9825c407
   
166
7bbb9825c407
      $result = insertNetwork($siteID,$data);
167
7bbb9825c407
      if($result == 1)
168
7bbb9825c407
         $result = 'Link added.';
169
7bbb9825c407
      else
170
7bbb9825c407
         $result = 'There was a problem adding the link. Refresh the page and try again.';
171
7bbb9825c407
   
172
7bbb9825c407
      $innerHTML = generateSocialLinksPreviewInnerHTML('');
173
7bbb9825c407
      die('
174
7bbb9825c407
         $("message").innerHTML = "'.$result.'";
175
7bbb9825c407
         $("message").className="updated fade";
176
7bbb9825c407
         $("message").style.visibility = "visible";
177
7bbb9825c407
         document.getElementById("displayDiv").innerHTML = "'.$innerHTML.'";
178
7bbb9825c407
         createSortables();
179
7bbb9825c407
      ');
180
7bbb9825c407
   
181
7bbb9825c407
      //Add this line to the above javascript to show the complete table.
182
7bbb9825c407
      //document.getElementById("editDiv").innerHTML = "' . generateSocialLinksEditInnerHTML(). '";
183
7bbb9825c407
   }
184
7bbb9825c407
185
7bbb9825c407
//TODO: Implement the add ajax process to send data and let the javascript add child elements
186
7bbb9825c407
//This is to avoid using innerHTML replacement and will then allow for more advanced client side effects
187
7bbb9825c407
/*	function wp_ajax_social_links_add_network_send_data(){
188
7bbb9825c407
   // read submitted information
189
7bbb9825c407
   global $definitions;
190
7bbb9825c407
191
7bbb9825c407
   $selectedIndex = $_POST['networkIndex'];
192
7bbb9825c407
   $data = $_POST['value'];
193
7bbb9825c407
194
7bbb9825c407
   $result = insertNetwork($selectedIndex,$data);
195
7bbb9825c407
   $data = generateSocialLinksData();
196
7bbb9825c407
   //$result = 'fake insert';
197
7bbb9825c407
   die("$result
198
7bbb9825c407
      $('message').innerHTML = 'Database result is $result.';
199
7bbb9825c407
   $('message').class='updated fade';
200
7bbb9825c407
   $('message').style.visibility = 'visible';
201
7bbb9825c407
   updateSocialLinks($data);
202
7bbb9825c407
   ");
203
7bbb9825c407
204
7bbb9825c407
}
205
7bbb9825c407
*/
206
7bbb9825c407
   function wp_ajax_social_links_delete_network(){
207
7bbb9825c407
      global $wpdb;
208
7bbb9825c407
      global $definitions;
209
7bbb9825c407
   
210
7bbb9825c407
      $linkId = $_POST['linkId'];
211
7bbb9825c407
      //WPD_print('deleting linkID='. $linkId);
212
7bbb9825c407
      $table_name = $wpdb->prefix . "social_links";
213
7bbb9825c407
      $sql = 'delete from ' .  $table_name . ' where id='.$linkId;
214
7bbb9825c407
      $result = $wpdb->query($wpdb->prepare($sql));
215
7bbb9825c407
   
216
7bbb9825c407
      if($result == 1)
217
7bbb9825c407
         $result = 'Removed link.';
218
7bbb9825c407
      else
219
7bbb9825c407
         $result = 'There was a problem deleting the link. Refresh the page and try again.'.$sql;
220
7bbb9825c407
      //WPD_print($result);
221
7bbb9825c407
      die('
222
7bbb9825c407
         $("message").innerHTML = "'.$result.'";
223
7bbb9825c407
         $("message").className="updated fade";
224
7bbb9825c407
         $("message").style.visibility = "visible";
225
7bbb9825c407
      ');
226
7bbb9825c407
   }
227
7bbb9825c407
228
7bbb9825c407
229
7bbb9825c407
230
7bbb9825c407
231
7bbb9825c407
232
7bbb9825c407
   function insertNetwork($id,$value){
233
7bbb9825c407
   
234
7bbb9825c407
   
235
7bbb9825c407
      //WPD_print('Inserting new network');
236
7bbb9825c407
      global $wpdb;
237
7bbb9825c407
   
238
7bbb9825c407
      //WPD_print('networkID='.$id.' data='.$value);
239
7bbb9825c407
      $table_name = $wpdb->prefix . "social_links";
240
7bbb9825c407
      $sql = 'Insert into ' .  $table_name . ' (network_id,user_info,sort_order) VALUES ("'.$id.'","'.$value.'",1000)';
241
7bbb9825c407
      $result = $wpdb->query($wpdb->prepare($sql));
242
7bbb9825c407
      //WPD_print($sql);
243
7bbb9825c407
      return $result;
244
7bbb9825c407
   }
245
7bbb9825c407
   
246
7bbb9825c407
   function getSocialLinks(){
247
7bbb9825c407
      global $wpdb;
248
7bbb9825c407
      $table_name = $wpdb->prefix . "social_links";
249
7bbb9825c407
      $sql = 'Select * from ' .  $table_name . ' order by sort_order';
250
7bbb9825c407
      $results = $wpdb->get_results($sql,ARRAY_N);
251
7bbb9825c407
      ////WPD_print("Select networks results: ".$results);
252
7bbb9825c407
      return $results;
253
7bbb9825c407
   
254
7bbb9825c407
   }
255
7bbb9825c407
   
256
7bbb9825c407
   function generateSocialLinksInnerHTML(){
257
7bbb9825c407
      global $definitions;
258
7bbb9825c407
      global $plugindir;
259
7bbb9825c407
   
260
7bbb9825c407
      $rows = getSocialLinks();
261
7bbb9825c407
      if(count($rows)==0)
262
7bbb9825c407
         return;
263
7bbb9825c407
      ////WPD_print("Found".count($rows)." networks.");
264
7bbb9825c407
   
265
7bbb9825c407
      foreach ($rows as $row) {
266
7bbb9825c407
         //WPD_print("SiteID: " . $row[1]);
267
7bbb9825c407
         $linkInfoArray = $definitions[$row[1]];
268
7bbb9825c407
         //WPD_print('network info '. $linkInfoArray);
269
7bbb9825c407
         $url = str_replace("%userid%",$row[2],$linkInfoArray[KEY_URL_TEMPLATE]);
270
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>";
271
7bbb9825c407
         if($row != $rows[count($rows)-1]){
272
7bbb9825c407
            $innerHTML = $innerHTML."\n";
273
7bbb9825c407
         }
274
7bbb9825c407
      }
275
7bbb9825c407
   
276
7bbb9825c407
      return $innerHTML;
277
7bbb9825c407
   }
278
7bbb9825c407
   
279
7bbb9825c407
   function generateSocialLinksPreviewInnerHTML($delimiter){
280
7bbb9825c407
      global $definitions;
281
7bbb9825c407
      global $plugindir;
282
7bbb9825c407
   
283
7bbb9825c407
      $rows = getSocialLinks();
284
7bbb9825c407
      if(count($rows)==0)
285
7bbb9825c407
         return;
286
7bbb9825c407
      //WPD_print("Found ".count($rows)." networks.");
287
7bbb9825c407
   
288
7bbb9825c407
      foreach ($rows as $row) {
289
7bbb9825c407
         //WPD_print("SiteID: " . $row[2]);
290
7bbb9825c407
         //var_dump($row);
291
7bbb9825c407
         $linkInfoArray = $definitions[$row[1]];
292
7bbb9825c407
         //var_dump($linkInfoArray);
293
7bbb9825c407
         //WPD_print('network info '. $linkInfoArray);
294
7bbb9825c407
         $url = str_replace("%userid%",$row[2],$linkInfoArray[KEY_URL_TEMPLATE]);
295
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>";
296
7bbb9825c407
         if($row != $rows[count($rows)-1]){
297
7bbb9825c407
            $innerHTML = $innerHTML.$delimiter;
298
7bbb9825c407
         }
299
7bbb9825c407
      }
300
7bbb9825c407
   
301
7bbb9825c407
      return $innerHTML;
302
7bbb9825c407
   }
303
7bbb9825c407
304
7bbb9825c407
/*
305
7bbb9825c407
function generateSocialLinksData(){
306
7bbb9825c407
   global $definitions;
307
7bbb9825c407
308
7bbb9825c407
   $rows = getSocialLinks();
309
7bbb9825c407
   if(count($rows)==0)
310
7bbb9825c407
      return;
311
7bbb9825c407
   ////WPD_print("Found".count($rows)." networks.");
312
7bbb9825c407
   $data = '';
313
7bbb9825c407
   foreach ($rows as $row) {
314
7bbb9825c407
      $linkInfoArray = $definitions[$row[2]];
315
7bbb9825c407
      $data += "link_$row[0],$linkInfoArray[0],$linkInfoArray[1],$linkInfoArray[4]\n";
316
7bbb9825c407
   }
317
7bbb9825c407
   return $data;
318
7bbb9825c407
319
7bbb9825c407
}
320
7bbb9825c407
*/
321
7bbb9825c407
322
7bbb9825c407
   function social_links_admin_menu(){
323
38f374c63b59
324
7bbb9825c407
      add_management_page('Social Links Settings - About Me', 'About Me', 8,__FILE__,'widget_social_links_settings');
325
7bbb9825c407
   
326
7bbb9825c407
      global $plugindir;
327
7bbb9825c407
      wp_enqueue_script('about-me', $plugindir . '/javascript.js',array('sack'));
328
7bbb9825c407
      wp_enqueue_script('scriptaculous');
329
7bbb9825c407
   }
330
7bbb9825c407
   
331
7bbb9825c407
   function addHeaderCode(){
332
7bbb9825c407
      //WPD_print("header code");
333
7bbb9825c407
      global $plugindir;
334
7bbb9825c407
      echo '<link type="text/css" rel="stylesheet" href="' . $plugindir . '/stylesheet.css" />' . "\n";
335
7bbb9825c407
   
336
7bbb9825c407
   }
337
7bbb9825c407
338
7bbb9825c407
339
7bbb9825c407
340
7bbb9825c407
////WPD_print("Registering plugin");
341
7bbb9825c407
342
7bbb9825c407
   add_action('wp_head','addHeaderCode');
343
7bbb9825c407
344
7bbb9825c407
345
7bbb9825c407
346
7bbb9825c407
   //Add action to load sub menu
347
7bbb9825c407
   add_action('admin_menu', 'social_links_admin_menu');
348
7bbb9825c407
349
7bbb9825c407
350
7bbb9825c407
351
7bbb9825c407
352
7bbb9825c407
   //Add ajax callback action called from client side javascript
353
7bbb9825c407
   add_action('wp_ajax_social_links_add_network', 'wp_ajax_social_links_add_network' );
354
7bbb9825c407
   add_action('wp_ajax_social_links_delete_network', 'wp_ajax_social_links_delete_network' );
355
7bbb9825c407
   
356
7bbb9825c407
   register_sidebar_widget('About Me - Social Links', 'widget_social_links');
357
7bbb9825c407
   register_widget_control('About Me - Social Links', 'widget_social_links_control');
358
7bbb9825c407
359
7bbb9825c407
}//End of SocialLinks class
360
d0811661659f
361
d0811661659f
362
d0811661659f
add_action('plugins_loaded','social_links_wrapper');
363
d0811661659f
364
d0811661659f
//todo handle auto db table update
365
d0811661659f
function social_links_install(){
366
7bbb9825c407
   //require_once('datastore.php');
367
7bbb9825c407
   //sl_install();
368
d0811661659f
369
7bbb9825c407
   global $wpdb;
370
7bbb9825c407
371
7bbb9825c407
   //WPD_print("Installing Social Links Plugin");
372
7bbb9825c407
   //echo '<div>Activation social links</div>';
373
7bbb9825c407
374
7bbb9825c407
   $table_name = $wpdb->prefix . "social_links";
375
7bbb9825c407
376
7bbb9825c407
   // $installed_ver = get_option( "SOCIAL_LINKS_DB_VERSION" );
377
7bbb9825c407
378
7bbb9825c407
   if($wpdb->get_var("show tables like '$table_name'") != $table_name ) {
379
7bbb9825c407
380
7bbb9825c407
      $sql = "CREATE TABLE " . $table_name . " (
381
7bbb9825c407
         id mediumint(9) NOT NULL AUTO_INCREMENT,
382
7bbb9825c407
         network_id int not null,
383
7bbb9825c407
         user_info VARCHAR(55) NOT NULL,
384
7bbb9825c407
         sort_order int not null DEFAULT 0,
385
7bbb9825c407
         UNIQUE KEY id (id)
386
7bbb9825c407
         );";
387
7bbb9825c407
388
7bbb9825c407
      require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
389
7bbb9825c407
      dbDelta($sql);
390
7bbb9825c407
391
7bbb9825c407
392
7bbb9825c407
      add_option("SOCIAL_LINKS_DB_VERSION", SOCIAL_LINKS_DB_VERSION);
393
7bbb9825c407
   }
394
7bbb9825c407
}
395
d0811661659f
396
d0811661659f
397
d0811661659f
//Administration page
398
d0811661659f
$message;
399
d0811661659f
$messageClass;
400
d0811661659f
function widget_social_links_settings(){
401
d0811661659f
402
7bbb9825c407
   if (isset($_POST['saveorder']))
403
7bbb9825c407
   {
404
7bbb9825c407
      saveSortOrder();
405
7bbb9825c407
   }
406
d0811661659f
407
d0811661659f
408
7bbb9825c407
   global $definitions;
409
7bbb9825c407
   global $message;
410
7bbb9825c407
   global $messageClass;
411
7bbb9825c407
   global $plugindir;
412
d0811661659f
413
7bbb9825c407
   $visibility = 'hidden';
414
7bbb9825c407
   if(!empty($messageClass))
415
7bbb9825c407
      $visibility = 'visible';
416
7bbb9825c407
417
7bbb9825c407
   ?>
418
7bbb9825c407
419
7bbb9825c407
420
7bbb9825c407
   <div class="wrap">
421
7bbb9825c407
      <h2>About Me</h2>
422
7bbb9825c407
423
7bbb9825c407
424
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>
425
7bbb9825c407
      <div style="position:relative;float:left;margin-right:20px;">
426
7bbb9825c407
         <h3>Add New Social Link</h3>
427
7bbb9825c407
         <select id='networkDropdown' onchange='selectionChanged()'>
428
7bbb9825c407
            <option>Select network...</option>
429
7bbb9825c407
430
7bbb9825c407
            <?php
431
7bbb9825c407
432
7bbb9825c407
         foreach ($definitions as $key => $linkInfoArray){
433
7bbb9825c407
            echo "<option value='$linkInfoArray[0]' instruction='$linkInfoArray[3]'>$linkInfoArray[4]</option>";
434
7bbb9825c407
         }
435
7bbb9825c407
         ?>
436
7bbb9825c407
      </select>
437
7bbb9825c407
438
7bbb9825c407
      <label id='instruction'></label>
439
7bbb9825c407
      <br/>
440
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'));}">
441
7bbb9825c407
      <input type="button" id="addButton" value="Add" disabled=true
442
7bbb9825c407
      onclick="social_links_ajax_addNetwork(document.getElementById('networkDropdown').selectedIndex,document.getElementById('addSettingInput'),document.getElementById('responseDiv'));" />
443
7bbb9825c407
      <br/>
444
7bbb9825c407
   </div> 
445
7bbb9825c407
446
7bbb9825c407
   <form method="post" onSubmit="social_links_ajax_saveOrder()" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
447
7bbb9825c407
448
7bbb9825c407
      <div style="float:left;">
449
7bbb9825c407
         <h3>Preview</h3>
450
7bbb9825c407
         <div  id="displayDiv" style="width:100px;cursor:move;" class="drop_target">
451
7bbb9825c407
            <?php echo generateSocialLinksPreviewInnerHTML("\n");  ?>
452
7bbb9825c407
         </div>
453
7bbb9825c407
454
7bbb9825c407
         <input type="submit" id="saveOrderButton" name="saveorder" value="Save Order" style="margin-top:20px"/>
455
7bbb9825c407
         <input type="hidden" name="sortOrderData" id="sortOrderData"/>
456
7bbb9825c407
         <input type="hidden" name="callBackUrl" id="callBackUrl" value="<?php echo $plugindir ?>"/>
457
d0811661659f
      </div>
458
7bbb9825c407
      <div id="trash" style="float:left;position:relative;top:45px;left:25px;width:50px;height:50px;" class="drop_target">
459
7bbb9825c407
         <img src="<?php echo $plugindir ?>/images/trash.jpg"/>
460
7bbb9825c407
      </div>
461
7bbb9825c407
   </form>
462
7bbb9825c407
   <div style="clear: both;"> </div>
463
7bbb9825c407
   <div>
464
7bbb9825c407
      <p>
465
7bbb9825c407
         To add a new link select the network from the drop down, fill in the appropriate information and press enter.<br/>
466
7bbb9825c407
         To change the order they appear, rearrange the icons in the preview and click 'Save Order'. <br/>
467
7bbb9825c407
         To delete a link, simply drag it to the trash can.
468
7bbb9825c407
      </p>
469
7bbb9825c407
   </div>
470
7bbb9825c407
</div>	
471
7bbb9825c407
<script language="JavaScript">
472
7bbb9825c407
createSortables();
473
7bbb9825c407
</script>
474
7bbb9825c407
<?php
475
7bbb9825c407
476
7bbb9825c407
477
7bbb9825c407
}//End of widget_social_links_settings
478
d0811661659f
479
d0811661659f
function saveSortOrder(){
480
7bbb9825c407
   global $wpdb;
481
7bbb9825c407
   global $message;
482
7bbb9825c407
   global $messageClass;
483
7bbb9825c407
   //WPD_print("Action: " . $action);
484
7bbb9825c407
   //WPD_print("Sort Data: " . $sortDataOrder);
485
7bbb9825c407
   $sortDataOrder = !empty($_POST['sortOrderData']) ? $_POST['sortOrderData'] : '';
486
7bbb9825c407
   if(!empty($sortDataOrder))
487
7bbb9825c407
   {
488
7bbb9825c407
      //WPD_print("Saving order");
489
7bbb9825c407
      parse_str($sortDataOrder,$newSortorderArray);
490
7bbb9825c407
      if(count($newSortorderArray) != 0){
491
7bbb9825c407
         //WPD_print("List size: " . count($newSortorderArray));
492
7bbb9825c407
         $table_name = $wpdb->prefix . "social_links";
493
7bbb9825c407
         foreach($newSortorderArray["displayDiv"] as $order => $id){
494
7bbb9825c407
            //WPD_print('Order: '.$order.' Value: '.$id);
495
7bbb9825c407
496
7bbb9825c407
            $sql = 'Update ' .  $table_name . ' Set sort_order='.$order.' where id='.$id;
497
7bbb9825c407
            $result = $wpdb->query($wpdb->prepare($sql));
498
7bbb9825c407
            //WPD_print('Result for '.$sql.' is '.$result);
499
7bbb9825c407
500
7bbb9825c407
         }
501
7bbb9825c407
         $message = 'Saved links\' order.';
502
7bbb9825c407
      }
503
7bbb9825c407
      else{
504
7bbb9825c407
         $message = 'No items to save.';
505
7bbb9825c407
      }
506
7bbb9825c407
      $messageClass = 'updated fade';
507
7bbb9825c407
   }
508
d0811661659f
}
509
d0811661659f
510
7bbb9825c407
511
6f118e1bf4fc
?>