Changeset 1418

Show
Ignore:
Timestamp:
12/07/07 19:57:32 (1 year ago)
Author:
rho
Message:

updated elggadmin

  • removed legacy _elggadmin
  • includes an option to restore defaults values
  • fixed notice in datalib

Signed-off: Rolando Espinoza La fuente <rho@prosoftpeople.com

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • releases/0.9/lib/datalib.php

    r1064 r1418  
    693693            print_object($rs); 
    694694        } 
    695         print_continue("$CFG->wwwroot/$CFG->admin/config.php"); 
     695        //print_continue("$CFG->wwwroot/$CFG->admin/config.php"); 
    696696    } 
    697697} 
  • releases/0.9/mod/elggadmin/index.php

    r1415 r1418  
    88 */ 
    99 
    10 include('../../includes.php'); 
     10define('context', 'elggadmin'); 
     11require('./../../includes.php'); 
    1112 
    1213$request = elggadmin_parse_request(); 
  • releases/0.9/mod/elggadmin/lib.php

    r1415 r1418  
    11<?php 
     2/** 
     3 * Elgg administrator plugin 
     4 * 
     5 * @copyright Copyright (c) 2007 Pro Soft Resources Inc. http://www.prosoftpeople.com 
     6 * @author Rolando Espinoza La Fuente <rho@prosoftpeople.com> 
     7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License 
     8 */ 
    29 
    3 include('engine.php'); 
     10 
     11require_once(dirname(__FILE__).'/lib/engine.inc.php'); 
    412 
    513function elggadmin_init() { 
    6     elggadmin_add_rule('mod/elggadmin/?$', 'elggadmin_page'); 
    7     elggadmin_add_rule('mod/elggadmin/(theme|frontpage)$', 'elggadmin_page'); 
    8     elggadmin_add_rule('mod/elggadmin/index.php/?(theme|frontpage)?$', 'elggadmin_page'); 
     14    if (context() == 'elggadmin') { 
     15        require_once('./lib/elggadmin.inc.php'); 
    916 
    10     elggadmin_add_function('elggadmin_page_before', 'elggadmin_actions'); 
    11     // this should go somewhere else  
    12     elggadmin_add_rule('.*', 'elggadmin_404', 1000); 
     17        elggadmin_add_rule('mod/elggadmin/?$', 'elggadmin_page'); 
     18        elggadmin_add_rule('mod/elggadmin/(theme|frontpage)$', 'elggadmin_page'); 
     19        elggadmin_add_rule('mod/elggadmin/index.php/?(theme|frontpage)?$', 'elggadmin_page'); 
     20 
     21        elggadmin_add_function('elggadmin_page_before', 'elggadmin_actions'); 
     22        // this should go somewhere else  
     23        elggadmin_add_rule('.*', 'elggadmin_404', 1000); 
     24    } 
    1325} 
    1426 
    1527function elggadmin_pagesetup() { 
    1628    if (context() == 'admin') { 
    17  
    18         pages_submenu_add('elggadmin', __gettext('Site administration'), get_url(null, 'elggadmin::'), 10); 
     29        if (!plugin_is_loaded('pages')) { 
     30            elgg_messages_add(__gettext('Error: <code>elggadmin</code> plugin needs <code>pages</code> plugin to run')); 
     31        } else { 
     32            pages_submenu_add('elggadmin', __gettext('Site administration'), get_url(null, 'elggadmin::'), 10); 
     33        } 
    1934 
    2035    } elseif (context() == 'elggadmin') { 
     
    4257} 
    4358 
    44 function elggadmin_actions() { 
    45     // do actions 
    46     $page = elggadmin_currentpage(); 
    47  
    48     if (pages_is_submitted()) { 
    49         elggadmin_save($page); 
    50     } 
    51 } 
    52  
    53 function elggadmin_page($page_name=null) { 
    54     // this must go somewhere else! 
    55     global $metatags; 
    56     $metatags .= "\n<style type=\"text/css\">\n"; 
    57     $metatags .= file_get_contents('./elggadmin.css'); 
    58     $metatags .= "</style>"; 
    59  
    60     if ($page_name == 'theme') { 
    61         $page = elggadmin_page_theme(); 
    62         elggadmin_currentpage('theme'); 
    63     } elseif ($page_name == 'frontpage') { 
    64         $page = elggadmin_page_frontpage(); 
    65         elggadmin_currentpage('frontpage'); 
    66     } else { 
    67         $page = elggadmin_page_config(); 
    68         elggadmin_currentpage('config'); 
    69     } 
    70  
    71     return $page; 
    72  
    73 } 
    74  
    75 function elggadmin_page_before($c=null, $args=null) { 
    76     require_login('admin'); 
    77     context('elggadmin'); 
    78     $page = (isset($args[1])) ? $args[1] : 'config'; 
    79     elggadmin_currentpage($page); 
    80 } 
    81  
    82 function elggadmin_sidebar() { 
    83     $output = ''; 
    84     if (elggadmin_currentpage() == 'frontpage' || elggadmin_currentpage() == 'pageshell') { 
    85         $output .= "<h2>" . __gettext("Special keywords") . "</h2>"; 
    86         $output .= "<p>" . __gettext("You can insert these into your pageshell for special functionality:") . "</p>"; 
    87         $output .= "<p><b>{{url}}</b> " . __gettext("The address of your site.") . "</p>"; 
    88         $output .= "<p><b>{{sitename}}</b> " . __gettext("The name of your site.") . "</p>"; 
    89         $output .= "<p><b>{{tagline}}</b> " . __gettext("Your site's tagline.") . "</p>"; 
    90         $output .= "<p><b>{{username}}</b> " . __gettext("The current user's username.") . "</p>"; 
    91         $output .= "<p><b>{{userfullname}}</b> " . __gettext("The current user's full name.") . "</p>"; 
    92         $output .= "<p><b>{{populartags}}</b> " . __gettext("A list of the most popular tags.") . "</p>"; 
    93         $output .= "<p><b>{{randomusers}}</b> " . __gettext("A list of random users who have filled in their profiles, if some exist.") . "</p>"; 
    94         $output .= "<p><b>{{people:interests:foo:5}}</b> " . __gettext("Lists five people interested in 'foo' in a horizontal table.") . "</p>"; 
    95         $output .= "<p><b>{{toptags:town}}</b> " . __gettext("Lists the top tags of type 'town' (or select weblog, file or the profile field of your choice).") . "</p>"; 
    96     } 
    97  
    98     return $output; 
    99 } 
    100  
    101 function elggadmin_save($page) { 
    102     switch ($page) { 
    103         case 'config': 
    104             $defcfg = elggadmin_get_defconfig(); 
    105             $allowed = array(); 
    106             foreach ($defcfg as $name => $obj) { 
    107                 if (!isset($obj->noteditable)) { 
    108                     $allowed[] = $name; 
    109                 } 
    110             } 
    111  
    112             $config = optional_param('config'); 
    113             foreach ($config as $name => $value) { 
    114                 if (in_array($name, $allowed)) { 
    115                     set_config($name, $value); 
    116                     elgg_messages_add(sprintf(__gettext('Configuration option <code>%s</code> updated'), $name)); 
    117                 } 
    118             } 
    119     } 
    120 } 
    121  
    122 function elggadmin_currentpage($page_name=null) { 
    123     static $name; 
    124  
    125     if (!isset($name) && !empty($page_name)) { 
    126         $name = $page_name; 
    127     } else { 
    128         if (!isset($name)) { 
    129             $name = null; 
    130         } 
    131     } 
    132  
    133     return $name; 
    134 } 
    135  
    136 function elggadmin_page_frontpage() { 
    137      
    138     $page = new StdClass; 
    139     $page->title = __gettext('Front page'); 
    140     $page->body .= elggadmin_tpltextarea('frontpage_loggedout', __gettext('Front page (when logged out)')); 
    141     $page->body .= elggadmin_tpltextarea('frontpage_loggedin', __gettext('Front page (when logged in)')); 
    142  
    143     return $page; 
    144 } 
    145  
    146 function elggadmin_page_theme() { 
    147     $page = new StdClass; 
    148     $page->title = __gettext('Site theme'); 
    149     $page->body .= elggadmin_tpltextarea('pageshell', __gettext('Main pageshell')); 
    150     $page->body .= elggadmin_tpltextarea('css', __gettext('CSS styles')); 
    151     // wrap into form 
    152     $page->body = pages_html_form('elggtheme', $page->body); 
    153  
    154     return $page; 
    155 } 
    156  
    157 function elggadmin_page_config() { 
    158  
    159     $show_all = optional_param('view'); 
    160  
    161     $_config = elggadmin_get_defconfig(); 
    162     $page = new StdClass; 
    163     $page->title = __gettext('Configuration manager'); 
    164     $page->body = null; 
    165  
    166     if (empty($show_all)) { 
    167         $view_all = pages_html_a(get_url_query(1, 'elggadmin::', 'view=all'), __gettext('View all options')); 
    168         $page->body .= pages_html_wrap('div', pages_html_wrap('label', $view_all), array('class'=>'')); 
    169     } 
    170  
    171     $note = __gettext('Note: some fields are disabled because the value is forced by your <code>config.php</code>.'); 
    172     $note .= __gettext('To change you must hand edit your <code>config.php</code>.'); 
    173     $page->body .= pages_html_wrap('p', $note); 
    174  
    175     foreach ($_config as $c => $obj) { 
    176         if ((isset($obj->noteditable) || isset($obj->hidden)) && !$show_all) { 
    177             continue; 
    178         } 
    179  
    180         $name = htmlspecialchars($obj->name, ENT_COMPAT, 'utf-8'); 
    181         if (isset($obj->important)) { 
    182             $name .= ': *'; 
    183         } else { 
    184             $name .= ': &nbsp;'; 
    185         } 
    186  
    187         $class = 'form-item ' . (isset($obj->important) ? ' important' : ''); 
    188         $desc = (isset($obj->description)) ? $obj->description : '&nbsp;'; 
    189  
    190         $input = pages_html_wrap('label', $name); 
    191         $input .= elggadmin_config_input($c, $obj); 
    192         $input .= pages_html_wrap('span', $desc); 
    193  
    194         $page->body .= pages_html_wrap('div', $input, array('class'=>$class)); 
    195     } 
    196  
    197     $page->body = pages_html_form('elggconfig', $page->body); 
    198  
    199     return $page; 
    200 } 
    201  
    202 function elggadmin_config_input($c, $obj) { 
    203     global $CFG; 
    204  
    205     $value = (isset($CFG->$c)) ? $CFG->$c : null; 
    206     $input_name = "config[$c]"; 
    207  
    208     $attrs =  array(); 
    209     $attrs['name'] = $input_name; 
    210     $attrs['value'] = $value; 
    211  
    212     if (isset($obj->noteditable)) { 
    213         $attrs['disabled'] = 'disabled'; 
    214     } 
    215  
    216     $result = pages_html_input('text', $attrs); 
    217  
    218     return $result; 
    219 } 
    220  
    221 function elggadmin_get_defconfig() { 
    222     if (!is_readable('./configdef.php')) { 
    223         trigger_error(__FUNCTION__.': can not locate <code>configdef.php</code> file, perhaps your installation is corrupted.', E_USER_ERROR); 
    224     } 
    225  
    226     $DEFCFG = new StdClass; 
    227     require('./configdef.php'); 
    228  
    229     $current = elggadmin_get_currentconfig(); 
    230     $defined = get_object_vars($current); 
    231     foreach ($defined as $name => $value) { 
    232         if (isset($DEFCFG->config[$name])) { 
    233             $DEFCFG->config[$name]->noteditable = true; 
    234         } 
    235     } 
    236  
    237     return $DEFCFG->config; 
    238 } 
    239  
    240 function elggadmin_get_currentconfig() { 
    241     $CFG = new StdClass; 
    242     @include('../../config.php'); 
    243  
    244     return $CFG; 
    245 } 
    246  
    247 function elggadmin_tpltextarea($tplname, $title=null) { 
    248     $output = ''; 
    249     if (is_string($title)) { 
    250         $output .= pages_html_wrap('h2', $title); 
    251     } 
    252  
    253     if (!$tpl = elggadmin_loadtpl($tplname)) { 
    254         elgg_messages_add(__gettext("Can't load <code>$tplname</code> file.")); 
    255     } 
    256  
    257     $output .= pages_html_wrap('textarea', empty($tpl) ? ' ' : $tpl, array('name' => $tplname, 'style' => 'width:95%;height:300px;margin:0px 10px 20px 10px;')); 
    258  
    259     return $output; 
    260 } 
    261  
    26259function elggadmin_url($object_id, $object_type) { 
    26360    global $CFG; 
     
    26764    switch ($object_type) { 
    26865        case 'elggadmin::': 
     66        case 'elggadmin::config': 
    26967            $url = $CFG->wwwroot . 'mod/elggadmin/index.php'; 
    27068            break; 
     
    28078} 
    28179 
    282 function elggadmin_loadtpl($tplname) { 
    283     global $CFG; 
    284     $tpl = $CFG->templatesroot . 'Default_Template/' . $tplname; 
    285     if (!is_writable($tpl)) { 
    286         elgg_messages_add(__gettext("Please specify that <code>$tpl</code> is world-writable in order to use this administration panel.")); 
    287     } 
    288     return elggadmin_loadfile($tpl); 
    289 } 
    290  
    291 function elggadmin_loadfile($filepath) { 
    292     $filepath = realpath($filepath); 
    293     // security check 
    294     //if (strpos($filepath, $CFG->dirroot) === 0) { 
    295         if (is_readable($filepath)) { 
    296             return file_get_contents($filepath); 
    297         } 
    298     //} 
    299      
    300     return false; 
    301 } 
    302  
    303 function elggadmin_writefile($filepath, $content) { 
    304     $filepath = realpath($filepath); 
    305     // security check 
    306     //if (strpos($filepath, $CFG->dirroot) === 0) { 
    307         if (is_writable($filepath)) { 
    308             $f = @fopen($filepath, 'w'); 
    309             if ($f && @fwrite($f, $content)) { 
    310                 @fclose($f); 
    311                 return true; 
    312             } 
    313         } 
    314     //} 
    315      
    316     return false; 
    317 } 
    318  
    31980?> 
  • releases/0.9/mod/elggadmin/lib/configdef.php

    r1415 r1418  
    6666            $DEFCFG->config['maxspace']->description = __gettext("The maximum disk space taken up by all uploaded files"); 
    6767            $DEFCFG->config['maxspace']->type = "integer"; 
     68            $DEFCFG->config['maxspace']->hidden = true; 
    6869 
    6970            $DEFCFG->config['walledgarden']->name = __gettext("Walled garden"); 
  • releases/0.9/mod/elggadmin/lib/engine.inc.php

    r1415 r1418  
    11<?php 
     2/** 
     3 * Elgg administrator engine 
     4 * 
     5 * @copyright Copyright (c) 2007 Pro Soft Resources Inc. http://www.prosoftpeople.com 
     6 * @author Rolando Espinoza La Fuente <rho@prosoftpeople.com> 
     7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License 
     8 */ 
    29 
    310// ported from wp 
     
    218225    if (isset($context)) { 
    219226        if (defined('context')) { 
    220             trigger_error(__FUNCTION__.": context already defined (context: ".context.")", E_USER_ERROR); 
     227            trigger_error(__FUNCTION__.": context already defined (context: ".context.")", E_USER_WARNING); 
    221228        } else { 
    222229            define('context', $context); 
     
    257264} 
    258265 
     266function unset_config($name) { 
     267    global $CFG; 
     268 
     269    if (empty($name)) { 
     270        trigger_error(__FUNCTION__.": invalid argument empty", E_USER_ERROR); 
     271    } 
     272 
     273    $rs = null; 
     274 
     275    if (isset($CFG->$name)) { 
     276        unset($CFG->$name); 
     277        $rs = delete_records('datalists', 'name', $name); 
     278    } 
     279 
     280    return $rs; 
     281} 
     282 
    259283?>