plugins/SpecialAdmin.php
changeset 885 a86a69394a95
parent 832 7152ca0a0ce9
child 898 c75754f5b1da
equal deleted inserted replaced
884:d6c7b310295d 885:a86a69394a95
  2456     redirect(makeUrlNS('Special', 'Login/'.$paths->page, 'level='.USER_LEVEL_ADMIN), '', '', false);
  2456     redirect(makeUrlNS('Special', 'Login/'.$paths->page, 'level='.USER_LEVEL_ADMIN), '', '', false);
  2457     exit;
  2457     exit;
  2458   }
  2458   }
  2459   else 
  2459   else 
  2460   {
  2460   {
  2461     
  2461     if ( isset($_GET['update_order']) )
  2462     $template->add_header('<script type="text/javascript" src="'.cdnPath.'/includes/clientside/dbx.js"></script>');
  2462     {
  2463     $template->add_header('<script type="text/javascript" src="'.cdnPath.'/includes/clientside/dbx-key.js"></script>');
  2463       header('Content-type: text/javascript');
       
  2464       $order = @$_POST['order'];
       
  2465       try
       
  2466       {
       
  2467         $order = enano_json_decode($order);
       
  2468       }
       
  2469       catch ( Zend_Json_Exception $e )
       
  2470       {
       
  2471         return print enano_json_encode(array(
       
  2472             'mode' => 'error',
       
  2473             'error' => 'bad order'
       
  2474           ));
       
  2475       }
       
  2476       
       
  2477       foreach ( $order as $sidebar_id => $blocks )
       
  2478       {
       
  2479         foreach ( $blocks as $order => $block_id )
       
  2480         {
       
  2481           $sbid = intval($sidebar_id);
       
  2482           $order = intval($order);
       
  2483           $block_id = intval($block_id);
       
  2484           $q = $db->sql_query('UPDATE ' . table_prefix . "sidebar SET sidebar_id = $sbid, item_order = $order WHERE item_id = $block_id;");
       
  2485           if ( !$q )
       
  2486             $db->die_json();
       
  2487         }
       
  2488       }
       
  2489       
       
  2490       return print enano_json_encode(array(
       
  2491           'mode' => 'success'
       
  2492         ));
       
  2493     }
       
  2494     
  2464     $template->add_header('<script type="text/javascript" src="'.cdnPath.'/includes/clientside/sbedit.js"></script>');
  2495     $template->add_header('<script type="text/javascript" src="'.cdnPath.'/includes/clientside/sbedit.js"></script>');
  2465     $template->add_header('<link rel="stylesheet" type="text/css" href="'.cdnPath.'/includes/clientside/dbx.css" />');
       
  2466     
       
  2467     $template->load_theme('oxygen', 'bleu');
       
  2468     $template->init_vars();
       
  2469     
  2496     
  2470     $template->header();
  2497     $template->header();
  2471     
  2498     
  2472     if(isset($_POST['save']))
  2499     if(isset($_POST['save']))
  2473     {
  2500     {
  2622                 </select>
  2649                 </select>
  2623             
  2650             
  2624             </p>
  2651             </p>
  2625             
  2652             
  2626             <div class="sbadd_block" id="blocktype_<?php echo BLOCK_WIKIFORMAT; ?>">
  2653             <div class="sbadd_block" id="blocktype_<?php echo BLOCK_WIKIFORMAT; ?>">
  2627               <p>
  2654               <?php echo $lang->get('sbedit_field_wikitext'); ?>
  2628                 <?php echo $lang->get('sbedit_field_wikitext'); ?>
       
  2629               </p>
       
  2630               <p>
  2655               <p>
  2631                 <textarea style="width: 98%;" name="wikiformat_content" rows="15" cols="50"></textarea>
  2656                 <textarea style="width: 98%;" name="wikiformat_content" rows="15" cols="50"></textarea>
  2632               </p>
  2657               </p>
  2633             </div>
  2658             </div>
  2634             
  2659             
  2635             <div class="sbadd_block" id="blocktype_<?php echo BLOCK_TEMPLATEFORMAT; ?>">
  2660             <div class="sbadd_block" id="blocktype_<?php echo BLOCK_TEMPLATEFORMAT; ?>">
  2636               <p>
  2661               <?php echo $lang->get('sbedit_field_tplcode'); ?>
  2637                 <?php echo $lang->get('sbedit_field_tplcode'); ?>
       
  2638               </p>
       
  2639               <p>
  2662               <p>
  2640                 <textarea style="width: 98%;" name="templateformat_content" rows="15" cols="50"></textarea>
  2663                 <textarea style="width: 98%;" name="templateformat_content" rows="15" cols="50"></textarea>
  2641               </p>
  2664               </p>
  2642             </div>
  2665             </div>
  2643             
  2666             
  2644             <div class="sbadd_block" id="blocktype_<?php echo BLOCK_HTML; ?>">
  2667             <div class="sbadd_block" id="blocktype_<?php echo BLOCK_HTML; ?>">
  2645               <p>
  2668               <?php echo $lang->get('sbedit_field_html'); ?>
  2646                 <?php echo $lang->get('sbedit_field_html'); ?>
       
  2647               </p>
       
  2648               <p>
  2669               <p>
  2649                 <textarea style="width: 98%;" name="html_content" rows="15" cols="50"></textarea>
  2670                 <textarea style="width: 98%;" name="html_content" rows="15" cols="50"></textarea>
  2650               </p>
  2671               </p>
  2651             </div>
  2672             </div>
  2652             
  2673             
  2661               </p>
  2682               </p>
  2662               <?php } ?>
  2683               <?php } ?>
  2663             </div>
  2684             </div>
  2664             
  2685             
  2665             <div class="sbadd_block" id="blocktype_<?php echo BLOCK_PLUGIN; ?>">
  2686             <div class="sbadd_block" id="blocktype_<?php echo BLOCK_PLUGIN; ?>">
  2666               <p>
  2687               <?php echo $lang->get('sbedit_field_plugin'); ?>
  2667                 <?php echo $lang->get('sbedit_field_plugin'); ?>
       
  2668               </p>
       
  2669               <p>
  2688               <p>
  2670                 <select name="plugin_id">
  2689                 <select name="plugin_id">
  2671                 <?php
  2690                 <?php
  2672                   foreach($template->plugin_blocks as $k => $c)
  2691                   foreach($template->plugin_blocks as $k => $c)
  2673                   {
  2692                   {
  2812           if(!$q)
  2831           if(!$q)
  2813           {
  2832           {
  2814             echo 'var status=unescape(\''.hexencode($db->get_error()).'\');';
  2833             echo 'var status=unescape(\''.hexencode($db->get_error()).'\');';
  2815             exit;
  2834             exit;
  2816           }
  2835           }
  2817           $q = $db->sql_query('SELECT block_type,block_content FROM '.table_prefix.'sidebar WHERE item_id=' . intval($_GET['id']) . ';');
  2836           echo 'GOOD';
  2818           if(!$q)
  2837           return;
  2819           {
       
  2820             echo 'var status=unescape(\''.hexencode($db->get_error()).'\');';
       
  2821             exit;
       
  2822           }
       
  2823           $row = $db->fetchrow();
       
  2824           $db->free_result();
       
  2825           switch($row['block_type'])
       
  2826           {
       
  2827             case BLOCK_WIKIFORMAT:
       
  2828             default:
       
  2829               $c = RenderMan::render($row['block_content']);
       
  2830               break;
       
  2831             case BLOCK_TEMPLATEFORMAT:
       
  2832               $c = $template->tplWikiFormat($row['block_content'], false, 'sidebar-editor.tpl');
       
  2833               $c = preg_replace('#<a (.*?)>(.*?)</a>#is', '<a href="#" onclick="return false;">\\2</a>', $c);
       
  2834               break;
       
  2835             case BLOCK_HTML:
       
  2836               $c = $row['block_content'];
       
  2837               $c = preg_replace('#<a (.*?)>(.*?)</a>#is', '<a href="#" onclick="return false;">\\2</a>', $c);
       
  2838               break;
       
  2839             case BLOCK_PHP:
       
  2840               ob_start();
       
  2841               eval($row['block_content']);
       
  2842               $c = ob_get_contents();
       
  2843               ob_end_clean();
       
  2844               $c = preg_replace('#<a (.*?)>(.*?)</a>#is', '<a href="#" onclick="return false;">\\2</a>', $c);
       
  2845               break;
       
  2846             case BLOCK_PLUGIN:
       
  2847               $c = ($template->fetch_block($row['block_content'])) ? $template->fetch_block($row['block_content']) : $lang->get('sbedit_msg_plugin_not_loaded');
       
  2848               break;
       
  2849           }
       
  2850           $c = preg_replace('/\{(restrict|hideif) ([a-z0-9_\(\)\|&! ]+)\}/', '', $c);
       
  2851           $cache->purge('anon_sidebar');
       
  2852           die('var status = \'GOOD\'; var content = unescape(\''.hexencode($c).'\');');
       
  2853           break;
       
  2854       }
       
  2855     }
       
  2856     
       
  2857     $q = $db->sql_query('SELECT item_id,sidebar_id,item_enabled,block_name,block_type,block_content FROM '.table_prefix.'sidebar ORDER BY sidebar_id ASC, item_order ASC;');
       
  2858     if(!$q) $db->_die('The sidebar text data could not be selected.');
       
  2859     
       
  2860     $vars = $template->extract_vars('sidebar-editor.tpl');
       
  2861     
       
  2862     $parser = $template->makeParserText($vars['sidebar_button']);
       
  2863     $parser->assign_vars(Array(
       
  2864         'HREF'=>'#',
       
  2865         'FLAGS'=>'onclick="return false;"',
       
  2866         'TEXT' => $lang->get('sidebar_btn_changestyle')
       
  2867       ));
       
  2868     $template->tpl_strings['THEME_LINK'] = $parser->run();
       
  2869     $parser->assign_vars(Array(
       
  2870         'TEXT' => $lang->get('sidebar_btn_logout'),
       
  2871       ));
       
  2872     $template->tpl_strings['LOGOUT_LINK'] = $parser->run();
       
  2873     
       
  2874     $n1 = Array();
       
  2875     $n2 = Array();
       
  2876     $n  =& $n1;
       
  2877     
       
  2878     echo '<table border="0"><tr><td valign="top"><div class="dbx-group" id="sbedit_left">';
       
  2879     //if(isset($vars['sidebar_top'])) echo $template->parse($vars['sidebar_top']);
       
  2880     
       
  2881     // Time for the loop
       
  2882     // what this loop does is fetch the row data, then send it out to the appropriate parser for formatting,
       
  2883     // then puts the result into $c, which is then sent to the template compiler for insertion into the TPL code.
       
  2884     while($row = $db->fetchrow())
       
  2885     {
       
  2886       if(isset($current_side))
       
  2887       {
       
  2888         if($current_side != $row['sidebar_id'])
       
  2889         {
       
  2890           // Time to switch!
       
  2891           //if(isset($vars['sidebar_top'])) echo $template->parse($vars['sidebar_bottom']);
       
  2892           echo '</div></td><td valign="top"><div class="dbx-group" id="sbedit_right">';
       
  2893           //echo '</td><td valign="top">';
       
  2894           //if(isset($vars['sidebar_top'])) echo $template->parse($vars['sidebar_top']);
       
  2895           $n =& $n2;
       
  2896         }
       
  2897       }
       
  2898       $n[] = count($n);
       
  2899       $current_side = $row['sidebar_id'];
       
  2900       switch($row['block_type'])
       
  2901       {
       
  2902         case BLOCK_WIKIFORMAT:
       
  2903         default:
       
  2904           $parser = $template->makeParserText($vars['sidebar_section']);
       
  2905           $c = RenderMan::render($row['block_content']);
       
  2906           break;
       
  2907         case BLOCK_TEMPLATEFORMAT:
       
  2908           $parser = $template->makeParserText($vars['sidebar_section']);
       
  2909           $c = $template->tplWikiFormat($row['block_content'], false, 'sidebar-editor.tpl');
       
  2910           $c = preg_replace('#<a (.*?)>(.*?)</a>#is', '<a href="#" onclick="return false;">\\2</a>', $c);
       
  2911           // fix for the "Administration" link that somehow didn't get rendered properly
       
  2912           $c = preg_replace("/(^|\n)([ ]*)<a([ ]+.*)?>(.+)<\/a>(<br(.*)\/>)([\r\n]+|$)/isU", '\\1\\2<li><a\\3>\\4</a></li>\\7', $c);
       
  2913           break;
       
  2914         case BLOCK_HTML:
       
  2915           $parser = $template->makeParserText($vars['sidebar_section_raw']);
       
  2916           $c = $row['block_content'];
       
  2917           $c = preg_replace('#<a (.*?)>(.*?)</a>#is', '<a href="#" onclick="return false;">\\2</a>', $c);
       
  2918           break;
       
  2919         case BLOCK_PHP:
       
  2920           $parser = $template->makeParserText($vars['sidebar_section_raw']);
       
  2921           ob_start();
       
  2922           eval($row['block_content']);
       
  2923           $c = ob_get_contents();
       
  2924           ob_end_clean();
       
  2925           $c = preg_replace('#<a (.*?)>(.*?)</a>#is', '<a href="#" onclick="return false;">\\2</a>', $c);
       
  2926           break;
       
  2927         case BLOCK_PLUGIN:
       
  2928           $parser = $template->makeParserText($vars['sidebar_section_raw']);
       
  2929           $c = ($template->fetch_block($row['block_content'], true)) ? $template->fetch_block($row['block_content'], true) : $lang->get('sbedit_msg_plugin_not_loaded');
       
  2930           
  2838           
  2931           break;
  2839           break;
  2932       }
  2840       }
  2933       $c = preg_replace('/\{(restrict|hideif) ([a-z0-9_\(\)\|&! ]+)\}/', '', $c);
  2841     }
  2934       $block_name = $row['block_name']; // $template->tplWikiFormat($row['block_name']);
  2842     
  2935       if ( empty($block_name) )
  2843     ?>
  2936         $block_name = '&lt;' . $lang->get('sbedit_note_block_unnamed') . '&gt;';
  2844       <p>
  2937       $t = '<span title="' . $lang->get('sbedit_hint_rename') . '" id="sbrename_' . $row['item_id'] . '" ondblclick="ajaxRenameSidebarStage1(this, \''.$row['item_id'].'\'); return false;">' . $block_name . '</span>';
  2845         <?php echo $lang->get('sbedit_header_msg', array( 'create_link' => makeUrlNS('Special', 'EditSidebar', 'action=new&id=0', true) )); ?>
  2938       if($row['item_enabled'] == 0) $t .= ' <span id="disabled_'.$row['item_id'].'" style="color: red;">' . $lang->get('sbedit_note_block_disabled') . '</span>';
  2846       </p>
  2939       else           $t .= ' <span id="disabled_'.$row['item_id'].'" style="color: red; display: none;">' . $lang->get('sbedit_note_block_disabled') . '</span>';
  2847     <?php
  2940       $side = ( $row['sidebar_id'] == SIDEBAR_LEFT ) ? SIDEBAR_RIGHT : SIDEBAR_LEFT;
  2848     
  2941       $tb = '<a title="' . $lang->get('sbedit_tip_disenable') . '" href="'.makeUrl($paths->page, 'action=disenable&id='.$row['item_id'].''       , true).'" onclick="ajaxDisenableBlock(\''.$row['item_id'].'\'); return false;"   ><img alt="' . $lang->get('sbedit_tip_disenable') . '" style="border-width: 0;" src="'.scriptPath.'/images/disenable.png" /></a>
  2849     $q = $db->sql_query('SELECT item_id, sidebar_id, block_name, block_type, block_content, item_enabled FROM ' . table_prefix . "sidebar ORDER BY sidebar_id ASC, item_order ASC;");
  2942              <a title="' . $lang->get('sbedit_tip_edit') . '"      href="'.makeUrl($paths->page, 'action=edit&id='.$row['item_id'].''            , true).'" onclick="ajaxEditBlock(\''.$row['item_id'].'\', this); return false;"><img alt="' . $lang->get('sbedit_tip_edit') . '" style="border-width: 0;" src="'.scriptPath.'/images/edit.png" /></a>
  2850     if ( !$q )
  2943              <a title="' . $lang->get('sbedit_tip_delete') . '"    href="'.makeUrl($paths->page, 'action=delete&id='.$row['item_id'].''          , true).'" onclick="if(confirm(\'' . $lang->get('sbedit_msg_delete_confirm') . '\')) { ajaxDeleteBlock(\''.$row['item_id'].'\', this); } return false;"><img alt="' . $lang->get('sbedit_tip_delete') . '" style="border-width: 0;" src="'.scriptPath.'/images/delete.png" /></a>
  2851       $db->_die();
  2944              <a title="' . $lang->get('sbedit_tip_move') . '"      href="'.makeUrl($paths->page, 'action=move&id='.$row['item_id'].'&side='.$side, true).'"><img alt="' . $lang->get('sbedit_tip_move') . '" style="border-width: 0;" src="'.scriptPath.'/images/move.png" /></a>';
  2852     
  2945       $as = '';
  2853     $switched_to_right = false;
  2946       $ae = '&nbsp;&nbsp;'.$tb;
  2854     
  2947       $parser->assign_vars(Array('CONTENT'=>$c,'TITLE'=>$t,'ADMIN_START'=>$as,'ADMIN_END'=>$ae));
  2855     echo '<table border="0" cellspacing="4" cellpadding="0"><tr><td class="sbedit-column">';
  2948       echo $parser->run();
  2856     while ( $row = $db->fetchrow() )
  2949       unset($parser);
  2857     {
  2950       
  2858       if ( $row['sidebar_id'] == SIDEBAR_RIGHT && !$switched_to_right )
  2951     }
  2859       {
  2952     $db->free_result();
  2860         echo '</td><td class="sbedit-column">';
  2953     //if(isset($vars['sidebar_top'])) echo $template->parse($vars['sidebar_bottom']);
  2861         $switched_to_right = true;
  2954     echo '</div></td></tr></table>';
  2862       }
  2955     echo '<form action="'.makeUrl($paths->page).'" method="post">';
  2863       $disabled_class = ( $row['item_enabled'] ) ? '' : ' disabled';
  2956     $order = implode(',', $n1);
  2864       echo '<div class="sbedit-block' . $disabled_class . '" id="block:' . $row['item_id'] . '">
  2957     echo "<input type='hidden' id='divOrder_Left' name='order_left' value='{$order}' />";
  2865               <div class="sbedit-handle">
  2958     $order = implode(',', $n2);
  2866                 <span>' . htmlspecialchars($template->compile_template_text_post($row['block_name'])) . '</span>
  2959     echo "<input type='hidden' id='divOrder_Right' name='order_right' value='{$order}' />";
  2867                 <input type="text" id="block_name:' . $row['item_id'] . '" value="' . htmlspecialchars($row['block_name']) . '" />
  2960     echo '
  2868               </div>';
  2961           <div style="margin: 0 auto 0 auto; text-align: center;">
  2869       ?>
  2962             <input type="submit" name="save" style="font-weight: bold;" value="' . $lang->get('etc_save_changes') . '" />
  2870       <div class="sbedit-metainfo">
  2963             <input type="submit" name="revert" style="font-weight: normal;" value="' . $lang->get('sbedit_btn_revert') . '" onclick="return confirm($lang.get(\'sbedit_msg_discard_order_confirm\'))" />
  2871         <?php
  2964             <br />
  2872         $toolbarvars = $template->extract_vars('toolbar.tpl');
  2965             <a href="'.makeUrl($paths->page, 'action=new&id=0', true).'">' . $lang->get('sbedit_btn_create_new_stage1') . '</a>  |  <a href="'.makeUrl(get_main_page(), false, true).'">' . $lang->get('sbedit_btn_main_page') . '</a>
  2873         $parser_start = $template->makeParserText($toolbarvars['toolbar_vert_start']);
  2966           </div>
  2874         echo $parser_start->run();
  2967         </form>
  2875         
  2968          ';
  2876         $button = $template->makeParserText($toolbarvars['toolbar_vert_button']);
       
  2877         $label = $template->makeParserText($toolbarvars['toolbar_vert_label']);
       
  2878         
       
  2879         $type = '<b>';
       
  2880         switch($row['block_type'])
       
  2881         {
       
  2882           case BLOCK_WIKIFORMAT: $type .= $lang->get('sbedit_block_type_wiki'); break;
       
  2883           case BLOCK_TEMPLATEFORMAT: $type .= $lang->get('sbedit_block_type_tpl'); break;
       
  2884           case BLOCK_HTML: $type .= $lang->get('sbedit_block_type_html'); break;
       
  2885           case BLOCK_PHP: $type .= $lang->get('sbedit_block_type_php'); break;
       
  2886           case BLOCK_PLUGIN: $type .= $lang->get('sbedit_block_type_plugin'); break;
       
  2887           default: $type .= '$&#@'; break;
       
  2888         }
       
  2889         $type .= '</b>';
       
  2890         if ( $row['block_type'] == BLOCK_PLUGIN )
       
  2891         {
       
  2892           $type .= ': ' . $lang->get($row['block_content']);
       
  2893         }
       
  2894         
       
  2895         $label->assign_vars(array(
       
  2896             'TITLE' => $type
       
  2897           ));
       
  2898         echo $label->run();
       
  2899         
       
  2900         // edit
       
  2901         if ( $row['block_type'] != BLOCK_PLUGIN )
       
  2902         {
       
  2903           $button->assign_vars(array(
       
  2904               'TITLE' => $lang->get('sbedit_tip_edit'),
       
  2905               'FLAGS' => 'href="#" onclick="sbedit_open_editor(this); return false;"',
       
  2906               'IMAGE' => cdnPath . '/images/edit.png'
       
  2907             ));
       
  2908           echo $button->run();
       
  2909         }
       
  2910         
       
  2911         // delete
       
  2912         $button->assign_vars(array(
       
  2913             'TITLE' => $lang->get('sbedit_tip_delete'),
       
  2914             'FLAGS' => 'href="#" onclick="sbedit_delete_block(this); return false;"',
       
  2915             'IMAGE' => cdnPath . '/images/delete.png'
       
  2916           ));
       
  2917         echo $button->run();
       
  2918         
       
  2919         // rename
       
  2920         $button->assign_vars(array(
       
  2921             'TITLE' => $lang->get('sbedit_tip_rename'),
       
  2922             'FLAGS' => 'href="#" onclick="sbedit_rename_block(this); return false;"',
       
  2923             'IMAGE' => cdnPath . '/images/rename.png'
       
  2924           ));
       
  2925         echo $button->run();
       
  2926         
       
  2927         // disenable
       
  2928         $button->assign_vars(array(
       
  2929             'TITLE' => $lang->get('sbedit_tip_disenable'),
       
  2930             'FLAGS' => 'href="#" onclick="sbedit_disenable_block(this); return false;"',
       
  2931             'IMAGE' => cdnPath . '/images/disenable.png'
       
  2932           ));
       
  2933         echo $button->run();
       
  2934         
       
  2935         $parser_end = $template->makeParserText($toolbarvars['toolbar_vert_end']);
       
  2936         echo $parser_end->run();
       
  2937         ?>
       
  2938       </div>
       
  2939       <?php
       
  2940       echo '</div>';
       
  2941     }
       
  2942     
       
  2943     if ( !$switched_to_right )
       
  2944       echo '</td><td class="sbedit-column">';
       
  2945     
       
  2946     echo '</td></tr></table>';
  2969   }
  2947   }
  2970   
  2948   
  2971   $template->footer();
  2949   $template->footer();
  2972 }
  2950 }
  2973 
  2951