Commit cdd76253 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

Merge branch 'dev#72845_bdp_yonne_evolution_connecteur_cvs' into 'master'

Dev#72845 bdp yonne evolution connecteur cvs

See merge request afi/opacce!2661
parents e68c0e9f 774fd7c7
......@@ -3,7 +3,7 @@ RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(google[a-z0-9]+\.html|xhprof_html|ckeditor|exploit|\.well-known)
RewriteCond %{REQUEST_FILENAME} !^.*/robots\.txt$ [NC]
RewriteRule !(userfiles|public|tmp|temp|skins)/.*\.(js|ico|txt|gif|jpg|jpeg|png|css|xml|swf|mov|pdf|doc|docx|woff|woff2|eot|svg|ttf|xls|wsdl|mp3|m4v|ogg|ogv|epub|html|xhtml|asmx|zip|sql|bro|flv|mp4|webm|tgz|json|geojson|xsl)$ index.php [NC,NE]
RewriteRule !(userfiles|public|tmp|temp|skins|library/digital_resources/.*/js)/.*\.(js|ico|txt|gif|jpg|jpeg|png|css|xml|swf|mov|pdf|doc|docx|woff|woff2|eot|svg|ttf|xls|wsdl|mp3|m4v|ogg|ogv|epub|html|xhtml|asmx|zip|sql|bro|flv|mp4|webm|tgz|json|geojson|xsl)$ index.php [NC,NE]
AddType application/x-javascript .js
AddType text/css .css
......
- ticket #72845 : Ressources numériques : la configuration du connecteur CVS permet à un utilisateur anonyme d'accéder à la ressource sur la plateforme.
\ No newline at end of file
......@@ -49,13 +49,6 @@ class ModulesController extends ZendAfi_Controller_Action {
}
public function cvsAction() {
$cvs = new Class_Systeme_ModulesMenu_CVS();
$cvs->setDocId($this->_getParam('docid'));
$this->simple($cvs);
}
public function numeriquepremiumAction() {
$url = $this->_getParam('url');
$this->checkNotifyMessage((new Class_Entity)->setMessage($this->_('Le service est mal configuré. Il manque l\'URL du service.')), $url);
......
......@@ -454,64 +454,6 @@ class NoticeAjaxController extends Zend_Controller_Action {
}
function cvsSearchAction() {
if ((new Class_UserAgent())->isBot())
return $this->_sendResponse('');
$this->preferences = Class_Profil::getCurrentProfil()->getCfgModulesPreferences('recherche',
'resultat',
'simple');
$current_module = $this->_getParam("current_module");
$preferences = $current_module["preferences"];
$user = Class_Users::getLoader()->getIdentity();
if (!(new Class_AdminVar_CVS())->isCVSAccessOrDemo($user)) {
$html = "Vous devez vous connecter pour voir les résultats";
return $this->_sendResponse($html);
}
$criteres_recherche = new Class_CriteresRecherche();
$criteres_recherche->setParams($this->_request->getParams());
$query=$this->view->tagCVSCriteresRecherche($criteres_recherche);
$cvs = Class_CVSLink::forUser($user);
$notices = $cvs->searchNotices($query,$criteres_recherche->getPage(),$this->preferences['cvs_nb_result']);
$nb_total_cvs_records = $cvs->getTotalNotices();
$helper = $this->view->getHelper('ListeCVSNotices');
$html = "<script>";
if ($nb_total_cvs_records)
$html .= "$('.cvs_container:hidden').slideDown('slow');";
$html .= "$(document).ready(function(){
$('#cvs_result .pager a').click(function(e){
e.preventDefault();
var url = $(this).attr('href');
$('#cvs_result').load(url);
return false;
});
$('a[href*=\"modules/cvs\"]').attr('target', '_blank');
});</script><div id='cvs_result'>";
$html .= $helper->listeCVSNotices($notices,
$nb_total_cvs_records,
$criteres_recherche->getPage(),
$this->preferences);
$html .= $this->view->pager($nb_total_cvs_records,
$this->preferences['cvs_nb_result'],
$criteres_recherche->getPage(),
$this->view->url(['controller' => 'noticeajax',
'action' => 'cvs-search']));
$html .= '</div>';
$this->_sendResponseWithScripts($html);
}
public function frbrAction() {
$id = str_replace('N', '', $this->_getParam('id_notice'));
......
<?php
echo $this->render($this->actionScript);
?>
\ No newline at end of file
echo $this->render($this->actionScript);
?>
<?php
(new Class_Migration_DigitalResource_CVS)->run();
\ No newline at end of file
......@@ -155,14 +155,6 @@ class Class_AdminVarLoader extends Storm_Model_Loader {
'BIBNUM' => Class_AdminVar_Meta::newOnOff($this->_('Activer ou désactiver la bibliothèque numérique'))->bePrivate(),
'SITO_IN_ALBUMS' => Class_AdminVar_Meta::newOnOff($this->_('Gérer la sitothèque dans la bibliothèque numérique, nécessite l\'activation de la bibliothèque numérique'))->bePrivate(),
'CVS_BMKEY' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage CVS'))->bePrivate(),
'CVS_BMID' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage CVS'))->bePrivate(),
'CVS_BMLABEL' => Class_AdminVar_Meta::newDefault($this->_('Libellé de regroupement des abonnés'))->bePrivate(),
'CVS_SOURCENAME' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage CVS'))->bePrivate(),
'CVS_SOURCEID' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage CVS'))->bePrivate(),
'CVS_SOURCEKEY' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage CVS'))->bePrivate(),
'CVS_SOURCEPASSWORD' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage CVS'))->bePrivate(),
'CVS_LOGINTEST' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage CVS'))->bePrivate(),
'NUMILOG_URL' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage <a href="http://forge.afi-sa.fr/projects/opac3/wiki/Ressources_externes_enrichissements#Numilog">Numilog</a>'))->bePrivate(),
'NUMILOG_OAI_URL' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage <a href="http://forge.afi-sa.fr/projects/opac3/wiki/Ressources_externes_enrichissements#Numilog">Numilog</a>'))->bePrivate(),
'NUMILOG_OAI_IDBIB' => Class_AdminVar_Meta::newDefault($this->_('Paramétrage <a href="http://forge.afi-sa.fr/projects/opac3/wiki/Ressources_externes_enrichissements#Numilog">Numilog</a>'))->bePrivate(),
......@@ -689,17 +681,6 @@ class Class_AdminVarLoader extends Storm_Model_Loader {
}
/**
* @return bool
*/
public function isCVSEnabled() {
return (('' != Class_AdminVar::get('CVS_BMKEY')) && ('' != Class_AdminVar::get('CVS_BMID')) &&
('' != Class_AdminVar::get('CVS_SOURCEPASSWORD')) && ('' != Class_AdminVar::get('CVS_SOURCEKEY')) &&
('' != Class_AdminVar::get('CVS_SOURCEID')) && ('' != Class_AdminVar::get('CVS_SOURCENAME'))
);
}
/**
* @return bool
*/
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_CVSLink {
use Trait_TimeSource;
const CVS_SOURCEXPIRATIONTIME = 30;
protected $_user;
protected $loginTest;
public static function forUser($user) {
return new self($user);
}
public function __construct($user) {
$this->_user = $user;
}
public static function staticLink() {
return ['controller' => 'modules', 'action' => 'cvs'];
}
public function baseUrl() {
return 'http://stream.cvs-mediatheques.com/api/partners.php';
}
public function setConfig() {
$this->bmkey = Class_AdminVar::get('CVS_BMKEY');
$this->bmid = Class_AdminVar::get('CVS_BMID');
$this->sourceName = Class_AdminVar::get('CVS_SOURCENAME');
$this->sourceId = Class_AdminVar::get('CVS_SOURCEID');
$this->sourceKey = Class_AdminVar::get('CVS_SOURCEKEY');
$this->sourcePassword = Class_AdminVar::get('CVS_SOURCEPASSWORD');
$this->loginTest = Class_AdminVar::get('CVS_LOGINTEST');
}
public function url() {
$this->setConfig();
return $this->getCvsLnk('');
}
public function searchNotices($query, $page=1, $nb_par_page=5) {
$this->setConfig();
return $this->getCvsSearchNotices($query,$page,$nb_par_page);
}
public function formatXML($xml) {
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
$dom->loadXML($xml);
$dom->formatOutput = true;
return $dom->saveXml();
}
public function callCVS($action, $body = [], &$infos){
$user = $this->_user
? $this->_user :
Class_Users::newInstance(['login' => $this->loginTest]);
$time = $this->getCurrentTime();
$xml_user_infos = $this->_getUserInfos($user);
$loginCVS = $this->_getLogin($user);
$key = md5($loginCVS
. $this->bmid
. $this->bmkey
. $this->sourceName
. $this->sourceId
. $this->sourceKey
. $this->sourcePassword
. $time . static::CVS_SOURCEXPIRATIONTIME);
// construction du XML
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<albums>
<header>
<bmid>".$this->bmid."</bmid>
<sourceid>".$this->sourceId."</sourceid>
<key>{$key}</key>
<time>{$time}</time>
<adhid>".$loginCVS.
"</adhid>
<action>{$action}</action>
</header>
<body>";
if($action == "acces_site"){
$xml .= "
<querystring><![CDATA[".urldecode($body['querystring'])."]]></querystring>
<affichage>{$body['affichage']}</affichage>
";
} elseif($action == "search_document"){
$xml .= "
<q><![CDATA[".$body['q']."]]></q>
<espace><![CDATA[".$body['espace']."]]></espace>
<classement><![CDATA[".$body['classement']."]]></classement>
<page><![CDATA[".$body['page']."]]></page>
<nombre_par_page><![CDATA[".$body['nombre_par_page']."]]></nombre_par_page>
";
}
$xml .= "$xml_user_infos</body></albums>";
$xml = base64_encode($this->formatXML($xml));
$xml = strtr($xml,'+/','-_');
// envoi du XML à cvs
$this->parser = new Class_WebService_BibNumerique_CVS_AlbumParser();
try {
$ret = Class_WebService_Abstract::getHttpClient()
->postData($this->baseUrl(), ['xml' => $xml]);
} catch(Zend_Http_Client_Adapter_Exception $e) {
return $this->parser;
}
$this->parser->parseXML($ret);
return $this->parser;
}
protected function _getUserInfos($user) {
$user_infos = ['login' => $user->getLogin(),
'nom' => $user->getNom(),
'prenom' => $user->getPrenom(),
'pseudo' => $user->getPseudo(),
'password' => $user->getPassword(),
'email' => $user->getMail(),
'dnaiss' => (($naissance = $user->getNaissance())
? implode('-', array_reverse(explode('/', $naissance)))
: ''),
'datout' => (($finabo = $user->getDateFin())
? implode('-', array_reverse(explode('/', $finabo)))
: ''),
'bibliotheque' => (($label = Class_AdminVar::get('CVS_BMLABEL'))
? $label : $user->getLibelleBib())];
$user_infos = array_filter($user_infos);
$xml_user_infos = '';
foreach($user_infos as $k => $v)
$xml_user_infos .= '<' . $k . '>' .
preg_replace('#&(?![a-z]{1,6};)#i', '&amp;',$v).
'</' . $k . '>';
return $xml_user_infos;
}
protected function _getLogin($user) {
return $user->getIdabon()
? $user->getIdabon() : $user->getLogin();
}
// retourne le lien chrono-dégradable vers un espace souhaité ($lnk)
public function getCvsLnk($lnk) {
$this->parser = $this->callCVS('acces_site',
['querystring' => $lnk,
'affichage' => 'complet'],
$infos);
if ($this->parser->isSuccess())
return $this->parser->getUrl();
$this->setMessage("Merci de contacter la médiathèque pour obtenir un accès.");
return '';
}
public function getCvsSearchNotices($query, $page, $nb_par_page){
$this->parser = $this->callCVS('search_document',
['q' => $query,
'espace'=> '',
'classement' =>
'consultes',
'page' => $page,
'nombre_par_page' => $nb_par_page],
$infos);
return $this->parser->isSuccess()
? $this->parser->getNotices() : [];
}
public function getTotalNotices() {
return $this->parser->getTotalNotices();
}
}
\ No newline at end of file
......@@ -76,6 +76,18 @@ class Class_DigitalResource extends Class_Entity {
}
public function addFormElementsIn($form) {
$this->getPlugins()
->eachDo(
function($config) use ($form)
{
return $config->addFormElementsIn($form);
}
);
return $form;
}
public function getPluginsSSOActions() {
return $this->getPlugins()
->collect(
......@@ -173,15 +185,19 @@ class Class_DigitalResource extends Class_Entity {
if (!$this->isPluginDocType($type = $album->getTypeDocId()))
return '';
if (is_readable($this->getBaseDir() . '/' . $type . '/View/Helper/Album.php')) {
$class_name = $type . '_View_Helper_Album';
$helper = $this->build($class_name, $this->configFor($type))
->setView($view);
return ($helper = $this->viewHelperFor($type, 'Album', $view))
? $helper->album($album)
: '';
}
return $helper->album($album);
}
public function viewHelperFor($type, $helper, $view) {
if (!is_readable($this->getBaseDir() . '/' . $type . '/View/Helper/' . $helper . '.php'))
return;
return '';
$class_name = $type . '_View_Helper_' . $helper;
return $this->build($class_name, $this->configFor($type))
->setView($view);
}
......
......@@ -197,7 +197,7 @@ class Class_DigitalResource_Config extends Class_Entity {
}
public function urlFor($user, $album = null, $record = null) {
public function urlFor($user, $params = []) {
if(!$user)
return;
......@@ -207,16 +207,30 @@ class Class_DigitalResource_Config extends Class_Entity {
if(!$this->isEnabled())
return;
if($record)
if($record = $this->_recordFromParams($params))
return $this->getRecordSsoUrl($user, $record);
if($album)
if($album = $this->_albumFromParams($params))
return $this->getAlbumSsoUrl($user, $album);
return $this->getSsoUrl($user);
}
protected function _recordFromParams($params) {
return array_key_exists('id', $params)
? Class_Notice::find($params['id'])
: null;
}
protected function _albumFromParams($params) {
return array_key_exists('album_id', $params)
? Class_Album::find($params['album_id'])
: null;
}
public function getSsoUrl($user) {
return '';
}
......@@ -247,8 +261,17 @@ class Class_DigitalResource_Config extends Class_Entity {
public function renderHarvestDiagOn($view) {
return $view->tag('p',
$this->_('Cette ressource ne prend pas en charge l\'affichage du l\'url de moissonnage'), ['class' => 'error']);
return $view->tagInfo($this->_('Cette ressource ne prend pas en charge l\'affichage du l\'url de moissonnage'));
}
public function renderCustomDiagOn($view) {
return '';
}
public function renderSSODiagOn($view) {
return '';
}
......@@ -263,7 +286,8 @@ class Class_DigitalResource_Config extends Class_Entity {
$group = $this->getTestGroup();
$group->addUser($user)->save();
return $user;
Class_Users::clearCache();
return Class_Users::find($user->getId());
}
......@@ -280,6 +304,31 @@ class Class_DigitalResource_Config extends Class_Entity {
$permission->permitTo($group, new Class_Entity());
return $group;
Class_UserGroup::clearCache();
return Class_UserGroup::find($group->getId());
}
public function addFormElementsIn($form) {
return $this;
}
public function getSearchUrlForRecord($record) {
return [];
}
public function getPermittedGroups() {
$groups = new Storm_Collection(Class_UserGroup::findAll());
return array_filter(
$groups
->select(function ($group)
{
$permission = $this->getPermission();
return $group->hasPermissionOn($permission, $this);
})
->getArrayCopy());
}
}
\ No newline at end of file
......@@ -50,11 +50,9 @@ class Class_DigitalResource_Controller extends ZendAfi_Controller_Action {
public function ssoAction() {
if(!$user = Class_Users::getIdentity())
return $this->_afterLoginRedirectTo($this->view->absoluteUrl(),
$this->_('Vous devez vous connecter pour accéder à cette page'));
$this->_('Vous devez vous connecter pour accéder à cette page'));
$url = $this->_config->urlFor($user,
Class_Album::find($this->_getParam('album_id', 0)),
Class_Notice::find($this->_getParam('id', 0)));
$url = $this->_config->urlFor($user, $this->_request->getParams());
return $url
? $this->_javascriptRedirectTo($url)
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
......@@ -19,49 +19,37 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Systeme_ModulesMenu_CVS extends Class_Systeme_ModulesMenu_SSOAbstract {
protected
$_group = Class_Systeme_ModulesMenu::GROUP_MENU_ABONNES,
$_type_module = 'CVS',
$_doc_id = null;
class Class_Migration_DigitalResource_CVS extends Class_Migration_DigitalResource_Abstract {
public function __construct() {
parent::__construct();
$this->_libelle = $this->_('Lien vers CVS');
$this->_url = Class_CVSLink::staticLink();
protected function _getOldRightToken() {
return 4;
}
public function getCVSUrlForUser($user) {
if (!(new Class_AdminVar_CVS())->isCVSAccessOrDemo($user))
return '';
$cvs_link = Class_CVSLink::forUser($user);
$url = $cvs_link->url();
if (!strlen($url)>0)
$this->setMessage($cvs_link->getMessage());
return $url;
protected function _getAdminVarMapping() {
return ['CVS_BMKEY' => 'Cvs_BMKEY',
'CVS_BMID' => 'Cvs_BMID',
'CVS_SOURCENAME' => 'Cvs_SOURCENAME',
'CVS_SOURCEID' => 'Cvs_SOURCEID',
'CVS_SOURCEPASSWORD' => 'Cvs_SOURCEPASSWORD',
'CVS_SOURCEKEY' => 'Cvs_SOURCEKEY',
'CVS_BMLABEL' => 'Cvs_BMLABEL',
'CVS_LOGINTEST' => 'Cvs_LOGINTEST'];
}
public function setDocId($doc_id) {
$this->_doc_id = $doc_id;
return $this;
protected function _getConfig() {
return Cvs_Config::getInstance();
}
public function urlForUser($user) {
$url = $this->getCVSUrlForUser($user);
if ($url && (strlen($this->_doc_id)>0))
$url.='#album&docid='.$this->_doc_id;
return $url;
protected function _getOldMenuName() {
return 'CVS';
}
public function isVisibleForProfil($profil) {
return Class_AdminVar::isCVSEnabled();
protected function _getOldBatchName() {
return '';
}
}
\ No newline at end of file