Make WordPress Core

Changeset 265


Ignore:
Timestamp:
07/23/2003 12:26:03 AM (21 years ago)
Author:
mikelittle
Message:

Added notes column to links. Can add/edit/save them in linkmanager.
Update/install scripts updated for new column.
added new methods get_linkobjects() and get_linkobjectsbyname()

Location:
trunk/wp-admin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/b2-2-wp.php

    r262 r265  
    124124           " link_updated DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " .
    125125           " link_rel varchar(255) NOT NULL default '',         " .
     126           " link_notes MEDIUMTEXT NOT NULL default '',         " .
    126127           " PRIMARY KEY (link_id)                              " .
    127128           ") ";
  • trunk/wp-admin/linkmanager.php

    r254 r265  
    3434
    3535function add_magic_quotes($array) {
    36     foreach ($array as $k => $v) {
    37         if (is_array($v)) {
    38             $array[$k] = add_magic_quotes($v);
    39         } else {
    40             $array[$k] = addslashes($v);
    41         }
    42     }
    43     return $array;
    44 } 
     36    foreach ($array as $k => $v) {
     37        if (is_array($v)) {
     38            $array[$k] = add_magic_quotes($v);
     39        } else {
     40            $array[$k] = addslashes($v);
     41        }
     42    }
     43    return $array;
     44}
    4545
    4646if (!get_magic_quotes_gpc()) {
    47     $HTTP_GET_VARS    = add_magic_quotes($HTTP_GET_VARS);
    48     $HTTP_POST_VARS   = add_magic_quotes($HTTP_POST_VARS);
    49     $HTTP_COOKIE_VARS = add_magic_quotes($HTTP_COOKIE_VARS);
     47    $HTTP_GET_VARS    = add_magic_quotes($HTTP_GET_VARS);
     48    $HTTP_POST_VARS   = add_magic_quotes($HTTP_POST_VARS);
     49    $HTTP_COOKIE_VARS = add_magic_quotes($HTTP_COOKIE_VARS);
    5050}
    5151
    5252$b2varstoreset = array('action','standalone','cat_id', 'linkurl', 'name', 'image',
    5353                       'description', 'visible', 'target', 'category', 'link_id',
    54                        'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel');
     54                       'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel', 'notes');
    5555for ($i=0; $i<count($b2varstoreset); $i += 1) {
    5656    $b2var = $b2varstoreset[$i];
     
    7171$links_show_order = $HTTP_COOKIE_VARS["links_show_order"];
    7272
    73 // error_log("start, links_show_cat_id=$links_show_cat_id"); 
     73// error_log("start, links_show_cat_id=$links_show_cat_id");
    7474
    7575switch ($action) {
     
    8888    $link_rating = $HTTP_POST_VARS["rating"];
    8989    $link_rel = $HTTP_POST_VARS["rel"];
     90    $link_notes = $HTTP_POST_VARS["notes"];
    9091    $auto_toggle = get_autotoggle($link_category);
    9192
     
    9899      $wpdb->query("UPDATE $tablelinks set link_visible = 'N' WHERE link_category = $link_category");
    99100    }
    100 
    101     $wpdb->query("INSERT INTO $tablelinks (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel) " .
     101    $wpdb->query("INSERT INTO $tablelinks (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes) " .
    102102      " VALUES('" . addslashes($link_url) . "','"
    103103           . addslashes($link_name) . "', '"
    104104           . addslashes($link_image) . "', '$link_target', $link_category, '"
    105            . addslashes($link_description) . "', '$link_visible', $user_ID, $link_rating, '" . addslashes($link_rel) ."')");
     105           . addslashes($link_description) . "', '$link_visible', $user_ID, $link_rating, '" . addslashes($link_rel) . "', '" . addslashes($link_notes) . "')");
    106106
    107107    header('Location: linkmanager.php');
     
    135135      $link_rating = $HTTP_POST_VARS["rating"];
    136136      $link_rel = $HTTP_POST_VARS["rel"];
     137      $link_notes = $HTTP_POST_VARS["notes"];
    137138      $auto_toggle = get_autotoggle($link_category);
    138139
     
    151152             " link_visible='$link_visible',\n link_description='" . addslashes($link_description) . "',\n " .
    152153             " link_rating=$link_rating,\n" .
    153              " link_rel='" . addslashes($link_rel) . "'\n" .
     154             " link_rel='" . addslashes($link_rel) . "',\n" .
     155             " link_notes='" . addslashes($link_notes) . "'\n" .
    154156             " WHERE link_id=$link_id");
    155157      //error_log($sql);
     
    174176    if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
    175177        $cat_id = $links_show_cat_id;
    176        
     178
    177179    if (!isset($cat_id) || ($cat_id == '')) {
    178180        if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
     
    184186    break;
    185187  } // end Delete
    186  
     188
    187189  case 'linkedit':
    188190  {
     
    193195    }
    194196
    195     $row = $wpdb->get_row("SELECT link_url, link_name, link_image, link_target, link_description, link_visible, link_category AS cat_id, link_rating, link_rel " .
     197    $row = $wpdb->get_row("SELECT link_url, link_name, link_image, link_target, link_description, link_visible, link_category AS cat_id, link_rating, link_rel, link_notes " .
    196198      " FROM $tablelinks " .
    197199      " WHERE link_id = $link_id");
    198200
    199201    if ($row) {
    200       $link_url = $row->link_url;
     202      $link_url = stripslashes($row->link_url);
    201203      $link_name = stripslashes($row->link_name);
    202204      $link_image = $row->link_image;
     
    207209      $link_rating = $row->link_rating;
    208210      $link_rel = stripslashes($row->link_rel);
     211      $link_notes = stripslashes($row->link_notes);
    209212    }
    210213
     
    212215
    213216<div class="wrap">
    214    
    215   <table width="95%" cellpadding="5" cellspacing="0" border="0"><form name="editlink" method="post">
     217
     218  <table width="95%" cellpadding="5" cellspacing="0" border="0">
     219  <form name="editlink" method="post">
    216220    <input type="hidden" name="action" value="editlink" />
    217221    <input type="hidden" name="link_id" value="<?php echo $link_id; ?>" />
     
    221225      <td colspan="2"><b>Edit</b> a link:</td>
    222226    </tr>
    223     <tr height="20"> 
     227    <tr height="20">
    224228      <td height="20" align="right">URL:</td>
    225229      <td><input type="text" name="linkurl" size="80" value="<?php echo $link_url; ?>"></td>
    226230    </tr>
    227     <tr height="20"> 
     231    <tr height="20">
    228232      <td height="20" align="right">Display Name/Alt text:</td>
    229233      <td><input type="text" name="name" size="80" value="<?php echo $link_name; ?>"></td>
    230234    </tr>
    231     <tr height="20"> 
     235    <tr height="20">
    232236      <td height="20" align="right">Image:</td>
    233237      <td><input type="text" name="image" size="80" value="<?php echo $link_image; ?>"></td>
    234238    </tr>
    235     <tr height="20"> 
     239    <tr height="20">
    236240      <td height="20" align="right">Description:</td>
    237241      <td><input type="text" name="description" size="80" value="<?php echo $link_description; ?>"></td>
    238242    </tr>
    239     <tr height="20"> 
     243    <tr height="20">
    240244      <td height="20" align="right">Rel:</td>
    241245      <td><input type="text" name="rel" size="80" value="<?php echo $link_rel; ?>"></td>
    242246    </tr>
    243     <tr height="20">
     247    <tr height="20">
     248      <td height="20" valign="top" align="right">Notes:</td>
     249      <td><textarea name="notes" cols="80" rows="10"><?php echo $link_notes; ?></textarea></td>
     250    </tr>
     251    <tr height="20">
    244252      <td height="20" align="right">Rating:</td>
    245       <td> <select name="rating" size="1">
    246           <?php
     253      <td>
     254        <select name="rating" size="1">
     255<?php
    247256    for ($r = 0; $r < 10; $r++) {
    248257      echo('            <option value="'.$r.'" ');
     
    252261    }
    253262?>
    254         </select>
    255         &nbsp;(Leave at 0 for no rating.) </td>
    256     </tr>
    257     <tr height="20"> 
     263        </select>&nbsp;(Leave at 0 for no rating.)
     264      </td>
     265    </tr>
     266    <tr height="20">
    258267      <td height="20" align="right">Target:</td>
     268      <td><label><input type="radio" name="target" value="_blank"   <?php echo(($link_target == '_blank') ? 'checked="checked"' : ''); ?>> _blank</label>
     269        &nbsp;<label><input type="radio" name="target" value="_top" <?php echo(($link_target == '_top') ? 'checked="checked"' : ''); ?>> _top</label>
     270        &nbsp;<label><input type="radio" name="target" value=""     <?php echo(($link_target == '') ? 'checked="checked"' : ''); ?>> none</label>
     271      </td>
     272    </tr>
     273    <tr height="20">
     274      <td height="20" align="right">Visible:</td>
    259275      <td><label>
    260         <input type="radio" name="target"  value="_blank" <?php echo(($link_target == '_blank') ? 'checked="checked"' : ''); ?>>
    261         _blank</label> &nbsp;
    262         <label>
    263         <input type="radio" name="target" value="_top" <?php echo(($link_target == '_top') ? 'checked="checked"' : ''); ?>>
    264         _top</label> &nbsp;
    265         <label>
    266         <input type="radio" name="target" value="" <?php echo(($link_target == '') ? 'checked="checked"' : ''); ?>>
    267         none</label>
     276        <input type="radio" name="visible" checked="checked" value="Y">
     277        Yes</label>
     278        &nbsp;<label>
     279        <input type="radio" name="visible" value="N">
     280        No</label>
    268281      </td>
    269282    </tr>
    270     <tr height="20">
    271       <td height="20" align="right">Visible:</td>
    272       <td><label>
    273         <input type="radio" name="visible" checked="checked" value="Y">
    274         Y</label> &nbsp; <label>
    275         <input type="radio" name="visible" value="N">
    276         N</label></td>
    277     </tr>
    278     <tr height="20">
    279       <td height="20" align="right">Category:</td>
    280       <td>
    281         <?php
     283    <tr height="20">
     284      <td height="20" align="right"><label for="category">Category</label>:</td>
     285      <td>
     286<?php
    282287    $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id");
    283288    echo "        <select name=\"category\" size=\"1\">\n";
    284     foreach($results as $row) {
     289    foreach ($results as $row) {
    285290      echo "          <option value=\"".$row->cat_id."\"";
    286291      if ($row->cat_id == $link_category)
     
    295300      </td>
    296301    </tr>
    297     <tr height="20"> 
    298       <td colspan="2" align="center"> <input type="submit" name="submit" value="Save" class="search">
    299         &nbsp;
    300         <input type="submit" name="submit" value="Cancel" class="search"></a>
     302    <tr height="20">
     303      <td colspan="2" align="center">
     304        <input type="submit" name="submit" value="Save" class="search">&nbsp;
     305        <input type="submit" name="submit" value="Cancel" class="search">
    301306      </td>
    302307    </tr>
     
    330335    if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
    331336        $cat_id = $links_show_cat_id;
    332        
     337
    333338    if (!isset($cat_id) || ($cat_id == '')) {
    334339        if (!isset($links_show_cat_id) || ($links_show_cat_id == ''))
     
    338343    if (isset($links_show_order) && ($links_show_order != ''))
    339344        $order_by = $links_show_order;
    340    
     345
    341346    if (!isset($order_by) || ($order_by == ''))
    342347        $order_by = 'order_name';
     
    358363        case 'order_owner':  $sqlorderby = 'owner';       break;
    359364        case 'order_rating': $sqlorderby = 'rating';      break;
    360         case 'order_name':
     365        case 'order_name':
    361366        default:             $sqlorderby = 'name';        break;
    362367    }
    363    
     368
    364369  if ($action != "popup") {
    365370?>
     
    368373    <form name="cats" method="post">
    369374    <table width="75%" cellpadding="5" cellspacing="0" border="0">
    370       <tr><td><b>Link Categories:</b></td><td><a href="linkcategories.php">Manage Link Categories</a></td><td><a href="links.import.php">Import Blogroll</a></td></tr>
     375      <tr>
     376        <td><b>Link Categories:</b></td>
     377        <td><a href="linkcategories.php">Manage Link Categories</a></td>
     378        <td><a href="links.import.php">Import Blogroll</a></td>
     379      </tr>
    371380      <tr>
    372381        <td>
     
    419428<div class="wrap">
    420429
    421      <form name="links" id="links" method="post">
     430    <form name="links" id="links" method="post">
    422431    <input type="hidden" name="link_id" value="" />
    423432    <input type="hidden" name="action" value="" />
     
    425434    <input type="hidden" name="cat_id" value="<?php echo $cat_id ?>" />
    426435  <table width="100%" border="0" cellspacing="0" cellpadding="5">
    427     <tr> 
     436    <tr>
    428437      <th width="15%">Name</th>
    429438      <th>URL</th>
    430439      <th>Category</th>
    431       <th>Relevance</th>
     440      <th>Relationship</th>
    432441      <th>Image</th>
    433442      <th>Visible</th>
     
    442451    LEFT JOIN $tablelinkcategories ON $tablelinks.link_category = $tablelinkcategories.cat_id
    443452    LEFT JOIN $tableusers on $tableusers.ID = $tablelinks.link_owner ";
    444    
     453
    445454    // have we got a where clause?
    446455    if (($use_adminlevels) || (isset($cat_id) && ($cat_id != 'All')) ) {
     
    465474    if ($links) {
    466475        foreach ($links as $link) {
    467             $short_url = str_replace('http://', '', $link->link_url);
     476            $short_url = str_replace('http://', '', stripslashes($link->link_url));
    468477            $short_url = str_replace('www.', '', $short_url);
    469             if ('/' == substr($short_url, -1)) $short_url = substr($short_url, 0, -1);
    470             if (strlen($short_url) > 35) $short_url =  substr($short_url, 0, 32).'...';
    471      
     478            if ('/' == substr($short_url, -1))
     479                $short_url = substr($short_url, 0, -1);
     480            if (strlen($short_url) > 35)
     481                $short_url =  substr($short_url, 0, 32).'...';
     482
    472483            $link->link_name = stripslashes($link->link_name);
    473484            $link->category = stripslashes($link->category);
    474485            $link->link_rel = stripslashes($link->link_rel);
     486            $link->link_description = stripslashes($link->link_description);
    475487            $image = ($link->link_image != null) ? 'Yes' : 'No';
    476488            $visible = ($link->link_visible == 'Y') ? 'Yes' : 'No';
     
    478490            $style = ($i % 2) ? ' class="alternate"' : '';
    479491            echo <<<LINKS
    480     <tr valign="middle"$style>
    481         <td><strong>$link->link_name</strong><br />
    482         Description: $link->link_description</td>
    483         <td><a href="$link->link_url" title="Visit $link->link_name">$short_url</a></td>
    484         <td>$link->category</td>
    485         <td>$link->link_rel</td>
    486         <td>$image</td>
    487         <td>$visible</td>
    488         <td><input type="submit" name="edit" onclick="document.forms['links'].link_id.value='$link->link_id'; document.forms['links'].action.value='linkedit'; " value="Edit" class="search" /></td>
    489         <td><input type="submit" name="delete" onclick="document.forms['links'].link_id.value='$link->link_id'; document.forms['links'].action.value='Delete'; return confirm('You are about to delete this link.\\n  \'Cancel\' to stop, \'OK\' to delete.'); " value="Delete" class="search" /></td>
    490     </tr>
     492    <tr valign="middle"$style>
     493        <td><strong>$link->link_name</strong><br />
     494        Description: $link->link_description</td>
     495        <td><a href="$link->link_url" title="Visit $link->link_name">$short_url</a></td>
     496        <td>$link->category</td>
     497        <td>$link->link_rel</td>
     498        <td>$image</td>
     499        <td>$visible</td>
     500        <td><input type="submit" name="edit" onclick="document.forms['links'].link_id.value='$link->link_id'; document.forms['links'].action.value='linkedit'; " value="Edit" class="search" /></td>
     501        <td><input type="submit" name="delete" onclick="document.forms['links'].link_id.value='$link->link_id'; document.forms['links'].action.value='Delete'; return confirm('You are about to delete this link.\\n  \'Cancel\' to stop, \'OK\' to delete.'); " value="Delete" class="search" /></td>
     502    </tr>
     503
    491504LINKS;
    492505        }
     
    512525      <tr height="20">
    513526        <td height="20" align="right">Display Name/Alt text:</td>
    514         <td><input type="text" name="name" size="80" value="<?php echo $name; ?>"></td>
     527        <td><input type="text" name="name" size="80" value="<?php echo $link_name; ?>"></td>
    515528      </tr>
    516529      <tr height="20">
     
    525538        <td height="20" align="right">Rel:</td>
    526539        <td><input type="text" name="rel" size="80" value=""></td>
     540      </tr>
     541      <tr height="20">
     542        <td height="20" valign="top" align="right">Notes:</td>
     543        <td><textarea name="notes" cols="80" rows="10"></textarea></td>
    527544      </tr>
    528545      <tr height="20">
     
    540557      <tr height="20">
    541558        <td height="20" align="right">Target:</td>
    542         <td><label><input type="radio" name="target"  value="_blank"> _blank</label>
    543         &nbsp;<label><input type="radio" name="target" value="_top">
    544         _top</label>&nbsp;<label><input type="radio" name="target" value="" checked="checked">
    545         none</label></td>
     559        <td><label><input type="radio" name="target" value="_blank"> _blank</label>
     560        &nbsp;<label><input type="radio" name="target" value="_top"> _top</label>
     561        &nbsp;<label><input type="radio" name="target" value="" checked="checked"> none</label>
     562        </td>
    546563      </tr>
    547564      <tr height="20">
    548565        <td height="20" align="right">Visible:</td>
    549566        <td><label>
    550         <input type="radio" name="visible" checked="checked" value="Y">
    551         Y</label>
    552         &nbsp;
    553 <label>
    554         <input type="radio" name="visible" value="N">
    555         N</label></td>
    556       </tr>
    557       <tr height="20">
    558         <td height="20" align="right">Category:</td>
     567          <input type="radio" name="visible" checked="checked" value="Y">
     568          Yes</label>
     569          &nbsp;<label>
     570          <input type="radio" name="visible" value="N">
     571          No</label>
     572        </td>
     573      </tr>
     574      <tr height="20">
     575        <td height="20" align="right"><label for="category">Category</label>:</td>
    559576        <td>
    560577<?php
  • trunk/wp-admin/upgrade-071-to-072.php

    r260 r265  
    7171<?php
    7272    break;
    73    
    74     case 1:
     73
     74    case 1:
    7575?>
    7676<h1>Step 1</h1>
     77<p>There are some changes we need to make to the links tables with this version, so lets get those out of
     78  the way.</p>
     79<?php
     80$error_count = 0;
     81$tablename = $tablelinks;
     82$ddl = "ALTER TABLE $tablelinks ADD COLUMN link_notes MEDIUMTEXT NOT NULL DEFAULT '' ";
     83maybe_add_column($tablename, 'link_notes', $ddl);
     84if (check_column($tablelinks, 'link_notes', 'mediumtext')) {
     85    $res .= $tablename . ' - ok <br />';
     86} else {
     87    $res .= 'There was a problem with ' . $tablename . '<br />';
     88    ++$error_count;
     89}
     90?>
     91<p>OK, that wasn't too bad was it? Let's move on to <a href="<?php echo $thisfile;?>?step=2">step 2</a>!</p>
     92
     93<?php
     94    case 2:
     95?>
     96<h1>Step 2</h1>
    7797<p>There are a few new database tables with this version, so lets get those out of
    7898  the way.</p>
  • trunk/wp-admin/wp-install-helper.php

    r236 r265  
    7474    return true;
    7575}
     76
     77
     78/**
     79 ** check_column()
     80 ** Check column matches passed in criteria.
     81 ** Pass in null to skip checking that criteria
     82 ** Returns:  true if it matches
     83 **           false otherwise
     84 ** (case sensitive) Column names returned from DESC table are:
     85 **      Field
     86 **      Type
     87 **      Null
     88 **      Key
     89 **      Default
     90 **      Extra
     91 */
     92function check_column($table_name, $col_name, $col_type, $is_null = null, $key = null, $default = null, $extra = null) {
     93    global $wpdb;
     94    $diffs = 0;
     95    $results = $wpdb->get_results("DESC $table_name");
     96   
     97    foreach ($results as $row ) {
     98        print_r($row);
     99        if ($row->Field == $col_name) {
     100            // got our column, check the params
     101            echo ("checking $row->Type != $col_type\n");
     102            if (($col_type != null) && ($row->Type != $col_type)) {
     103                ++$diffs;
     104            }
     105            if (($is_null != null) && ($row->Null != $is_null)) {
     106                ++$diffs;
     107            }
     108            if (($key != null) && ($row->Key  != $key)) {
     109                ++$diffs;
     110            }
     111            if (($default != null) && ($row->Default != $default)) {
     112                ++$diffs;
     113            }
     114            if (($extra != null) && ($row->Extra != $extra)) {
     115                ++$diffs;
     116            }
     117            if ($diffs > 0)
     118                return false;
     119            return true;
     120        } // end if found our column
     121    }
     122    return false;
     123}
     124   
     125/*
     126echo "<p>testing</p>";
     127echo "<pre>";
     128
     129//check_column('wp_links', 'link_description', 'mediumtext');
     130//if (check_column($tablecomments, 'comment_author', 'tinytext'))
     131//    echo "ok\n";
     132$error_count = 0;
     133$tablename = $tablelinks;
     134// check the column
     135if (!check_column($tablelinks, 'link_description', 'varchar(255)'))
     136{
     137    $ddl = "ALTER TABLE $tablelinks MODIFY COLUMN link_description varchar(255) NOT NULL DEFAULT '' ";
     138    $q = $wpdb->query($ddl);
     139}
     140if (check_column($tablelinks, 'link_description', 'varchar(255)')) {
     141    $res .= $tablename . ' - ok <br />';
     142} else {
     143    $res .= 'There was a problem with ' . $tablename . '<br />';
     144    ++$error_count;
     145}
     146echo "</pre>";
     147*/
    76148?>
  • trunk/wp-admin/wp-install.php

    r240 r265  
    114114           " link_updated DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " .
    115115           " link_rel varchar(255) NOT NULL default '',         " .
     116           " link_notes MEDIUMTEXT NOT NULL default '',         " .
    116117           " PRIMARY KEY (link_id)                              " .
    117118           ") ";
Note: See TracChangeset for help on using the changeset viewer.