Dotclear

Changeset 1070:64699c5b7cc9 for admin


Ignore:
Timestamp:
12/17/12 00:15:04 (13 years ago)
Author:
JcDenis
Branch:
twig
Message:
  • First draft for the use of Twig on plugins
  • aboutConfig is now "Twig compliant"
File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin/plugin.php

    r500 r1070  
    1515dcPage::check('usage,contentadmin'); 
    1616 
     17//* TODO: Do it better later, required by some javascripts 
     18$some_globals = array( 
     19     'rtl' => l10n::getTextDirection($_lang) == 'rtl', 
     20     'Nonce' => $core->getNonce(), 
     21     'sess_id' => session_id(), 
     22     'sess_uid' => $_SESSION['sess_browser_uid'], 
     23     'media_manage' => $core->auth->check('media,media_admin',$core->blog->id), 
     24     'enable_wysiwyg' => isset($core->auth) && $core->auth->getOption('enable_wysiwyg'), 
     25     'edit_size' => $core->auth->getOption('edit_size') 
     26); 
     27foreach($some_globals as $name => $value) { 
     28     $_ctx->$name = $value; 
     29}; 
     30//*/ 
     31 
     32$has_content = false; 
    1733$p_file = ''; 
    1834$p = !empty($_REQUEST['p']) ? $_REQUEST['p'] : null; 
    19 $popup = (integer) !empty($_REQUEST['popup']); 
    20  
    21 if ($popup) { 
    22      $open_f = array('dcPage','openPopup'); 
    23      $close_f = array('dcPage','closePopup'); 
    24 } else { 
    25      $open_f = array('dcPage','open'); 
    26      $close_f = array('dcPage','close'); 
    27 } 
     35$popup = $_ctx->popup = (integer) !empty($_REQUEST['popup']); 
    2836 
    2937if ($core->plugins->moduleExists($p)) { 
    3038     $p_file = $core->plugins->moduleRoot($p).'/index.php'; 
    3139} 
     40if (file_exists($p_file)) { 
    3241 
    33 if (file_exists($p_file)) 
    34 { 
    35      # Loading plugin 
     42//* Keep this for old style plugins using dcPage 
     43     if ($popup) { 
     44          $open_f = array('dcPage','openPopup'); 
     45          $close_f = array('dcPage','closePopup'); 
     46     } else { 
     47          $open_f = array('dcPage','open'); 
     48          $close_f = array('dcPage','close'); 
     49     } 
     50      
    3651     $p_info = $core->plugins->getModules($p); 
    37       
    3852     $p_url = 'plugin.php?p='.$p; 
    39       
    40      $p_title = 'no content - plugin'; 
    41      $p_head = ''; 
    42      $p_content = '<p>'.__('No content found on this plugin.').'</p>'; 
    43       
     53     $p_title = $p_head = $p_content = ''; 
     54//*/  
     55     # Get page content 
    4456     ob_start(); 
    4557     include $p_file; 
    4658     $res = ob_get_contents(); 
    4759     ob_end_clean(); 
    48       
    49      if (preg_match('|<head>(.*?)</head|ms',$res,$m)) { 
    50           if (preg_match('|<title>(.*?)</title>|ms',$m[1],$mt)) { 
    51                $p_title = $mt[1]; 
    52           } 
     60 
     61//* Keep this for old style plugins using dcPage 
     62     if (!$_ctx->hasPageTitle()) { 
    5363           
    54           if (preg_match_all('|(<script.*?>.*?</script>)|ms',$m[1],$ms)) { 
    55                foreach ($ms[1] as $v) { 
    56                     $p_head .= $v."\n"; 
     64          if (preg_match('|<head>(.*?)</head|ms',$res,$m)) { 
     65               if (preg_match('|<title>(.*?)</title>|ms',$m[1],$mt)) { 
     66                    $p_title = $mt[1]; 
     67               } 
     68                
     69               if (preg_match_all('|(<script.*?>.*?</script>)|ms',$m[1],$ms)) { 
     70                    foreach ($ms[1] as $v) { 
     71                         $p_head .= $v."\n"; 
     72                    } 
     73               } 
     74                
     75               if (preg_match_all('|(<style.*?>.*?</style>)|ms',$m[1],$ms)) { 
     76                    foreach ($ms[1] as $v) { 
     77                         $p_head .= $v."\n"; 
     78                    } 
     79               } 
     80                
     81               if (preg_match_all('|(<link.*?/>)|ms',$m[1],$ms)) { 
     82                    foreach ($ms[1] as $v) { 
     83                         $p_head .= $v."\n"; 
     84                    } 
    5785               } 
    5886          } 
    5987           
    60           if (preg_match_all('|(<style.*?>.*?</style>)|ms',$m[1],$ms)) { 
    61                foreach ($ms[1] as $v) { 
    62                     $p_head .= $v."\n"; 
    63                } 
    64           } 
    65            
    66           if (preg_match_all('|(<link.*?/>)|ms',$m[1],$ms)) { 
    67                foreach ($ms[1] as $v) { 
    68                     $p_head .= $v."\n"; 
    69                } 
     88          if (preg_match('|<body.*?>(.+)</body>|ms',$res,$m)) { 
     89               $p_content = $m[1]; 
     90                
     91               call_user_func($open_f,$p_title,$p_head); 
     92               echo $p_content; 
     93               call_user_func($close_f); 
     94                
     95               $has_content = true; 
    7096          } 
    7197     } 
    72       
    73      if (preg_match('|<body.*?>(.+)</body>|ms',$res,$m)) { 
    74           $p_content = $m[1]; 
     98//*/ 
     99     # Check context and display 
     100     if ($_ctx->hasPageTitle() && !empty($res)) { 
     101          $has_content = true; 
     102          echo $res; 
    75103     } 
    76       
    77      call_user_func($open_f,$p_title,$p_head); 
    78      echo $p_content; 
    79      call_user_func($close_f); 
    80104} 
    81 else 
    82 { 
    83      call_user_func($open_f,__('Plugin not found')); 
    84       
    85      echo '<h2 class="page-title">'.__('Plugin not found').'</h2>'; 
    86       
    87      echo '<p>'.__('The plugin you reached does not exist or does not have an admin page.').'</p>'; 
    88       
    89      call_user_func($close_f); 
     105# No plugin or content found 
     106if (!$has_content) { 
     107     $_ctx->setPageTitle(__('Plugin not found')); 
     108     $_ctx->addError(__('The plugin you reached does not exist or does not have an admin page.')); 
     109     $core->tpl->display('plugin.html.twig'); 
    90110} 
    91111?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map