update( $wpdb->postmeta, array( 'meta_key' => AKA_META_KEY ), array( 'meta_key' => 'article', 'meta_value' => '1' ) ); header('Location: '.admin_url('options-general.php?page=articles.php&updated=true')); die(); } function aka_plugin_action_links($links, $file) { return CF_Admin::plugin_action_links($links, $file, AKA_FILE, 'articles'); } add_filter('plugin_action_links', 'aka_plugin_action_links', 10, 2); function aka_css() { header('Content-type: text/css'); ?> .aka-article-list { margin-left:15px; width:100px; font-family:times; font-size:14px; } div.aka_half { float: left; overflow: auto; width: 45%; } div.aka_clear { clear: both; float: none; } '); } } add_action('wp_head', 'aka_head'); function aka_get_articles($keyword = '') { global $wpdb, $post; $original_post = $post; if (!($columns = aka_get_setting('aka_columns'))) { $columns = 1; } $kw_arg = ''; if (!empty($keyword)) { $kw_arg = '&meta_value='.esc_attr($keyword); } $query = new WP_Query('meta_key='.AKA_META_KEY. $kw_arg .'&posts_per_page=99999999'); if (!count($query->posts)) { return ''; } $posts = array(); $post_ids = array(); foreach ($query->posts as $post) { $posts['post_'.$post->ID] = $post; $post_ids[] = $post->ID; } $cats = $wpdb->get_results(" SELECT $wpdb->term_relationships.object_id, $wpdb->terms.term_id, $wpdb->terms.name, $wpdb->terms.slug FROM $wpdb->term_relationships, $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id AND $wpdb->term_relationships.object_id IN (".implode(',', $wpdb->escape($post_ids)).") AND $wpdb->term_taxonomy.taxonomy = 'category' ORDER BY $wpdb->terms.slug, $wpdb->term_relationships.object_id DESC "); $cats_unique = array(); foreach ($cats as $cat) { $cats_unique[] .= $cat->name; } $cats_unique = array_unique($cats_unique); $output = ''; $current = ''; $open = false; $i = 0; $j = 0; if ($columns == '2') { $half = 0; $next = false; $output .= '
'; } foreach ($cats as $cat) { $slug = $cat->slug; if ($current != $slug) { if ($next) { $output .= '
'; $half++; $open = false; $next = false; } if ($i > 0 && $open) { $output .= ' '; } $output .= '

'.$cat->name.'

'; } if ($columns == '2') { $output .= '
'; } $post = $original_post; return $output; } function aka_show_articles($keyword = '') { echo aka_get_articles($keyword); } function aka_article_shortcode($atts) { extract( shortcode_atts( array('list' => ''), $atts)); aka_show_articles($list); } add_shortcode('articles', 'aka_article_shortcode'); function aka_post_options() { global $post; echo('

'.__('Mark as an Article?', 'articles').' '); $article = get_post_meta($post->ID, AKA_META_KEY, true); $article_list = ''; if ($article == '') { $article = '0'; } else if ($article != '1') { $article_list = $article; $article = 1; } echo('   
'); echo ('

'); } function aka_add_meta_boxes() { add_meta_box('aka-article', __('Article', 'articles'), 'aka_post_options', 'post', 'side', 'low'); } add_action('add_meta_boxes', 'aka_add_meta_boxes'); function aka_store_post_options($post_id) { if (!isset($_POST['aka_article'])) { return; } $post = get_post($post_id); if (!$post || $post->post_type == 'revision') { return; } $meta = get_post_meta($post->ID, AKA_META_KEY, true); $posted = $_POST['aka_article']; $posted_type = $_POST['aka_article_list']; if (empty($_POST['aka_article_list'])) { $posted_meta_val = $posted; } else { $posted_meta_val = $_POST['aka_article_list']; } switch ($posted) { case 1: if ($meta == $posted_meta_val) { // already set return; } update_post_meta($post_id, AKA_META_KEY, $posted_meta_val); break; case 0: delete_post_meta($post_id, AKA_META_KEY); // turn it off break; } } add_action('save_post', 'aka_store_post_options'); function aka_admin_init() { if ($_GET['page'] == basename(__FILE__)) { CF_Admin::load_js(); CF_Admin::load_css(); wp_enqueue_style('aka_styles', admin_url('options-general.php?cf_action=aka_css')); } } add_action('admin_init', 'aka_admin_init'); global $aka_settings; $aka_settings = array( 'aka_columns' => array( 'type' => 'select', 'options' => array( '1' => '1', '2' => '2'), 'label' => __('List Articles in how many columns:', 'articles'), 'default' => '2', 'help' => '' ), 'aka_token' => array( 'type' => 'select', 'options' => array( '1' => 'Yes', '0' => 'No',), 'label' => __('Enable token method replacement:', 'articles'), 'default' => '0', 'help' => '(deprecated)', ), ); function aka_get_setting($setting) { return CF_Admin::get_setting($setting, 'aka'); } function aka_update_settings() { if (!current_user_can('manage_options')) { return; } global $aka_settings; CF_Admin::update_settings($aka_settings, 'aka'); } function aka_settings_form() { global $aka_settings; global $wpdb; $meta = $wpdb->get_results( $wpdb->prepare(" SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value <> '1'", AKA_META_KEY )); $meta_values = array(); foreach ($meta as $meta_item) { if (!in_array($meta_item->meta_value, $meta_values)) { array_push($meta_values, $meta_item->meta_value); } } echo('
'); CF_Admin::admin_header(__('Articles Options', 'articles'), 'Articles', AKA_VERSION, 'articles'); echo('
'); CF_Admin::start_form('aka'); echo '
'; echo ''.__('Settings', 'articles').''; CF_Admin::display_settings($aka_settings, 'aka'); echo '
'; CF_Admin::end_form_submit('aka', 'articles'); echo ('

'.__('Usage', 'articles').'

'.__('On the bottom of each write post, you can mark the post as an article, you can also supply a list keyword but is not required.', 'articles').'

'.__('To display a list of all your articles, you can use the following shortcode', 'articles').': [articles]

'.__('You can also use the following template tag in your theme', 'articles').': <?php if (function_exists(\'aka_show_articles\')) { aka_show_articles(); } ?>

'); echo ('

'.__('Article Lists', 'articles').'

'.__('Below is all of your article lists; you can use them in conjunction with the articles shortcode to display only articles of a certain list.
Example', 'articles').': [articles list="list name"] or use the template tag <?php if (function_exists(\'aka_show_articles\')) { aka_show_articles("list name"); } ?>

'); foreach ($meta_values as $meta_value) { echo '' . $meta_value . ''; } echo ('

'.__('Upgrade/Update', 'articles').'

'.__('If you recently upgraded from version 1.2 or below, or have changed your meta key name in the plugin file you will need to click the button below to have the Articles plugin fully working.', 'articles').'

'); CF_Admin::callouts('articles'); echo '
'; } function aka_admin_menu() { add_options_page( __('Articles Options', 'articles'), __('Articles', 'articles'), 'manage_options', basename(__FILE__), 'aka_settings_form' ); } add_action('admin_menu', 'aka_admin_menu'); // Keep for backwards compatability, ###articles### deprecated function aka_the_content($content) { if (strstr($content, '###articles###')) { $content = str_replace('###articles###', aka_get_articles(), $content); } return $content; } function aka_the_excerpt($content) { return str_replace('###articles###', '', $content);; } function aka_replace_token() { add_filter('the_content', 'aka_the_content'); add_filter('the_excerpt', 'aka_the_excerpt'); } add_action('init', 'aka_replace_token'); // Multisite function aka_is_multisite() { return CF_Admin::is_multisite(); } function aka_activate_for_network() { CF_Admin::activate_for_network('aka_activate_single'); } function aka_activate_plugin_for_new_blog($blog_id) { CF_Admin::activate_plugin_for_new_blog(AKA_FILE, $blog_id, 'aka_activate_single'); } add_action('new_blog', 'aka_activate_plugin_for_new_blog'); ?>