Advertisement
Guest User

dsader

a guest
Feb 16th, 2010
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 54.09 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Userthemes Revisited Plugin
  4. Plugin URI: http://wpmudev.org/project/Userthemes-Revisited/
  5. Description: Allows selected MU blogs to edit their own themes. Beware allowing theme-editor.php. A zillion users copying a zillion themes to their zillion blogs.dir/id/themes folders and editing php with a zillion "lay-waste-to-the-database" commands will give you a zillion reasons to ignore this plugin.
  6. Author: D Sader
  7. Original Author: Brian Samson http://samson.blog.asu.edu/userthemes/
  8. Version: 2.9.1
  9. Author URI: http://iblog.stjschool.org
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20.  
  21. NAGGING BUGS:
  22. � While a Usertheme is active, and if no theme of the same name exists in system themes list, landing on the regular themes.php admin page unsets the usertheme and front end becomes a white page. Previewing a system theme while a usertheme is active draws a blank. Setting and usetting the theme.php menu may collide with other plugins doing the same. TODO: function userthemes() page output code is long, tedious, repetitous. TODO: at some point code was added to quickly revert to and from last active usertheme/system theme. It doesn't work as intended, yet. TODO: etc., etc.
  23.  
  24. LESSER WARNINGS:
  25. � If a usertheme is copied, but then the original is removed from the "Site Allowed"(wpmu-themes) it still lists as a System Theme on that blog.
  26.  
  27. MAJOR WARNINGS:
  28. � WPMU does not have a theme-editor.php for very good reasons. What users do you want to script php?
  29. � A tricked out, evil-code-bashing user and server friendly theme-editor.php doesn't exist.
  30. � The plugin management page has suggestiongs for hacking and limiting access to the theme-editor.php.
  31. � Do not enable the theme-editor.php for any blog if you can't hold the admins of that blog to account for deleting your entire directory/database.
  32. � If a blog is enabled to use the theme-editor, any user that is an admin of the blog can edit themes. Any blog admin can make any other user a blog admin, and so on.
  33.  
  34. MAJOR WORKAROUND:
  35. � There is no filter of the "allowed_files" in theme-editor.php.
  36. Workaround: You can edit one "allowed_files" line in theme-editor.php to limit files to just stylesheets. But this seems a giant plugin to fiddle with just the stylesheet. Beware: Stylesheets can still import php and any nasty code to take down a server. Hack away at theme=editor.php
  37. // $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
  38. $allowed_files = $themes[$theme]['Stylesheet Files'];
  39.  
  40. */
  41.  
  42. /*
  43. // for the panic button
  44. if (strpos($_SERVER['REQUEST_URI'], 'theme-editor.php') )
  45. add_action('admin_head', 'ds_redirect_theme_editor');
  46. function ds_redirect_theme_editor() {
  47. if (
  48. (get_option('ut_use_user_theme') != 1) || // toggled by User when activating a usertheme
  49. (get_option('ut_enabled') != 1) // toggled by SiteAdmin at Userthemes Management page
  50. )
  51.  
  52. if(file_exists('js/revisions-js.php')) {
  53. include('js/revisions-js.php'); // wpmu2.6 easter egg, I couldn't resist
  54. } else {
  55. wp_die('The SiteAdmin does not want you to see this page.');
  56. }
  57. return;
  58. }
  59.  
  60. */
  61.  
  62. class DS_User_Themes {
  63.  
  64. var $userThemes;
  65. var $systemThemes;
  66. var $adminOptionsName = "DS_User_Themes_Options";
  67.  
  68. function DS_User_Themes() { // constructor
  69.  
  70. }
  71. function ds_ut_theme_preview_scripts() {
  72.  
  73. add_thickbox();
  74. wp_enqueue_script( 'theme-preview' );
  75. }
  76. function ds_ut_hide_original_themes_php() {
  77. global $submenu;
  78. if(!empty($submenu['themes.php'])) {
  79. foreach($submenu['themes.php'] as $key => $sm) {
  80. if(__($sm[0]) == "Themes" || $sm[2] == "themes.php") {
  81. unset($submenu['themes.php'][$key]);
  82. break;
  83. }
  84. }
  85. }
  86. }
  87.  
  88. //The theme root needs to be filtered here
  89. function theme_root_filter($root) {
  90. if (get_option('ut_use_user_theme') == 1) {
  91. $path = DS_UT_USERTHEMES_DIR;
  92. return $path;
  93. }
  94. return $root;
  95. }
  96.  
  97. function theme_root_uri_filter($root) {
  98. if (get_option('ut_use_user_theme') == 1) {
  99. $uri = DS_UT_USERTHEMES_URL;
  100. return $uri;
  101. }
  102. return $root;
  103. }
  104.  
  105. function admin_menu_pages() {
  106. //Enable the out-of the box(WP) theme editor to be added to the menu.
  107. if (get_option('ut_enabled') == 1 ) {
  108. global $menu;
  109.  
  110. $page = add_theme_page('Userthemes', 'Userthemes', 10, 'userthemes', array(&$this, 'userthemes'));
  111. $help = '<p>' . __('Themes give your WordPress style. Once a theme is installed, you may preview it, activate it or deactivate it here.') . '</p>';
  112. if ( is_site_admin() ) {
  113. $help .= '<p>' . sprintf(__('You can find additional themes for your site by using the new <a href="%1$s">Theme Browser/Installer</a> functionality or by browsing the <a href="http://wordpress.org/extend/themes/">WordPress Theme Directory</a> directly and installing manually. To install a theme <em>manually</em>, <a href="%2$s">upload its ZIP archive with the new uploader</a> or copy its folder via FTP into your <code>wp-content/themes</code> directory.'), 'theme-install.php', 'theme-install.php?tab=upload' ) . '</p>';
  114. $help .= '<p>' . __('Once a theme is uploaded, you should see it on this page.') . '</p>';
  115. }
  116. $help .= '<p>' . __('You can\'t edit System Themes, you must copy that theme to your Userthemes area first. You need to click the Activate link of a Usertheme before the you can use or edit any of your custom themes.') . '</p>';
  117.  
  118.  
  119. add_contextual_help($page, $help);
  120. // add_submenu_page('options-general.php', 'Userthemes', 'Userthemes', 10, 'userthemes', array(&$this, 'userthemes'));
  121.  
  122. //Only show the usertheme editor menu when usertheme is active, permission granted, and theme-editor.php exists, and user can edit themes
  123. if (
  124. (get_option('ut_use_user_theme') == 1) &&
  125. (get_option('ut_enabled') == 1 ) &&
  126. file_exists(ABSPATH.'wp-admin/theme-editor.php') &&
  127. (current_user_can('edit_themes'))
  128. )
  129. add_theme_page('Edit Userthemes', 'Edit Userthemes', 10, 'theme-editor.php');
  130.  
  131. }
  132. //Add the site-wide administrator menu
  133. if (is_site_admin()) {
  134. add_submenu_page('wpmu-admin.php', 'Usertheme Management', 'Userthemes Management', 10, 'management_page', array(&$this, 'management_page'));
  135. }
  136. }
  137.  
  138. function flip_mode() {
  139. $this->get_all_themes;
  140. unset($GLOBAL['wp_templates']);
  141. if (get_option('ut_use_user_theme') == 1) {
  142. //Go back to system theme set
  143. $this->backup_user_theme();
  144. $this->restore_system_theme();
  145. update_option('ut_use_user_theme', 0);
  146. $message = "Flipping Back to System Mode: ";
  147. } else {
  148. if (count($this->userThemes) == 0) {
  149. $message = "error=true";
  150. } else {
  151. $this->backup_system_theme();
  152. $this->restore_user_theme();
  153. if (!array_search(get_current_theme(), $this->userThemes)) {
  154. $keys = array_keys($this->userThemes);
  155. update_option('template', $this->userThemes[$keys[0]]['Template']);
  156. update_option('stylesheet', $this->userThemes[$keys[0]]['Stylesheet']);
  157. update_option('current_theme', $this->userThemes[$keys[0]]['Name']);
  158. }
  159. update_option('ut_use_user_theme', 1);
  160. $message = "Flipping to Usertheme Mode: ";
  161. }
  162. }
  163. return $message;
  164. }
  165. function restore_system_theme() {
  166. update_option('template', get_option('ut_backup_template'));
  167. update_option('stylesheet', get_option('ut_backup_stylesheet'));
  168. update_option('current_theme', get_option('ut_backup_name'));
  169.  
  170. }
  171. function backup_system_theme() {
  172. update_option('ut_backup_template', get_option('template'));
  173. update_option('ut_backup_stylesheet', get_option('stylesheet'));
  174. update_option('ut_backup_name', get_option('current_theme'));
  175. }
  176. function restore_user_theme() {
  177. update_option('template', get_option('ut_backup_user_template'));
  178. update_option('stylesheet', get_option('ut_backup_user_stylesheet'));
  179. update_option('current_theme', get_option('ut_backup_user_name'));
  180.  
  181. }
  182. function backup_user_theme() {
  183. update_option('ut_backup_user_template', get_option('template'));
  184. update_option('ut_backup_user_stylesheet', get_option('stylesheet'));
  185. update_option('ut_backup_user_name', get_option('current_theme'));
  186. }
  187.  
  188. function userthemes() {
  189.  
  190. $ds_Options = $this->getAdminOptions();
  191. if( is_site_admin() ) {
  192. ?><div id="message0" class="updated fade"><p><?php _e('Administrator: new themes must be activated in the <a href="wpmu-themes.php">Themes Admin</a> page before they appear here.'); ?></p></div><?php
  193. }
  194. if ( ! validate_current_theme() ) : ?>
  195. <div id="message1" class="updated fade"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
  196. <?php endif;
  197.  
  198. $this->get_all_themes();
  199. $utpage = $_GET['page'];
  200.  
  201. switch ($_GET['action']) {
  202. //Important TODO: make sure to strip ..'s and such
  203.  
  204. case 'edit':
  205. check_admin_referer('edit-theme_' . $_GET['theme']);
  206. // theme-editor.php checks the user cap for 'edit_themes'
  207. if (
  208. get_option('ut_use_user_theme') == 1 &&
  209. get_option('ut_enabled') == 1 &&
  210. current_user_can('edit_themes')
  211. ) {
  212. if (get_option('ut_use_user_theme') != 1)
  213. $this->flip_mode();
  214. $location = "theme-editor.php?theme={$_GET['theme']}";
  215. echo "<meta http-equiv='refresh' content='0;url=$location' />";
  216. exit;
  217. }
  218. break;
  219.  
  220. case 'copy':
  221. check_admin_referer('copy-theme_' . $_GET['theme']);
  222. $copyTheme = $_GET['theme'];
  223. if (!isset($copyTheme)) {
  224. $message = "Error: No theme selected";
  225. return;
  226. }
  227. if (count($this->userThemes) < $ds_Options['ut_max_copy']) {
  228. $dest = DS_UT_USERTHEMES_DIR . '/' . $copyTheme ;
  229. while (file_exists($dest . $suffix))
  230. $suffix = $suffix + 1;
  231. mkdir($dest . $suffix, 0755, true);
  232. $src = DS_UT_SYSTEM_THEMES_DIR . '/' . $copyTheme;
  233.  
  234. exec("/bin/cp -R $src/* $dest$suffix");
  235. exec("/bin/chmod -R 755 $dest$suffic");
  236.  
  237. if (count($this->userThemes) == 1) {
  238. //This is the first theme, so prepare the db for the switch
  239. $keys = @array_keys($this->userThemes); //still may thow an error on first theme if no @
  240. update_option('ut_backup_user_template', $this->userThemes[$keys[0]]['Template']);
  241. update_option('ut_backup_user_stylesheet', $this->userThemes[$keys[0]]['Stylesheet']);
  242. update_option('ut_backup_user_name', $this->userThemes[$keys[0]]['Name']);
  243. }
  244. $message = "System Theme copied to Userthemes.";
  245. } else {
  246. $message = $ds_Options['ut_max_copy']." userthemes is max. Delete userthemes before trying to copy.";
  247. }
  248. break;
  249.  
  250. case 'delete':
  251. check_admin_referer('delete-theme_' . $_GET['theme']);
  252. if ( !current_user_can('edit_themes') )
  253. wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
  254.  
  255. $delTheme = $_GET['theme'];
  256. if (!isset($delTheme)) {
  257. $message = "Error: No theme selected";
  258. return;
  259. }
  260. // this is the kind of stuff an end user could put into a template via theme editor YIKES!!
  261. $goner = DS_UT_USERTHEMES_DIR . '/' . $delTheme ;
  262. exec("/bin/rm -rf $goner");
  263.  
  264. if (count($this->userThemes) <= 1) { // TODO restores to the last system theme when no more userthemes
  265. $this->restore_system_theme();
  266. update_option('ut_use_user_theme', 0);
  267. }
  268. $message = "Usertheme deleted.";
  269.  
  270. break;
  271.  
  272. case 'activate':
  273. check_admin_referer('switch-theme_' . $_GET['theme']);
  274.  
  275. $mode = trim($_GET['mode']);
  276.  
  277. if ($mode == 'user') {
  278. $message = "Usertheme Mode: ";
  279. $theme = $this->userThemes[$_GET['theme']];
  280. if ( get_option('ut_use_user_theme') != 1 )
  281. $flip = true;
  282. }
  283. if ($mode == 'system') {
  284. $message = "System Mode: ";
  285. $theme = $this->systemThemes[$_GET['theme']];
  286. if ( get_option('ut_use_user_theme') == 1 )
  287. $flip = true;
  288. }
  289. if (!isset($theme)) {
  290. $message = "Error: invalid theme";
  291. break;
  292. }
  293. if ($flip)
  294. $message = $this->flip_mode();
  295. update_option('current_theme', $theme['Name']);
  296. update_option('template', $theme['Template']);
  297. update_option('stylesheet', $theme['Stylesheet']);
  298. $message = $message . " {$theme['Name']} theme acitvated. <a style='font-style: italic; font-size: .8em' href='".get_settings('siteurl')."'>(view site)</a>";
  299. break;
  300.  
  301. case 'default':
  302. check_admin_referer('default-theme_default');
  303. update_option('ut_use_user_theme', 0);
  304. switch_theme('default', 'default');
  305. $message = 'Default theme activated. <a href="'.get_bloginfo('url') . '">Visit site</a>';
  306. break;
  307. }
  308.  
  309. $this->get_all_themes();
  310. $ct = current_theme_info();
  311.  
  312. if (!isset($message)) $message = $_GET['message'];
  313.  
  314. if (isset($message)) {
  315. if (strstr($message, "Error:"))
  316. $bgcolor = '#880000';
  317. else
  318. $bgcolor = '#c0c0c0';
  319. echo "<div id='message' class='updated fade' style='background-color: $bgcolor'>
  320. <p>$message</p>
  321. </div>";
  322. }
  323. ?>
  324. <div class='wrap'>
  325. <h3>Current <?php if (get_option('ut_use_user_theme') == 1 )
  326. echo "Usertheme";
  327. else
  328. echo "System Theme"; ?></h3>
  329. <div id="current-theme">
  330. <?php if ( $ct->screenshot ) : ?>
  331. <img src="<?php echo $ct->theme_root_uri . '/' . $ct->stylesheet . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" />
  332. <?php endif; ?>
  333. <h4><?php printf(_c('%1$s %2$s by %3$s|1: theme title, 2: theme version, 3: theme author'), $ct->title, $ct->version, $ct->author) ; ?></h4>
  334. <p class="description"><?php echo $ct->description; ?></p>
  335. <?php if( is_site_admin() ) { if ($ct->parent_theme) { ?>
  336. <p><?php printf(__('The template files are located in <code>%2$s</code>. The stylesheet files are located in <code>%3$s</code>. <strong>%4$s</strong> uses templates from <strong>%5$s</strong>. Changes made to the templates will affect both themes.'), $ct->title, $ct->template_dir, $ct->stylesheet_dir, $ct->title, $ct->parent_theme); ?></p>
  337. <?php } else { ?>
  338. <p><?php printf(__('All of this theme&#8217;s files are located in <code>%2$s</code>.'), $ct->title, $ct->template_dir, $ct->stylesheet_dir); ?></p>
  339. <?php } } // site admin
  340. ?>
  341. <?php
  342. if ( $ct->tags ) :
  343. echo '<p>'. __('Tags: | ');
  344. foreach ($ct->tags as $tag) {
  345. $tag_link = add_query_arg('tag', $tag, $_SERVER['REQUEST_URI'] );
  346. echo '<a href="'.$tag_link.'">'.$tag.'</a> | ';
  347. }
  348. echo '</p>';
  349. endif;
  350. echo "<p>The currently active theme is <b>$ct->title</b> ";
  351. if (get_option('ut_use_user_theme') == 1 )
  352. { echo "from the <b>Userthemes</b> library.</p>"; }
  353. else
  354. { echo "from the <b>System Themes</b> library.</p>";
  355.  
  356. $this->theme_update_available($ct); }
  357.  
  358.  
  359.  
  360. ?>
  361. </div>
  362. <div class='clear'></div>
  363. <?php
  364. if (empty($this->userThemes)) {
  365. echo "<h3>No Userthemes</h3>";
  366. } else {
  367. ?>
  368. <h3><?php echo count($this->userThemes) . ' Userthemes '; if (count($this->userThemes) >= $ds_Options['ut_max_copy']) { echo '(MAX)';
  369. } ?></h3>
  370. <table class="widefat">
  371. <thead>
  372. <tr>
  373. <th>Theme</th>
  374. <th>Description</th>
  375. <th>Version</th>
  376. <th>Author</th>
  377. <th>Action</th>
  378.  
  379. </tr>
  380. </thead>
  381. <tbody id='the-list-x' width='auto'>
  382. <?php
  383. $theme_names = array_keys($this->userThemes);
  384.  
  385. uksort( $theme_names, "strnatcasecmp" );
  386.  
  387. $default_link = wp_nonce_url("?page=$utpage&amp;action=default&amp;theme=default", 'default-theme_default');
  388.  
  389. foreach ($theme_names as $theme_name) {
  390. $template = $this->userThemes[$theme_name]['Template'];
  391. $stylesheet = $this->userThemes[$theme_name]['Stylesheet'];
  392. $name = $this->userThemes[$theme_name]['Name'];
  393. $title = $this->userThemes[$theme_name]['Title'];
  394. $version = $this->userThemes[$theme_name]['Version'];
  395. $description = $this->userThemes[$theme_name]['Description'];
  396. $author = $this->userThemes[$theme_name]['Author'];
  397. $screenshot = $this->userThemes[$theme_name]['Screenshot'];
  398. $stylesheet_dir = $this->userThemes[$theme_name]['Stylesheet Dir'];
  399. $template_dir = $this->userThemes[$theme_name]['Template Dir'];
  400. $parent_theme = $this->userThemes[$theme_name]['Parent Theme'];
  401.  
  402. // $theme_root = $this->userThemes[$theme_name]['Theme Root'];
  403. // $theme_root_uri = $this->userThemes[$theme_name]['Theme Root URI'];
  404.  
  405. $preview_link = esc_url(get_option('home') . '/');
  406. if ( is_ssl() )
  407. $preview_link = str_replace( 'http://', 'https://', $preview_link );
  408. $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
  409. $preview_text = esc_attr( sprintf( __('Preview of &#8220;%s&#8221;'), $title ) );
  410. $tags = $this->userThemes[$theme_name]['Tags'];
  411. $thickbox_class = 'thickbox thickbox-preview';
  412. $activate_link = wp_nonce_url("?page=$utpage&amp;action=activate&amp;mode=user&amp;theme=".urlencode($name)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $name);
  413. $activate_text = esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $title ) );
  414. $edit_link = wp_nonce_url("?page=$utpage&amp;action=edit&amp;theme=".urlencode($name)."&amp;stylesheet=".urlencode($stylesheet), 'edit-theme_' . $name);
  415. $edit_text = esc_attr( sprintf( __('Edit &#8220;%s&#8221;'), $title ) );
  416.  
  417. $delete_link = wp_nonce_url("?page=$utpage&amp;action=delete&amp;theme=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'delete-theme_' . $template);
  418. $delete_text = esc_attr( sprintf( __('Delete &#8220;%s&#8221;'), $title ) );
  419.  
  420. $actions = array();
  421. if ($ct->stylesheet != $stylesheet)
  422. $actions[] = '<a href="' . $activate_link . '" class="activatelink" title="' . $activate_text . '">' . __('Activate') . '</a>';
  423. $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $theme_name)) . '">' . __('Preview') . '</a>';
  424. if (
  425. (get_option('ut_use_user_theme') == 1) &&
  426. (get_option('ut_enabled') == 1 ) &&
  427. (current_user_can('edit_themes'))
  428. )
  429. $actions[] = '<a href="' . $edit_link . '" class="activatelink" title="' . $edit_text . '">' . __('Edit') . '</a>';
  430.  
  431.  
  432. if ( $ct->stylesheet_dir == $stylesheet_dir ) {
  433. $actions[] = '<a href="' . $default_link . '" class="activatelink" title="Do not delete an active theme">' . __('Deactivate') . '</a>';
  434. } elseif ( current_user_can('edit_themes') )
  435. {
  436. $actions[] = '<a href="' . $delete_link . '" class="activatelink" title="' . $delete_text . '">' . __('Delete') . '</a>';
  437. }
  438.  
  439. // $actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);
  440.  
  441. $actions = implode ( '&nbsp;|&nbsp;', $actions );
  442.  
  443.  
  444. $alt = $alt == '' ? 'alternate' : '';
  445. ?>
  446. <tr class='<?php echo $alt; ?>'>
  447. <td><a class="<?php echo $thickbox_class; ?>" href="<?php echo $preview_link; ?>" title="<?php echo $preview_text; ?>" onMouseOver="preview('<?php echo WP_CONTENT_URL . $stylesheet_dir . '/' . $screenshot; ?>', getTopPosition(this));" onMouseOut="unpreview();">"<?php echo "$title"; ?>"</a></td>
  448. <td><?php echo "$description"; ?>
  449. <?php if( is_site_admin() ) { if ($parent_theme) { ?>
  450. <p><?php printf(__('The template files are located in <code>%2$s</code>. The stylesheet files are located in <code>%3$s</code>. <strong>%4$s</strong> uses templates from <strong>%5$s</strong>. Changes made to the templates will affect both themes.'), $title, $template_dir, $stylesheet_dir, $title, $parent_theme); ?></p>
  451. <?php } else { ?>
  452. <p><?php printf(__('All of this theme&#8217;s files are located in <code>%2$s</code>.'), $title, $template_dir, $stylesheet_dir); ?></p>
  453. <?php } } // site admin
  454.  
  455. if ( $tags ) :
  456. echo '<p>'. __('Tags: | ');
  457. foreach ($tags as $tag) {
  458. $uri = '?page=userthemes';
  459. $tag_link = add_query_arg('tag', $tag, $uri );
  460. echo '<a href="'.$tag_link.'">'.$tag.'</a> | ';
  461. }
  462. echo '</p>';
  463. endif;
  464. // $this->theme_update_available( $this->userThemes[$theme_name] );
  465.  
  466. ?>
  467. </td>
  468. <td><?php echo "$version"; ?></td>
  469. <td><?php echo "$author"; ?></td>
  470. <td><span class='action-links'><?php echo $actions ?></span></td>
  471. </tr>
  472. <?php } ?>
  473. </form>
  474. </tbody>
  475. </table>
  476. <br class="clear" />
  477. <?php }
  478. reset($this->systemThemes);
  479. $unfiltered_theme_total = count($this->systemThemes);
  480. //System Themes
  481. echo '<h3>' . $unfiltered_theme_total . ' System Themes</h3>';
  482.  
  483. if ($_POST['tag']) {
  484. if($_POST['tag'] == 'all') {
  485. $this->systemThemes = $this->systemThemes;
  486. } else {
  487. $showbytag = $_POST['tag'];
  488. $filltered = array();
  489. foreach ( $this->systemThemes as $id=>$t ) {
  490. if ( in_array($showbytag, $t['Tags'])) {
  491. $filltered[$id] = $t;
  492. }
  493. }
  494. $this->systemThemes = $filltered;
  495. }
  496.  
  497. }
  498. if ($_GET['tag']) {
  499. if($_GET['tag'] == 'all') {
  500. $this->systemThemes = $this->systemThemes;
  501. } else {
  502. $showbytag = $_GET['tag'];
  503. $filltered = array();
  504. foreach ( $this->systemThemes as $id=>$t ) {
  505. if ( in_array($showbytag, $t['Tags'])) {
  506. $filltered[$id] = $t;
  507. }
  508. }
  509. $this->systemThemes = $filltered;
  510. }
  511.  
  512. }
  513. $ct = current_theme_info();
  514. unset($this->systemThemes[$ct->name]);
  515.  
  516.  
  517. uksort( $this->systemThemes, "strnatcasecmp" );
  518.  
  519. $theme_total = count( $this->systemThemes );
  520. $per_page = $ds_Options['ut_themes_per_page']; // DS_UT_THEMES_PER_PAGE;
  521.  
  522. if ( isset( $_GET['pagenum'] ) )
  523. $page = absint( $_GET['pagenum'] );
  524. if ( empty($page) )
  525. $page = 1;
  526. $start = $offset = ( $page - 1 ) * $per_page;
  527. $page_links = paginate_links( array(
  528. 'base' => add_query_arg( 'pagenum', '%#%' ) . '#themenav',
  529. 'format' => '',
  530. 'prev_text' => __('&laquo;'),
  531. 'next_text' => __('&raquo;'),
  532. 'total' => ceil($theme_total / $per_page),
  533. 'current' => $page
  534. ));
  535. $altags = array();
  536. foreach ($this->systemThemes as $t){
  537. foreach ($t['Tags'] as $id =>$tag) {
  538. $altags[$tag]=(int)$altags[$tag]+1;
  539. }
  540. }
  541. arsort($altags);
  542. $this->systemThemes = array_slice( $this->systemThemes, $start, $per_page );
  543.  
  544.  
  545. ?>
  546. <form method="POST" action="?page=userthemes">
  547. <div class="tablenav">
  548. <span class="aligncenter">
  549. <select name="tag">
  550. <option value="all">Show all <?php echo $unfiltered_theme_total; ?> themes</option>
  551. <?
  552. $links = '';
  553.  
  554. foreach ( $altags as $name => $count ) {
  555. // TODO selected from GET and POST
  556. $links.= '<option value="'.$name.'" '.$selected.' >'.$name.' ('.$count.')</option>';
  557. }
  558. echo substr($links,0,-2);
  559. ?>
  560. </select>
  561. <input type="submit" class="button-secondary" value="Filter" />
  562. </span>
  563. <?php if ( $page_links ) : ?>
  564. <?php echo "<div class='tablenav-pages'>$page_links</div>"; ?>
  565. <?php endif; ?>
  566.  
  567. <br class="clear" />
  568. </div>
  569. </form>
  570. <br class="clear" />
  571. <table class="widefat">
  572. <thead>
  573. <tr>
  574. <th>Theme</th>
  575. <th>Description</th>
  576. <th>Version</th>
  577. <th>Author</th>
  578. <th>Action</th>
  579. </tr>
  580. </thead>
  581. <tbody id='the-list-x' width='auto'>
  582. <?php
  583. $theme_names = array_keys($this->systemThemes);
  584.  
  585. natcasesort($theme_names);
  586.  
  587. foreach ($theme_names as $theme_name) {
  588. $template = $this->systemThemes[$theme_name]['Template'];
  589. $name = $this->systemThemes[$theme_name]['Name'];
  590. $stylesheet = $this->systemThemes[$theme_name]['Stylesheet'];
  591. $title = $this->systemThemes[$theme_name]['Title'];
  592. $version = $this->systemThemes[$theme_name]['Version'];
  593. $description = $this->systemThemes[$theme_name]['Description'];
  594. $author = $this->systemThemes[$theme_name]['Author'];
  595. $screenshot = $this->systemThemes[$theme_name]['Screenshot'];
  596. $stylesheet_dir = $this->systemThemes[$theme_name]['Stylesheet Dir'];
  597. $template_dir = $this->systemThemes[$theme_name]['Template Dir'];
  598. $parent_theme = $this->systemThemes[$theme_name]['Parent Theme'];
  599. $theme_root = $this->systemThemes[$theme_name]['Theme Root'];
  600. $theme_root_uri = $this->systemThemes[$theme_name]['Theme Root URI'];
  601.  
  602. $preview_link = esc_url(get_option('home') . '/');
  603. if ( is_ssl() )
  604. $preview_link = str_replace( 'http://', 'https://', $preview_link );
  605. $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
  606. $preview_text = esc_attr( sprintf( __('Preview of &#8220;%s&#8221;'), $title ) );
  607. $tags = $this->systemThemes[$theme_name]['Tags'];
  608. $thickbox_class = 'thickbox thickbox-preview';
  609. $activate_link = wp_nonce_url("?page=$utpage&amp;action=activate&amp;mode=system&amp;theme=".urlencode($name)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $name);
  610. $activate_text = esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $title ) );
  611.  
  612. $copy_link = wp_nonce_url("?page=$utpage&amp;action=copy&amp;theme=$template", 'copy-theme_' . $template);
  613.  
  614. $actions = array();
  615. if ($ct->stylesheet != $stylesheet)
  616. $actions[] = '<a href="' . $activate_link . '" class="activatelink" title="' . $activate_text . '">' . __('Activate') . '</a>';
  617. $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $theme_name)) . '">' . __('Preview') . '</a>';
  618. if (( current_user_can('edit_themes') ) && (count($this->userThemes) < $ds_Options['ut_max_copy']) )
  619. $actions[] = '<a href="' . $copy_link . '" class="activatelink" title="' . esc_attr(sprintf(__('Copy &#8220;%s&#8221;'), $theme_name)) . '">' . __('Copy') . '</a>';
  620.  
  621. // $actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);
  622.  
  623. $actions = implode ( '&nbsp;|&nbsp;', $actions );
  624.  
  625.  
  626. $alt = $alt == '' ? 'alternate' : '';
  627. ?>
  628. <tr class='<?php echo $alt; ?>'>
  629. <td><a class="<?php echo $thickbox_class; ?>" href="<?php echo $preview_link; ?>" title="<?php echo $preview_text; ?>" onMouseOver="preview('<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>', getTopPosition(this));" onMouseOut="unpreview();">"<?php echo "$title"; ?>"</a></td>
  630. <td><?php echo "$description";
  631. if( is_site_admin() ) { if ($parent_theme) { ?>
  632. <p><?php printf(__('The template files are located in <code>%2$s</code>. The stylesheet files are located in <code>%3$s</code>. <strong>%4$s</strong> uses templates from <strong>%5$s</strong>. Changes made to the templates will affect both themes.'), $title, $template_dir, $stylesheet_dir, $title, $parent_theme); ?></p>
  633. <?php } else { ?>
  634. <p><?php printf(__('All of this theme&#8217;s files are located in <code>%2$s</code>.'), $title, $template_dir, $stylesheet_dir); ?></p>
  635. <?php } } // site admin
  636.  
  637. if ( $tags ) :
  638. echo '<p>'. __('Tags: | ');
  639. foreach ($tags as $tag) {
  640. $uri = '?page=userthemes';
  641. $tag_link = add_query_arg('tag', $tag, $uri );
  642. echo '<a href="'.$tag_link.'">'.$tag.'</a> | ';
  643. }
  644. echo '</p>';
  645. endif;
  646. $this->theme_update_available( $this->systemThemes[$theme_name] );
  647.  
  648. ?>
  649. </td>
  650. <td><?php echo "$version"; ?></td>
  651. <td><?php echo "$author"; ?></td>
  652. <td><span class='action-links'><?php echo $actions ?></span></td>
  653.  
  654. </tr>
  655. <?php } ?>
  656. </form>
  657. </tbody>
  658. </table>
  659. <br class="clear" />
  660. <div class="tablenav">
  661. <span class="alignleft">
  662. <a class="button-secondary" href="<?php echo $default_link; ?>" class="delete"><?php _e('Activate Default Theme'); ?></a>
  663. </span>
  664. <?php if ( $page_links ) { echo "<div class='tablenav-pages'>$page_links</div>"; } ?>
  665. <br class="clear" />
  666. </div>
  667.  
  668. <p>Before you can edit system themes, you must copy that theme to your &quot;Userthemes&quot; area. You need to click the Activate link of a &quot;Usertheme&quot; before the you can use or edit any of your custom themes. The SiteAdmin may enable access to the Theme Editor on a blog by blog basis.</p>
  669. </div>
  670. <?php }
  671. function theme_update_available( $theme ) {
  672. static $themes_update;
  673.  
  674. if( is_multisite() && false == is_site_admin() )
  675. return;
  676.  
  677. if ( !isset($themes_update) )
  678. $themes_update = get_transient('update_themes');
  679.  
  680. if ( is_object($theme) && isset($theme->stylesheet) )
  681. $stylesheet = $theme->stylesheet;
  682. elseif ( is_array($theme) && isset($theme['Stylesheet']) )
  683. $stylesheet = $theme['Stylesheet'];
  684. else
  685. return false; //No valid info passed.
  686.  
  687. if ( isset($themes_update->response[ $stylesheet ]) ) {
  688. $update = $themes_update->response[ $stylesheet ];
  689. $theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : '');
  690. $details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
  691. $update_url = wp_nonce_url('update.php?action=upgrade-theme&amp;theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
  692. $update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Upgrading this theme will lose any customizations you have made. 'Cancel' to stop, 'OK' to upgrade.") ) . '\') ) {return true;}return false;"';
  693.  
  694. if ( ! current_user_can('update_themes') )
  695. printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
  696. else if ( empty($update->package) )
  697. printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> <em>automatic upgrade unavailable for this theme</em>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
  698. else
  699. printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> or <a href="%4$s" %5$s >upgrade automatically</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
  700. }
  701. }
  702. function get_themes() {
  703. global $wp_themes, $wp_broken_themes;
  704.  
  705. if ( isset($wp_themes) )
  706. return $wp_themes;
  707. if ( isset($this->userThemes) )
  708. return array_keys($this->userThemes);
  709. if ( isset($this->systemThemes) )
  710. return array_keys($this->systemThemes);
  711.  
  712.  
  713. $themes = array();
  714. $wp_broken_themes = array();
  715. $theme_loc = $theme_root = get_theme_root();
  716. if ( '/' != WP_CONTENT_DIR ) // don't want to replace all forward slashes, see Trac #4541
  717. $theme_loc = str_replace(WP_CONTENT_DIR, '', $theme_root);
  718.  
  719. // Files in wp-content/themes directory and one subdir down
  720. $themes_dir = @ opendir($theme_root);
  721. if ( !$themes_dir )
  722. return false;
  723.  
  724. while ( ($theme_dir = readdir($themes_dir)) !== false ) {
  725. if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
  726. if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
  727. continue;
  728. $stylish_dir = @ opendir($theme_root . '/' . $theme_dir);
  729. $found_stylesheet = false;
  730. while ( ($theme_file = readdir($stylish_dir)) !== false ) {
  731. if ( $theme_file == 'style.css' ) {
  732. $theme_files[] = $theme_dir . '/' . $theme_file;
  733. $found_stylesheet = true;
  734. break;
  735. }
  736. }
  737. @closedir($stylish_dir);
  738. if ( !$found_stylesheet ) { // look for themes in that dir
  739. $subdir = "$theme_root/$theme_dir";
  740. $subdir_name = $theme_dir;
  741. $theme_subdir = @ opendir( $subdir );
  742. while ( ($theme_dir = readdir($theme_subdir)) !== false ) {
  743. if ( is_dir( $subdir . '/' . $theme_dir) && is_readable($subdir . '/' . $theme_dir) ) {
  744. if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
  745. continue;
  746. $stylish_dir = @ opendir($subdir . '/' . $theme_dir);
  747. $found_stylesheet = false;
  748. while ( ($theme_file = readdir($stylish_dir)) !== false ) {
  749. if ( $theme_file == 'style.css' ) {
  750. $theme_files[] = $subdir_name . '/' . $theme_dir . '/' . $theme_file;
  751. $found_stylesheet = true;
  752. break;
  753. }
  754. }
  755. @closedir($stylish_dir);
  756. }
  757. }
  758. @closedir($theme_subdir);
  759. $wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
  760. }
  761. }
  762. }
  763. if ( is_dir( $theme_dir ) )
  764. @closedir( $theme_dir );
  765.  
  766. if ( !$themes_dir || !$theme_files )
  767. return $themes;
  768.  
  769. sort($theme_files);
  770.  
  771. foreach ( (array) $theme_files as $theme_file ) {
  772. if ( !is_readable("$theme_root/$theme_file") ) {
  773. $wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
  774. continue;
  775. }
  776.  
  777. $theme_data = get_theme_data("$theme_root/$theme_file");
  778.  
  779. $name = $theme_data['Name'];
  780. $title = $theme_data['Title'];
  781. $description = wptexturize($theme_data['Description']);
  782. $version = $theme_data['Version'];
  783. $author = $theme_data['Author'];
  784. $template = $theme_data['Template'];
  785. $stylesheet = dirname($theme_file);
  786.  
  787. $screenshot = false;
  788. foreach ( array('png', 'gif', 'jpg', 'jpeg') as $ext ) {
  789. if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) {
  790. $screenshot = "screenshot.$ext";
  791. break;
  792. }
  793. }
  794.  
  795. if ( empty($name) ) {
  796. $name = dirname($theme_file);
  797. $title = $name;
  798. }
  799.  
  800. if ( empty($template) ) {
  801. if ( file_exists(dirname("$theme_root/$theme_file/index.php")) )
  802. $template = dirname($theme_file);
  803. else
  804. continue;
  805. }
  806.  
  807. $template = trim($template);
  808.  
  809. if ( !file_exists("$theme_root/$template/index.php") ) {
  810. $parent_dir = dirname(dirname($theme_file));
  811. if ( file_exists("$theme_root/$parent_dir/$template/index.php") ) {
  812. $template = "$parent_dir/$template";
  813. } else {
  814. $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
  815. continue;
  816. }
  817. }
  818.  
  819. $stylesheet_files = array();
  820. $stylesheet_dir = @ dir("$theme_root/$stylesheet");
  821. if ( $stylesheet_dir ) {
  822. while ( ($file = $stylesheet_dir->read()) !== false ) {
  823. if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) )
  824. $stylesheet_files[] = "$theme_loc/$stylesheet/$file";
  825. }
  826. }
  827.  
  828. $template_files = array();
  829. $template_dir = @ dir("$theme_root/$template");
  830. if ( $template_dir ) {
  831. while(($file = $template_dir->read()) !== false) {
  832. if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
  833. $template_files[] = "$theme_loc/$template/$file";
  834. }
  835. }
  836.  
  837. $template_dir = dirname($template_files[0]);
  838. $stylesheet_dir = dirname($stylesheet_files[0]);
  839.  
  840. if ( empty($template_dir) )
  841. $template_dir = '/';
  842. if ( empty($stylesheet_dir) )
  843. $stylesheet_dir = '/';
  844.  
  845. // Check for theme name collision. This occurs if a theme is copied to
  846. // a new theme directory and the theme header is not updated. Whichever
  847. // theme is first keeps the name. Subsequent themes get a suffix applied.
  848. // The Default and Classic themes always trump their pretenders.
  849. if ( isset($themes[$name]) ) {
  850. if ( ('WordPress Default' == $name || 'WordPress Classic' == $name) &&
  851. ('default' == $stylesheet || 'classic' == $stylesheet) ) {
  852. // If another theme has claimed to be one of our default themes, move
  853. // them aside.
  854. $suffix = $themes[$name]['Stylesheet'];
  855. $new_name = "$name/$suffix";
  856. $themes[$new_name] = $themes[$name];
  857. $themes[$new_name]['Name'] = $new_name;
  858. } else {
  859. $name = "$name/$stylesheet";
  860. }
  861. }
  862.  
  863. $themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Stylesheet' => $stylesheet, 'Template Files' => $template_files, 'Stylesheet Files' => $stylesheet_files, 'Template Dir' => $template_dir, 'Stylesheet Dir' => $stylesheet_dir, 'Status' => $theme_data['Status'], 'Screenshot' => $screenshot, 'Tags' => $theme_data['Tags']);
  864. }
  865.  
  866. // Resolve theme dependencies.
  867. $theme_names = array_keys($themes);
  868.  
  869. foreach ( (array) $theme_names as $theme_name ) {
  870. $themes[$theme_name]['Parent Theme'] = '';
  871. if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) {
  872. foreach ( (array) $theme_names as $parent_theme_name ) {
  873. if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) {
  874. $themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
  875. break;
  876. }
  877. }
  878. }
  879. }
  880.  
  881. $wp_themes = $themes;
  882.  
  883. return $themes;
  884. }
  885.  
  886. function get_theme($theme) {
  887. $themes = $this->get_themes();
  888. if ( array_key_exists($theme, $themes) )
  889. return $themes[$theme];
  890.  
  891. return NULL;
  892. }
  893. //This is the wpmu admin page for managing user themes
  894.  
  895. function init() {
  896. $this->getAdminOptions();
  897. }
  898.  
  899. function getAdminOptions() {
  900. $AdminOptions = array(
  901. 'ut_hide_original_menu' => 'false',
  902. 'ut_max_copy' => '5', // DS_UT_THEMES_MAX_COPY
  903. 'ut_themes_per_page' => '50', // DS_UT_THEMES_PER_PAGE
  904. 'ut_blogs_per_page' => '50' // DS_UT_WPMUBLOGS_PAGE
  905. );
  906. $ds_Options = get_site_option($this->adminOptionsName);
  907. if (!empty($ds_Options)) {
  908. foreach ($ds_Options as $key => $option)
  909. $AdminOptions[$key] = $option;
  910. }
  911. update_site_option($this->adminOptionsName, $AdminOptions);
  912. return $AdminOptions;
  913. }
  914.  
  915. function management_page() {
  916. if (!is_site_admin) {
  917. echo "You do not belong here";
  918. return;
  919. }
  920. global $wpdb;
  921. $utpage = $_GET['page'];
  922.  
  923. $ds_Options = $this->getAdminOptions();
  924.  
  925. if (isset($_POST['update_DS_User_Themes_Options'])) {
  926. if (isset($_POST['ds_ut_hide_original_menu'])) {
  927. $ds_Options['ut_hide_original_menu'] = $_POST['ds_ut_hide_original_menu'];
  928. }
  929. if (isset($_POST['ds_ut_max_copy'])) {
  930. $ds_Options['ut_max_copy'] = $_POST['ds_ut_max_copy'];
  931. }
  932. if (isset($_POST['ds_ut_themes_per_page'])) {
  933. $ds_Options['ut_themes_per_page'] = $_POST['ds_ut_themes_per_page'];
  934. }
  935. if (isset($_POST['ds_ut_blogs_per_page'])) {
  936. $ds_Options['ut_blogs_per_page'] = $_POST['ds_ut_blogs_per_page'];
  937. }
  938. update_site_option($this->adminOptionsName, $ds_Options);
  939. ?>
  940. <div class="updated"><p><strong><?php _e("Settings Updated.", "DS_User_Themes");?></strong></p></div>
  941. <?php
  942. } ?>
  943.  
  944.  
  945.  
  946.  
  947.  
  948. <?php
  949.  
  950.  
  951. switch ($_GET['action']) {
  952.  
  953. case 'ds_ut_options' :
  954.  
  955.  
  956.  
  957. break;
  958.  
  959. case 'enable' :
  960. $blog = $_GET['blog'];
  961. if (!isset($blog)) {
  962. echo "just click the links please";
  963. return;
  964. }
  965. update_blog_option($blog, 'ut_enabled', 1);
  966. break;
  967. case 'disable' :
  968. $blog = $_GET['blog'];
  969. if (!isset($blog)) {
  970. echo "just click the links please";
  971. return;
  972. }
  973. update_blog_option($blog, 'ut_enabled', 0);
  974. break;
  975. }
  976. ?><div class='wrap'>
  977. <h3>MU Userthemes Manager</h3>
  978. <p>WPMU 2.8.1 has a new function disable_some_pages in /wp-admin/includes/mu.php. WPMU forums has suggestions for enabling theme editor. The userthemes plugin file has a "function ds_disable_some_pages" which <strong>will remove the mu.php action hook restricting the theme-editor.php</strong>. Furthermore, it will enable theme-editor.php for blogs listed as enabled below AND only while a usertheme is the active theme on that blog.</p>
  979. <p>Hack theme-editor.php to restrict allowed files to just the stylesheets (still no fitering any included evildoing code though):
  980. <pre>
  981. // $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
  982. $allowed_files = $themes[$theme]['Stylesheet Files'];
  983. </pre>
  984. </p>
  985. <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
  986. <table class="form-table">
  987. <tr valign="top">
  988. <th scope="row">MAX Userthemes Per Blog</th>
  989. <td><input type="text" name="ds_ut_max_copy" style="width: 5%;" value="<?php echo $ds_Options['ut_max_copy']; ?>" /><br /><small>Without a limit a user could copy themes to their blogs.dir/blog_id/themes folder until the crack of doom.</small></td>
  990. </tr>
  991. <tr valign="top">
  992. <th scope="row">Hide Original Themes Menu</th>
  993. <td>
  994. <label for="ds_ut_hide_original_menu_yes"><input type="radio" id="ds_ut_hide_original_menu_yes" name="ds_ut_hide_original_menu" value="true" <?php if ($ds_Options['ut_hide_original_menu'] == "true") { echo 'checked="checked"';} ?> /> Yes</label>&nbsp;&nbsp;&nbsp;&nbsp;<label for="ds_ut_hide_original_menu_no"><input type="radio" id="ds_ut_hide_original_menu_no" name="ds_ut_hide_original_menu" value="false" <?php if ($ds_Options['ut_hide_original_menu'] == "false") { echo 'checked="checked"';} ?>/> No</label><br /><small>This action will only be added to a blog if Userthemes is enabled below. While a usertheme is active, the normal Themes page may reset the active theme. In my tests this occured if the name of the usertheme could no longer be found in the system themes list: ie. usertheme renamed or original disabled/deleted. Users of this plugin will find many ways to create the dreaded "white screen" on the frontend: "template <a href="http://en.wikipedia.org/wiki/Nihilism">nihilists</a>" unite!.</small>
  995. </td>
  996. </tr>
  997. <tr valign="top">
  998. <th scope="row">Userthemes Per Page</th>
  999. <td><input type="text" name="ds_ut_themes_per_page" style="width: 5%;" value="<?php echo $ds_Options['ut_themes_per_page']; ?>" /><small>Have a WPMU with 200+ themes? List 50 per page to throttle.</small></td>
  1000. </tr>
  1001. <tr valign="top">
  1002. <th scope="row">Userthemes Management Blogs Per Page</th>
  1003. <td><input type="text" name="ds_ut_blogs_per_page" style="width: 5%;" value="<?php echo $ds_Options['ut_blogs_per_page']; ?>" /><small>Have a WPMU with 200+ blogs? List 50 per page to throttle.</small></td>
  1004. </tr>
  1005.  
  1006. <div class="submit">
  1007. <input type="submit" name="update_DS_User_Themes_Options" value="<?php echo 'Update Settings'; ?>" /></div>
  1008. </table></form><?php
  1009.  
  1010. $blogs = $wpdb->get_results( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = '$wpdb->siteid' AND archived = '0' AND spam = '0' AND deleted = '0' ORDER BY blog_id ASC", ARRAY_A );
  1011.  
  1012. // pagination
  1013. ksort( $blogs );
  1014. $blogs_total = count( $blogs );
  1015. $per_page = $ds_Options['ut_blogs_per_page']; //DS_UT_WPMUBLOGS_PAGE;
  1016.  
  1017. if ( isset( $_GET['pagenum'] ) )
  1018. $page = absint( $_GET['pagenum'] );
  1019.  
  1020. if ( empty($page) )
  1021. $page = 1;
  1022.  
  1023. $start = $offset = ( $page - 1 ) * $per_page;
  1024.  
  1025. $page_links = paginate_links( array(
  1026. 'base' => add_query_arg( 'pagenum', '%#%' ) . '#themenav',
  1027. 'format' => '',
  1028. 'total' => ceil($blogs_total / $per_page),
  1029. 'current' => $page
  1030. ));
  1031. $blogs = array_slice( $blogs, $start, $per_page );
  1032. // pagination end
  1033.  
  1034. $panic_link = 'theme-editor.php';
  1035. ?>
  1036. <div class="tablenav">
  1037. <div class="alignleft">
  1038. <a class="button-secondary" href="<?php echo $panic_link; ?>" class="delete" title="Is theme-editor.php secure?"><?php _e('Panic Button'); ?></a>
  1039. </div>
  1040. <?php if ( $page_links ) { echo "<div class='tablenav-pages'>$page_links</div>"; } ?>
  1041. <br class="clear" />
  1042. </div>
  1043. <br class="clear" />
  1044. <table width="100%" cellpadding="3" cellspacing="3" class="widefat">
  1045. <thead>
  1046. <tr>
  1047. <th>Blog ID</th>
  1048. <th>Blog Name</th>
  1049. <th>Theme Library</th>
  1050. <th>Theme</th>
  1051. <th>Userthemes and Theme Editor</th>
  1052. </tr>
  1053. </thead>
  1054. <tbody id="the-list">
  1055. <?php
  1056. //Reverse this because I want the blogs in ID order not in recently registered order
  1057.  
  1058.  
  1059. foreach ($blogs as $bloginfo) {
  1060. $alt = $alt == '' ? 'alternate' : '';
  1061.  
  1062. $bgcolor = 'class='. $alt .'';
  1063. if(get_blog_option($bloginfo['blog_id'], 'ut_use_user_theme' ) == 1 )
  1064. $bgcolor = " style='background:#d1d1d1'";
  1065. if(get_blog_option($bloginfo['blog_id'], 'ut_enabled' ) == 1 )
  1066. $bgcolor = " style='background:#faa'";
  1067. if ((get_blog_option($bloginfo['blog_id'], 'ut_enabled') == 1) && (get_blog_option($bloginfo['blog_id'], ut_use_user_theme ) == 1 ))
  1068. $bgcolor = " style='background:#c70000'";
  1069.  
  1070. echo '<tr '.$bgcolor.'>';
  1071. echo "<td>{$bloginfo['blog_id']}</td>";
  1072. if( constant( "VHOST" ) == 'yes' ) {
  1073. echo "<td><a href='http://".$bloginfo[ 'domain' ] . $bloginfo[ 'path' ]."'>".$bloginfo[ 'domain' ]."</a></td>";
  1074. } else {
  1075. echo "<td><a href='http://".$bloginfo[ 'domain' ] . $bloginfo[ 'path' ]."'>".$bloginfo[ 'path' ]."</a></td>";
  1076. }
  1077.  
  1078. if (get_blog_option($bloginfo['blog_id'], 'ut_use_user_theme') == 1)
  1079. echo "<td><b><font color='blue' size='1'>*</font>".DS_UT_USERTHEMES_DIR."</b></td>";
  1080. else
  1081. echo "<td>System</td>";
  1082. echo "<td>";
  1083. echo get_blog_option($bloginfo['blog_id'], 'template');
  1084. echo "</td>";
  1085. if (get_blog_option($bloginfo['blog_id'], 'ut_enabled') == 1)
  1086. echo "<td><a href=?page=$utpage&blog=".$bloginfo['blog_id']."&action=disable>Enabled (Secure Theme Editor)</a></td>";
  1087. if (get_blog_option($bloginfo['blog_id'], 'ut_enabled') != 1)
  1088. echo "<td><a href=?page=$utpage&blog=".$bloginfo['blog_id']."&action=enable>Disabled</a></td>";
  1089. echo "</tr>";
  1090. }
  1091. echo "</tbody></table>";
  1092. echo "</div>";
  1093. }
  1094.  
  1095. function get_all_themes() {
  1096. unset($this->userThemes);
  1097. unset($this->systemThemes);
  1098. unset($GLOBALS['wp_themes']);
  1099. $oldValue = get_option('ut_use_user_theme');
  1100. $newValue = 0;
  1101. if ($oldValue == 1) {
  1102. $this->userThemes = $this->get_themes();
  1103. $newValue = 0;
  1104. } else {
  1105. //if it wasn't 1, then it was either 0 or some other invalid number, so set it to 0
  1106. $oldValue = 0;
  1107. {
  1108. $this->systemThemes = get_themes();
  1109. $ct = current_theme_info();
  1110. $ut_allowed_themes = get_site_allowed_themes();
  1111. if( $ut_allowed_themes == false )
  1112. $ut_allowed_themes = array();
  1113.  
  1114. $ut_blog_allowed_themes = wpmu_get_blog_allowedthemes();
  1115. if( is_array( $ut_blog_allowed_themes ) )
  1116. $ut_allowed_themes = array_merge( $ut_allowed_themes, $ut_blog_allowed_themes );
  1117. if( $blog_id != 1 )
  1118. unset( $ut_allowed_themes[ "h3" ] );
  1119.  
  1120. if( isset( $ut_allowed_themes[ wp_specialchars( $ct->stylesheet ) ] ) == false )
  1121. $ut_allowed_themes[ wp_specialchars( $ct->stylesheet ) ] = true;
  1122.  
  1123. reset( $this->systemThemes );
  1124. foreach( $this->systemThemes as $key => $theme ) {
  1125. if( isset( $ut_allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == false ) {
  1126. unset( $this->systemThemes[ $key ] );
  1127. }
  1128. }
  1129. reset( $this->systemThemes );
  1130. }
  1131.  
  1132. $newValue = 1;
  1133. }
  1134. update_option('ut_use_user_theme', $newValue);
  1135. unset($GLOBALS['wp_themes']);
  1136.  
  1137. if ($newValue == 1)
  1138. { $this->userThemes = $this->get_themes();
  1139. } else {
  1140. $this->systemThemes = get_themes();
  1141. $ct = current_theme_info();
  1142. $ut_allowed_themes = get_site_allowed_themes();
  1143. if( $ut_allowed_themes == false )
  1144. $ut_allowed_themes = array();
  1145.  
  1146. $ut_blog_allowed_themes = wpmu_get_blog_allowedthemes();
  1147. if( is_array( $ut_blog_allowed_themes ) )
  1148. $ut_allowed_themes = array_merge( $ut_allowed_themes, $ut_blog_allowed_themes );
  1149. if( $blog_id != 1 )
  1150. unset( $ut_allowed_themes[ "h3" ] );
  1151.  
  1152. if( isset( $ut_allowed_themes[ wp_specialchars( $ct->stylesheet ) ] ) == false )
  1153. $ut_allowed_themes[ wp_specialchars( $ct->stylesheet ) ] = true;
  1154.  
  1155. reset( $this->systemThemes );
  1156. foreach( $this->systemThemes as $key => $theme ) {
  1157. if( isset( $ut_allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == false ) {
  1158. unset( $this->systemThemes[ $key ] );
  1159. }
  1160. }
  1161. reset( $this->systemThemes );
  1162. }
  1163. update_option('ut_use_user_theme', $oldValue);
  1164. unset($GLOBALS['wp_themes']);
  1165. }
  1166. function print_header() {
  1167. echo " <script>
  1168. var pendingOpen = 0;
  1169. var open = 0;
  1170. var pendingClose = 0;
  1171. function preview(url, top) {
  1172. document.getElementById('utpreviewbox').style.top=top-100 + 'px';
  1173. document.getElementById('previewimage').src=url;
  1174. pendingOpen = 1;
  1175. pendingClose = 0;
  1176. setTimeout('showpreview()', 1000);
  1177. }
  1178. function unpreview() {
  1179. pendingClose = 1;
  1180. setTimeout('hidepreview()', 400);
  1181. }
  1182. function showpreview() {
  1183. if (pendingOpen == 0) { return; }
  1184. var p = document.getElementById('utpreviewbox');
  1185. p.style.visibility='visible';
  1186. }
  1187. function hidepreview() {
  1188. if (pendingClose == 0 ) {return;}
  1189. pendingClose = 0;
  1190. pendingOpen = 0;
  1191. var p = document.getElementById('utpreviewbox');
  1192. p.style.visibility='hidden';
  1193. }
  1194. function getTopPosition(e) {
  1195. p = 0;
  1196. while (e!=null) {
  1197. p += e.offsetTop;
  1198. e = e.offsetParent;
  1199. }
  1200. return p;
  1201. }
  1202. </script>
  1203. <style>
  1204. #utpreviewbox {
  1205. visibility: hidden;
  1206. background-color: white;
  1207. border: 5px solid #cccccc;
  1208. position: absolute;
  1209. z-index: 1000;
  1210. left: 220px;
  1211. top: 300px;
  1212. }
  1213. </style>
  1214. <div id='utpreviewbox'>
  1215. <img id='previewimage' width='320' border='0' src='http://www.google.com/intl/en/images/logo.gif'/>
  1216. </div>";
  1217. }
  1218.  
  1219. function ds_disable_some_pages() {
  1220. global $messages;
  1221.  
  1222. if ( strpos( $_SERVER['PHP_SELF'], 'user-new.php' ) && !get_site_option( 'add_new_users' ) ) {
  1223. if ( is_site_admin() ) {
  1224. $messages[] = '<div id="message" class="updated fade"><p>' . __( 'Warning! Only site administrators may see this page. Everyone else will see a <em>page disabled</em> message. Enable it again on <a href="wpmu-options.php#addnewusers">the options page</a>.' ) . '</p></div>';
  1225. } else {
  1226. wp_die( __('Page disabled by the administrator') );
  1227. }
  1228. }
  1229.  
  1230. $pages = array( 'plugin-editor.php' );
  1231. foreach( $pages as $page ) {
  1232. if ( strpos( $_SERVER['PHP_SELF'], $page ) ) {
  1233. wp_die( __('Page disabled by the administrator') );
  1234. }
  1235. }
  1236.  
  1237. $pages = array( 'theme-editor.php' );
  1238. foreach( $pages as $page ) {
  1239. if ( strpos( $_SERVER['PHP_SELF'], $page ) && (
  1240. get_option('ut_use_user_theme') != 1 // blog enabled to see Userthemes via Usertheme Management
  1241. || // if either condition is not a '1' then wp_die
  1242. get_option('ut_enabled') != 1 // blog has a Usertheme active
  1243. )
  1244. )
  1245. {
  1246. wp_die( __('Page disabled by Userthemes Management') );
  1247. }
  1248. }
  1249.  
  1250. $pages = array( 'theme-install.php', 'plugin-install.php' );
  1251. foreach( $pages as $page ) {
  1252. if ( strpos( $_SERVER['PHP_SELF'], $page ) && !is_site_admin() ) {
  1253. wp_die( __( "Sorry, you're not allowed here." ) );
  1254. }
  1255. }
  1256. remove_action( 'admin_init', 'disable_some_pages' );
  1257. }
  1258.  
  1259.  
  1260. }
  1261. $user_themes = new DS_User_Themes();
  1262.  
  1263. if (isset($user_themes)) {
  1264.  
  1265. if( strpos($_SERVER['REQUEST_URI'], 'userthemes')) add_action('admin_init', array(&$user_themes, 'ds_ut_theme_preview_scripts'));
  1266.  
  1267.  
  1268. add_action( 'admin_init', array(&$user_themes, 'ds_disable_some_pages'), 1 );
  1269.  
  1270. add_action('admin_menu', array(&$user_themes, 'admin_menu_pages'));
  1271. add_action('userthemes.php', array(&$user_themes, 'init'));
  1272. $ut_hide_menu_perms = get_site_option( "DS_User_Themes_Options" );
  1273. if( is_array( $ut_hide_menu_perms ) == false )
  1274. $ut_hide_menu_perms = array();
  1275. if(( $ut_hide_menu_perms[ 'ut_hide_original_menu' ] == 'true' ) && (get_option('ut_enabled') == 1)) {
  1276. add_action('_admin_menu', array(&$user_themes,'ds_ut_hide_original_themes_php'));
  1277. }
  1278.  
  1279. if ( !defined('WP_CONTENT_DIR') )
  1280. define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
  1281. if ( !defined('WP_CONTENT_URL') )
  1282. define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
  1283. define( 'DS_UT_SYSTEM_THEMES_DIR', WP_CONTENT_DIR.'/themes');
  1284. define( 'DS_UT_USERTHEMES_DIR', WP_CONTENT_DIR.'/blogs.dir/'.$wpdb->blogid.'/themes');
  1285. define( 'DS_UT_USERTHEMES_URL', WP_CONTENT_URL.'/blogs.dir/'.$wpdb->blogid.'/themes');
  1286.  
  1287. if (strpos($_SERVER['REQUEST_URI'], 'page=userthemes'))
  1288. add_action('admin_head', array(&$user_themes, 'print_header'));
  1289.  
  1290. if (strpos($_SERVER['REQUEST_URI'], 'page=userthemes') ||
  1291. strpos($_SERVER['REQUEST_URI'], 'theme-editor.php') ||
  1292. !is_admin()
  1293. ) {
  1294. add_filter('theme_root', array(&$user_themes, 'theme_root_filter'));
  1295. add_filter('theme_root_uri', array(&$user_themes, 'theme_root_uri_filter'));
  1296. }
  1297. }
  1298. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement