Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lib
unicaen
ksup
Commits
b113a6a1
Commit
b113a6a1
authored
Nov 15, 2016
by
Laurent Lécluse
Browse files
Module UnicaenKsup opérationnel
parent
ca62b978
Changes
11
Hide whitespace changes
Inline
Side-by-side
Module.php
View file @
b113a6a1
...
...
@@ -2,8 +2,8 @@
namespace
UnicaenKsup
;
use
Zend\ModuleManager\Feature\AutoloaderProviderInterface
;
use
Zend\ModuleManager\Feature\ConfigProviderInterface
;
use
Zend\Mvc\MvcEvent
;
/**
...
...
@@ -11,32 +11,32 @@ use Zend\Mvc\MvcEvent;
*
* @author Laurent LECLUSE <laurent.lecluse at unicaen.fr>
*/
class
Module
implements
ConfigProviderInterface
class
Module
implements
AutoloaderProviderInterface
,
ConfigProviderInterface
{
public
function
onBootstrap
(
MvcEvent
$e
)
/**
*
* @return array
* @see AutoloaderProviderInterface
*/
public
function
getAutoloaderConfig
()
{
/* define("KPHPLIB_PATH", __DIR__ . "vendor/ksup_connecteur_php-5.1/kphplib5/");
// chemins des librairies
define("KPHPLIB_PATH_CLASSE", KPHPLIB_PATH . "classe/");
define("KPHPLIB_PATH_CLASSE_DATA", KPHPLIB_PATH . "classe/data/");
define("KPHPLIB_PATH_CLASSE_SSO", KPHPLIB_PATH . "classe/sso/");
define("KPHPLIB_PATH_CLASSE_UTIL_XML", KPHPLIB_PATH . "classe/util/xml/");
define("KPHPLIB_PATH_CLASSE_UTIL_HTTP", KPHPLIB_PATH . "classe/util/http/");
define("KPHPLIB_PATH_INCLUDE", KPHPLIB_PATH . "include/");*/
return
[
'Zend\Loader\ClassMapAutoloader'
=>
[
__DIR__
.
'/autoload_classmap.php'
,
],
'Zend\Loader\StandardAutoloader'
=>
[
'namespaces'
=>
[
__NAMESPACE__
=>
__DIR__
.
'/src/'
.
__NAMESPACE__
,
],
],
];
}
public
function
getConfig
()
{
$config
=
include
__DIR__
.
'/config/module.config.php'
;
/*$ksup = $config['unicaen-ksup'];
define("SSO_URL_SERVER", $ksup['sso_url_server']);
define("SSO_HOST_SERVER", $ksup['sso_host_server']);
define("SSO_PORT_SERVER", $ksup['sso_port_server']);*/
return
$config
;
return
include
__DIR__
.
'/config/module.config.php'
;
}
}
\ No newline at end of file
config/module.config.php
View file @
b113a6a1
...
...
@@ -3,27 +3,22 @@ namespace UnicaenKsup;
return
[
'unicaen-ksup'
=>
[
'sso_url_server'
=>
'http://www.unicaen.fr'
,
'sso_host_server'
=>
'www.unicaen.fr'
,
'sso_port_server'
=>
'80'
,
'connecteur_path'
=>
__DIR__
.
'/../vendor/ksup_connecteur_php-5.1/kphplib5/'
,
'remplacement'
=>
[
'charset=iso-8859-1'
=>
'charset=utf-8'
],
],
'view_manager'
=>
[
// TemplateMapResolver configuration
// template/path pairs
'template_map'
=>
[
'layout/ksup'
=>
__DIR__
.
'/../view/layout/ksup.phtml'
,
],
// TemplatePathStack configuration
'template_path_stack'
=>
[
'ksup'
=>
__DIR__
.
'/../view'
,
'strategies'
=>
[
'ViewKsupStrategy'
,
// register ksup strategy
],
// Layout template name
'layout'
=>
'layout/layout'
,
// e.g., 'layout/layout'
// Additional strategies to attach
'strategies'
=>
[
//'ViewKsupStrategy', // register JSON renderer strategy
],
'service_manager'
=>
[
'factories'
=>
[
'ViewKsupStrategy'
=>
Mvc\Service\ViewKsupStrategyFactory
::
class
,
'ksup'
=>
Service\KsupServiceFactory
::
class
,
],
],
];
\ No newline at end of file
config/unicaen-ksup.global.php.dist
View file @
b113a6a1
<?php
namespace
UnicaenKsup
;
return
[
'unicaen-ksup'
=>
[
$config
=
[
'sso_url_server'
=>
'http://www.unicaen.fr'
,
'sso_host_server'
=>
'www.unicaen.fr'
,
'sso_port_server'
=>
'80'
,
'langue'
=>
'fr'
,
'https'
=>
false
,
'remplacement'
=>
[
// sert à remplacer un texte par un autre dans le code KSUP de la page
// format ancien texte => nouveau texte
'"/images/'
=>
'"http://www.unicaen.fr/images/'
],
'scripts'
=>
[
// placez ici les URL de vos scripts JS souhaités
],
'links'
=>
[
// placez ici les URL de vos feuilles de style souhaitées
],
];
return
[
'unicaen-ksup'
=>
$config
,
];
\ No newline at end of file
config/unicaen-ksup.local.php.dist
View file @
b113a6a1
<?php
namespace
UnicaenKsup
;
return
[
'unicaen-ksup'
=>
[
],
$config
=
[
];
return
[
'unicaen-ksup'
=>
$config
,
];
\ No newline at end of file
src/UnicaenKsup/Mvc/Service/ViewKsupStrategyFactory.php
0 → 100644
View file @
b113a6a1
<?php
namespace
UnicaenKsup\Mvc\Service
;
use
Application\View\Renderer\PhpRenderer
;
use
UnicaenKsup\Service\KsupService
;
use
Zend\ServiceManager\FactoryInterface
;
use
Zend\ServiceManager\ServiceLocatorInterface
;
use
UnicaenKsup\View\Strategy\KsupStrategy
;
class
ViewKsupStrategyFactory
implements
FactoryInterface
{
public
function
createService
(
ServiceLocatorInterface
$serviceLocator
)
{
/** @var PhpRenderer $renderer */
$renderer
=
$serviceLocator
->
get
(
'ViewRenderer'
);
/** @var KsupService $service */
$service
=
$serviceLocator
->
get
(
'ksup'
);
$strategy
=
new
KsupStrategy
(
$renderer
);
$strategy
->
setServiceKsup
(
$service
);
return
$strategy
;
}
}
src/UnicaenKsup/Service/KsupService.php
0 → 100644
View file @
b113a6a1
<?php
namespace
UnicaenKsup\Service
;
use
UnicaenKsup\View\Model\KsupModel
;
use
Zend\View\Helper\BasePath
;
class
KsupService
{
/**
* @var KsupModel
*/
protected
$model
;
/**
* @var array
*/
protected
$config
;
/**
* @var BasePath
*/
private
$basePath
;
/**
* @return KsupModel
*/
public
function
getModel
()
{
return
$this
->
model
;
}
/**
* @param KsupModel $model
*
* @return KsupService
*/
public
function
setModel
(
$model
)
{
$this
->
model
=
$model
;
return
$this
;
}
/**
* @return BasePath
*/
public
function
getBasePath
()
{
return
$this
->
basePath
;
}
/**
* @param BasePath $basePath
*
* @return KsupService
*/
public
function
setBasePath
(
$basePath
)
{
$this
->
basePath
=
$basePath
;
return
$this
;
}
protected
function
initVars
()
{
/* Initialisation des variables globales à donner au connecteur KSup */
define
(
"KPHPLIB_PATH"
,
$this
->
getConfig
(
'connecteur_path'
));
define
(
"KPHPLIB_PATH_CLASSE"
,
KPHPLIB_PATH
.
"classe/"
);
define
(
"KPHPLIB_PATH_CLASSE_DATA"
,
KPHPLIB_PATH
.
"classe/data/"
);
define
(
"KPHPLIB_PATH_CLASSE_SSO"
,
KPHPLIB_PATH
.
"classe/sso/"
);
define
(
"KPHPLIB_PATH_CLASSE_UTIL_XML"
,
KPHPLIB_PATH
.
"classe/util/xml/"
);
define
(
"KPHPLIB_PATH_CLASSE_UTIL_HTTP"
,
KPHPLIB_PATH
.
"classe/util/http/"
);
define
(
"KPHPLIB_PATH_INCLUDE"
,
KPHPLIB_PATH
.
"include/"
);
include_once
(
KPHPLIB_PATH_INCLUDE
.
"params.php"
);
define
(
"SSO_URL_SERVER"
,
$this
->
getConfig
(
'sso_url_server'
));
define
(
"SSO_HOST_SERVER"
,
$this
->
getConfig
(
'sso_host_server'
));
define
(
"SSO_PORT_SERVER"
,
$this
->
getConfig
(
'sso_port_server'
));
return
$this
;
}
/**
* @return \requete
*/
protected
function
getRequete
()
{
global
$GLOBALS
;
if
(
!
isset
(
$GLOBALS
[
"objRequete"
]))
{
$GLOBALS
[
"objRequete"
]
=
new
\
requete
(
$this
->
getModel
()
->
getRubrique
(),
$this
->
getModel
()
->
getStructure
());
if
(
$langue
=
$this
->
getConfig
(
'langue'
))
$GLOBALS
[
"objRequete"
]
->
setLangue
(
$langue
);
if
(
$secure
=
$this
->
getConfig
(
'https'
))
$GLOBALS
[
"objRequete"
]
->
setSecure
(
$secure
);
}
return
$GLOBALS
[
"objRequete"
];
}
protected
function
traiterEncadres
()
{
$encadres
=
$this
->
getModel
()
->
getEncadres
();
foreach
(
$encadres
as
$titre
=>
$contenu
)
{
$this
->
getRequete
()
->
addEncadre
(
new
\
encadre
(
$titre
,
$contenu
));
}
return
$this
;
}
public
function
traiterDonneesSpecifiques
()
{
$dsCode
=
''
;
$links
=
$this
->
getConfig
(
'links'
);
if
(
$links
)
foreach
(
$links
as
$link
){
$dsCode
.
=
'<link href="'
.
$this
->
makeAbsUrl
(
$link
)
.
'" media="all" rel="stylesheet" type="text/css">'
.
"
\r\n
"
;
}
$dsCode
.
=
trim
(
$this
->
getModel
()
->
getLinks
()
->
toString
(
4
));
$scripts
=
$this
->
getConfig
(
'scripts'
);
if
(
$scripts
)
foreach
(
$scripts
as
$script
){
$dsCode
.
=
'<script type="text/javascript" src="'
.
$this
->
makeAbsUrl
(
$script
)
.
'">'
.
"
\r\n
"
;
}
$dsCode
.
=
trim
(
$this
->
getModel
()
->
getScripts
()
->
toString
(
4
));
// if ($dsCode) {
// $ds = new \donnesSpecifiques("INCLUDE_HEAD", $dsCode);
// $this->getRequete()->addDonneesSpecifiques($ds);
// }
return
$dsCode
;
}
private
function
makeAbsUrl
(
$url
)
{
if
(
0
!==
strpos
(
$url
,
'//'
)
&&
0
!==
strpos
(
$url
,
'http://'
)
&&
0
!==
strpos
(
$url
,
'https://'
))
{
$url
=
$this
->
basePath
->
__invoke
(
$url
);
}
return
$url
;
}
protected
function
lireTemplate
(
$template
)
{
$patterns
=
$this
->
getConfig
(
'remplacement'
);
ob_start
();
\
connecteurMgr
::
lireTemplate
(
$template
);
$res
=
ob_get_contents
();
ob_end_clean
();
foreach
(
$patterns
as
$old
=>
$new
)
{
$res
=
str_replace
(
$old
,
$new
,
$res
);
}
$res
=
trim
(
utf8_encode
(
$res
));
return
$res
;
}
public
function
render
(
$content
)
{
if
(
!
$this
->
getModel
())
{
throw
new
\
Exception
(
'Pas de modèle transmis!!'
);
}
$this
->
initVars
();
/* Contrôle de session! */
$bean
=
new
\
sso
();
if
(
array_key_exists
(
"kticket"
,
$_GET
)
&&
$_SESSION
[
"KSESSION"
]
==
""
)
{
\
connecteurMgr
::
validerTicket
(
$bean
);
}
else
{
\
connecteurMgr
::
verifierSession
(
$bean
);
}
$this
->
traiterEncadres
();
//$this->traiterDonneesSpecifiques(); // ne fonctionne pas avec KSUP!!
$haut
=
$this
->
lireTemplate
(
'haut'
);
$bodyPos
=
strpos
(
$haut
,
'<body'
);
$insert
=
$this
->
traiterDonneesSpecifiques
()
.
'</head>'
.
"
\r\n
"
;
$haut
=
substr
(
$haut
,
0
,
$bodyPos
)
.
$insert
.
substr
(
$haut
,
$bodyPos
);
$bas
=
$this
->
lireTemplate
(
'bas'
);
return
$haut
.
$content
.
$bas
;
}
public
function
getConfig
(
$key
=
null
)
{
$config
=
$this
->
config
;
if
(
$key
)
{
$key
=
explode
(
'/'
,
$key
);
foreach
(
$key
as
$k
)
{
if
(
isset
(
$config
[
$k
]))
{
$config
=
$config
[
$k
];
}
else
{
return
null
;
}
}
}
return
$config
;
}
public
function
setConfig
(
array
$config
)
{
$this
->
config
=
$config
;
}
}
\ No newline at end of file
src/UnicaenKsup/Service/KsupServiceFactory.php
0 → 100644
View file @
b113a6a1
<?php
namespace
UnicaenKsup\Service
;
use
Zend\ServiceManager\FactoryInterface
;
use
Zend\ServiceManager\ServiceLocatorInterface
;
use
Zend\View\Helper\BasePath
;
class
KsupServiceFactory
implements
FactoryInterface
{
public
function
createService
(
ServiceLocatorInterface
$serviceLocator
)
{
$service
=
new
KsupService
();
$config
=
$serviceLocator
->
get
(
'config'
);
if
(
isset
(
$config
[
'unicaen-ksup'
])){
$config
=
$config
[
'unicaen-ksup'
];
}
else
{
$config
=
[];
}
$service
->
setConfig
(
$config
);
/** @var BasePath $basePath */
$basePath
=
$serviceLocator
->
get
(
'viewHelperManager'
)
->
get
(
'basePath'
);
$service
->
setBasePath
(
$basePath
);
return
$service
;
}
}
src/UnicaenKsup/Service/Traits/KsupServiceAwareTrait.php
0 → 100755
View file @
b113a6a1
<?php
namespace
UnicaenKsup\Service\Traits
;
use
UnicaenKsup\Service\KsupService
;
use
RuntimeException
;
/**
* Description of KsupServiceAwareTrait
*
* @author UnicaenCode
*/
trait
KsupServiceAwareTrait
{
/**
* @var KsupService
*/
private
$serviceKsup
;
/**
* @param KsupService $serviceKsup
* @return self
*/
public
function
setServiceKsup
(
KsupService
$serviceKsup
)
{
$this
->
serviceKsup
=
$serviceKsup
;
return
$this
;
}
/**
* @return KsupService
* @throws RuntimeException
*/
public
function
getServiceKsup
()
{
if
(
empty
(
$this
->
serviceKsup
)){
if
(
!
method_exists
(
$this
,
'getServiceLocator'
))
{
throw
new
RuntimeException
(
'La classe '
.
get_class
(
$this
)
.
' n\'a pas accès au ServiceLocator.'
);
}
$serviceLocator
=
$this
->
getServiceLocator
();
if
(
method_exists
(
$serviceLocator
,
'getServiceLocator'
))
{
$serviceLocator
=
$serviceLocator
->
getServiceLocator
();
}
$this
->
serviceKsup
=
$serviceLocator
->
get
(
'ksup'
);
}
return
$this
->
serviceKsup
;
}
}
\ No newline at end of file
src/UnicaenKsup/View/Model/KsupModel.php
0 → 100644
View file @
b113a6a1
<?php
namespace
UnicaenKsup\View\Model
;
use
Zend\View\Helper\HeadLink
;
use
Zend\View\Model\ViewModel
;
use
Zend\View\Helper\HeadScript
;
class
KsupModel
extends
ViewModel
{
/**
* @var string
*/
protected
$rubrique
=
''
;
/**
* @var string
*/
protected
$structure
=
''
;
/**
* @var array
*/
protected
$encadres
=
[];
/**
* @var HeadScript
*/
protected
$scripts
;
/**
* @var HeadStyle
*/
protected
$links
;
/**
* Is this a standalone, or terminal, model?
*
* @var bool
*/
protected
$terminate
=
true
;
public
function
__construct
()
{
$this
->
scripts
=
new
HeadScript
();
$this
->
links
=
new
HeadLink
();
}
/**
* @return string
*/
public
function
getRubrique
()
{
return
$this
->
rubrique
;
}
/**
* @param string $rubrique
*
* @return KsupModel
*/
public
function
setRubrique
(
$rubrique
)
{
$this
->
rubrique
=
$rubrique
;
return
$this
;
}
/**
* @return string
*/
public
function
getStructure
()
{
return
$this
->
structure
;
}
/**
* @param string $structure
*
* @return KsupModel
*/
public
function
setStructure
(
$structure
)
{
$this
->
structure
=
$structure
;
return
$this
;
}
/**
* @param string $titre
* @param string $contenu
*
* @return $this
*/
public
function
addEncadre
(
$titre
,
$contenu
)
{
if
(
$contenu
)
{
$this
->
encadres
[
$titre
]
=
$contenu
;
}
else
{
unset
(
$this
->
encadres
[
$titre
]);
}
return
$this
;