* * Creation: 2012-04-22 jed * Last Update: $Id: capi2text-rss.php 43019 2016-08-26 11:50:52Z jed $ * * Usage: If you want to create a RSS feed for a specific MSN (e.g. 31) * you only have to create a symbolic link wich contains the * MSN as follows: * * ln -s capi2text-rss.php capi2text-rss-31.php * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *------------------------------------------------------------------------ */ // the following parameters are set by configuration parameters $call_file = '/public/anrufe.txt'; $msn_replace_file = '/public/msn-replace.txt'; $text_nbr_not_found = 'Kein Eintrag'; $web_fqdn = 'www.beispiel.de'; // the following parameters could be customized using the index-params.inc file $rss_encoding = 'UTF-8'; $rss_title = 'Capi2Text Anrufliste'; $rss_specific_msn = 'für MSN'; $rss_name = 'Name:'; $rss_address = 'Adresse:'; $rss_extension = 'Nebenstelle:'; $rss_protocol = 'http'; $rss_docs_path = 'capi2text/rss.php'; $rss_description = 'Liste der eingegangenen Anrufe'; $rss_language = 'de-de'; $rss_generator = 'Capi2Text Feed Engine'; $rss_editor = 'webmaster@beispiel.de (Editor in Charge)'; $rss_webmaster = 'webmaster@beispiel.de (Webmaster)'; $rss_call_from = 'Anruf von'; $rss_no_msn = false; // 'true' will suppress msn information $rss_no_loginfo = false; // 'true' will suppress log // information like [Ws] etc. $rss_filter_msn = 'all'; // 'all' or valid MSN $rss_ttl = 5; // time to live: 5 min $rss_skip_days = ''; // no rss polling days, e.g. 'Saturday' $rss_skip_hours = '0 1 2 3 4 5'; // no rss polling hours, e.g. '0 1 2 3' // end of customizable parameters // override parameters if (@file_exists('capi2text-params.inc')) include_once('capi2text-params.inc'); $rss_link = $rss_protocol . "://" . $web_fqdn . "/"; $rss_docs = $rss_link . $rss_docs_path; $rss_item_link = $rss_docs; // extract numeric value from script name to allow multiple MSN specific RSS feeds // page name must be in the format *-33.php, e.g. rss-33.php or capi2text-33.php $rss_msn = preg_replace("|^.*-|", "", pathinfo($_SERVER["SCRIPT_NAME"], PATHINFO_FILENAME)); if (is_numeric($rss_msn)) { // use value to filter MSNs $rss_filter_msn = $rss_msn; } // read MSN replace file if it exists // // 'msn' -> valid MSN (extension), e.g. '31' // 'desc' -> description of MSN, e.g. 'Living Room' // 'color' -> MSN specific color, e.g. '#ffee00' // $arr_msn_replace = array(array('msn' => '', 'desc' => '', 'color' => '')); $msn_replace = false; $i = 0; if ($msn_replace_file <> '' && file_exists($msn_replace_file)) { $msn_replace = true; $mf = fopen($msn_replace_file, 'r') or die("Cannot open file '$msn_replace_file'!"); while (!feof($mf)) { $line = trim(fgets($mf, 500)); if (!preg_match("/^#/", $line) && !preg_match("/^$/", $line)) { // ignore comments and empty lines list($arr_msn_replace[$i]['msn'], $arr_msn_replace[$i]['desc'], $arr_msn_replace[$i]['color']) = array_pad(explode("\t", $line), 3, ''); if ( $arr_msn_replace[$i]['desc'] == "" ) $arr_msn_replace[$i]['desc'] = $arr_msn_replace[$i]['msn']; if ( $arr_msn_replace[$i]['color'] <> "" ) $msn_color['msn'.$arr_msn_replace[$i]['desc']] = $arr_msn_replace[$i]['color']; $i++; } } fclose($mf); } // read call logfile // // 'date' -> date stamp, e.g. '2012-03-13' // 'time' -> time stamp, e.g. '14:15:59' // 'from' -> incoming phone number, e.g. '0221334455' // 'to' -> called MSN (extension), e.g. '31' // 'name' -> name of caller, e.g. 'Hans Mueller' // 'address' -> address of caller, e.g. 'Hauptstr. 111, 41472 Neuss, DE' // 'to_desc' -> description of called MSN, e.g. 'Living Room' // $arr_phone_calls = array(array('date' => '', 'time' => '', 'from' => '', 'to' => '', 'name' => '', 'address' => '', 'to_desc' => '' )); $i = 0; if ($call_file <> '' && file_exists($call_file)) { $cf = fopen($call_file, 'r') or die("Cannot open file '$call_file'!"); while (!feof($cf)) { // write calls to array list($arr_phone_calls[$i]['date'], $arr_phone_calls[$i]['time'], $arr_phone_calls[$i]['from'], $arr_phone_calls[$i]['to'], $arr_phone_calls[$i]['name'], $arr_phone_calls[$i]['address']) = array_pad(explode("\t", rtrim(fgets($cf, 500))), 6, ''); // preset MSN description $arr_phone_calls[$i]['to_desc'] = $arr_phone_calls[$i]['to']; // suppress loginfo, like '[Ws]' etc. if ($rss_no_loginfo && preg_match("/ \[[CLW]s*\]/", $arr_phone_calls[$i]['name'])) $arr_phone_calls[$i]['name'] = preg_replace("/ \[[CLW]s*\]/", "", $arr_phone_calls[$i]['name']); if ($msn_replace) { // replace MSN by description $msn_search = $arr_phone_calls[$i]['to']; foreach ($arr_msn_replace as $msn_replace) { if ($msn_replace['msn'] == $msn_search) { $arr_phone_calls[$i]['to_desc'] = $msn_replace['desc']; break; } } } $i++; } $i--; fclose($cf); } else die("File '$call_file' doesn't exist!"); // modify RSS title if a specifc MSN filter has been set if ($rss_filter_msn !== 'all') { // preset MSN description $rss_filter_msn_desc = $rss_filter_msn; foreach ($arr_msn_replace as $msn_replace) { if ($msn_replace['msn'] == $rss_filter_msn) { $rss_filter_msn_desc = $msn_replace['desc']; break; } } $rss_title = "$rss_title $rss_specific_msn $rss_filter_msn_desc"; } // create RSS output echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " $rss_title\n"; echo " $rss_link\n"; echo " $rss_description\n"; echo " $rss_language\n"; echo " " . date(DATE_RFC2822, strtotime("2012-04-22")) . "\n"; echo " " . date(DATE_RFC2822) . "\n"; echo " $rss_docs\n"; echo " $rss_generator\n"; echo " $rss_editor\n"; echo " $rss_webmaster\n"; if ($rss_ttl !== '') // time-to-live of cache content echo " $rss_ttl\n"; if ($rss_skip_days !== '') { // don't poll on this days echo " \n"; foreach (explode(' ', $rss_skip_days, 7) as $skip_day) echo " $skip_day\n"; echo " \n"; } if ($rss_skip_hours !== '') { // don't poll at this hours echo " \n"; foreach (explode(' ', $rss_skip_hours, 24) as $skip_hour) echo " $skip_hour\n"; echo " \n"; } // output data in reverse order foreach(array_reverse($arr_phone_calls, true) as $phone_call) { if ( $phone_call['date'] != "" ) { // not empty, go on ... if ($rss_filter_msn == "all" || $rss_filter_msn == $phone_call['to']) { // valid selection, output RSS item echo " \n"; if ($phone_call['address'] == $text_nbr_not_found) $rss_outstr = $phone_call['address']; // set 'No entry found' else $rss_outstr = $phone_call['name']; // set 'Hans Müller' if (is_numeric($phone_call['from'])) $rss_outstr = $rss_outstr . " (" . htmlspecialchars($phone_call['from']) . ")"; // add ' (calling number)' if (!$rss_no_msn) { if ($rss_filter_msn == 'all') { // add 'for MSN ...' if ($msn_replace) $rss_outstr = $rss_outstr . " " . $rss_specific_msn . " " . $phone_call['to_desc']; // ... 'MSN replacement text' else $rss_outstr = $rss_outstr . " " . $rss_specific_msn . " " . $phone_call['to']; // ... 'MSN number' } } echo " [" . $phone_call['date'] . " " . $phone_call['time'] . "] $rss_call_from " . htmlspecialchars($rss_outstr) . "\n"; echo " " . $rss_item_link . "\n"; echo " " . date(DATE_RFC2822, strtotime($phone_call['date'] . " " . $phone_call['time'])) . "\n"; if (htmlspecialchars($phone_call['address']) == '') $rss_outstr = " " . $rss_name . " " . $phone_call['name']; else $rss_outstr = " " . $rss_name . " " . $phone_call['name'] . "
 " . $rss_address . " " . $phone_call['address']; if ($msn_replace) $rss_outstr = $rss_outstr . "
 " . $rss_extension . " " . $phone_call['to_desc']; // ... 'MSN replacement text' else $rss_outstr = $rss_outstr . "
 " . $rss_extension . " " . $phone_call['to']; // ... 'MSN number' echo " " . htmlspecialchars($rss_outstr) . "\n"; echo " " . $rss_item_link . "#" . preg_replace("|[^\d]|", "", $phone_call['date'] . $phone_call['time']) . "\n"; echo "
\n"; } } } echo "
\n"; echo "
\n"; ?>