PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/blog.old/wp-content/themes/customizr/inc/admin/class-fire-admin_init.php

https://github.com/chopsuei3/oscc
PHP | 361 lines | 215 code | 78 blank | 68 comment | 18 complexity | ea2a2af7ca6415754c566f90cb215e8e MD5 | raw file
  1. <?php
  2. /**
  3. * Init admin actions : loads the meta boxes,
  4. *
  5. *
  6. * @package Customizr
  7. * @subpackage classes
  8. * @since 3.0
  9. * @author Nicolas GUILLAUME <nicolas@themesandco.com>
  10. * @copyright Copyright (c) 2013, Nicolas GUILLAUME
  11. * @link http://themesandco.com/customizr
  12. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  13. */
  14. class TC_admin_init {
  15. //Access any method or var of the class with classname::$instance -> var or method():
  16. static $instance;
  17. function __construct () {
  18. self::$instance =& $this;
  19. global $wp_version;
  20. //check WP version to include customizer functions, must be >= 3.4
  21. if (version_compare( $wp_version, '3.4' , '>=' ) ) {
  22. //require_once( TC_BASE.'inc/admin/tc_customize.php' );
  23. tc__( 'admin' , 'customize' );
  24. }
  25. else {
  26. //adds an information page if version < 3.4
  27. add_action ( 'admin_menu' , array( $this , 'tc_add_fallback_page' ));
  28. }
  29. //load the meta boxes
  30. add_action ( 'admin_init' , array( $this , 'tc_load_meta_boxes' ));
  31. //add welcome page in menu
  32. add_action ( 'admin_menu' , array( $this , 'tc_add_welcome_page' ));
  33. //add help button to admin bar
  34. add_action ( 'wp_before_admin_bar_render' , array( $this , 'tc_add_help_button' ));
  35. //enqueue additional styling for admin screens
  36. add_action ( 'admin_init' , array( $this , 'tc_admin_style' ));
  37. //changelog
  38. add_action ( 'changelog' , array( $this , 'tc_extract_changelog' ));
  39. }
  40. /**
  41. * load the meta boxes for pages, posts and attachment
  42. * @package Customizr
  43. * @since Customizr 3.0.4
  44. */
  45. function tc_load_meta_boxes() {
  46. //loads meta boxes
  47. tc__( 'admin' , 'meta_boxes' );
  48. }
  49. /**
  50. * Add fallback admin page.
  51. * @package Customizr
  52. * @since Customizr 1.1
  53. */
  54. function tc_add_fallback_page() {
  55. $theme_page = add_theme_page(
  56. __( 'Upgrade WP' , 'customizr' ), // Name of page
  57. __( 'Upgrade WP' , 'customizr' ), // Label in menu
  58. 'edit_theme_options' , // Capability required
  59. 'upgrade_wp.php' , // Menu slug, used to uniquely identify the page
  60. array( $this , 'tc_fallback_admin_page' ) //function to be called to output the content of this page
  61. );
  62. }
  63. /**
  64. * Render fallback admin page.
  65. * @package Customizr
  66. * @since Customizr 1.1
  67. */
  68. function tc_fallback_admin_page() {
  69. ?>
  70. <div class="wrap upgrade_wordpress">
  71. <div id="icon-options-general" class="icon32"><br></div>
  72. <h2><?php _e( 'This theme requires WordPress 3.4+' , 'customizr' ) ?> </h2>
  73. <br />
  74. <p style="text-align:center">
  75. <a style="padding: 8px" class="button-primary" href="<?php echo admin_url().'update-core.php' ?>" title="<?php _e( 'Upgrade Wordpress Now' , 'customizr' ) ?>">
  76. <?php _e( 'Upgrade Wordpress Now' , 'customizr' ) ?></a>
  77. <br /><br />
  78. <img src="<?php echo TC_BASE_URL . 'screenshot.png' ?>" alt="Customizr" />
  79. </p>
  80. </div>
  81. <?php
  82. }
  83. /**
  84. * Add fallback admin page.
  85. * @package Customizr
  86. * @since Customizr 1.1
  87. */
  88. function tc_add_welcome_page() {
  89. $theme_page = add_theme_page(
  90. __( 'About Customizr' , 'customizr' ), // Name of page
  91. __( 'About Customizr' , 'customizr' ), // Label in menu
  92. 'edit_theme_options' , // Capability required
  93. 'welcome.php' , // Menu slug, used to uniquely identify the page
  94. array( $this , 'tc_welcome_panel' ) //function to be called to output the content of this page
  95. );
  96. }
  97. /**
  98. * Add help button
  99. * @package Customizr
  100. * @since Customizr 1.0
  101. */
  102. function tc_add_help_button() {
  103. if ( current_user_can( 'edit_theme_options' ) ) {
  104. global $wp_admin_bar;
  105. $wp_admin_bar->add_menu( array(
  106. 'parent' => 'top-secondary', // Off on the right side
  107. 'id' => 'tc-customizr-help' ,
  108. 'title' => __( 'Help' , 'customizr' ),
  109. 'href' => admin_url( 'themes.php?page=welcome.php&help=true' ),
  110. 'meta' => array(
  111. 'title' => __( 'Need help with Customizr? Click here!', 'customizr' ),
  112. ),
  113. ));
  114. }
  115. }
  116. /**
  117. * Render welcome admin page.
  118. * @package Customizr
  119. * @since Customizr 3.0.4
  120. */
  121. function tc_welcome_panel() {
  122. $is_help = isset($_GET['help']) ? true : false;
  123. //CHECK IF WE ARE USING A CHILD THEME
  124. $is_child = tc_is_child();
  125. ?>
  126. <div class="wrap about-wrap">
  127. <?php ?>
  128. <?php if ($is_help) : ?>
  129. <h1 class="need-help-title"><?php _e( 'Need help with Customizr ?','customizr' ) ?></h1>
  130. <?php else : ?>
  131. <h1><?php printf( __( 'Welcome to Customizr %s','customizr' ), CUSTOMIZR_VER ); ?></h1>
  132. <?php endif; ?>
  133. <?php if ($is_help) : ?>
  134. <div class="changelog">
  135. <div class="about-text tc-welcome">
  136. <?php printf( __( 'You can start by watching the <a href="%1$s" target="_blank">introduction video</a> or by reading <a href="%2$s" target="_blank">the documentation</a>.<br/> If you don\'t find an answer to your issue, don\'t panic! Since Customizr is used by a growing community of webmasters reporting bugs and making continuous improvements, you will probably find a solution to your problem either in the FAQ or in the user forum.','customizr' ),
  137. TC_WEBSITE,
  138. TC_WEBSITE.'customizr'
  139. ); ?>
  140. </div>
  141. <div class="feature-section col two-col">
  142. <div>
  143. <br/>
  144. <a class="button-secondary customizr-help" title="documentation" href="<?php echo TC_WEBSITE ?>customizr" target="_blank"><?php _e( 'Read the documentation','customizr' ); ?></a>
  145. </div>
  146. <div class="last-feature">
  147. <br/>
  148. <a class="button-secondary customizr-help" title="faq" href="<?php echo TC_WEBSITE ?>customizr/faq" target="_blank"><?php _e( 'Check the FAQ','customizr' ); ?></a>
  149. </div>
  150. </div><!-- .two-col -->
  151. <div class="feature-section col two-col">
  152. <div>
  153. <a class="button-secondary customizr-help" title="code snippets" href="<?php echo TC_WEBSITE ?>code-snippets/" target="_blank"><?php _e( 'Code snippets','customizr' ); ?></a>
  154. </div>
  155. <div class="last-feature">
  156. <a class="button-secondary customizr-help" title="forum" href="http://wordpress.org/support/theme/customizr" target="_blank"><?php _e( 'Discuss in the user forum','customizr' ); ?></a>
  157. </div>
  158. </div><!-- .two-col -->
  159. </div><!-- .changelog -->
  160. <?php else: ?>
  161. <div class="about-text tc-welcome">
  162. <?php printf( __( 'Thank you for using Customizr! Customizr %1$s has more features, is safer and more stable than ever <a href="#customizr-changelog">(see the changelog)</a> to help you build an awesome website. Watch the <a href="%2$s" target="_blank">introduction video</a> and find inspiration in the <a href="#showcase">showcase</a>.<br/>Enjoy it! ','customizr' ),
  163. CUSTOMIZR_VER,
  164. TC_WEBSITE
  165. ); ?>
  166. </div>
  167. <?php endif; ?>
  168. <?php if ($is_child) : ?>
  169. <div class="changelog point-releases"></div>
  170. <div class="tc-upgrade-notice">
  171. <p>
  172. <?php
  173. printf( __('You are using a child theme of Customizr %1$s : always check the %2$s after upgrading to see if a function or a template has been deprecated.' , 'customizr'),
  174. 'v'.CUSTOMIZR_VER,
  175. '<strong><a href="#customizr-changelog">changelog</a></strong>'
  176. );
  177. ?>
  178. </p>
  179. </div>
  180. <?php endif; ?>
  181. <div class="changelog point-releases"></div>
  182. <div class="changelog">
  183. <div class="feature-section col three-col">
  184. <div>
  185. <h3><?php _e( 'We need sponsors!','customizr' ); ?></h3>
  186. <p><?php _e( '<strong>We do our best do make Customizr the perfect free theme for you!</strong><br/> Please help support it\'s continued development with a donation of $20, $50, or even $100.','customizr' ) ?></br>
  187. <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8CTH6YFDBQYGU" target="_blank" rel="nofollow"><img class="tc-donate" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" alt="Make a donation for Customizr" /></a>
  188. </p>
  189. </div>
  190. <div>
  191. <h3><?php _e( 'Happy user of Customizr?','customizr' ); ?></h3>
  192. <p><?php _e( 'If you are happy with the theme, say it on wordpress.org and give Customizr a nice review! <br />(We are addicted to your feedbacks...)','customizr' ) ?></br>
  193. <a class="button-primary review-customizr" title="Customizr WordPress Theme" href="http://wordpress.org/support/view/theme-reviews/customizr" target="_blank">Review Customizr &raquo;</a></p>
  194. </div>
  195. <div class="last-feature">
  196. <h3><?php _e( 'Follow us','customizr' ); ?></h3>
  197. <p class="tc-follow"><a href="<?php echo TC_WEBSITE.'blog' ?>" target="_blank"><img src="<?php echo TC_BASE_URL.'inc/admin/img/tc.png' ?>" alt="Themes and co" /></a></p>
  198. <!-- Place this tag where you want the widget to render. -->
  199. </div><!-- .feature-section -->
  200. </div><!-- .changelog -->
  201. <div id="dev-box" class="changelog">
  202. <h3 style=""><?php _e('New! Customizr Developer Tools' ,'customizr') ?></h3>
  203. <div class="feature-section images-stagger-right">
  204. <img alt="Customizr developer tools" src="<?php echo TC_BASE_URL.'inc/admin/img/dev-box.jpg' ?>" class="">
  205. <h4><?php _e('Easily drill down into Customizr code with the dev tools!' ,'customizr') ?></h4>
  206. <p><?php _e('A new section called "Dev Tools" has been added to the customizer options.<br/> There you will find two optional new features : <br/><strong>-The developer box</strong> : this draggable box is a developer dashboard allowing you to have an overview of your theme settings (plugins, custom post types, theme options,...) and providing useful informations for debug and development : a loading timeline of any pages, contextual data ( like conditional tags and query), the hook\'s structure of the theme and a note section about the code logic of Customizr.<br/><strong>-The embedded tooltips</strong> : this option displays clickable (and draggable) contextual tooltips right inside your website. They help you understand which part of the php code handles any front-end block or element. The informations provided are : class -> method, hook, file, function description and possible filter.<br/><br/><i>Those tools are only displayed to logged in users with an admin capability profile.</i>' , 'customizr') ?>
  207. </p>
  208. </div>
  209. </div>
  210. <div id="showcase" class="changelog">
  211. <h3 style="text-align:right"><?php _e('Customizr Showcase' ,'customizr') ?></h3>
  212. <div class="feature-section images-stagger-left">
  213. <a class="" title="<?php _e('Visit the showcase','customizr') ?>" href="<?php echo TC_WEBSITE ?>customizr/showcase/" target="_blank"><img alt="Customizr Showcase" src="<?php echo TC_BASE_URL.'inc/admin/img/mu2.jpg' ?>" class=""></a>
  214. <h4 style="text-align: right"><?php _e('Find inspiration for your next Customizr based website!' ,'customizr') ?></h4>
  215. <p style="text-align: right"><?php _e('This showcase aims to show what can be done with Customizr and helping other users to find inspiration for their web design.' , 'customizr') ?>
  216. </p>
  217. <p style="text-align: right"><?php _e('Do you think you made an awesome website that can inspire people? Submitting a site for review is quick and easy to do.' , 'customizr') ?></br>
  218. </p>
  219. <p style="text-align:right">
  220. <a class="button-primary review-customizr" title="<?php _e('Visit the showcase','customizr') ?>" href="<?php echo TC_WEBSITE ?>customizr/showcase/" target="_blank"><?php _e('Visit the showcase','customizr') ?> &raquo;</a>
  221. </p>
  222. </div>
  223. </div>
  224. <div id="customizr-changelog" class="changelog">
  225. <h3><?php printf( __( 'Changelog in version %1$s' , 'customizr' ) , CUSTOMIZR_VER ); ?></h3>
  226. <p><?php do_action('changelog'); ?></p>
  227. </div>
  228. <div class="return-to-dashboard">
  229. <a href="<?php echo esc_url( self_admin_url() ); ?>"><?php
  230. is_blog_admin() ? _e( 'Go to Dashboard &rarr; Home','customizr' ) : _e( 'Go to Dashboard','customizr' ); ?></a>
  231. </div>
  232. </div>
  233. <?php
  234. }
  235. /**
  236. * enqueue additional styling for admin screens
  237. * @package Customizr
  238. * @since Customizr 3.0.4
  239. */
  240. function tc_admin_style() {
  241. wp_enqueue_style( 'admincss' , TC_BASE_URL.'inc/admin/css/tc_admin.css' );
  242. }
  243. /**
  244. * Extract changelog of latest version from readme.txt file
  245. * @package Customizr
  246. * @since Customizr 3.0.5
  247. */
  248. function tc_extract_changelog() {
  249. if( !file_exists(TC_BASE."readme.txt") ) {
  250. return;
  251. }
  252. if( !is_readable(TC_BASE."readme.txt") ) {
  253. echo '<p>The changelog in readme.txt is not readable.</p>';
  254. return;
  255. }
  256. $stylelines = explode("\n", implode('', file(TC_BASE."readme.txt")));
  257. $read = false;
  258. $i = 0;
  259. foreach ($stylelines as $line) {
  260. //echo 'i = '.$i.'|read = '.$read.'pos = '.strpos($line, '= ').'|line :'.$line.'<br/>';
  261. //we stop reading if we reach the next version change
  262. if ($i == 1 && strpos($line, '= ') === 0 ) {
  263. $read = false;
  264. $i = 0;
  265. }
  266. //we write the line if between current and previous version
  267. if ($read) {
  268. echo $line.'<br/>';
  269. }
  270. //we skip all lines before the current version changelog
  271. if ($line != strpos($line, '= '.CUSTOMIZR_VER.' =')) {
  272. if ($i == 0) {
  273. $read = false;
  274. }
  275. }
  276. //we begin to read after current version title
  277. else {
  278. $read = true;
  279. $i = 1;
  280. }
  281. }
  282. }
  283. }//end of class