'Taggic', 'email' => 'Taggic@t-online.de', 'date' => '2016-06-02', 'name' => 'News archive page (action plugin component)', 'desc' => 'to show the News aechive alone on a page.', 'url' => 'http://www.dokuwiki.org/plugin:anewssystem', ); } /****************************************************************************** ** Register its handlers with the dokuwiki's event controller */ function register(Doku_Event_Handler &$controller) { $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, '_handle_act', array()); $controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'output', array()); } /****************************************************************************** ** Handle the action */ function _handle_act(&$event, $param) { if($event->data !== 'shownewsarchive') { return; } $event->preventDefault(); // https://www.dokuwiki.org/devel:events#event_object return true; } /****************************************************************************** ** Generate output */ function output(&$event, $param) { if($event->data !== 'shownewsarchive') { return; } global $ID; $target = $this->getConf('news_datafile'); $targetpage = htmlspecialchars(trim($target)); $prefix = 'anss'; $del = 'anss_del'; $cut_prefx = 'news_input_'; $allnewsdata1 = $this->getConf('news_output'); $allnewsdata = wl( (isset($allnewsdata1) ? $allnewsdata1 : 'news:newsdata') ); $i = strripos($allnewsdata, ":"); $news_root = substr($allnewsdata, 0, $i); // necessary for the back link of a show one article per page (SOAPP) if(stripos($_GET['archive'],'archive')!== false) $ans_conf['param'] = $_GET['archive']; $_GET['archive']=""; // 1. read template (plugins/anewssystem/template.php) $template = file_get_contents(DOKU_PLUGIN.'anewssystem/tpl/newstemplate.txt'); /*------- add news action part -----------------------------------------*/ $post_prefix = $_POST["xs-".$prefix]; $delete_record = $_POST["anss_del_record"]; $delete_anchor = $_POST["anss_del_anchor"]; // date ... consider all news of a defined month of a year (mm.yyyy, empty per default) // qty ... limits the number of news headlines starting with most recent (either integer or all, default:all) // tag ... consider all news where news article owns the given tag string (empty per default) tag delimiter is "|" // style ... css style string as used in HTML (except quotation marks) for the outer element div // class ... css style for usecase toc, page or box // ho ... headlinesonly will list the news headlines without timestamp and author (on/off, default: off) // check if page ID was called with tag filter // $tmp .= ','.$_GET['tag']; // this will overrule the page syntax setting if(strlen($tmp)<2) { // strip parameter to get set of add parameter $tmp = substr($ans_conf['param'],strlen('allnews')); } $split_array = explode(',',$tmp); // one or multiple tag filters: $prefs[1] ... [n] $archive_options = array(); // split parameter into array with key and data foreach ($split_array as $item) { list($key, $value) = split("=",trim($item),2); $archive_options = $archive_options + array($key => $value); } if(($archive_options['qty']=='') || ($archive_options['qty']<1)) $archive_options['qty'] = 'all'; if(array_key_exists('class',$archive_options) === false) $archive_options['class'] = 'page'; if(array_key_exists('ho',$archive_options) === false) $archive_options['ho'] = 'off'; $page = wl( (isset($targetpage) ? $targetpage : 'news:newsdata') ); // load raw news file (e.g. news:newsdata.txt) $av = 0; $oldrecord = rawWiki($targetpage); // split the news articles $newsitems = explode("======",$oldrecord); $info = array(); // get the headline level from config $yh_level = $this->getConf('yh_level'); $mh_level = $this->getConf('mh_level'); $h_level = $this->getConf('h_level'); // 1. read news file (e.g. news:newsdata.txt) foreach($newsitems as $article) { // split news block into line items $article_array = explode("\n * ",$article); unset($article_array[0]); // 2. create output // split line items into key and data $aFlag = false; // flag: start date value exists and start is not in future foreach ($article_array as $item) { list($key, $value) = split(":",trim($item),2); $tag_flag = false; if($key=='anchor') { $anchor = trim($value); } elseif(($key=='start') && strtotime(trim($value)) < time()) { $value = date($this->getConf('d_format'), strtotime($value)); $news_date = ' ('. $value; // get month and year to compare with $archive_options['date'] if(isset($archive_options['date']) && ($archive_options['date'] !== date('m.Y',strtotime($value)))) break; $aFlag = true; } // head has to be before the link in the template ! elseif($key=='head'){ $news_head = trim($value); } elseif($key=='subtitle'){ $news_subtitle = '
'.trim($value).''.NL; } elseif($key=='link'){ $news_head = ''. trim($news_head) .''.NL; } elseif($key=='author'){ $news_date .= ', '. $value; } elseif(($key=='tags') && (isset($archive_options['tag']) !== false)) { // echo $value.'
'; $tags = explode(',',$value); foreach($tags as $tag) { if(($tag!==false) && (stripos($archive_options['tag'],trim($tag))!==false)){ $tag_flag = true; break; } } } } $news_date .= ')
'.NL; if((isset($archive_options['tag']) === false) || (strlen($archive_options['tag']) <2)) $tag_flag = true; if (($aFlag === true) && ($tag_flag === true)) { //stop adding older news articles if quantity is reached // echo intval($archive_options['qty']).' >= '.$qty.'
'; $qty++; if(($qty > intval($archive_options['qty'])) && ($archive_options['qty']!=='all')) break; // list all news stories as headline linked to the story itself $elt = explode(",",$news_date); $elt[0] = trim(strip_tags(str_replace('(','',$elt[0]))); $elt[0] = date('F,Y',strtotime($elt[0])); list($new_month,$new_year) = explode(',',$elt[0]); // idea is that all stories are created one after the other // and the order within newsdata is according the start date // manipulation of Start/Perishing date possible but not expected // !!! There is no sort algorithm for year and month implemented !!! // to do such would lead into re-development of the plugin if(($old_year !== $new_year) && (($archive_options['class']==='page') || ($archive_options['ho']==='off'))) { if(trim($old_year) !== '') $close_ytag = "".NL; $output .= $close_ytag.'