'page', 'post_parent' => $parent_id, 'showposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ) ); } function cws_imp_get_plugin_description( $page_id ) { $readme = cws_imp_get_plugin_readme( $page_id ); if ( $readme ) return $readme->short_description; else return ' '; // Why a space? Must investigate further } function cws_imp_get_plugin_readme( $page_id ) { $page = get_page( $page_id ); $slug = $page->post_name; global $cws_imp_readme_cache; // First, try in-memory cache if ( isset( $cws_imp_readme_cache[$slug] ) ) return $cws_imp_readme_cache[$slug]; // Next, try postmeta cache if ( $ts = get_post_meta( $page_id, '_cws_imp_readme_timestamp', true ) && $ts > time() - 3600 && $rm = get_post_meta( $page_id, '_cws_imp_readme', true ) ) { // fresh $cws_imp_readme_cache[$slug] = unserialize($rm); return $rm; } // 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; $cws_imp_readme_cache[$slug] = $readme; update_post_meta( $page_id, '_cws_imp_readme', serialize( $readme ) ); update_post_meta( $page_id, '_cws_imp_readme_timestamp', time() ); return $readme; } function cws_imp_get_readme_url( $slug, $tag ) { if ( 'trunk' == $tag ) return 'http://svn.wp-plugins.org/' . $slug . '/trunk/readme.txt'; else return 'http://svn.wp-plugins.org/' . $slug . '/tags/' . $tag . '/readme.txt'; } function cws_imp_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; } /* [imp*] shortcodes */ function cws_imp_shortcode( $atts, $content, $tag ) { global $post, $imp_readme, $imp_current_faq, $imp_current_faq_answer, $imp_current_changelog_v, $imp_current_changes, $imp_current_change; $imp_readme = cws_imp_get_plugin_readme( $post->ID ); // fetch it, just in case we need it. $return = ''; switch ( $tag ) : case 'implist' : return cws_imp_shortcode_implist( $atts, $content, $tag ); break; case 'imp_name' : case 'implist_name' : return get_the_title(); break; case 'imp_version' : case 'implist_version' : return $imp_readme->version; break; case 'imp_url' : case 'implist_url' : return get_permalink(); break; case 'implist_desc' : return $post->post_excerpt; break; case 'imp_zip_url' : if ( isset( $imp_readme->download_link ) ) return $imp_readme->download_link; break; case 'imp_full_desc' : if ( isset( $imp_readme->sections['description'] ) ) return $imp_readme->sections['description']; break; case 'imp_installation' : if ( isset( $imp_readme->sections['installation'] ) ) return $imp_readme->sections['installation']; break; case 'imp_changelog' : if ( isset( $imp_readme->sections['changelog'] ) ) { $imp_changes = cws_imp_parse_changelog( $imp_readme->sections['changelog'] ); if ( $content ) { $shortcodes = array( 'imp_changelog_version', 'imp_changelog_changes', 'imp_changelog_change' ); cws_imp_add_shortcodes( $shortcodes ); foreach ( (array) $imp_changes as $imp_current_changelog_v => $imp_current_changes ) $return .= do_shortcode( $content ); cws_imp_remove_shortcodes( $shortcodes ); unset( $imp_current_changelog_v, $imp_current_changes, $imp_current_change ); return $return; } else { return cws_imp_output_changelog( $imp_changes ); } } break; case 'imp_changelog_version' : return $imp_current_changelog_v; break; case 'imp_changelog_changes' : $shortcodes = array( 'imp_changelog_change' ); foreach ( (array) $imp_current_changes as $imp_current_change ) $return .= do_shortcode( $content ); return $return; break; case 'imp_changelog_change' : return $imp_current_change; break; case 'imp_faq' : if ( isset( $imp_readme->sections['faq'] ) ) { $imp_faqs = cws_imp_parse_faq( $imp_readme->sections['faq'] ); if ( $content ) { $shortcodes = array( 'imp_faq_question', 'imp_faq_answer' ); cws_imp_add_shortcodes( $shortcodes ); foreach ( $imp_faqs as $imp_current_faq => $imp_current_faq_answer ) $return .= do_shortcode( $content ); cws_imp_remove_shortcodes( $shortcodes ); unset( $imp_current_faq, $imp_current_faq_answer ); return $return; } else { return cws_imp_output_faq( $imp_faqs ); } } break; case 'imp_faq_question' : return $imp_current_faq; break; case 'imp_faq_answer' : return $imp_current_faq_answer; break; case 'imp_min_version' : return $imp_readme->requires; break; case 'imp_tested_version' : return $imp_readme->tested; break; case 'imp_slug' : return $imp_readme->slug; break; case 'imp_downloads' : return $imp_readme->downloaded; break; endswitch; } function cws_imp_shortcode_conditional( $atts, $content, $tag ) { $test_tag = preg_replace( '#^if_#', '', $tag ); $test_output = cws_imp_shortcode( NULL, NULL, $test_tag ); if ( !empty( $test_output ) ) return do_shortcode( $content ); } function cws_imp_shortcode_implist( $atts, $content = NULL ) { global $post; $plugins = cws_imp_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 $post->post_excerpt = trim( cws_imp_get_plugin_description( $post->ID ) ); if ( empty( $post->post_excerpt ) ) $post->post_excerpt = __( 'No description', 'cws-imp' ); $return .= do_shortcode( $content ); endwhile; return $return; } function cws_imp_add_shortcodes( $array ) { foreach ( (array) $array as $shortcode ) { $conditional = 'if_' . $shortcode; add_shortcode( $shortcode, 'cws_imp_shortcode' ); add_shortcode( $conditional, 'cws_imp_shortcode_conditional' ); } } function cws_imp_remove_shortcodes( $array ) { foreach ( (array) $array as $shortcode ) { $conditional = 'if_' . $shortcode; remove_shortcode( $shortcode ); remove_shortcode( $conditional ); } } function cws_imp_plugins_list( $content ) { global $post, $cws_imp_prevent_recursion; if ( ( isset( $cws_imp_prevent_recursion ) && $cws_imp_prevent_recursion ) || $post->ID != cws_imp_get_plugin_list_page_id() ) { return $content; } else { $cws_imp_prevent_recursion = true; $shortcodes = array( 'implist', 'implist_name', 'implist_url', 'implist_version', 'implist_desc' ); cws_imp_add_shortcodes( $shortcodes ); $content = cws_imp_plugin_list_html() . $content; cws_imp_remove_shortcodes( $shortcodes ); $cws_imp_prevent_recursion = false; return $content; } } function cws_imp_parse_faq( $faq ) { $faq = preg_split( '#

