Dotclear

source: admin/plugin.php @ 1074:57967b687622

Revision 1074:57967b687622, 2.9 KB checked in by JcDenis, 13 years ago (diff)
  • dcPage::open and dcPage::close now use template
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     # Check context and display
62     if ($_ctx->hasPageTitle() && !empty($res)) {
63          $has_content = true;
64          echo $res;
65     }
66//* Keep this for old style plugins using dcPage
67     elseif (!$_ctx->hasPageTitle()) {
68         
69          if (preg_match('|<head>(.*?)</head|ms',$res,$m)) {
70               if (preg_match('|<title>(.*?)</title>|ms',$m[1],$mt)) {
71                    $p_title = $mt[1];
72               }
73               
74               if (preg_match_all('|(<script.*?>.*?</script>)|ms',$m[1],$ms)) {
75                    foreach ($ms[1] as $v) {
76                         $p_head .= $v."\n";
77                    }
78               }
79               
80               if (preg_match_all('|(<style.*?>.*?</style>)|ms',$m[1],$ms)) {
81                    foreach ($ms[1] as $v) {
82                         $p_head .= $v."\n";
83                    }
84               }
85               
86               if (preg_match_all('|(<link.*?/>)|ms',$m[1],$ms)) {
87                    foreach ($ms[1] as $v) {
88                         $p_head .= $v."\n";
89                    }
90               }
91          }
92         
93          if (preg_match('|<body.*?>(.+)</body>|ms',$res,$m)) {
94               $p_content = $m[1];
95               
96               call_user_func($open_f,$p_title,$p_head);
97               echo $p_content;
98               call_user_func($close_f);
99               
100               $has_content = true;
101          }
102     }
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