post_type = apply_filters( 'i-make-plugins__post_type', $this->post_type ); load_plugin_textdomain( 'cws-imp', '', plugin_basename( dirname( __FILE__ ) ) ); // Add our default options add_option( 'cws_imp_plugin_list_template', "
[implist_desc]
\nThe templating system is based on WordPress Shortcodes, which look like HTML tags but with square brackets.
Any of the shortcodes can be turned into a conditional wrapper by adding if_ or if_not_to the front of the tag. So to test [implist_version], you could wrap some code in [if_implist_version] ... [/if_implist_version].
Some loop tags can be used in a self-closing form, in which case the plugin will generate the HTML for you. You only have to use the advanced loop format if you want to choose your own HTML for the loop.
', 'cws-imp' ); } function field_container_page() { wp_dropdown_pages( array( 'name' => 'cws_imp_container_id', 'echo' => 1, 'show_option_none' => __('- Select -'), 'selected' => get_option( 'cws_imp_container_id' ) ) ); ?> This controls what will be displayed on the container page. You can use the following tags to loop through the plugins:[implist]—[/implist]
Within that loop, you can use the following tags:
[implist_name] [implist_url] [implist_version] [implist_desc] [implist_zip_url] [implist_banner-772x250]
[imp_name] [imp_url] [imp_zip_url] [imp_full_desc] [imp_version] [imp_banner-772x250] [imp_changelog] [imp_faq] [imp_installation] [imp_min_version] [imp_tested_version] [imp_slug] [imp_downloads] [imp_screenshots] [imp_other_notes]
An example advanced FAQ loop format is as follows:
[imp_faq]
—Q. [imp_faq_question]
—A. [imp_faq_answer][/imp_faq]
An example advanced Changelog loop format is as follows:
[imp_changelog]
—[imp_changelog_version]
——[imp_changelog_changes]
———[imp_changelog_change]
——[/imp_changelog_changes][/imp_changelog]
' . __( 'Normally the plugin slug is determined by the slug of this page, but you can override it here. It should exactly match the slug used in the WordPress.org plugin repository.', 'cws-imp' ) . '
'; ?>0 ) update_post_meta( $id, '_cws_imp_slug', stripslashes( $_REQUEST['cws_imp_slug'] ) ); else delete_post_meta( $id, '_cws_imp_slug' ); } return $id; } function get_list_page_id() { return get_option( 'cws_imp_container_id' ); } function get_plugins() { $options = apply_filters( 'i-make-plugins__get_plugins', array( 'post_type' => $this->post_type, 'post_parent' => $this->get_list_page_id(), 'showposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ) ); return new WP_Query( $options ); } function get_plugin_description( $page_id ) { $readme = $this->get_plugin_readme( $page_id ); if ( isset( $readme->short_description ) && !empty( $readme->short_description ) ) return $readme->short_description; else return ' '; // Why a space? Must investigate further } function get_plugin_slug( $post ) { $post = get_post( $post ); $postmeta_slug = get_post_meta( $post->ID, '_cws_imp_slug', true ); $slug = ( $postmeta_slug ) ? $postmeta_slug : $post->post_name; return $slug; } function get_plugin_readme( $page_id, $force_update = false ) { $slug = $this->get_plugin_slug( $page_id ); if ( !$force_update ) { // First, try in-memory cache if ( isset( $this->cache[$slug] ) ) return $this->cache[$slug]; // Next, try postmeta cache $ts = get_post_meta( $page_id, '_cws_imp_readme_timestamp', true ); $rm = get_post_meta( $page_id, '_cws_imp_readme', true ); // We force a dynamic update after two hours // Note that we have a cron job that ideally does this once an hour if ( $rm && $ts && $ts > time() - 7200 ) { // fresh $this->cache[$slug] = $rm; return $this->cache[$slug]; } } // Fetch via API require_once( ABSPATH . '/wp-admin/includes/plugin-install.php' ); $readme = plugins_api( 'plugin_information', array('slug' => $slug, 'fields' => array( 'short_description' => true ) ) ); if ( is_wp_error( $readme ) ) return false; $readme->banners = array( '772x250' => $this->get_banner_url( $page_id, '772x250' ) ); $this->cache[$slug] = $readme; update_post_meta( $page_id, '_cws_imp_readme', $readme ); update_post_meta( $page_id, '_cws_imp_readme_timestamp', time() ); return $readme; } function update_plugins() { $plugins = $this->get_plugins(); if( $plugins->have_posts() ) { foreach ( $plugins->posts as $p ) { $this->get_plugin_readme( $p->ID, true ); } } } function get_readme_url( $slug, $tag ) { if ( 'trunk' == $tag ) return 'http://plugins.svn.wordpress.org/' . $slug . '/trunk/readme.txt'; else return 'http://plugins.svn.wordpress.org/' . $slug . '/tags/' . $tag . '/readme.txt'; } function get_banner_url( $post, $dimension_string = '772x250' ) { $slug = $this->get_plugin_slug( $post ); if ( !$slug ) return false; foreach ( array( 'png', 'jpg' ) as $extension ) { $url = "http://plugins.svn.wordpress.org/{$slug}/assets/banner-{$dimension_string}.{$extension}"; $result = wp_remote_head( $url ); if ( !is_wp_error( $result ) && 200 == $result['response']['code'] ) return $url; } return false; } function plugin_list_html() { global $post; $temp_post = $post; // Backup $return = do_shortcode( get_option( 'cws_imp_plugin_list_template' ) ); $post = $temp_post; // Restore return $return; } function shortcode( $atts, $content, $tag ) { global $post; $this->readme = $this->get_plugin_readme( $post->ID ); // fetch it, just in case we need it. $return = ''; switch ( $tag ) : case 'implist' : return $this->shortcode_implist( $atts, $content, $tag ); break; case 'imp_name' : case 'implist_name' : return get_the_title(); break; case 'imp_version' : case 'implist_version' : return isset( $this->readme->version ) ? $this->readme->version : ''; break; case 'imp_url' : case 'implist_url' : return get_permalink(); break; case 'implist_desc' : return $post->post_excerpt; break; case 'implist_zip_url' : case 'imp_zip_url' : return isset( $this->readme->download_link ) ? $this->readme->download_link : ''; break; case 'imp_full_desc' : return isset( $this->readme->sections['description'] ) ? $this->readme->sections['description'] : ''; break; case 'imp_installation' : return isset( $this->readme->sections['installation'] ) ? $this->readme->sections['installation'] : ''; break; case 'imp_screenshots' : return isset( $this->readme->sections['screenshots'] ) ? $this->readme->sections['screenshots'] : ''; break; case 'imp_other_notes' : return isset( $this->readme->sections['other_notes'] ) ? $this->readme->sections['other_notes'] : ''; break; case 'imp_changelog' : if ( isset( $this->readme->sections['changelog'] ) ) { $this->changes = $this->parse_changelog( $this->readme->sections['changelog'] ); if ( $content ) { $shortcodes = array( 'imp_changelog_version', 'imp_changelog_changes', 'imp_changelog_change' ); $this->add_shortcodes( $shortcodes ); foreach ( (array) $this->changes as $this->current_changelog_v => $this->current_changes ) $return .= do_shortcode( $content ); $this->remove_shortcodes( $shortcodes ); unset( $this->current_changelog_v, $this->current_changes, $this->current_change ); return $return; } else { return $this->output_changelog( $this->changes ); } } break; case 'imp_changelog_version' : return $this->current_changelog_v; break; case 'imp_changelog_changes' : $shortcodes = array( 'imp_changelog_change' ); foreach ( (array) $this->current_changes as $this->current_change ) $return .= do_shortcode( $content ); return $return; break; case 'imp_changelog_change' : return $this->current_change; break; case 'imp_faq' : if ( isset( $this->readme->sections['faq'] ) ) { $imp_faqs = $this->parse_faq( $this->readme->sections['faq'] ); if ( $content ) { $shortcodes = array( 'imp_faq_question', 'imp_faq_answer' ); $this->add_shortcodes( $shortcodes ); foreach ( $imp_faqs as $this->current_faq => $this->current_faq_answer ) $return .= do_shortcode( $content ); $this->remove_shortcodes( $shortcodes ); unset( $this->current_faq, $this->current_faq_answer ); return $return; } else { return $this->output_faq( $imp_faqs ); } } break; case 'imp_faq_question' : return $this->current_faq; break; case 'imp_faq_answer' : return $this->current_faq_answer; break; case 'imp_min_version' : return isset( $this->readme->requires ) ? $this->readme->requires : ''; break; case 'imp_tested_version' : return isset( $this->readme->tested ) ? $this->readme->tested : ''; break; case 'imp_slug' : return isset( $this->readme->slug ) ? $this->readme->slug : ''; break; case 'imp_downloads' : return isset( $this->readme->downloaded ) ? $this->readme->downloaded : ''; break; case 'imp_banner-772x250' : case 'implist_banner-772x250' : return isset( $this->readme->banners['772x250'] ) ? $this->readme->banners['772x250'] : ''; break; endswitch; } function shortcode_conditional( $atts, $content, $tag ) { $test_tag = preg_replace( '#^if_#', '', $tag ); $test_output = $this->shortcode( NULL, NULL, $test_tag ); if ( !empty( $test_output ) ) return do_shortcode( $content ); } function shortcode_negative_conditional( $atts, $content, $tag ) { $test_tag = preg_replace( '#^if_not_#', '', $tag ); $test_output = $this->shortcode( NULL, NULL, $test_tag ); if ( empty( $test_output ) ) return do_shortcode( $content ); } function shortcode_implist( $atts, $content = NULL ) { global $post; $plugins = $this->get_plugins(); $return = ''; while ( $plugins->have_posts() ) : $plugins->the_post(); if ( get_post_meta( $post->ID, '_cws_imp_retired_plugin', true ) ) continue; // TO-DO: UI for this $desc = trim( $this->get_plugin_description( $post->ID ) ); if ( !empty( $desc ) ) $post->post_excerpt = $desc; $return .= do_shortcode( $content ); endwhile; return $return; } function add_shortcodes( $array ) { foreach ( (array) $array as $shortcode ) { $conditional = 'if_' . $shortcode; $negative_conditional = 'if_not_' . $shortcode; add_shortcode( $shortcode, array( $this, 'shortcode' ) ); add_shortcode( $conditional, array( $this, 'shortcode_conditional' ) ); add_shortcode( $negative_conditional, array( $this, 'shortcode_negative_conditional' ) ); } } function remove_shortcodes( $array ) { foreach ( (array) $array as $shortcode ) { $conditional = 'if_' . $shortcode; remove_shortcode( $shortcode ); remove_shortcode( $conditional ); } } function plugins_list( $content = '' ) { global $post; if ( ( isset( $this->prevent_recursion ) && $this->prevent_recursion ) || $post->ID != $this->get_list_page_id() ) { return $content; } else { $this->prevent_recursion = true; $shortcodes = array( 'implist', 'implist_name', 'implist_url', 'implist_version', 'implist_desc', 'implist_zip_url', 'implist_banner-772x250' ); $this->add_shortcodes( $shortcodes ); $content = $this->plugin_list_html() . $content; $this->remove_shortcodes( $shortcodes ); $this->prevent_recursion = false; return $content; } } function parse_faq( $faq ) { $faq = preg_split( '#
', '
' ), array( '', '' ), $a ) ); $questions[$q] = $a; } return $questions; } function output_faq( $questions ) { $return = ''; foreach ( (array) $questions as $q => $a ) { $return .= 'Q. ' . $q . '' . "\n"; $return .= 'A. ' . $a . "\n\n"; } return $return; } function parse_changelog( $changelog ) { $changelog = preg_split( "#This plugin has been marked as retired. It is recommended that you no longer use it.
', 'cws-imp' ); if ( $this->is_plugin( $post ) ) { $this->readme = $this->get_plugin_readme( $post->ID ); if ( $this->readme ) { $shortcodes = array( 'imp_name', 'imp_url', 'imp_zip_url', 'imp_full_desc', 'imp_installation', 'imp_changelog', 'imp_faq', 'imp_version', 'imp_min_version', 'imp_tested_version', 'imp_slug', 'imp_downloads', 'imp_screenshots', 'imp_other_notes', 'imp_banner-772x250' ); $this->add_shortcodes( $shortcodes ); $content = ''; $content .= do_shortcode( get_option( 'cws_imp_plugin_template' ) ); $this->remove_shortcodes( $shortcodes ); } $content = apply_filters( 'cws_imp_plugin_body', $content ); } return $content; } function admin_menu() { $hook = add_options_page( __( 'I Make Plugins', 'cws-imp' ), __( 'I Make Plugins', 'cws-imp' ), 'manage_options', 'cws-imp', array( $this, 'options_page' ) ); } function options_page() { ?>