Changeset 688 for trunk

Show
Ignore:
Timestamp:
10/31/07 23:36:55 (14 months ago)
Author:
michiel
Message:

make the ammount of years to show in the altarchive
plugin a plugin setting instead of a hardcoded 3.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/altarchive.php

    r687 r688  
    6464                else 
    6565                        $url = "index.php?action=archive&m="; 
    66                 /* this should be a setting for this plugin */ 
    6766                /* years to show */ 
    68                 $years  = 3; 
     67                if (array_key_exists("altarchive_showyears", $this->_settings)) 
     68                        $years = $this->_settings["altarchive_showyears"]; 
     69                else 
     70                        $years  = 3; 
    6971                $output = ""; 
    7072                for ($i=date("Y"); $i>date("Y")-$years; $i--) { 
     
    136138                $output .= "</select></td>\n"; 
    137139                $output .= "</tr><tr>"; 
     140                $output .= "<td>".gettext("years to show")."</td>"; 
     141                $output .= "<td><select name=\"altarchive_showyears\">"; 
     142                for ($i=1;$i<10;$i++) { 
     143                        $output .= "<option value=\"$i\""; 
     144                        if (array_key_exists("altarchive_showyears", $this->_settings) && $this->_settings["altarchive_showyears"] == $i) 
     145                                $output .= " selected=\"selected\""; 
     146                        $output .= ">$i</option>"; 
     147                } 
     148                $output .= "</select></td>"; 
     149                $output .= "</tr><tr>"; 
    138150                $output .= "<td colspan=\"2\"><input type=\"submit\" value=\"".gettext("Save")."\" /></td>"; 
    139151                $output .= "</tr></table>"; 
     
    158170                $res = $this->_mvblog->db->exec($sql); 
    159171                $this->_settings["altarchive_showdefaultcss"] = sprintf("%d", $requestdata["altarchive_showdefaultcss"]); 
     172                /* first look if the setting is already there */ 
     173                $sql = "SELECT COUNT(*) FROM settings WHERE settingname = 'altarchive_showyears'"; 
     174                $res = $this->_mvblog->db->query($sql); 
     175                $row = $res->fetchRow(); 
     176                if ($row[0]) { 
     177                        /* yes, so update */ 
     178                        $sql = sprintf("UPDATE settings SET settingvalue='%d' WHERE settingname='altarchive_showyears'", $requestdata["altarchive_showyears"]); 
     179                } else { 
     180                        /* no, so insert */ 
     181                        $sql = sprintf("INSERT INTO settings (settingname, settingvalue) VALUES ('altarchive_showyears', '%d')", $requestdata["altarchive_showyears"]); 
     182                } 
     183                $res = $this->_mvblog->db->exec($sql); 
     184                $this->_settings["altarchive_showyears"] = sprintf("%d", $requestdata["altarchive_showyears"]); 
    160185                $this->show_settings(); 
    161186        }