Ticket #14703: wp_thank_you.diff

File wp_thank_you.diff, 8.6 KB (added by johnjamesjacoby, 3 years ago)

What about an 'About' page with a little license loader?

  • wp-thank-you.php

     
     1<?php 
     2/** 
     3 * Plugin Name: WP About 
     4 * Plugin URI:  
     5 * Description: Adds About TLM 
     6 * Author:  
     7 * Version: 0.1 
     8 */ 
     9 
     10function wph_about_page() { ?> 
     11        <div class="wrap"> 
     12                <?php screen_icon( 'options-general' ); ?> 
     13                <h2><?php _e( 'About', 'wph' ); ?></h2> 
     14 
     15                <?php do_action( 'wph_about_page' ); ?> 
     16 
     17        </div> 
     18<?php 
     19} 
     20 
     21function wph_admin_menu() { 
     22        $base_page = 'wph-about-page'; 
     23 
     24        // Top Level Page 
     25        add_utility_page( __( 'About', 'wph' ), __( 'About', 'wph' ), 'read_post', $base_page, array(), '' ); 
     26 
     27        // Add About page to bottom 
     28        add_submenu_page( $base_page, __( 'About', 'wph' ), __( 'About', 'wph' ), 'read_post', 'wph-about-page', 'wph_about_page' ); 
     29 
     30        // Allow plugins to hook in 
     31        do_action( 'wph_admin_menu' ); 
     32} 
     33add_action( 'admin_menu', 'wph_admin_menu' ); 
     34 
     35function wpty_admin_footer_text( $admin_footer_text ) { 
     36        $admin_footer_text .= sprintf( __( ' | <a href="%s">About</a>', 'wpl' ), add_query_arg( array( 'page' => 'wph-about-page' ), admin_url( 'admin.php') ) ); 
     37 
     38        return $admin_footer_text; 
     39} 
     40add_filter( 'admin_footer_text', 'wpty_admin_footer_text' ); 
     41 
     42function _wp_core_wpty_add() { 
     43        wpty_add( 'WordPress Core', 'Kind of a big deal...',     'http://wordpress.org/',         site_url() . '/license.txt',                     'GPL 2' ); 
     44        wpty_add( 'TwentyTen',      'Default WordPress theme',   'http://wordpress.org/',         content_url() . '/themes/twentyten/license.txt', 'GPL 2' ); 
     45        wpty_add( 'TinyMCE',        'WYSIWYG Editor',            'http://tinymce.moxiecode.com/', includes_url() . '/js/tinymce/license.txt',      'GPL 2.1' ); 
     46} 
     47add_action( 'admin_init', '_wp_core_wpty_add' ); 
     48 
     49function _wp_core_wpty_about_page() { 
     50 
     51        if ( wpty_has_projects() ) : ?> 
     52 
     53                <h3><?php _e( 'Projects', 'wph' ); ?></h3> 
     54                <p><?php _e( 'WordPress is made up of many smaller projects. Here are a few of them.', 'wph' ); ?></p> 
     55                <ol class="item-list" style="float: left; width: 20%;"> 
     56                <?php while ( wpty_projects() ) : wpty_the_project(); ?> 
     57 
     58                        <li> 
     59                                <h4><a href="<?php wpty_project_link(); ?>" target="wph-license"><?php wpty_project_name(); ?></a></h4> 
     60                                <div class="item"> 
     61                                        <p class="description"><?php wpty_project_message(); ?></p> 
     62                                        <a href="<?php wpty_project_license_path(); ?>" target="wph-license"><?php _e( 'View License &rarr;', 'wph' ); ?></a> 
     63                                </div> 
     64                        </li> 
     65 
     66                <?php endwhile; ?> 
     67                </ol> 
     68 
     69                <iframe src="<?php echo site_url() . '/license.txt'; ?>" name="wph-license" width="65%" height="500px" style="border: 1px solid #bbb; background-color: #fff; margin-bottom: 15px;"></iframe> 
     70 
     71        <?php else : ?> 
     72 
     73                <div id="message" class="info"> 
     74                        <p><?php _e( 'There were no projects found. This is probably wrong.', 'wph' ); ?></p> 
     75                </div> 
     76 
     77        <?php endif; 
     78 
     79} 
     80add_action( 'wph_about_page', '_wp_core_wpty_about_page' ); 
     81 
     82/** 
     83 * WP_Thank_You 
     84 * 
     85 * Container for internal WordPress projects and their licenses 
     86 */ 
     87class WP_Thank_You { 
     88        var $projects = array(); 
     89        var $total; 
     90 
     91        function WP_Thank_You() { 
     92                do_action( 'wp_thank_you' ); 
     93        } 
     94 
     95        function add( $project, $message, $link, $license_path, $license_type ) { 
     96 
     97                if ( empty( $project ) || empty( $message ) || empty( $license_type ) ) 
     98                        return false; 
     99 
     100                if ( !in_array( $project, $this->projects ) ) 
     101                        $this->projects[] = array( $project, $message, $link, $license_path, $license_type ); 
     102 
     103                $this->total = (int)$this->total + 1; 
     104        } 
     105 
     106        function remove( $project ) { 
     107                if ( isset( $this->projects[$project] ) ) 
     108                        unset( $this->projects[$project] ); 
     109 
     110                $this->total = (int)$this->total - 1; 
     111        } 
     112} 
     113 
     114// I want to thank you, for giving me, time to breath... :) 
     115$wpty = new WP_Thank_You(); 
     116 
     117/** 
     118 * wpty_add 
     119 * 
     120 * Add an internal project to the global Thank You 
     121 * 
     122 * @global WP_Thank_You $wph 
     123 * @param string $project 
     124 * @param string $message 
     125 * @param string $license_path 
     126 * @param string $license_type 
     127 */ 
     128function wpty_add( $project, $message, $link, $license_path, $license_type ) { 
     129        global $wpty; 
     130 
     131        $wpty->add( $project, $message, $link, $license_path, $license_type ); 
     132} 
     133 
     134/** 
     135 * wpty_remove 
     136 * 
     137 * Remove an internal project from the global Thank You 
     138 * 
     139 * @global WP_Thank_You $wph 
     140 * @param string $project 
     141 */ 
     142function wpty_remove( $project ) { 
     143        global $wpty; 
     144 
     145        $wpty->remove( $project ); 
     146} 
     147 
     148/** THANK YOU TEMPLATE TAGS **/ 
     149 
     150class WP_Thank_You_Template { 
     151        var $current_project = -1; 
     152        var $project_count; 
     153        var $projects; 
     154        var $project; 
     155 
     156        var $in_the_loop; 
     157 
     158        var $pag_page; 
     159        var $pag_num; 
     160        var $pag_links; 
     161        var $total_project_count; 
     162 
     163        var $sort_by; 
     164        var $order; 
     165 
     166        function WP_Thank_You_Template( $page, $per_page, $max, $search_terms ) { 
     167                global $wpty; 
     168 
     169                $this->pag_page = isset( $_REQUEST['typage'] ) ? intval( $_REQUEST['typage'] ) : $page; 
     170                $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; 
     171 
     172                $this->projects = $wpty->projects; 
     173 
     174                if ( !$max || $max >= (int)$wpty->projects['total'] ) 
     175                        $this->total_project_count = (int)$wpty->projects['total']; 
     176                else 
     177                        $this->total_project_count = (int)$max; 
     178 
     179                if ( $max ) { 
     180                        if ( $max >= count($this->projects) ) { 
     181                                $this->project_count = count( $this->projects ); 
     182                        } else { 
     183                                $this->project_count = (int)$max; 
     184                        } 
     185                } else { 
     186                        $this->project_count = count( $this->projects ); 
     187                } 
     188 
     189                // Build pagination links 
     190                if ( (int)$this->total_project_count && (int)$this->pag_num ) { 
     191                        $this->pag_links = paginate_links( array( 
     192                                'base'      => add_query_arg( array( 'typage' => '%#%', 'num' => $this->pag_num, 's' => $search_terms, 'sortby' => $this->sort_by, 'order' => $this->order ) ), 
     193                                'format'    => '', 
     194                                'total'     => ceil( (int)$this->total_project_count / (int)$this->pag_num ), 
     195                                'current'   => $this->pag_page, 
     196                                'prev_text' => '&larr;', 
     197                                'next_text' => '&rarr;', 
     198                                'mid_size'  => 1 
     199                        ) ); 
     200                } 
     201        } 
     202 
     203        function has_projects() { 
     204                if ( $this->project_count ) 
     205                        return true; 
     206 
     207                return false; 
     208        } 
     209 
     210        function next_project() { 
     211                $this->current_project++; 
     212                $this->project = $this->projects[$this->current_project]; 
     213 
     214                return $this->project; 
     215        } 
     216 
     217        function rewind_projects() { 
     218                $this->current_project = -1; 
     219                if ( $this->project_count > 0 ) 
     220                        $this->project = $this->projects[0]; 
     221        } 
     222 
     223        function projects() { 
     224                if ( $this->current_project + 1 < $this->project_count ) { 
     225                        return true; 
     226                } elseif ( $this->current_project + 1 == $this->project_count ) { 
     227                        do_action( 'loop_end' ); 
     228                        // Do some cleaning up after the loop 
     229                        $this->rewind_projects(); 
     230                } 
     231 
     232                $this->in_the_loop = false; 
     233                return false; 
     234        } 
     235 
     236        function the_project() { 
     237                $this->in_the_loop = true; 
     238                $this->project     = $this->next_project(); 
     239 
     240                if ( 0 == $this->current_project ) // loop has just started 
     241                        do_action( 'loop_start' ); 
     242        } 
     243} 
     244 
     245function wpty_has_projects ( $args = '' ) { 
     246        global $wpty, $wpty_template; 
     247 
     248        $defaults = array( 
     249                'page'         => 1, 
     250                'per_page'     => 20, 
     251                'max'          => false, 
     252                'search_terms' => '', 
     253        ); 
     254 
     255        $r = wp_parse_args( $args, $defaults ); 
     256        extract( $r ); 
     257 
     258        $wpty_template = new WP_Thank_You_Template( $page, $per_page, $max, $search_terms ); 
     259 
     260        return apply_filters( 'wpty_has_projects', $wpty_template->projects, &$wpty_template ); 
     261} 
     262 
     263function wpty_the_project () { 
     264        global $wpty_template; 
     265        return $wpty_template->the_project(); 
     266} 
     267 
     268function wpty_projects() { 
     269        global $wpty_template; 
     270        return $wpty_template->projects(); 
     271} 
     272 
     273function wpty_project_name () { 
     274        echo wpty_get_project_name(); 
     275} 
     276        function wpty_get_project_name () { 
     277                global $wpty_template; 
     278                return apply_filters( 'wpty_get_project_name', $wpty_template->project[0] ); 
     279        } 
     280 
     281function wpty_project_message () { 
     282        echo wpty_get_project_message(); 
     283} 
     284        function wpty_get_project_message () { 
     285                global $wpty_template; 
     286                return apply_filters( 'wpty_get_project_message', $wpty_template->project[1] ); 
     287        } 
     288 
     289function wpty_project_link () { 
     290        echo wpty_get_project_link(); 
     291} 
     292        function wpty_get_project_link () { 
     293                global $wpty_template; 
     294                return apply_filters( 'wpty_get_project_link', $wpty_template->project[2] ); 
     295        } 
     296 
     297function wpty_project_license_path () { 
     298        echo wpty_get_project_license_path(); 
     299} 
     300        function wpty_get_project_license_path () { 
     301                global $wpty_template; 
     302                return apply_filters( 'wpty_get_project_license_path', $wpty_template->project[3] ); 
     303        } 
     304 
     305function wpty_project_license_type () { 
     306        echo wpty_get_project_license_type(); 
     307} 
     308        function wpty_get_project_license_type () { 
     309                global $wpty_template; 
     310                return apply_filters( 'wpty_get_project_license_type', $wpty_template->project[4] ); 
     311        } 
     312 
     313/** END THANK YOU TEMPLATE TAGS **/ 
     314 
     315?>