PluginProbe
FeedWordPress / 2021.0713
FeedWordPress v2021.0713
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 / template-functions.php

template-functions.php in FeedWordPress 2021.0713, at template-functions.php

168 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 ################################################################################
3 ## TEMPLATE API: functions to make your templates syndication-aware ############
4 ################################################################################
5
6 /**
7 * is_syndicated: Tests whether the current post in a Loop context, or a post
8 * given by ID number, was syndicated by FeedWordPress. Useful for templates
9 * to determine whether or not to retrieve syndication-related meta-data in
10 * displaying a post.
11 *
12 * @param int $id The post to check for syndicated status. Defaults to the current post in a Loop context.
13 * @return bool TRUE if the post's meta-data indicates it was syndicated; FALSE otherwise
14 */
15 function is_syndicated ($id = NULL) {
16 $p = new FeedWordPressLocalPost($id);
17 return $p->is_syndicated();
18 } /* function is_syndicated() */
19
20 /**
21 * feedwordpress_display_url: format a fully-formed URL for display in the
22 * FeedWordPress admin interface, abbreviating it (e.g.: input of
23 * `http://feedwordpress.radgeek.com/feed/` will be shortened to
24 * `feedwordpress.radgeek.com/feed/`)
25 *
26 * @param string $url provides the URL to display
27 * @param int $before a number of characters to preserve from the beginning of the URL if it must be shortened
28 * @param int $after a number of characters to preserve from the end of the URL if it must be shortened
29 * @return string containing an abbreviated display form of the URL (e.g.: `feedwordpress.radgeek.net/feed`)
30 */
31 function feedwordpress_display_url ($url, $before = 60, $after = 0) {
32 $bits = parse_url($url);
33
34 // Strip out crufty subdomains
35 if (isset($bits['host'])) :
36 $bits['host'] = preg_replace('/^www[0-9]*\./i', '', $bits['host']);
37 endif;
38
39 // Reassemble bit-by-bit with minimum of crufty elements
40 $url = (isset($bits['user'])?$bits['user'].'@':'')
41 .(isset($bits['host'])?$bits['host']:'')
42 .(isset($bits['path'])?$bits['path']:'')
43 .(isset($uri_bits['port'])?':'.$uri_bits['port']:'')
44 .(isset($bits['query'])?'?'.$bits['query']:'');
45
46 if (strlen($url) > ($before+$after)) :
47 $url = substr($url, 0, $before).'.'.substr($url, 0 - $after, $after);
48 endif;
49
50 return $url;
51 } /* feedwordpress_display_url () */
52
53 function get_syndication_source_property ($original, $id, $local, $remote = NULL) {
54 $p = new FeedWordPressLocalPost($id);
55 return $p->meta($local, array("unproxy" => $original, "unproxied setting" => $remote));
56 } /* function get_syndication_source_property () */
57
58 function get_syndication_source_link ($original = NULL, $id = NULL) {
59 $p = new FeedWordPressLocalPost($id);
60 return $p->syndication_source_link($original);
61 } /* function get_syndication_source_link() */
62
63 function the_syndication_source_link ($original = NULL, $id = NULL) {
64 echo get_syndication_source_link($original, $id);
65 } /* function the_syndication_source_link() */
66
67 function get_syndication_source ($original = NULL, $id = NULL) {
68 $p = new FeedWordPressLocalPost($id);
69 return $p->syndication_source($original);
70 } /* function get_syndication_source() */
71
72 function the_syndication_source ($original = NULL, $id = NULL) {
73 echo get_syndication_source($original, $id);
74 } /* function the_syndication_source () */
75
76 function get_syndication_feed ($original = NULL, $id = NULL) {
77 $p = new FeedWordPressLocalPost($id);
78 return $p->syndication_feed($original);
79 } /* function get_syndication_feed() */
80
81 function the_syndication_feed ($original = NULL, $id = NULL) {
82 echo get_syndication_feed($original, $id);
83 } /* function the_syndication_feed() */
84
85 function get_syndication_feed_guid ($original = NULL, $id = NULL) {
86 $p = new FeedWordPressLocalPost($id);
87 return $p->syndication_feed_guid($original);
88 } /* function get_syndication_feed_guid () */
89
90 function the_syndication_feed_guid ($original = NULL, $id = NULL) {
91 echo get_syndication_feed_guid($original, $id);
92 } /* function the_syndication_feed_guid () */
93
94 function get_syndication_feed_id ($id = NULL) {
95 $p = new FeedWordPressLocalPost($id);
96 return $p->feed_id();
97 } /* function get_syndication_feed_id () */
98
99 function the_syndication_feed_id ($id = NULL) {
100 echo get_syndication_feed_id($id);
101 } /* function the_syndication_feed_id () */
102
103 function get_syndication_feed_object ($id = NULL) {
104 $p = new FeedWordPressLocalPost($id);
105 return $p->feed();
106 } /* function get_syndication_feed_object() */
107
108 function get_feed_meta ($key, $id = NULL) {
109 $ret = NULL;
110
111 $link = get_syndication_feed_object($id);
112 if (is_object($link) and isset($link->settings[$key])) :
113 $ret = $link->settings[$key];
114 endif;
115 return $ret;
116 } /* function get_feed_meta() */
117
118 function get_syndication_permalink ($id = NULL) {
119 $p = new FeedWordPressLocalPost($id);
120 return $p->syndication_permalink();
121 } /* function get_syndication_permalink () */
122
123 function the_syndication_permalink ($id = NULL) {
124 echo get_syndication_permalink($id);
125 } /* function the_syndication_permalink () */
126
127 /**
128 * get_local_permalink: returns a string containing the internal permalink
129 * for a post (whether syndicated or not) on your local WordPress installation.
130 * This may be useful if you want permalinks to point to the original source of
131 * an article for most purposes, but want to retrieve a URL for the local
132 * representation of the post for one or two limited purposes (for example,
133 * linking to a comments page on your local aggregator site).
134 *
135 * @param $id The numerical ID of the post to get the permalink for. If empty,
136 * defaults to the current post in a Loop context.
137 * @return string The URL of the local permalink for this post.
138 *
139 * @uses get_permalink()
140 * @global $feedwordpress_the_original_permalink
141 *
142 * @since 2010.0217
143 */
144 function get_local_permalink ($id = NULL) {
145 global $feedwordpress_the_original_permalink;
146
147 // get permalink, and thus activate filter and force global to be filled
148 // with original URL.
149 $url = get_permalink($id);
150 return $feedwordpress_the_original_permalink;
151 } /* get_local_permalink() */
152
153 /**
154 * the_original_permalink: displays the contents of get_original_permalink()
155 *
156 * @param $id The numerical ID of the post to get the permalink for. If empty,
157 * defaults to the current post in a Loop context.
158 *
159 * @uses get_local_permalinks()
160 * @uses apply_filters
161 *
162 * @since 2010.0217
163 */
164 function the_local_permalink ($id = NULL) {
165 print apply_filters('the_permalink', get_local_permalink($id));
166 } /* function the_local_permalink() */
167
168