source: trunk/www.guidonia.net/wp/wp-content/plugins/parteibuch-aggregator/bdp-rss-aggregator.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 27.8 KB
Line 
1<?php
2
3/*
4Plugin Name: Parteibuch RSS Aggregator
5Plugin URI: http://www.mein-parteibuch.com/blog/parteibuch-aggregator/
6Description: A template based RSS Aggregator with search capability. After first activation <a href="edit.php?page=parteibuch-aggregator/bdp-rssadmin.php&action=editpbaoutput&pboutput=1&pbstart=1">start configuration here</a>
7Version: 0.5.2
8Author: Mein Parteibuch
9Author URI: http://www.mein-parteibuch.com/
10
11The Parteibuch Aggregator is
12based on Bryan Palmers (bryan@ozpolitics.info)
13http://www.ozpolitics.info/blog/?p=87
14BDP RSS Aggregator.
15
16Thank Bryan for the great work, but please don't bother
17him with support requests for the Parteibuch Aggregator.
18
19Bookmarks come from social bookmarks plugin.
20
21Note: tabs set to two spaces
22*/
23
24/* Copyright 2009 Mein Parteibuch (email : katzen_no_xxx_spam_freund@mein-parteibuch.com)
25
26 This program is free software; you can redistribute it and/or modify
27 it under the terms of the GNU General Public License as published by
28 the Free Software Foundation; either version 2 of the License, or
29 (at your option) any later version.
30
31 This program is distributed in the hope that it will be useful,
32 but WITHOUT ANY WARRANTY; without even the implied warranty of
33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 GNU General Public License for more details.
35
36 You should have received a copy of the GNU General Public License
37 along with this program; if not, write to the Free Software
38 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
39*/
40
41/* ----- constants ----- */
42define ('PBA_PRODUCT', 'Parteibuch Aggregator'); // Doh!
43define ('PBA_VERSION', '0.5.2'); // CHECK: should be the same as above!
44define ('PBA_DIRECTORY', 'parteibuch-aggregator'); // base in plugins directory
45
46define ('PBA_CACHE_PATH',dirname(__FILE__)."/pbacache/"); // the directory to be used as disk cache
47define ('BDPRSS2_DEBUG', FALSE);
48
49/* ----- initialisation ----- */
50
51if ( !(phpversion() >= '5.0') )
52 die( 'Your server is running PHP version ' . phpversion() .
53 ' but the Parteibuch Aggregator Wordpress plugin requires at least 5.0' );
54
55if( !function_exists('mb_internal_encoding') || !function_exists('mb_regex_encoding') )
56 die( 'Your installation of PHP does not appear to support multibyte strings. '.
57 'This support is needed by the Parteibuch Aggregator plugin. '.
58 'You should ask your web-hoster to install it; it is easy to install. '.
59 'For more information, refer to <a href="http://www.phpbuilder.com/manual/ref.mbstring.php">'.
60 'http://www.phpbuilder.com/manual/ref.mbstring.php</a>.');
61
62//$timeshift=get_option('gmt_offset');
63//echo $timeshift;
64
65/* ----- includes ----- */
66if( !class_exists('Snoopy') ) require_once(ABSPATH."wp-includes/class-snoopy.php");
67if(defined('WPLANG') && file_exists(dirname(__FILE__) . '/pba-defaultparameter_'. substr(WPLANG,0,2) .'.php')){
68 include_once(dirname(__FILE__) . '/pba-defaultparameter_'. substr(WPLANG,0,2) .'.php');
69}else{
70 include_once(dirname(__FILE__) . '/pba-defaultparameter.php');
71}
72
73require_once(dirname(__FILE__) . '/bdp-rssaggregator-db.php');
74require_once(dirname(__FILE__) . '/bdp-rssfeed.php');
75
76/* ----- main game ----- */
77if( !class_exists('BDPRSS2') ) // for protection only
78{
79 /* ----- globals ----- */
80
81 // this seems to be the first reliable header, let us test, when it is called, just testing, it seems to be loaded before headers are sent
82 //add_action('plugins_loaded', array('BDPRSS2', 'testingheaders'));
83
84 // this seems to be the first reliable header, let us test, when it is called, just testing, it seems usually to be loaded before headers are sent
85 //add_action('init', array('BDPRSS2', 'testingheaders'));
86
87 add_action('template_redirect', array('BDPRSS2', 'pba_catch_template_redirect'));
88 add_action('wp_head', array('BDPRSS2', 'tag')); // advertising
89 add_action('admin_menu', array('BDPRSS2', 'adminMenu')); // link in the relevant admin menus
90 add_action('shutdown', array('BDPRSS2', 'pba_shutdown')); // routine updating
91 add_filter('the_content', array('BDPRSS2', 'replace_page_content'));
92 add_filter('rewrite_rules_array', array('BDPRSS2', 'pba_rewrite'));
93 if(function_exists('register_deactivation_hook')) register_deactivation_hook( __FILE__, 'pba_uninstaller' );
94
95 function pba_uninstaller(){
96 global $bdprss_db;
97 if($bdprss_db->pbaoption('delete_alldata') == 'Y'){
98 //echo 'Parteibuch Aggregator: "Delete all data" option set';
99 $bdprss_db->reset();
100 }else{
101 true;
102 //nothing to do, we are before sending headers, so we can't send a message to the user
103 //echo 'Parteibuch Aggregator: "Delete all data" option not set, keeping data for reactivation of the aggregator plugin.';
104 }
105 }
106
107 //like to have some widgets? here you have:
108 include_once(dirname(__FILE__) . '/pba-widgets.php');
109
110 $bdprssTagSet = array(
111 'Links' => array('a'),
112 'Images' => array('img'),
113 'Paragraphs' => array('p'),
114 'Line breaks' => array('br'),
115 'Italics' => array('em', 'i'),
116 'Underlining' => array('u'),
117 'Bolding' => array('b', 'strong'),
118 'Spans' => array('span'),
119 'Text formating'=> array('abbr', 'cite', 'code', 'dfn', 'kbd', 'object', 'pre',
120 'quote', 'ruby', 'samp', 'strike', 'style', 'sub', 'sup', 'var' ),
121 'Tables' => array('table', 'tr', 'th', 'td', 'thead', 'tbody', 'tfoot'),
122 'Lists' => array('ol', 'ul', 'dl', 'nl', 'li', 'di', 'dd', 'dt', 'label'),
123 'Headings' => array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'),
124 'Block quotes' => array('blockquote'),
125 'Divisions' => array('div'),
126 'Separators' => array('separator', 'hr')
127 );
128
129 $bdprssdate = "bdprssarchivedate";
130 $bdprssCacheItem = "bdprsscacheitem";
131 $bdprssList = "bdprsslist";
132
133 //globals
134
135 $remember_pbapage=false;
136
137 class BDPRSS2
138 {
139 /* --- hooks --- */
140
141//some functions triggered by the hooks
142
143
144 function pba_rewrite(&$rules){
145
146 global $bdprss_db;
147 $pbadefault=$bdprss_db->pbaoption('enable_rewriting'); // can we access this already when generating rewrite rules?
148 $doit=false;
149 if(isset($pbadefault)) {
150 if($pbadefault == 'Y' && count($rules) > 5) $doit = true;
151 }
152 //hook and function is only fired, when rewrite rules are recreated
153 //Now the funny part
154 $pba_rules = array(
155 //tickersucheregex
156 '(.+?)?/s/[^/]+(/tickerpage/[0-9]+)?(/feed)?/?$' => 'index.php?&pagename=$matches[1]',
157 //kalenderregex
158 '([^/]+?)/([kc]alend[ae]r|opml|feedlist|ticker-feed|tickerpage)(/[0-9/-]+)?/?$' => 'index.php?&pagename=$matches[1]',
159 //dateregex
160 '(.+?)?/?[0-9]{4}-[0-9]{2}-[0-9]{2}(/tickerpage/[0-9]{1,}|/feed|/ticker-feed)?/?$' => 'index.php?&pagename=$matches[1]',
161 //cacheregex
162 '([^/page0-9]+?)/([0-9]+)/?$' => 'index.php?&pagename=$matches[1]'
163 );
164
165 //echo "Debug: myrules: " . print_r($pba_rules);
166 if($doit) $rules = array_merge($pba_rules, $rules);
167
168 //tricky stuff: the following line will make the rewrite entry in mstatustable be recreated at next page call
169 //if we would just recreate the memtablestatus rewriting row now, then the rules change would
170 //not be detected, because wordpress is not finished processing the rule
171
172 $bdprss_db->mark_entry_as_old_in_statustable('rewriting');
173
174 return $rules;
175 }
176
177//see here, MSIE is buggy http://us3.php.net/manual/en/function.ob-gzhandler.php#84493
178 function isBuggyIe() {
179 $ua = $_SERVER['HTTP_USER_AGENT'];
180 // quick escape for non-IEs
181 if (0 !== strpos($ua, 'Mozilla/4.0 (compatible; MSIE ')
182 || false !== strpos($ua, 'Opera')) {
183 return false;
184 }
185 // no regex = faaast
186 $version = (float)substr($ua, 30);
187 return ( $version <= 8 );
188 }
189
190 function pba_catch_template_redirect(){
191 //here some lines to debug rewrite rules
192 //global $post;
193 //echo "<br><b>We passed pba_catch_template_redirect, post is: " . PBALIB::get_r($post) . "</b>";
194 //echo "The rules are: " . str_replace("\n",'<br>',PBALIB::get_r(get_option('rewrite_rules')));
195
196 if(is_page()){
197
198 global $remember_pbapage;
199 $pba_page_config['getoutputconfigbypageid']=true;
200 $pba_page=@PBA::outputwrapper($pba_page_config);
201
202 if(isset($pba_page['shutdown']) && $pba_page['shutdown'] === true) {
203 BDPRSS2::isBuggyIe() || ob_start("ob_gzhandler");
204 echo $pba_page['result']; //xml output goes here
205 do_action('shutdown');
206 wp_cache_close();
207 exit;
208 } elseif(isset($pba_page['redirect']) && $pba_page['redirect'] === true){
209 //do redirect
210 header("Location: " . $pba_page['result']);
211 exit;
212 } else {
213 if($pba_page['result'] !== false){
214 $remember_pbapage=$pba_page;
215 }
216 }
217 }
218 }
219
220 function tag()
221 {
222 /* tag()
223 * -- called early on to place a comment tag in the page
224 * -- I use the tag when people ask for help debugging why the plugin doesn't work for them.
225 */
226 global $bdprss_db;
227// echo "\n\t<!-- ".PBA_PRODUCT." " .PBA_VERSION. " -->\n";
228//parteibuch deactiveated due to security concerns if( $bdprss_db->get_mysql_version() < '4.0' )
229//parteibuch deactiveated due to security concerns echo "\t<!-- Warning: Your version of MySQL (" . $bdprss_db->get_mysql_version() .
230//parteibuch deactiveated due to security concerns ") appears old. You should update it. -->\n";
231 }
232
233 function adminMenu()
234 {
235 /* adminMenu() -- called when the administration pages are being displayed
236 * -- this function hooks the RSS Feeds page into the admin menus
237 */
238 if (function_exists('add_management_page'))
239 add_management_page('Parteibuch RSS Aggregator', 'RSS Aggregator', 9,
240 dirname(__FILE__).'/bdp-rssadmin.php');
241 }
242
243 function pba_shutdown()
244 {
245 // pba_shutdown() -- called at shutdown - processed the jobs
246 //print_r(getrusage());
247
248 global $bdprss_db;
249
250//print_r($bdprss_db->serverstatus);
251
252 ignore_user_abort(true);
253 wp_cache_close();
254 flush();
255 if(!ini_get('safe_mode')) set_time_limit(0);
256// sleep(15); //just for simulating time intensive operations
257
258 if(isset($bdprss_db->serverstatus['job2start']['name'])&& isset($bdprss_db->serverstatus['job2start']['time'])){
259 //we will not touch any jobs announced more than 8 seconds ago, the job manager could be already trying to reassign them
260 if(time() - $bdprss_db->serverstatus['job2start']['time'] < 8) $pba_job=$bdprss_db->serverstatus['job2start']['name'];
261 }
262 if(isset($pba_job)
263 && !$bdprss_db->highserverload
264 && $bdprss_db->memtablesok
265 && method_exists($bdprss_db, $pba_job)
266 ){
267 $bdprss_db->jobaction($pba_job, "start");
268 $return=$bdprss_db->$pba_job();
269 }
270 if(isset($pba_job)){
271 //echo "killing the job ... ";
272 $bdprss_db->jobaction($pba_job, "kill");
273 //echo "... done";
274 }
275 }
276
277 //see an example of wp hooks here: http://www.devlounge.net/articles/wordpress-plugin-filters
278 function replace_page_content($content = ''){
279 global $remember_pbapage;
280 if($remember_pbapage !== false){
281 $content .= $remember_pbapage['result'];
282 }
283 return $content;
284 }
285
286 /* ----- utilities ----- */
287 function tagalise($key)
288 {
289 return 'bdprss_xhtml_' . preg_replace("'[\s]*'", '', strtolower($key));
290 }
291
292
293 /* --- core input functions --- */
294
295 function update(&$row)
296 {
297 /* update(&$row)
298 * -- does the grunt work of updating a feed,
299 * -- specified by a row from the site-table
300 */
301 global $bdprss_db;
302
303 //$bdprss_db->recordError('Debug', 'Im here 1 at update');
304
305 // Check we have a row from the site-table
306 if(!isset($row) || !$row || !$row->{$bdprss_db->cidentifier} || !$row->{$bdprss_db->cfeedurl})
307 {
308 $bdprss_db->recordError('Snark',
309 "Snark: update() called without a row from the siteTable (this should never happen)");
310 return;
311 }
312 $now = time();
313 $cidentifier = $row->{$bdprss_db->cidentifier};
314 $url = $row->{$bdprss_db->cfeedurl};
315 $lastupdated = (int) $row->{$bdprss_db->cupdatetime};
316
317 // set the next poll time
318 $siteArray = array();
319 $siteArray['cidentifier'] = $cidentifier;
320 $siteArray['clastpolltime'] = $now;
321 if($row->{$bdprss_db->cpollingfreqmins})
322 $siteArray['cnextpolltime'] = $now + (60 * (int) $row->{$bdprss_db->cpollingfreqmins});
323 else
324 $siteArray['cnextpolltime'] = $now + (60 * (int) get_option('bdprss_update_frequency'));
325 $bdprss_db->updateTable($bdprss_db->sitetable, $siteArray, 'cidentifier');
326
327//mem table update
328 $bdprss_db->updateTable($bdprss_db->msitetable, $siteArray, 'cidentifier');
329
330 // Clear errorBase
331 $bdprss_db->deleteErrors($url);
332
333 // Get the feed
334 $feed = new BDPFeed($url);
335 $pfeed = $feed->parse();
336 if(!$pfeed)
337 {
338 $bdprss_db->recordError($url, "Failed to parse $url");
339 return;
340 }
341
342 // extract and save key site information
343 if(isset($pfeed['title'])) { $siteArray['csitename'] = mb_substr($pfeed['title'], 0, 250); } else { $siteArray['csitename'] = ""; };
344 $siteArray['csiteurl'] = mb_substr($pfeed['link'], 0, 250);
345 if(isset($pfeed['copyright'])) $siteArray['csitelicense'] = mb_substr($pfeed['copyright'], 0, 250);
346 if(isset($pfeed['description'])) {
347 $siteArray['cdescription'] = mb_substr($pfeed['description'], 0, 250);
348 }elseif(isset($pfeed['tagline'])){
349 $siteArray['cdescription'] = mb_substr($pfeed['tagline'], 0, 250);
350 }else{
351 $siteArray['cdescription'] = "";
352 }
353 $siteArray['cupdatetime'] = $now;
354 $bdprss_db->updateTable($bdprss_db->sitetable, $siteArray, 'cidentifier',
355 $row->{$bdprss_db->csitenameoverride}=='Y');
356
357//mem table
358 $bdprss_db->updateTable($bdprss_db->msitetable, $siteArray, 'cidentifier',
359 $row->{$bdprss_db->csitenameoverride}=='Y');
360
361
362 // Establish virginity - an important concept for sites that don't provide item timestamps
363 $virgin = ($lastupdated == 1);
364 if(BDPRSS2_DEBUG) $bdprss_db->recordError($url, "I am a virgin site");
365
366 // extract and save key item information
367 $counter = 1;
368 foreach ($pfeed['items'] as $item)
369 {
370 $ticks = 0;
371
372 $link = $item['link'];
373 if(isset($item['title'])) {
374 $title = $item['title'];
375 }else{
376 $title=false;
377 }
378
379//parteibuch fill the new item site name, url and license info
380 $itemsitename="";
381 $itemsiteurl="";
382 $itemlicense="";
383
384 $itemsitename .= $row->{$bdprss_db->csitename};
385 $itemsiteurl .= $row->{$bdprss_db->csiteurl};
386 $itemlicense .= $row->{$bdprss_db->csitelicense};
387
388 if(!($row->{$bdprss_db->csitenameoverride}=='Y')){
389 if(isset($item['dc:creator']) && strlen($item['dc:creator'])>0) {
390 $itemsitename = $item['dc:creator'];
391 } elseif(strlen(mb_substr($pfeed['title'], 0, 250))>0){
392 $itemsitename = mb_substr($pfeed['title'], 0, 250);
393 }
394 if(isset($item['dc:source']) && strlen($item['dc:source'])>0) {
395 $itemsiteurl = $item['dc:source'];
396 } elseif(strlen(mb_substr($pfeed['link'], 0, 250))>0){
397 $itemsiteurl = mb_substr($pfeed['link'], 0, 250);
398 }
399 if(isset($item['dc:rights']) && strlen($item['dc:rights'])>0) {
400 $itemlicense = $item['dc:rights'];
401 } elseif(isset($pfeed['copyright']) && strlen(mb_substr($pfeed['copyright'], 0, 250))>0){
402 $itemlicense = mb_substr($pfeed['copyright'], 0, 250);
403 }
404 }
405
406 if(!$link && isset($item['guid']))
407 {
408 // A work around for Penny Sharpe's blog - http://pennysharpe.com/redleather/
409 $link = $item['guid']; // in RSS guid stands for globally unique identifier
410 }
411
412 // some error reporting sequences
413 if($link)
414 { $preError = "<a href='$link'>"; $postError = '</a>'; }
415 if($title && $link)
416 $errorLink = ' ('.$preError.$title.$postError.') ';
417 elseif($title && !$link)
418 $errorLink = ' ('.$title.') ';
419 elseif($link && !$title)
420 $errorLink = ' ['.$preError.'link'.$postError.'] ';
421 else
422 $errorLink = '';
423
424 if(!$title)
425 {
426 $bdprss_db->recordError($url, "No title in feed for item $errorLink");
427 // lets see if we can make a half a meaningful title from the link
428 $title = 'No title';
429 }
430
431 if(!$link)
432 {
433 $bdprss_db->recordError($url, "No link in feed for item $errorLink");
434 continue; // a URL link for the item is needed for the database
435 }
436
437//Parteibuch Debug
438 if(false && $url=='http://www.blog.de/srv/xml/xmlfeed.php?blog=140501&mode=rss2.0')
439 {
440 $bdprss_db->recordError($url, "Debug about wrong link for $errorLink");
441 }
442
443
444 $link = mb_substr($link, 0, 250); // keep it short buddy
445 $title = mb_substr($title, 0, 250); // keep it short buddy
446
447 // get the itemtext
448 if(isset($item['content:encoded']))
449 $itemtext = $item['content:encoded'];
450 elseif(isset($item['description']))
451 $itemtext = $item['description'];
452 elseif(isset($item['content']))
453 $itemtext = $item['content'];
454 elseif(isset($item['summary']))
455 $itemtext = $item['summary'];
456 else
457 $itemtext = '';
458
459 // get the time - this is tricky because many feeds don't provide a timestamp
460 $ticks = 0;
461 $timeType =
462 array('pubDate', 'dc:date', 'created', 'issued', 'published', 'updated', 'modified');
463 $done = FALSE;
464 foreach($timeType as $t)
465 {
466 if(isset($item[$t]))
467 {
468 $done = TRUE;
469 $ticks = strtotime($item[$t]);
470 if($ticks > 0) break;
471 $ticks = preg_replace("'[- +a-z]*$'si", '', $item[$t]);
472 $ticks = strtotime($ticks);
473 if($ticks > 0) break;
474 $ticks = BDPRSS2::w3cdtf($item[$t]);
475 if($ticks > 0) break;
476 $bdprss_db->recordError($url, 'Exact time of item post not correctly encoded: '.
477 $t.'['.$item[$t]."] $errorLink");
478 $done = FALSE;
479 }
480 if($ticks < 0) $ticks = 0;
481 }
482 if(!$done) $bdprss_db->recordError($url,
483 "No time-stamp in feed for post item $errorLink");
484 $rawTicks = $ticks;
485 $gmtadjust_seconds = intval(floatval($row->{$bdprss_db->cgmtadjust}) * 3600);
486 $ticks += $gmtadjust_seconds;
487
488 // make time adjustments -- including for those feeds without timestamps
489 $windforward = FALSE;
490 $windback = FALSE;
491 $gmt_adjust = 0.0;
492 if($ticks <= 1000000)
493 {
494 if($virgin)
495 $ticks = 0;
496 else
497 $ticks = $now - $counter;
498 }
499 else
500 {
501 if (!$virgin)
502 {
503 // reprogram any necessary GMT adjustments for out of sync time stamps
504 // we can change $ticks here as ...
505 // ... $bdprss_db->update_itemstable() only updates $ticks on inserts
506 // ... it will not affect updates
507 if($ticks > intval($now+300))
508 {
509 $windback = TRUE;
510 $gmt_adjust = -0.5;
511 }
512 if($ticks < intval($lastupdated-300)) {
513 $windforward = TRUE;
514 $ticks = $now - $counter;
515 $gmt_adjust = 0.5;
516 }
517 }
518 }
519
520 // one final tweak to prevent forward time
521 if($ticks > $now) $ticks = $now - $counter;
522
523 // update/insert item information
524
525 if ($bdprss_db->updateItem($url, $title, $counter, $itemtext, $link, $ticks, $itemsitename, $itemsiteurl, $itemlicense) && !$virgin)
526 {
527 // it was an item insert (and not an update) for an old feedurl
528 // -- let's see if we need to do an automatic adjustmemt to the time!
529 if($windback || $windforward)
530 {
531 $bdprss_db->recordError($url, "Raw time stamp: " .
532 PBALIB::gettheage($rawTicks). $errorLink);
533 $gmt_adjust += floatval($row->{$bdprss_db->cgmtadjust});
534 if($gmt_adjust > 48.0) $gmt_adjust = 48.0;
535 if($gmt_adjust < -48.0) $gmt_adjust = -48.0;
536 $siteArray['cgmtadjust'] = $gmt_adjust;
537 $bdprss_db->updateTable($bdprss_db->sitetable, $siteArray, 'cidentifier',
538 $row->{$bdprss_db->csitenameoverride}=='Y');
539
540//mem table
541 $bdprss_db->updateTable($bdprss_db->msitetable, $siteArray, 'cidentifier',
542 $row->{$bdprss_db->csitenameoverride}=='Y');
543
544 $bdprss_db->recordError($url, "New GMT adjustment: $gmt_adjust hours $errorLink");
545 }
546 }
547 $counter++;
548 }
549 $bdprss_db->delete_old_items($url);
550 }
551
552 function w3cdtf($dateString='')
553 {
554 /* w3cdtf() -- modified from parse_w3cdtf() in functions-rss.php in Wordpress!
555 */
556
557 //parteibuch: get rid of milliseconds if any
558 $dateString=preg_replace('/\.\d{3}/','',$dateString);
559
560 // regex to match wc3dtf
561 $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/i";
562
563 if ( preg_match( $pat, $dateString, $match ) )
564 {
565 list( $year, $month, $day, $hours, $minutes, $seconds) =
566 array( intval($match[1]), intval($match[2]), intval($match[3]),
567 intval($match[4]), intval($match[5]), intval($match[6]));
568
569 if ( $match[10] != 'Z' )
570 {
571 list( $tz_mod, $tz_hour, $tz_min ) =
572 array( $match[8], intval($match[9]), intval($match[10]));
573
574 // zero out the variables
575 if ( ! $tz_hour ) { $tz_hour = 0; }
576 if ( ! $tz_min ) { $tz_min = 0; }
577
578 $offset = (($tz_hour*60)+$tz_min)*60;
579
580 // is timezone ahead of GMT? then subtract offset
581 if ( $tz_mod == '+' ) { $offset *= -1; }
582 }
583 else
584 {
585 $offset = 0;
586 }
587
588 $secondsSinceEpoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year) + $offset;
589 }
590 else
591 {
592 $secondsSinceEpoch = -1; // error
593 }
594
595 return $secondsSinceEpoch;
596 }
597
598
599 /* --- core output functions --- */
600
601 function remove_link_and_cache_links_from_item($itemtext=''){
602 //Remove old Cache Link at end of posting
603 $itemtext=preg_replace('/\[[^\]]*&gt;Cache&lt;\/a&gt;\]$/','',$itemtext);
604 //Remove old Link Link at end of posting
605 $itemtext=preg_replace('/\[[^\]]*&gt;Link&lt;\/a&gt;\] ?$/','',$itemtext);
606 return $itemtext;
607 }
608
609 function packageItemText($string, $wordCount=0, $maxWordLength=50, $processTags=FALSE, $tagSet='')
610 {
611 global $bdp_output;
612 // keep acceptable tags
613 $string = mb_eregi_replace("\&lt;", '<', $string);
614 $string = mb_eregi_replace("\&gt;", '>', $string);
615 if($processTags && $tagSet)
616 {
617 $tagSet = preg_split("','", $tagSet, -1, PREG_SPLIT_NO_EMPTY);
618 foreach($tagSet as $ts)
619 {
620 // space out tags so they are are easy to identify
621 $string = mb_eregi_replace("<($ts [^>]*)>", " &lt;\\1&gt;", $string);
622 $string = mb_eregi_replace("<($ts)>", " &lt;\\1&gt;", $string);
623 $string = mb_eregi_replace("<(/$ts)>", " &lt;\\1&gt;", $string);
624 }
625 }
626 // delete unrequired tags
627 $string = mb_eregi_replace("<[a-zA-Z]+[^>]*>", '', $string);
628 $string = mb_eregi_replace("</[a-zA-Z]+[^>]*>", '', $string);
629 // restore required tags
630 $string = mb_eregi_replace("\&lt;", '<', $string);
631 $string = mb_eregi_replace("\&gt;", '>', $string);
632
633 // count words
634 $words = explode(' ', $string);
635 $outWords = array();
636 $count = count($words);
637
638 $inTag = false;
639 $HTMLclosure = array();
640 $token = false;
641
642 if(!$wordCount) $wordCount= -1; // backward compatibility so that zero = no limit
643
644 for($i=0; $i<$count && $wordCount!=0; $i++)
645 {
646 // trim
647 $outWords[$i] = mb_ereg_replace("^\s+", "", $words[$i]);
648 $outWords[$i] = mb_ereg_replace("\s+$", "", $outWords[$i]);
649
650 if(!$outWords[$i]) continue;
651
652 if($processTags)
653 {
654 if(mb_ereg('^<', $outWords[$i]))
655 {
656 if($inTag) $bdp_output .= "<!-- glitch nested tags? -->\n";
657 $inTag = TRUE;
658 if(mb_ereg('^<([a-zA-Z]+)', $outWords[$i], $matches))
659 {
660 //open tag
661 $m = mb_strtolower($matches[1]);
662 array_push($HTMLclosure, $m);
663 $token = $m;
664 }
665 if(mb_ereg('^</([a-zA-Z]+).*', $outWords[$i], $matches))
666 {
667 // close tag
668 $m = mb_strtolower($matches[1]);
669 $t = array_pop($HTMLclosure);
670 if($t && $t!=$m)
671 array_push($HTMLclosure, $t);
672 $inTag = FALSE;
673 }
674 }
675
676 if($inTag)
677 {
678 if(mb_ereg('/>', $outWords[$i]))
679 {
680 // closure
681 $m = $token;
682 $t = array_pop($HTMLclosure);
683 if($t && $t!=$m) array_push($HTMLclosure, $t);
684 }
685 // quotes in tags must be respected
686 $outWords[$i] = mb_eregi_replace('&quot;', '"', $outWords[$i]);
687 $outWords[$i] = mb_eregi_replace('&#39;', "'", $outWords[$i]);
688 if(mb_ereg('>', $outWords[$i]))
689 {
690 $inTag = FALSE;
691 $token = FALSE;
692 }
693 continue;
694 }
695 }
696 $len = mb_strlen($outWords[$i]);
697 if($maxWordLength && $len > $maxWordLength)
698 {
699 $outWords[$i] = mb_substr($outWords[$i], 0, $maxWordLength);
700 $outWords[$i] .= '~';
701 }
702 $wordCount--;
703 }
704
705 $ret = implode(' ', $outWords);
706
707 if($inTag) $ret .= '>';
708
709 if(count($words) > count($outWords)) $ret .= ' ...';
710
711 if($processTags)
712 {
713 // close open tags
714 while($t = array_pop($HTMLclosure)) $ret .= "</$t>";
715
716 // tighten up the HTML
717 $ret = mb_eregi_replace(" (</[a-zA-Z]+>)", "\\1", $ret);
718 $ret = mb_eregi_replace("([\(\$\[\{]) (<[a-zA-Z]+[^\>]*>)", "\\1\\2", $ret);
719 $ret = mb_eregi_replace("&quot; (<[a-zA-Z]+[^\>]*>)", "&quot;\\1", $ret);
720 $ret = mb_eregi_replace("&#34; (<[a-zA-Z]+[^\>]*>)", "&#34;\\1", $ret);
721 $ret = mb_eregi_replace("&#39; (<[a-zA-Z]+[^\>]*>)", "&#39;\\1", $ret);
722 $ret = mb_eregi_replace("&#8216; (<[a-zA-Z]+[^\>]*>)", "&#8216;\\1", $ret);
723 $ret = mb_eregi_replace("&lsquo; (<[a-zA-Z]+[^\>]*>)", "&lsquo;\\1", $ret);
724 $ret = mb_eregi_replace("&#8220; (<[a-zA-Z]+[^\>]*>)", "&#8220;\\1", $ret);
725 $ret = mb_eregi_replace("&ldquo; (<[a-zA-Z]+[^\>]*>)", "&ldquo;\\1", $ret);
726 $ret = mb_eregi_replace("(<[a-zA-Z]+[^\>]*>) (<[a-zA-Z]+[^\>]*>)", "\\1\\2", $ret);
727 }
728 return ($ret);
729 }
730
731 function codeQuotes($text)
732 {
733 $text = ereg_replace('&#39;' ,"'", $text);
734 $text = eregi_replace('&quot;' ,'"' , $text);
735 return $text;
736 }
737
738// begin old function dummies
739 function print_item_set(&$itemSet, $listInfo, $relative='relative', $short_cache_link=false, $add_social_bookmarks=false, $useitemtitles=false){
740 echo "Debug: functionality of print_item_set function has been replaced by PBA::outputwrapper";
741 return false;
742 }
743 function putsiteheader($prehead, $posthead, $siteaddress, $description, $sitename){
744 echo "Debug: functionality of putsiteheader function has been replaced by PBA::outputwrapper";
745 return false;
746 }
747 function output($output_id, $overwrite_items_per_site='N', $short_cache_link=false, $outputdate="", $add_social_bookmarks=false, $tickerpage=1, $search="", $useitemtitles=false, $overwrite_listfilter=false){
748 echo "Debug: functionality of output function has been replaced by PBA::outputwrapper";
749 return false;
750 }
751 function archiveDate($output_id){
752 echo "Debug: functionality of archiveDate function has been replaced by PBA::outputwrapper";
753 return false;
754 }
755 function archiveList($output_id, $query_string_archive=true){
756 echo "Debug: functionality of archiveList function has been replaced by PBA::outputwrapper";
757 return false;
758 }
759 function viewCache($listnum=0,$itemnum=0){
760 echo "Debug: functionality of viewCache function has been replaced by PBA::outputwrapper";
761 return false;
762 }
763 function rss_print_item_set(&$itemSet, $listInfo, $relative='relative', $short_cache_link=false, $itemdate, $search) {
764 echo "Debug: functionality of rss_print_item_set function has been replaced by PBA::outputwrapper";
765 return false;
766 }
767 function rss_output($output_id, $short_cache_link=false){
768 // rss_output() -- just a reference on historic reasons to output()
769 $feeditems=BDPRSS2::output($output_id, 'N', $short_cache_link, "", false, 'feed', "", false);
770 return $feeditems;
771 }
772 function feeds_in_ticker($feedinlist=1,$age=604800){
773 echo "Debug: functionality of feeds_in_ticker function has been replaced by PBA::outputwrapper";
774 return false;
775 }
776 function feedlist($output_id=1, $maxage=604800, $list_id=false){
777 echo "Debug: functionality of feeds_in_ticker function has been replaced by PBA::outputwrapper";
778 return false;
779 }
780 function process_url_parameter(){
781 echo "Debug: function process_url_parameter has been removed to class PBALIB in pba_output_library.php";
782 return false;
783 }
784// end old function dummies
785
786
787 } // class BDPRSS2
788} // if( !class_exists('BDPRSS2') )
789
790
791//here cames the parteibuch aggregator stuff
792 if(!(isset($bdprsssearchdebug) && $bdprsssearchdebug ===true)&& !class_exists('BDPRSS_SEARCH') ) {
793 require_once(dirname(__FILE__) . '/pba-rsssearch.php');
794 require_once(dirname(__FILE__) . '/pba_output_function.php');
795 global $bdprss_db;
796 if($bdprss_db->memtables_were_ok == 0) $result=$bdprss_search->bdprss_create_proc();
797 }
798
799
800
801?>
Note: See TracBrowser for help on using the repository browser.