]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/link-manager.php
Wordpress 2.0.4
[autoinstalls/wordpress.git] / wp-admin / link-manager.php
1 <?php
2 // Links
3 // Copyright (C) 2002, 2003 Mike Little -- mike@zed1.com
4
5 require_once('admin.php');
6
7 $title = __('Manage Links');
8 $this_file = $parent_file = 'link-manager.php';
9 $list_js = true;
10
11 $wpvarstoreset = array('action','cat_id', 'linkurl', 'name', 'image',
12                        'description', 'visible', 'target', 'category', 'link_id',
13                        'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel',
14                        'notes', 'linkcheck[]');
15
16 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
17     $wpvar = $wpvarstoreset[$i];
18     if (!isset($$wpvar)) {
19         if (empty($_POST["$wpvar"])) {
20             if (empty($_GET["$wpvar"])) {
21                 $$wpvar = '';
22             } else {
23                 $$wpvar = $_GET["$wpvar"];
24             }
25         } else {
26             $$wpvar = $_POST["$wpvar"];
27         }
28     }
29 }
30
31 $links_show_cat_id = $_COOKIE['links_show_cat_id_' . COOKIEHASH];
32 $links_show_order = $_COOKIE['links_show_order_' . COOKIEHASH];
33
34 if ('' != $_POST['assign']) $action = 'assign';
35 if ('' != $_POST['visibility']) $action = 'visibility';
36 if ('' != $_POST['move']) $action = 'move';
37 if ('' != $_POST['linkcheck']) $linkcheck = $_POST[linkcheck];
38
39 switch ($action) {
40   case 'assign':
41   {
42         check_admin_referer('bulk-bookmarks');
43
44     // check the current user's level first.
45     if ( !current_user_can('manage_links') )
46       die (__("Cheatin' uh ?"));
47
48     //for each link id (in $linkcheck[]): if the current user level >= the
49     //userlevel of the owner of the link then we can proceed.
50
51     if (count($linkcheck) == 0) {
52         wp_redirect($this_file);
53         exit;
54     }
55     $all_links = join(',', $linkcheck);
56     $results = $wpdb->get_results("SELECT link_id, link_owner FROM $wpdb->links LEFT JOIN $wpdb->users ON link_owner = ID WHERE link_id in ($all_links)");
57     foreach ($results as $row) {
58        $ids_to_change[] = $row->link_id;
59     }
60
61     // should now have an array of links we can change
62     $all_links = join(',', $ids_to_change);
63     $q = $wpdb->query("update $wpdb->links SET link_owner='$newowner' WHERE link_id IN ($all_links)");
64
65     wp_redirect($this_file);
66     break;
67   }
68   case 'visibility':
69   {
70         check_admin_referer('bulk-bookmarks');
71
72     // check the current user's level first.
73     if ( !current_user_can('manage_links') )
74       die (__("Cheatin' uh ?"));
75
76     //for each link id (in $linkcheck[]): toggle the visibility
77     if (count($linkcheck) == 0) {
78         wp_redirect($this_file);
79         exit;
80     }
81     $all_links = join(',', $linkcheck);
82     $results = $wpdb->get_results("SELECT link_id, link_visible FROM $wpdb->links WHERE link_id in ($all_links)");
83     foreach ($results as $row) {
84         if ($row->link_visible == 'Y') { // ok to proceed
85             $ids_to_turnoff[] = $row->link_id;
86         } else {
87             $ids_to_turnon[] = $row->link_id;
88         }
89     }
90
91     // should now have two arrays of links to change
92     if (count($ids_to_turnoff)) {
93         $all_linksoff = join(',', $ids_to_turnoff);
94         $q = $wpdb->query("update $wpdb->links SET link_visible='N' WHERE link_id IN ($all_linksoff)");
95     }
96
97     if (count($ids_to_turnon)) {
98         $all_linkson = join(',', $ids_to_turnon);
99         $q = $wpdb->query("update $wpdb->links SET link_visible='Y' WHERE link_id IN ($all_linkson)");
100     }
101
102     wp_redirect($this_file);
103     break;
104   }
105   case 'move':
106   {
107         check_admin_referer('bulk-bookmarks');
108
109     // check the current user's level first.
110     if ( !current_user_can('manage_links') )
111       die (__("Cheatin' uh ?"));
112
113     //for each link id (in $linkcheck[]) change category to selected value
114     if (count($linkcheck) == 0) {
115         wp_redirect($this_file);
116         exit;
117     }
118     $all_links = join(',', $linkcheck);
119     // should now have an array of links we can change
120     $q = $wpdb->query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)");
121
122     wp_redirect($this_file);
123     break;
124   }
125
126   case 'Add':
127   {
128         check_admin_referer('add-bookmark');
129
130         add_link();
131         
132     wp_redirect(wp_get_referer() . '?added=true');
133     break;
134   } // end Add
135
136   case 'editlink':
137   {
138         $link_id = (int) $_POST['link_id'];
139         check_admin_referer('update-bookmark_' . $link_id);
140         
141         if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
142                 $cat_id = $links_show_cat_id;
143
144         if (!isset($cat_id) || ($cat_id == '')) {
145                 if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
146                         $cat_id = 'All';
147         }
148         $links_show_cat_id = $cat_id;
149
150         edit_link($link_id);
151         
152     setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600);
153     wp_redirect($this_file);
154     break;
155   } // end Save
156
157   case 'delete':
158   {
159         $link_id = (int) $_GET['link_id'];
160         check_admin_referer('delete-bookmark_' . $link_id);
161
162     if ( !current_user_can('manage_links') )
163       die (__("Cheatin' uh ?"));
164
165         wp_delete_link($link_id);
166         
167     if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
168         $cat_id = $links_show_cat_id;
169
170     if (!isset($cat_id) || ($cat_id == '')) {
171         if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
172         $cat_id = 'All';
173     }
174     $links_show_cat_id = $cat_id;
175     setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600);
176     wp_redirect($this_file);
177     break;
178   } // end Delete
179
180   case 'linkedit': {
181         $xfn_js = true;
182         include_once ('admin-header.php');
183         if ( !current_user_can('manage_links') )
184                 die(__('You do not have sufficient permissions to edit the links for this blog.'));
185         
186         $link_id = (int) $_GET['link_id'];
187         
188         if ( !$link = get_link_to_edit($link_id) )
189                 die( __('Link not found.') );
190         
191         include('edit-link-form.php');
192         break;
193   } // end linkedit
194   case __("Show"):
195   {
196     if (!isset($cat_id) || ($cat_id == '')) {
197         if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
198         $cat_id = 'All';
199     }
200     $links_show_cat_id = $cat_id;
201     if (!isset($order_by) || ($order_by == '')) {
202         if (!isset($links_show_order) || ($links_show_order == ''))
203         $order_by = 'order_name';
204     }
205     $links_show_order = $order_by;
206     //break; fall through
207   } // end Show
208   case "popup":
209   {
210     $link_url = stripslashes($_GET["linkurl"]);
211     $link_name = stripslashes($_GET["name"]);
212     //break; fall through
213   }
214   default:
215   {
216     if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
217         $cat_id = $links_show_cat_id;
218
219     if (!isset($cat_id) || ($cat_id == '')) {
220         if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
221         $cat_id = 'All';
222     }
223     $links_show_cat_id = $cat_id;
224     if (isset($links_show_order) && ($links_show_order != ''))
225         $order_by = $links_show_order;
226
227     if (!isset($order_by) || ($order_by == ''))
228         $order_by = 'order_name';
229     $links_show_order = $order_by;
230
231     setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600);
232     setcookie('links_show_order_' . COOKIEHASH, $links_show_order, time()+600);
233     include_once ("./admin-header.php");
234     if ( !current_user_can('manage_links') )
235       die(__("You do not have sufficient permissions to edit the links for this blog."));
236
237     switch ($order_by)
238     {
239         case 'order_id':     $sqlorderby = 'id';          break;
240         case 'order_url':    $sqlorderby = 'url';         break;
241         case 'order_desc':   $sqlorderby = 'description'; break;
242         case 'order_owner':  $sqlorderby = 'owner';       break;
243         case 'order_rating': $sqlorderby = 'rating';      break;
244         case 'order_name':
245         default:             $sqlorderby = 'name';        break;
246     }
247
248   if ($action != "popup") {
249 ?>
250 <script type="text/javascript">
251 <!--
252 function checkAll(form)
253 {
254         for (i = 0, n = form.elements.length; i < n; i++) {
255                 if(form.elements[i].type == "checkbox") {
256                         if(form.elements[i].checked == true)
257                                 form.elements[i].checked = false;
258                         else
259                                 form.elements[i].checked = true;
260                 }
261         }
262 }
263 //-->
264 </script>
265
266 <div class="wrap">
267     <form name="cats" method="post" action="">
268     <table width="75%" cellpadding="3" cellspacing="3">
269       <tr>
270         <td>
271         <?php _e('<strong>Show</strong> links in category:'); ?><br />
272         </td>
273         <td>
274           <?php _e('<strong>Order</strong> by:');?>
275         </td>
276                 <td>&nbsp;</td>
277       </tr>
278       <tr>
279         <td>
280 <?php
281     $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id");
282     echo "        <select name=\"cat_id\">\n";
283     echo "          <option value=\"All\"";
284     if ($cat_id == 'All')
285       echo " selected='selected'";
286     echo "> " . __('All') . "</option>\n";
287     foreach ($results as $row) {
288       echo "          <option value=\"".$row->cat_id."\"";
289       if ($row->cat_id == $cat_id)
290         echo " selected='selected'";
291         echo ">".$row->cat_id.": ".wp_specialchars($row->cat_name);
292         if ($row->auto_toggle == 'Y')
293             echo ' '.__('(auto toggle)');
294         echo "</option>\n";
295     }
296     echo "        </select>\n";
297 ?>
298         </td>
299         <td>
300           <select name="order_by">
301             <option value="order_id"     <?php if ($order_by == 'order_id')     echo " selected='selected'";?>><?php _e('Link ID') ?></option>
302             <option value="order_name"   <?php if ($order_by == 'order_name')   echo " selected='selected'";?>><?php _e('Name') ?></option>
303             <option value="order_url"    <?php if ($order_by == 'order_url')    echo " selected='selected'";?>><?php _e('URI') ?></option>
304             <option value="order_desc"   <?php if ($order_by == 'order_desc')   echo " selected='selected'";?>><?php _e('Description') ?></option>
305             <option value="order_owner"  <?php if ($order_by == 'order_owner')  echo " selected='selected'";?>><?php _e('Owner') ?></option>
306             <option value="order_rating" <?php if ($order_by == 'order_rating') echo " selected='selected'";?>><?php _e('Rating') ?></option>
307           </select>
308         </td>
309         <td>
310           <input type="submit" name="action" value="<?php _e('Show') ?>" />
311         </td>
312       </tr>
313     </table>
314     </form>
315
316 </div>
317
318 <form name="links" id="links" method="post" action="">
319 <div class="wrap">
320
321     <?php wp_nonce_field('bulk-bookmarks') ?>
322     <input type="hidden" name="link_id" value="" />
323     <input type="hidden" name="action" value="" />
324     <input type="hidden" name="order_by" value="<?php echo wp_specialchars($order_by, 1); ?>" />
325     <input type="hidden" name="cat_id" value="<?php echo (int) $cat_id ?>" />
326   <table id="the-list-x" width="100%" cellpadding="3" cellspacing="3">
327     <tr>
328       <th width="15%"><?php _e('Name') ?></th>
329       <th><?php _e('URI') ?></th>
330       <th><?php _e('Category') ?></th>
331       <th><?php _e('rel') ?></th>
332       <th><?php _e('Image') ?></th>
333       <th><?php _e('Visible') ?></th>
334       <th colspan="2"><?php _e('Action') ?></th>
335       <th>&nbsp;</th>
336   </tr>
337 <?php
338     $sql = "SELECT link_url, link_name, link_image, link_description, link_visible,
339             link_category AS cat_id, cat_name AS category, $wpdb->users.user_login, link_id,
340             link_rating, link_rel
341             FROM $wpdb->links
342             LEFT JOIN $wpdb->linkcategories ON $wpdb->links.link_category = $wpdb->linkcategories.cat_id
343             LEFT JOIN $wpdb->users ON $wpdb->users.ID = $wpdb->links.link_owner ";
344
345     if (isset($cat_id) && ($cat_id != 'All')) {
346       $sql .= " WHERE link_category = $cat_id ";
347     }
348     $sql .= ' ORDER BY link_' . $sqlorderby;
349
350     // echo "$sql";
351     $links = $wpdb->get_results($sql);
352     if ($links) {
353         foreach ($links as $link) {
354             $link->link_name = wp_specialchars($link->link_name);
355             $link->link_category = wp_specialchars($link->link_category);
356             $link->link_description = wp_specialchars($link->link_description);
357             $link->link_url = wp_specialchars($link->link_url);
358             $short_url = str_replace('http://', '', $link->link_url);
359             $short_url = str_replace('www.', '', $short_url);
360             if ('/' == substr($short_url, -1))
361                 $short_url = substr($short_url, 0, -1);
362             if (strlen($short_url) > 35)
363                 $short_url =  substr($short_url, 0, 32).'...';
364
365             $image = ($link->link_image != null) ? __('Yes') : __('No');
366             $visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
367             ++$i;
368             $style = ($i % 2) ? '' : ' class="alternate"';
369 ?>
370     <tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>>
371                 <td><strong><?php echo $link->link_name; ?></strong><br />
372 <?php                   
373         echo sprintf(__('Description: %s'), $link->link_description) . "</td>";
374         echo "<td><a href=\"$link->link_url\" title=\"" . sprintf(__('Visit %s'), $link->link_name) . "\">$short_url</a></td>";
375         echo <<<LINKS
376         <td>$link->category</td>
377         <td>$link->link_rel</td>
378         <td align='center'>$image</td>
379         <td align='center'>$visible</td>
380 LINKS;
381             $show_buttons = 1; // default
382
383             if ($show_buttons) {
384         echo '<td><a href="link-manager.php?link_id=' . $link->link_id . '&amp;action=linkedit" class="edit">' . __('Edit') . '</a></td>';
385                 echo '<td><a href="' . wp_nonce_url('link-manager.php?link_id='.$link->link_id.'&amp;action=delete', 'delete-bookmark_' . $link->link_id ) . '"'." class='delete' onclick=\"return deleteSomething( 'link', $link->link_id , '".sprintf(__("You are about to delete the &quot;%s&quot; bookmark to %s.\\n&quot;Cancel&quot; to stop, &quot;OK&quot; to delete."), js_escape($link->link_name), js_escape($link->link_url)).'\' );">'.__('Delete').'</a></td>';
386         echo '<td><input type="checkbox" name="linkcheck[]" value="' . $link->link_id . '" /></td>';
387             } else {
388               echo "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>\n";
389             }
390
391                 echo "\n    </tr>\n";
392         }
393     }
394 ?>
395 </table>
396
397 <div id="ajax-response"></div>
398
399 </div>
400
401 <div class="wrap">
402   <table width="100%" cellpadding="3" cellspacing="3">
403     <tr><th colspan="4"><?php _e('Manage Multiple Links:') ?></th></tr>
404     <tr><td colspan="4"><?php _e('Use the checkboxes on the right to select multiple links and choose an action below:') ?></td></tr>
405     <tr>
406         <td>
407           <?php _e('Assign ownership to:'); ?>
408 <?php
409     $results = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users ORDER BY ID");
410     echo "          <select name=\"newowner\" size=\"1\">\n";
411     foreach ($results as $row) {
412       echo "            <option value=\"".$row->ID."\"";
413       echo ">".$row->user_login;
414       echo "</option>\n";
415     }
416     echo "          </select>\n";
417 ?>
418         <input name="assign" type="submit" id="assign" value="<?php _e('Go') ?>" />
419         </td>
420         <td>
421           <input name="visibility" type="submit" id="visibility" value="<?php _e('Toggle Visibility') ?>" />
422         </td>
423         <td>
424           <?php _e('Move to category:'); link_category_dropdown('category'); ?> <input name="move" type="submit" id="move" value="<?php _e('Go') ?>" />
425         </td>
426         <td align="right">
427           <a href="#" onclick="checkAll(document.getElementById('links')); return false; "><?php _e('Toggle Checkboxes') ?></a>
428         </td>
429     </tr>
430 </table>
431
432 <?php
433   } // end if !popup
434 ?>
435 </div>
436 </form>
437
438
439 <?php
440     break;
441   } // end default
442 } // end case
443 ?>
444
445 <?php include('admin-footer.php'); ?>