Ticket #688: glotpress.diff
| File glotpress.diff, 3.0 KB (added by , 11 years ago) |
|---|
-
sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-help/wporg-help.php
1 1 <?php 2 2 3 3 class GP_Help_Page_Plugin extends GP_Plugin { 4 var $id = 'wporg-help'; 5 var $hide_notice = 'wporg-help-hide-notice'; 6 4 public $id = 'wporg-help'; 5 private $hide_notice = 'wporg-help-hide-notice'; 6 const $handbook_link = 'https://make.wordpress.org/polyglots/handbook/tools/glotpress-translate-wordpress-org/'; 7 7 8 function __construct() { 8 9 parent::__construct(); 9 10 $this->template_path = dirname( __FILE__ ); … … 11 12 $this->add_action( 'after_hello' ); 12 13 $this->add_action( 'after_notices' ); 13 14 } 14 15 15 16 function init() { 16 GP::$router->add( '/getting-started', array('GP_Help_Page_Plugin_Route', 'getting_started') );17 17 GP::$router->add( '/getting-started/hide-notice', array('GP_Help_Page_Plugin_Route', 'hide_notice') ); 18 18 } 19 19 20 20 function after_hello() { 21 21 if ( GP::$user->logged_in() || $this->is_notice_hidden() ) { 22 echo '<em><a class="secondary" href="' .gp_url('/getting-started').'">Need help?</a></em>';22 echo '<em><a class="secondary" href="' . self::handbook_link . '">Need help?</a></em>'; 23 23 } 24 24 } 25 25 26 26 function is_notice_hidden() { 27 27 return ( gp_array_get( $_COOKIE, $this->hide_notice ) || ( GP::$user->logged_in() && GP::$user->get_meta( $this->hide_notice ) ) ); 28 28 } 29 29 30 30 function hide_notice() { 31 31 if ( GP::$user->logged_in() ) { 32 32 GP::$user->set_meta( $this->hide_notice, true ); 33 33 } 34 34 setcookie( $this->hide_notice, '1', time() + 3600*24*30, gp_url( '/' ) ); // a month 35 35 } 36 36 37 37 function after_notices() { 38 38 if ( $this->is_notice_hidden() ) return; 39 39 $hide_url = gp_url( '/getting-started/hide-notice' ); 40 40 ?> 41 41 <div class="notice" id="help-notice"> 42 42 New to <em>translate.wordpress.org</em>? 43 Have a look at the <a href="<?php echo esc_url( gp_url( '/getting-started' ) ); ?>">Getting Started guide.</a>43 Have a look at the <a href="<?php echo self::handbook_link; ?>" target="_blank">Getting Started guide.</a> 44 44 <a id="hide-help-notice" class="secondary" style="float: right;" href="<?php echo esc_url( $hide_url ); ?>">Hide</a> 45 45 </div> 46 46 <script type="text/javascript"> … … 52 52 </script> 53 53 <?php 54 54 } 55 55 56 56 } 57 57 58 58 class GP_Help_Page_Plugin_Route extends GP_Route { 59 59 60 function __construct() { 60 61 parent::__construct(); 61 62 $this->template_path = GP::$plugins->wporg_help->template_path; 62 63 } 63 64 64 65 function getting_started() { 65 GP::$plugins->wporg_help->remove_action( 'after_notices' ); 66 $this->tmpl( 'getting-started' ); 66 GP::$plugins->wporg_help->remove_action( 'after_notices' ); 67 68 gp_redirect( GP_Help_Page_Plugin::link ); 69 exit; 67 70 } 68 71 69 72 function hide_notice() { 70 73 GP::$plugins->wporg_help->hide_notice(); 71 74 } 75 72 76 } 73 77 74 78 GP::$plugins->wporg_help = new GP_Help_Page_Plugin;