[44] | 1 | <?php
|
---|
| 2 | function image_files($matches) {
|
---|
| 3 | return '<img src="' . get_bloginfo('template_directory') . '/images/icons/' . $matches[1] . '" alt="" />';
|
---|
| 4 | }
|
---|
| 5 |
|
---|
| 6 | function postinfo($postinfo_string) {
|
---|
| 7 |
|
---|
| 8 | // replace put date format escape character (#) with backslashes
|
---|
| 9 | // This is needed because we remove all backslashes to avoid issues with hosts that have magic_quotes_gpc ON
|
---|
| 10 | // but we want to keep (only) the backslashes inside date items that used to escape literal strings inside dates
|
---|
| 11 | $postinfo_string = str_replace("#", "\\", $postinfo_string);
|
---|
| 12 |
|
---|
| 13 | # get all the data for the current post
|
---|
| 14 | //$post_id = $wp_query->get_queried_object_id();
|
---|
| 15 | $post_id = $post->ID;
|
---|
| 16 | $post_data = get_post($post_id, ARRAY_A);
|
---|
| 17 | $post_title = $post_data['post_title'];
|
---|
| 18 | $post_author_id = $post_data['post_author'];
|
---|
| 19 | $post_comment_count = $post_data['comment_count'];
|
---|
| 20 | $post_comment_status = $post_data['comment_status'];
|
---|
| 21 | // This may not work for imported posts:
|
---|
| 22 | // $post_permalink = $post_data['guid'];
|
---|
| 23 | $post_permalink = get_permalink($post_id);
|
---|
| 24 | $post_date = $post_data['post_date'];
|
---|
| 25 | #$post_date = date("Y m d",strtotime($post->post_date))
|
---|
| 26 |
|
---|
| 27 | if (strpos($postinfo_string,'%tags')!==false) {
|
---|
| 28 | ######## TAGS ########
|
---|
| 29 | $tag_options = preg_match("/(.*)%tags\('(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*)/i",$postinfo_string,$tag_matches);
|
---|
| 30 | $tag_link_options = preg_match("/(.*)%tags-linked\('(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*)/i",$postinfo_string,$tag_link_matches);
|
---|
| 31 | // tags-linked
|
---|
| 32 | if (get_the_tag_list()) {$tags_linked = get_the_tag_list($tag_link_matches[2], $tag_link_matches[4], $tag_link_matches[6]);}
|
---|
| 33 | else { $tags_linked = ""; }
|
---|
| 34 | // tags
|
---|
| 35 | $posttags = get_the_tags();
|
---|
| 36 | if ($posttags) { foreach($posttags as $tag) {
|
---|
| 37 | $tag_list .= $tag->name . $tag_matches[4];
|
---|
| 38 | }
|
---|
| 39 | // remove last separator
|
---|
| 40 | $tag_list = preg_replace("/".$tag_matches[4]."$/mi", "", $tag_list);
|
---|
| 41 | $tags = $tag_matches[2] . $tag_list . $tag_matches[6];
|
---|
| 42 | } else { $tags = ""; }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | if (strpos($postinfo_string,'%author')!==false) {
|
---|
| 46 | ######### AUTHOR ########
|
---|
| 47 | $author_name = get_author_name($post_author_id);
|
---|
| 48 | $author_url = get_author_posts_url($post_author_id, $author_name);
|
---|
| 49 | // author-linked
|
---|
| 50 | $author_linked = '<a href="' . $author_url . '">' . $author_name . '</a>';
|
---|
| 51 | // author
|
---|
| 52 | $author = $author_name;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | if (strpos($postinfo_string,'%date(')!==false) {
|
---|
| 56 | ######## DATE ########
|
---|
| 57 | $date_param = preg_match("/(.*)\%date\('(.*?)'\)(.*)/i",$postinfo_string,$date_matches);
|
---|
| 58 | # This works, but not with localization:
|
---|
| 59 | #$date = date("$date_matches[2]",strtotime($post_date));
|
---|
| 60 | #$date = mysql2date($date_matches[2], date('Y-m-d H:i:s',strtotime($post_date)));
|
---|
| 61 | #$date = mysql2date($date_matches[2], $post_date);
|
---|
| 62 | $date = mysql2date($date_matches[2], get_the_time('Y-m-d H:i:s'));
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | if (strpos($postinfo_string,'%category')!==false) {
|
---|
| 66 | ######## CATEGORY ########
|
---|
| 67 | // category
|
---|
| 68 | $all_categories = get_the_category();
|
---|
| 69 | $category = $all_categories[0]->cat_name;
|
---|
| 70 | $category_notlinked = $category;
|
---|
| 71 | // category-linked
|
---|
| 72 | $category_linked = '<a href="' . get_category_link($all_categories[0]->cat_ID) . '">' . $category . '</a>';
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | if (strpos($postinfo_string,'%categories')!==false) {
|
---|
| 76 | ######## CATEGORIES ########
|
---|
| 77 | $category_separator = preg_match("/(.*)%categories\('(.*?)'\)(.*)/i",$postinfo_string,$category_matches);
|
---|
| 78 | $category_linked_separator = preg_match("/(.*)%categories-linked\('(.*?)'\)(.*)/i",$postinfo_string,$category_linked_matches);
|
---|
| 79 | $categories = "";
|
---|
| 80 | $categories_linked = "";
|
---|
| 81 | foreach((get_the_category()) as $category) {
|
---|
| 82 | // categories
|
---|
| 83 | $categories .= $category->cat_name . $category_matches[2];
|
---|
| 84 | // categories-linked
|
---|
| 85 | $categories_linked .= '<a href="' . get_category_link($category->cat_ID) . '">' . $category->cat_name . '</a>' . $category_linked_matches[2];
|
---|
| 86 | }
|
---|
| 87 | // remove last separator
|
---|
| 88 | $categories = preg_replace("/".$category_matches[2]."$/mi", "", $categories);
|
---|
| 89 | $categories_linked = preg_replace("/".$category_linked_matches[2]."$/mi", "", $categories_linked);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | if (strpos($postinfo_string,'%comments(')!==false) {
|
---|
| 93 | ######## COMMENTS ########
|
---|
| 94 | $comment_options = preg_match("/(.*)%comments\('(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*)/i",$postinfo_string,$comment_matches);
|
---|
| 95 |
|
---|
| 96 | if ($post_comment_count == 0) { $comment_link_anchor = $comment_matches[2]; }
|
---|
| 97 | elseif ($post_comment_count == 1) { $comment_link_anchor = $comment_matches[4]; }
|
---|
| 98 | elseif ($post_comment_count > 1) { $comment_link_anchor = str_replace("%", $post_comment_count, $comment_matches[6]); }
|
---|
| 99 | elseif ($post_comment_status == "closed") { $comment_link_anchor = $comment_matches[8]; }
|
---|
| 100 |
|
---|
| 101 | if ($post_comment_status == "closed") { $comment_link = $comment_matches[8]; }
|
---|
| 102 | else { $comment_link = '<a href="' . get_permalink() . '#comments">' . $comment_link_anchor . '</a>'; }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | if (strpos($postinfo_string,'%comments-rss')!==false) {
|
---|
| 106 | ######## COMMENTS RSS #####
|
---|
| 107 | $comments_rss_url = comments_rss();
|
---|
| 108 | $comments_rss_link_text = preg_match("/(.*)%comments-rss\('(.*?)'(.*)/i",$postinfo_string,$comments_rss_matches);
|
---|
| 109 | $comments_rss_link = '<a href="' . $comments_rss_url .'"';
|
---|
| 110 | global $options; if (get_option('bfa_ata_nofollow') == "Yes") {
|
---|
| 111 | $comments_rss_link .= ' rel="nofollow"';
|
---|
| 112 | }
|
---|
| 113 | $comments_rss_link .= '>' . $comments_rss_matches[2] . '</a>';
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | if (strpos($postinfo_string,'%trackback(')!==false) {
|
---|
| 117 | ######## TRACKBACK ########
|
---|
| 118 | $trackback_url = trackback_url(false);
|
---|
| 119 | $trackback_link_text = preg_match("/(.*)%trackback\('(.*?)'(.*)/i",$postinfo_string,$trackback_matches);
|
---|
| 120 | $trackback_link = '<a href="' . $trackback_url . '">' . $trackback_matches[2] . '</a>';
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | if (strpos($postinfo_string,'%edit(')!==false) {
|
---|
| 124 | ######## EDIT ########
|
---|
| 125 | $edit_options = preg_match("/(.*)%edit\('(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*)/i",$postinfo_string,$edit_matches);
|
---|
| 126 | $edit_link = get_edit_post_link( $post->ID );
|
---|
| 127 | if ( !current_user_can( 'edit_page', $post->ID )) { $edit = ""; }
|
---|
| 128 | else { $edit = $edit_matches[2] . '<a href="' . $edit_link . '">' . $edit_matches[4] . '</a>' . $edit_matches[6]; }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | if (strpos($postinfo_string,'%print(')!==false) {
|
---|
| 132 | ######## PRINT ########
|
---|
| 133 | $print_text = preg_match("/(.*)%print\('(.*?)'(.*)/i",$postinfo_string,$print_text_matches);
|
---|
| 134 | $print_link = '<a href="javascript:window.print()">' .$print_text_matches[2]. '</a>';
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | if (strpos($postinfo_string,'%wp-email')!==false) {
|
---|
| 138 | ######## EMAIL ########
|
---|
| 139 | $wp_email = ( function_exists('wp_email') ? email_link($email_post_text = '', $email_page_text = '', $echo = false) : "" );
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | if (strpos($postinfo_string,'%wp-print')!==false) {
|
---|
| 143 | ######## WP-PRINT ########
|
---|
| 144 | $wp_print = ( function_exists('wp_print') ? print_link($print_post_text = '', $print_page_text = '', $echo = false) : "" );
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | if (strpos($postinfo_string,'%wp-postviews')!==false) {
|
---|
| 148 | ######## WP-POSTVIEWS ########
|
---|
| 149 | $wp_postviews = ( function_exists('the_views') ? the_views($display = false) : "" );
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | if (strpos($postinfo_string,'%wp-postratings')!==false) {
|
---|
| 153 | ######## WP-POSTRATINGS ########
|
---|
| 154 | $wp_postratings = ( function_exists('the_ratings') ? the_ratings($start_tag = 'span', $custom_id = 0, $display = false) : "" );
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | if (strpos($postinfo_string,'%sociable')!==false) {
|
---|
| 158 | ######## SOCIABLE ########
|
---|
| 159 | $sociable = ( (function_exists('sociable_html2') AND function_exists('sociable_html'))? $sociable = sociable_html2() : "" );
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 | $postinfo = $postinfo_string;
|
---|
| 166 | $postinfo = preg_replace("/(.*)%tags\((.*?)\)%(.*)/i", "\${1}" .$tags. "\${3}", $postinfo);
|
---|
| 167 | $postinfo = preg_replace("/(.*)%tags-linked\((.*?)\)%(.*)/i", "\${1}" .$tags_linked. "\${3}", $postinfo);
|
---|
| 168 | $postinfo = str_replace("%author%", $author, $postinfo);
|
---|
| 169 | $postinfo = str_replace("%author-linked%", $author_linked, $postinfo);
|
---|
| 170 | $postinfo = preg_replace("/(.*)%date\((.*?)\)%(.*)/i", "\${1}" .$date. "\${3}", $postinfo);
|
---|
| 171 | $postinfo = str_replace("%category%", $category_notlinked, $postinfo);
|
---|
| 172 | $postinfo = str_replace("%category-linked%", $category_linked, $postinfo);
|
---|
| 173 | $postinfo = preg_replace("/(.*)%categories\((.*?)\)%(.*)/i", "\${1}" .$categories. "\${3}", $postinfo);
|
---|
| 174 | $postinfo = preg_replace("/(.*)%categories-linked\((.*?)\)%(.*)/i", "\${1}" .$categories_linked. "\${3}", $postinfo);
|
---|
| 175 | $postinfo = preg_replace("/(.*)%comments\((.*?)\)%(.*)/i", "\${1}" .$comment_link. "\${3}", $postinfo);
|
---|
| 176 | $postinfo = preg_replace("/(.*)%comments-rss\((.*?)\)%(.*)/i", "\${1}" .$comments_rss_link. "\${3}", $postinfo);
|
---|
| 177 | $postinfo = str_replace("%trackback%", $trackback_url, $postinfo);
|
---|
| 178 | $postinfo = preg_replace("/(.*)%trackback-linked\((.*?)\)%(.*)/i", "\${1}" .$trackback_link. "\${3}", $postinfo);
|
---|
| 179 | $postinfo = preg_replace("/(.*)%edit\((.*?)\)%(.*)/i", "\${1}" .$edit. "\${3}", $postinfo);
|
---|
| 180 | $postinfo = preg_replace("/(.*)%print\((.*?)\)%(.*)/i", "\${1}" .$print_link. "\${3}", $postinfo);
|
---|
| 181 | $postinfo = str_replace("%wp-print%", $wp_print, $postinfo);
|
---|
| 182 | $postinfo = str_replace("%wp-email%", $wp_email, $postinfo);
|
---|
| 183 | $postinfo = str_replace("%wp-postviews%", $wp_postviews, $postinfo);
|
---|
| 184 | $postinfo = str_replace("%wp-postratings%", $wp_postratings, $postinfo);
|
---|
| 185 | $postinfo = str_replace("%sociable%", $sociable, $postinfo);
|
---|
| 186 |
|
---|
| 187 | if (strpos($postinfo_string,'<image(')!==false) {
|
---|
| 188 | // images
|
---|
| 189 | $postinfo = preg_replace_callback("|<image\((.*?)\)>|","image_files",$postinfo);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | return $postinfo;
|
---|
| 193 | }
|
---|
| 194 | ?> |
---|