Changeset 1058

Show
Ignore:
Timestamp:
12/05/05 02:57:08 (3 years ago)
Author:
sdcosta
Message:

More nonsense... Preliminary patch for #276

Location:
trunk/rss
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/rss/admin/config.php

    r1035 r1058  
    4040    ."</tr>\n"; 
    4141 
    42     $sql = "select * from " .getTable("config") ." order by key_ asc"; 
     42    $sql = "select * from " .getTable("config") ." where key_ like 
     43           'rss.%' order by key_ asc"; 
    4344 
    4445    $res = rss_query($sql); 
     
    4748        $value =  real_strip_slashes($row['value_']); 
    4849        $class_ = (($cntr++ % 2 == 0)?"even":"odd"); 
    49          
     50 
    5051        // Fix for #279. Plugins have their own section. 
    5152        if ($row['key_'] == 'rss.config.plugins') { 
    52             continue; 
     53            continue; 
    5354        } 
    5455 
  • trunk/rss/admin/index.php

    r1051 r1058  
    6363define ('CST_ADMIN_DOMAIN_OPML','opml'); 
    6464define ('CST_ADMIN_DOMAIN_PLUGINS','plugins'); 
     65define ('CST_ADMIN_DOMAIN_PLUGIN_OPTIONS','plugin_options'); 
    6566 
    6667// OPML import target 
     
    112113 
    113114    echo "\n<div id=\"channel_admin\" class=\"frame\">"; 
    114  
    115115    if ($authorised) { 
    116116        admin_menu(); 
     
    132132                $show = plugins_admin(); 
    133133                break; 
     134            case CST_ADMIN_DOMAIN_PLUGIN_OPTIONS: 
     135                $show = plugin_options_admin(); 
     136                break; 
    134137            default: 
    135138                break; 
     
    167170            case CST_ADMIN_DOMAIN_PLUGINS: 
    168171                plugins(); 
     172                break; 
     173            case CST_ADMIN_DOMAIN_PLUGIN_OPTIONS: 
     174                plugin_options(); 
    169175                break; 
    170176            default: 
  • trunk/rss/admin/plugins.php

    r1045 r1058  
    11<?php 
     2 
    23 
    34function plugins_admin() { 
     
    56} 
    67 
     8function plugin_options_admin() { 
     9    if (array_key_exists('plugin_name',$_REQUEST)) { 
     10        return CST_ADMIN_DOMAIN_PLUGIN_OPTIONS; 
     11    } else { 
     12        return CST_ADMIN_DOMAIN_PLUGINS; 
     13    } 
     14} 
    715 
    816function plugins() { 
    917 
    10         // Submit changes 
     18    // Submit changes 
    1119    if (isset($_POST['admin_plugin_submit_changes'])) { 
    1220        $active_plugins=array(); 
     
    2331    } 
    2432 
    25  
    26         // Check for updates 
     33    // Check for updates 
    2734    $doUpdates = false; 
    2835    $updates = array(); 
     
    3441 
    3542 
    36         // Rendering 
     43    // Rendering 
    3744    echo "<h2 class=\"trigger\">".LBL_ADMIN_PLUGINS."</h2>\n" 
    3845    ."<div id=\"admin_plugins\">\n"; 
    3946 
    4047 
    41         echo LBL_ADMIN_PLUGINS_GET_MORE; 
     48    echo LBL_ADMIN_PLUGINS_GET_MORE; 
    4249 
    4350    echo "<form method=\"post\" action=\"" .$_SERVER['PHP_SELF'] ."\">\n"; 
     
    4855    ."<th>".LBL_ADMIN_PLUGINS_HEADING_VERSION."</th>\n" 
    4956    ."<th>".LBL_ADMIN_PLUGINS_HEADING_AUTHOR."</th>\n" 
    50     ."<th>".LBL_ADMIN_PLUGINS_HEADING_DESCRIPTION."</th>\n"; 
     57    ."<th>".LBL_ADMIN_PLUGINS_HEADING_DESCRIPTION."</th>\n" 
     58    ."<th>".LBL_ADMIN_PLUGINS_HEADING_OPTIONS."</th>\n"; 
    5159    if ($doUpdates) { 
    5260        echo "<th>".LBL_ADMIN_PLUGINS_HEADING_UPDATES."</th>\n"; 
     
    6371            $active= in_array($entry,$active_plugins); 
    6472            if (count($info)) { 
    65  
    66  
    6773                $updateDl = null; 
    6874                if (is_array($updates) && array_key_exists($info['file'],$updates)) { 
     
    8389                .($active?"checked=\"checked\"":"")." />\n" 
    8490                ."</td>\n"; 
    85                 echo "<td><label for=\"_gregarius_plugin_$entry\">".(array_key_exists('name',$info)?$info['name']:"&nbsp"). "</label></td>\n"; 
    86                 echo "<td class=\"cntr\">"  .(array_key_exists('version',$info)?$info['version']:"&nbsp"). "</td>\n"; 
     91                echo "<td><label 
     92                for=\"_gregarius_plugin_$entry\">".(array_key_exists('name',$info)?$info['name']:"&nbsp"). 
     93                "</label></td>\n"; 
     94                echo "<td class=\"cntr\">" 
     95                .(array_key_exists('version',$info)?$info['version']:"&nbsp"). "</td>\n"; 
    8796                echo "<td>" .(array_key_exists('author',$info)?$info['author']:"&nbsp"). "</td>\n"; 
    8897                echo "<td>" .(array_key_exists('description',$info)?$info['description']:"&nbsp"). "</td>\n"; 
     98 
     99                // output the column to call a plugin's config page. 
     100                echo "<td>"; 
     101                if(array_key_exists('configuration',$info)) { 
     102                    $escaped_plugin_name = str_replace("/", "%2F", $entry); 
     103                    echo "<a href=\"".$_SERVER['PHP_SELF']. "?".CST_ADMIN_DOMAIN."=". 
     104                    CST_ADMIN_DOMAIN_PLUGIN_OPTIONS 
     105                    ."&amp;action=". CST_ADMIN_EDIT_ACTION. "&amp;plugin_name=".$escaped_plugin_name."\">" . LBL_ADMIN_EDIT 
     106                    ."</a>"; 
     107                } else { 
     108                    echo "&nbsp"; 
     109                } 
     110                echo "</td>\n"; 
    89111 
    90112                if ($doUpdates && $updateDl) { 
     
    92114                    echo "<a href=\"$updateDl\">$lastV</a>"; 
    93115                    echo "</td>"; 
    94                 } elseif($doUpdates) { 
     116                } 
     117                elseif($doUpdates) { 
    95118                    echo "<td>&nbsp;</td>"; 
    96119                } 
     
    101124    echo "</table>\n"; 
    102125    echo "<p><input type=\"hidden\" name=\"". CST_ADMIN_METAACTION ."\" value=\"LBL_ADMIN_SUBMIT_CHANGES\"/>\n"; 
    103     echo "<input type=\"submit\" name=\"admin_plugin_submit_changes\" value=\"".LBL_ADMIN_SUBMIT_CHANGES."\" />\n";         
     126    echo "<input type=\"submit\" name=\"admin_plugin_submit_changes\" value=\"".LBL_ADMIN_SUBMIT_CHANGES."\" />\n"; 
    104127    echo "<input type=\"submit\" name=\"admin_plugin_check_for_updates\" value=\"".LBL_ADMIN_CHECK_FOR_UPDATES."\" /></p></form>\n"; 
    105  
    106  
    107128    echo "</div>"; 
    108129} 
    109130 
     131function plugin_options() { 
     132    if (!array_key_exists('plugin_name',$_REQUEST)) { 
     133        return; 
     134    } 
     135    $plugin_filename = $_REQUEST['plugin_name']; 
     136    $plugin_filename = str_replace("%2F", "/", $plugin_filename); 
     137    if (preg_match('/([a-zA-Z0-9_\/\-]+).php/',$plugin_filename,$matches)) { 
     138        $plugin_filename = $matches[1] .".php"; // sanitize input 
     139        $plugin_info = getPluginInfo($plugin_filename); 
     140        if($plugin_info && array_key_exists('configuration', $plugin_info)) { 
     141            $plugin_config_func = $plugin_info['configuration']; 
     142            require_once("../".RSS_PLUGINS_DIR. "/" . $plugin_filename); 
     143            if(function_exists($plugin_config_func)) { 
     144                call_user_func($plugin_config_func); // Are you happy now? 
     145            } 
     146        } 
     147    } 
     148} 
    110149 
    111150 
     
    235274} 
    236275 
     276/** 
     277 * Wrapper functions for plugins 
     278 */ 
     279function rss_plugins_add_option($key, $value, $type = "string", $default = "", $desc= "", $export = NULL) { 
     280    if (!$key || !$value) { 
     281        return false; 
     282    } 
     283    $pKey = "plugins." . rss_real_escape_string($key); 
     284 
     285 
     286    // first check for duplicates 
     287    $res = rss_query("select value_,default_,type_ from " .getTable('config') . " where key_='$pKey'"); 
     288    if(!rss_num_rows($res)) { // Then insert the config value 
     289        $value = rss_real_escape_string($value); 
     290        $default = $default? $default: $value; 
     291        return rss_query("insert into " . getTable("config") 
     292                         . " (key_,value_,default_,type_,desc_,export_) VALUES (" 
     293                         . "'$pKey','$value','$default','$type','$desc','$export')" ); 
     294    } else { // the key exists, so update the option 
     295        return rss_plugins_update_option($key, $value, $type, $default, $desc, $export); 
     296    } 
     297 
     298 
     299} 
     300 
     301function rss_plugins_update_option($key, $value, $type = "string", $default = "", $desc= "", $export = NULL) { 
     302    $pKey = "plugins." . rss_real_escape_string($key); 
     303    $value = rss_real_escape_string($value); 
     304    return rss_query("update " . getTable("config") . " set value_=" . 
     305                     $value . " where key_ ='$pKey'"); 
     306} 
     307 
     308function rss_plugins_get_option($key) { 
     309    if (!$key) { 
     310        return; 
     311    } 
     312    $pKey = "plugins." . rss_real_escape_string($key); 
     313    $res = rss_query("select value_ from " . getTable("config") . " where key_='$pKey'"); 
     314    $res_count = rss_num_rows($res); 
     315    if ($res_count == 1) { 
     316        list($value) = rss_fetch_row($res); 
     317        return $value; // should we unescape the string? 
     318    } else { 
     319        return; 
     320    } 
     321 
     322} 
     323 
     324function rss_plugins_delete_option($key) { 
     325    if (!$key) { 
     326        return; 
     327    } 
     328    $pKey = "plugins." . rss_real_escape_string($key); 
     329    return rss_query("delete from " . getTable("config") . " where key_='$pKey'"); 
     330 
     331} 
     332 
     333function rss_plugins_redirect_to_admin() { 
     334    rss_redirect("/admin/index.php?" . CST_ADMIN_VIEW . "=" . CST_ADMIN_DOMAIN_PLUGINS); 
     335} 
     336 
     337function rss_plugins_redirect_to_plugin_config($filename) { 
     338    rss_redirect("/admin/index.php" . "?".CST_ADMIN_DOMAIN."=". CST_ADMIN_DOMAIN_PLUGIN_OPTIONS ."&amp;action=". CST_ADMIN_EDIT_ACTION. "&amp;plugin_name=" . $filename); 
     339} 
     340 
     341function rss_plugins_get_plugins_http_path() { 
     342    //returns http://example.com/rss/plugins/ 
     343    return guessTransportProto().$_SERVER['HTTP_HOST'] . getPath() . RSS_PLUGINS_DIR . "/"; 
     344} 
     345 
    237346?> 
  • trunk/rss/config.php

    r1056 r1058  
    3232    if ($config == null) { 
    3333        $cfgQry = "select key_,value_,default_,type_,desc_,export_ " 
    34           ." from " .getTable("config"); 
     34          ." from " .getTable("config") ."  where key_ LIKE 'rss.%'"; 
    3535         
    3636        $res = rss_query($cfgQry);       
  • trunk/rss/intl/en.php

    r1044 r1058  
    147147define ('LBL_ADMIN_PLUGINS_HEADING_DESCRIPTION','Description'); 
    148148define ('LBL_ADMIN_PLUGINS_HEADING_ACTION','Active'); 
     149define ('LBL_ADMIN_PLUGINS_HEADING_OPTIONS','Options'); 
    149150 
    150151