#ims', $faq ); array_shift( $faq ); $questions = array(); foreach ( (array) $faq as $f ) { $f = '

' . $f; preg_match('#

(.*?)

#ims', $f, $matches ); $q = trim( $matches[1] ); $a = trim( str_replace( $matches[0], '', $f ) ); $a = trim( str_replace( array( '

', '

' ), array( '', '' ), $a ) ); $questions[$q] = $a; } return $questions; } function cws_imp_output_faq( $questions ) { $return = ''; foreach ( (array) $questions as $q => $a ) { $return .= 'Q. ' . $q . '' . "\n"; $return .= 'A. ' . $a . "\n\n"; } return $return; } function cws_imp_parse_changelog( $changelog ) { $changelog = preg_split( "#

#ims", $changelog ); array_shift( $changelog ); $changes = array(); foreach ( (array) $changelog as $c ) { $c = '

' . $c; preg_match('#

(.*?)

#ims', $c, $matches ); $v = trim( $matches[1] ); $cs = trim( str_replace( $matches[0], '', $c ) ); preg_match_all( '#
  • (.*)
  • #ims', $cs, $change_matches ); $changes[$v] = $change_matches[1]; } return $changes; } function cws_imp_output_changelog( $changes ) { $return = ''; foreach ( (array) $changes as $v => $cs ) { $return .= "

    $v

    \n\n\n"; } return $return; } function cws_imp_plugin( $content ) { global $post, $imp_readme; if ( get_post_meta( $post->ID, '_cws_imp_retired_plugin', true ) ) $content = __( '

    This plugin has been marked as retired. It is recommended that you no longer use it.

    ', 'cws-imp' ); if ( $post->post_parent && $post->post_parent == get_option( 'cws_imp_container_id' ) ) { $imp_readme = cws_imp_get_plugin_readme( $post->ID ); if ( $imp_readme ) { /* if ( $_GET['test_plugin'] ) { echo '
    ';
    				var_dump( $imp_readme );
    				echo '
    '; die(); } /**/ $shortcodes = array( 'imp_name', 'imp_url', 'imp_zip_url', 'imp_full_desc', 'imp_if_installation', 'imp_installation', 'imp_if_changelog', 'imp_changelog', 'imp_if_faq', 'imp_faq', 'imp_version', 'imp_min_version', 'imp_tested_version', 'imp_slug', 'imp_downloads' ); cws_imp_add_shortcodes( $shortcodes ); $content = ''; $content .= do_shortcode( get_option( 'cws_imp_plugin_template' ) ); cws_imp_remove_shortcodes( $shortcodes ); } $content = apply_filters( 'cws_imp_plugin_body', $content ); } return $content; } function cws_imp_admin_menu() { $hook = add_options_page( __( 'I Make Plugins', 'cws-imp' ), __( 'I Make Plugins', 'cws-imp' ), 'manage_options', 'cws-imp', 'cws_imp_options_page' ); add_action( 'load-' . $hook, 'cws_imp_options_save' ); } function cws_imp_options_save() { if ( !isset( $_POST['cws-imp-form'] ) ) return; check_admin_referer( 'cws-imp-update' ); foreach ( array( 'container_id', 'plugin_list_template', 'plugin_template' ) as $setting ) { $setting = 'cws_imp_' . $setting; update_option( $setting, stripslashes( $_POST[$setting] ) ); } wp_redirect( admin_url( 'options-general.php?page=cws-imp&updated=true' ) ); exit(); } function cws_imp_options_page() { ?>

    'cws_imp_container_id', 'echo' => 1, 'show_option_none' => __('- Select -'), 'selected' => get_option( 'cws_imp_container_id' ) ) ); ?>

    The 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_ 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' ); ?>

    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]

    ', 'cws-imp' ); ?>
    This controls what will be displayed on each plugin page. You can use the following tags:

    [imp_name] [imp_url] [imp_zip_url] [imp_full_desc] [imp_version] [imp_changelog] [imp_faq] [imp_installation] [imp_min_version] [imp_tested_version] [imp_slug] [imp_downloads]

    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]

    ', 'cws-imp' ); ?>

    \n\n[implist]\n
  • [implist_name]\n

    [implist_desc]

    \n
  • \n[/implist]\n\n" ); add_option( 'cws_imp_plugin_template', "[imp_full_desc]\n\n

    Download

    \nLatest version: Download [imp_name] v[imp_version] [zip]\n\n[if_imp_installation]\n

    Installation

    \n[imp_installation]\n[/if_imp_installation]\n\n[if_imp_faq]\n

    FAQ

    \n[imp_faq]\n[/if_imp_faq]\n\n[if_imp_changelog]\n

    Changelog

    \n[imp_changelog]\n[/if_imp_changelog]" );