Advertisement
makss

txp_form - LastMod patch

Jan 5th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.40 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.     This is Textpattern
  5.  
  6.     Copyright 2005 by Dean Allen
  7.     www.textpattern.com
  8.     All rights reserved
  9.  
  10.     Use of this software indicates acceptance of the Textpattern license agreement
  11.  
  12. $HeadURL: https://textpattern.googlecode.com/svn/development/4.x/textpattern/include/txp_form.php $
  13. $LastChangedRevision: 3560 $
  14.  
  15. */
  16.  
  17.     if (!defined('txpinterface')) die('txpinterface is undefined.');
  18.  
  19.     global $vars;
  20.     $vars = array('Form','type','new_type','name','savenew','oldname');
  21.     $essential_forms = array('comments','comments_display','comment_form','default','Links','files');
  22.  
  23.     if ($event == 'form') {
  24.     require_privs('form');
  25.  
  26.     bouncer($step,
  27.         array(
  28.         'form_edit'       => false,
  29.         'form_create'     => false,
  30.         'form_delete'     => true,
  31.         'form_multi_edit' => true,
  32.         'form_save'       => true,
  33.         'save_pane_state' => true
  34.         )
  35.     );
  36.  
  37.     switch(strtolower($step)) {
  38.         case "":                form_edit();             break;
  39.         case "form_edit":       form_edit();             break;
  40.         case "form_create":     form_create();           break;
  41.         case "form_delete":     form_delete();           break;
  42.         case "form_multi_edit": form_multi_edit();       break;
  43.         case "form_save":       form_save();             break;
  44.         case "save_pane_state": form_save_pane_state();  break;
  45.     }
  46.  
  47.     }
  48.  
  49. // -------------------------------------------------------------
  50.     function form_list($curname)
  51.     {
  52.     global $step,$essential_forms;
  53.     $out[] = '<p class="action-create smallerbox">'.sLink('form','form_create',gTxt('create_new_form')).'</p>';
  54.  
  55.     $methods = array('delete'=>gTxt('delete'));
  56.  
  57.     $rs = safe_rows_start("*", "txp_form", "1 order by type asc, name asc");
  58.  
  59.     if ($rs) {
  60.         $ctr = 1;
  61.         $prev_type = '';
  62.         while ($a = nextRow($rs)){
  63.         extract($a);
  64.         $editlink = ($curname!=$name)
  65.             ?   eLink('form','form_edit','name',$name,$name)
  66.             :   htmlspecialchars($name);
  67.         $modbox = (!in_array($name, $essential_forms))
  68.             ?   '<input type="checkbox" name="selected_forms[]" value="'.$name.'" />'
  69.             :   '';
  70.  
  71.         if ($prev_type != $type) {
  72.             $visipref = 'pane_form_'.$type.'_visible';
  73.             //TODO: Add 'article', 'comment', 'misc' to rpc server for gTxt()
  74.             $group_start = '<div class="form-list-group '.$type.'"><h3 class="plain lever'.(get_pref($visipref) ? ' expanded' : '').'"><a href="#'.$type.'">'.ucfirst(gTxt($type)).'</a></h3>'.n.
  75.             '<div id="'.$type.'" class="toggle form-list" style="display:'.(get_pref($visipref) ? 'block' : 'none').'">'.n.
  76.             '<ul class="plain-list">'.n;
  77.             $group_end = ($ctr > 1) ? '</ul></div></div>'.n : '';
  78.         } else {
  79.             $group_start = $group_end = '';
  80.         }
  81.  
  82.         $out[] = $group_end.$group_start;
  83.         $out[] = '<li class="'.(($ctr%2 == 0) ? 'even' : 'odd').'">'.n.'<span class="form-list-action">'.$modbox.'</span><span class="form-list-name">'.$editlink.'</span></li>';
  84.         $prev_type = $type;
  85.         $ctr++;
  86.         }
  87.  
  88.         $out[] = '</ul></div></div>';
  89.         $out[] = eInput('form').sInput('form_multi_edit');
  90.         $out[] = graf(selectInput('edit_method',$methods,'',1).sp.gTxt('selected').sp.
  91.         fInput('submit','form_multi_edit',gTxt('go'),'smallerbox')
  92.         , ' align="right"');
  93.  
  94.         return form( join('',$out),'',"verify('".gTxt('are_you_sure')."')", 'post', '', '', 'allforms_form' );
  95.     }
  96.     }
  97.  
  98. // -------------------------------------------------------------
  99.  
  100.     function form_multi_edit()
  101.     {
  102.     global $essential_forms;
  103.  
  104.     $method = ps('edit_method');
  105.     $forms = ps('selected_forms');
  106.  
  107.     if ($forms and is_array($forms))
  108.     {
  109.         if ($method == 'delete')
  110.         {
  111.         foreach ($forms as $name)
  112.         {
  113.             if (!in_array($name, $essential_forms) && form_delete($name))
  114.             {
  115.             $deleted[] = $name;
  116.             }
  117.         }
  118.  
  119.         $message = gTxt('forms_deleted', array('{list}' => join(', ', $deleted)));
  120.  
  121.         form_edit($message);
  122.         }
  123.     }
  124.  
  125.     else
  126.     {
  127.         form_edit();
  128.     }
  129.     }
  130.  
  131. // -------------------------------------------------------------
  132.     function form_create()
  133.     {
  134.     form_edit();
  135.     }
  136.  
  137. // -------------------------------------------------------------
  138.     function form_edit($message='')
  139.     {
  140.     global $event,$step,$essential_forms;
  141.     pagetop(gTxt('edit_forms'),$message);
  142.  
  143.     extract(gpsa(array('Form','name','type')));
  144.     $name = trim(preg_replace('/[<>&"\']/', '', $name));
  145.  
  146.     if ($step=='form_create') {
  147.         $inputs = fInput('submit','savenew',gTxt('save_new'),'publish').
  148.         eInput("form").sInput('form_save');
  149.     } else {
  150.         $name = (!$name or $step=='form_delete') ? 'default' : $name;
  151. // LastMod patch
  152. //      $rs = safe_row("*", "txp_form", "name='".doSlash($name)."'");
  153.         $rs = safe_row("*, unix_timestamp(LastMod) as sLastMod", "txp_form", "name='".doSlash($name)."'");
  154.  
  155. //          if ($rs)
  156.  {
  157.         extract($rs);
  158.         $inputs = fInput('submit','save',gTxt('save'),'publish').
  159.             eInput("form").sInput('form_save').hInput('oldname',$name);
  160.         }
  161.     }
  162.  
  163. // essential_forms patch
  164.     if (!in_array($name, $essential_forms)){
  165.         $changename = graf(gTxt('form_name').br.fInput('text','name',$name,'edit','','',15));
  166.         $formtype = graf(gTxt('form_type').br.formtypes($type));
  167.     } else {
  168.         $changename = graf(gTxt('form_name').br.tag($name, 'em').hInput('name',$name));
  169.         $formtype = graf(gTxt('form_type').br.tag($type, 'em').hInput('type',$type));
  170.     }
  171. /*
  172.     if (!in_array($name, $essential_forms))
  173.             $changename = graf(gTxt('form_name').br.fInput('text','name',$name,'edit','','',15));
  174.     else
  175.             $changename = graf(gTxt('form_name').br.tag($name, 'em').hInput('name',$name));
  176. */
  177.  
  178.  
  179. // LastMod patch
  180.     if( @$sLastMod ){
  181.         $changename = '<p class="author small">'.gTxt('modified_by').': '.safe_strftime('%d %b %Y &#183; %X',$sLastMod).'</p>'.
  182.         $changename;
  183.     }
  184.  
  185.     // Generate the tagbuilder links
  186.     // Format of each entry is popTagLink -> array ( gTxt string, class/ID, popHelp ref )
  187.     $tagbuild_items = array(
  188.         'article' => array('articles', 'article-tags', 'form_articles'),
  189.         'link' => array('links', 'link-tags', 'form__place_link'),
  190.         'comment' => array('comments', 'comment-tags', 'form_comments'),
  191.         'comment_details' => array('comment_details', 'comment-detail-tags', 'form_comment_details'),
  192.         'comment_form' => array('comment_form', 'comment-form-tags', 'form_comment_form'),
  193.         'search_result' => array('search_results_form', 'search-result-tags', 'form_search_results'),
  194.         'file_download' => array('file_download_tags', 'file-tags', 'form_file_download_tags'),
  195.         'category' => array('category_tags', 'category-tags', 'form_category_tags'),
  196.         'section' => array('section_tags', 'section-tags', 'form_section_tags'),
  197.     );
  198.  
  199.     $tagbuild_links = '';
  200.     foreach ($tagbuild_items as $tb => $item) {
  201.         $tagbuild_links .= '<div class="'.$item[1].'">'.hed('<a href="#'.$item[1].'">'.gTxt($item[0]).'</a>'.
  202.             sp.popHelp($item[2]), 3, ' class="plain lever'.(get_pref('pane_form_'.$item[1].'_visible') ? ' expanded' : '').'"').
  203.             '<div id="'.$item[1].'" class="toggle on" style="display:'.(get_pref('pane_form_'.$item[1].'_visible') ? 'block' : 'none').'">'.popTagLinks($tb).'</div></div>';
  204.     }
  205.  
  206.     $out =
  207.         '<div id="'.$event.'_container" class="txp-container txp-edit">'.
  208.         startTable('edit').
  209.         tr(
  210.         tdtl(
  211.             '<div id="tagbuild_links">'.hed(gTxt('tagbuilder'), 2).
  212.             $tagbuild_links.
  213.             '</div>'
  214.         , ' class="column"').
  215.         tdtl(
  216.             '<form action="index.php" method="post" id="form_form">'.
  217.             '<div id="main_content">'.
  218.             '<div class="edit-title">'.gTxt('you_are_editing_form').sp.strong(($name) ? $name : gTxt('untitled')).'</div>'.
  219.             '<textarea id="form" class="code" name="Form" cols="60" rows="20">'.htmlspecialchars($Form).'</textarea>'.
  220.  
  221.             $changename.
  222. // essential_forms patch
  223. //          graf(gTxt('form_type').br.
  224. //          formtypes($type)).
  225. $formtype.
  226.             (empty($type) ? graf(gTxt('only_articles_can_be_previewed')) : '').
  227.             (empty($type) || $type == 'article' ? fInput('submit','form_preview',gTxt('preview'),'smallbox') : '' ).
  228.             graf($inputs).
  229.             '</div>'.
  230.             n.tInput().
  231.             n.'</form>'
  232.  
  233.         , ' class="column"').
  234.         tdtl(
  235.             '<div id="content_switcher" class="list">'.hed(gTxt('all_forms'), 2).
  236.             form_list($name).
  237.             '</div>'
  238.         , ' class="column"')
  239.         ).endTable().'</div>';
  240.  
  241.     echo $out;
  242.     }
  243.  
  244. // -------------------------------------------------------------
  245.  
  246.     function form_save()
  247.     {
  248.     global $vars, $step, $essential_forms;
  249.  
  250.     extract(doSlash(gpsa($vars)));
  251.     $name = doSlash(trim(preg_replace('/[<>&"\']/', '', gps('name'))));
  252.  
  253.     if (!$name)
  254.     {
  255.         $step = 'form_create';
  256.         $message = gTxt('form_name_invalid');
  257.  
  258.         return form_edit(array($message, E_ERROR));
  259.     }
  260.  
  261.     if ($new_type != '') {
  262.         $type = trim($new_type);
  263.     }
  264.  
  265.     if ($type == '')
  266.     {
  267.         $step = 'form_create';
  268.         $message = gTxt('form_type_missing');
  269.  
  270.         return form_edit(array($message, E_ERROR));
  271.     }
  272.  
  273.     if ($savenew)
  274.     {
  275.         $exists = safe_field('name', 'txp_form', "name = '$name'");
  276.  
  277.         if ($exists)
  278.         {
  279.         $step = 'form_create';
  280.         $message = gTxt('form_already_exists', array('{name}' => $name));
  281.  
  282.         return form_edit(array($message, E_ERROR));
  283.         }
  284.  
  285. // LastMod patch
  286. //      safe_insert('txp_form', "Form = '$Form', type = '$type', name = '$name'");
  287.         safe_insert('txp_form', "Form = '$Form', type = '$type', name = '$name', LastMod=now() ");
  288.  
  289.         update_lastmod();
  290.  
  291.         $message = gTxt('form_created', array('{name}' => $name));
  292.  
  293.         return form_edit($message);
  294.     }
  295.  
  296. // LastMod patch
  297. //  safe_update('txp_form', "Form = '$Form', type = '$type', name = '$name'", "name = '$oldname'");
  298.     safe_update('txp_form', "Form = '$Form', type = '$type', name = '$name', LastMod=now() ", "name = '$oldname'");
  299.  
  300.     update_lastmod();
  301.  
  302.     $message = gTxt('form_updated', array('{name}' => $name));
  303.  
  304.     form_edit($message);
  305.     }
  306.  
  307. // -------------------------------------------------------------
  308.     function form_delete($name)
  309.     {
  310.     global $essential_forms;
  311.     if (in_array($name, $essential_forms)) return false;
  312.     $name = doSlash($name);
  313.     if (safe_delete("txp_form","name='$name'")) {
  314.         return true;
  315.     }
  316.     return false;
  317.     }
  318.  
  319. // -------------------------------------------------------------
  320.     function formTypes($type)
  321.     {
  322.     $all_types = safe_column('type', 'txp_form', '1=1 GROUP BY type');
  323.         $fixed_types = array(''=>'','article'=>'article','category'=>'category','comment'=>'comment',
  324.         'file'=>'file','link'=>'link','misc'=>'misc','section'=>'section');
  325.         $types = array_merge($fixed_types, $all_types);
  326.         natsort($types);
  327. //  return selectInput('type', $types, $type) . fInput('text', 'new_type', '');
  328.     return selectInput('type', $types, $type) . fInput('text', 'new_type', '', 'edit','','',15);
  329.     }
  330.  
  331. // -------------------------------------------------------------
  332.     function form_save_pane_state()
  333.     {
  334.     global $event;
  335.     $all_types = safe_column('type', 'txp_form', '1=1 GROUP BY type');
  336.     $panes = array('article', 'category', 'comment', 'file', 'link', 'misc', 'section', 'article-tags', 'link-tags', 'comment-tags', 'comment-detail-tags', 'comment-form-tags', 'search-result-tags', 'file-tags', 'category-tags', 'section-tags');
  337.     $pane = gps('pane');
  338.     if (in_array($pane, $panes + $all_types))
  339.     {
  340.         set_pref("pane_form_{$pane}_visible", (gps('visible') == 'true' ? '1' : '0'), $event, PREF_HIDDEN, 'yesnoradio', 0, PREF_PRIVATE);
  341.         send_xml_response();
  342.     } else {
  343.         send_xml_response(array('http-status' => '400 Bad Request'));
  344.     }
  345.     }
  346.  
  347. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement