Merge branch 'master' into permissions

This commit is contained in:
Paolo
2018-06-28 14:52:09 +02:00
72 changed files with 655 additions and 381 deletions
+9 -10
View File
@@ -27,6 +27,8 @@ require_once FHCPATH.'include/authentication.class.php';
class AuthLib extends authentication
{
private $_ci; // CI instance
/**
* Construct
*/
@@ -35,10 +37,7 @@ class AuthLib extends authentication
parent::__construct();
// Gets CI instance
$this->ci =& get_instance();
// Loads helper message to manage returning messages
$this->ci->load->helper('Message');
$this->_ci =& get_instance();
}
/**
@@ -83,9 +82,9 @@ class AuthLib extends authentication
$result = error(false);
// Load model PersonModel
$this->ci->load->model('person/person_model', 'PersonModel');
$this->_ci->load->model('person/person_model', 'PersonModel');
$person = $this->ci->PersonModel->loadWhere(array('zugangscode' => $code));
$person = $this->_ci->PersonModel->loadWhere(array('zugangscode' => $code));
if (hasData($person))
{
@@ -103,9 +102,9 @@ class AuthLib extends authentication
$result = error(false);
// Load model PersonModel
$this->ci->load->model('person/person_model', 'PersonModel');
$this->_ci->load->model('person/person_model', 'PersonModel');
$person = $this->ci->PersonModel->getPersonKontaktByZugangscode($code, $email);
$person = $this->_ci->PersonModel->getPersonKontaktByZugangscode($code, $email);
if (hasData($person))
{
@@ -124,9 +123,9 @@ class AuthLib extends authentication
$finalUserBasicDataByUID = null;
// Load model BenutzerModel
$this->ci->load->model('person/Benutzer_model', 'BenutzerModel');
$this->_ci->load->model('person/Benutzer_model', 'BenutzerModel');
$benutzer = $this->ci->BenutzerModel->load($uid);
$benutzer = $this->_ci->BenutzerModel->load($uid);
if (hasData($benutzer))
{
-3
View File
@@ -33,9 +33,6 @@ class CallerLib
// Gets CI instance
$this->ci =& get_instance();
// Loads helper message to manage returning messages
$this->ci->load->helper('Message');
// Loads permission library
$this->ci->load->library('PermissionLib');
}
-3
View File
@@ -17,9 +17,6 @@ class DmsLib
$this->ci->load->model('content/Dms_model', 'DmsModel');
$this->ci->load->model('content/DmsVersion_model', 'DmsVersionModel');
$this->ci->load->model('content/DmsFS_model', 'DmsFSModel');
// Loads helper message to manage returning messages
$this->ci->load->helper('message');
}
/**
+1 -1
View File
@@ -733,7 +733,7 @@ class ExtensionsLib
);
if (!$_addSoftLinks)
{
log_message('error','Failed to create Symlink to '.$extensionPath.$targetDirectory);
log_message('error', 'Failed to create Symlink to '.$extensionPath.$targetDirectory);
break;
}
}
+12 -23
View File
@@ -86,11 +86,6 @@ class FiltersLib
{
$this->_ci =& get_instance(); // get code igniter instance
// Loads helper message to manage returning messages
$this->_ci->load->helper('message');
// Loads helper session to manage the php session
$this->_ci->load->helper('session');
$this->_filterUniqueId = $this->_getFilterUniqueId($params); // sets the id for the related filter widget
}
@@ -291,7 +286,7 @@ class FiltersLib
$trimedval = trim($query);
// If the given query is valid and the parameter filters is an array
if (!empty($trimedval) && $filters != null && is_array($filters))
if (!isEmptyString($query) && $filters != null && is_array($filters))
{
$where = ''; // starts building the SQL where clause
@@ -303,8 +298,7 @@ class FiltersLib
if ($filtersCounter > 0)
$where .= ' AND '; // if it's NOT the last one
$trimedname = trim($filterDefinition->name);
if (!empty($trimedname)) // if the name of the applied filter is valid
if (!isEmptyString($filterDefinition->name)) // if the name of the applied filter is valid
{
// ...build the condition
$where .= '"'.$filterDefinition->name.'"'.$this->_getDatasetQueryCondition($filterDefinition);
@@ -346,14 +340,13 @@ class FiltersLib
$filterName = $filterJson->name; // always present, used as default
$trimedname = (isset($filterJson->namePhrase)?trim($filterJson->namePhrase):'');
// Filter name from phrases system
if (isset($filterJson->namePhrase) && !empty($trimedname))
if (isset($filterJson->namePhrase) && !isEmptyString($filterJson->namePhrase))
{
// Loads the library to use the phrases system
$this->_ci->load->library('PhrasesLib', array(self::FILTER_PHRASES_CATEGORY));
$tmpFilterNamePhrase = $this->_ci->phraseslib->t(self::FILTER_PHRASES_CATEGORY, $filterJson->namePhrase);
$trimedphrase = (isset($tmpFilterNamePhrase)?trim($tmpFilterNamePhrase):'');
if (isset($tmpFilterNamePhrase) && !empty($trimedphrase)) // if is not null or an empty string
if (isset($tmpFilterNamePhrase) && !isEmptyString($tmpFilterNamePhrase)) // if is not null or an empty string
{
$filterName = $tmpFilterNamePhrase;
}
@@ -395,7 +388,7 @@ class FiltersLib
$removeSelectedField = false;
$trimedval = (isset($selectedField)?trim($selectedField):'');
// Checks the parameter selectedField
if (isset($selectedField) && !empty($trimedval))
if (isset($selectedField) && !isEmptyString($selectedField))
{
// Retrives all the used fields by the current filter
$fields = $this->getElementSession(self::SESSION_FIELDS);
@@ -429,7 +422,7 @@ class FiltersLib
$removeSelectedField = false;
$trimedval = (isset($selectedField)?trim($selectedField):'');
// Checks the parameter selectedField
if (isset($selectedField) && !empty($trimedval))
if (isset($selectedField) && !isEmptyString($selectedField))
{
// Retrives all the used fields by the current filter
$fields = $this->getElementSession(self::SESSION_FIELDS);
@@ -458,7 +451,7 @@ class FiltersLib
$removeAppliedFilter = false;
$trimedval = (isset($appliedFilter)?trim($appliedFilter):'');
// Checks the parameter appliedFilter
if (isset($appliedFilter) && !empty($trimedval))
if (isset($appliedFilter) && !isEmptyString($appliedFilter))
{
// Retrives all the used fields by the current filter
$fields = $this->getElementSession(self::SESSION_FIELDS);
@@ -546,7 +539,7 @@ class FiltersLib
$addFilter = false;
$trimedval = (isset($filter)?trim($filter):'');
// Checks the parameter filter
if (isset($filter) && !empty($trimedval))
if (isset($filter) && !isEmptyString($filter))
{
// Retrives all the used fields by the current filter
$fields = $this->getElementSession(self::SESSION_FIELDS);
@@ -589,7 +582,7 @@ class FiltersLib
$saveCustomFilter = false; // by default returns a failure
$trimedval = (isset($customFilterDescription)?trim($customFilterDescription):'');
// Checks parameter customFilterDescription if not valid stop the execution
if (!isset($customFilterDescription) || empty($trimedval))
if (!isset($customFilterDescription) || isEmptyString($customFilterDescription))
{
return $saveCustomFilter;
}
@@ -706,11 +699,10 @@ class FiltersLib
*/
private function _getFilterUniqueId($params)
{
$trimedval = (isset($params[self::FILTER_PAGE_PARAM])?trim($params[self::FILTER_PAGE_PARAM]):'');
if ($params != null
&& is_array($params)
&& isset($params[self::FILTER_PAGE_PARAM])
&& !empty($trimedval))
&& !isEmptyString($params[self::FILTER_PAGE_PARAM]))
{
$filterUniqueId = $params[self::FILTER_PAGE_PARAM];
}
@@ -742,8 +734,7 @@ class FiltersLib
$condition = ''; // starts building the condition
// "operation" is a required property for the applied filter definition
$trimedval = trim($filterDefinition->operation);
if (!empty($trimedval))
if (!isEmptyString($filterDefinition->operation))
{
// Checks what operation is required
switch ($filterDefinition->operation)
@@ -818,9 +809,7 @@ class FiltersLib
}
// if the condition is valid
$trimedval = trim($condition);
if (!empty($trimedval))
$condition = ' '.$condition; // add a white space before
if (!isEmptyString($condition)) $condition = ' '.$condition; // add a white space before
return $condition;
}
+2 -2
View File
@@ -88,7 +88,7 @@ class MailLib
if (!is_null($recipientBCC)) $this->ci->email->bcc($recipientBCC);
$this->ci->email->subject($subject);
$this->ci->email->message($message);
if (!empty($altMessage)) $this->ci->email->set_alt_message($altMessage);
if (!isEmptyString($altMessage)) $this->ci->email->set_alt_message($altMessage);
// Avoid printing on standard output ugly error messages
$result = @$this->ci->email->send();
@@ -151,7 +151,7 @@ class MailLib
{
$valid = false;
if (!empty($emailAddress))
if (!isEmptyString($emailAddress))
{
$valid = filter_var($emailAddress, FILTER_VALIDATE_EMAIL);
}
+14 -19
View File
@@ -35,11 +35,6 @@ class MessageLib
$this->ci->load->model('system/Recipient_model', 'RecipientModel');
$this->ci->load->model('system/Attachment_model', 'AttachmentModel');
// Loads fhc helper
$this->ci->load->helper('fhc');
// Loads helper message to manage returning messages
$this->ci->load->helper('message');
// Loads phrases
$this->ci->lang->load('message');
}
@@ -49,9 +44,9 @@ class MessageLib
*/
public function getMessage($msg_id, $person_id)
{
if (empty($msg_id))
if (!is_numeric($msg_id))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
if (empty($person_id))
if (!is_numeric($person_id))
return $this->_error('', MSG_ERR_INVALID_RECIPIENTS);
$msg = $this->ci->RecipientModel->getMessage($msg_id, $person_id);
@@ -64,7 +59,7 @@ class MessageLib
*/
public function getMessagesByUID($uid, $oe_kurzbz = null, $all = false)
{
if (empty($uid))
if (isEmptyString($uid))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
$msg = $this->ci->RecipientModel->getMessagesByUID($uid, $oe_kurzbz, $all);
@@ -77,7 +72,7 @@ class MessageLib
*/
public function getMessagesByPerson($person_id, $oe_kurzbz = null, $all = false)
{
if (empty($person_id))
if (!is_numeric($person_id))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
$msg = $this->ci->RecipientModel->getMessagesByPerson($person_id, $oe_kurzbz, $all);
@@ -90,7 +85,7 @@ class MessageLib
*/
public function getSentMessagesByPerson($person_id, $oe_kurzbz = null, $all = false)
{
if (empty($person_id))
if (!is_numeric($person_id))
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
$msg = $this->ci->MessageModel->getMessagesByPerson($person_id, $oe_kurzbz, $all);
@@ -103,7 +98,7 @@ class MessageLib
*/
public function getMessageByToken($token)
{
if (empty($token))
if (isEmptyString($token))
return $this->_error('', MSG_ERR_INVALID_TOKEN);
$result = $this->ci->RecipientModel->getMessageByToken($token);
@@ -160,12 +155,12 @@ class MessageLib
*/
public function updateMessageStatus($message_id, $person_id, $status)
{
if (empty($message_id))
if (!is_numeric($message_id))
{
return $this->_error('', MSG_ERR_INVALID_MSG_ID);
}
if (empty($person_id))
if (!is_numeric($person_id))
{
return $this->_error('', MSG_ERR_INVALID_USER_ID);
}
@@ -227,7 +222,7 @@ class MessageLib
if ($this->_checkReceiverId($receiver_id))
{
// If the text and the subject of the template are not empty
if (!empty($subject) && !empty($body))
if (!isEmptyString($subject) && !isEmptyString($body))
{
$result = $this->_saveMessage($sender_id, $receiver_id, $subject, $body, $relationmessage_id, $oe_kurzbz);
// If no errors were occurred
@@ -244,12 +239,12 @@ class MessageLib
}
else
{
if (empty($subject))
if (isEmptyString($subject))
{
$result = $this->_error('', MSG_ERR_SUBJECT_EMPTY);
break;
}
elseif (empty($body))
elseif (isEmptyString($body))
{
$result = $this->_error('', MSG_ERR_BODY_EMPTY);
break;
@@ -320,7 +315,7 @@ class MessageLib
{
// If the text and the subject of the template are not empty
if (is_array($result->retval) && count($result->retval) > 0 &&
!empty($result->retval[0]->text) && !empty($result->retval[0]->subject))
!isEmptyString($result->retval[0]->text) && !isEmptyString($result->retval[0]->subject))
{
// Parses template text
$parsedText = $this->ci->vorlagelib->parseVorlagetext($result->retval[0]->text, $data);
@@ -354,12 +349,12 @@ class MessageLib
$result = $this->_error('', MSG_ERR_TEMPLATE_NOT_FOUND);
break;
}
elseif (empty($result->retval[0]->text))
elseif (isEmptyString($result->retval[0]->text))
{
$result = $this->_error('', MSG_ERR_INVALID_TEMPLATE);
break;
}
elseif (empty($result->retval[0]->subject))
elseif (isEmptyString($result->retval[0]->subject))
{
$result = $this->_error('', MSG_ERR_INVALID_TEMPLATE);
break;
+1 -8
View File
@@ -32,11 +32,6 @@ class NavigationLib
// Loads navigation configs
$this->_ci->config->load('navigation');
// Loads helper message to manage returning messages
$this->_ci->load->helper('message');
// Loads helper session to manage the php session
$this->_ci->load->helper('session');
// Loads library ExtensionsLib
$this->_ci->load->library('ExtensionsLib');
@@ -305,12 +300,10 @@ class NavigationLib
*/
private function _getNavigationtPage($params)
{
$trimedval = trim($params[self::NAVIGATION_PAGE_PARAM]);
//
if ($params != null
&& is_array($params)
&& isset($params[self::NAVIGATION_PAGE_PARAM])
&& !empty($trimedval))
&& !isEmptyString($params[self::NAVIGATION_PAGE_PARAM]))
{
$navigationPage = $params[self::NAVIGATION_PAGE_PARAM];
}
@@ -13,9 +13,6 @@ class OrganisationseinheitLib
// Loads model Organisationseinheit_model
$this->ci->load->model('organisation/Organisationseinheit_model', 'OrganisationseinheitModel');
// Loads helper message to manage returning messages
$this->ci->load->helper('Message');
}
/**
+8 -6
View File
@@ -41,6 +41,7 @@ class PermissionLib
const READ_HTTP_METHOD = 'GET';
const WRITE_HTTP_METHOD = 'POST';
private $_ci; // CI instance
private $acl; // conversion array from a source to a permission
private static $bb; // benutzerberechtigung
@@ -51,19 +52,20 @@ class PermissionLib
public function __construct()
{
// Loads CI instance
$this->ci =& get_instance();
// Loads the auth helper
$this->ci->load->helper('fhcauth');
$this->_ci =& get_instance();
// Loads the array of resources
$this->acl = $this->ci->config->item('fhc_acl');
$this->acl = $this->_ci->config->item('fhc_acl');
// Loads authentication library
$this->_ci->load->library('AuthLib');
// If it's NOT called from command line
if (!is_cli())
{
// API Caller rights initialization
self::$bb = new benutzerberechtigung();
self::$bb->getBerechtigungen(getAuthUID());
self::$bb->getBerechtigungen($this->_ci->authlib->getUser());
}
}
+10 -12
View File
@@ -22,9 +22,6 @@ class PhrasesLib
$this->_ci->load->model('system/Phrase_model', 'PhraseModel');
$this->_ci->load->model('system/Phrasentext_model', 'PhrasentextModel');
// Loads helper message to manage returning messages
$this->_ci->load->helper('message');
// Workaround to use more parameters in the construct since PHP doesn't support many constructors
$this->_extend_construct(func_get_args());
}
@@ -37,7 +34,7 @@ class PhrasesLib
*/
public function getPhrase($phrase_id)
{
if (empty($phrase_id)) return error(MSG_ERR_INVALID_MSG_ID);
if (isEmptyString($phrase_id)) return error(MSG_ERR_INVALID_MSG_ID);
return $this->_ci->PhraseModel->load($phrase_id);
}
@@ -55,7 +52,7 @@ class PhrasesLib
*/
public function getPhraseInhalt($phrase_id)
{
if (empty($phrase_id)) return error(MSG_ERR_INVALID_MSG_ID);
if (isEmptyString($phrase_id)) return error(MSG_ERR_INVALID_MSG_ID);
return $this->_ci->PhrasentextModel->loadWhere(array('phrase_id' => $phrase_id));
}
@@ -65,7 +62,7 @@ class PhrasesLib
*/
public function delPhrasentext($phrasentext_id)
{
if (empty($phrasentext_id)) return error(MSG_ERR_INVALID_MSG_ID);
if (isEmptyString($phrasentext_id)) return error(MSG_ERR_INVALID_MSG_ID);
return $this->_ci->PhrasentextModel->delete(array('phrasentext_id' => $phrasentext_id));
}
@@ -75,7 +72,7 @@ class PhrasesLib
*/
public function savePhrase($phrase_id, $data)
{
if (empty($data)) return error(MSG_ERR_INVALID_MSG_ID);
if (isEmptyString($data)) return error(MSG_ERR_INVALID_MSG_ID);
return $this->_ci->PhraseModel->update($phrase_id, $data);
}
@@ -85,7 +82,7 @@ class PhrasesLib
*/
public function getPhrasentextById($phrasentext_id)
{
if (empty($phrasentext_id))
if (isEmptyString($phrasentext_id))
return error($this->_ci->lang->line('fhc_'.FHC_INVALIDID, false));
return $this->_ci->PhrasentextModel->load($phrasentext_id);
@@ -173,7 +170,7 @@ class PhrasesLib
*/
public function parseVorlagetext($text, $data = array())
{
if (empty($text))
if (isEmptyString($text))
return error($this->_ci->lang->line('fhc_'.FHC_INVALIDID, false));
return $this->_ci->parser->parse_string($text, $data, true);
@@ -203,7 +200,7 @@ class PhrasesLib
&& $_phrase->phrase == $phrase
&& $_phrase->orgeinheit_kurzbz == $orgeinheit_kurzbz
&& $_phrase->orgform_kurzbz == $orgform_kurzbz
&& (!empty($trimedval)))
&& !isEmptyString($_phrase->text))
{
if (!is_array($parameters)) $parameters = array(); // if params is not an array
@@ -247,11 +244,12 @@ class PhrasesLib
// Use the given language if present, otherwise retrives the language for the logged user
$language = DEFAULT_LANGUAGE;
if (count($parameters) == 2 && !empty($parameters[1]) && is_string($parameters[1]))
if (count($parameters) == 2 && !isEmptyString($parameters[1]) && is_string($parameters[1]))
{
$language = $parameters[1];
}
else
// Checks if the user is authenticated to retrive the users's language
elseif (function_exists('getAuthUID'))
{
$this->_ci->load->model('person/Person_model', 'PersonModel');
@@ -1814,6 +1814,9 @@ abstract class REST_Controller extends CI_Controller {
return FALSE;
}
// Loads authentication library
$this->load->library('AuthLib');
if (is_callable([$auth_library_class, $auth_library_function]) === FALSE)
{
$this->load->library($auth_library_class);
+5 -6
View File
@@ -53,8 +53,6 @@ class UDFLib
public function __construct()
{
$this->_ci =& get_instance();
$this->_ci->load->helper('fhc');
}
// -------------------------------------------------------------------------------------------------
@@ -65,7 +63,8 @@ class UDFLib
*/
public function UDFWidget($args, $htmlArgs = array())
{
if (!empty($args[UDFLib::SCHEMA_ARG_NAME]) && !empty($args[UDFLib::TABLE_ARG_NAME]))
if ((isset($args[UDFLib::SCHEMA_ARG_NAME]) && !isEmptyString($args[UDFLib::SCHEMA_ARG_NAME]))
&& (isset($args[UDFLib::TABLE_ARG_NAME]) && !isEmptyString($args[UDFLib::TABLE_ARG_NAME])))
{
// Loads the widget library
$this->_ci->load->library('WidgetLib');
@@ -74,7 +73,7 @@ class UDFLib
loadResource(APPPATH.'widgets/udf');
// Default external block is true
if (empty($args[UDFLib::FIELD_ARG_NAME]) && !isset($htmlArgs[HTMLWidget::EXTERNAL_BLOCK]))
if (!isset($args[UDFLib::FIELD_ARG_NAME]) && !isset($htmlArgs[HTMLWidget::EXTERNAL_BLOCK]))
{
$htmlArgs[HTMLWidget::EXTERNAL_BLOCK] = true;
}
@@ -87,11 +86,11 @@ class UDFLib
}
else
{
if (empty($args[UDFLib::SCHEMA_ARG_NAME]))
if (!isset($args[UDFLib::SCHEMA_ARG_NAME]) || isEmptyString($args[UDFLib::SCHEMA_ARG_NAME]))
{
show_error(UDFLib::SCHEMA_ARG_NAME.' parameter is missing!');
}
if (empty($args[UDFLib::TABLE_ARG_NAME]))
if (!isset($args[UDFLib::TABLE_ARG_NAME]) || isEmptyString($args[UDFLib::TABLE_ARG_NAME]))
{
show_error(UDFLib::TABLE_ARG_NAME.' parameter is missing!');
}
+5 -10
View File
@@ -20,11 +20,6 @@ class VorlageLib
$this->ci->load->model('system/Vorlage_model', 'VorlageModel');
$this->ci->load->model('system/Vorlagestudiengang_model', 'VorlageStudiengangModel');
$this->ci->load->helper('language');
// Loads helper message to manage returning messages
$this->ci->load->helper('message');
//$this->ci->lang->load('fhcomplete');
}
/**
@@ -35,7 +30,7 @@ class VorlageLib
*/
public function getVorlage($vorlage_kurzbz)
{
if (empty($vorlage_kurzbz))
if (isEmptyString($vorlage_kurzbz))
return error(MSG_ERR_INVALID_MSG_ID);
$vorlage = $this->ci->VorlageModel->load($vorlage_kurzbz);
@@ -62,7 +57,7 @@ class VorlageLib
*/
public function saveVorlage($vorlage_kurzbz, $data)
{
if (empty($data))
if (isEmptyArray($data))
return error(MSG_ERR_INVALID_MSG_ID);
$vorlage = $this->ci->VorlageModel->update($vorlage_kurzbz, $data);
@@ -77,7 +72,7 @@ class VorlageLib
*/
public function getVorlagetextByVorlage($vorlage_kurzbz)
{
if (empty($vorlage_kurzbz))
if (isEmptyString($vorlage_kurzbz))
return error($this->ci->lang->line('fhc_'.FHC_INVALIDID, false));
$vorlage = $this->ci->VorlageStudiengangModel->loadWhere(array('vorlage_kurzbz' => $vorlage_kurzbz));
@@ -95,7 +90,7 @@ class VorlageLib
*/
public function loadVorlagetext($vorlage_kurzbz, $oe_kurzbz = null, $orgform_kurzbz = null, $sprache = null)
{
if (empty($vorlage_kurzbz))
if (isEmptyString($vorlage_kurzbz))
return error($this->ci->lang->line('fhc_'.FHC_INVALIDID, false));
// Try to search the template with the given vorlage_kurzbz and other parameters if present
@@ -205,7 +200,7 @@ class VorlageLib
*/
public function parseVorlagetext($text, $data = array())
{
if (empty($text))
if (isEmptyString($text))
return error($this->ci->lang->line('fhc_'.FHC_INVALIDID, false));
$text = $this->ci->parser->parse_string($text, $data, true);
return $text;
+84 -88
View File
@@ -4,17 +4,17 @@
* @author Jens Segers
* @link http://www.jenssegers.be
* @license MIT License Copyright (c) 2012 Jens Segers
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -30,16 +30,16 @@ class WidgetLib
{
const DIR_HTML_WIDGETS = 'html';
const HTML_WIDGET_NAME = 'HTMLWidget';
/* default values */
private $_template = 'template';
private $_parser = false;
private $_cache_ttl = 0;
private $_widget_path = '';
private $_ci;
private $_partials = array();
/**
* Construct with configuration array. Codeigniter will use the config file otherwise
* @param array $config
@@ -47,23 +47,19 @@ class WidgetLib
public function __construct($config = array())
{
$this->_ci = & get_instance();
$this->_ci->load->helper('fhc');
// Set the default widget path with APPPATH
$this->_widget_path = APPPATH.'widgets/';
// Loads widgets to render HTML elements
// NOTE: the first one to be loaded must be HTMLWidget
loadResource($this->_widget_path.WidgetLib::DIR_HTML_WIDGETS, WidgetLib::HTML_WIDGET_NAME);
loadResource($this->_widget_path.WidgetLib::DIR_HTML_WIDGETS);
if (!empty($config))
$this->initialize($config);
log_message('debug', 'Template library initialized');
// If config are given then initialize this lib with the given config
if (!isEmptyArray($config)) $this->initialize($config);
}
/**
* Initialize with configuration array
* @param array $config
@@ -73,14 +69,14 @@ class WidgetLib
{
foreach ($config as $key => $val)
$this->{'_'.$key} = $val;
if ($this->_widget_path == '')
$this->_widget_path = APPPATH.'widgets/';
if ($this->_parser && !class_exists('CI_Parser'))
$this->_ci->load->library('parser');
}
/**
* Set a partial's content. This will create a new partial when not existing
* @param string $index
@@ -90,7 +86,7 @@ class WidgetLib
{
$this->partial($name)->set($value);
}
/**
* Access to partials for method chaining
* @param string $name
@@ -100,7 +96,7 @@ class WidgetLib
{
return $this->partial($name);
}
/**
* Check if a partial exists
* @param string $index
@@ -110,7 +106,7 @@ class WidgetLib
{
return array_key_exists($index, $this->_partials);
}
/**
* Set the template file
* @param string $template
@@ -119,7 +115,7 @@ class WidgetLib
{
$this->_template = $template;
}
/**
* Publish the template with the current partials
* You can manually pass a template file with extra data, or use the default template from the config file
@@ -136,12 +132,12 @@ class WidgetLib
{
$this->_template = $template;
}
if (!$this->_template)
{
show_error('There was no template file selected for the current template');
}
if (is_array($data) || is_object($data))
{
foreach ($data as $name => $content)
@@ -149,9 +145,9 @@ class WidgetLib
$this->partial($name)->set($content);
}
}
unset($data);
if ($this->_parser)
{
$this->_ci->parser->parse($this->_template, $this->_partials);
@@ -161,7 +157,7 @@ class WidgetLib
$this->_ci->load->view($this->_template, $this->_partials);
}
}
/**
* Create a partial object with an optional default content
* Can be usefull to use straight from the template file
@@ -183,24 +179,24 @@ class WidgetLib
{
$partial->cache($this->_cache_ttl);
}
// detect local triggers
if (method_exists($this, 'trigger_'.$name))
{
$partial->bind($this, 'trigger_'.$name);
}
$this->_partials[$name] = $partial;
}
if (!$partial->content() && $default)
{
$partial->set($default);
}
return $partial;
}
/**
* Create a widget object with optional parameters
* Can be usefull to use straight from the template file
@@ -213,15 +209,15 @@ class WidgetLib
{
// Loads the widget file, trying to find it also in the subdirectories
loadResource($this->_widget_path, $name, true);
if (!class_exists($name))
{
show_error("Widget '".$name."' was not found.");
}
return new $name($name, $data, $htmlArgs);
}
/**
* Enable cache for all partials with TTL, default TTL is 60
* @param int $ttl
@@ -233,10 +229,10 @@ class WidgetLib
{
$partial->cache($ttl, $identifier);
}
$this->_cache_ttl = $ttl;
}
// ---- TRIGGERS -----------------------------------------------------------------
/**
@@ -255,27 +251,27 @@ class WidgetLib
}
return $return;
}
if (!stristr($url, 'http://') && !stristr($url, 'https://') && substr($url, 0, 2) != '//')
{
$url = $this->_ci->config->item('base_url').$url;
}
// legacy support for media
if (is_string($attributes))
{
$attributes = array('media' => $attributes);
}
if (is_array($attributes))
{
$attributeString = "";
foreach ($attributes as $key => $value)
{
$attributeString .= $key.'="'.$value.'" ';
}
return '<link rel="stylesheet" href="'.htmlspecialchars(strip_tags($url)).'" '.$attributeString.'>'."\n\t";
}
else
@@ -283,7 +279,7 @@ class WidgetLib
return '<link rel="stylesheet" href="'.htmlspecialchars(strip_tags($url)).'">'."\n\t";
}
}
/**
* Javascript trigger
* @param string $source
@@ -300,15 +296,15 @@ class WidgetLib
}
return $return;
}
if (!stristr($url, 'http://') && !stristr($url, 'https://') && substr($url, 0, 2) != '//')
{
$url = $this->_ci->config->item('base_url').$url;
}
return '<script src="'.htmlspecialchars(strip_tags($url)).'"></script>'."\n\t";
}
/**
* Meta trigger
* @param string $name
@@ -319,12 +315,12 @@ class WidgetLib
{
$name = htmlspecialchars(strip_tags($name));
$value = htmlspecialchars(strip_tags($value));
if ($name == 'keywords' and !strpos($value, ','))
{
$content = preg_replace('/[\s]+/', ', ', trim($value));
}
switch ($type)
{
case 'meta' :
@@ -334,10 +330,10 @@ class WidgetLib
$content = '<link rel="'.$name.'" href="'.$value.'">'."\n\t";
break;
}
return $content;
}
/**
* Title trigger, keeps it clean
* @param string $name
@@ -348,7 +344,7 @@ class WidgetLib
{
return htmlspecialchars(strip_tags($title));
}
/**
* Title trigger, keeps it clean
* @param string $name
@@ -366,7 +362,7 @@ class Partial
{
protected $_ci, $_content, $_name, $_cache_ttl = 0, $_cached = false, $_identifier, $_trigger;
protected $_args = array();
/**
* Construct with optional parameters
* @param array $args
@@ -377,7 +373,7 @@ class Partial
$this->_args = $args;
$this->_name = $name;
}
/**
* Gives access to codeigniter's functions from this class if needed
* This will be handy in extending classes
@@ -387,7 +383,7 @@ class Partial
{
return $this->_ci->$name;
}
/**
* Alias methods
*/
@@ -403,7 +399,7 @@ class Partial
break;
}
}
/**
* Returns the content when converted to a string
* @return string
@@ -412,7 +408,7 @@ class Partial
{
return (string) $this->content();
}
/**
* Returns the content
* @return string
@@ -423,10 +419,10 @@ class Partial
{
$this->cache->save($this->cache_id(), $this->_content, $this->_cache_ttl);
}
return $this->_content;
}
/**
* Overwrite the content
* @param mixed $content
@@ -438,10 +434,10 @@ class Partial
{
$this->_content = (string) $this->trigger(func_get_args());
}
return $this;
}
/**
* Append something to the content
* @param mixed $content
@@ -453,10 +449,10 @@ class Partial
{
$this->_content .= (string) $this->trigger(func_get_args());
}
return $this;
}
/**
* Prepend something to the content
* @param mixed $content
@@ -468,10 +464,10 @@ class Partial
{
$this->_content = (string) $this->trigger(func_get_args()).$this->_content;
}
return $this;
}
/**
* Set content if partial is empty
* @param mixed $default
@@ -486,10 +482,10 @@ class Partial
$this->_content = $default;
}
}
return $this;
}
/**
* Load a view inside this partial, overwrite if wanted
* @param string $view
@@ -511,9 +507,9 @@ class Partial
}
$data = $array;
}
$content = $this->_ci->load->view($view, $data, true);
if ($overwrite)
{
$this->set($content);
@@ -525,7 +521,7 @@ class Partial
}
return $this;
}
/**
* Parses a view inside this partial, overwrite if wanted
* @param string $view
@@ -541,7 +537,7 @@ class Partial
{
$this->_ci->load->library('parser');
}
// better object to array
if (is_object($data))
{
@@ -552,9 +548,9 @@ class Partial
}
$data = $array;
}
$content = $this->_ci->parser->parse($view, $data, true);
if ($overwrite)
{
$this->set($content);
@@ -564,10 +560,10 @@ class Partial
$this->append($content);
}
}
return $this;
}
/**
* Loads a widget inside this partial, overwrite if wanted
* @param string $name
@@ -580,7 +576,7 @@ class Partial
if (!$this->_cached)
{
$widget = $this->template->widget($name, $data);
if ($overwrite)
{
$this->set($widget->content());
@@ -592,7 +588,7 @@ class Partial
}
return $this;
}
/**
* Enable cache with TTL, default TTL is 60
* @param int $ttl
@@ -604,10 +600,10 @@ class Partial
{
$this->_ci->load->driver('cache', array('adapter' => 'file'));
}
$this->_cache_ttl = $ttl;
$this->_identifier = $identifier;
if ($cached = $this->_ci->cache->get($this->cache_id()))
{
$this->_cached = true;
@@ -615,7 +611,7 @@ class Partial
}
return $this;
}
/**
* Used for cache identification
* @return string
@@ -631,7 +627,7 @@ class Partial
return $this->_name.'_'.md5(get_class($this).implode('', $this->_args));
}
}
/**
* Trigger returns the result if a trigger is set
* @param array $args
@@ -648,7 +644,7 @@ class Partial
return call_user_func_array($this->_trigger, $args);
}
}
/**
* Bind a trigger function
* Can be used like bind($this, "function") or bind("function")
@@ -663,12 +659,12 @@ class Partial
$args = func_get_args();
$obj = array_shift($args);
$func = array_pop($args);
foreach ($args as $trigger)
{
$obj = $obj->$trigger;
}
$this->_trigger = array($obj, $func);
}
else
@@ -703,8 +699,8 @@ class Widget extends Partial
ob_start();
$this->display($this->_args);
$buffer = ob_get_clean();
// if no content is produced but there was direct ouput we set
// if no content is produced but there was direct ouput we set
// that output as content
if (!$this->_content && $buffer)
{
@@ -712,7 +708,7 @@ class Widget extends Partial
}
}
}
return parent::content();
}
}
}