Changeset 1150005
- Timestamp:
- 04/30/2015 10:08:34 AM (11 years ago)
- Location:
- wp-post-list-widget/trunk
- Files:
-
- 4 edited
-
help/args.php (modified) (1 diff)
-
help/template.php (modified) (1 diff)
-
style.css (modified) (1 diff)
-
wp-post-list-widget.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-post-list-widget/trunk/help/args.php
r1119384 r1150005 10 10 ); 11 11 </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: 12 It will be used in <b><pre>new WP_Query( $args );</pre></b> command.<br/><br/> 13 It 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/> 14 If <b>$args</b> isn't set, a default value is used, which is: 14 15 <b><pre><?php print_r($this->getDefaultArgs()); ?></pre></b> 15 16 -
wp-post-list-widget/trunk/help/template.php
r1119384 r1150005 2 2 <?php 3 3 $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 27 27 border:1px solid #ccc; 28 28 } 29 .post_list_widget_form_help {29 .post_list_widget_form_help, .post_list_widget_form_help xmp { 30 30 display:inline; 31 31 } -
wp-post-list-widget/trunk/wp-post-list-widget.php
r1130288 r1150005 38 38 39 39 40 // executing user's code that should contain the array of $args array40 // executing user's code that cand contain array $args 41 41 if ($instance['use_custom_args']=="1") { 42 42 eval ($instance['custom_args']); … … 51 51 } 52 52 53 //print_r($args); 54 55 56 53 57 54 global $post; 58 55 $original_post = $post; … … 68 65 $instance['after_template']=$default["after"]; 69 66 } 70 if (!$instance['script']) $output.=$this->subst($instance['before_template'] );67 if (!$instance['script']) $output.=$this->subst($instance['before_template'],$args); 71 68 $i=0; 72 69 while ( $query->have_posts() ) { 73 70 $query->the_post(); 74 71 $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); 76 73 } 77 74 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); 79 76 } else { 80 $output.=$this->subst($instance['no_posts'] );77 $output.=$this->subst($instance['no_posts'],$args); 81 78 } 82 79 … … 132 129 } 133 130 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('\]\]\>', ']]>', $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) { 136 158 global $post; 137 159 $common=$this->get_common_fields(); … … 175 197 176 198 $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); 177 211 178 212 … … 199 233 200 234 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"; 202 236 //$a=array(); 203 237 foreach(explode(",",$get_the_fields) as $f)$a[$f]=array("get_the_".$f); … … 299 333 foreach ($common as $c=>$v) echo ' <span>{{'.$c.'}}</span>'; 300 334 echo '</div>'; 301 335 336 $this->get_help('common-fields'); 302 337 303 338 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.