'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( '#
', '
' ), 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( "#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() { ?> \n\n[implist]\n
[implist_desc]
\n