mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-06 15:14:58 +00:00
add rss feed of timeline
This commit is contained in:
parent
eebb3e996d
commit
073bdf24bb
83
inc/inc.BasicAuthentication.php
Normal file
83
inc/inc.BasicAuthentication.php
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
/**
|
||||
* Do authentication of users and session management
|
||||
*
|
||||
* @category DMS
|
||||
* @package SeedDMS
|
||||
* @license GPL 2
|
||||
* @version @version@
|
||||
* @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
|
||||
* @copyright Copyright (C) 2002-2005 Markus Westphal,
|
||||
* 2006-2008 Malcolm Cowe, 2010 Uwe Steinmann
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
|
||||
require_once("inc.Utils.php");
|
||||
require_once("inc.ClassNotificationService.php");
|
||||
require_once("inc.ClassEmailNotify.php");
|
||||
require_once("inc.ClassSession.php");
|
||||
require_once("inc.ClassAccessOperation.php");
|
||||
|
||||
function __authenticate($username, $password) { /* {{{ */
|
||||
global $dms, $settings;
|
||||
|
||||
$user = false;
|
||||
|
||||
/* Authenticate against LDAP server {{{ */
|
||||
if (!$user && isset($settings->_ldapHost) && strlen($settings->_ldapHost)>0) {
|
||||
require_once("../inc/inc.ClassLdapAuthentication.php");
|
||||
$authobj = new SeedDMS_LdapAuthentication($dms, $settings);
|
||||
$user = $authobj->authenticate($username, $password);
|
||||
} /* }}} */
|
||||
|
||||
/* Authenticate against SeedDMS database {{{ */
|
||||
else {
|
||||
require_once("../inc/inc.ClassDbAuthentication.php");
|
||||
$authobj = new SeedDMS_DbAuthentication($dms, $settings);
|
||||
$user = $authobj->authenticate($username, $password);
|
||||
} /* }}} */
|
||||
|
||||
if (!$user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($user->getID() == $settings->_guestID) && (!$settings->_enableGuestLogin)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if account is disabled
|
||||
if($user->isDisabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// control admin IP address if required
|
||||
if ($user->isAdmin() && ($_SERVER['REMOTE_ADDR'] != $settings->_adminIP ) && ( $settings->_adminIP != "") ){
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user;
|
||||
} /* }}} */
|
||||
|
||||
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
header('WWW-Authenticate: Basic realm="'.$settings->_siteName.'"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
echo getMLText('cancel_basic_authentication');
|
||||
exit;
|
||||
} else {
|
||||
if(!($user = __authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))) {
|
||||
header('WWW-Authenticate: Basic realm="'.$settings->_siteName.'"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
echo getMLText('cancel_basic_authentication');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear login failures if login was successful */
|
||||
$user->clearLoginFailures();
|
||||
|
||||
$dms->setUser($user);
|
||||
$notifier = new SeedDMS_NotificationService();
|
||||
if($settings->_enableEmail) {
|
||||
$notifier->addService(new SeedDMS_EmailNotify($dms));
|
||||
}
|
||||
|
53
out/out.TimelineFeed.php
Normal file
53
out/out.TimelineFeed.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
// MyDMS. Document Management System
|
||||
// Copyright (C) 2010-2016 Uwe Steinmann
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
include("../inc/inc.Settings.php");
|
||||
include("../inc/inc.Language.php");
|
||||
include("../inc/inc.Init.php");
|
||||
include("../inc/inc.Extension.php");
|
||||
include("../inc/inc.DBInit.php");
|
||||
include("../inc/inc.ClassUI.php");
|
||||
include("../inc/inc.BasicAuthentication.php");
|
||||
|
||||
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
|
||||
$view = UI::factory($theme, $tmp[1], array('dms'=>$dms, 'user'=>$user));
|
||||
$accessop = new SeedDMS_AccessOperation($dms, $user, $settings);
|
||||
if (!$accessop->check_view_access($view, $_GET)) {
|
||||
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
|
||||
}
|
||||
|
||||
if(isset($_GET['skip']))
|
||||
$skip = $_GET['skip'];
|
||||
else
|
||||
$skip = array();
|
||||
|
||||
if($view) {
|
||||
$view->setParam('httproot', $settings->_httpRoot);
|
||||
$view->setParam('fromdate', isset($_GET['fromdate']) ? $_GET['fromdate'] : '');
|
||||
$view->setParam('todate', isset($_GET['todate']) ? $_GET['todate'] : '');
|
||||
$view->setParam('skip', $skip);
|
||||
$view->setParam('sitename', $settings->_siteName);
|
||||
$view->setParam('cachedir', $settings->_cacheDir);
|
||||
$view->setParam('previewWidthList', $settings->_previewWidthList);
|
||||
$view->setParam('previewWidthDetail', $settings->_previewWidthDetail);
|
||||
$view->setParam('timeout', $settings->_cmdTimeout);
|
||||
$view($_GET);
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
151
views/bootstrap/class.TimelineFeed.php
Normal file
151
views/bootstrap/class.TimelineFeed.php
Normal file
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
/**
|
||||
* Implementation of Feed view
|
||||
*
|
||||
* @category DMS
|
||||
* @package SeedDMS
|
||||
* @license GPL 2
|
||||
* @version @version@
|
||||
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||
* @copyright Copyright (C)2016 Uwe Steinmann
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include parent class
|
||||
*/
|
||||
require_once("class.Bootstrap.php");
|
||||
|
||||
require_once("FeedWriter/Item.php");
|
||||
require_once("FeedWriter/Feed.php");
|
||||
require_once("FeedWriter/RSS2.php");
|
||||
|
||||
use \FeedWriter\RSS2;
|
||||
|
||||
/**
|
||||
* Include class to preview documents
|
||||
*/
|
||||
require_once("SeedDMS/Preview.php");
|
||||
|
||||
/**
|
||||
* Class which outputs the html page for UserList view
|
||||
*
|
||||
* @category DMS
|
||||
* @package SeedDMS
|
||||
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||
* @copyright Copyright (C)2016 Uwe Steinmann
|
||||
* @version Release: @package_version@
|
||||
*/
|
||||
class SeedDMS_View_TimelineFeed extends SeedDMS_Bootstrap_Style {
|
||||
|
||||
function show() { /* {{{ */
|
||||
$dms = $this->params['dms'];
|
||||
$user = $this->params['user'];
|
||||
$httproot = $this->params['httproot'];
|
||||
$skip = $this->params['skip'];
|
||||
$fromdate = $this->params['fromdate'];
|
||||
$todate = $this->params['todate'];
|
||||
$cachedir = $this->params['cachedir'];
|
||||
$sitename = $this->params['sitename'];
|
||||
$previewwidthlist = $this->params['previewWidthList'];
|
||||
$previewwidthdetail = $this->params['previewWidthDetail'];
|
||||
$timeout = $this->params['timeout'];
|
||||
|
||||
if($fromdate) {
|
||||
$from = makeTsFromLongDate($fromdate.' 00:00:00');
|
||||
} else {
|
||||
$from = time()-7*86400;
|
||||
}
|
||||
|
||||
if($todate) {
|
||||
$to = makeTsFromLongDate($todate.' 23:59:59');
|
||||
} else {
|
||||
$to = time();
|
||||
}
|
||||
|
||||
$baseurl = "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$httproot;
|
||||
$feed = new RSS2;
|
||||
$feed->setTitle($sitename.': Recent Changes');
|
||||
$feed->setLink($baseurl);
|
||||
$feed->setDescription('Show recent changes in SeedDMS.');
|
||||
// Image title and link must match with the 'title' and 'link' channel elements for RSS 2.0,
|
||||
// which were set above.
|
||||
// $feed->setImage('Testing & Checking the Feed Writer project', 'https://github.com/mibe/FeedWriter', 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Rss-feed.svg/256px-Rss-feed.svg.png');
|
||||
// Use core setChannelElement() function for other optional channel elements.
|
||||
// See http://www.rssboard.org/rss-specification#optionalChannelElements
|
||||
// for other optional channel elements. Here the language code for American English and
|
||||
$feed->setChannelElement('language', 'en-US');
|
||||
// The date when this feed was lastly updated. The publication date is also set.
|
||||
$feed->setDate(date(DATE_RSS, time()));
|
||||
$feed->setChannelElement('pubDate', date(\DATE_RSS, strtotime('2013-04-06')));
|
||||
// You can add additional link elements, e.g. to a PubSubHubbub server with custom relations.
|
||||
// It's recommended to provide a backlink to the feed URL.
|
||||
$feed->setSelfLink($baseurl.'out/out.Feed.php');
|
||||
// $feed->setAtomLink('http://pubsubhubbub.appspot.com', 'hub');
|
||||
// You can add more XML namespaces for more custom channel elements which are not defined
|
||||
// in the RSS 2 specification. Here the 'creativeCommons' element is used. There are much more
|
||||
// available. Have a look at this list: http://feedvalidator.org/docs/howto/declare_namespaces.html
|
||||
// $feed->addNamespace('creativeCommons', 'http://backend.userland.com/creativeCommonsRssModule');
|
||||
// $feed->setChannelElement('creativeCommons:license', 'http://www.creativecommons.org/licenses/by/1.0');
|
||||
// If you want you can also add a line to publicly announce that you used
|
||||
// this fine piece of software to generate the feed. ;-)
|
||||
// $feed->addGenerator();
|
||||
|
||||
if($data = $dms->getTimeline($from, $to)) {
|
||||
foreach($data as $i=>$item) {
|
||||
switch($item['type']) {
|
||||
case 'add_version':
|
||||
$msg = getMLText('timeline_'.$item['type']);
|
||||
break;
|
||||
case 'add_file':
|
||||
$msg = getMLText('timeline_'.$item['type']);
|
||||
break;
|
||||
case 'status_change':
|
||||
$msg = getMLText('timeline_'.$item['type'], array('version'=> $item['version'], 'status'=> getOverallStatusText($item['status'])));
|
||||
break;
|
||||
default:
|
||||
$msg = '???';
|
||||
}
|
||||
$data[$i]['msg'] = $msg;
|
||||
}
|
||||
|
||||
$previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidthdetail, $timeout);
|
||||
foreach($data as $item) {
|
||||
if($item['type'] == 'status_change')
|
||||
$classname = $item['type']."_".$item['status'];
|
||||
else
|
||||
$classname = $item['type'];
|
||||
if(!$skip || !in_array($classname, $skip)) {
|
||||
$doc = $item['document'];
|
||||
$owner = $doc->getOwner();
|
||||
$version = $doc->getContentByVersion($item['version']);
|
||||
$previewer->createPreview($version);
|
||||
$d = makeTsFromLongDate($item['date']);
|
||||
$newItem = $feed->createNewItem();
|
||||
$newItem->setTitle($doc->getName()." (".$item['msg'].")");
|
||||
$newItem->setLink($baseurl.'out/out.ViewDocument.php?documentid='.$doc->getID());
|
||||
$newItem->setDescription("<h2>".$item['msg']."</h2>".
|
||||
"<p>".getMLText('comment').": <b>".$doc->getComment()."</b></p>".
|
||||
"<p>".getMLText('owner').": <b><a href=\"mailto:".$owner->getEmail()."\">".$owner->getFullName()."</a></b></p>".
|
||||
"<p>".getMLText("creation_date").": <b>".getLongReadableDate($doc->getDate())."</p>"
|
||||
);
|
||||
$newItem->setDate(date('c', $d));
|
||||
$newItem->setAuthor($owner->getFullName(), $owner->getEmail());
|
||||
$newItem->setId('out/out.ViewDocument.php?documentid='.$doc->getID(), true);
|
||||
if($previewer->hasPreview($version)) {
|
||||
$newItem->addElement('enclosure', null, array('url' => $baseurl.'op/op.Preview.php?documentid='.$item['document']->getId().'&version='.$version->getVersion().'&width='.$previewwidthdetail, 'length'=>$previewer->getFileSize($version), 'type'=>'image/png'));
|
||||
}
|
||||
$feed->addItem($newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// OK. Everything is done. Now generate the feed.
|
||||
// If you want to send the feed directly to the browser, use the printFeed() method.
|
||||
$myFeed = $feed->generateFeed();
|
||||
// Do anything you want with the feed in $myFeed. Why not send it to the browser? ;-)
|
||||
// You could also save it to a file if you don't want to invoke your script every time.
|
||||
header('Content-Type: application/rss+xml');
|
||||
echo $myFeed;
|
||||
} /* }}} */
|
||||
}
|
Loading…
Reference in New Issue
Block a user