Plugin Directory

Changeset 1245503


Ignore:
Timestamp:
09/14/2015 10:56:20 PM (11 years ago)
Author:
boyevul
Message:

[mom_reddit] add thread comment embedding capabilities / remove colorization of share links for easier/better theme integration

Location:
my-optional-modules/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • my-optional-modules/trunk/class.myoptionalmodules-shortcodes.php

    r1245317 r1245503  
    33 * CLASS myoptionalmodules_shortcodes()
    44 *
    5  * File update: 10.1.6
     5 * File update: 10.1.7
    66 *
    77 * All shortcodes for My Optional Modules
     
    216216            shortcode_atts (
    217217                array (
    218                     'sub'         => '' ,
     218                    'sub'         => '' ,
     219                    'thread'      => '' ,
    219220                    'limit'       => 10 ,
    220221                    'title'       => '' ,
     
    226227       
    227228        $sub    = sanitize_text_field ( $sub );
     229        $thread = sanitize_text_field ( $thread );
    228230        $limit  = intval ( $limit );
    229231        $title  = sanitize_text_field ( $title );
    230232        $output = null;
    231        
    232         if ( $sub ) {
    233        
    234             $url = "https://www.reddit.com/r/{$sub}/.rss?limit={$limit}";
     233        $count  = 0;
     234       
     235        if ( $sub || $thread ) {
     236       
     237            if ( $sub && !$thread ) {
     238                $url = "https://www.reddit.com/r/{$sub}/.rss?limit={$limit}";
     239            } elseif ( $thread && !$sub ) {
     240                $url = "{$thread}/.rss?limit={$limit}";
     241            } else {
     242                $url = null;
     243            }
    235244           
    236             $content = file_get_contents( $url );
    237 
    238             $x = new SimpleXmlElement( $content );
    239             $x->channel->title = sanitize_text_field ( $x->channel->title );
    240             $x->channel->description = sanitize_text_field ( $x->channel->description );
     245            if ( $url ) {
    241246           
    242             if ( 'search results' != strtolower ( $x->channel->title ) ) {
    243            
    244                 $channel_title = strtolower( str_replace( array( 'https://www.reddit.com/r/', '/' ), '', $x->channel->link ) );
     247                $content = file_get_contents( $url );
     248
     249                $x = new SimpleXmlElement( $content );
     250                $x->channel->title = sanitize_text_field ( $x->channel->title );
     251                $x->channel->description = sanitize_text_field ( $x->channel->description );
    245252               
    246                 if ( '%blank%' == $title ) {
    247                     $title = null;
    248                 } elseif ( $title ) {
    249                     $title = "<h1>{$title}</h1>";
    250                 } elseif ( !$title ) {
    251                     $title = "<h1><a href='{$x->channel->link}'>{$x->channel->title}</a></h1>";
     253                if ( 'search results' != strtolower ( $x->channel->title ) ) {
     254               
     255                    $channel_title = strtolower( str_replace( array( 'https://www.reddit.com/r/', '/' ), '', $x->channel->link ) );
     256                   
     257                    if ( '%blank%' == $title ) {
     258                        $title = null;
     259                    } elseif ( $title ) {
     260                        $title = "<h1>{$title}</h1>";
     261                    } elseif ( !$title ) {
     262                        $title = "<h1><a href='{$x->channel->link}'>{$x->channel->title}</a></h1>";
     263                    }
     264                   
     265                    if ( $sub && !$thread ) {
     266                        if ( $description ) {
     267                            $description = "<h2>{$x->channel->description}</h2>";
     268                        } else {
     269                            $description = null;
     270                        }
     271                    } elseif ( $thread && !$sub ) {
     272                        $description = null;
     273                        $title = null;
     274                    }
     275                   
     276                    $output .= "
     277                        <div class='mom-reddit-feed'>
     278                            {$title}{$description}
     279                           
     280                    ";
     281                    foreach( $x->channel->item as $entry ){
     282                        ++$count;
     283                        $post_type = null;
     284                        if( strpos( $entry->description, 'SC_OFF' ) !== false ){
     285                            $post_type = "<small>(self.{$channel_title})</small>";
     286                        }
     287                        if ( $sub && !$thread ) {
     288                            $output .= "<h3><a href='{$entry->link}'>{$entry->title} {$post_type}</a></h3>";
     289                        } elseif ( $thread && !$sub ) {
     290                            if ( $count > 1 ) {
     291                                $output .= "<p>{$entry->description} <small><a href='{$entry->link}'>#</a></small></p>";
     292                            }
     293                        }
     294                    }
     295                    $output .= "</div>";
     296               
    252297                }
    253298               
    254                 if ( $description ) {
    255                     $description = "<h2>{$x->channel->description}</h2>";
    256                 } else {
    257                     $description = null;
    258                 }
    259                
    260                 $output .= "
    261                     <div class='mom-reddit-feed'>
    262                         {$title}{$description}
    263                        
    264                 ";
    265                 foreach( $x->channel->item as $entry ){
    266                     $post_type = null;
    267                     if( strpos( $entry->description, 'SC_OFF' ) !== false ){
    268                         $post_type = "<small>(self.{$channel_title})</small>";
    269                     }
    270                     $output .= "<h3><a href='{$entry->link}'>{$entry->title} {$post_type}</a></h3>";
    271                 }
    272                 $output .= "</div>";
    273                
    274299            }
    275300       
  • my-optional-modules/trunk/includes/css/myoptionalmodules10.css

    r1245272 r1245503  
    55    border: none;
    66    color: rgba(30,123,195,1);
    7     display: block;
     7   
    88    text-decoration: none;
    99}
     
    2525    padding: 5% 0;
    2626}
     27    .mom-reddit-feed p {
     28        clear: both;
     29        display: block;
     30    }
     31        .mom-reddit-feed small {
     32            display: inline;
     33            clear: none;
     34            margin: 10px;
     35        }
    2736    .mom-reddit-feed  h3 {
    2837        display: block;
     
    122131}
    123132.mom_shareLinks a{
    124     background-color: #fff;
    125     color: #000;
     133    border: none;
    126134    margin: 5px 5px 5px 0;
    127135    padding: 15px 25px;
  • my-optional-modules/trunk/plugin.php

    r1245317 r1245503  
    44Plugin URI:
    55Description: Optional modules and additions for Wordpress.
    6 Version: 10.1.6
     6Version: 10.1.7
    77Author: boyevul
    88Author URI:
  • my-optional-modules/trunk/readme.txt

    r1245317 r1245503  
    9898customized to display your own title, and description should be a 1 or a 0 (to display (1) or not (0)).
    9999
    100 Example: [mom_reddit sub='destinythegame' limit='5' title='You might be interested in' description='0']
     100Designate a thread URL to pull comments for that thread. Comment output ignores title and sub attribute of shortcode.
     101
     102Example: [mom_reddit sub='destinythegame' thread='' limit='5' title='You might be interested in' description='0']
    101103
    102104== Screenshots ==
     
    105107
    106108== Changelog ==
    107 = 10.1.4 / .5 / .6 =
     109
     110= 10.1.7 =
    108111*   *Release Date - 14th, September, 2015*
    109112*   (added) [mom_reddit] for embedding subreddit feeds
     113*   Remove background color from share links for better theme integration
    110114
    111115= 10.1.3 =
Note: See TracChangeset for help on using the changeset viewer.