PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wp-mobile-detector/admin/themes.php

https://gitlab.com/endomorphosis/jeffersonsmithmayor
PHP | 318 lines | 277 code | 33 blank | 8 comment | 48 complexity | bff8e0d0ccdd96c3be187150753a78d1 MD5 | raw file
  1. <?php
  2. function websitez_themes_page(){
  3. global $wpdb, $websitez_plugin_description, $table_prefix, $websitez_free_version;
  4. if(function_exists('get_allowed_themes'))
  5. $themes_standard = get_allowed_themes();
  6. else
  7. $themes_standard = get_themes();
  8. $path = WEBSITEZ_PLUGIN_DIR.'/themes';
  9. $themes_preinstalled = websitez_get_themes($path,true);
  10. $themes = array_merge($themes_standard,$themes_preinstalled);
  11. if (isset($_GET['action']) ) {
  12. $preinstalled_themes_update = false;
  13. if ( 'activate' == $_GET['action'] ) {
  14. foreach($themes_preinstalled as $k=>$v):
  15. if($v['Template']==$_GET['template']){
  16. //If this is true, this is a theme located in the plugins folder
  17. //This value will tell the rest of the script to look in the plugin themes folder
  18. if(get_option(WEBSITEZ_USE_PREINSTALLED_THEMES_NAME)){
  19. update_option(WEBSITEZ_USE_PREINSTALLED_THEMES_NAME, "true");
  20. $preinstalled_themes_update = true;
  21. }
  22. }
  23. endforeach;
  24. //If this is false, it means we're using a theme from the regular themes folder
  25. //and must tell the rest of the script not to change the theme folder location
  26. if($preinstalled_themes_update == false){
  27. if(get_option(WEBSITEZ_USE_PREINSTALLED_THEMES_NAME)){
  28. update_option(WEBSITEZ_USE_PREINSTALLED_THEMES_NAME, "false");
  29. }
  30. }
  31. if(get_option(WEBSITEZ_ADVANCED_THEME))
  32. update_option(WEBSITEZ_ADVANCED_THEME, $_GET['template']);
  33. if(get_option(WEBSITEZ_BASIC_THEME))
  34. update_option(WEBSITEZ_BASIC_THEME, $_GET['template']);
  35. $activated=true;
  36. }
  37. }
  38. //Get the theme that is currently set for mobile devices
  39. $ct = current_mobile_theme_info($themes);
  40. unset($themes[$ct->name]);
  41. uksort( $themes, "strnatcasecmp" );
  42. $theme_total = count( $themes );
  43. $per_page = 15;
  44. if ( isset( $_GET['pagenum'] ) )
  45. $page = absint( $_GET['pagenum'] );
  46. if ( empty($page) )
  47. $page = 1;
  48. $start = $offset = ( $page - 1 ) * $per_page;
  49. $page_links = paginate_links( array(
  50. 'base' => add_query_arg( 'pagenum', '%#%' ) . '#themenav',
  51. 'format' => '',
  52. 'prev_text' => __('&laquo;'),
  53. 'next_text' => __('&raquo;'),
  54. 'total' => ceil($theme_total / $per_page),
  55. 'current' => $page
  56. ));
  57. $themes = array_slice( $themes, $start, $per_page );
  58. ?>
  59. <div class="wrap">
  60. <table width="100%" cellpadding="0" cellspacing="0">
  61. <tr>
  62. <td width="60%" valign="top">
  63. <h1><?php echo esc_html( __(WEBSITEZ_PLUGIN_NAME." - Mobile Themes") ); ?></h1>
  64. <p><?php _e('Configure which theme to show to each mobile device.') ?></p>
  65. </td>
  66. <td width="40%" valign="top" align="right" style="padding: 15px 15px 0px 0px">
  67. <p><a href="http://ready.mobi/results.jsp?uri=<?php echo bloginfo('url'); ?>&ref=websitez-com-wp-mobile-detector" target="_blank" title="<?php _e('Check the mobile readiness of this website.') ?>"><img src="<?php echo plugin_dir_url(__FILE__).'images/check-mobile-readiness.jpg'?>" border="0" alt="<?php _e('Check the mobile readiness of this website.') ?>"></a></p>
  68. </td>
  69. </tr>
  70. </table>
  71. <div id="plugin-description" class="widefat alternate" style="margin:10px 0; padding:5px;background-color:#FFFEEB;">
  72. <table width="100%" cellpadding="0" cellspacing="0">
  73. <tr>
  74. <td width="20" align="center" style="padding-top: 5px;"><img src="<?php echo plugin_dir_url(__FILE__); ?>images/basic_phone_icon_16x16.gif"></td>
  75. <td><?php _e('<h3 style="margin: 0px 0px 10px;"><u>Basic Mobile Device</u></h3><p>The WP Mobile Detector will remove all images and advanced HTML from being displayed on basic devices.</p>') ?></td>
  76. </tr>
  77. <tr>
  78. <td width="20" align="center" style="padding-top: 10px;"><img src="<?php echo plugin_dir_url(__FILE__); ?>images/phone_icon_16x16.png"></td>
  79. <td><?php _e('<h3 style="margin: 5px 0px 10px;"><u>Advanced Mobile Device</u></h3><p>The WP Mobile Detector will resize images that are too large to display on advanced mobile devices.</p>') ?></td>
  80. </tr>
  81. </table>
  82. </div>
  83. <?php if ( !validate_current_mobile_theme($ct->template,$ct->template_dir) ) : ?>
  84. <div id="message1" class="updated"><p><?php _e('The active mobile theme is broken. Reverting to the default mobile theme.'); ?></p></div>
  85. <?php elseif ( $activated == true ) :
  86. ?>
  87. <div id="message2" class="updated"><p><?php printf( __( 'New mobile theme activated.' ), home_url( '/' ) ); ?></p></div><?php
  88. endif; ?>
  89. <h3><?php _e('Current Mobile Theme'); ?></h3>
  90. <div id="current-theme">
  91. <?php if ( $ct->screenshot ) : ?>
  92. <img src="<?php echo $ct->theme_root_uri . '/' . $ct->stylesheet . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" />
  93. <?php endif; ?>
  94. <h4><?php
  95. /* translators: 1: theme title, 2: theme version, 3: theme author */
  96. printf(__('%1$s %2$s by %3$s'), $ct->title, $ct->version, $ct->author) ; ?></h4>
  97. <p class="theme-description"><?php echo $ct->description; ?></p>
  98. <?php if ( current_user_can('edit_themes') && $ct->parent_theme ) { ?>
  99. <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, str_replace( WP_CONTENT_DIR, '', $ct->template_dir ), str_replace( WP_CONTENT_DIR, '', $ct->stylesheet_dir ), $ct->title, $ct->parent_theme); ?></p>
  100. <?php } else { ?>
  101. <p><?php printf(__('All of this theme&#8217;s files are located in <code>%2$s</code>.'), $ct->title, str_replace( WP_CONTENT_DIR, '', $ct->template_dir ), str_replace( WP_CONTENT_DIR, '', $ct->stylesheet_dir ) ); ?></p>
  102. <?php } ?>
  103. <?php if ( $ct->tags ) : ?>
  104. <p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p>
  105. <?php endif; ?>
  106. <?php theme_update_available($ct); ?>
  107. </div>
  108. <div class="clear"></div>
  109. <?php
  110. if ( ! current_user_can( 'switch_themes' ) ) {
  111. echo '</div>';
  112. require( './admin-footer.php' );
  113. exit;
  114. }
  115. ?>
  116. <h3><?php _e('Available Themes'); ?></h3>
  117. <div class="clear"></div>
  118. <?php if ( $theme_total ) { ?>
  119. <?php if ( $page_links ) : ?>
  120. <div class="tablenav">
  121. <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
  122. number_format_i18n( $start + 1 ),
  123. number_format_i18n( min( $page * $per_page, $theme_total ) ),
  124. number_format_i18n( $theme_total ),
  125. $page_links
  126. ); echo $page_links_text; ?></div>
  127. </div>
  128. <?php endif; ?>
  129. <table id="availablethemes" cellspacing="0" cellpadding="0">
  130. <?php
  131. $style = '';
  132. $theme_names = array_keys($themes);
  133. natcasesort($theme_names);
  134. $table = array();
  135. $rows = ceil(count($theme_names) / 3);
  136. for ( $row = 1; $row <= $rows; $row++ )
  137. for ( $col = 1; $col <= 3; $col++ )
  138. $table[$row][$col] = array_shift($theme_names);
  139. foreach ( $table as $row => $cols ) {
  140. ?>
  141. <tr>
  142. <?php
  143. foreach ( $cols as $col => $theme_name ) {
  144. $class = array('available-theme');
  145. if ( $row == 1 ) $class[] = 'top';
  146. if ( $col == 1 ) $class[] = 'left';
  147. if ( $row == $rows ) $class[] = 'bottom';
  148. if ( $col == 3 ) $class[] = 'right';
  149. ?>
  150. <td class="<?php echo join(' ', $class); ?>">
  151. <?php if ( !empty($theme_name) ) :
  152. $template = $themes[$theme_name]['Template'];
  153. $stylesheet = $themes[$theme_name]['Stylesheet'];
  154. $title = $themes[$theme_name]['Title'];
  155. $version = $themes[$theme_name]['Version'];
  156. $description = $themes[$theme_name]['Description'];
  157. $author = $themes[$theme_name]['Author'];
  158. $screenshot = $themes[$theme_name]['Screenshot'];
  159. $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
  160. $template_dir = $themes[$theme_name]['Template Dir'];
  161. $parent_theme = $themes[$theme_name]['Parent Theme'];
  162. $theme_root = $themes[$theme_name]['Theme Root'];
  163. $theme_root_uri = $themes[$theme_name]['Theme Root URI'];
  164. $preview_link = esc_url(get_option('home') . '/');
  165. if ( is_ssl() )
  166. $preview_link = str_replace( 'http://', 'https://', $preview_link );
  167. $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
  168. $preview_text = esc_attr( sprintf( __('Preview of &#8220;%s&#8221;'), $title ) );
  169. $tags = $themes[$theme_name]['Tags'];
  170. $thickbox_class = 'thickbox thickbox-preview';
  171. $activate_link = wp_nonce_url("admin.php?page=websitez_themes&action=activate&amp;template=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
  172. $activate_text = esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $title ) );
  173. $actions = array();
  174. $actions[] = '<a href="' . $activate_link . '" class="activatelink" title="' . $activate_text . '">' . __('Activate') . '</a>';
  175. $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $theme_name)) . '" target="_blank">' . __('Preview') . '</a>';
  176. $actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);
  177. $actions = implode ( ' | ', $actions );
  178. ?>
  179. <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
  180. <?php if ( $screenshot ) : ?>
  181. <img src="<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>" alt="" />
  182. <?php endif; ?>
  183. </a>
  184. <h3><?php
  185. /* translators: 1: theme title, 2: theme version, 3: theme author */
  186. printf(__('%1$s %2$s by %3$s'), $title, $version, $author) ; ?></h3>
  187. <p class="description"><?php echo $description; ?></p>
  188. <span class='action-links'><?php echo $actions ?></span>
  189. <?php if ( current_user_can('edit_themes') && $parent_theme ) {
  190. /* translators: 1: theme title, 2: template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
  191. <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, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ), $title, $parent_theme); ?></p>
  192. <?php } else { ?>
  193. <p><?php printf(__('All of this theme&#8217;s files are located in <code>%2$s</code>.'), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ) ); ?></p>
  194. <?php } ?>
  195. <?php if ( $tags ) : ?>
  196. <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
  197. <?php endif; ?>
  198. <?php theme_update_available( $themes[$theme_name] ); ?>
  199. <?php endif; // end if not empty theme_name ?>
  200. </td>
  201. <?php } // end foreach $cols ?>
  202. </tr>
  203. <?php } // end foreach $table ?>
  204. </table>
  205. <?php } else { ?>
  206. <p><?php
  207. if ( current_user_can('install_themes') )
  208. printf(__('You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress.org Theme Directory at any time: just click on the <em><a href="%s">Install Themes</a></em> tab above.'), 'theme-install.php');
  209. else
  210. printf(__('Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.'), get_site_option('site_name'));
  211. ?></p>
  212. <?php } // end if $theme_total?>
  213. <br class="clear" />
  214. <?php if ( $page_links ) : ?>
  215. <div class="tablenav">
  216. <?php echo "<div class='tablenav-pages'>$page_links_text</div>"; ?>
  217. <br class="clear" />
  218. </div>
  219. <?php endif; ?>
  220. <br class="clear" />
  221. <?php
  222. // List broken themes, if any.
  223. $broken_themes = get_broken_themes();
  224. if ( current_user_can('edit_themes') && count( $broken_themes ) ) {
  225. ?>
  226. <h2><?php _e('Broken Themes'); ?> <?php if ( is_multisite() ) _e( '(Site admin only)' ); ?></h2>
  227. <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
  228. <table id="broken-themes">
  229. <tr>
  230. <th><?php _e('Name'); ?></th>
  231. <th><?php _e('Description'); ?></th>
  232. </tr>
  233. <?php
  234. $theme = '';
  235. $theme_names = array_keys($broken_themes);
  236. natcasesort($theme_names);
  237. foreach ($theme_names as $theme_name) {
  238. $title = $broken_themes[$theme_name]['Title'];
  239. $description = $broken_themes[$theme_name]['Description'];
  240. $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
  241. echo "
  242. <tr $theme>
  243. <td>$title</td>
  244. <td>$description</td>
  245. </tr>";
  246. }
  247. ?>
  248. </table>
  249. <?php
  250. }
  251. ?>
  252. </div>
  253. <?php
  254. }
  255. function current_mobile_theme_info($themes) {
  256. $current_theme_safe = get_current_mobile_theme();
  257. foreach($themes as $k=>$v):
  258. if($v['Template']==$current_theme_safe){
  259. $current_theme = $k;
  260. break;
  261. }else{
  262. $current_theme = ucwords(str_replace("-"," ",$current_theme_safe));
  263. }
  264. endforeach;
  265. $ct->name = $current_theme;
  266. $ct->title = $themes[$current_theme]['Title'];
  267. $ct->version = $themes[$current_theme]['Version'];
  268. $ct->parent_theme = $themes[$current_theme]['Parent Theme'];
  269. $ct->template_dir = $themes[$current_theme]['Template Dir'];
  270. $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir'];
  271. $ct->template = $themes[$current_theme]['Template'];
  272. $ct->stylesheet = $themes[$current_theme]['Stylesheet'];
  273. $ct->screenshot = $themes[$current_theme]['Screenshot'];
  274. $ct->description = $themes[$current_theme]['Description'];
  275. $ct->author = $themes[$current_theme]['Author'];
  276. $ct->tags = $themes[$current_theme]['Tags'];
  277. $ct->theme_root = $themes[$current_theme]['Theme Root'];
  278. $ct->theme_root_uri = $themes[$current_theme]['Theme Root URI'];
  279. return $ct;
  280. }
  281. function get_current_mobile_theme(){
  282. $theme = get_option(WEBSITEZ_ADVANCED_THEME);
  283. return $theme;
  284. }
  285. ?>