Ignore:
Timestamp:
Feb 17, 2011, 4:27:09 PM (13 years ago)
Author:
patdenice
Message:

New administration pannel for additional pages.
Better url.
Add permalinks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/AdditionalPages/maintain.inc.php

    r3609 r9261  
    1111    $query = 'CREATE TABLE ' . $prefixeTable . 'additionalpages (
    1212id SMALLINT( 5 ) UNSIGNED NOT NULL ,
    13 pos SMALLINT( 5 ) UNSIGNED default NULL ,
    14 lang VARCHAR( 255 ) NOT NULL ,
     13pos SMALLINT( 5 ) NULL default NULL ,
     14lang VARCHAR( 255 ) NULL default NULL ,
    1515title VARCHAR( 255 ) NOT NULL ,
    16 text LONGTEXT NOT NULL ,
     16content LONGTEXT NOT NULL ,
     17permalink VARCHAR( 64 ) NULL DEFAULT NULL ,
    1718PRIMARY KEY (id) ,
    1819INDEX (pos) ,
     
    2425  if (!isset($conf['additional_pages']))
    2526  {
     27    $config = array(
     28      'languages' => array('default' => 'Additional Pages'),
     29      'show_menu' => true,
     30      'show_home' => true,
     31      'redirect' => false,
     32      'group_perm' => false,
     33      'user_perm' => false,
     34      'homepage' => null,
     35    );
    2636    $query = 'INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment)
    27 VALUES ("additional_pages" , "Additional Pages,on,on,off,off,,off,off" , "Parametres du plugin Additional Pages");';
     37VALUES ("additional_pages" , "'.addslashes(serialize($config)).'" , "Additional Pages config configuration");';
    2838    pwg_query($query);
    2939  }
     
    5161  {
    5262    upgrade_ap_from_17();
     63  }
     64  $result = array_from_query($query, 'Field');
     65  if (!in_array('permalink', $result))
     66  {
     67    upgrade_ap_from_21();
    5368  }
    5469}
     
    7893}
    7994
     95function upgrade_ap_from_21()
     96{
     97  global $prefixeTable, $conf;
     98
     99  $query = 'ALTER TABLE ' . $prefixeTable . 'additionalpages
     100CHANGE `id` `id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
     101CHANGE `pos` `pos` SMALLINT( 5 ) NULL DEFAULT NULL ,
     102CHANGE `lang` `lang` VARCHAR( 255 ) NULL DEFAULT NULL ,
     103CHANGE `text` `content` LONGTEXT NOT NULL ,
     104ADD `users` VARCHAR( 255 ) NULL DEFAULT NULL ,
     105ADD `groups` VARCHAR( 255 ) NULL DEFAULT NULL ,
     106ADD `permalink` VARCHAR( 64 ) NULL DEFAULT NULL;';
     107  pwg_query($query);
     108
     109  $query = '
     110SELECT id, pos, title, lang
     111FROM '.$prefixeTable.'additionalpages
     112ORDER 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 = '
     143UPDATE '.$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 = '
     175UPDATE '.CONFIG_TABLE.'
     176  SET value = "'.addslashes(serialize($new_conf)).'"
     177  WHERE param = "additional_pages"
     178;';
     179  pwg_query($query);
     180}
     181
    80182?>
Note: See TracChangeset for help on using the changeset viewer.