1<?php 2global $lib_exe; 3$lib_exe = false; 4if(strpos(dirname(__FILE__), 'lib/exe')) { 5 define("INC_DIR", "../../inc"); 6 $lib_exe = true; 7} 8else { 9 define("INC_DIR", "./inc"); 10 } 11 12require_once INC_DIR . '/init.php'; 13require_once DOKU_INC . 'lib/plugins/news/scripts/rss.php'; 14require_once DOKU_INC . 'lib/plugins/news/helper.php'; 15$newsfeed_ini = DOKU_INC . 'lib/plugins/news/scripts/newsfeed.ini'; 16global $conf; 17global $newsChannelTitle; 18global $newsChannelDescription; 19global $newsChannelTtl; 20global $newsFeedURL,$INPUT, $helper; 21$newsFeedURL = ""; 22$refresh=false; 23$title = ""; 24$test = ""; 25$helper = new helper_plugin_news(); 26 27if(isset($_POST) && isset($_POST['feed']) && $_POST['feed']=='refresh') { 28 $refresh = true; 29 if(isset($_POST['title'])) { 30 $title = $INPUT->str('title'); 31 } 32} 33else if($argc > 1) { 34 $title = $argv[1]; 35} 36else if(isset($_GET) && isset($_GET['feed'])) { 37 $title = $INPUT->str('feed'); 38} 39if(isset($_POST) || isset($_GET) ) { 40 if(isset($_REQUEST['test']) && !is_writable(DOKU_INC) ) { 41 echo DOKU_INC . " is not writable by the web server.<br />Please check your permissions."; 42 return; 43 } 44} 45$minute = 60; 46$default_ttl = 720*$minute; 47$ttl = 0; 48$filetime = 0; 49$curent_time = time(); 50if($title) { 51 $xml_file = DOKU_INC . $title . '_news.xml'; 52} 53else { 54 $xml_file = DOKU_INC . 'news_feed.xml'; 55 } 56 if(file_exists($newsfeed_ini)) { 57 $ini_array = parse_ini_file($newsfeed_ini, true); 58 $which = isset($ini_array[$title]) ? $title : 'default'; 59 $newsChannelTitle = $ini_array[$which]['title']; 60 $newsChannelDescription = $ini_array[$which]['description'] ; 61 $newsChannelTtl = isset($ini_array[$which]['ttl']) ? $ini_array[$which]['ttl'] : $helper->ttl(); 62 63} 64 65 if(isset($conf['plugin']['news'])) { 66 if(isset($conf['plugin']['news']['ttl'])) { 67 $ttl = $conf['plugin']['news']['ttl']; 68 if($ttl) $ttl *= $minute; 69 } 70 if(!$newsChannelTitle && isset($conf['plugin']['news']['title'])) { 71 $newsChannelTitle = $conf['plugin']['news']['title']; 72 } 73 if(!$newsChannelDescription && isset($conf['plugin']['news']['desc'])) { 74 $newsChannelDescription = $conf['plugin']['news']['desc']; 75 } 76 if(!$newsChannelTtl && isset($conf['plugin']['news']['ttl'])) { 77 $newsChannelTtl = $conf['plugin']['news']['ttl']; 78 } 79 if(isset($conf['plugin']['news']['url'])) { 80 $newsFeedURL = $conf['plugin']['news']['url']; 81 } 82 } 83 84 if(!$ttl) $ttl = $default_ttl; 85 if(@file_exists($xml_file)) { 86 $filetime = filemtime($xml_file); 87 } 88 89 $time_elapsed = ($curent_time - $filetime); 90 if($time_elapsed >= $ttl || $lib_exe || $refresh) { 91 new externalNewsFeed($xml_file,$ttl/$minute,$title); 92 if($lib_exe) { 93 chmod($xml_file, 0666); 94 } 95 } 96 if(!$lib_exe && ! $refresh) { 97 header('Content-type: application/xml'); 98 readfile($xml_file); 99 } 100 101 if($refresh) { 102 header('Content-type: text/html'); 103 if(@file_exists($xml_file)) { 104 $create_time= filectime($xml_file); 105 if($create_time >= $current_time) { 106 echo '<span style="font-size: 11pt">'; 107 echo 'Feed generated: ' . date('r',$create_time) , '</span><br/>'; 108 } 109 else echo "New Feed may not have been not created<br />"; 110 } 111 112 $id = htmlentities(urldecode($INPUT->str('feed_ref'))); 113 $ret_url = DOKU_URL . 'doku.php?id=' . $id; 114 echo '<br /><a href ="' . $ret_url . '" style="font-size: 12pt;color:#8cacbb">Return to ' . $id . '</a>'; 115 } 116 117 118 exit; 119 120?>