Changeset 16118


Ignore:
Timestamp:
Jun 28, 2012, 12:11:22 PM (12 years ago)
Author:
mistic100
Message:

add a simple page template system

Location:
extensions/AdditionalPages/trunk
Files:
5 added
5 edited

Legend:

Unmodified
Added
Removed
  • extensions/AdditionalPages/trunk/admin/add_page.inc.php

    r9660 r16118  
    1919    'content'    => '',
    2020  );
     21}
     22
     23// load template
     24if (isset($_GET['load_template']))
     25{
     26  if (file_exists(AP_DISTRIBUED . $_GET['load_template']))
     27  {
     28    $distribued = load_ap_template($_GET['load_template'], true);
     29  }
     30  else
     31  {
     32    $distribued = trigger_event('load_ap_template', array(), $_GET['load_template']);
     33  }
     34  $edited_page = array_merge($edited_page, $distribued);
     35  $template->assign('template_selected', $_GET['load_template']);
    2136}
    2237
     
    198213}
    199214
     215// Available templates
     216if (!isset($_GET['edit']))
     217{
     218  $distribued = array();
     219  $dh = opendir(AP_DISTRIBUED);
     220  if ($dh)
     221  {
     222    while (($dir = readdir($dh)) !== false)
     223    {
     224      if ( is_dir(AP_DISTRIBUED.$dir) and $dir!='.' and $dir!='..' )
     225      {
     226        array_push($distribued, load_ap_template($dir, false));
     227      }
     228    }
     229    closedir($dh);
     230  }
     231  $distribued = trigger_event('load_ap_templates_list', $distribued); // external plugins can add templates
     232  $template->assign('TEMPLATES', $distribued);
     233}
     234
    200235// template output
    201236$template->assign(array(
     
    212247$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
    213248
     249
     250function load_ap_template($dir, $with_content=true)
     251{
     252  $path = AP_DISTRIBUED . $dir . '/';
     253 
     254  // default template
     255  $template_conf = array(
     256    'name'       => $dir,
     257    'title'      => '',
     258    'permalink'  => '',
     259    'lang'       => 'ALL',
     260    'homepage'   => false,
     261    'standalone' => false,
     262    'level'      => 0,
     263    'users'      => array('guest', 'generic', 'normal', 'admin', 'webmaster'),
     264    'groups'     => array(),
     265    'content'    => '',
     266  );
     267 
     268  // load config
     269  if (file_exists($path.'config.php'))
     270  {
     271    include($path.'config.php');
     272  }
     273 
     274  // load content
     275  if ( $with_content and file_exists($path.'content.tpl') )
     276  {
     277    $template_conf['content'] = file_get_contents($path.'content.tpl');
     278  }
     279 
     280  $template_conf['tpl_id'] = $dir;
     281  return $template_conf;
     282}
     283
    214284?>
  • extensions/AdditionalPages/trunk/admin/template/add_page.tpl

    r9660 r16118  
    77        auto_permalink = false;
    88      });
     9  });
     10 
     11  var content_changed = false;
     12  jQuery("#ap_content").change(function() {
     13    content_changed = true;
     14  });
     15 
     16  jQuery("#template").change(function() {
     17    if ($(this).val() != '-1') {
     18{/literal}
     19      if (content_changed == false || confirm("{'The content of the page changed, are your sure you wan\'t to quit without saving?'|@translate|escape:javascript}")) {ldelim}
     20        window.location.href = "admin.php?page=plugin-AdditionalPages-add_page&load_template="+ $(this).val();
     21      } else {ldelim}
     22        $(this).val('-1');
     23      }
     24{literal}
     25    }
    926  });
    1027});
     
    2845  <legend></legend>
    2946        <ul>
     47    {if $TEMPLATES}
     48    <li>
     49      <span class="property">
     50        <label for="template">{'Load a page model'|@translate}</label>
     51      </span>
     52      <select name="template" id="template">
     53        <option value="-1">---------</option>
     54        {foreach from=$TEMPLATES item=tpl}
     55        <option value="{$tpl.tpl_id}" {if $template_selected==$tpl.tpl_id}selected="selected"{/if}>{$tpl.name}</option>
     56        {/foreach}
     57      </select>
     58    </li>
     59    {/if}
     60   
    3061    <li>
    3162      <span class="property">
  • extensions/AdditionalPages/trunk/language/en_UK/plugin.lang.php

    r9350 r16118  
    4848$lang['ap_language_perm'] = 'by language';
    4949
     50$lang['Load a page model'] = 'Load a page model';
     51$lang['The content of the page changed, are your sure you wan\'t to quit without saving?'] = 'The content of the page changed, are your sure you wan\'t to quit without saving?';
     52
    5053?>
  • extensions/AdditionalPages/trunk/language/fr_FR/plugin.lang.php

    r9350 r16118  
    4848$lang['ap_language_perm'] = 'par langue';
    4949
     50$lang['Load a page model'] = 'Charger un modèle de page';
     51$lang['The content of the page changed, are your sure you wan\'t to quit without saving?'] = 'Le contenu de la page a changé, êtes-vous sûr de vouloir quitter sans sauvegarder ?';
     52
    5053?>
  • extensions/AdditionalPages/trunk/main.inc.php

    r12502 r16118  
    1616define('AP_PATH' , PHPWG_PLUGINS_PATH . AP_DIR . '/');
    1717define('ADD_PAGES_TABLE' , $prefixeTable . 'additionalpages');
     18define('AP_DISTRIBUED', AP_PATH . 'distribued/');
    1819
    1920$conf['AP'] = @unserialize($conf['additional_pages']);
Note: See TracChangeset for help on using the changeset viewer.