PluginProbe
FeedWordPress / 2025.1211
FeedWordPress v2025.1211
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / feedwordpressboilerplatereformatter.shortcode.functions.php

feedwordpressboilerplatereformatter.shortcode.functions.php in FeedWordPress 2025.1211, at feedwordpressboilerplatereformatter.shortcode.functions.php

127 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * function add_boilerplate_reformat: reformat boilerplate template to fit into post elements; return reformatted text
4 *
5 * @uses FeedWordPressBoilerplateReformatter
6 * @uses FeedWordPressBoilerplateReformatter::do_shortcode()
7 *
8 * @param string $template The boilerplate template text, mostly in text/html, with any inline [shortcode] elements
9 * @param string $element the wp_post element being processed, e.g. 'post' (= post_content), 'excerpt', 'title'
10 * @param int|null $id the numeric id of the post to be reformatted, or NULL for the current post in the WP loop
11 * @return string The reformatted text, in text/html format.
12 */
13 function add_boilerplate_reformat ($template, $element, $id = NULL) {
14 if ('post' == $element and !preg_match('/< (p|div) ( \s [^>]+ )? >/xi', $template)) :
15 $template = '<p class="syndicated-attribution">'.$template.'</p>';
16 endif;
17
18 $ref = new FeedWordPressBoilerplateReformatter($id, $element);
19 return $ref->do_shortcode($template);
20 } /* add_boilerplate_reformat() */
21
22 /**
23 * function add_boilerplate_simple: look for any relevant Boilerplate / Credits template text to add
24 * to elements (post body, excerpt, title...) of a post being displayed in WordPress theme code.
25 *
26 * @uses is_syndicated()
27 * @uses get_feed_meta()
28 * @uses get_option()
29 * @uses add_boilerplate_reformat()
30 *
31 * @param string $element indicates the element of the post 'post' (= main body), 'excerpt', or 'title'
32 * @param string $title provides the text of the element waiting for boilerplate to be inserted
33 * @param int|null $id provides the numeric ID of the post being displayed (null = current post in WP loop)
34 * @return string provides the reformatted text, including any boilerplate text that has been inserted
35 */
36 function add_boilerplate_simple ($element, $title, $id = NULL) {
37 if (is_syndicated($id)) :
38 $meta = get_feed_meta('boilerplate rules', $id);
39 if ($meta and !is_array($meta)) : $meta = unserialize($meta); endif;
40
41 if ( !is_array($meta) or empty($meta)) :
42 $meta = get_option('feedwordpress_boilerplate');
43 endif;
44
45 if (is_array($meta) and !empty($meta)) :
46 foreach ($meta as $rule) :
47 if ($element==$rule['element']) :
48 $rule['template'] = add_boilerplate_reformat($rule['template'], $element, $id);
49
50 if ('before'==$rule['placement']) :
51 $title = $rule['template'] . ' ' . $title;
52 else :
53 $title = $title . ' ' . $rule['template'];
54 endif;
55 endif;
56 endforeach;
57 endif;
58 endif;
59 return $title;
60 } /* function add_boilerplate_simple() */
61
62 /**
63 * function add_boilerplate_title: filter hook for the_title to add Boilerplate / Credit text,
64 * if any is set, for the title of syndicated posts
65 *
66 * @uses add_boilerplate_simple()
67 *
68 * @param string $title contains the text of the title of the post being displayed
69 * @param int|null $id provides the numeric ID of the post being displayed (null = current post in WP loop)
70 * @return string provides the text of the title, reformatted to include any relevant boilerplate text
71 */
72 function add_boilerplate_title ($title, $id = NULL) {
73 return add_boilerplate_simple('title', $title, $id);
74 } /* function add_boilerplate_title () */
75
76 /**
77 * function add_boilerplate_excerpt: filter hook for the_excerpt to add Boilerplate / Credit text,
78 * if any is set, for the excerpt of syndicated posts
79 *
80 * @uses add_boilerplate_simple()
81 *
82 * @param string $excerpt contains the text of the excerpt of the post being displayed
83 * @param int|null $id provides the numeric ID of the post being displayed (null = current post in WP loop)
84 * @return string provides the text of the excerpt, reformatted to include any relevant boilerplate text
85 */
86 function add_boilerplate_excerpt ($title, $id = NULL) {
87 return add_boilerplate_simple('excerpt', $title, $id);
88 } /* function add_boilerplate_excerpt () */
89
90 /**
91 * function add_boilerplate_content: filter hook for the_content to add Boilerplate / Credit text,
92 * if any is set, for the excerpt of syndicated posts
93 *
94 * @uses is_syndicated()
95 * @uses get_feed_meta()
96 * @uses get_option()
97 * @uses add_boilerplate_reformat()
98 *
99 * @param string $content contains the text content of the post being displayed
100 * @return string provides the text content, reformatted to include any relevant boilerplate text
101 */
102 function add_boilerplate_content ($content) {
103 if (is_syndicated()) :
104 $meta = get_feed_meta('boilerplate rules');
105 if ($meta and !is_array($meta)) : $meta = unserialize($meta); endif;
106
107 if ( !is_array($meta) or empty($meta)) :
108 $meta = get_option('feedwordpress_boilerplate');
109 endif;
110
111 if (is_array($meta) and !empty($meta)) :
112 foreach ($meta as $rule) :
113 if ('post'==$rule['element']) :
114 $rule['template'] = add_boilerplate_reformat($rule['template'], 'post');
115
116 if ('before'==$rule['placement']) :
117 $content = $rule['template'] . "\n" . $content;
118 else :
119 $content = $content . "\n" . $rule['template'];
120 endif;
121 endif;
122 endforeach;
123 endif;
124 endif;
125 return $content;
126 } /* add_boilerplate_content () */
127