Plugin Directory

Changeset 1263789


Ignore:
Timestamp:
10/12/2015 04:41:35 AM (10 years ago)
Author:
boyevul
Message:

[mom_reddit]

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

Legend:

Unmodified
Added
Removed
  • my-optional-modules/trunk/class.mom-reddit.php

    r1263667 r1263789  
    33 * CLASS mom-reddit()
    44 *
    5  * File last update: 11.1.1
     5 * File last update: 11.1.2
    66 *
    77 * Embed a subreddit into WordPress
     
    5050            shortcode_atts (
    5151                array (
    52                     'sub'    => ''    ,
    53                     'sticky' => 1     ,
    54                     'score'  => 0     ,
    55                     'thumbs' => 1     ,
    56                     'nsfw'   => 1     ,
    57                     'type'   => 'all' ,
    58                     'amount' => '25'  ,
     52                    'sub'    => ''          ,
     53                    'search' => ''          ,
     54                    'sort'   => 'relevance' ,
     55                    'thread' => ''          ,
     56                    'sticky' => 1           ,
     57                    'score'  => 0           ,
     58                    'thumbs' => 1           ,
     59                    'nsfw'   => 1           ,
     60                    'type'   => 'all'       ,
     61                    'amount' => '25'        ,
     62                    'header' => 1           ,
     63                    'credit' => 1           ,
     64                    'from'   => 'all'       ,
    5965                ),
    6066                $atts
     
    6268        );
    6369
    64         $count  = 0;
    65         $sub    = strtolower ( sanitize_text_field ( $sub ) );
    66         $type   = strtolower ( sanitize_text_field ( $type ) );
    67         $sticky = intval ( $sticky );
    68         $score  = intval ( $score );
    69         $thumbs = intval ( $thumbs );
    70         $nsfw   = intval ( $nsfw );
    71        
    72         $output_open = null;
    73         $post        = null;
    74         $output_end  = null;
     70        $count     = 0;
     71        $sub       = strtolower ( sanitize_text_field ( $sub ) );
     72        $search    = sanitize_text_field ( $search );
     73        $relevance = strtolower ( sanitize_text_field ( $sort ) );
     74        $type      = strtolower ( sanitize_text_field ( $type ) );
     75        $from      = strtolower ( $from );
     76        $sticky    = intval ( $sticky );
     77        $score     = intval ( $score );
     78        $thumbs    = intval ( $thumbs );
     79        $nsfw      = intval ( $nsfw );
     80        $header    = intval ( $header );
     81        $credit    = intval ( $credit );
     82       
     83        $output_open   = null;
     84        $post          = null;
     85        $output_end    = null;
     86        $header_output = null;
     87        $credit_output = null;
    7588       
    7689        if ( $sub ):
    77             $json = json_decode ( file_get_contents ( 'http://reddit.com/r/' . sanitize_text_field ( $sub ) . '/.json' ) );
    78         endif;
    79        
    80         if ( $sub || $user ):
    81             $data = $json->data->children;
    82            
     90            $json = json_decode ( file_get_contents ( "https://reddit.com/r/{$sub}/.json?limit={$amount}&t={$from}" ) );
     91        elseif ( $search ):
    8392            if ( $sub ):
    84                 if ( $data ):
    85                     $output_open .= "
    86                     <div class='myoptionalmodules-subreddit'>
    87                         <span class='title-bar'><a href='//reddit.com/r/{$sub}'>r/{$sub}</a></span>
    88                         <div class='inner'><i class='fa fa-reddit'> powered by <a href='//reddit.com/'>reddit</a></i>";
    89                     foreach ( $data as $value ):
    90                         ++$count;
    91                         $domain    = null;
    92                         $title     = null;
    93                         $url       = null;
    94                         $permalink = null;
    95                         $author    = null;
    96                         $stickied  = null;
    97                         $created   = null;
    98                         $thumb     = null;
    99                         $gild      = null;
    100                         $comments  = null;
    101                         $points    = null;
    102                         $is_nsfw   = null;
    103                         $over18    = false;
    104                         $div       = 'nonstickied';
    105                         $padding   = 'no-image';
    106                         $is_self   = $value->data->is_self;
     93                $restrict = "&restrict_sr={$sub}";
     94            else:
     95                $restrict = null;
     96            endif;
     97            $json = json_decode ( file_get_contents ( "https://www.reddit.com/search.json?q={$search}&limit={$amount}&t={$from}&sort={$sort}{$restrict}" ) );
     98        endif;
     99       
     100        if ( $header ):
     101            $header_output = "<span class='title-bar'><a href='//reddit.com/r/{$sub}'>r/{$sub}</a></span>";
     102        endif;
     103       
     104        if ( $credit ):
     105            $credit_output = "<i class='fa fa-reddit'> powered by <a href='//reddit.com/'>reddit</a></i>";
     106        endif;
     107       
     108        if ( $sub || $search ):
     109            $sub_data = $json->data->children;
     110            if ( $sub_data ):
     111                $output_open .= "
     112                <div class='myoptionalmodules-subreddit'>
     113                    {$header_output}
     114                    <div class='inner'>{$credit_output}";
     115                foreach ( $sub_data as $value ):
     116                    ++$count;
     117                    $domain    = null;
     118                    $title     = null;
     119                    $url       = null;
     120                    $permalink = null;
     121                    $author    = null;
     122                    $stickied  = null;
     123                    $created   = null;
     124                    $thumb     = null;
     125                    $gild      = null;
     126                    $comments  = null;
     127                    $points    = null;
     128                    $is_nsfw   = null;
     129                    $over18    = false;
     130                    $div       = 'nonstickied';
     131                    $padding   = 'no-image';
     132                    $is_self   = $value->data->is_self;
     133                   
     134                    $subreddit = strtolower ( sanitize_text_field ( $value->data->subreddit ) );
     135                   
     136                    if ( true == $value->data->stickied ):
     137                        $div      = 'stickied';
     138                        $stickied = '<i class="fa fa-sticky-note"> sticky</i>';
     139                    endif;
     140                    if ( $value->data->domain ):
     141                        $domain_raw = sanitize_text_field ( $value->data->domain );
     142                        $domain     = sanitize_text_field ( $value->data->domain );
     143                        $domain     = "<small>(<a href='//reddit.com/domain/{$domain}'>{$domain}</a>)</small>";
     144                    endif;
     145                    if ( $value->data->title ):
     146                        $title = sanitize_text_field ( $value->data->title );
     147                    endif;
     148                    if ( $value->data->url ):
     149                        $url = esc_url ( $value->data->url );
     150                        $url = "<a href='{$url}'>{$title}</a>";
     151                    endif;
     152                    if ( $value->data->gilded ):
     153                        $gild = intval ( $value->data->gilded );
     154                    endif;
     155                    if ( $value->data->permalink ):
     156                        $permalink = esc_url ( '//reddit.com/' . $value->data->permalink );
     157                    endif;
     158                    if ( $value->data->num_comments ):
     159                        $comments = intval ( $value->data->num_comments );
     160                        $comments = "<a href='{$permalink}'>{$comments} comments</a>";
     161                    else:
     162                        $comments = "<a href='{$permalink}'><em>no comments</em></a>";
     163                    endif;
     164                    if ( $value->data->score ):
     165                        $raw_score = intval ( $value->data->score );
     166                        $points    = intval ( $value->data->score );
     167                        $points    = "<span class='listing-score'>{$points}</span>";
     168                    else:
     169                        $points = '<span class="listing-score">0</span>';
     170                    endif;
     171                    if ( $value->data->author ):
     172                        $author = sanitize_text_field ( $value->data->author );
     173                        $author = " by <a href='//reddit.com/user/{$author}'>{$author}</a>";
     174                    endif;
     175                    if ( $value->data->created_utc ):
     176                        $date          = $value->data->created_utc;
     177                        $date_readable = date( 'Y-m-d H:i:s' , $date );
     178                        $date          = human_time_diff ( $date , current_time ( 'timestamp' ) );
     179                        $date          = "submitted {$author} {$date} ago";
     180                    endif;
     181                    if ( $value->data->thumbnail && false == $is_self ):
    107182                       
    108                         $subreddit = strtolower ( sanitize_text_field ( $value->data->subreddit ) );
    109                        
    110                         if ( true == $value->data->stickied ):
    111                             $div      = 'stickied';
    112                             $stickied = '<i class="fa fa-sticky-note"> sticky</i>';
    113                         endif;
    114                         if ( $value->data->domain ):
    115                             $domain_raw = sanitize_text_field ( $value->data->domain );
    116                             $domain     = sanitize_text_field ( $value->data->domain );
    117                             $domain     = "<small>(<a href='//reddit.com/domain/{$domain}'>{$domain}</a>)</small>";
    118                         endif;
    119                         if ( $value->data->title ):
    120                             $title = sanitize_text_field ( $value->data->title );
    121                         endif;
    122                         if ( $value->data->url ):
    123                             $url = esc_url ( $value->data->url );
    124                             $url = "<a href='{$url}'>{$title}</a>";
    125                         endif;
    126                         if ( $value->data->gilded ):
    127                             $gild = intval ( $value->data->gilded );
    128                         endif;
    129                         if ( $value->data->permalink ):
    130                             $permalink = esc_url ( '//reddit.com/' . $value->data->permalink );
    131                         endif;
    132                         if ( $value->data->num_comments ):
    133                             $comments = intval ( $value->data->num_comments );
    134                             $comments = "<a href='{$permalink}'>{$comments} comments</a>";
     183                        if ( true == $value->data->over_18 ):
     184                            $thumb   = null;
     185                            $is_nsfw = '<span class="nsfw">nsfw</span>';
    135186                        else:
    136                             $comments = "<a href='{$permalink}'><em>no comments</em></a>";
    137                         endif;
    138                         if ( $value->data->score ):
    139                             $raw_score = intval ( $value->data->score );
    140                             $points    = intval ( $value->data->score );
    141                             $points    = "<span class='listing-score'>{$points}</span>";
    142                         else:
    143                             $points = '<span class="listing-score">0</span>';
    144                         endif;
    145                         if ( $value->data->author ):
    146                             $author = sanitize_text_field ( $value->data->author );
    147                             $author = " by <a href='//reddit.com/user/{$author}'>{$author}</a>";
    148                         endif;
    149                         if ( $value->data->created_utc ):
    150                             $date          = $value->data->created_utc;
    151                             $date_readable = date( 'Y-m-d H:i:s' , $date );
    152                             $date          = human_time_diff ( $date , current_time ( 'timestamp' ) );
    153                             $date          = "submitted {$author} {$date} ago";
    154                         endif;
    155                         if ( $value->data->thumbnail && false == $is_self ):
    156                            
    157                             if ( true == $value->data->over_18 ):
     187                            if ( !strpos ( strtolower ( $value->data->title ) , 'spoiler' ) ):
     188                                $padding = 'image';
     189                                $thumb   = esc_url ( $value->data->thumbnail );
     190                                $thumb   = "<img src='{$thumb}' class='thumb' />";
     191                            else:
    158192                                $thumb   = null;
    159                                 $is_nsfw = '<span class="nsfw">nsfw</span>';
    160                             else:
    161                                 if ( !strpos ( strtolower ( $value->data->title ) , 'spoiler' ) ):
    162                                     $padding = 'image';
    163                                     $thumb   = esc_url ( $value->data->thumbnail );
    164                                     $thumb   = "<img src='{$thumb}' class='thumb' />";
    165                                 else:
    166                                     $thumb   = null;
    167                                 endif;
    168193                            endif;
    169                            
    170                         else:
    171                             $thumb = null;
    172194                        endif;
    173195                       
    174                         if ( !$thumbs ):
    175                             $padding = 'no-image';
    176                             $thumb   = null;
    177                         endif;
    178                        
    179                         if ( $score >= $raw_score || $count > $amount ):
    180                             $post .= '';
    181                         elseif ( !$sticky && 'stickied' == $div ):
    182                             $post .= '';
    183                         elseif ( !$nsfw && $is_nsfw ):
    184                             $post .= '';
    185                         elseif ( 'self' == $type && false == $is_self ):
    186                             $post .= '';
    187                         elseif ( 'links' == $type && true == $is_self ):
    188                             $post .= '';                           
    189                         else:
    190                             $post .= "
    191                                 <div class='reddit-item-listing {$div} {$padding}'>
    192                                     {$points}{$stickied}
    193                                     {$thumb}
    194                                     <span class='listing-title'>
    195                                         {$url} {$domain}
    196                                     </span>
    197                                     <span class='listing-date'>
    198                                         {$date}
    199                                     </span>
    200                                     <span class='listing-information'>
    201                                     {$is_nsfw} {$comments}
    202                                     </span>
    203                                 </div>
    204                             ";
    205                         endif;
    206 
    207                     endforeach;
    208                     $output_end .= '</div></div>';
    209                 endif;
     196                    else:
     197                        $thumb = null;
     198                    endif;
     199                   
     200                    if ( !$thumbs ):
     201                        $padding = 'no-image';
     202                        $thumb   = null;
     203                    endif;
     204                   
     205                    if ( $score >= $raw_score ):
     206                        $post .= '';
     207                    elseif ( !$sticky && 'stickied' == $div ):
     208                        $post .= '';
     209                    elseif ( !$nsfw && $is_nsfw ):
     210                        $post .= '';
     211                    elseif ( 'self' == $type && false == $is_self ):
     212                        $post .= '';
     213                    elseif ( 'links' == $type && true == $is_self ):
     214                        $post .= '';                           
     215                    else:
     216                        $post .= "
     217                            <div class='reddit-item-listing {$div} {$padding}'>
     218                                {$points}{$stickied}
     219                                {$thumb}
     220                                <span class='listing-title'>
     221                                    {$url} {$domain}
     222                                </span>
     223                                <span class='listing-date'>
     224                                    {$date}
     225                                </span>
     226                                <span class='listing-information'>
     227                                {$is_nsfw} {$comments}
     228                                </span>
     229                            </div>
     230                        ";
     231                    endif;
     232
     233                endforeach;
     234                $output_end .= '</div></div>';
    210235            endif;
    211236        endif;
  • my-optional-modules/trunk/includes/css/css.css

    r1263667 r1263789  
    55    background-color: #fff;
    66    border: 1px solid rgba(0,0,0,.1);
     7    margin: 25px 0;
    78    padding: 0 0 20px 0;
    89    position: relative;
  • my-optional-modules/trunk/plugin.php

    r1263667 r1263789  
    33Plugin Name: My Optional Modules
    44Description: Optional modules and additions for Wordpress.
    5 Version: 11.1.1
     5Version: 11.1.2
    66Author: boyevul
    77*/
  • my-optional-modules/trunk/readme.txt

    r1263667 r1263789  
    44Requires at least: 4.1
    55Tested up to: 4.3.2
    6 Stable tag: 11.1.1
     6Stable tag: 11.1.2
    77
    88An assortment of functions to enhance WordPress.
     
    119119
    1201201. `sub` :: the sub you wish to embed :: default: none
     1211. `search` :: keyword to search for :: combine with `sub` to search within that sub only :: default: none
     1221. `sort` :: combine with `search` to sort results :: top,relevance,new,comments,relevance2 :: default: relevance
    1211231. `sticky` :: include sticky posts :: 1(yes) 0(no) :: default: 1
    1221241. `score` :: exclude posts below a certain score :: default: 1
    1231251. `nsfw` :: show posts that are marked as NSFW :: 1(yes) 0(no) :: default: 1
    1241261. `type` :: which type of posts to show :: all, self, or links :: default: all
    125 1. `amount` :: return (between) 1 and 25 results :: default: 25
     1271. `amount` :: how many results to return :: default: 25
     1281. `header` :: display link back to sub on reddit :: 1(yes) 0(no) :: default: 1
     1291. `credit` :: display powered by text :: 1(yes) 0(no) :: default: 1
     1301. `from` :: determine when to draw posts from :: hour,day,week,month,year,all :: default: all
    126131
    127132`sub` examples: sub, sub/new, sub/rising, sub/controversial, sub/top.
    128133
    129 Example: [mom_reddit sub='all' sticky=1 score=0 nsfw=1 type=all amount=25]
     134Example: [mom_reddit sub='all' search='' sort='relevance' sticky=1 score=0 nsfw=1 type=all amount=25 header=1 credit=1 from='all']
    130135
    131136== Screenshots ==
     
    134139
    135140== Changelog ==
    136 = 11.1 / 11.1.1 =
     141= 11.1 / 11.1.1 / 11.1.2 =
    137142*   *Release Date - 11th, October, 2015*
    138 *   Additional parameters can be set for [mom_reddit]
     143*   **Additional parameters can be set for [mom_reddit]**
    139144*   [mom_reddit] now uses .json instead of .rss (and just works better)
    140145
Note: See TracChangeset for help on using the changeset viewer.