Plugin Directory

Changeset 1264295


Ignore:
Timestamp:
10/12/2015 05:43:58 PM (10 years ago)
Author:
boyevul
Message:

[mom_reddit] additional parameters (including a grid mode)

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

Legend:

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

    r1263789 r1264295  
    33 * CLASS mom-reddit()
    44 *
    5  * File last update: 11.1.2
     5 * File last update: 11.1.3
    66 *
    77 * Embed a subreddit into WordPress
     
    5050            shortcode_atts (
    5151                array (
    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'       ,
     52                    'sub'      => ''          ,
     53                    'search'   => ''          ,
     54                    'sort'     => 'relevance' ,
     55                    'thread'   => ''          ,
     56                    'sticky'   => 1           ,
     57                    'score'    => 0           ,
     58                    'thumbs'   => 1           ,
     59                    'thumbs_l' => 1           ,
     60                    'nsfw'     => 1           ,
     61                    'type'     => 'all'       ,
     62                    'amount'   => '25'        ,
     63                    'header'   => 1           ,
     64                    'header_t' => ''          ,
     65                    'credit'   => 1           ,
     66                    'from'     => 'all'       ,
     67                    'site'     => 1           ,
     68                    'meta'     => 1           ,
     69                    'grid'     => 0           ,
    6570                ),
    6671                $atts
     
    6873        );
    6974
    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        
     75        $count         = 0;
     76        $sub           = strtolower ( sanitize_text_field ( $sub ) );
     77        $search        = sanitize_text_field ( $search );
     78        $relevance     = strtolower ( sanitize_text_field ( $sort ) );
     79        $type          = strtolower ( sanitize_text_field ( $type ) );
     80        $from          = strtolower ( $from );
     81        $sticky        = intval ( $sticky );
     82        if ( '-1' != $score ):
     83            $score     = intval ( $score );
     84        endif;
     85        $thumbs        = intval ( $thumbs );
     86        $thumbs_l      = intval ( $thumbs_l );
     87        $nsfw          = intval ( $nsfw );
     88        $header        = intval ( $header );
     89        $header_t      = sanitize_text_field ( $header_t );
     90        $credit        = intval ( $credit );
     91        $site          = intval ( $site );
     92        $meta          = intval ( $meta );
    8393        $output_open   = null;
    8494        $post          = null;
     
    8696        $header_output = null;
    8797        $credit_output = null;
     98        $grid_active   = null;
     99        $thumb_class   = ' class="thumb"';
     100        $grid          = intval ( $grid );
     101        if ( $grid ):
     102            $grid_active = 'id="myoptionalmodules-grid-active"';
     103            $thumb_class = null;
     104        endif;
    88105       
    89106        if ( $sub ):
     
    99116       
    100117        if ( $header ):
    101             $header_output = "<span class='title-bar'><a href='//reddit.com/r/{$sub}'>r/{$sub}</a></span>";
     118            if ( $header_t ):
     119                $header_output = "<span class='title-bar'>{$header_t}</span>";
     120            else:
     121                $header_output = "<span class='title-bar'><a href='//reddit.com/r/{$sub}'>r/{$sub}</a></span>";
     122            endif;
    102123        endif;
    103124       
     
    112133                <div class='myoptionalmodules-subreddit'>
    113134                    {$header_output}
    114                     <div class='inner'>{$credit_output}";
     135                    <div class='inner'{$grid_active}>{$credit_output}";
    115136                foreach ( $sub_data as $value ):
    116137                    ++$count;
     138                    $link_to   = null;
     139                    $date      = null;
    117140                    $domain    = null;
    118141                    $title     = null;
    119142                    $url       = null;
     143                    $url_raw   = null;
    120144                    $permalink = null;
    121145                    $author    = null;
     
    127151                    $points    = null;
    128152                    $is_nsfw   = null;
     153                    $raw_score = null;
    129154                    $over18    = false;
    130155                    $div       = 'nonstickied';
     
    138163                        $stickied = '<i class="fa fa-sticky-note"> sticky</i>';
    139164                    endif;
    140                     if ( $value->data->domain ):
     165                    if ( $value->data->domain && $site ):
    141166                        $domain_raw = sanitize_text_field ( $value->data->domain );
    142167                        $domain     = sanitize_text_field ( $value->data->domain );
     
    147172                    endif;
    148173                    if ( $value->data->url ):
    149                         $url = esc_url ( $value->data->url );
    150                         $url = "<a href='{$url}'>{$title}</a>";
     174                        $url_raw = esc_url ( $value->data->url );
     175                        $url     = esc_url ( $value->data->url );
     176                        $url     = "<a href='{$url}'>{$title}</a>";
    151177                    endif;
    152178                    if ( $value->data->gilded ):
     
    162188                        $comments = "<a href='{$permalink}'><em>no comments</em></a>";
    163189                    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>';
     190                    if ( '-1' == $score ):
     191                        $points = null;
     192                    else:
     193                        if ( $value->data->score ):
     194                            $raw_score = intval ( $value->data->score );
     195                            $points    = intval ( $value->data->score );
     196                            $points    = "<span class='listing-score'>{$points}</span>";
     197                        else:
     198                            $points = '<span class="listing-score">0</span>';
     199                        endif;
    170200                    endif;
    171201                    if ( $value->data->author ):
     
    173203                        $author = " by <a href='//reddit.com/user/{$author}'>{$author}</a>";
    174204                    endif;
    175                     if ( $value->data->created_utc ):
     205                    if ( $value->data->created_utc && $meta ):
    176206                        $date          = $value->data->created_utc;
    177207                        $date_readable = date( 'Y-m-d H:i:s' , $date );
     
    179209                        $date          = "submitted {$author} {$date} ago";
    180210                    endif;
    181                     if ( $value->data->thumbnail && false == $is_self ):
    182                        
    183                         if ( true == $value->data->over_18 ):
    184                             $thumb   = null;
    185                             $is_nsfw = '<span class="nsfw">nsfw</span>';
     211                    if ( $value->data->thumbnail ):
     212                        if ( 'self' == $value->data->thumbnail ):
     213                            $thumb = null;
    186214                        else:
    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' />";
     215                            if ( 'default' == $value->data->thumbnail ):
     216                                $thumb = null;
    191217                            else:
    192                                 $thumb   = null;
     218                                if ( !strpos ( strtolower ( $value->data->title ) , 'spoiler' ) ):
     219                                    $padding = 'image';
     220                                    $thumb   = esc_url ( $value->data->thumbnail );
     221                                    if ( !$thumbs_l ):
     222                                        $link_to = $url_raw;
     223                                    else:
     224                                        $link_to = $permalink;
     225                                    endif;
     226                                    if ( $url_raw ):
     227                                        $thumb   = "<a href='{$link_to}'><img src='{$thumb}'{$thumb_class}/></a>";
     228                                    else:
     229                                        $thumb   = "<a href='{$link_to}'><img src='{$thumb}'{$thumb_class}/></a>";
     230                                    endif;
     231                                else:
     232                                    $thumb   = null;
     233                                endif;
    193234                            endif;
    194235                        endif;
    195                        
    196236                    else:
    197237                        $thumb = null;
     
    203243                    endif;
    204244                   
    205                     if ( $score >= $raw_score ):
     245                    if ( $score >= $raw_score && $score >= 0 ):
    206246                        $post .= '';
    207247                    elseif ( !$sticky && 'stickied' == $div ):
     
    214254                        $post .= '';                           
    215255                    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                         ";
     256                        if ( $grid ):
     257                            $post .= "{$thumb}";
     258                        else:
     259                            $post .= "
     260                                <div class='reddit-item-listing {$div} {$padding}'>
     261                                    {$points}{$stickied}
     262                                    {$thumb}
     263                                    <span class='listing-title'>
     264                                        {$url} {$domain}
     265                                    </span>
     266                                    <span class='listing-date'>
     267                                        {$date}
     268                                    </span>
     269                                    <span class='listing-information'>
     270                                    {$is_nsfw} {$comments}
     271                                    </span>
     272                                </div>
     273                            ";
     274                        endif;
    231275                    endif;
    232276
  • my-optional-modules/trunk/includes/css/css.css

    r1263789 r1264295  
    99    position: relative;
    1010}
     11    /**
     12     * Seamless Responsive Photo Grid | CSS-Tricks
     13     * //css-tricks.com/seamless-responsive-photo-grid/
     14     */
     15    #myoptionalmodules-grid-active {
     16      /* Prevent vertical gaps */
     17      line-height: 0;
     18      -webkit-column-count: 5;
     19      -webkit-column-gap: 0px;
     20      -moz-column-count: 5;
     21      -moz-column-gap: 0px;
     22      column-count: 5;
     23      column-gap: 0px; 
     24    }
     25    #myoptionalmodules-grid-active img {
     26      /* Just in case there are inline attributes */
     27      height: auto !important;
     28      padding: 5px;
     29      width: 100% !important;
     30    }
     31    #myoptionalmodules-grid-active img:hover {
     32        opacity: .6;
     33    }
    1134    .myoptionalmodules-subreddit a {
    12         border: none;
     35        border-color: rgba(0,0,0,.1);
     36        border-style: solid;
     37        border-width: 0 0 1px 0;
    1338        box-shadow: none;
     39        padding: 0 0 3px 0;
    1440        text-decoration: none;
    1541    }
     
    832858}
    833859
     860@media (max-width: 1200px) {
     861  #myoptionalmodules-grid-active {
     862  -moz-column-count:    4;
     863  -webkit-column-count: 4;
     864  column-count:         4;
     865  }
     866}
     867@media (max-width: 1000px) {
     868  #myoptionalmodules-grid-active {
     869  -moz-column-count:    3;
     870  -webkit-column-count: 3;
     871  column-count:         3;
     872  }
     873}
     874@media (max-width: 800px) {
     875  #myoptionalmodules-grid-active {
     876  -moz-column-count:    2;
     877  -webkit-column-count: 2;
     878  column-count:         2;
     879  }
     880}
     881@media (max-width: 400px) {
     882  #myoptionalmodules-grid-active {
     883  -moz-column-count:    1;
     884  -webkit-column-count: 1;
     885  column-count:         1;
     886  }
     887}
     888
    834889@media screen and (max-width: 31.250em ) {
    835890.mom_cat-container {
  • my-optional-modules/trunk/plugin.php

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

    r1263789 r1264295  
    44Requires at least: 4.1
    55Tested up to: 4.3.2
    6 Stable tag: 11.1.2
     6Stable tag: 11.1.3
    77
    88An assortment of functions to enhance WordPress.
     
    1221221. `sort` :: combine with `search` to sort results :: top,relevance,new,comments,relevance2 :: default: relevance
    1231231. `sticky` :: include sticky posts :: 1(yes) 0(no) :: default: 1
    124 1. `score` :: exclude posts below a certain score :: default: 1
     1241. `score` :: exclude posts below a certain score :: -1 to disable, 0+ for point-based exclusions :: default: 1
     1251. `thumbs` :: whether to display thumbnails or not :: 1(on) 0(off) :: default: 1
     1261. `thumbs_l` :: whether to link to reddit thread or URL :: 1(reddit) 0(URL) :: default: 1
    1251271. `nsfw` :: show posts that are marked as NSFW :: 1(yes) 0(no) :: default: 1
    1261281. `type` :: which type of posts to show :: all, self, or links :: default: all
    1271291. `amount` :: how many results to return :: default: 25
    1281301. `header` :: display link back to sub on reddit :: 1(yes) 0(no) :: default: 1
     1311. `header_t` :: instead of link back, display this text in header instead :: default: none
    1291321. `credit` :: display powered by text :: 1(yes) 0(no) :: default: 1
    1301331. `from` :: determine when to draw posts from :: hour,day,week,month,year,all :: default: all
    131 
    132 `sub` examples: sub, sub/new, sub/rising, sub/controversial, sub/top.
    133 
    134 Example: [mom_reddit sub='all' search='' sort='relevance' sticky=1 score=0 nsfw=1 type=all amount=25 header=1 credit=1 from='all']
     1341. `site` :: display domain information next to title :: 1(on) 0(off) :: default: 1
     1351. `meta` :: display author and submission date information :: 1(on) 0(off) :: default: 1
     1361. `grid` :: returns a grid of images (and only images) :: 1(on) 0(off) :: default: 0
     137
     138sub examples: sub, sub/new, sub/rising, sub/controversial, sub/top.
     139
     140Example: [mom_reddit sub='all' search='' sort='relevance' sticky=1 score=0 nsfw=1 type=all amount=25 header=1 credit=1 from='all' site=1 meta=1]
    135141
    136142== Screenshots ==
     
    139145
    140146== Changelog ==
     147= 11.1.3 =
     148*   *Release Date - 12th, October, 2015*
     149*   [mom_reddit] additional parameters (including a grid mode)
     150
    141151= 11.1 / 11.1.1 / 11.1.2 =
    142152*   *Release Date - 11th, October, 2015*
Note: See TracChangeset for help on using the changeset viewer.