[992] | 1 | <?php |
---|
[1056] | 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 | if (!defined('DC_RC_PATH')) { return; } |
---|
[992] | 13 | |
---|
[1056] | 14 | /** |
---|
[1128] | 15 | * @ingroup DC_CORE |
---|
| 16 | * @brief Template extension for admin context. |
---|
| 17 | * |
---|
| 18 | * This extends template environment with tools required in admin context. |
---|
| 19 | */ |
---|
| 20 | class dcAdminContext extends dcContext |
---|
[1056] | 21 | { |
---|
| 22 | public function __construct($core) |
---|
| 23 | { |
---|
[1128] | 24 | parent::__construct($core); |
---|
[1056] | 25 | |
---|
[1128] | 26 | $this->protected_globals = array_merge($this->protected_globals,array( |
---|
[1089] | 27 | 'page_title' => array(), |
---|
| 28 | 'page_global' => false, |
---|
[1056] | 29 | |
---|
| 30 | 'admin_url' => DC_ADMIN_URL, |
---|
| 31 | 'theme_url' => DC_ADMIN_URL.'index.php?tf=', |
---|
[1070] | 32 | 'plugin_url' => DC_ADMIN_URL.'index.php?pf=', |
---|
[1128] | 33 | )); |
---|
[992] | 34 | } |
---|
| 35 | |
---|
[1056] | 36 | /** |
---|
[1128] | 37 | * Returns a list of global variables to add to the existing list. |
---|
| 38 | * |
---|
| 39 | * This merges overloaded variables with defined variables. |
---|
| 40 | * |
---|
| 41 | * @return array An array of global variables |
---|
| 42 | */ |
---|
[1056] | 43 | public function getGlobals() |
---|
| 44 | { |
---|
[1060] | 45 | $this->getBlogs(); |
---|
| 46 | $this->getCurrentBlog(); |
---|
| 47 | $this->getCurrentUser(); |
---|
[1064] | 48 | $this->getMenus(); |
---|
[1060] | 49 | |
---|
| 50 | # Additional globals |
---|
| 51 | $p = path::info($_SERVER['REQUEST_URI']); |
---|
| 52 | $this->protected_globals['current_page'] = $p['base']; |
---|
| 53 | $this->protected_globals['blog_count'] = $this->core->auth->blog_count; |
---|
[1088] | 54 | $this->protected_globals['rtl'] = l10n::getTextDirection( |
---|
| 55 | $this->protected_globals['current_user']['lang']) == 'rtl'; |
---|
| 56 | $this->protected_globals['session'] = array( |
---|
| 57 | 'id' => session_id(), |
---|
| 58 | 'uid' => isset($_SESSION['sess_browser_uid']) ? $_SESSION['sess_browser_uid'] : '', |
---|
| 59 | 'nonce' => $this->core->getNonce() |
---|
| 60 | ); |
---|
[1060] | 61 | |
---|
[1056] | 62 | # Keep protected globals safe |
---|
| 63 | return array_merge($this->globals,$this->protected_globals); |
---|
| 64 | } |
---|
| 65 | |
---|
[1089] | 66 | /** |
---|
[1128] | 67 | * Fill the page title. |
---|
| 68 | * |
---|
| 69 | * $title can be: |
---|
| 70 | * - a string for page title part or |
---|
| 71 | * - TRUE to add blog name at the begining of title or |
---|
| 72 | * - NULL to empty/reset title |
---|
| 73 | * |
---|
| 74 | * @param mixed $title A title part |
---|
| 75 | * @param boolean $url Link of the title part |
---|
| 76 | * @return object self |
---|
| 77 | */ |
---|
[1089] | 78 | public function fillPageTitle($title,$url='') |
---|
[992] | 79 | { |
---|
[1089] | 80 | if (is_bool($title)) { |
---|
| 81 | $this->protected_globals['page_global'] = $title; |
---|
| 82 | } |
---|
| 83 | elseif (null === $title) { |
---|
| 84 | $this->protected_globals['page_global'] = false; |
---|
| 85 | $this->protected_globals['page_title'] = array(); |
---|
| 86 | } |
---|
| 87 | else { |
---|
| 88 | $this->protected_globals['page_title'][] = array( |
---|
| 89 | 'title' => $title, |
---|
| 90 | 'link' => $url |
---|
| 91 | ); |
---|
| 92 | } |
---|
| 93 | return $this; |
---|
[992] | 94 | } |
---|
| 95 | |
---|
[1056] | 96 | /** |
---|
[1128] | 97 | * Check if a page title is set |
---|
| 98 | */ |
---|
[1070] | 99 | public function hasPageTitle() |
---|
| 100 | { |
---|
| 101 | return !empty($this->protected_globals['page_title']); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | /** |
---|
[1128] | 105 | * Get list of blogs |
---|
| 106 | */ |
---|
[1060] | 107 | protected function getBlogs() |
---|
| 108 | { |
---|
[1061] | 109 | $blog_id = ''; |
---|
| 110 | |
---|
[1060] | 111 | # Blogs list |
---|
| 112 | $blogs = array(); |
---|
| 113 | if ($this->core->auth->blog_count > 1 && $this->core->auth->blog_count < 20) { |
---|
[1061] | 114 | $blog_id = $this->core->blog->id; |
---|
[1060] | 115 | $rs_blogs = $this->core->getBlogs(array('order'=>'LOWER(blog_name)','limit'=>20)); |
---|
| 116 | while ($rs_blogs->fetch()) { |
---|
| 117 | $blogs[$rs_blogs->blog_id] = $rs_blogs->blog_name.' - '.$rs_blogs->blog_url; |
---|
| 118 | $this->protected_globals['blogs'][$rs_blogs->blog_id] = array( |
---|
| 119 | 'id' => $rs_blogs->blog_id, |
---|
| 120 | 'name' => $rs_blogs->blog_name, |
---|
| 121 | 'desc' => $rs_blogs->blog_desc, |
---|
| 122 | 'url' => $rs_blogs->blog_url, |
---|
| 123 | 'creadt' => $rs_blogs->blog_creadt, |
---|
| 124 | 'upddt' => $rs_blogs->blog_upddt |
---|
| 125 | ); |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | # Switch blog form |
---|
| 130 | $form = new dcForm($this->core,'switchblog_menu','index.php'); |
---|
| 131 | $form |
---|
| 132 | ->addField( |
---|
[1061] | 133 | new dcFieldCombo('switchblog',$blog_id,$blogs,array( |
---|
[1060] | 134 | 'label' => __('Blogs:')))) |
---|
| 135 | ->addField( |
---|
| 136 | new dcFieldSubmit('switchblog_submit',__('ok'),array( |
---|
| 137 | 'action' => 'switchblog'))) |
---|
| 138 | ->setup(); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | /** |
---|
[1128] | 142 | * Get current blog information |
---|
| 143 | */ |
---|
[1060] | 144 | protected function getCurrentBlog() |
---|
| 145 | { |
---|
| 146 | $this->protected_globals['current_blog'] = $this->core->auth->blog_count ? |
---|
| 147 | array( |
---|
| 148 | 'id' => $this->core->blog->id, |
---|
| 149 | 'name' => $this->core->blog->name, |
---|
| 150 | 'desc' => $this->core->blog->desc, |
---|
| 151 | 'url' => $this->core->blog->url, |
---|
| 152 | 'host' => $this->core->blog->host, |
---|
| 153 | 'creadt' => $this->core->blog->creadt, |
---|
| 154 | 'upddt' => $this->core->blog->upddt |
---|
| 155 | ) : array( |
---|
| 156 | 'id' => '', |
---|
| 157 | 'name' => '', |
---|
| 158 | 'desc' => '', |
---|
| 159 | 'url' => '', |
---|
| 160 | 'host' => '', |
---|
| 161 | 'creadt' => '', |
---|
| 162 | 'upddt' => '' |
---|
| 163 | ); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | /** |
---|
[1128] | 167 | * Get current user information |
---|
| 168 | */ |
---|
[1060] | 169 | protected function getCurrentUser() |
---|
| 170 | { |
---|
[1087] | 171 | $infos = array( |
---|
| 172 | 'pwd','name','firstname','displayname', |
---|
| 173 | 'email','url','default_blog','lang','tz', |
---|
| 174 | 'post_status','creadt','upddt','cn' |
---|
| 175 | ); |
---|
| 176 | |
---|
| 177 | $user = array( |
---|
| 178 | 'id' => '', |
---|
| 179 | 'super' => false, |
---|
[1088] | 180 | 'lang' => 'en', |
---|
| 181 | 'options' => $this->core->userDefaults(), |
---|
| 182 | 'prefs' => array(), |
---|
| 183 | 'rights' => array( |
---|
| 184 | 'media' => false |
---|
| 185 | ) |
---|
[1087] | 186 | ); |
---|
| 187 | |
---|
| 188 | foreach($infos as $i) { |
---|
| 189 | $user[$i] = ''; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | if ($this->core->auth->userID()) { |
---|
| 193 | |
---|
| 194 | $user = array( |
---|
| 195 | 'id' => $this->core->auth->userID(), |
---|
| 196 | 'super' => $this->core->auth->isSuperAdmin(), |
---|
[1088] | 197 | 'options' => $this->core->auth->getOptions(), |
---|
| 198 | 'rights' => array( |
---|
| 199 | 'media' => $this->core->auth->check('media,media_admin',$this->core->blog->id) |
---|
| 200 | ) |
---|
[1060] | 201 | ); |
---|
[1087] | 202 | |
---|
| 203 | foreach($infos as $i) { |
---|
| 204 | $user[$i] = $this->core->auth->getInfo('user_'.$i); |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | foreach($this->core->auth->user_prefs->dumpWorkspaces() as $ws => $prefs) { |
---|
| 208 | $user['prefs'][$ws] = $prefs->dumpPrefs(); |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | $this->protected_globals['current_user'] = $user; |
---|
[1060] | 213 | } |
---|
[1064] | 214 | |
---|
[1089] | 215 | /** |
---|
[1128] | 216 | * Get sidebar menus |
---|
| 217 | */ |
---|
[1064] | 218 | protected function getMenus() |
---|
| 219 | { |
---|
| 220 | global $_menu; |
---|
| 221 | |
---|
| 222 | $this->protected_globals['menus'] = array(); |
---|
| 223 | |
---|
| 224 | if (!isset($_menu)) { |
---|
| 225 | return; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | foreach($_menu as $m) { |
---|
| 229 | $this->protected_globals['menus'][] = array( |
---|
| 230 | 'id' => $m->getID(), |
---|
| 231 | 'title' => $m->getTitle(), |
---|
| 232 | 'separator' => $m->getSeparator(), |
---|
| 233 | 'items' => $m->getItems() |
---|
| 234 | ); |
---|
| 235 | } |
---|
| 236 | } |
---|
[992] | 237 | } |
---|
[1056] | 238 | ?> |
---|