Plugin Directory

Changeset 1245862


Ignore:
Timestamp:
09/15/2015 12:43:36 PM (11 years ago)
Author:
TrendMD
Message:
  • Option for excluding post categories from indexing
  • Option for manually embedding the widget
Location:
trendmd/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trendmd/trunk/readme.txt

    r1209902 r1245862  
    124124
    1251255. The recommendations widget 
     126
     127== Changelog ==
     128
     129= 1.1 =
     130* Option for excluding post categories from indexing
     131* Option for manually embedding the widget
  • trendmd/trunk/settings.php

    r1185392 r1245862  
    2020            // register your plugin's settings
    2121            register_setting('trendmd-group', 'trendmd_journal_id');
     22            register_setting('trendmd-group', 'trendmd_custom_widget_location');
     23            register_setting('trendmd-group', 'trendmd_categories_ignored');
     24            register_setting('trendmd-group', 'trendmd_settings_saved');
    2225
    2326            // add your settings section
     
    3134            // add your setting's fields
    3235            add_settings_field(
     36                'trendmd-custom_widget_location',
     37                'Do not auto-embed widget code, I want to place the widget in a custom location',
     38                array(&$this, 'settings_field_input_checkbox'),
     39                'trendmd',
     40                'trendmd-section',
     41                array(
     42                    'field' => 'trendmd_custom_widget_location'
     43                )
     44            );
     45            add_settings_field(
     46                'trendmd-categories_ignored',
     47                'Do not index posts from the following categories:',
     48                array(&$this, 'settings_categories'),
     49                'trendmd',
     50                'trendmd-section',
     51                array(
     52                    'field' => 'trendmd_categories_ignored'
     53                )
     54            );
     55            add_settings_field(
    3356                'trendmd-journal_id',
    3457                '',
     
    3861                array(
    3962                    'field' => 'trendmd_journal_id'
     63                )
     64            );
     65            add_settings_field(
     66                'trendmd-settings_saved',
     67                '',
     68                array(&$this, 'settings_field_input_text2'),
     69                'trendmd',
     70                'trendmd-section',
     71                array(
     72                    'field' => 'trendmd_settings_saved',
     73                    'value' => '1'
    4074                )
    4175            );
     
    4983            update_option('trendmd_journal_id', TrendMD::trendmd_get_journal_id());
    5084            // Think of this as help text for the section.
    51             if (TrendMD::is_set_journal_id()) {
     85            if (TrendMD::is_set_journal_id() ) {
    5286                $count_posts = wp_count_posts();
    5387                $published_posts = $count_posts->publish;
    5488                $chunk = round(400 / $published_posts);
    5589
    56                 echo '<div style="color: #333; background-color: #f2f7ec;border-color: #d6e9c6; padding: 30px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 6px; font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif; font-size: 14px; max-width: 750px;"><div style="display: inline;" class="trendmd-message"><h3>TrendMD is indexing <span class="articles-indexed">1</span> of ' . number_format($published_posts) . ' articles from ' . parse_url(get_bloginfo("url"), PHP_URL_HOST) . '</h3></div><br /><br /><div class="trendmd-progress-container" style="border-radius: 4px; background: #fff; border: 1px solid #ccc; width: 400px; height: 30px; box-shadow: inset 0 1px 1px 0 rgba(0,0,0,0.2); position: relative;"><div class="trendmd-progress" style="position: absolute; top: -1px; left: 0; height: 30px; border-radius: 4px; border: 1px solid #2b6ede; background-color: #3e81ef; border-top-right-radius: 0; border-bottom-right-radius: 0; width: 0px;"></div></div></div>';
     90             if(get_option('trendmd_settings_saved'))   echo '<div style="color: #333; background-color: #f2f7ec;border-color: #d6e9c6; padding: 30px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 6px; font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif; font-size: 14px; max-width: 750px;"><div style="display: inline;" class="trendmd-message"><h3>TrendMD is indexing <span class="articles-indexed">1</span> of ' . number_format($published_posts) . ' articles from ' . parse_url(get_bloginfo("url"), PHP_URL_HOST) . '</h3></div><br /><br /><div class="trendmd-progress-container" style="border-radius: 4px; background: #fff; border: 1px solid #ccc; width: 400px; height: 30px; box-shadow: inset 0 1px 1px 0 rgba(0,0,0,0.2); position: relative;"><div class="trendmd-progress" style="position: absolute; top: -1px; left: 0; height: 30px; border-radius: 4px; border: 1px solid #2b6ede; background-color: #3e81ef; border-top-right-radius: 0; border-bottom-right-radius: 0; width: 0px;"></div></div></div>';
    5791
    5892            } else {
     
    6599
    66100        /**
    67          * This function provides text inputs for settings fields
     101    * This function provides text inputs for settings fields
    68102         */
    69103        public function settings_field_input_text($args)
     
    76110            // echo a proper input type="text"
    77111            echo sprintf('<input type="hidden" name="%s" id="%s" value="%s" />', $field, $field, $value);
    78             //echo TrendMD::trendmd_get_journal_id();
    79112        } // END public function settings_field_input_text($args)
     113
     114        /**
     115         * This function provides text inputs for settings fields
     116         */
     117        public function settings_field_input_text2($args)
     118        {
     119            // Get the field name from the $args array
     120            $field = $args['field'];
     121            $value = $args['value'];
     122            // Get the value of this setting
     123            // $value = get_option($field);
     124
     125            // echo a proper input type="text"
     126            echo sprintf('<input type="hidden" name="%s" id="%s" value="%s" />', $field, $field, $value);
     127        } // END public function settings_field_input_text($args)
     128
     129        /**
     130         * This function provides text inputs for settings fields
     131         */
     132        public function settings_field_input_checkbox($args)
     133        {
     134            $html = '<input type="checkbox" id="trendmd_custom_widget_location" name="trendmd_custom_widget_location" value="1"' . checked(1, get_option('trendmd_custom_widget_location'), false) . '/>';
     135            echo $html;
     136        } // END public function settings_field_input_text($args)
     137
     138        public function settings_categories($args)
     139        {
     140            ob_start();
     141            wp_category_checklist( 0, 0, get_option('trendmd_categories_ignored'),  0, 0, 0);
     142            $select_cats = ob_get_contents();
     143            ob_end_clean();
     144
     145            $select_cats = str_replace("post_category[]", "trendmd_categories_ignored[]", $select_cats);
     146            echo $select_cats;
     147
     148        }
    80149
    81150        /**
     
    111180add_action('wp_ajax_my_action', array('TrendMD', 'index_posts'));
    112181
    113 
    114 
    115182?>
  • trendmd/trunk/templates/settings.php

    r1185392 r1245862  
    11<div class="wrap">
     2    <form method="POST" action="options.php">
    23    <?php @settings_fields('trendmd-group'); ?>
    34    <?php do_settings_sections('trendmd'); ?>
     5
     6    <?php submit_button(); ?>
     7    </form>
    48</div>
     9<?php
     10if(get_option('trendmd_settings_saved')) {
     11    ?>
    512<script type="text/javascript">
    613<?php global $wpdb; $offset = TrendMD::offset() ?>
     
    3744?>
    3845</script>
     46<?php
     47}
     48?>
     49<style type="text/css">
     50    .form-table th {
     51        width:328px;
     52    }
     53    .form-table li
     54    {
     55        list-style-type: none;
     56    }
     57</style>
     58
  • trendmd/trunk/trendmd.php

    r1185392 r1245862  
    44Plugin URI: http://www.trendmd.com
    55Description: This plugin will add the TrendMD recommendations widget to your WordPress website. The TrendMD recommendations widget is used by scholarly publishers to increase their readership and revenue.
    6 Version: 1.0
     6Version: 1.1
    77*/
    88
     
    7979        public static function trendmd_add_html($content)
    8080        {
    81             if (self::show_widget()) {
     81            if (self::show_widget() && !self::custom_widget_location()) {
    8282                $content .= "<div id='trendmd-suggestions'></div>";
    8383            }
     
    9797        public static function show_widget()
    9898        {
    99             return (self::is_set_journal_id() && is_singular() && !is_preview());
     99            return (self::is_set_journal_id() && is_singular() && !is_preview() && self::category_is_indexed());
    100100        }
    101101
     
    111111        }
    112112
     113        public static function custom_widget_location()
     114        {
     115            return get_option('trendmd_custom_widget_location', array());
     116        }
     117
     118        public static function category_is_indexed()
     119        {
     120
     121            if (in_category( get_option('trendmd_categories_ignored') )) return false;
     122            return true;
     123        }
     124
    113125        static function prepare_string($string)
    114126        {
     
    118130        static function submit_post($post)
    119131        {
     132            if(!is_object($post)) return;
    120133            global $wpdb;
    121134            $wpdb->query('REPLACE INTO ' . $wpdb->prefix . 'trendmd_indexed_articles values(' . $post->ID . ');');
     
    151164                    'post_type' => 'post',
    152165                    'post_status' => 'publish',
    153                     'suppress_filters' => true
     166                    'suppress_filters' => true,
     167                    'category__not_in' => get_option('trendmd_categories_ignored')
    154168                );
     169                //$posts_array = get_posts($args);
    155170                $posts_array = get_posts($args);
     171
    156172
    157173                foreach ($posts_array as $post) {
Note: See TracChangeset for help on using the changeset viewer.