Ignore:
Timestamp:
Feb 24, 2011, 4:45:43 PM (13 years ago)
Author:
patdenice
Message:

Plugins can add their own modules.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/PWG_Stuffs/admin/add_module.php

    r7855 r9369  
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
    5 global $template, $conf;
    6 
    7 include_once(STUFFS_PATH . 'include/functions.inc.php');
    8 include_once(STUFFS_PATH . 'admin/functions.inc.php');
    9 load_language('plugin.lang', STUFFS_PATH);
    10 
    11 if (!isset($_GET['type']) or !is_dir(STUFFS_PATH . 'modules/' . $_GET['type']))
     5if ($page['tab'] == 'add_module')
    126{
    13   die('Wrong parameters...');
    14 }
    15 else
    16 {
    17   $type = $_GET['type'];
     7  if (!isset($_GET['path']) or !isset($modules[$_GET['path']]))
     8  {
     9    die('Wrong module path.');
     10  }
     11  else
     12  {
     13    $module_path = $_GET['path'];
     14  }
    1815}
    1916
    20 // Cas particulier des News
    21 if ($type == 'News') include(STUFFS_PATH . 'modules/News/config.inc.php');
    22 
    23 // Enregistrement du module
     17// Save module
    2418if (isset($_POST['submit']) and !is_adviser())
    2519{
    26   include(STUFFS_PATH . 'modules/' . $type . '/config.inc.php');
     20  include($module_path.'config.inc.php');
    2721  if (empty($page['errors']))
    2822  {
     
    3428    {
    3529      $module_name = $_POST['module_name'];
    36       $desc = (!empty($_POST['module_desc']) ? '"' . $_POST['module_desc'] . '"' : 'NULL');
    37       $groups = (!empty($_POST['groups']) ? '"' . implode(',', $_POST['groups']) . '"' : 'NULL');
    38       $users = (!empty($_POST['users']) ? '"' . implode(',', $_POST['users']) . '"' : 'NULL');
     30      $desc = !empty($_POST['module_desc']) ? '"' . $_POST['module_desc'] . '"' : 'NULL';
     31      $groups = !empty($_POST['groups']) ? '"' . implode(',', $_POST['groups']) . '"' : 'NULL';
     32      $users = !empty($_POST['users']) ? '"' . implode(',', $_POST['users']) . '"' : 'NULL';
    3933      $show_title = isset($_POST['show_title']) ? '"true"' : '"false"';
    4034      $on_home = isset($_POST['on_home'])  ? '"true"' : '"false"';
     
    4236      $on_picture = isset($_POST['on_picture'])  ? '"true"' : '"false"';
    4337
    44                         $sav_datas = (!empty($datas) ? '"' . addslashes(serialize($datas)) . '"' : 'NULL');
     38      $sav_datas = (!empty($datas) ? '"' . addslashes(serialize($datas)) . '"' : 'NULL');
    4539
    4640      if (isset($_GET['edit']))
    47       {                 
     41      {     
    4842        pwg_query('
    4943UPDATE ' . STUFFS_TABLE . '
    5044SET name ="' . $module_name . '",
    51                 descr=' . $desc . ',
    52                 type="' . $type . '",
    53                 datas=' . $sav_datas . ',
    54                 users=' . $users . ',
    55                 groups=' . $groups . ',
     45    descr=' . $desc . ',
     46    datas=' . $sav_datas . ',
     47    users=' . $users . ',
     48    groups=' . $groups . ',
    5649    show_title=' . $show_title .',
    5750    on_home=' . $on_home .',
     
    5952    on_picture='. $on_picture . '
    6053WHERE id = ' . $_GET['edit'] . ';');
     54        if (isset($_GET['redirect']))
     55        {
     56          redirect(urldecode($_GET['redirect']));
     57        }
    6158      }
    6259      else
     
    6966
    7067        $query = '
    71 INSERT INTO ' . STUFFS_TABLE . ' ( id, pos, name, descr, type, datas, users, groups, show_title, on_home, on_cats, on_picture, id_line, width )
     68INSERT INTO ' . STUFFS_TABLE . ' ( id, pos, name, descr, path, parent, datas, users, groups, show_title, on_home, on_cats, on_picture, id_line, width )
    7269VALUES (' . $next_element_id . ' ,
    73         ' . $pos . ',
    74         "' . $module_name . '",
    75         ' . $desc . ',
    76         "' . $type . '",
    77         ' . $sav_datas . ',
    78         ' . $users . ',
    79         ' . $groups . ',
     70  ' . $pos . ',
     71  "' . $module_name . '",
     72  ' . $desc . ',
     73  "' . $module_path . '",
     74  ' . (isset($modules[$module_path]['parent']) ? '"'.$modules[$module_path]['parent'].'"' : 'NULL') .',
     75  ' . $sav_datas . ',
     76  ' . $users . ',
     77  ' . $groups . ',
    8078  ' . $show_title . ',
    8179  ' . $on_home . ',
     
    8684        pwg_query($query);
    8785      }
    88 
    8986      redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php');
    9087    }
     
    9289}
    9390
    94 // Récupération des données du module
    95 if (isset($_GET['edit']))
    96 {
    97   $q = ('SELECT * FROM ' . STUFFS_TABLE . ' WHERE id = ' . $_GET['edit'] . ';');
    98   $module = mysql_fetch_array(pwg_query($q));
    99 
    100   $module['users'] = explode(',', $module['users']);
    101   $module['groups'] = explode(',', $module['groups']);
    102 
    103   $datas = (!empty($module['datas']) ? unserialize($module['datas']) : false);
    104 
    105   $template->assign(array(
    106     'STUFFS_TITLE' => l10n('stuffs_edit_mod') . ' <i>' . trigger_event('render_stuffs_name', $module['name']) . '</i>',
    107     'MODULE_NAME' => $module['name'],
    108     'DESC_VALUE' => (isset($module['descr']) ? $module['descr'] : ''),
    109     'show_title_CHECKED' => ($module['show_title'] == 'true' ? 'checked="checked"' : ''),
    110     'on_home_CHECKED' => ($module['on_home'] == 'true' ? 'checked="checked"' : ''),
    111     'on_cats_CHECKED' => ($module['on_cats'] == 'true' ? 'checked="checked"' : ''),
    112     'on_picture_CHECKED' => ($module['on_picture'] == 'true' ? 'checked="checked"' : '')));
    113 }
    114 else
     91// Default module data
     92if ($page['tab'] == 'add_module')
    11593{
    11694  $module['users'] = array('guest', 'generic', 'normal', 'admin', 'webmaster');
     
    11896  $template->assign(array(
    11997    'STUFFS_TITLE' => l10n('stuffs_add_mod'),
    120     'MODULE_NAME' => l10n('module_name_' . strtolower($type)),
     98    'MODULE_NAME' => $modules[$module_path]['name'],
    12199    'show_title_CHECKED' => 'checked="checked"',
    122100    'on_home_CHECKED' => 'checked="checked"'));
    123101}
    124102
    125 // Selection des utilisateurs
     103// Users perm
    126104$template->assign('user_perm', array(
    127105  'GUEST' => (in_array('guest', $module['users']) ? 'checked="checked"' : ''),
     
    131109  'WEBMASTER' => (in_array('webmaster', $module['users']) ? 'checked="checked"' : '')));
    132110
    133 // Selection des groupes
     111// Groups perm
    134112$groups = get_all_groups();
    135113if (!empty($groups))
     
    138116}
    139117
    140 // Configuration du module
    141 include_once(STUFFS_PATH . 'modules/' . $type . '/config.inc.php');
     118// Module configuration
     119include_once($module_path.'config.inc.php');
    142120
    143121$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/add_module.tpl'));
Note: See TracChangeset for help on using the changeset viewer.