Ignore:
Timestamp:
Feb 17, 2011, 5:24:12 PM (14 years ago)
Author:
patdenice
Message:

Automatic upgrade from previous version.
Hide manage tab if no page in database.

Location:
extensions/AdditionalPages
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/AdditionalPages/admin/admin.php

    r9261 r9262  
    99$my_base_url = get_admin_plugin_menu_link(__FILE__);
    1010
     11$query = 'SELECT id
     12FROM ' . ADD_PAGES_TABLE . '
     13LIMIT 1
     14;';
     15$page_exist = array_from_query($query, 'id');
     16
    1117if (!isset($_GET['tab']))
    12   $page['tab'] = 'manage';
     18{
     19  $page['tab'] = $page_exist ? 'manage' : 'add_page';
     20}
    1321else
     22{
    1423  $page['tab'] = $_GET['tab'];
     24}
    1525
    1626include(AP_PATH.'admin/'.$page['tab'].'.inc.php');
    1727
    1828$tabsheet = new tabsheet();
    19 $tabsheet->add('manage', l10n('Manage'), $my_base_url.'&tab=manage');
     29if ($page_exist)
     30{
     31  $tabsheet->add('manage', l10n('Manage'), $my_base_url.'&tab=manage');
     32}
    2033$tabsheet->add('add_page', l10n('ap_add_page'), $my_base_url.'&tab=add_page');
    2134$tabsheet->add('config', l10n('Configuration'), $my_base_url.'&tab=config');
  • extensions/AdditionalPages/admin/config.inc.php

    r9261 r9262  
    66if (isset($_POST['submit']))
    77{
    8   $params = array('show_menu', 'show_home', 'redirect', 'group_perm', 'user_perm');
     8  $params = array('show_home', 'group_perm', 'user_perm');
    99
    1010  $new_conf = array();
  • extensions/AdditionalPages/admin/template/config.tpl

    r9261 r9262  
    88        <table>
    99                <tr>
    10                         <td><br>{'ap_menu_name'|@translate} : &nbsp;&nbsp;</td>
    11                         <td><br>{'Default'|@translate}&nbsp;&nbsp;</td>
    12                         <td><br><input type="text" size="50" maxlength="255" value="{$LANG_DEFAULT_VALUE}" name="menu_lang[default]"/></td>
    13                 </tr>
    14                 {foreach from=$language item=lang}
    15                 <tr>
    16                         <td></td>
    17                         <td>{$lang.LANGUAGE_NAME}&nbsp;&nbsp;</td>
    18                         <td><input type="text" size="50" maxlength="255" value="{$lang.VALUE}" name="menu_lang[{$lang.LANGUAGE_CODE}]"/></td>
    19                 </tr>
    20                 {/foreach}
    21                 <tr>
    22                         <td colspan="3"><br><hr><br></td>
    23                 </tr>
    24                 <tr>
    25                         <td colspan="3"><input type="checkbox" name="show_menu" value="on" {if $ap_conf.show_menu}checked="checked"{/if}/> {'ap_show_menu'|@translate}</td>
    26                 </tr>
    27                 <tr>
    2810                        <td colspan="3"><input type="checkbox" name="show_home" value="on" {if $ap_conf.show_home}checked="checked"{/if}/> {'ap_show_home'|@translate}</td>
    29                 </tr>
    30                 <tr>
    31                         <td colspan="3"><input type="checkbox" name="redirect" value="on" {if $ap_conf.redirect}checked="checked"{/if}/> {'ap_redirect'|@translate}</td>
    3211                </tr>
    3312                <tr>
     
    4322                        <td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="group_perm" value="on" {if $ap_conf.group_perm}checked="checked"{/if}/> <i>{'ap_group_perm'|@translate}</i></td>
    4423                </tr>
    45 
     24    <tr>
     25                        <td colspan="3"><br><hr><br></td>
     26                </tr>
     27                <tr>
     28                        <td><br>{'ap_menu_name'|@translate} : &nbsp;&nbsp;</td>
     29                        <td><br>{'Default'|@translate}&nbsp;&nbsp;</td>
     30                        <td><br><input type="text" size="50" maxlength="255" value="{$LANG_DEFAULT_VALUE}" name="menu_lang[default]"/></td>
     31                </tr>
     32                {foreach from=$language item=lang}
     33                <tr>
     34                        <td></td>
     35                        <td>{$lang.LANGUAGE_NAME}&nbsp;&nbsp;</td>
     36                        <td><input type="text" size="50" maxlength="255" value="{$lang.VALUE}" name="menu_lang[{$lang.LANGUAGE_CODE}]"/></td>
     37                </tr>
     38                {/foreach}
    4639        </table>
    4740
  • extensions/AdditionalPages/index_menu.php

    r9261 r9262  
    4141FROM ' . ADD_PAGES_TABLE . '
    4242WHERE (lang = "' . $user['language'] . '" OR lang IS NULL)
    43   AND pos > 0
     43  AND pos >= 0
    4444ORDER BY pos ASC, id ASC
    4545;';
  • extensions/AdditionalPages/main.inc.php

    r9261 r9262  
    1717define('ADD_PAGES_TABLE' , $prefixeTable . 'additionalpages');
    1818
    19 $conf['additional_pages'] = unserialize($conf['additional_pages']);
     19$conf['additional_pages'] = @unserialize($conf['additional_pages']);
     20
     21if ($conf['additional_pages'] === false)
     22  include(AP_PATH.'admin/upgrade_from_21.php');
    2023
    2124function additional_pages_admin_menu($menu)
  • extensions/AdditionalPages/maintain.inc.php

    r9261 r9262  
    2727    $config = array(
    2828      'languages' => array('default' => 'Additional Pages'),
    29       'show_menu' => true,
    3029      'show_home' => true,
    31       'redirect' => false,
    3230      'group_perm' => false,
    3331      'user_perm' => false,
     
    6260    upgrade_ap_from_17();
    6361  }
    64   $result = array_from_query($query, 'Field');
    65   if (!in_array('permalink', $result))
    66   {
    67     upgrade_ap_from_21();
    68   }
    6962}
    7063
     
    9386}
    9487
    95 function upgrade_ap_from_21()
    96 {
    97   global $prefixeTable, $conf;
    98 
    99   $query = 'ALTER TABLE ' . $prefixeTable . 'additionalpages
    100 CHANGE `id` `id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
    101 CHANGE `pos` `pos` SMALLINT( 5 ) NULL DEFAULT NULL ,
    102 CHANGE `lang` `lang` VARCHAR( 255 ) NULL DEFAULT NULL ,
    103 CHANGE `text` `content` LONGTEXT NOT NULL ,
    104 ADD `users` VARCHAR( 255 ) NULL DEFAULT NULL ,
    105 ADD `groups` VARCHAR( 255 ) NULL DEFAULT NULL ,
    106 ADD `permalink` VARCHAR( 64 ) NULL DEFAULT NULL;';
    107   pwg_query($query);
    108 
    109   $query = '
    110 SELECT id, pos, title, lang
    111 FROM '.$prefixeTable.'additionalpages
    112 ORDER BY pos ASC, id ASC
    113 ;';
    114   $result = pwg_query($query);
    115   while ($row = mysql_fetch_assoc($result))
    116   {
    117     $title = $row['title'];
    118     $authorized_users = 'NULL';
    119     $authorized_groups = 'NULL';
    120 
    121     if (strpos($title , '/user_id='))
    122     {
    123       $array = explode('/user_id=' , $title);
    124       $title = $array[0];
    125       $authorized_users = '"'.$array[1].'"';
    126     }
    127     if (strpos($title , '/group_id='))
    128     {
    129       $array = explode('/group_id=' , $title);
    130       $title = $array[0];
    131       $authorized_groups = '"'.$array[1].'"';
    132     }
    133 
    134     $position = $row['pos'];
    135     if ($row['pos'] === '0')
    136       $position = '-1';
    137     elseif (empty($row['pos']))
    138       $position = '0';
    139 
    140     $language = $row['lang'] != 'ALL' ? '"'.$row['lang'].'"' : 'NULL';
    141 
    142     $query = '
    143 UPDATE '.$prefixeTable.'additionalpages
    144   SET title = "'.addslashes($title).'",
    145       pos = '.$position.',
    146       lang = '.$language.',
    147       users = '.$authorized_users.',
    148       groups = '.$authorized_groups.'
    149   WHERE id = '.$row['id'].'
    150 ;';
    151     pwg_query($query);
    152   }
    153 
    154   $old_conf = explode ("," , $conf['additional_pages']);
    155 
    156   $new_conf = array(
    157     'show_menu' => @($old_conf[1] == 'on'),
    158     'show_home' => @($old_conf[2] == 'on'),
    159     'redirect' => @($old_conf[4] == 'on'),
    160     'group_perm' => @($old_conf[6] == 'on'),
    161     'user_perm' => @($old_conf[7] == 'on'),
    162     'homepage' => null,
    163     );
    164 
    165   $languages = explode('/', $old_conf[0]);
    166   $new_conf['languages'] = array();
    167   foreach($languages as $language)
    168   {
    169     $array = explode(':', $language);
    170     if (!isset($array[1])) $new_conf['languages']['default'] = $array[0];
    171     else $new_conf['languages'][$array[0]] = $array[1];
    172   }
    173 
    174   $query = '
    175 UPDATE '.CONFIG_TABLE.'
    176   SET value = "'.addslashes(serialize($new_conf)).'"
    177   WHERE param = "additional_pages"
    178 ;';
    179   pwg_query($query);
    180 }
    181 
    18288?>
Note: See TracChangeset for help on using the changeset viewer.