1 | <?php
|
---|
2 |
|
---|
3 | class PBALIB extends BDPRSS2
|
---|
4 | {
|
---|
5 |
|
---|
6 | //this class is a collection of the following functions
|
---|
7 | ////functions with parameter definitions
|
---|
8 | // function getdefaultparameter(){ -- moved to get_pbadefaultparameter in pba-defaultparameter__LANG__.php
|
---|
9 | // function get_para_definition(){
|
---|
10 | // function geturlparameter(){
|
---|
11 | // function getoutputconfigparameter($outputid=1){
|
---|
12 | // function process_superparameter($superparameter){
|
---|
13 | // function bootstrap_parameters($firstparafromfunctioncall){
|
---|
14 | //
|
---|
15 | ////functions needed for debugging
|
---|
16 | // function get_r($invar){
|
---|
17 | // function process_profiler($profilerarray=array()){
|
---|
18 | //
|
---|
19 | ////functions to process templates
|
---|
20 | // function template_replacements($template, &$replacements){
|
---|
21 | // function split_template($template, $bodytag=false){
|
---|
22 | // function process_template_conditions($processed_template="", $conditionarray=array()){
|
---|
23 | // function preprocess_headertemplate(&$resultparas, &$pbaout, $footer=false){
|
---|
24 | // function formatheader(&$resultparas, &$pbaout, $footer=false, $formatteditem=false){
|
---|
25 | // function preprocess_itemtemplate(&$resultparas){
|
---|
26 | // function formatitem(&$item, &$resultparas, $resultrownumber){
|
---|
27 | //
|
---|
28 | ////functions to generate href values
|
---|
29 | // function makesearchactionhref(&$resultparas){
|
---|
30 | // function makehiddenformvalues(&$resultparas){
|
---|
31 | // function makecachehref(&$resultparas, $itemid){
|
---|
32 | // function makefeedhref(&$resultparas){
|
---|
33 | // function makehtmlhref(&$resultparas){
|
---|
34 | // function makelastpagehref($lastpage, &$resultparas){
|
---|
35 | // function makenextpagehref($nextpage, &$resultparas){
|
---|
36 | // function makedatepagehref($thedate="", &$resultparas, $regardkalenderlinkpart=false, $forcekalender=false){
|
---|
37 | //
|
---|
38 | ////functions to generate boxes with content
|
---|
39 | // function formatted_feedlist(&$resultparas, $liststyle="sidebar"){
|
---|
40 | // function formatkalender($kalenderdates, &$resultparas, $thedate="", &$pbaout){
|
---|
41 | //
|
---|
42 | //
|
---|
43 | ////helper functions
|
---|
44 | // function analysepagetype(&$resultparas){
|
---|
45 | // function analyze_needed_boxes($rawtemplate){
|
---|
46 | // function makebox($boxtomake, &$resultparas, &$pbaout){
|
---|
47 | // function processtagset($tagsetfromdb){
|
---|
48 | // function gettheage($seconds, &$resultparas=false, &$ageunitsstring=false){
|
---|
49 | // function pba_cache(&$identifier, &$cache_content, $cache_mode='get', $name='c', $type='mixed', $cache_max_time=180, $serverstatus='OK'){
|
---|
50 |
|
---|
51 | //functions with parameter definitions
|
---|
52 | function get_para_definition(){
|
---|
53 | //outcommenting or setting values to false will disable parameters from url
|
---|
54 |
|
---|
55 | //list all possible url parameters for looping through
|
---|
56 | $paralist["url"]["outputid"]=true; //forbidden anyway by default
|
---|
57 | $paralist["url"]["searchphrase"]=true;
|
---|
58 | $paralist["url"]["feedrequest"]=true;
|
---|
59 | $paralist["url"]['opmlrequest']=true;
|
---|
60 | $paralist["url"]['feedlistrequest']=true;
|
---|
61 | $paralist["url"]["tickerpage"]=true;
|
---|
62 | $paralist["url"]["archivdate"]=true;
|
---|
63 | $paralist["url"]["maxitems"]=true;
|
---|
64 | $paralist["url"]["listid"]=true; //forbidden anyway by default, may be opened by function call or later by config
|
---|
65 | $paralist["url"]["kalreq"]=true;
|
---|
66 | $paralist["url"]["cacheid"]=true;
|
---|
67 | $paralist["url"]['srequri']=true; //this is the base url
|
---|
68 |
|
---|
69 | return $paralist;
|
---|
70 | }
|
---|
71 |
|
---|
72 | function geturlparameter(){
|
---|
73 |
|
---|
74 | global $post;
|
---|
75 | if(function_exists('get_page_link')){
|
---|
76 | $stripped_guid=get_page_link();
|
---|
77 | if(!strstr($stripped_guid,'?')
|
---|
78 | && !preg_match('/\/$/',$stripped_guid)
|
---|
79 | ) $stripped_guid = $stripped_guid . '/';
|
---|
80 | $stripped_guid=str_replace($_SERVER['HTTP_HOST'],'',str_replace(array('http://','https://'),'',$stripped_guid));
|
---|
81 | }else{
|
---|
82 | $stripped_guid=str_replace($_SERVER['HTTP_HOST'],'',str_replace(array('http://','https://'),'',$post->guid));
|
---|
83 | }
|
---|
84 | $sanitized_request_uri= substr($_SERVER['REQUEST_URI'],strlen($stripped_guid));
|
---|
85 |
|
---|
86 | // echo "<br>stripped_guid: " . $stripped_guid;
|
---|
87 | // echo "<br>request_uri: " . $_SERVER['REQUEST_URI'];
|
---|
88 | // echo "<br>sanitized_request_uri: " . $sanitized_request_uri;
|
---|
89 |
|
---|
90 | //searchphrase
|
---|
91 | $paras['searchphrase']="";
|
---|
92 | $paras['feedrequest']=false;
|
---|
93 | $paras['opmlrequest']=false;
|
---|
94 | $paras['feedlistrequest']=false;
|
---|
95 | $paras['kalreq']=false;
|
---|
96 | $paras['tickerpage']=1;
|
---|
97 | $paras['cacheid']=false;
|
---|
98 | $paras['archivdate']=false;
|
---|
99 | $paras['outputid']=false;
|
---|
100 | $paras['srequri']=$sanitized_request_uri;
|
---|
101 |
|
---|
102 | if(preg_match("/^opml\//", $sanitized_request_uri)){
|
---|
103 | $paras['opmlrequest']=true;
|
---|
104 | }elseif(preg_match("/^feedlist\//", $sanitized_request_uri)){
|
---|
105 | $paras['feedlistrequest']=true;
|
---|
106 | }elseif(preg_match("/^ticker-feed\//", $sanitized_request_uri)){
|
---|
107 | $paras['feedrequest']=true;
|
---|
108 | }elseif(preg_match("/^tickerpage\/([0-9]+)?\//", $sanitized_request_uri, $pagetemp)){
|
---|
109 | if(preg_match("/^[0-9]+$/",$pagetemp[1])) {
|
---|
110 | $paras['tickerpage']=abs(intval($pagetemp[1]));
|
---|
111 | if($paras['tickerpage']<1) $paras['tickerpage']=1;
|
---|
112 | }
|
---|
113 | }elseif(preg_match("/^[kc]alend[ea]r\/([0-9]{4,4}-[0-9]{2,2}-[0-9]{2,2})?\/?/", $sanitized_request_uri, $kalendertemp)){
|
---|
114 | $paras['kalreq']=true;
|
---|
115 | if(preg_match("/^[0-9]{4,4}-[0-9]{2,2}-[0-9]{2,2}$/",$kalendertemp[1])) $paras['archivdate'] = $kalendertemp[1];
|
---|
116 | }elseif(isset($_GET['kalender'])||isset($_GET['calendar'])){
|
---|
117 | $paras['kalreq']=true;
|
---|
118 | }elseif(isset($_GET['opml'])){
|
---|
119 | $paras['opmlrequest']=true;
|
---|
120 | }elseif(isset($_GET['feedlist'])){
|
---|
121 | $paras['feedlistrequest']=true;
|
---|
122 | }elseif(preg_match("/^([0-9]+)\//", $sanitized_request_uri, $cachetemp)){
|
---|
123 | $paras['cacheid']=abs(intval($cachetemp[1]));
|
---|
124 | }elseif(isset($_GET['cacheid'])){
|
---|
125 | $paras['cacheid']=abs(intval($_GET['cacheid']));
|
---|
126 | }elseif(preg_match("/([0-9]{4,4}-[0-9]{2,2}-[0-9]{2,2})(\/tickerpage\/)?([0-9]+)?\/(feed\/)?/", $sanitized_request_uri, $datetemp)) {
|
---|
127 | if(strstr($datetemp[2] . $datetemp[3]. $datetemp[4],'feed')) $paras['feedrequest']=true;
|
---|
128 | $paras['archivdate']=$datetemp[1];
|
---|
129 | if(preg_match("/^[0-9]+$/",$datetemp[3])) {
|
---|
130 | $paras['tickerpage']=abs(intval($datetemp[3]));
|
---|
131 | if($paras['tickerpage']<1) $paras['tickerpage']=1;
|
---|
132 | }
|
---|
133 | }elseif(preg_match("/^s\/([a-zA-Z0-9-+%_]+)(\/tickerpage\/)?([0-9]+)?\/(feed\/)?/", $sanitized_request_uri, $searchtemp)){
|
---|
134 | $paras['searchphrase']=utf8_encode(urldecode(str_replace("_","+",$searchtemp[1])));
|
---|
135 | if(strstr($searchtemp[2] . $searchtemp[3]. $searchtemp[4],'feed')) $paras['feedrequest']=true;
|
---|
136 | if(preg_match("/^[0-9]+$/",$searchtemp[3])) {
|
---|
137 | $paras['tickerpage']=abs(intval($searchtemp[3]));
|
---|
138 | if($paras['tickerpage']<1) $paras['tickerpage']=1;
|
---|
139 | }
|
---|
140 | }elseif(isset($_GET['searchphrase'])){
|
---|
141 | $paras['searchphrase']=stripslashes($_GET['searchphrase']);
|
---|
142 | $paras['searchphrase']=utf8_encode(urldecode(str_replace("_","+",$paras['searchphrase'])));
|
---|
143 | }
|
---|
144 | if(!$paras['cacheid'] && !$paras['kalreq']) {
|
---|
145 | if(isset($_GET['feed'])) $paras['feedrequest'] = true;
|
---|
146 | if(isset($_GET['tickerpage']) && abs(intval($_GET['tickerpage'])) > 0) $paras['tickerpage'] = abs(intval($_GET['tickerpage']));
|
---|
147 | }
|
---|
148 | if(!$paras['cacheid']){
|
---|
149 | if(isset($_GET['bdprssarchivedate'])) {
|
---|
150 | if(preg_match("/([0-9]{4,4}-[0-9]{2,2}-[0-9]{2,2})/", $_GET['bdprssarchivedate'], $badtemp)) $paras['archivdate'] = $badtemp[1];
|
---|
151 | }elseif(isset($_GET['itemdate'])) {
|
---|
152 | if(preg_match("/([0-9]{4,4}-[0-9]{2,2}-[0-9]{2,2})/", $_GET['itemdate'], $badtemp)) $paras['archivdate'] = $badtemp[1];
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | //echo "itemdate: " . $_GET['itemdate'];
|
---|
157 | //echo "archivdate: " . $paras['archivdate'];
|
---|
158 |
|
---|
159 | if(isset($_GET['bdprsslist'])) $paras['outputid']=abs(intval($_GET['bdprsslist']));
|
---|
160 |
|
---|
161 | //search parameter possible in GET: $search_phrase, $start=0, $max=10, $list_id=0, $itemdate="", $feed="", item_id
|
---|
162 | //output parameter possible in GET: page, outputformat
|
---|
163 |
|
---|
164 | //parameter directly possible in url: search_phrase, itemdate, item_id, page, calendar
|
---|
165 | //indirect parameter in url: list, max
|
---|
166 |
|
---|
167 | return $paras;
|
---|
168 | }
|
---|
169 |
|
---|
170 | function getoutputconfigparameter(&$resultparas){
|
---|
171 | //just overloading $resultparas for speed, not changing
|
---|
172 | global $bdprss_db, $post;
|
---|
173 |
|
---|
174 | if($resultparas['getoutputconfigbypageid']===true){
|
---|
175 | if(abs(intval($post->ID))>0){
|
---|
176 | $outputinfo = $bdprss_db->get_pbaoutput_from_page_id(abs(intval($post->ID)));
|
---|
177 | }
|
---|
178 | }else{
|
---|
179 | $outputid=$resultparas['outputid'];
|
---|
180 | $outputinfo = $bdprss_db->get_pbaoutput(abs(intval($outputid)));
|
---|
181 | }
|
---|
182 |
|
---|
183 | if(!isset($outputinfo->{$bdprss_db->pbaoidentifier})){
|
---|
184 | return false;
|
---|
185 | }
|
---|
186 |
|
---|
187 | //item selection
|
---|
188 | $configparas["outputid"]=abs(intval($outputinfo->{$bdprss_db->pbaoidentifier}));
|
---|
189 | $configparas['outputname']=BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->pbaoname});
|
---|
190 | $configparas["page2hookin"]=abs(intval($outputinfo->page2hookin));
|
---|
191 |
|
---|
192 | $configparas["listid"]=abs(intval($outputinfo->{$bdprss_db->pbaodefaultlist}));
|
---|
193 | $configparas["maxitems"]=abs(intval($outputinfo->{$bdprss_db->pbaomaxitems}));
|
---|
194 | $configparas["formattype"]=BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->pbaoformattype});
|
---|
195 |
|
---|
196 | //item page formatting
|
---|
197 | $configparas["template_ticker"]=BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->pbaotemplate_ticker});
|
---|
198 | $extralinkhelper=$outputinfo->{$bdprss_db->pbaoappend_extra_link};
|
---|
199 | if($extralinkhelper != 'Y') $configparas['noextralink']= 'Y';
|
---|
200 | $configparas["append_cache_link"]=$outputinfo->{$bdprss_db->pbaoappend_cache_link};
|
---|
201 | $configparas["add_social_bookmarks"]=$outputinfo->{$bdprss_db->pbaoadd_social_bookmarks};
|
---|
202 |
|
---|
203 | //item formatting
|
---|
204 | $configparas['maxbodylength']= abs(intval($outputinfo->{$bdprss_db->pbaomaxlength}));
|
---|
205 | $configparas['maxwordlength']= abs(intval($outputinfo->{$bdprss_db->pbaomaxwordlength}));
|
---|
206 | $configparas["itemdateformat"]= BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->pbaoitem_date_format});
|
---|
207 | $configparas["tagset"]= BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->pbaoallowablexhtmltags});
|
---|
208 |
|
---|
209 | //widget paras
|
---|
210 | $configparas['template_sidebarwidget'] = BDPRSS2::codeQuotes($outputinfo->template_sidebarwidget);
|
---|
211 |
|
---|
212 | //cache page options
|
---|
213 | $configparas["iscachable"] = $outputinfo->{$bdprss_db->pbaoiscachable};
|
---|
214 | $configparas["template_cache"]=BDPRSS2::codeQuotes($outputinfo->template_cache);
|
---|
215 | $configparas["cacheviewpage"]= BDPRSS2::codeQuotes($outputinfo->cache_view_page);
|
---|
216 |
|
---|
217 | //feed options
|
---|
218 | $configparas["channel_title"]= BDPRSS2::codeQuotes($outputinfo->channel_title);
|
---|
219 | $configparas["htmlpage"]= BDPRSS2::codeQuotes($outputinfo->channel_link);
|
---|
220 | $configparas["channel_description"]= BDPRSS2::codeQuotes($outputinfo->channel_description);
|
---|
221 | $configparas["channel_language"]= BDPRSS2::codeQuotes($outputinfo->channel_language);
|
---|
222 | $configparas["channel_copyright"]= BDPRSS2::codeQuotes($outputinfo->channel_copyright);
|
---|
223 |
|
---|
224 | //kalender options
|
---|
225 | $configparas["template_kalender"]=BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->otemplate_kalender});
|
---|
226 | $configparas["archive_date_format"]=BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->oarchive_date_format});
|
---|
227 | $configparas["kalendermonthslist"]=BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->okalendermonthslist});
|
---|
228 | $configparas["kalenderboxtablecaption"]=BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->okalenderboxtablecaption});
|
---|
229 | $configparas["kalender_last"]=BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->okalender_last});
|
---|
230 | $configparas["kalender_next"]=BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->okalender_next});
|
---|
231 | $configparas["kalenderboxdaysofweeklist"]=BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->okalenderboxdaysofweeklist});
|
---|
232 |
|
---|
233 | if($bdprss_db->serverstatus['pbacache']['status']=='ok'){
|
---|
234 | if(isset($bdprss_db->serverstatus['full_cache_time']['notice'])) $configparas["pba_full_cache_time"]=$bdprss_db->serverstatus['full_cache_time']['notice'];
|
---|
235 | if(isset($bdprss_db->serverstatus['kalenderquery_cache_time']['notice'])) $configparas["pba_kalenderquery_cache_time"]=$bdprss_db->serverstatus['kalenderquery_cache_time']['notice'];
|
---|
236 | if(isset($bdprss_db->serverstatus['feedlistquery_cache_time']['notice'])) $configparas["pba_feedlistquery_cache_time"]=$bdprss_db->serverstatus['Delete feedlistquery_cache_time']['notice'];
|
---|
237 | }
|
---|
238 | if(isset($bdprss_db->serverstatus['rewriting']['status'])) $configparas["short_cache_link"] = ($bdprss_db->serverstatus['rewriting']['status']=='ok');
|
---|
239 |
|
---|
240 | $configparas["superparameter"]=BDPRSS2::codeQuotes($outputinfo->{$bdprss_db->pbao_superparameter});
|
---|
241 |
|
---|
242 | $superparameterarray=PBALIB::process_superparameter($configparas["superparameter"]);
|
---|
243 | foreach($superparameterarray as $paraname => $paravalue){
|
---|
244 | $configparas[$paraname]=$paravalue;
|
---|
245 | }
|
---|
246 | unset ($configparas["superparameter"]);
|
---|
247 |
|
---|
248 | return $configparas;
|
---|
249 | }
|
---|
250 |
|
---|
251 | function process_superparameter($superparameter=""){
|
---|
252 | $superparameterarray=array();
|
---|
253 | preg_match_all("'###SUPERPARAMETER_([A-Za-z0-9_-]+?)_BEGIN###(.*?)###SUPERPARAMETER_[A-Za-z0-9_-]*?END###'s", $superparameter, $match);
|
---|
254 | //print_r($match);
|
---|
255 | if(is_array($match) && isset($match[1]) && isset($match[2])){
|
---|
256 | foreach($match[1] as $match1key => $match1value){
|
---|
257 | //echo "<br>matchkey is : " . $matchkey . "value is: ";
|
---|
258 | if(trim($match[2][$match1key]) == "false") {
|
---|
259 | $superparameterarray[$match1value]=false;
|
---|
260 | }elseif(trim($match[2][$match1key]) == "true"){
|
---|
261 | $superparameterarray[$match1value]=true;
|
---|
262 | }else{
|
---|
263 | $superparameterarray[$match1value]=$match[2][$match1key];
|
---|
264 | }
|
---|
265 | }
|
---|
266 | //print_r($superparameterarray);
|
---|
267 | }
|
---|
268 | return $superparameterarray;
|
---|
269 | }
|
---|
270 |
|
---|
271 | function bootstrap_parameters($firstparafromfunctioncall){
|
---|
272 | global $post;
|
---|
273 |
|
---|
274 | //initialize all neeeded parameters with default values
|
---|
275 | $resultparas=get_pbadefaultparameter();
|
---|
276 | //get lists in array to name all possible parameters for looping through
|
---|
277 | $paralist=PBALIB::get_para_definition();
|
---|
278 |
|
---|
279 | $resultparas['url2plugindir'] = get_option('home') . '/wp-content/plugins/'.PBA_DIRECTORY.'/';
|
---|
280 |
|
---|
281 | //$pbaout['debug'] .= "\n<br>Debug: Default resultparas: " . PBALIB::get_r($resultparas);
|
---|
282 |
|
---|
283 | //get function call parameters
|
---|
284 | if(is_array($firstparafromfunctioncall)) $funcdefparas=$firstparafromfunctioncall;
|
---|
285 |
|
---|
286 | //'N' meaning not set used for backward compatibility
|
---|
287 | //stupid idea? we possibly may use false to overwrite the maxitems in function call
|
---|
288 | if($funcdefparas["maxitems"] == 'N') unset($funcdefparas["maxitems"]);
|
---|
289 |
|
---|
290 | //we have got all parameters from function call now and normalized them
|
---|
291 | //$pbaout['debug'] .= "\n<br>Debug: funcdefparas: " . PBALIB::get_r($funcdefparas);
|
---|
292 |
|
---|
293 | //if exist, we overwrite default output id paras with paras from func call, do other later
|
---|
294 | //we unset the output id function parameters, so they will not overwrite config parameter values later
|
---|
295 | if(isset($funcdefparas['outputid'])) {
|
---|
296 | $resultparas['outputid'] = $funcdefparas['outputid'];
|
---|
297 | }else{
|
---|
298 | if(isset($funcdefparas['getoutputconfigbypageid'])) $resultparas['getoutputconfigbypageid'] = $funcdefparas['getoutputconfigbypageid'];
|
---|
299 | }
|
---|
300 | unset($funcdefparas["outputid"]);
|
---|
301 | unset($funcdefparas['getoutputconfigbypageid']);
|
---|
302 | if(isset($funcdefparas['outputidfromurlallowed'])) $resultparas['outputidfromurlallowed'] = $funcdefparas['outputidfromurlallowed'];
|
---|
303 | unset($funcdefparas["outputidfromurlallowed"]);
|
---|
304 |
|
---|
305 |
|
---|
306 | //get parameters from url
|
---|
307 | $urlparas=PBALIB::geturlparameter();
|
---|
308 | //$pbaout['debug'] .= "\n<br>Debug: urlparas: " . PBALIB::get_r($urlparas);
|
---|
309 |
|
---|
310 | //now let's apply limits to url parameter output_id and find out the output id to take
|
---|
311 | //first normalize output id parameter from url - check other values later
|
---|
312 | $urlparas['outputid']=abs(intval($urlparas['outputid']));
|
---|
313 | if(!$urlparas['outputid']>0) unset($urlparas['outputid']);
|
---|
314 |
|
---|
315 | if($resultparas['outputidfromurlallowed'] === false){
|
---|
316 | unset($urlparas['outputid']);
|
---|
317 | }elseif($resultparas['outputidfromurlallowed'] !== true){
|
---|
318 | if(!strstr("," . str_replace(" ", '', $resultparas['outputidfromurlallowed']) . ",", $urlparas['outputid'])) unset($urlparas['outputid']);
|
---|
319 | }
|
---|
320 | if(isset($urlparas['outputid'])) $resultparas['outputid'] = intval($urlparas['outputid']);
|
---|
321 |
|
---|
322 | //now we know, which output definition we have to take from db -> let's get it
|
---|
323 | $configparas=PBALIB::getoutputconfigparameter($resultparas);
|
---|
324 | if(!is_array($configparas)) {
|
---|
325 | return false;
|
---|
326 | }
|
---|
327 |
|
---|
328 | if(function_exists('get_page_link')){
|
---|
329 | if($funcdefparas['show_sidebarwidget'] == 'Y'
|
---|
330 | && $configparas['page2hookin'] > 0){
|
---|
331 | $resultparas['baseurl']=get_page_link($configparas['page2hookin']);
|
---|
332 | $resultparas['search_page_baseurl']="";
|
---|
333 | }else{
|
---|
334 | $resultparas['baseurl']=get_page_link();
|
---|
335 | }
|
---|
336 | if(!strstr($resultparas['baseurl'],'?')
|
---|
337 | && !preg_match('/\/$/',$resultparas['baseurl'])
|
---|
338 | ) $resultparas['baseurl'] = $resultparas['baseurl'] . '/';
|
---|
339 | }else{
|
---|
340 | $resultparas['baseurl'] = $post->guid;
|
---|
341 | }
|
---|
342 | if($resultparas['search_page_baseurl']=="") $resultparas['search_page_baseurl'] = $resultparas['baseurl'];
|
---|
343 | if($resultparas['htmlpage']=="")$resultparas['htmlpage'] = $resultparas['baseurl'];
|
---|
344 | if($configparas["htmlpage"]=="") unset($configparas["htmlpage"]); //this will make the default post->guid be used
|
---|
345 |
|
---|
346 | //copy config paras over default paras
|
---|
347 | if($configparas){
|
---|
348 | foreach($configparas as $paraname => $paravalue){
|
---|
349 | $resultparas[$paraname]=$paravalue;
|
---|
350 | }
|
---|
351 | }
|
---|
352 |
|
---|
353 | //copy func defined paras over default paras
|
---|
354 | if($funcdefparas){
|
---|
355 | foreach($funcdefparas as $paraname => $paravalue){
|
---|
356 | $resultparas[$paraname]=$paravalue;
|
---|
357 | }
|
---|
358 | }
|
---|
359 |
|
---|
360 | //check if we want to show a sidebar
|
---|
361 | if($resultparas['show_sidebarwidget'] == 'Y'){
|
---|
362 | $resultparas['template_ticker']=$resultparas['template_sidebarwidget'];
|
---|
363 | $resultparas["add_social_bookmarks"]='N';
|
---|
364 | unset($urlparas['searchphrase']);
|
---|
365 | unset($urlparas['cacheid']);
|
---|
366 | unset($urlparas['kalreq']);
|
---|
367 | }
|
---|
368 |
|
---|
369 | //to be completed filter url parameter to allowed values
|
---|
370 | if($resultparas['listidfromurlallowed'] === false){
|
---|
371 | unset($urlparas['listid']);
|
---|
372 | }elseif($resultparas['listidfromurlallowed'] !== true){
|
---|
373 | if(!strstr("," . str_replace(" ", '', $resultparas['listidfromurlallowed']) . ",", $urlparas['listid'])) unset($urlparas['listid']);
|
---|
374 | }
|
---|
375 | if($urlparas['kalreq'] === false) unset($paralist["url"]["kalreq"]);
|
---|
376 | if($urlparas['feedrequest'] === false) unset($paralist["url"]["feedrequest"]);
|
---|
377 | if($resultparas['searchenabled']){
|
---|
378 | $resultparas['searchactionhref'] = PBALIB::makesearchactionhref($resultparas);
|
---|
379 | $resultparas['hiddensearchformformvalues'] = PBALIB::makehiddenformvalues($resultparas);
|
---|
380 | $urlparas['searchphrase']=utf8_decode($urlparas['searchphrase']);
|
---|
381 | }else{
|
---|
382 | unset($urlparas['searchphrase']);
|
---|
383 | $resultparas['template_search_box']="";
|
---|
384 | }
|
---|
385 |
|
---|
386 | //copy url paras over result got by funcdef paras copying
|
---|
387 | foreach($paralist["url"] as $paraname => $paravalue){
|
---|
388 | if(isset($urlparas[$paraname])){
|
---|
389 | if($paravalue) $resultparas[$paraname]=$urlparas[$paraname]; //false means not overwriting !!!
|
---|
390 | }
|
---|
391 | }
|
---|
392 | return $resultparas;
|
---|
393 | }
|
---|
394 |
|
---|
395 | //functions needed for debugging
|
---|
396 | function get_r($invar){
|
---|
397 | ob_start();
|
---|
398 | print_r($invar);
|
---|
399 | $outvar = ob_get_contents();
|
---|
400 | ob_end_clean();
|
---|
401 | return $outvar;
|
---|
402 | }
|
---|
403 |
|
---|
404 | function process_profiler($profilerarray=array()){
|
---|
405 | $profilerself['Profiler reached at']=microtime();
|
---|
406 | $profilerarray=array_merge($profilerarray, $profilerself);
|
---|
407 | $precision=4;
|
---|
408 | $first=true;
|
---|
409 | $counter=0;
|
---|
410 | $outstring="\nOutput from Profiler:";
|
---|
411 | foreach($profilerarray as $point => $microtimer){
|
---|
412 | $timearray = explode(" ", $microtimer);
|
---|
413 | $microtimestamp = (substr($timearray[1],6,4) + substr($timearray[0],0,$precision + 2));
|
---|
414 | if($first) { $starttime = $microtimestamp; $last=$microtimestamp; $first=false; $outstring .= "<table>"; }
|
---|
415 | $outstring .= "<tr>\n<td>Checkpoint: " . $point .
|
---|
416 | "</td><td> Time: " . substr($timearray[1],0,6) . $microtimestamp .
|
---|
417 | "</td><td> Diff: " . round($microtimestamp - $last,$precision) .
|
---|
418 | "</td><td> Total: " . round($microtimestamp - $starttime,$precision) . "</td>\n</tr>";
|
---|
419 | $last=$microtimestamp;
|
---|
420 | }
|
---|
421 | $outstring .= "</table>";
|
---|
422 | return $outstring;
|
---|
423 | }
|
---|
424 |
|
---|
425 | //functions to process page templates
|
---|
426 | function template_replacements($template, &$replacements){
|
---|
427 | //we will not change input values, but pass replacements like eg resultparas by reference parameters to be quick,
|
---|
428 | //is it really neccessary? or will the php optimizer understand itself not to pass variables as value,
|
---|
429 | //until the value is not changed?
|
---|
430 | preg_match_all('/###[0-9A-Z_]+###/', $template, $uppertags);
|
---|
431 | foreach($uppertags[0] as $key => $uppertag){
|
---|
432 | $tag=str_replace('#','',strtolower($uppertag));
|
---|
433 | if(isset($replacements[$tag])) {
|
---|
434 | $needle[]=$uppertag;
|
---|
435 | $replace[]=$replacements[$tag];
|
---|
436 | }
|
---|
437 | }
|
---|
438 | $processed_template=str_replace($needle, $replace, $template);
|
---|
439 | return $processed_template;
|
---|
440 | }
|
---|
441 |
|
---|
442 | function split_template($template, $bodytag=false, $looptag='LOOP', $headeronly=false){
|
---|
443 | if($bodytag===false) $bodytag = '###INSIDELOOP###';
|
---|
444 | $split_template['aroundloop']=preg_replace('/###'.$looptag.'BEGIN###.*?###'.$looptag.'END###/s',$bodytag,$template);
|
---|
445 | preg_match("'(.*)###".$looptag."BEGIN###(.*?)###".$looptag."END###(.*)'s", $template, $match);
|
---|
446 | $split_template['beforeloop']=$match[1];
|
---|
447 | $split_template['inloop']=$match[2];
|
---|
448 | $split_template['postloop']=$match[3];
|
---|
449 | if($headeronly=="header"){
|
---|
450 | return $split_template['beforeloop'];
|
---|
451 | }elseif($headeronly=="footer"){
|
---|
452 | return $split_template['postloop'];
|
---|
453 | }elseif($headeronly=="body"){
|
---|
454 | return $split_template['inloop'];
|
---|
455 | }elseif($headeronly=="aroundloop"){
|
---|
456 | return $split_template['aroundloop'];
|
---|
457 | }
|
---|
458 | return $split_template;
|
---|
459 | }
|
---|
460 |
|
---|
461 | function process_template_conditions($processed_template="", $conditionarray=array()){
|
---|
462 | foreach($conditionarray as $value){
|
---|
463 | $conditionaltag=$value['tag'];
|
---|
464 | $expression=$value['expression'];
|
---|
465 | if($expression !== true) $expression = false;
|
---|
466 | if($expression) {
|
---|
467 | $conditionaltagarray=array('###'.$conditionaltag.'BEGIN###', '###'.$conditionaltag.'END###');
|
---|
468 | $processed_template = str_replace($conditionaltagarray , '', $processed_template);
|
---|
469 | } else {
|
---|
470 | $processed_template=PBALIB::split_template($processed_template, '', $conditionaltag, 'aroundloop');
|
---|
471 | }
|
---|
472 | }
|
---|
473 | return $processed_template;
|
---|
474 | }
|
---|
475 |
|
---|
476 | function preprocess_headertemplate(&$resultparas, &$pbaout, $footer=false){
|
---|
477 | $pre="pre";
|
---|
478 | if($footer) $pre="post";
|
---|
479 | if($resultparas["profiler_enabled"]) $pbaout['profiler']['Start making a ' . $pre . ' header']=microtime();
|
---|
480 | if($resultparas['kalreq']) {
|
---|
481 | $pbaheader = $resultparas['template_' . $resultparas['template']];
|
---|
482 | }elseif($resultparas['pagetype'] == 'cachepage'){
|
---|
483 | $pbaheader = $resultparas['template_' . $resultparas['template']];
|
---|
484 | }elseif($resultparas['feedrequest']) {
|
---|
485 | $pbaheader_tmp = $resultparas['template_' . $resultparas['template']];
|
---|
486 | $headeronly="header";
|
---|
487 | if($footer) $headeronly="footer";
|
---|
488 | $pbaheader = PBALIB::split_template($pbaheader_tmp, false, 'LOOP', $headeronly);
|
---|
489 | // $pbaheader=$resultparas[$pre . '_loop_feedtemplate'];
|
---|
490 | } else {
|
---|
491 | $pbaheader_tmp = $resultparas['template_' . $resultparas['template']];
|
---|
492 | $headeronly="header";
|
---|
493 | if($footer) $headeronly="footer";
|
---|
494 | $pbaheader = PBALIB::split_template($pbaheader_tmp, false, 'LOOP', $headeronly);
|
---|
495 | // $pbaheader=$resultparas[$pre . '_loop_template'];
|
---|
496 | if($footer && $resultparas['add_social_bookmarks']=="Y") {
|
---|
497 | //this looks stupid, why to format it here?
|
---|
498 | $pbaheader = str_replace('###URL2PLUGINDIR###' , $resultparas['url2plugindir'], $resultparas['headersbtemplate']) . $pbaheader;
|
---|
499 | }
|
---|
500 | }
|
---|
501 |
|
---|
502 | //first let's cut out the condional parts, where the condition is false
|
---|
503 | //Syntax: $conditionarray[]=array('tag' =>'MYCONDITIONALTAG','expression' => (true));
|
---|
504 |
|
---|
505 | //why to use such sloppy conditions here - haven't we calculated pagetype for this?
|
---|
506 | $conditionarray[]=array('tag' =>'ISSEARCH','expression' => ($resultparas['searchphrase'] !=""));
|
---|
507 | $conditionarray[]=array('tag' =>'ISDATE','expression' => ($resultparas['archivdate']!=""));
|
---|
508 | $conditionarray[]=array('tag' =>'ISNODATENOSEARCH','expression' => ($resultparas['searchphrase'] =="" && $resultparas['archivdate']==""));
|
---|
509 | $conditionarray[]=array('tag' =>'LASTLINK','expression' => ($pbaout['lastpageexists']));
|
---|
510 | $conditionarray[]=array('tag' =>'NEXTLINK','expression' => ($pbaout['nextpageexists']));
|
---|
511 |
|
---|
512 | if($resultparas["debug"]) $pbaout['debug'] .= "\n<br>Debug: conditionarray: " . PBALIB::get_r($conditionarray);
|
---|
513 | $pbaheader=PBALIB::process_template_conditions($pbaheader, $conditionarray);
|
---|
514 |
|
---|
515 | if($resultparas["debug"]) $pbaout['debug'] .= "\n<br>Debug: See the pbaheader: " . PBALIB::get_r($pbaheader);
|
---|
516 |
|
---|
517 | return $pbaheader;
|
---|
518 | }
|
---|
519 |
|
---|
520 | function formatheader(&$resultparas, &$pbaout, $footer=false, $formatteditem=false, $pbaheader){
|
---|
521 |
|
---|
522 | //will see later if we need more paras
|
---|
523 |
|
---|
524 | //variables we understand
|
---|
525 | if($resultparas['cacheid']>0) $formattedheader = $formatteditem; //copy over variables from loop to understand them here
|
---|
526 | $formattedheader['searchphrase']=$resultparas['searchphrase'];
|
---|
527 | $formattedheader['archivedate']=$resultparas['archivdate'];
|
---|
528 | $formattedheader['feedhref']=$resultparas['feedhref'];
|
---|
529 | $formattedheader['founditems']=$pbaout['founditems'];
|
---|
530 | $formattedheader['startitem']=$pbaout['startitem'];
|
---|
531 | $formattedheader['lastitem']=$pbaout['lastitem'];
|
---|
532 | $formattedheader['lastpage']=$pbaout['lastpage'];
|
---|
533 | $formattedheader['nextpage']=$pbaout['nextpage'];
|
---|
534 | $formattedheader['lastpagehref']=$pbaout['lastpagehref'];
|
---|
535 | $formattedheader['nextpagehref']=$pbaout['nextpagehref'];
|
---|
536 | $formattedheader['kalenderhref']=$resultparas['kalenderhref'];
|
---|
537 | $formattedheader['feedlisthref']=$resultparas['feedlisthref'];
|
---|
538 | $formattedheader['feedopmlhref']=$resultparas['feedopmlhref'];
|
---|
539 | $formattedheader['outputname']=$resultparas['outputname'];
|
---|
540 |
|
---|
541 | $formattedheader['channel_title']=$resultparas["channel_title"];
|
---|
542 | $formattedheader['htmlpage']=$resultparas["htmlpage"];
|
---|
543 | $formattedheader['channel_description']=$resultparas["channel_description"];
|
---|
544 | $formattedheader['channel_language']=$resultparas["channel_language"];
|
---|
545 | $formattedheader['channel_copyright']=$resultparas["channel_copyright"];
|
---|
546 | $formattedheader['firstitem_datefeed']= $pbaout['firstitem_datefeed'];
|
---|
547 | $formattedheader['htmlhref']= $resultparas['htmlhref'];
|
---|
548 | $formattedheader['baseurl']=$resultparas['baseurl'];
|
---|
549 | $formattedheader['pba_version']= PBA_PRODUCT . " " . PBA_VERSION;
|
---|
550 |
|
---|
551 | $formattedheader['kalenderdate']=$pbaout['kalenderdate'];
|
---|
552 |
|
---|
553 | //boxes we understand
|
---|
554 | $formattedheader['kalenderlist_box']=$pbaout['kalenderlist_box'];
|
---|
555 | $formattedheader['kalender_box']=$pbaout['kalender_box'];
|
---|
556 | $formattedheader['feedlistsidebar_box']=$pbaout['feedlistsidebar_box'];
|
---|
557 | $formattedheader['search_box']=$pbaout['search_box'];
|
---|
558 |
|
---|
559 | //now do the final replacements
|
---|
560 | foreach($formattedheader as $key => $value){
|
---|
561 | $needle[$key]="###" . strtoupper($key) . "###";
|
---|
562 | //echo $needle[$key] . "\n"; //take this to find out with variables the engine understands
|
---|
563 | $replace[$key]=$value;
|
---|
564 | }
|
---|
565 |
|
---|
566 | // if($pre=="post" && $resultparas["debug"]) $pbaout['debug1'] .= "\n<br>Debug: See the needles: " . PBALIB::get_r($needle);
|
---|
567 | // if($pre=="post" && $resultparas["debug"]) $pbaout['debug1'] .= "\n<br>Debug: See the replaces: " . PBALIB::get_r($replace);
|
---|
568 | // if($pre=="post" && $resultparas["debug"]) $pbaout['debug1'] .= "\n<br>Debug: See the template: " . PBALIB::get_r($pbaheader);
|
---|
569 |
|
---|
570 | $formattedheader['result']=str_replace($needle, $replace, $pbaheader);
|
---|
571 | return $formattedheader;
|
---|
572 | }
|
---|
573 |
|
---|
574 | function preprocess_itemtemplate(&$resultparas){
|
---|
575 | //get the item template
|
---|
576 | if($resultparas['cacheid']>0){
|
---|
577 | $itemtemplate=""; //just an empty template, we will print it with the footer - is this clever???
|
---|
578 | }elseif($resultparas['feedrequest']){
|
---|
579 | $itemtemplate_tmp = $resultparas['template_' . $resultparas['template']];//fixme later to template come from resultparas again, was before: $itemtemplate=$resultparas['in_loop_feedtemplate'];
|
---|
580 | $itemtemplate = PBALIB::split_template($itemtemplate_tmp, false, 'LOOP', 'body');
|
---|
581 | }else{
|
---|
582 | $itemtemplate_tmp = $resultparas['template_' . $resultparas['template']];
|
---|
583 | $itemtemplate = PBALIB::split_template($itemtemplate_tmp, false, 'LOOP', 'body');
|
---|
584 | if($resultparas['add_social_bookmarks']=="Y") $itemtemplate = str_replace('###ITEM_BODY###' , '###ITEM_BODY###' . $resultparas['itemssbtemplate'], $itemtemplate);
|
---|
585 | }
|
---|
586 | //add some standard components to the template, if desired
|
---|
587 | if($resultparas["iscachable"]=="Y" && $resultparas["append_cache_link"]=="Y") $itemtemplate = str_replace('###ITEM_BODY###' , '###ITEM_BODY###' . $resultparas['cachelinktemplate'], $itemtemplate);
|
---|
588 | if($resultparas["noextralink"]!="Y") $itemtemplate = str_replace('###ITEM_BODY###' , '###ITEM_BODY###' . $resultparas['extralinktemplate'], $itemtemplate);
|
---|
589 |
|
---|
590 | return $itemtemplate;
|
---|
591 | }
|
---|
592 |
|
---|
593 | function formatitem(&$item, &$resultparas, $itemtemplate, $resultrownumber, $itemvaluesneeded=false){
|
---|
594 | //takes an item-site object row from dbquery and gives back
|
---|
595 | //in array field result the result,
|
---|
596 | //and further in array field debug some debug output
|
---|
597 |
|
---|
598 | //the row number in the list given out
|
---|
599 | $formatteditem['result_rownumber']=$resultrownumber + 1;
|
---|
600 |
|
---|
601 | $formatteditem['baseurl']=$resultparas['baseurl'];
|
---|
602 |
|
---|
603 | //read in the row ... for site
|
---|
604 | $formatteditem['site_id']=$item->siteid;
|
---|
605 | $formatteditem['site_name']=$item->site_name;
|
---|
606 | $formatteditem['site_feedurl']=$item->feed_url;
|
---|
607 | $formatteditem['site_nameoverridden']=$item->site_name_overriden;
|
---|
608 | $formatteditem['site_description']=$item->description;
|
---|
609 | $formatteditem['site_license']=$item->site_license;
|
---|
610 | $formatteditem['site_url']=$item->site_url;
|
---|
611 | $formatteditem['site_updatetime']=$item->site_update_time;
|
---|
612 |
|
---|
613 | //read in the row ... for item
|
---|
614 | $formatteditem['item_id']=$item->itemid;
|
---|
615 | $formatteditem['item_url']=$item->item_url;
|
---|
616 | $formatteditem['item_name']=$item->item_name;
|
---|
617 | $formatteditem['item_sitename']=$item->item_site_name;
|
---|
618 | $formatteditem['item_siteurl']=$item->item_site_url;
|
---|
619 | $formatteditem['item_license']=$item->item_license;
|
---|
620 | $formatteditem['item_timestamp']=$item->item_time;
|
---|
621 | $formatteditem['item_updatetimestamp']=$item->item_update_time;
|
---|
622 | $formatteditem['item_body']=$item->text_body;
|
---|
623 |
|
---|
624 | //we got the rows from database,
|
---|
625 | //now do some quick processing with the raw row values
|
---|
626 | //and get in this way some new values
|
---|
627 |
|
---|
628 | $formatteditem['cachehref']=PBALIB::makecachehref($resultparas, $formatteditem['item_id']);
|
---|
629 |
|
---|
630 | //make an item text as to be displayed as cache item
|
---|
631 | if($itemvaluesneeded['item_cachebody']){
|
---|
632 | $formatteditem['item_cachebody'] = BDPRSS2::codeQuotes($formatteditem['item_body']);
|
---|
633 | $formatteditem['item_cachebody'] = eregi_replace('<' , '<', $formatteditem['item_cachebody']);
|
---|
634 | $formatteditem['item_cachebody'] = eregi_replace('>' , '>', $formatteditem['item_cachebody']);
|
---|
635 | }
|
---|
636 |
|
---|
637 | //process the item body
|
---|
638 | if($itemvaluesneeded['item_body'] || $itemvaluesneeded['item_cachebody'] || $itemvaluesneeded['item_feedbody'] || $itemvaluesneeded['item_description']){
|
---|
639 | $formatteditem['item_body']=BDPRSS2::remove_link_and_cache_links_from_item($formatteditem['item_body']);
|
---|
640 | }
|
---|
641 | //this seems to be for feed usage
|
---|
642 | if($itemvaluesneeded['item_description']){
|
---|
643 | $formatteditem['item_description'] = BDPRSS2::packageItemText($formatteditem['item_body'], $resultparas['maxbodylength'], $resultparas['maxwordlength'], false, $resultparas['formattedtagset']);
|
---|
644 | }
|
---|
645 | if($itemvaluesneeded['item_feedbody']){
|
---|
646 | $formatteditem['item_feedbody']= $formatteditem['item_body'];
|
---|
647 | }
|
---|
648 | $formatteditem['item_datefeed']= date('r', $formatteditem['item_timestamp']);
|
---|
649 | if($formatteditem['result_rownumber'] == 1) $formatteditem['firstitem_datefeed'] = $formatteditem['item_datefeed'];
|
---|
650 |
|
---|
651 | //package item text for list description display
|
---|
652 | if($itemvaluesneeded['item_body']){
|
---|
653 | $formatteditem['item_body'] = BDPRSS2::packageItemText($formatteditem['item_body'], $resultparas['maxbodylength'], $resultparas['maxwordlength'], true, $resultparas['formattedtagset']);
|
---|
654 | }
|
---|
655 | //process item titles decode ": " separator in item titles -- may be buggy, needs to come from site details overridden and have some testing
|
---|
656 | if($formatteditem['site_nameoverridden'] != 'Y'){
|
---|
657 | $itemtitlearray=explode(': ', $formatteditem['item_name'], 2);
|
---|
658 | if(strlen($itemtitlearray[1])>0) {
|
---|
659 | $formatteditem['item_name'] = $itemtitlearray[1];
|
---|
660 | $formatteditem['site_name'] = $itemtitlearray[0];
|
---|
661 | }else{
|
---|
662 | //site name not overridden, but no : in item
|
---|
663 | $formatteditem['site_name']=$formatteditem['item_sitename'];
|
---|
664 | }
|
---|
665 | } else {
|
---|
666 | //site_name overridden
|
---|
667 | $formatteditem['site_name'] = $formatteditem['site_name']; //bogus, no need for this
|
---|
668 | }
|
---|
669 |
|
---|
670 | if(strlen($formatteditem['item_siteurl'])>0) $formatteditem['site_url'] = $formatteditem['item_siteurl'];
|
---|
671 |
|
---|
672 | $formatteditem['site_name'] = BDPRSS2::packageItemText($formatteditem['site_name']);
|
---|
673 | $formatteditem['item_name'] = BDPRSS2::packageItemText($formatteditem['item_name']);
|
---|
674 |
|
---|
675 | //generate dates in some configured and standard formats
|
---|
676 | if(strlen($resultparas["itemdateformat"]."") >0){
|
---|
677 | $formatteditem['item_datetime'] = date($resultparas["itemdateformat"]."", ($formatteditem['item_timestamp'])+(0*3600));
|
---|
678 | } else {
|
---|
679 | $formatteditem['item_datetime'] = PBALIB::gettheage($formatteditem['item_timestamp'], $resultparas['ageunit'], $resultparas['ageunitsstring']);
|
---|
680 | }
|
---|
681 |
|
---|
682 | if(strlen($resultparas["itemdateformat"]."") >0){
|
---|
683 | $formatteditem['item_updatedatetime'] = date($resultparas["itemdateformat"]."", ($formatteditem['item_updatetimestamp'])+(0*3600));
|
---|
684 | } else {
|
---|
685 | $formatteditem['item_updatedatetime'] = PBALIB::gettheage($formatteditem['item_updatetimestamp'], $resultparas['ageunit'], $resultparas['ageunitsstring']);
|
---|
686 | }
|
---|
687 | $formatteditem['item_updatedate']= date('r', $formatteditem['item_updatetimestamp']);
|
---|
688 |
|
---|
689 | //unset not needed values, to be done later
|
---|
690 | unset ($formatteditem['item_sitename']);
|
---|
691 | unset ($formatteditem['item_siteurl']);
|
---|
692 | unset ($formatteditem['site_nameoverridden']);
|
---|
693 |
|
---|
694 | //build up variables for the template
|
---|
695 | $result=PBALIB::template_replacements($itemtemplate, &$formatteditem);
|
---|
696 | $formatteditem['result']=$result;
|
---|
697 | // foreach($formatteditem as $key => $value){
|
---|
698 | // $needle[$key]="###" . strtoupper($key) . "###";
|
---|
699 | // echo $needle[$key] . "\n"; //take this to find out with variables the engine understands
|
---|
700 | // $replace[$key]=$value;
|
---|
701 | // }
|
---|
702 | // $formatteditem['result']=str_replace($needle, $replace, $itemtemplate);
|
---|
703 | return $formatteditem;
|
---|
704 | }
|
---|
705 |
|
---|
706 | //functions to generate href values
|
---|
707 | function makefeedlisthref(&$resultparas){
|
---|
708 | if($resultparas['short_cache_link']){
|
---|
709 | $feedlisthref = $resultparas['baseurl'] . 'feedlist/';
|
---|
710 | }else{
|
---|
711 | $joiner='?';
|
---|
712 | if(strstr($resultparas['baseurl'], '?')) $joiner = '&';
|
---|
713 | $feedlisthref = $resultparas['baseurl'] . $joiner . 'feedlist';
|
---|
714 | }
|
---|
715 | return $feedlisthref;
|
---|
716 | }
|
---|
717 |
|
---|
718 |
|
---|
719 | function makefeedopmlhref(&$resultparas){
|
---|
720 | if($resultparas['short_cache_link']){
|
---|
721 | $feedopmlhref = $resultparas['baseurl'] . 'opml/';
|
---|
722 | }else{
|
---|
723 | $joiner='?';
|
---|
724 | if(strstr($resultparas['baseurl'], '?')) $joiner = '&';
|
---|
725 | $feedopmlhref = $resultparas['baseurl'] . $joiner . 'opml';
|
---|
726 | }
|
---|
727 | return $feedopmlhref;
|
---|
728 | }
|
---|
729 |
|
---|
730 | function makesearchactionhref(&$resultparas){
|
---|
731 | if(strstr($resultparas['search_page_baseurl'],'?')) {
|
---|
732 | $searchactionhref=$resultparas['search_page_baseurl'];
|
---|
733 | }else{
|
---|
734 | $searchactionhref=$resultparas['search_page_baseurl'] . 'index.php';
|
---|
735 | }
|
---|
736 | return $searchactionhref;
|
---|
737 | }
|
---|
738 |
|
---|
739 | function makehiddenformvalues(&$resultparas){
|
---|
740 | $hiddenformvalues = "";
|
---|
741 | if(preg_match('/\?(.+)$/',$resultparas['search_page_baseurl'],$baseurlquerystring)) {
|
---|
742 | parse_str($baseurlquerystring[1], $baseurlgetarray);
|
---|
743 | //print_r($baseurlgetarray);
|
---|
744 | foreach($baseurlgetarray as $key => $value){
|
---|
745 | $hiddenformvalues .= '<input type="hidden" name="'.$key.'" value="'.$value.'" />';
|
---|
746 | }
|
---|
747 | }
|
---|
748 | return $hiddenformvalues;
|
---|
749 | }
|
---|
750 |
|
---|
751 | function makecachehref(&$resultparas, $itemid){
|
---|
752 | //not changing resultparas, just passing by reference to gain speed
|
---|
753 | $itemid=abs(intval($itemid));
|
---|
754 | $baseurl = $resultparas['baseurl'];
|
---|
755 | if($resultparas['cacheviewpage'] != "" ) $baseurl = $resultparas['cacheviewpage'];
|
---|
756 |
|
---|
757 | if($resultparas['short_cache_link']){
|
---|
758 | $cachehref = $baseurl . $itemid . '/';
|
---|
759 | }else{
|
---|
760 | $joiner='?';
|
---|
761 | if(strstr($baseurl, '?')) $joiner = '&';
|
---|
762 | $cachehref = $baseurl . $joiner . 'cacheid=' . $itemid;
|
---|
763 | }
|
---|
764 | return $cachehref;
|
---|
765 | }
|
---|
766 |
|
---|
767 |
|
---|
768 | function makefeedhref(&$resultparas){
|
---|
769 | //not changing resultparas, just passing by reference to gain speed
|
---|
770 | //calculate the link to the feedalized version of this page
|
---|
771 | if(!$resultparas['feedrequest']){
|
---|
772 | if($resultparas['feedpage']!="") {
|
---|
773 | //use this url replaced by feedurlbase and strip page info
|
---|
774 | $feedhref=$resultparas['feedpage'] . preg_replace("/[&\?]?tickerpage[\/=][0-9]+\/?/s", '', $resultparas['srequri']);
|
---|
775 | }else{
|
---|
776 | $feedhref= $resultparas['baseurl'] . preg_replace("/[&\?]?tickerpage[\/=][0-9]+\/?/s", '', $resultparas['srequri']);
|
---|
777 | if(strstr($feedhref,'?')) {
|
---|
778 | $feedhref .= '&feed';
|
---|
779 | } else {
|
---|
780 | if($resultparas['short_cache_link']){
|
---|
781 | $feedhrefworkaround="";
|
---|
782 | if($resultparas['searchphrase'] == "" && $resultparas['archivdate'] == "") $feedhrefworkaround="ticker-";
|
---|
783 | $feedhref .= $feedhrefworkaround . 'feed/';
|
---|
784 | }else{
|
---|
785 | $feedhref .= '?feed';
|
---|
786 | }
|
---|
787 | }
|
---|
788 | }
|
---|
789 | } else {
|
---|
790 | //this is a feedrequest, so let us give out a link to ourself
|
---|
791 | //wrong idea - this could also be a feedlist?
|
---|
792 | $feedhref = $resultparas['baseurl'] . $resultparas['srequri'];
|
---|
793 | //to do: and calculate a nice html link for use in feed header
|
---|
794 | }
|
---|
795 | return $feedhref;
|
---|
796 | }
|
---|
797 |
|
---|
798 | function makehtmlhref(&$resultparas){
|
---|
799 | //used to calculate the href value to pba html page when displaying a feed
|
---|
800 | if($resultparas['searchphrase'] == "" && $resultparas['archivdate'] == ""){
|
---|
801 | $htmlhref = $resultparas['htmlpage'];
|
---|
802 | } else {
|
---|
803 | if($resultparas['short_cache_link']){
|
---|
804 | $htmlhref = $resultparas['htmlpage'] . preg_replace("/\/(ticker-)?feed\//s", '/',$resultparas['srequri']);
|
---|
805 | }else{
|
---|
806 | $htmlhref = $resultparas['htmlpage'] . preg_replace("/[&\?]feed/s", '', str_replace('?feed&' , '&feed?', $resultparas['srequri']));
|
---|
807 | }
|
---|
808 | }
|
---|
809 | return $htmlhref;
|
---|
810 | }
|
---|
811 |
|
---|
812 | function makelastpagehref($lastpage, &$resultparas){
|
---|
813 | //resultparas should not be changed, just overloaded by reference to gain speed in processing
|
---|
814 | if($lastpage == 1) {
|
---|
815 | if($resultparas['specialpage1url']
|
---|
816 | && $resultparas['specialpage1url'] != 'N'
|
---|
817 | && $resultparas['searchphrase']== ""
|
---|
818 | && $resultparas['archivdate']== ""
|
---|
819 | ){
|
---|
820 | $lastpagehref = $resultparas['specialpage1url'];
|
---|
821 | }else{
|
---|
822 | $lastpagehref= $resultparas['baseurl'] . preg_replace("/[&\?]?tickerpage[\/=][0-9]+\/?/s", '', $resultparas['srequri']);
|
---|
823 | }
|
---|
824 | } else {
|
---|
825 | if(strstr($resultparas['srequri'],"tickerpage/".$resultparas['tickerpage']."/")) {
|
---|
826 | $lastpagehref=$resultparas['baseurl'] . str_replace("tickerpage/".$resultparas['tickerpage']."/","tickerpage/".$lastpage."/",$resultparas['srequri']);
|
---|
827 | }else{
|
---|
828 | $lastpagehref=$resultparas['baseurl'] . str_replace("tickerpage=".$resultparas['tickerpage'],"tickerpage=".$lastpage,$resultparas['srequri']);
|
---|
829 | }
|
---|
830 | }
|
---|
831 | return $lastpagehref;
|
---|
832 | }
|
---|
833 |
|
---|
834 | function makenextpagehref($nextpage, &$resultparas){
|
---|
835 | //resultparas should not be changed, just overloaded by reference to gain speed in processing
|
---|
836 | if($nextpage == 2){
|
---|
837 | //add the page to the link
|
---|
838 | //we have to decide, if we add a short uri rewritten page link or a query style link, on start page, there s no way to determine this from URI, so we need to get it from some config value
|
---|
839 | if(strstr($resultparas['srequri'],'?')){
|
---|
840 | if($resultparas['short_cache_link']){
|
---|
841 | $slash ="/";
|
---|
842 | if(strstr($resultparas['srequri'],'/?')) $slash ="";
|
---|
843 | $nextpagehref= $resultparas['baseurl'] . str_replace('?', $slash . 'tickerpage/' . $nextpage . '?', $resultparas['srequri']);
|
---|
844 | } else {
|
---|
845 | $nextpagehref= $resultparas['baseurl'] . $resultparas['srequri'] . '&tickerpage=' . $nextpage;
|
---|
846 | }
|
---|
847 | }else{
|
---|
848 | //no ? in url
|
---|
849 | if($resultparas['short_cache_link']){
|
---|
850 | $slash ="";
|
---|
851 | if(substr($resultparas['baseurl'] . $resultparas['srequri'], strlen($resultparas['baseurl'] . $resultparas['srequri']) - 1) != '/') $slash ="/";
|
---|
852 | $nextpagehref= $resultparas['baseurl'] . $resultparas['srequri'] . $slash . 'tickerpage/' . $nextpage . '/';
|
---|
853 | } else {
|
---|
854 | $joiner='?';
|
---|
855 | if(strstr($resultparas['baseurl'], '?')) $joiner = '&';
|
---|
856 | $nextpagehref= $resultparas['baseurl'] . $resultparas['srequri'] . $joiner . 'tickerpage=' . $nextpage;
|
---|
857 | }
|
---|
858 | }
|
---|
859 | }else{
|
---|
860 | // nextpage > 2 - replace existing page identifier
|
---|
861 | //echo "srequri: " . $resultparas['srequri'] . "<br>";
|
---|
862 | if(strstr($resultparas['srequri'],'tickerpage=')){
|
---|
863 | $nextpagehref= $resultparas['baseurl'] . str_replace('tickerpage=' . $resultparas['tickerpage'], 'tickerpage=' . $nextpage, $resultparas['srequri']);
|
---|
864 | }else{
|
---|
865 | $nextpagehref= $resultparas['baseurl'] . str_replace('tickerpage/' . $resultparas['tickerpage'] . '/', 'tickerpage/' . $nextpage . '/', $resultparas['srequri']);
|
---|
866 | }
|
---|
867 | }
|
---|
868 | return $nextpagehref;
|
---|
869 | }
|
---|
870 |
|
---|
871 | function makedatepagehref($thedate="", &$resultparas, $regardkalenderlinkpart=false, $forcekalender=false){
|
---|
872 | //check input values
|
---|
873 | if ($thedate!="" && !ereg("[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]", $thedate)) $thedate = "";
|
---|
874 | if($thedate=="") $forcekalender = true;
|
---|
875 |
|
---|
876 | //depends on $resultparas['short_cache_link']
|
---|
877 | $kalender="";
|
---|
878 | $datepart="";
|
---|
879 | if($resultparas['short_cache_link']){
|
---|
880 | if($forcekalender || ($regardkalenderlinkpart && (substr($resultparas['srequri'], 0, 8) == "calendar" || substr($resultparas['srequri'], 0, 8) == "kalender"))) $kalender="calendar/";
|
---|
881 | if ($thedate!="") $datepart = $thedate . '/';
|
---|
882 | $datepagehref = $resultparas['baseurl'] . $kalender . $datepart;
|
---|
883 | } else {
|
---|
884 | if($forcekalender || ($regardkalenderlinkpart && preg_match('/[&\?][kc]alend[ae]r/',$resultparas['srequri']))) $kalender="calendar";
|
---|
885 | if ($thedate!="") {
|
---|
886 | $datepart = 'itemdate=' . $thedate;
|
---|
887 | if($kalender != "") $kalender = "&" . $kalender;
|
---|
888 | }
|
---|
889 | $joiner='?';
|
---|
890 | if(strstr($resultparas['baseurl'], '?')) $joiner = '&';
|
---|
891 | $datepagehref= $resultparas['baseurl'] . $joiner . $datepart . $kalender;
|
---|
892 | }
|
---|
893 | return $datepagehref;
|
---|
894 | }
|
---|
895 |
|
---|
896 | //functions to generate boxes with content
|
---|
897 | function formatted_feedlist(&$resultparas, $dateformat="", $template=false){
|
---|
898 | global $bdprss_db;
|
---|
899 |
|
---|
900 | //$liststyle shall be one of sidebar, feedlist, opml
|
---|
901 | $maxage=$resultparas['feedlistmaxage']; //to be done in parameter definition, 0 means filter disabled, age in seconds
|
---|
902 | $list_id=$resultparas['listid'];
|
---|
903 |
|
---|
904 | $split_template=PBALIB::split_template($template, '###INSIDELOOP###');
|
---|
905 |
|
---|
906 | if($resultparas['pba_feedlistquery_cache_time'] > 0) {
|
---|
907 | $key=array($maxage, $list_id);
|
---|
908 | $feedlistcache=@PBALIB::pba_cache($key, $dummy, 'get', 'feedlist', 'mixed', $resultparas['pba_feedlistquery_cache_time'], 'OK');
|
---|
909 | if($feedlistcache[1]) {
|
---|
910 | if($resultparas["profiler_enabled"]) $pbaout['profiler']['Got feedlist cache']=microtime();
|
---|
911 | $result = $feedlistcache[0];
|
---|
912 | }
|
---|
913 | }
|
---|
914 | if(!$feedlistcache[1]){
|
---|
915 | if($resultparas["profiler_enabled"]) $pbaout['profiler']['Start query for feedlist']=microtime();
|
---|
916 | $result = $bdprss_db->getsiteswithupdatetime($maxage, $list_id);
|
---|
917 | if($resultparas['pba_feedlistquery_cache_time'] > 0) {
|
---|
918 | $pba_cachereturn=PBALIB::pba_cache($feedlistcache[0], $result, 'write', 'feedlist', 'mixed', 0, 'OK');
|
---|
919 | }
|
---|
920 | }
|
---|
921 | foreach($result as $r) {
|
---|
922 | //$feedlist_loop['feedlist_loop_site_id'] = $r->{$bdprss_db->cidentifier};
|
---|
923 | $feedlist_loop['feedlist_loop_feedurl'] = $r->{$bdprss_db->cfeedurl};
|
---|
924 | $feedlist_loop['feedlist_loop_siteurl'] = $r->{$bdprss_db->csiteurl};
|
---|
925 | $feedlist_loop['feedlist_loop_site'] = $r->{$bdprss_db->csitename};
|
---|
926 | $updated = $r->lastupdate;
|
---|
927 | if(strlen($dateformat . "") >0){
|
---|
928 | $feedlist_loop['feedlist_loop_date']=date($dateformat, $updated);
|
---|
929 | }else{
|
---|
930 | $feedlist_loop['feedlist_loop_date']=PBALIB::gettheage($updated, $resultparas['ageunit'], $resultparas['ageunitsstring']);
|
---|
931 | }
|
---|
932 | //build up variables for the inner template - here is potential for optimization - resul from test: optimization potential minimal - not measurable
|
---|
933 | //we shall analyze the template above to find out, which variables we need in inner loop
|
---|
934 | foreach($feedlist_loop as $key => $value){
|
---|
935 | $needle[$key]="###" . strtoupper($key) . "###";
|
---|
936 | $replace[$key]=$value;
|
---|
937 | }
|
---|
938 | $feedlist['insideloop'] .=str_replace($needle, $replace, $split_template['inloop']);
|
---|
939 | }
|
---|
940 | //now the outer template
|
---|
941 |
|
---|
942 | $feedlist['result'] =str_replace('###INSIDELOOP###', $feedlist['insideloop'], $split_template['aroundloop']);
|
---|
943 | //print_r($feedlist);
|
---|
944 | return $feedlist;
|
---|
945 | }
|
---|
946 |
|
---|
947 | function formatkalender(&$resultparas, $thedate="", &$pbaout, $longtype="kalenderlist_box", $template=""){
|
---|
948 | global $bdprss_db;
|
---|
949 |
|
---|
950 | if($resultparas["profiler_enabled"]) { $type="list"; if($longtype == 'kalender_box') $type="box"; }
|
---|
951 | if($resultparas['pba_kalenderquery_cache_time'] > 0) {
|
---|
952 | $key=array(substr($resultparas['archivdate'],0,7),$resultparas['listid']);
|
---|
953 | $kalendercache=@PBALIB::pba_cache($key, $dummy, 'get', 'kalender', 'mixed', $resultparas['pba_kalenderquery_cache_time'], 'OK');
|
---|
954 | if($kalendercache[1]) {
|
---|
955 | if($resultparas["profiler_enabled"]) $pbaout['profiler']['Got '. $type .' kalender cache']=microtime();
|
---|
956 | $kalenderdates = $kalendercache[0];
|
---|
957 | }
|
---|
958 | }
|
---|
959 | if(!$kalendercache[1]){
|
---|
960 | if($resultparas["profiler_enabled"]) $pbaout['profiler']['Start query for ' . $type . ' kalenderdates']=microtime();
|
---|
961 | $kalenderdates=$bdprss_db->getmonthlyarchivedates($resultparas['archivdate'],$resultparas['listid']);
|
---|
962 | if($resultparas['pba_kalenderquery_cache_time'] > 0) {
|
---|
963 | $pba_cachereturn=PBALIB::pba_cache($kalendercache[0], $kalenderdates, 'write', 'kalender', 'mixed', 0, 'OK');
|
---|
964 | }
|
---|
965 | }
|
---|
966 |
|
---|
967 | if($resultparas["profiler_enabled"]) $pbaout['profiler']['Start to format ' . $type . ' kalender']=microtime();
|
---|
968 |
|
---|
969 | //check input values
|
---|
970 | if (!ereg("[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]", $thedate)) $thedate = date('Y-m-d');
|
---|
971 |
|
---|
972 | //parameter for all kalender types
|
---|
973 | $dateformatinnormallinktext=$resultparas['kalendernormaldateformat'];
|
---|
974 | $kalendermonthslist=$resultparas['kalendermonthslist'];
|
---|
975 |
|
---|
976 | //get template for basic calendar and loop through to find subtemplates for earlierlink and laterlink
|
---|
977 | if($longtype == 'kalenderlist_box'){
|
---|
978 | $lastlinktpl=PBALIB::split_template($template, '###KALENDER_LASTLINK###','EARLIERLINK');
|
---|
979 | $lastlinktemplate=$lastlinktpl['inloop'];
|
---|
980 | $nextlinktpl=PBALIB::split_template($lastlinktpl['aroundloop'], '###KALENDER_NEXTLINK###','LATERLINK');
|
---|
981 | $nextlinktemplate=$nextlinktpl['inloop'];
|
---|
982 | $split_template=PBALIB::split_template($nextlinktpl['aroundloop'], '###INSIDELOOP###');
|
---|
983 | }
|
---|
984 |
|
---|
985 | //calculate some values from paras
|
---|
986 | $thetimestamp=mktime(0, 0, 0, substr($thedate, 5, 2), substr($thedate, 8, 2), substr($thedate, 0, 4));
|
---|
987 | $kalendermonths=explode(",", preg_replace('/\s/','',$kalendermonthslist));
|
---|
988 | $formattedkalender['kalenderdate']=$kalendermonths[(substr($thedate, 5, 2) - 1)] . ' ' . substr($thedate, 0, 4);
|
---|
989 |
|
---|
990 | //value initialization
|
---|
991 | $formattedkalender['insideloop']="";
|
---|
992 |
|
---|
993 | //format the body, if not box, else, we need the routine to check later, if a value for a date exists
|
---|
994 | foreach($kalenderdates as $k) {
|
---|
995 | if($k->type == 'last') {
|
---|
996 | $formattedkalender['kalender_lastlink'] = "";
|
---|
997 | if ($k->item_date != '0') {
|
---|
998 | $lasthref=PBALIB::makedatepagehref($k->item_date, $resultparas, true);
|
---|
999 | if($longtype == 'kalenderlist_box') $formattedkalender['kalender_lastlink'] = str_replace('###KALENDER_LASTHREF###',$lasthref, $lastlinktemplate);
|
---|
1000 | }
|
---|
1001 | } elseif($k->type == 'next'){
|
---|
1002 | $formattedkalender['kalender_nextlink'] = "";
|
---|
1003 | if ($k->item_date != '0') {
|
---|
1004 | $nexthref=PBALIB::makedatepagehref($k->item_date, $resultparas, true);
|
---|
1005 | if($longtype == 'kalenderlist_box') $formattedkalender['kalender_nextlink'] = str_replace('###KALENDER_NEXTHREF###',$nexthref,$nextlinktemplate);
|
---|
1006 | }
|
---|
1007 | }elseif($k->type == 'normal') {
|
---|
1008 | $inkalenderloop[$k->item_date]['kalenderloop_href']=PBALIB::makedatepagehref($k->item_date, $resultparas);
|
---|
1009 | $kalenderloop_timestamp=mktime(0, 0, 0, substr($k->item_date, 5, 2), substr($k->item_date, 8, 2), substr($k->item_date, 0, 4));
|
---|
1010 | $inkalenderloop[$k->item_date]['kalenderloop_inlinkdate']=date($dateformatinnormallinktext,$kalenderloop_timestamp);
|
---|
1011 | if($longtype=="kalenderlist_box"){
|
---|
1012 | foreach($inkalenderloop[$k->item_date] as $key => $value){
|
---|
1013 | $needle[$key]="###" . strtoupper($key) . "###";
|
---|
1014 | $replace[$key]=$value;
|
---|
1015 | }
|
---|
1016 | $formattedkalender['insideloop'] .= str_replace($needle, $replace, $split_template['inloop']);
|
---|
1017 | }
|
---|
1018 | }
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | if($longtype=="kalenderlist_box"){
|
---|
1022 | foreach($formattedkalender as $key => $value){
|
---|
1023 | $needle[$key]="###" . strtoupper($key) . "###";
|
---|
1024 | $replace[$key]=$value;
|
---|
1025 | }
|
---|
1026 | if($resultparas["debug"]) $formattedkalender['debug'] .= "\n<br>Debug: we understand the template keywords: " . PBALIB::get_r($needle);
|
---|
1027 | $formattedkalender['kalenderlist_box']= str_replace($needle, $replace, $split_template['aroundloop']);
|
---|
1028 | $formattedkalender['result']=$formattedkalender['kalenderlist_box'];
|
---|
1029 | }
|
---|
1030 | if($longtype=="kalender_box"){
|
---|
1031 | //get templates and other parameters for box calendar
|
---|
1032 | $kalenderdaysofweeklist=$resultparas['kalenderboxdaysofweeklist'];
|
---|
1033 | $kalenderdaysofweek=explode(",", preg_replace('/\s/','',$kalenderdaysofweeklist));
|
---|
1034 | $kalendertablecaption=$resultparas['kalenderboxtablecaption'];
|
---|
1035 | $formattedkalender['kalender_last']=$resultparas['kalender_last'];
|
---|
1036 | $formattedkalender['kalender_next']=$resultparas['kalender_next'];
|
---|
1037 |
|
---|
1038 | //calculating some special values
|
---|
1039 | $firstsecondofthemonth=mktime(0, 0, 0, substr($thedate,5,2), 1, substr($thedate,0,4));
|
---|
1040 | $weekdayoffirstsecondofthemonth=date('N', $firstsecondofthemonth);
|
---|
1041 | $offsetdays=$weekdayoffirstsecondofthemonth-1;
|
---|
1042 | $firstsecondofnextmonth=mktime(0, 0, 0, ( substr($thedate,5,2) +1 ), 1, substr($thedate,0,4));
|
---|
1043 |
|
---|
1044 | $formattedkalender['kalender_box']="<table".$kalendertablecaption."><caption>" . $formattedkalender['kalenderdate'] . "</caption>\n";
|
---|
1045 | $formattedkalender['kalender_box'].=' <thead><tr>';
|
---|
1046 | foreach($kalenderdaysofweek as $dayofweeknumber => $dayofweek){
|
---|
1047 | $formattedkalender['kalender_box'].= '<th abbr="'.$dayofweek.'" scope="col" title="'.$dayofweek.'">'.substr($dayofweek,0,1).'</th>';
|
---|
1048 | }
|
---|
1049 | $formattedkalender['kalender_box'].= '</tr></thead>' . "\n";
|
---|
1050 | $formattedkalender['kalender_box'].=' <tfoot><tr>';
|
---|
1051 | if($lasthref) {
|
---|
1052 | $formattedkalender['kalender_box'].='<td abbr="'.$formattedkalender['kalender_last'].'" colspan="3" id="prev"><a href="'.$lasthref.'" title="'.$formattedkalender['kalender_last'].'">'.$formattedkalender['kalender_last'].'</a></td>';
|
---|
1053 | } else {
|
---|
1054 | $formattedkalender['kalender_box'].='<td colspan="3" id="prev"> </td>';
|
---|
1055 | }
|
---|
1056 | $formattedkalender['kalender_box'].='<td> </td>';
|
---|
1057 | if($nexthref) {
|
---|
1058 | $formattedkalender['kalender_box'].='<td abbr="'.$formattedkalender['kalender_next'].'" colspan="3" id="next"><a href="'.$nexthref.'" title="'.$formattedkalender['kalender_next'].'">'.$formattedkalender['kalender_next'].'</a></td>';
|
---|
1059 | } else {
|
---|
1060 | $formattedkalender['kalender_box'].='<td colspan="3" id="next"> </td>';
|
---|
1061 | }
|
---|
1062 | $formattedkalender['kalender_box'].='</tr></tfoot><tbody>' . "\n";
|
---|
1063 |
|
---|
1064 | //loop through the rows
|
---|
1065 | $startdate=date('Y-m-d',mktime(0, 0, 0, substr($thedate,5,2), (1 - $offsetdays), substr($thedate,0,4)));
|
---|
1066 | while(mktime(0, 0, 0, substr($startdate,5,2), substr($startdate,8,2), substr($startdate,0,4)) < $firstsecondofnextmonth){
|
---|
1067 | $formattedkalender['kalender_box'].='<tr>';
|
---|
1068 | foreach($kalenderdaysofweek as $dayofweeknumber => $dayofweek){
|
---|
1069 | $blank = "";
|
---|
1070 | $daynumber=(substr($startdate,8,2)+0);
|
---|
1071 | if($daynumber < 10) $blank = " ";
|
---|
1072 | if(isset($inkalenderloop[$startdate]['kalenderloop_href'])){
|
---|
1073 | //there exists a link due to db entry, so we want to link it
|
---|
1074 | $formattedkalender['kalender_box'].='<td>'.$blank.'<a title="'.$inkalenderloop[$startdate]['kalenderloop_inlinkdate'].'" href="'.$inkalenderloop[$startdate]['kalenderloop_href'].'">'. $daynumber . '</a></td>';
|
---|
1075 | }elseif(substr($startdate,0,7) == substr($thedate,0,7)){
|
---|
1076 | //startdate in current month
|
---|
1077 | $formattedkalender['kalender_box'].='<td>'. $blank . $daynumber . '</td>';
|
---|
1078 | }else{
|
---|
1079 | $formattedkalender['kalender_box'].='<td> </td>';
|
---|
1080 | }
|
---|
1081 | $startdate=date('Y-m-d',mktime(0, 0, 0, substr($startdate,5,2), (substr($startdate,8,2) + 1), substr($startdate,0,4)));
|
---|
1082 | }
|
---|
1083 | $formattedkalender['kalender_box'].='</tr>';
|
---|
1084 | }
|
---|
1085 | $formattedkalender['kalender_box'].='</tbody></table>';
|
---|
1086 | $formattedkalender['result']=str_replace('###KALENDERBOX###',$formattedkalender['kalender_box'], $template);
|
---|
1087 | }
|
---|
1088 |
|
---|
1089 | if($resultparas["profiler_enabled"]) $pbaout['profiler']['End of format ' . $type . ' kalender']=microtime();
|
---|
1090 | return $formattedkalender;
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | //helper functions
|
---|
1094 |
|
---|
1095 | function analysepagetype(&$resultparas){
|
---|
1096 | // we have pages with templates:
|
---|
1097 | // 1. tickerpage - a tickerpage is a basic output list page
|
---|
1098 |
|
---|
1099 | if($resultparas['archivdate'] == ""
|
---|
1100 | && $resultparas['searchphrase']== ""
|
---|
1101 | && $resultparas['feedrequest']==false
|
---|
1102 | && $resultparas['cacheid']==false
|
---|
1103 | && $resultparas['kalreq']==false
|
---|
1104 | && $resultparas['tickerpage']>1
|
---|
1105 | && !$resultparas['displayonlybox'] ) {
|
---|
1106 | $pagetype['pagetype']='tickerpage';
|
---|
1107 | $pagetype['template']='ticker';
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 | // 2. searchpage - almost same as tickerpage, but with search specifica
|
---|
1111 | if($resultparas['archivdate'] == ""
|
---|
1112 | && $resultparas['searchphrase']!= ""
|
---|
1113 | && $resultparas['feedrequest']==false
|
---|
1114 | && $resultparas['cacheid']==false
|
---|
1115 | && $resultparas['kalreq']==false
|
---|
1116 | && !$resultparas['displayonlybox']) {
|
---|
1117 | $pagetype['pagetype']='searchpage';
|
---|
1118 | $pagetype['template']='ticker';
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | // 3. datepage - almost same as tickerpage, but with datepage specifica
|
---|
1122 | if($resultparas['archivdate'] != ""
|
---|
1123 | && $resultparas['searchphrase']== ""
|
---|
1124 | && $resultparas['feedrequest']==false
|
---|
1125 | && $resultparas['cacheid']==false
|
---|
1126 | && $resultparas['kalreq']==false
|
---|
1127 | && !$resultparas['displayonlybox'] ) {
|
---|
1128 | $pagetype['pagetype']='datepage';
|
---|
1129 | $pagetype['template']='ticker';
|
---|
1130 | }
|
---|
1131 |
|
---|
1132 | // 8. startpage - almost a tickerpage, but headers can be suppressed and a special uri can be assigned
|
---|
1133 | if($resultparas['archivdate'] == ""
|
---|
1134 | && $resultparas['searchphrase']== ""
|
---|
1135 | && $resultparas['feedrequest']==false
|
---|
1136 | && $resultparas['cacheid']==false
|
---|
1137 | && $resultparas['kalreq']==false
|
---|
1138 | && $resultparas['tickerpage']==1
|
---|
1139 | && !$resultparas['displayonlybox'] ) {
|
---|
1140 | $pagetype['pagetype']='startpage';
|
---|
1141 | $pagetype['template']='ticker';
|
---|
1142 | }
|
---|
1143 | // these pagetypes above may use the same template with a preprocessor doing some modifications?
|
---|
1144 |
|
---|
1145 | // 5. feedpage - a ticker- no search- no date - page with diffrent output preprocessing and diffrent template
|
---|
1146 | if($resultparas['archivdate'] == ""
|
---|
1147 | && $resultparas['searchphrase']== ""
|
---|
1148 | && $resultparas['feedrequest']==true
|
---|
1149 | && $resultparas['cacheid']==false
|
---|
1150 | && $resultparas['kalreq']==false
|
---|
1151 | && !$resultparas['displayonlybox'] ) {
|
---|
1152 | $pagetype['pagetype']='feedpage';
|
---|
1153 | $pagetype['template']='feed';
|
---|
1154 | }
|
---|
1155 |
|
---|
1156 | // 5a. search feedpage - a feed ticker- with search - page
|
---|
1157 | if($resultparas['archivdate'] == ""
|
---|
1158 | && $resultparas['searchphrase']!= ""
|
---|
1159 | && $resultparas['feedrequest']==true
|
---|
1160 | && $resultparas['cacheid']==false
|
---|
1161 | && $resultparas['kalreq']==false
|
---|
1162 | && !$resultparas['displayonlybox'] ) {
|
---|
1163 | $pagetype['pagetype']='feedsearchpage';
|
---|
1164 | $pagetype['template']='feed';
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | // 5b. date feedpage - a feed ticker- with date - page
|
---|
1168 | if($resultparas['archivdate'] != ""
|
---|
1169 | && $resultparas['searchphrase']== ""
|
---|
1170 | && $resultparas['feedrequest']==true
|
---|
1171 | && $resultparas['cacheid']==false
|
---|
1172 | && $resultparas['kalreq']==false
|
---|
1173 | && !$resultparas['displayonlybox'] ) {
|
---|
1174 | $pagetype['pagetype']='feeddatepage';
|
---|
1175 | $pagetype['template']='feed';
|
---|
1176 | }
|
---|
1177 |
|
---|
1178 | // 7. cache page - a tickerpage with diffrent template and just one item requested
|
---|
1179 | //these pages also use the main loop via search engine
|
---|
1180 | //information which page was requested is in url, but limited by other config parameters
|
---|
1181 | if($resultparas['archivdate'] == ""
|
---|
1182 | && $resultparas['searchphrase']== ""
|
---|
1183 | && $resultparas['feedrequest']==false //maybe have a cache page delivered as feed?
|
---|
1184 | && $resultparas['cacheid']> 0
|
---|
1185 | && $resultparas["iscachable"]=="Y"
|
---|
1186 | && $resultparas['kalreq']==false
|
---|
1187 | && !$resultparas['displayonlybox'] ) {
|
---|
1188 | $pagetype['pagetype']='cachepage';
|
---|
1189 | $pagetype['template']='cache';
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | // 4. kalenderpage - a special page with no content but showing all our navigation and boxes
|
---|
1193 | if( $resultparas['searchphrase']== ""
|
---|
1194 | && $resultparas['feedrequest']==false
|
---|
1195 | && $resultparas['cacheid']==false
|
---|
1196 | && $resultparas['kalreq']==true
|
---|
1197 | && !$resultparas['displayonlybox']) {
|
---|
1198 | $pagetype['pagetype']='kalpage';
|
---|
1199 | $pagetype['template']='kalender';
|
---|
1200 | }
|
---|
1201 |
|
---|
1202 | // 9. nopage - maybe just a box was called? - great we could save a lot of time, when we know, that we don't need to process a page template
|
---|
1203 | if($resultparas['feedrequest']==false
|
---|
1204 | && $resultparas['displayonlybox'] // just a box
|
---|
1205 | ) {
|
---|
1206 | $pagetype['pagetype']='nopage';
|
---|
1207 | $pagetype['template']= $resultparas['displayonlybox'];
|
---|
1208 | // one of 'kalender_box', 'kalenderlist_box', 'search_box', 'feedlistsidebar_box', 'opml_box', 'feedlist_box', 'feedlistsidebar_box'
|
---|
1209 | }
|
---|
1210 |
|
---|
1211 | //10. errorpage - probably nobody wants this page, but maybe our system is not ready or it is not understandable what the user wanted
|
---|
1212 | if(!isset($pagetype['pagetype']) || !isset($pagetype['template'])
|
---|
1213 | ) {
|
---|
1214 | $pagetype['pagetype']='errorpage';
|
---|
1215 | $pagetype['template']='error';
|
---|
1216 | $pagetype['error'].='This error never should happen. Sorry for this. Cannot determine page type or template';
|
---|
1217 | }
|
---|
1218 | return $pagetype;
|
---|
1219 | }
|
---|
1220 |
|
---|
1221 | function analyze_needed_elements($rawtemplate, $type=''){
|
---|
1222 | //avaliable_boxes: 'search_box, kalender_box, kalenderlist_box, feedlist_box, sendfeedpermail_box'; //do we really need this?
|
---|
1223 | preg_match_all('/###[0-9A-Z_]+'.$type.'###/', $rawtemplate, $elementname);
|
---|
1224 | //$element['boxname']=$elementname;
|
---|
1225 | foreach($elementname[0] as $key => $elementnameupper){
|
---|
1226 | $element['result'][str_replace('#','',strtolower($elementnameupper))]=true;
|
---|
1227 | }
|
---|
1228 | if(!isset($element['result'])) $element['result'] = false;
|
---|
1229 | return $element;
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | function makebox($boxtomake, &$resultparas, &$pbaout){
|
---|
1233 | $boxtemplate = $resultparas['template_' . $boxtomake]; //Fix this later to be a copy of resultparas
|
---|
1234 | $preprocessed_boxtemplate=PBALIB::template_replacements($boxtemplate, $resultparas);
|
---|
1235 |
|
---|
1236 | if($boxtomake == 'kalender_box' || $boxtomake == 'kalenderlist_box'){
|
---|
1237 | //this one is tricky:
|
---|
1238 | //1. to query db only once, if we have diffrent kalenderboxes to make, we want them all make at once
|
---|
1239 | //2. we want to give some (?) other global results back like kalenderdate
|
---|
1240 | //formatted_kalender gives out:
|
---|
1241 | //1. result - as specified with boxtomake
|
---|
1242 | //2. kalenderdate - needed later in page templates,
|
---|
1243 | //3. maybe profiler, when profiler enabled set -> now directly sent to pbaout
|
---|
1244 |
|
---|
1245 | //we shall better work with db query results cache ? - nice to see in profiler: mysql does caching automatically very well
|
---|
1246 | $formatted_kalender=PBALIB::formatkalender($resultparas, $resultparas['archivdate'], $pbaout, $boxtomake, $preprocessed_boxtemplate);
|
---|
1247 | $box['result']=$formatted_kalender['result']; //completely unused so far?
|
---|
1248 | $pbaout['kalenderdate']=$formatted_kalender['kalenderdate'];
|
---|
1249 |
|
---|
1250 | }elseif($boxtomake == 'opml_box' || $boxtomake == 'feedlist_box' || $boxtomake == 'feedlistsidebar_box'){
|
---|
1251 |
|
---|
1252 | //we need to pass over dateformat for inside the loop
|
---|
1253 | $dateformat="";
|
---|
1254 | if (isset($resultparas['dateformat_' . $boxtomake])) $dateformat=$resultparas['dateformat_' . $boxtomake];
|
---|
1255 | $feedlist = PBALIB::formatted_feedlist($resultparas, $dateformat, $preprocessed_boxtemplate);
|
---|
1256 | $box['result']=$feedlist['result'];
|
---|
1257 | }else{
|
---|
1258 | //doing nothing special here is perfect for making a search box
|
---|
1259 | $box['result']=$preprocessed_boxtemplate; //this
|
---|
1260 | }
|
---|
1261 |
|
---|
1262 | return $box;
|
---|
1263 | }
|
---|
1264 |
|
---|
1265 | function processtagset($tagsetfromdb){
|
---|
1266 | //$bdprssTagSet: tags to possibly keep defined in programm code
|
---|
1267 | //$tagsetfromdb - the tags defined as allowed as defined per output id
|
---|
1268 | //$formattedtagset: the resulting tagset applied to the items in packageItemText
|
---|
1269 | //to do: encapsulate this into function and store it in database!!!
|
---|
1270 | global $bdprssTagSet;
|
---|
1271 | $formattedtagset = '';
|
---|
1272 | if($tagsetfromdb){
|
---|
1273 | $kts = preg_split("','", $tagsetfromdb, -1, PREG_SPLIT_NO_EMPTY);
|
---|
1274 | foreach($kts as $t){
|
---|
1275 | $u = $bdprssTagSet[$t];
|
---|
1276 | foreach($u as $v)
|
---|
1277 | $formattedtagset .= "$v,";
|
---|
1278 | }
|
---|
1279 | }
|
---|
1280 | return $formattedtagset;
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | function gettheage($seconds, &$resultparas=false, &$ageunitsstring=false){
|
---|
1284 |
|
---|
1285 | //this function is used inside inner loops and has to be quick
|
---|
1286 | //we set $resultparas['ageunit'] on first call with just a string and no array,
|
---|
1287 | //so in following calls we won't have to loop
|
---|
1288 |
|
---|
1289 | if(is_array($resultparas['ageunit'])){
|
---|
1290 | $ageunit=$resultparas['ageunit'];
|
---|
1291 | }else{
|
---|
1292 | if(!$ageunitsstring) $ageunitsstring = get_pbadefaultparameter('ageunitsstring');
|
---|
1293 | $ageunitsarray = explode(",", $ageunitsstring);
|
---|
1294 | foreach($ageunitsarray as $valuepair){
|
---|
1295 | $valuepairarray=explode(":", $valuepair);
|
---|
1296 | $ageunit[trim($valuepairarray[0])]= trim($valuepairarray[1]);
|
---|
1297 | }
|
---|
1298 | $resultparas['ageunit']=$ageunit;
|
---|
1299 | }
|
---|
1300 | if($seconds < 100000) return $ageunit['never']; // usually true :)
|
---|
1301 |
|
---|
1302 | $age = (time() - $seconds);
|
---|
1303 | if($age < 0) {
|
---|
1304 | $future = TRUE;
|
---|
1305 | $age = -$age;
|
---|
1306 | }
|
---|
1307 |
|
---|
1308 | $unit = $ageunit['seconds'];
|
---|
1309 | if($age>120.0) {
|
---|
1310 | $age /= 60;
|
---|
1311 | $unit = $ageunit['minutes'];
|
---|
1312 | }
|
---|
1313 |
|
---|
1314 | if($age>120.0 && $unit==$ageunit['minutes']){
|
---|
1315 | $age /= 60;
|
---|
1316 | $unit = $ageunit['hours'];
|
---|
1317 | }
|
---|
1318 |
|
---|
1319 | if($age>48.0 && $unit == $ageunit['hours']){
|
---|
1320 | $age /= 24;
|
---|
1321 | $unit = $ageunit['days'];
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | if($age>21.0 && $unit==$ageunit['days']){
|
---|
1325 | $age /= 7;
|
---|
1326 | $unit = $ageunit['weeks'];
|
---|
1327 | }
|
---|
1328 |
|
---|
1329 | if($age>13.0 && $unit==$ageunit['weeks'])
|
---|
1330 | {
|
---|
1331 | $age /= 4.34821;
|
---|
1332 | $unit = $ageunit['months'];
|
---|
1333 | }
|
---|
1334 |
|
---|
1335 | if($age>=24.0 && $unit==$ageunit['months']){
|
---|
1336 | $age /= 12;
|
---|
1337 | $unit = $ageunit['years'];
|
---|
1338 | }
|
---|
1339 |
|
---|
1340 | $age = round($age, 0);
|
---|
1341 | if(!isset($future)) {
|
---|
1342 | if($ageunit['before'] != "") $ageunit['before'] = $ageunit['before'] . " ";
|
---|
1343 | if($ageunit['beforeafter'] != "") $ageunit['beforeafter'] = " " . $ageunit['beforeafter'];
|
---|
1344 | $return = $ageunit['before'] . "$age $unit" . $ageunit['beforeafter'];
|
---|
1345 | } else {
|
---|
1346 | $return = $ageunit['in'] . " $age $unit";
|
---|
1347 | }
|
---|
1348 | return $return;
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 | //pba_cache($identifier, $content, 'write', $name, 'mixed', 0, 'OK');
|
---|
1352 | //pba_cache($identifier, $content, 'housekeeping', $name, 'mixed', 500, 'OK');
|
---|
1353 | //pba_cache($identifier, $content, 'clear', $name, 'mixed', 180, 'OK');
|
---|
1354 | //$cachereturn=pba_cache($identifier, $dummy, 'get', $name, 'mixed', 1800, 'OK');
|
---|
1355 | //if($cachereturn[1]) echo "Here is what I got: " . print_r($cachereturn);
|
---|
1356 | //if($cachereturn[0]) echo "Got no cache";
|
---|
1357 |
|
---|
1358 | function pba_cache(&$identifier, &$cache_content, $cache_mode='get', $name='c', $type='mixed', $cache_max_time=180, $serverstatus='OK'){
|
---|
1359 | $cache_file=false;
|
---|
1360 | $cache_path=PBA_CACHE_PATH;
|
---|
1361 |
|
---|
1362 | //if identifier is just a short string containing nothing else then a-zA-Z0-9_-, we will use it as part of filename instead of md5
|
---|
1363 | if(is_string($identifier)) {
|
---|
1364 | if(strlen($identifier)<=40){
|
---|
1365 | if(preg_match('/^[a-zA-Z0-9_-]+$/',$identifier)){
|
---|
1366 | $cache_file=$cache_path . $name . '_' . $identifier;
|
---|
1367 | }
|
---|
1368 | }
|
---|
1369 | }
|
---|
1370 | if(!$cache_file){
|
---|
1371 | $cache_file=$cache_path . $name . '_' . md5(serialize($identifier));
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | //to the filenames on disk will be appended:
|
---|
1375 | //__c for check files, __d for data files, __t for tmp files
|
---|
1376 |
|
---|
1377 | if($cache_mode=='write'){
|
---|
1378 | $wrote_cache=false;
|
---|
1379 | if ($serverstatus == 'OK' && !file_exists($cache_file."__t") && !(@filemtime($cache_file."__d") + $cache_max_time > time())){
|
---|
1380 | $cache_file_handle = fopen($cache_file."__t", 'w+');
|
---|
1381 |
|
---|
1382 | if($type=='string') {
|
---|
1383 | if(fwrite($cache_file_handle, $cache_content)) $wrote_cache=true;
|
---|
1384 | } else {
|
---|
1385 | if(fwrite($cache_file_handle, serialize($cache_content))) $wrote_cache=true;
|
---|
1386 | }
|
---|
1387 | fclose($cache_file_handle);
|
---|
1388 | rename($cache_file."__t",$cache_file."__d");
|
---|
1389 | @touch($cache_file."__c");
|
---|
1390 | }
|
---|
1391 | return $wrote_cache;
|
---|
1392 | }
|
---|
1393 | if($cache_mode=='get'){
|
---|
1394 | $got_cache=false;
|
---|
1395 | if (file_exists($cache_file."__c")){
|
---|
1396 | if( @filemtime($cache_file."__d") + $cache_max_time > time() && $serverstatus == 'OK' ) {
|
---|
1397 | if($type=='string') {
|
---|
1398 | if($get_cache=file_get_contents($cache_file."__d")) $got_cache=true;
|
---|
1399 | } else {
|
---|
1400 | if($get_cache=unserialize(file_get_contents($cache_file."__d"))) {
|
---|
1401 | $got_cache=true;
|
---|
1402 | }
|
---|
1403 | }
|
---|
1404 | }
|
---|
1405 | }
|
---|
1406 | if(!$got_cache) $get_cache = $identifier;
|
---|
1407 | return array($get_cache,$got_cache);
|
---|
1408 | }
|
---|
1409 |
|
---|
1410 | if($cache_mode=='housekeeping'){
|
---|
1411 | $counter=0;
|
---|
1412 | if($serverstatus == 'OK'){
|
---|
1413 | foreach (glob($cache_path . "*__?") as $filename) {
|
---|
1414 | if(preg_match('/__[cd]$/',$filename)){
|
---|
1415 | if(filemtime($filename) + $cache_max_time < time()) {
|
---|
1416 | unlink($filename);
|
---|
1417 | $counter++;
|
---|
1418 | }
|
---|
1419 | }
|
---|
1420 | }
|
---|
1421 | }
|
---|
1422 | return $counter;
|
---|
1423 | }
|
---|
1424 |
|
---|
1425 | if($cache_mode=='clear'){
|
---|
1426 | $counter=0;
|
---|
1427 | foreach (glob($cache_path . "*__?") as $filename) {
|
---|
1428 | unlink($filename);
|
---|
1429 | $counter++;
|
---|
1430 | }
|
---|
1431 | return $counter;
|
---|
1432 | }
|
---|
1433 | }
|
---|
1434 |
|
---|
1435 |
|
---|
1436 | }// end class PBALIB
|
---|
1437 | ?>
|
---|