Changeset 10348


Ignore:
Timestamp:
Apr 13, 2011, 12:36:53 PM (10 years ago)
Author:
patdenice
Message:

Clean code

Location:
trunk/plugins/LocalFilesEditor
Files:
7 added
2 edited
4 moved

Legend:

Unmodified
Added
Removed
  • trunk/plugins/LocalFilesEditor/admin.php

    r10309 r10348  
    2424if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    2525include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
    26 include_once(LOCALEDIT_PATH.'functions.inc.php');
     26include_once(LOCALEDIT_PATH.'include/functions.inc.php');
    2727load_language('plugin.lang', LOCALEDIT_PATH);
    2828$my_base_url = get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__));
     
    5555$tabsheet->assign();
    5656
    57 
    58 // +-----------------------------------------------------------------------+
    59 // |                            Variables init
    60 // +-----------------------------------------------------------------------+
    61 $edited_file = isset($_POST['edited_file']) ? $_POST['edited_file'] : '';
    62 $content_file = '';
    63 $new_file['localconf'] = "<?php\n\n/* ".l10n('locfiledit_newfile')." */\n\n\n\n\n?>";
    64 $new_file['css'] = "/* " . l10n('locfiledit_newfile') . " */\n\n";
    65 $new_file['tpl'] = "{* " . l10n('locfiledit_newfile') . " *}\n\n";
    66 $new_file['lang'] = $new_file['localconf'];
    67 $new_file['plug'] = "<?php\n/*
    68 Plugin Name: " . l10n('locfiledit_onglet_plug') . "
    69 Version: 1.0
    70 Description: " . l10n('locfiledit_onglet_plug') . "
    71 Plugin URI: http://piwigo.org
    72 Author:
    73 Author URI:
    74 */\n\n\n\n\n?>";
    75 $newfile_page = isset($_GET['newfile']) ? true : false;
    76 
    77 // Edit selected file for CSS, template and language
    78 if ((isset($_POST['edit'])) and !is_numeric($_POST['file_to_edit']))
    79 {
    80   $edited_file = $_POST['file_to_edit'];
    81   $content_file = file_exists($edited_file) ?
    82     file_get_contents($edited_file) : $new_file[$page['tab']];
    83 }
    84 
    85 // Edit new tpl file
    86 if (isset($_POST['create_tpl']))
    87 {
    88   $filename = $_POST['tpl_name'];
    89   if (empty($filename))
    90   {
    91     array_push($page['errors'], l10n('locfiledit_empty_filename'));
    92   }
    93   if (get_extension($filename) != 'tpl')
    94   {
    95     $filename .= '.tpl';
    96   }
    97   if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename))
    98   {
    99     array_push($page['errors'], l10n('locfiledit_filename_error'));
    100   }
    101   if (is_numeric($_POST['tpl_model']) and $_POST['tpl_model'] != '0')
    102   {
    103     array_push($page['errors'], l10n('locfiledit_model_error'));
    104   }
    105   if (file_exists($_POST['tpl_parent'] . '/' . $filename))
    106   {
    107     array_push($page['errors'], l10n('locfiledit_file_already_exists'));
    108   }
    109   if (!empty($page['errors']))
    110   {
    111     $newfile_page = true;
    112   }
    113   else
    114   {
    115     $edited_file = $_POST['tpl_parent'] . '/' . $filename;
    116     $content_file = ($_POST['tpl_model'] == '0') ? $new_file['tpl'] : file_get_contents($_POST['tpl_model']);
    117   }
    118 }
    119 
    120 // +-----------------------------------------------------------------------+
    121 // |                            Process tabsheet
    122 // +-----------------------------------------------------------------------+
    123 switch ($page['tab'])
    124 {
    125   case 'localconf':
    126     $edited_file = PHPWG_ROOT_PATH.PWG_LOCAL_DIR . "config/config.inc.php";
    127     $content_file = file_exists($edited_file) ?
    128       file_get_contents($edited_file) : $new_file['localconf'];
    129        
    130     $template->assign('show_default' , array(
    131         array('SHOW_DEFAULT' => LOCALEDIT_PATH
    132                 . 'show_default.php?file=include/config_default.inc.php',
    133               'FILE' => 'config_default.inc.php')));
    134     $codemirror_mode = 'application/x-httpd-php';
    135     break;
    136 
    137   case 'css':
    138     $selected = 0;
    139     $options[] = l10n('locfiledit_choose_file');
    140     $options[] = '----------------------';
    141     $value = PHPWG_ROOT_PATH.PWG_LOCAL_DIR . "css/rules.css";
    142     $options[$value] = 'local / css / rules.css';
    143     if ($edited_file == $value) $selected = $value;
    144     $options[] = '----------------------';
    145        
    146     foreach (get_dirs($conf['themes_dir']) as $theme_id)
    147     {
    148       $value = PHPWG_ROOT_PATH.PWG_LOCAL_DIR . 'css/'.$theme_id.'-rules.css';
    149       $options[$value] = 'local / css / '.$theme_id.'-rules.css';
    150       if ($edited_file == $value) $selected = $value;
    151     }
    152     $template->assign('css_lang_tpl', array(
    153         'OPTIONS' => $options,
    154         'SELECTED' => $selected));
    155     $codemirror_mode = 'text/css';
    156     break;
    157 
    158   case 'tpl':
    159     // New file form creation
    160     if ($newfile_page)
    161     {
    162       $filename = isset($_POST['tpl_name']) ? $_POST['tpl_name'] : '';
    163       $selected['model'] = isset($_POST['tpl_model']) ? $_POST['tpl_model'] : '0';
    164       $selected['parent'] = isset($_POST['tpl_parent']) ? $_POST['tpl_parent'] : PHPWG_ROOT_PATH . 'template-extension';
    165 
    166       // Parent directories list
    167       $options['parent'] = array(PHPWG_ROOT_PATH . 'template-extension' => 'template-extension');
    168       $options['parent'] = array_merge($options['parent'], get_rec_dirs(PHPWG_ROOT_PATH . 'template-extension'));
    169 
    170       $options['model'][] = l10n('locfiledit_empty_page');
    171       $options['model'][] = '----------------------';
    172       $i = 0;
    173       foreach (get_extents() as $pwg_template)
    174       {
    175         $value = PHPWG_ROOT_PATH . 'template-extension/' . $pwg_template;
    176         $options['model'][$value] =  'template-extension / ' . str_replace('/', ' / ', $pwg_template);
    177         $i++;
    178       }
    179       foreach (get_dirs($conf['themes_dir']) as $theme_id)
    180       {
    181         if ($i)
    182         {
    183           $options['model'][] = '----------------------';
    184           $i = 0;
    185         }
    186         $dir = $conf['themes_dir'] . '/' . $theme_id . '/template/';
    187         if (is_dir($dir) and $content = opendir($dir))
    188         {
    189           while ($node = readdir($content))
    190           {
    191             if (is_file($dir.$node) and get_extension($node) == 'tpl')
    192             {
    193               $value = $dir . $node;
    194               $options['model'][$value] = $theme_id . ' / ' . $node;
    195               $i++;
    196             }
    197           }
    198         }
    199       }
    200       if (end($options['model']) == '----------------------')
    201       {
    202         array_pop($options['model']);
    203       }
    204       // Assign variables to template
    205       $template->assign('create_tpl', array(
    206         'NEW_FILE_NAME' => $filename,
    207         'MODEL_OPTIONS' => $options['model'],
    208         'MODEL_SELECTED' => $selected['model'],
    209         'PARENT_OPTIONS' => $options['parent'],
    210         'PARENT_SELECTED' => $selected['parent']));
    211       break;
    212     }
    213     // List existing template extensions
    214     $selected = 0;
    215     $options[] = l10n('locfiledit_choose_file');
    216     $options[] = '----------------------';
    217     foreach (get_extents() as $pwg_template)
    218     {
    219       $value = './template-extension/' . $pwg_template;
    220       $options[$value] =  str_replace('/', ' / ', $pwg_template);
    221       if ($edited_file == $value) $selected = $value;
    222     }
    223     if ($selected == 0 and !empty($edited_file))
    224     {
    225       $options[$edited_file] =  str_replace(array('./template-extension/', '/'), array('', ' / '), $edited_file);
    226       $selected = $edited_file;
    227     }
    228     $template->assign('css_lang_tpl', array(
    229       'OPTIONS' => $options,
    230       'SELECTED' => $selected,
    231       'NEW_FILE_URL' => $my_base_url.'-tpl&amp;newfile',
    232       'NEW_FILE_CLASS' => empty($edited_file) ? '' : 'top_right'));
    233 
    234     $codemirror_mode = 'text/html';
    235     break;
    236 
    237   case 'lang':
    238     $selected = 0;
    239     $options[] = l10n('locfiledit_choose_file');
    240     $options[] = '----------------------';
    241     foreach (get_languages() as $language_code => $language_name)
    242     {
    243       $value = PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'language/'.$language_code.'.lang.php';
    244       if ($edited_file == $value)
    245       {
    246         $selected = $value;
    247         $template->assign('show_default', array(
    248           array('SHOW_DEFAULT' => LOCALEDIT_PATH
    249                   . 'show_default.php?file='
    250                   . 'language/'.$language_code.'/common.lang.php',
    251                 'FILE' => 'common.lang.php'),
    252           array('SHOW_DEFAULT' => LOCALEDIT_PATH
    253                   . 'show_default.php?file='
    254                   . 'language/'.$language_code.'/admin.lang.php',
    255                 'FILE' => 'admin.lang.php')));
    256       }
    257       $options[$value] = $language_name;
    258     }
    259     $template->assign('css_lang_tpl', array(
    260         'OPTIONS' => $options,
    261         'SELECTED' => $selected));
    262     $codemirror_mode = 'application/x-httpd-php';
    263     break;
    264    
    265   case 'plug':
    266     $edited_file = PHPWG_PLUGINS_PATH . "PersonalPlugin/main.inc.php";
    267     $content_file = file_exists($edited_file) ?
    268       file_get_contents($edited_file) : $new_file['plug'];
    269     $codemirror_mode = 'application/x-httpd-php';
    270     break;
    271 }
     57include_once(LOCALEDIT_PATH.'include/'.$page['tab'].'.inc.php');
    27258
    27359// +-----------------------------------------------------------------------+
     
    335121// +-----------------------------------------------------------------------+
    336122$template->set_filenames(array(
    337     'plugin_admin_content' => dirname(__FILE__) . '/admin.tpl'));
     123    'plugin_admin_content' => dirname(__FILE__) . '/template/admin.tpl'));
    338124
    339125if (!empty($edited_file))
     
    344130  }
    345131  $template->assign('zone_edit',
    346     array('EDITED_FILE' => $edited_file,
    347           'CONTENT_FILE' => htmlspecialchars($content_file),
    348           'FILE_NAME' => trim($edited_file, './\\')));
     132    array(
     133      'EDITED_FILE' => $edited_file,
     134      'CONTENT_FILE' => htmlspecialchars($content_file),
     135      'FILE_NAME' => trim($edited_file, './\\')
     136    )
     137  );
    349138  if (file_exists(get_bak_file($edited_file)))
    350139  {
     
    355144    $template->assign('restore_infos', true);
    356145  }
    357  
    358146}
    359147
  • trunk/plugins/LocalFilesEditor/show_default.php

    r10309 r10348  
    2525define('IN_ADMIN', true);
    2626include_once(PHPWG_ROOT_PATH . 'include/common.inc.php');
    27 include_once(LOCALEDIT_PATH.'functions.inc.php');
     27include_once(LOCALEDIT_PATH.'include/functions.inc.php');
    2828load_language('plugin.lang', LOCALEDIT_PATH);
    2929check_status(ACCESS_ADMINISTRATOR);
     
    3737  }
    3838   
    39   $template->set_filename('show_default', dirname(__FILE__) . '/show_default.tpl');
     39  $template->set_filename('show_default', dirname(__FILE__) . '/template/show_default.tpl');
    4040 
    4141  $file = file_get_contents(PHPWG_ROOT_PATH . $path);
     
    4545    'TITLE' => $title,
    4646    'DEFAULT_CONTENT' => $file,
    47     'LOCALEDIT_PATH' => LOCALEDIT_PATH,
    48     'CODEMIRROR_MODE' => 'application/x-httpd-php'
    4947    )
    5048  );
  • trunk/plugins/LocalFilesEditor/template/admin.tpl

    r10338 r10348  
    1212{combine_css path="plugins/LocalFilesEditor/codemirror/mode/css/css.css"}
    1313{combine_css path="plugins/LocalFilesEditor/codemirror/mode/clike/clike.css"}
    14 {combine_css path="plugins/LocalFilesEditor/locfiledit.css"}
     14{combine_css path="plugins/LocalFilesEditor/template/locfiledit.css"}
    1515
    1616{footer_script}
     
    6363{/if}
    6464
    65 <div style="overflow:auto;"> {* top bar buttons *}
     65{if isset ($zone_edit)}
     66<div id="title_bar">
     67{/if}
     68
    6669{if !empty($show_default)}
    6770{foreach from=$show_default item=file name=default_loop}
    68 <span class="top_right">
    69 <a href="{$file.SHOW_DEFAULT}" onclick="window.open( this.href, 'local_file', 'location=no,toolbar=no,menubar=no,status=no,resizable=yes,scrollbars=yes,width=800,height=700' ); return false;">{'locfiledit_show_default'|@translate} "{$file.FILE}"</a>
     71<span class="default_file">
     72<a href="{$file.URL}" onclick="window.open( this.href, 'local_file', 'location=no,toolbar=no,menubar=no,status=no,resizable=yes,scrollbars=yes,width=800,height=700' ); return false;">{'locfiledit_show_default'|@translate} "{$file.FILE}"</a>
    7073</span>
    7174{if !($smarty.foreach.default_loop.last)}<br>{/if}
     
    7477
    7578{if isset ($zone_edit)}
    76 <b>{$zone_edit.FILE_NAME}</b>
    77 
    78 </div> {* top bar buttons *}
     79<span class="file_name">{$zone_edit.FILE_NAME}</span>
     80</div> {* title_bar *}
    7981
    8082<textarea rows="30" cols="90" name="text" id="text">{$zone_edit.CONTENT_FILE}</textarea>
     83<br>
     84<input class="submit" type="submit" value="{'locfiledit_save_file'|@translate}" name="submit"/>
    8185
    82 <br>
    83 
    84 <input class="submit" type="submit" value="{'locfiledit_save_file'|@translate}" name="submit"/>
    8586{if isset ($restore)}
    8687<input class="submit" type="submit" value="{'locfiledit_restore'|@translate}" name="restore" onclick="return confirm('{'locfiledit_restore_confirm'|@translate|escape:'javascript'}');"/>
     
    9293{/if}
    9394
    94 {/if}
     95{/if} {* zone_edit *}
    9596</div>
    9697</form>
  • trunk/plugins/LocalFilesEditor/template/locfiledit.css

    r10338 r10348  
    44}
    55
    6 #LocalFilesEditor .top_right  {
    7   float: right;
    8   margin-right: 1%;
     6#LocalFilesEditor #title_bar {
     7  overflow: auto;
    98}
    109
    11 #LocalFilesEditor B {
     10#LocalFilesEditor .file_name {
     11  font-weight: bold;
    1212  float: left;
    1313}
    1414
    15 #LocalFilesEditor TEXTAREA {
    16   margin: 0.5em 0;
    17   width: 99%;
    18   height: 500px;
    19   float: left;
     15#LocalFilesEditor .default_file  {
     16  float: right;
    2017}
    2118
     
    2421}
    2522
    26 .CodeMirror {
     23#LocalFilesEditor TEXTAREA, .CodeMirror {
    2724  background-color: #EEEEEE;
    28   font-size: 1.3em;
     25  font-family: monospace,Arial,sans-serif;
     26  font-size: 1.2em;
    2927  border: 1px solid #999999;
    3028  margin: 0.5em 0;
    31   width: 99%;
     29  width: 100%;
    3230  min-height: 500px;
    3331  height: auto;
  • trunk/plugins/LocalFilesEditor/template/show_default.tpl

    r10338 r10348  
    1 {html_head}
    2 <style type="text/css">#headbranch, #theHeader, #copyright {ldelim} display: none; }</style>
    3 {/html_head}
    4 {combine_script id="jquery"}
    5 
    61{combine_script id="codemirror" path="plugins/LocalFilesEditor/codemirror/lib/codemirror.js"}
    72{combine_script id="codemirror.xml" require="codemirror" path="plugins/LocalFilesEditor/codemirror/mode/xml/xml.js"}
     
    1712{combine_css path="plugins/LocalFilesEditor/codemirror/mode/css/css.css"}
    1813{combine_css path="plugins/LocalFilesEditor/codemirror/mode/clike/clike.css"}
    19 {combine_css path="plugins/LocalFilesEditor/locfiledit.css"}
     14{combine_css path="plugins/LocalFilesEditor/template/locfiledit.css"}
    2015
    2116{footer_script}
    2217var editor = CodeMirror.fromTextArea(document.getElementById("text"), {ldelim}
    23   matchBrackets: true,
    2418  readOnly: true,
    25   mode: "{$CODEMIRROR_MODE}",
    26   tabMode: "shift"
     19  mode: "application/x-httpd-php"
    2720});
    2821{/footer_script}
    2922
     23{html_head}
     24<style type="text/css">
     25#headbranch, #theHeader, #copyright {ldelim} display: none; }
     26</style>
     27{/html_head}
     28
    3029<div id="LocalFilesEditor">
    31 <div style="overflow:auto;"><b>{$TITLE}</b></div>
    3230
    33 <textarea id="text" rows="30" cols="90">{$DEFAULT_CONTENT}</textarea>
     31<div id="title_bar">
     32  <span class="file_name">{$TITLE}</span>
     33</div>
     34
     35<textarea id="text" rows="30" cols="90" class="show_default_area">{$DEFAULT_CONTENT}</textarea>
    3436
    3537</div>
Note: See TracChangeset for help on using the changeset viewer.