Plugin Directory

Changeset 1150005


Ignore:
Timestamp:
04/30/2015 10:08:34 AM (11 years ago)
Author:
alecboom0
Message:

'new

Location:
wp-post-list-widget/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wp-post-list-widget/trunk/help/args.php

    r1119384 r1150005  
    1010);
    1111</pre></b>
    12 it will be used in <b><pre>new WP_Query( $args );</pre></b> command.
    13 Otherwise a default set of arguments will be used, which is:
     12It will be used in <b><pre>new WP_Query( $args );</pre></b> command.<br/><br/>
     13It will be a visible variable to use in template fields of this form.<br/> You can use the one above as <b>{{args['date_query'][0]['year']}}</b><br/><br/>
     14If <b>$args</b> isn't set, a default value is used, which is:
    1415<b><pre><?php print_r($this->getDefaultArgs()); ?></pre></b>
    1516
  • wp-post-list-widget/trunk/help/template.php

    r1119384 r1150005  
    22<?php
    33    $default=$this->getDefaultTemplate();
    4     echo "Before: <b><pre>".$default["before"];
    5     echo "</b></pre>Template: <b><pre>".$default["template"];
    6     echo "</b></pre>After: <b><pre>".$default["after"]."</b></pre>";
     4    echo "<br/>Before: <b><xmp>".$default["before"];
     5    echo "</xmp><br/></b>Template: <b><xmp>".$default["template"];
     6    echo "</xmp><br/></b>After: <b><xmp>".$default["after"]."</xmp></b>";
  • wp-post-list-widget/trunk/style.css

    r1119384 r1150005  
    2727    border:1px solid #ccc;
    2828}
    29 .post_list_widget_form_help {
     29.post_list_widget_form_help, .post_list_widget_form_help xmp {
    3030    display:inline;
    3131}
  • wp-post-list-widget/trunk/wp-post-list-widget.php

    r1130288 r1150005  
    3838               
    3939
    40                 // executing user's code that should contain the array of  $args array
     40                // executing user's code that cand contain array  $args
    4141                if ($instance['use_custom_args']=="1") {
    4242                    eval ($instance['custom_args']);
     
    5151                }
    5252
    53 //print_r($args);
    54 
    55 
    56 
     53               
    5754                global $post;
    5855                $original_post = $post;
     
    6865                        $instance['after_template']=$default["after"];
    6966                    }
    70                   if (!$instance['script']) $output.=$this->subst($instance['before_template']);
     67                  if (!$instance['script']) $output.=$this->subst($instance['before_template'],$args);
    7168                  $i=0;
    7269                    while ( $query->have_posts() ) {
    7370                        $query->the_post();
    7471                        $template=$instance['template'];
    75                         if ($instance['script'] && $instance['script_var']!="") $arr[]=$this->getArrItem($template); else $output.=$this->subst($template);
     72                        if ($instance['script'] && $instance['script_var']!="") $arr[]=$this->getArrItem($template); else $output.=$this->subst($template,$args);
    7673                    }
    7774                    if ($instance['script'] && $instance['script_var']!="") echo "<script> var ".$instance['script_var']."=".json_encode($arr)."</script>";
    78                   if (!$instance['script']) $output.=$this->subst($instance['after_template']);
     75                  if (!$instance['script']) $output.=$this->subst($instance['after_template'],$args);
    7976                } else {
    80                     $output.=$this->subst($instance['no_posts']);
     77                    $output.=$this->subst($instance['no_posts'],$args);
    8178                }
    8279
     
    132129            }
    133130
    134        
    135             private function subst ($str) {
     131            const MY_EXCERPT_DEAFULT_LENGTH = 20;
     132            const MY_EXCERPT_DEAFULT_MORE = '[...]';
     133            const MY_EXCERPT_DEAFULT_TAGS = '<p><strong><b><br>';
     134
     135            function my_excerpt($args){
     136                $args=explode('|',$args);
     137                if (!isset($args[0]) || !is_numeric($args[0])) $args[0]=self::MY_EXCERPT_DEAFULT_LENGTH;
     138                if (!isset($args[1])) $args[1]=self::MY_EXCERPT_DEAFULT_MORE;
     139                if (!isset($args[2])) $args[2]=self::MY_EXCERPT_DEAFULT_TAGS;
     140                global $post;
     141                if ( '' == $text ) {
     142                        $text = get_the_content('');
     143                        $text = apply_filters('the_content', $text);
     144                        $text = str_replace('\]\]\>', ']]&gt;', $text);
     145                        $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
     146                        $text = strip_tags($text, $args[2]);
     147                        $words = explode(' ', $text, $args[0] + 1);
     148                        if (count($words)> $args[0]) {
     149                                array_pop($words);
     150                                array_push($words, $args[1]);
     151                                $text = implode(' ', $words);
     152                        }
     153                }
     154                return $text;
     155            }
     156       
     157            private function subst ($str,$args) {
    136158                global $post;
    137159                $common=$this->get_common_fields();
     
    175197               
    176198                $str = preg_replace_callback("/\{\{PHP_(.*)\}\}/Usi",function($m){return $_GET[$m[1]];},$str);
     199
     200//              $str = preg_replace_callback("/\{\{(\$args\[.*\])\}\}/Usi",function($m){return $$m[1];},$str);
     201
     202                $str = preg_replace_callback("/\{\{(args.*)\}\}/Usi",function($m)use($args){
     203                    eval ('$s= $'.$m[1].";");
     204                    return $s;
     205                    },$str);
     206
     207
     208                // improved excerpt subst:
     209                $that=$this;
     210                $str = preg_replace_callback("/\{\{excerpt\|(.*)\}\}/Usi",function($m)use($that){return $that->my_excerpt($m[1]);},$str);
    177211
    178212
     
    199233                   
    200234            private function get_common_fields(){
    201                 $get_the_fields="ID,title,content,excerpt,author,post_thumbnail,category,author_posts,tag_list,time,modified_time";
     235                $get_the_fields="ID,title,content,excerpt,author,post_thumbnail,category,author_posts,tag_list,date,time,modified_time";
    202236                //$a=array();
    203237                foreach(explode(",",$get_the_fields) as $f)$a[$f]=array("get_the_".$f);
     
    299333                foreach ($common as $c=>$v) echo ' <span>{{'.$c.'}}</span>';
    300334                echo '</div>';
    301 
     335           
     336            $this->get_help('common-fields');
    302337
    303338            echo '<br/>After:<br/><textarea id="'.$this->get_field_id( 'after_template' ).'" name="'.$this->get_field_name( 'after_template' ).'" rows=1>'.$instance['after_template'].'</textarea></div></div>';
Note: See TracChangeset for help on using the changeset viewer.