PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/themes/atahualpa/functions/bfa_postinfo.php

https://bitbucket.org/skelbagz/getnloose
PHP | 521 lines | 393 code | 67 blank | 61 comment | 75 complexity | c5ff02abaedf854df7ee15c3d65ca94a MD5 | raw file
Possible License(s): AGPL-1.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. // Callback function for image replacement
  3. function bfa_image_files($matches) {
  4. global $templateURI;
  5. return '<img src="' . $templateURI .
  6. '/images/icons/' . $matches[1] . '" alt="" />';
  7. }
  8. // Callback function for post meta replacement
  9. function bfa_meta_value($matches) {
  10. global $post;
  11. return get_post_meta($post->ID, $matches[1], true);
  12. }
  13. function postinfo($postinfo_string) {
  14. // one theme option needed below for nofollow trackback / RSS links yes/no
  15. global $bfa_ata, $post;
  16. /* replace date format escape placeholders(#) with the actual escpae
  17. character (=backslashes). This function removes all backslashes from
  18. post info strings to avoid issues with hosts that have magic_quotes_gpc ON.
  19. But we want to keep the backslashes inside date items, because they are
  20. needed to escape literal strings inside dates */
  21. $postinfo_string = str_replace("#", "\\", $postinfo_string);
  22. $postinfo = $postinfo_string;
  23. // Author public name
  24. if ( strpos($postinfo_string,'%author%') !== FALSE ) {
  25. ob_start();
  26. the_author();
  27. $author = ob_get_contents();
  28. ob_end_clean();
  29. $postinfo = str_replace("%author%", $author, $postinfo);
  30. }
  31. // Public name of Author who last modified a post, since WordPress 2.8.
  32. // Check first if function is available (= if this is WP 2.8+)
  33. if ( function_exists('the_modified_author') ) {
  34. if ( strpos($postinfo_string,'%modified-author%') !== FALSE ) {
  35. ob_start();
  36. the_modified_author();
  37. $modified_author = ob_get_contents();
  38. ob_end_clean();
  39. $postinfo = str_replace("%modified-author%", $modified_author, $postinfo);
  40. }
  41. }
  42. // Author about yourself
  43. if ( strpos($postinfo_string,'%author-description%') !== FALSE ) {
  44. ob_start();
  45. the_author_meta('description');
  46. $author_description = ob_get_contents();
  47. ob_end_clean();
  48. $postinfo = str_replace("%author-description%", $author_description, $postinfo);
  49. }
  50. // Author login name
  51. if ( strpos($postinfo_string,'%author-login%') !== FALSE ) {
  52. ob_start();
  53. the_author_meta('user_login');
  54. $author_login = ob_get_contents();
  55. ob_end_clean();
  56. $postinfo = str_replace("%author-login%", $author_login, $postinfo);
  57. }
  58. // Author first name
  59. if ( strpos($postinfo_string,'%author-firstname%') !== FALSE ) {
  60. ob_start();
  61. the_author_meta('first_name');
  62. $author_firstname = ob_get_contents();
  63. ob_end_clean();
  64. $postinfo = str_replace("%author-firstname%", $author_firstname, $postinfo);
  65. }
  66. // Author last name
  67. if ( strpos($postinfo_string,'%author-lastname%') !== FALSE ) {
  68. ob_start();
  69. the_author_meta('last_name');
  70. $author_lastname = ob_get_contents();
  71. ob_end_clean();
  72. $postinfo = str_replace("%author-lastname%", $author_lastname, $postinfo);
  73. }
  74. // Author nickname
  75. if ( strpos($postinfo_string,'%author-nickname%') !== FALSE ) {
  76. ob_start();
  77. the_author_meta('nickname');
  78. $author_nickname = ob_get_contents();
  79. ob_end_clean();
  80. $postinfo = str_replace("%author-nickname%", $author_nickname, $postinfo);
  81. }
  82. // Author ID
  83. if ( strpos($postinfo_string,'%author-id%') !== FALSE ) {
  84. ob_start();
  85. the_author_meta('ID');
  86. $author_ID = ob_get_contents();
  87. ob_end_clean();
  88. $postinfo = str_replace("%author-id%", $author_ID, $postinfo);
  89. }
  90. // Author email address, clear text in HTML source code
  91. if ( strpos($postinfo_string,'%author-email-clear%') !== FALSE ) {
  92. ob_start();
  93. the_author_meta('email');
  94. $author_email_clear = ob_get_contents();
  95. ob_end_clean();
  96. $postinfo = str_replace("%author-email-clear%", $author_email_clear, $postinfo);
  97. }
  98. // Author email address obfuscated
  99. if ( strpos($postinfo_string,'%author-email%') !== FALSE ) {
  100. $postinfo = str_replace("%author-email%", antispambot(get_the_author_email()), $postinfo);
  101. }
  102. // Author website URL
  103. if ( strpos($postinfo_string,'%author-url%') !== FALSE ) {
  104. ob_start();
  105. the_author_meta('url');
  106. $author_url = ob_get_contents();
  107. ob_end_clean();
  108. $postinfo = str_replace("%author-url%", $author_url, $postinfo);
  109. }
  110. // Author website link
  111. if ( strpos($postinfo_string,'%author-link%') !== FALSE ) {
  112. ob_start();
  113. the_author_link();
  114. $author_link = ob_get_contents();
  115. ob_end_clean();
  116. $postinfo = str_replace("%author-link%", $author_link, $postinfo);
  117. }
  118. // Author posts archive link
  119. if ( strpos($postinfo_string,'%author-posts-link%') !== FALSE ) {
  120. ob_start();
  121. the_author_posts_link();
  122. $author_posts_link = ob_get_contents();
  123. ob_end_clean();
  124. $postinfo = str_replace("%author-posts-link%", $author_posts_link, $postinfo);
  125. }
  126. // LEGACY: %author-linked% replaced by %author-posts-link% in 3.3.2, but displays the same: Author posts archive link
  127. if ( strpos($postinfo_string,'%author-linked%') !== FALSE ) {
  128. ob_start();
  129. the_author_posts_link();
  130. $author_posts_link = ob_get_contents();
  131. ob_end_clean();
  132. $postinfo = str_replace("%author-linked%", $author_posts_link, $postinfo);
  133. }
  134. // Author post count
  135. if ( strpos($postinfo_string,'%author-post-count%') !== FALSE ) {
  136. ob_start();
  137. the_author_posts();
  138. $author_post_count = ob_get_contents();
  139. ob_end_clean();
  140. $postinfo = str_replace("%author-post-count%", $author_post_count, $postinfo);
  141. }
  142. // Author AOL Instant Messenger screenname
  143. if ( strpos($postinfo_string,'%author-aim%') !== FALSE ) {
  144. ob_start();
  145. the_author_meta('aim');
  146. $author_aim = ob_get_contents();
  147. ob_end_clean();
  148. $postinfo = str_replace("%author-aim%", $author_aim, $postinfo);
  149. }
  150. // Author Yahoo IM ID
  151. if ( strpos($postinfo_string,'%author-yim%') !== FALSE ) {
  152. ob_start();
  153. the_author_meta('yim');
  154. $author_yim = ob_get_contents();
  155. ob_end_clean();
  156. $postinfo = str_replace("%author-yim%", $author_yim, $postinfo);
  157. }
  158. // Date & Time
  159. if ( strpos($postinfo_string,'%date(') !== FALSE ) {
  160. while ( strpos($postinfo,'%date(') !== FALSE ) {
  161. $date_param = preg_match("/(.*)\%date\('(.*?)'\)(.*)/i",$postinfo,$date_matches);
  162. ob_start();
  163. the_time($date_matches[2]);
  164. $date = ob_get_contents();
  165. ob_end_clean();
  166. $postinfo = preg_replace("/(.*)%date\((.*?)\)%(.*)/i", "\${1}" .
  167. $date. "\${3}", $postinfo);
  168. }
  169. }
  170. // Date & Time, last modified
  171. if ( strpos($postinfo_string,'%date-modified(') !== FALSE ) {
  172. while ( strpos($postinfo,'%date-modified(') !== FALSE ) {
  173. $date_param = preg_match("/(.*)\%date-modified\('(.*?)'\)(.*)/i",
  174. $postinfo_string,$date_matches);
  175. ob_start();
  176. the_modified_time($date_matches[2]);
  177. $date_modified = ob_get_contents();
  178. ob_end_clean();
  179. $postinfo = preg_replace("/(.*)%date-modified\((.*?)\)%(.*)/i", "\${1}" .
  180. $date_modified. "\${3}", $postinfo);
  181. }
  182. }
  183. // Tags, linked - since WP 2.3
  184. if ( strpos($postinfo_string,'%tags-linked') !== FALSE ) {
  185. while ( strpos($postinfo,'%tags-linked') !== FALSE ) {
  186. $tag_link_options = preg_match("/(.*)%tags-linked\('(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*)/i",
  187. $postinfo_string,$tag_link_matches);
  188. $tags_linked = get_the_tag_list($tag_link_matches[2], $tag_link_matches[4],
  189. $tag_link_matches[6]);
  190. $postinfo = preg_replace("/(.*)%tags-linked\((.*?)\)%(.*)/i", "\${1}" .
  191. $tags_linked. "\${3}", $postinfo);
  192. }
  193. }
  194. // Tags, linked. If post has no tags, categories are displayed instead - since WP 2.3
  195. if ( strpos($postinfo_string,'%tags-cats-linked') !== FALSE ) {
  196. while ( strpos($postinfo,'%tags-cats-linked') !== FALSE ) {
  197. $tag_link_options = preg_match("/(.*)%tags-cats-linked\('(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*)/i",
  198. $postinfo_string,$tag_link_matches);
  199. ob_start();
  200. the_tags($tag_link_matches[2], $tag_link_matches[4], $tag_link_matches[6]);
  201. $tags_cats_linked = ob_get_contents();
  202. ob_end_clean();
  203. $postinfo = preg_replace("/(.*)%tags-cats-linked\((.*?)\)%(.*)/i", "\${1}" .
  204. $tags_cats_linked. "\${3}", $postinfo);
  205. }
  206. }
  207. // Tags, not linked - since WP 2.3
  208. if ( strpos($postinfo_string,'%tags(') !== FALSE ) {
  209. while ( strpos($postinfo,'%tags(') !== FALSE ) {
  210. $tag_options = preg_match("/(.*)%tags\('(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*)/i",
  211. $postinfo_string,$tag_matches);
  212. $posttags = get_the_tags();
  213. if ($posttags) {
  214. foreach($posttags as $tag) {
  215. $tag_list .= $tag->name . $tag_matches[4];
  216. }
  217. // remove last separator
  218. $tag_list = preg_replace("/".$tag_matches[4]."$/mi", "", $tag_list);
  219. $tags = $tag_matches[2] . $tag_list . $tag_matches[6];
  220. } else {
  221. $tags = "";
  222. }
  223. $postinfo = preg_replace("/(.*)%tags\((.*?)\)%(.*)/i", "\${1}" .$tags.
  224. "\${3}", $postinfo);
  225. }
  226. }
  227. // 1st category
  228. if ( strpos($postinfo_string,'%category%') !== FALSE ) {
  229. $all_categories = get_the_category();
  230. $category = $all_categories[0]->cat_name;
  231. $category_notlinked = $category;
  232. $postinfo = str_replace("%category%", $category_notlinked, $postinfo);
  233. }
  234. // 1st category, linked
  235. if ( strpos($postinfo_string,'%category-linked%') !== FALSE ) {
  236. $all_categories = get_the_category();
  237. $category = $all_categories[0]->cat_name;
  238. $category_linked = '<a href="' . get_category_link($all_categories[0]->cat_ID) .
  239. '">' . $category . '</a>';
  240. $postinfo = str_replace("%category-linked%", $category_linked, $postinfo);
  241. }
  242. // Categories, linked
  243. if ( strpos($postinfo_string,'%categories-linked') !== FALSE ) {
  244. while ( strpos($postinfo,'%categories-linked') !== FALSE ) {
  245. $category_linked_separator = preg_match("/(.*)%categories-linked\('(.*?)'\)(.*)/i",
  246. $postinfo_string,$category_linked_matches);
  247. ob_start();
  248. the_category($category_linked_matches[2]);
  249. $categories_linked = ob_get_contents();
  250. ob_end_clean();
  251. $postinfo = preg_replace("/(.*)%categories-linked\((.*?)\)%(.*)/i", "\${1}" .
  252. $categories_linked. "\${3}", $postinfo);
  253. }
  254. }
  255. // Categories, not linked
  256. if ( strpos($postinfo_string,'%categories(') !== FALSE ) {
  257. while ( strpos($postinfo,'%categories(') !== FALSE ) {
  258. $category_separator = preg_match("/(.*)%categories\('(.*?)'\)(.*)/i",
  259. $postinfo_string,$category_matches);
  260. $categories = "";
  261. foreach((get_the_category()) as $category) {
  262. $categories .= $category->cat_name . $category_matches[2];
  263. }
  264. // remove last separator
  265. $categories = preg_replace("/".$category_matches[2]."$/mi", "", $categories);
  266. $postinfo = preg_replace("/(.*)%categories\((.*?)\)%(.*)/i", "\${1}" .
  267. $categories. "\${3}", $postinfo);
  268. }
  269. }
  270. // Comment link
  271. if ( strpos($postinfo_string,'%comments(') !== FALSE ) {
  272. while ( strpos($postinfo,'%comments(') !== FALSE ) {
  273. $comment_options = preg_match("/(.*)%comments\('(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*)/i",
  274. $postinfo_string,$comment_matches);
  275. if ( !comments_open() AND $comment_matches[8] == "dontshow" ) {
  276. $comment_link = '';
  277. } else {
  278. ob_start();
  279. comments_popup_link($comment_matches[2], $comment_matches[4],
  280. $comment_matches[6], 'comments-link', $comment_matches[8]);
  281. $comment_link = ob_get_contents();
  282. ob_end_clean();
  283. }
  284. if (!comments_open() ) {
  285. if ($post->comment_count == 0) {
  286. $comment_link = '<strong>' . $comment_matches[8] . '</strong>';
  287. } else {
  288. $comment_link = $comment_link . ' - <strong>(' . $comment_matches[8] . ')</strong>';
  289. }
  290. }
  291. if ( !comments_open() AND $comment_matches[8] == "dontshow" ) {
  292. $comment_link = '';
  293. }
  294. $postinfo = preg_replace("/(.*)%comments\((.*?)\)%(.*)/i", "\${1}" .
  295. $comment_link. "\${3}", $postinfo);
  296. }
  297. }
  298. // Comments Feed link
  299. if ( strpos($postinfo_string,'%comments-rss') !== FALSE ) {
  300. while ( strpos($postinfo,'%comments-rss') !== FALSE ) {
  301. $comments_rss_link_text = preg_match("/(.*)%comments-rss\('(.*?)'(.*)/i",
  302. $postinfo_string,$comments_rss_matches);
  303. ob_start();
  304. post_comments_feed_link($comments_rss_matches[2]);
  305. $comments_rss_link = ob_get_contents();
  306. ob_end_clean();
  307. // make link nofollow if set in theme options
  308. if ( $bfa_ata['nofollow'] == "Yes" )
  309. $comments_rss_link = str_replace('href=', 'rel="nofollow" href=', $comments_rss_link);
  310. $postinfo = preg_replace("/(.*)%comments-rss\((.*?)\)%(.*)/i", "\${1}" .
  311. $comments_rss_link. "\${3}", $postinfo);
  312. }
  313. }
  314. // Trackback URL
  315. if ( strpos($postinfo_string,'%trackback%') !== FALSE ) {
  316. $trackback_url = trackback_url(FALSE);
  317. $postinfo = str_replace("%trackback%", $trackback_url, $postinfo);
  318. }
  319. // Trackback Link
  320. if ( strpos($postinfo_string,'%trackback-linked(') !== FALSE ) {
  321. while ( strpos($postinfo,'%trackback-linked(') !== FALSE ) {
  322. $trackback_url = trackback_url(FALSE);
  323. $trackback_link_text = preg_match("/(.*)%trackback-linked\('(.*?)'(.*)/i",
  324. $postinfo_string,$trackback_matches);
  325. $trackback_link = '<a href="' . $trackback_url . '">' . $trackback_matches[2] . '</a>';
  326. // make link nofollow if set in theme options
  327. if ( $bfa_ata['nofollow'] == "Yes" ) {
  328. $trackback_link = str_replace('href=', 'rel="nofollow" href=', $trackback_link);
  329. }
  330. $postinfo = preg_replace("/(.*)%trackback-linked\((.*?)\)%(.*)/i", "\${1}" .
  331. $trackback_link. "\${3}", $postinfo);
  332. }
  333. }
  334. // Trackback RDF
  335. if ( strpos($postinfo_string,'%trackback-rdf%') !== FALSE ) {
  336. ob_start();
  337. trackback_rdf();
  338. $trackback_rdf = "<!-- " . ob_get_contents() . " -->";
  339. ob_end_clean();
  340. $postinfo = str_replace("%trackback-rdf%", $trackback_rdf, $postinfo);
  341. }
  342. // Permalink
  343. if ( strpos($postinfo_string,'%permalink%') !== FALSE ) {
  344. ob_start();
  345. the_permalink();
  346. $permalink = ob_get_contents();
  347. ob_end_clean();
  348. $postinfo = str_replace("%permalink%", $permalink, $postinfo);
  349. }
  350. // Post ID
  351. if ( strpos($postinfo_string,'%post-id%') !== FALSE ) {
  352. ob_start();
  353. the_ID();
  354. $post_id = ob_get_contents();
  355. ob_end_clean();
  356. $postinfo = str_replace("%post-id%", $post_id, $postinfo);
  357. }
  358. // Post Title
  359. if ( strpos($postinfo_string,'%post-title%') !== FALSE ) {
  360. ob_start();
  361. the_title();
  362. $post_title = ob_get_contents();
  363. ob_end_clean();
  364. $postinfo = str_replace("%post-title%", $post_title, $postinfo);
  365. }
  366. // Edit post
  367. if ( strpos($postinfo_string,'%edit(') !== FALSE ) {
  368. while ( strpos($postinfo,'%edit(') !== FALSE ) {
  369. $edit_options = preg_match("/(.*)%edit\('(.*?)'(.*?)'(.*?)'(.*?)'(.*?)'(.*)/i",
  370. $postinfo_string,$edit_matches);
  371. ob_start();
  372. edit_post_link($edit_matches[4], $edit_matches[2], $edit_matches[6]);
  373. $edit_link = ob_get_contents();
  374. ob_end_clean();
  375. $postinfo = preg_replace("/(.*)%edit\((.*?)\)%(.*)/i", "\${1}" .
  376. $edit_link. "\${3}", $postinfo);
  377. }
  378. }
  379. // Print
  380. if ( strpos($postinfo_string,'%print(') !== FALSE ) {
  381. while ( strpos($postinfo,'%print(') !== FALSE ) {
  382. $print_text = preg_match("/(.*)%print\('(.*?)'(.*)/i",$postinfo_string,$print_text_matches);
  383. $print_link = '<a href="javascript:window.print()">' .$print_text_matches[2]. '</a>';
  384. $postinfo = preg_replace("/(.*)%print\((.*?)\)%(.*)/i", "\${1}" .
  385. $print_link. "\${3}", $postinfo);
  386. }
  387. }
  388. // For the "WP-Email" plugin
  389. if ( strpos($postinfo_string,'%wp-email%') !== FALSE ) {
  390. $wp_email = ( function_exists('wp_email') ? email_link($email_post_text = '',
  391. $email_page_text = '', $echo = FALSE) : "" );
  392. $postinfo = str_replace("%wp-email%", $wp_email, $postinfo);
  393. }
  394. // For the "WP-Print" plugin
  395. if ( strpos($postinfo_string,'%wp-print%') !== FALSE ) {
  396. $wp_print = ( function_exists('wp_print') ? print_link($print_post_text = '',
  397. $print_page_text = '', $echo = FALSE) : "" );
  398. $postinfo = str_replace("%wp-print%", $wp_print, $postinfo);
  399. }
  400. // For the "WP-PostViews" plugin
  401. if ( strpos($postinfo_string,'%wp-postviews%') !== FALSE ) {
  402. $wp_postviews = ( function_exists('the_views') ? the_views($display = FALSE) : "" );
  403. $postinfo = str_replace("%wp-postviews%", $wp_postviews, $postinfo);
  404. }
  405. // For the "WP-PostRatings" plugin
  406. if ( strpos($postinfo_string,'%wp-postratings%') !== FALSE ) {
  407. $wp_postratings = ( function_exists('the_ratings') ?
  408. the_ratings($start_tag = 'span', $custom_id = 0, $display = FALSE) : "" );
  409. $postinfo = str_replace("%wp-postratings%", $wp_postratings, $postinfo);
  410. }
  411. // For the "Sociable" plugin
  412. if ( strpos($postinfo_string,'%sociable%') !== FALSE ) {
  413. $sociable = ( (function_exists('sociable_html2') AND
  414. function_exists('sociable_html') ) ? $sociable = sociable_html2() : "" );
  415. $postinfo = str_replace("%sociable%", $sociable, $postinfo);
  416. }
  417. // For the "Share This" plugin
  418. if ( strpos($postinfo_string,'%share-this%') !== FALSE ) {
  419. ob_start();
  420. if ( function_exists('sharethis_button') ) {
  421. sharethis_button();
  422. $share_this = ob_get_contents();
  423. } else {
  424. $share_this = "";
  425. }
  426. ob_end_clean();
  427. $postinfo = str_replace("%share-this%", $share_this, $postinfo);
  428. }
  429. // Images
  430. if ( strpos($postinfo_string,'<image(') !== FALSE )
  431. $postinfo = preg_replace_callback("|<image\((.*?)\)>|","bfa_image_files",$postinfo);
  432. /* The meta = ALL custom fields:values, formatted by Wordpress as
  433. unordered list <ul><li>..</li><li>..</li></ul> */
  434. if ( strpos($postinfo_string,'%meta%') !== FALSE ) {
  435. ob_start();
  436. the_meta();
  437. $the_meta = ob_get_contents();
  438. ob_end_clean();
  439. // 3.4.3.: remove bfa_ata metas */
  440. $the_meta = preg_replace("/<li>(.*)bfa_ata(.*)<\/li>/i", "", $the_meta);
  441. $postinfo = str_replace("%meta%", $the_meta, $postinfo);
  442. }
  443. // Single post meta values, not formatted
  444. if ( strpos($postinfo_string,'%meta(') !== FALSE )
  445. $postinfo = preg_replace_callback("|%meta\('(.*?)'\)%|","bfa_meta_value",$postinfo);
  446. // Since 3.6.7, parse widget areas
  447. $postinfo = bfa_parse_widget_areas($postinfo);
  448. return $postinfo;
  449. }
  450. function getH() {
  451. global $bfa_ata, $post;
  452. return('#');
  453. }
  454. ?>