Dotclear

source: admin/plugin.php @ 1070:64699c5b7cc9

Revision 1070:64699c5b7cc9, 2.8 KB checked in by JcDenis, 13 years ago (diff)
  • First draft for the use of Twig on plugins
  • aboutConfig is now "Twig compliant"
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::check('usage,contentadmin');
16
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;
33$p_file = '';
34$p = !empty($_REQUEST['p']) ? $_REQUEST['p'] : null;
35$popup = $_ctx->popup = (integer) !empty($_REQUEST['popup']);
36
37if ($core->plugins->moduleExists($p)) {
38     $p_file = $core->plugins->moduleRoot($p).'/index.php';
39}
40if (file_exists($p_file)) {
41
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     
51     $p_info = $core->plugins->getModules($p);
52     $p_url = 'plugin.php?p='.$p;
53     $p_title = $p_head = $p_content = '';
54//*/
55     # Get page content
56     ob_start();
57     include $p_file;
58     $res = ob_get_contents();
59     ob_end_clean();
60
61//* Keep this for old style plugins using dcPage
62     if (!$_ctx->hasPageTitle()) {
63         
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                    }
85               }
86          }
87         
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;
96          }
97     }
98//*/
99     # Check context and display
100     if ($_ctx->hasPageTitle() && !empty($res)) {
101          $has_content = true;
102          echo $res;
103     }
104}
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');
110}
111?>
Note: See TracBrowser for help on using the repository browser.

Sites map