File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/api/class.module.php
<?php
/**
* This file contains the iwp_module class
*
* @version $Id$
*
*
* @package IWP
* @subpackage IWP_API
*/
/**
* IWP ModuleSession Class
*
* This is a modules-specific wrapper class for the standard iwp_session class which is available to use via iwp_module->session.
*
* Internally, it will use iwp_session for all session interaction, but will automatically prefix all session variable names with the current module name to assure unique session variables on a per module basis.
*
* @author Gwilym
*
*/
class iwp_modulesession {
protected $module;
/**
*
* @param iwp_module $module
* @return iwp_modulesession
*/
public function __construct (iwp_module $module) {
$this->module = $module;
}
protected function getSessionPrefix () {
return $this->module->moduleName .'_';
}
public function Set ($name, $value) {
return iwp_session::Set($this->getSessionPrefix() . $name, $value);
}
public function Get ($name) {
return iwp_session::Get($this->getSessionPrefix() . $name);
}
public function Kill ($name) {
return iwp_session::Kill($this->getSessionPrefix() . $name);
}
public function Exists ($name) {
return iwp_session::Exists($this->getSessionPrefix() . $name);
}
}
/**
* IWP Module Class
* This is the base class that all modules extend from.
*
* @package IWP
* @subpackage IWP_API
* @property iwp_tablecreator $table
*/
class iwp_module extends iwp_engine {
/**
* The name of the module
*
* @var string
*/
public $moduleName = "";
public $eventsFile = "";
protected $imageDirectories = array();
protected $fileDirectories = array();
/**
* This is the MySQL CREATE TABLE query used to create the table for this module. If the module has multiple tables, the queries should be separated by a semi-colon.
* This is often set using the iwp_tablecreator class to assist. This class should be using the in CreateModuleTable() function.
*
* @see CreateModuleTable()
* @see iwp_tablecreator
*/
protected $tableSchema = "";
/**
*
* @var iwp_modulesession
*/
public $session;
/**
* If the designer of the module has hard-coded the $tableSchema with their own create table SQL, the module still needs to know what fields exist.
* This array should contain the names of all columns in the database table, witht he exception of the primary key.
* Example:
* <code>
* $fieldsArray = array('field1', 'field2', 'field3');
* </code>
*
* @var array
*/
protected $fieldsArray = array();
public $hasBlocks = false;
protected $layoutBlocks = array();
protected $events = array();
protected $eventListeners = array();
/**
* This static variable contains permissions that are available to be chosen for setting module permissions on a per-content-type basis.
*
* @var Array
*/
public static $ContentPermissionOptions;
/**
* This static variable contains permissions that are available to be chosen for setting module permissions on a site-wide basis.
*
* @var Array
*/
public static $SitePermissionOptions;
/**
* The name of the primary database table that this module uses without any prefixes.
* The application prefix and the module profix are added to this after.
*
* @var string
*/
protected $baseTableName = "";
/**
* Defines the name of the content id column in the table for this module.
*
* @var string
*/
protected $contentIdColumn = 'contentid';
/**
* The ID number of this module, as per the database
*
* @var integer
*/
public $ModuleId = 0;
/**
* An array containing messages. This is intended to be populated by the extending module class during various events like activation / deactivation, and then passed back to the browser.
*
* @var Array
*/
public $messages = array();
/**
* This is used by content modules to decide where their output should show up in relation to the content on the page.
* Set this to true to place it AFTER the content, i.e. Append it
* Set this to false to place it BEFORE the content, i.e. Prepend it
*
* @var boolean
*/
protected $AppendContent = true;
/**
* This defines where the modules content should output when being displayed in a list. By default it just adds it after the summary.
*
* @var string
*/
protected $ListAppendSection = 'afterSummary';
/**
* This defines whether or not the module should have its own 'layout' on the 'Site Layout' with the drag and droppable lists and blocks. This should only be set to true if the module
* outputs its own pages at all.
*
* @var boolean
*/
public $hasLayout = false;
/**
* This determins where on a content page the module output should be output. By default it adds to the 'contentModules' section on the page. However there are various other hooks
* or variables that the content can be added to.
*
* Whether the content is appended to the bottom/end or top/beginning of the section defined here is specified by the member variable $AppendContent
*
* @var string
*
* @see $AppendContent
*/
protected $displayPosition = 'contentModules';
/**
* Internal variable to store instance of iwp_form for use on configuration page.
*
* @var iwp_form
*/
protected $form;
/**
* An instance of iwp_modulevars
*
* @var iwp_modulevars
*/
public $vars;
/**
* This is a list of URIs used by this module. This should not normally be handled by this array directly, but rather by using the uriPatterns.ini file
*
* @var array
*/
protected $UriList = null;
/**
* Deletes all data associated with this module.
* This is used when cleaning out the data during the importer process.
* This parent function is created as not all modules have to use the database to store their custom data.
*
* @return void
*/
public function TruncateAllData () {}
/**
* LoadVars
* A shorthand method for calling the vars object's Load() method for current module.
*
* @return Boolean
*/
public function LoadVars ()
{
return $this->vars->Load($this->moduleName);
}
/**
* VarExists
* A shorthand method for calling the vars object's Exists() method for current module.
*
* @param String $name
* @return Bool
*/
public function VarExists ($name)
{
return $this->vars->Exists($name, $this->moduleName);
}
/**
* GetVar
* A shorthand method for calling the vars object's Get() method for current module.
*
* @return Mixed
*/
public function GetVar ($name)
{
return $this->vars->Get($name, $this->moduleName);
}
/**
* SetVar
* A shorthand method for calling the vars object's Set() method for current module.
*
* @return Void
*/
public function SetVar ($name, $value)
{
return $this->vars->Set($name, $value, $this->moduleName);
}
/**
* DeleteVar
* A shorthand method for calling the vars object's Delete() method for current module.
*
* @return Void
*/
public function DeleteVar ($name)
{
return $this->vars->Delete($name, $this->moduleName);
}
/**
* The constructor. When the class is intialised, the language file is loaded and the parent constructor called.
*
* @return void
*
* @see LoadMod()
*/
public function __construct(){
$this->session = new iwp_modulesession($this);
$this->lang = new iwp_language();
$this->lang->LoadMod($this->moduleName);
$this->vars = new iwp_modulevars();
parent::__construct();
}
/**
* IsContentModule
* A function that should be overridden by a module extending on the iwp_module class to return true if the module implements content module functionality
*
* @return Boolean
*/
public function IsContentModule ()
{
return false;
}
/**
* IsWebsiteModule
* A function that should be overridden by a module extending on the iwp_module class to return TRUE if the module implements website module functionality.
*
* @return Boolean
*/
public function IsWebsiteModule ()
{
return false;
}
/**
* HasConfigurationScreen
* A function that should be overridden by a module extending on the iwp_module class to return TRUE if the module implements a configuration screen.
*
* @return Boolean
*/
public function HasConfigurationScreen ()
{
return false;
}
public function GetImageDirectories() {
return $this->imageDirectories;
}
public function GetFileDirectories() {
return $this->fileDirectories;
}
public function LoadLanguageVariables() {
$this->template->Assign(array($this->moduleName, 'lang'), $this->lang->GetLangVars(), false);
}
private $_inidata = null;
private function LoadIniData ()
{
if ($this->_inidata === null) {
$this->_inidata = iwp_module::GetModuleDeclarations($this->moduleName);
}
if ($this->_inidata) {
return true;
}
return false;
}
/**
* This is iwp_module's short-cut for calling iwp_auth->HasPerm which is pre-set to check the sitemodules scope type and $this->moduleName scope name.
*
* For a full description of this, see iwp_auth->HasPerm documentation.
*
* @see iwp_auth#HasPerm
* @param string $scopeItem
* @param mixed $itemId
* @param boolean $categoryCheck
* @return boolean
*/
public function hasPerm ($scopeItem, $itemId = false, $categoryCheck = false) {
return $this->auth->HasPerm('sitemodules', $this->moduleName, $scopeItem, $itemId, $categoryCheck);
}
/**
* This is iwp_module's short-cut for calling iwp_auth->HasMultiPerm which is pre-set to check the sitemodules scope type and $this->moduleName scope name.
*
* For a full description of this, see iwp_auth->HasMultiPerm documentation.
*
* @param integer $matchType
* @param array|string $scopeItemSet
* @param array|integer $itemIdSet
* @param array|boolean $categoryCheckSet
* @return boolean
*/
public function hasMultiPerm ($matchType, $scopeItemSet, $itemIdSet = false, $categoryCheckSet = false) {
return $this->auth->HasMultiPerm($matchType, array('sitemodules'), array($this->moduleName), $scopeItemSet);
}
/**
* Retrieves a database table name for the current module. It appends the module db prefix to the beggining.
*
* @param $tableName string The basename of the table to retrieve.
* @return string
*/
public function getTable($tableName=null) {
$tables = $this->getTables(true);
if(is_null($tableName) && is_array($tables) && isset($tables[0])) {
return IWP_MODULE_DB_PREFIX . $tables[0];
}
if (!is_null($tableName) && is_array($tables) && in_array($tableName, $tables)) {
return IWP_MODULE_DB_PREFIX . $tableName;
}
return '';
}
/**
* Returns a list of database tables for the current module. Each module should override this function if they have database tables.
* The keys for the array should be incrementally numeric starting from zero, i.e. the keys should not be set. The getTable() function relies on there being a [0] element.
*
* @param boolean $withoutPrefix A boolean for whether or not to include the prefix for the table.
*
* @return string
*/
public function getTables($withoutPrefix=false) {
return array();
}
/**
* GetVersionNumber
*
*
* @return Integer
*/
public function GetVersionNumber ()
{
if ($this->LoadIniData() && isset($this->_inidata['VersionNumber'])) {
return $this->_inidata['VersionNumber'];
}
return 0;
}
/**
* GetVersionString
* Returns the version string as defined in this module's module.ini file
*
* @return String
*/
public function GetVersionString ()
{
if ($version = $this->GetVersionNumber()) {
return IntervalVersionToReadable($version);
}
$lang = iwp_language::getInstance();
return $lang->Get('ModuleVersionNotDefined');
}
/**
* GetAuthorURL
* Returns the author's URL as defined in this module's module.ini file
*
* @return String
*/
public function GetAuthorName ()
{
if ($this->LoadIniData() && isset($this->_inidata['AuthorName'])) {
return $this->_inidata['AuthorName'];
}
$lang = iwp_language::getInstance();
return $lang->Get('ModuleAuthorUnknown');
}
/**
* GetAuthorURL
*
* @return String
*/
public function GetAuthorURL ()
{
if ($this->LoadIniData() && isset($this->_inidata['AuthorURL'])) {
return $this->_inidata['AuthorURL'];
}
return '';
}
/**
* GetListMessage
* A function that should be overridden by a module extending on he iwp_module class to return a string which will be shown on the module list page as a status 'message' below the module.
*
* @return String
*/
public function GetListMessage ()
{
return '';
}
/**
* Returns an array of types this module implements, powered by the responses to IsContentModule, IsWebsiteModule etc.
*
* @param Boolean $useLang If TRUE the results will contain language specific names, otherwise the results will contain codes
* @return Array
*/
public function GetTypeList ($useLang = false)
{
$typeList = array();
$lang = iwp_language::getInstance(); // use general language file instead of $this->lang
if ($this->IsContentModule()) {
$typeList[] = $useLang ? $lang->Get('ModuleType_Content') : 'content';
}
if ($this->IsWebsiteModule()) {
$typeList[] = $useLang ? $lang->Get('ModuleType_Website') : 'website';
}
return $typeList;
}
/**
* A function to return the ContentPermissionOptions array usable by call_user_func. This should be overridden by modules that define their own permissions.
*
* @return array
*/
public static function GetContentPermissionOptions () {
return array();
}
/**
* A function to return the SitePermissionOptions array usable by call_user_func. This should be overridden by modules that define their own permissions.
*
* @return array
*/
public static function GetSitePermissionOptions () {
return array();
}
/**
* Loads the variables defined in the module.ini file for a given module.
*
*/
public static function GetModuleDeclarations ($moduleCodeName)
{
$filename = IWP_MODULES_PATH . '/'. $moduleCodeName . "/module.ini";
return @parse_ini_file($filename);
}
/**
* Return the ID number for the current module. It searches the loaded module list to locate the ID number
*
* @param boolean $reset If the member variable ModuleId is set, it will be returned unless $reset is passed in as true where the ID number will be searched for again. The default for $reset is false.
*
* @return integer The ID number of the current module
*/
public function GetActiveId ($reset=false){
if(isset($this->ModuleId) && $this->ModuleId > 0 && !$reset){
return $this->ModuleId;
}
$modules = iwp_modules::getInstance();
if(!is_array($modules->ModuleIdList) || sizeof($modules->ModuleIdList) < 1){
$modules->LoadModuleIdList();
}
if(is_array($modules->ModuleIdList)){
$key = array_search($this->moduleName, $modules->ModuleIdList);
}else{
$key = false;
}
if ($key) {
$this->ModuleId = $key;
}
return $this->ModuleId;
}
/**
* This function takes the base database table name and adds the application and module prefixes and sets the TableName variable
*
* @return void
*/
public function SetTableName(){
if(!empty($this->baseTableName)){
$this->TableName = $this->tablePrefix . 'module_' . $this->baseTableName;
}
}
/**
* UpgradeModule
* This function upgrades an active module, running any required functions to upgrade it.
* This is an interface function only and should be overridden by modules which are extending on this class.
*
* @return Boolean Returns TRUE if upgrade process was successful
*/
public function UpgradeModule ()
{
return false;
}
/**
* DeactivateModule
* This function removes this module from the list of current modules in the database. It should be called by modules extending on this class during any custom deactivation routine.
*
* @see iwp_module::messages
* @return Boolean Returns TRUE if deactivation was successful, FALSE if not.
*/
public function DeactivateModule ()
{
if ($this->db->Query("DELETE FROM `" . IWP_TABLE_MODULES . "` WHERE codename = '" . $this->db->Quote($this->moduleName) . "'")) {
// unregister event listeners
foreach ($this->eventListeners as $eventName => $arguments) {
try { iwp_event::listenerUnregister($eventName, $arguments, $this->GetEventsFile()); }
catch (InterspireEventException $e) { /* do nothing */ }
}
// remove events
foreach ($this->events as $eventName) {
try { iwp_event::eventRemove($eventName); }
catch (InterspireEventException $e) { /* do nothing */ }
}
return true;
}
return false;
}
/**
* ActivateModule
* This function adds this module to the list of current modules in the database. It should be called by modules extending on this class during any custom activation routine.
*
* @see iwp_module::messages
* @return Boolean Returns TRUE if activation was successful, FALSE if not.
*/
public function ActivateModule ()
{
$this->messages = array();
$insertData = array();
$insertData['codename'] = $this->moduleName;
$insertData['version'] = $this->GetVersionNumber();
$insertData['type'] = implode(',', $this->GetTypeList());
$lang = iwp_language::getInstance();
$id = $this->db->InsertQuery(IWP_TABLE_MODULES, $insertData);
if ($id < 1) {
$lang = iwp_language::getInstance();
$this->messages[] = sprintf($lang->Get('ModuleActivateDatabaseError'), $this->lang->Get('ModuleNamePlural'));
return false;
}
$this->ModuleId = $id;
$success = false;
$moduleTables = $this->getTables();
if(!empty($moduleTables)) {
$fields = $tables = array();
$this->CreateModuleTable();
if(!isset($this->table) || (!is_object($this->table) && !is_array($this->table))){
$this->messages[] = sprintf($lang->Get('ModuleErrorNoFields'), $this->lang->Get('ModuleNamePlural'));
$this->DeactivateModule();
return false;
}
if(is_object($this->table) && !is_array($this->table)){
$tables[] = &$this->table;
}elseif(is_array($this->table) && is_object($this->table[0])){
$tables = &$this->table;
}else{
$this->messages[] = sprintf($lang->Get('ModuleErrorInvalidTableStructure'), $this->lang->Get('ModuleNamePlural'));
$this->DeactivateModule();
return false;
}
foreach($tables as $tableObj){
if(empty($tableObj->fields)){
$this->messages[] = sprintf($lang->Get('ModuleErrorNoFields'), $this->lang->Get('ModuleNamePlural'));
$this->DeactivateModule();
return false;
}
$fields = array();
foreach($tableObj->fields as $fieldName=>$fieldObj){
$fields[] = $fieldName;
}
if ($this->db->TableExists($tableObj->name)) {
if ($this->db->ColumnExists($tableObj->name, $fields)) {
// table and columns exists
$success = true;
} else if (iwp_session::Exists('module_'.$tableObj->name.'_removetable')) {
// table exists and this is the second time they have clicked, drop the table and re-create it
if ($this->RunModuleTableQuery($tableObj->name)) {
$success = true;
}
} else {
// table exists but columns do not match
iwp_session::Set('module_'.$tableObj->name.'_removetable', 1);
$this->messages[] = sprintf(GetLang('ModuleTableExistsButDifferent'), $tableObj->name);
$this->messages[] = sprintf(GetLang('ModuleTableExistsButDifferentNote'));
$this->DeactivateModule();
return false;
}
} else {
// table does not exist at all
if ($this->RunModuleTableQuery($tableObj->name)) {
$success = true;
}else{
iwp_session::Set('module_'.$tableObj->name.'_removetable', 1);
$this->messages[] = $this->db->GetErrorMsg();
$this->DeactivateModule();
return false;
}
}
}
} else {
$success = true;
}
$imageDirs = $this->GetImageDirectories();
$fileDirs = $this->GetFileDirectories();
$failDirs = array();
if(is_array($imageDirs) && !empty($imageDirs)) {
foreach($imageDirs as $imageDir){
if(!is_dir(IWP_BASE_PATH . '/images/' . $imageDir)){
if(!mkdir(IWP_BASE_PATH . '/images/' . $imageDir, 0777)){
$failDirs[] = '/images/' . $imageDir;
}else{
@chmod(IWP_BASE_PATH . '/images/' . $imageDir, 0777);
}
}
}
}
if(is_array($fileDirs) && !empty($fileDirs)) {
foreach($fileDirs as $fileDir){
if(!is_dir(IWP_BASE_PATH . '/files/' . $fileDir)){
if(!mkdir(IWP_BASE_PATH . '/files/' . $fileDir, 0777)){
$failDirs[] = '/files/' . $fileDir;
}else{
@chmod(IWP_BASE_PATH . '/files/' . $fileDir, 0777);
}
}
}
}
// register events
if ($success) {
foreach ($this->events as $eventName) {
if (!iwp_event::eventExists($eventName)) {
try {
iwp_event::eventCreate($eventName);
} catch (InterspireEventException $e) {
$success = false;
$this->messages[] = sprintf($lang->Get('unableToCreateEvent'), $eventName, $e->getMessage());
}
}
}
}
// register event listeners
if ($success) {
foreach ($this->eventListeners as $eventName => $arguments) {
if (!iwp_event::listenerExists($eventName, $arguments, $this->GetEventsFile())) {
try {
iwp_event::listenerRegister($eventName, $arguments, $this->GetEventsFile());
} catch (InterspireEventException $e) {
$success = false;
$this->messages[] = sprintf($lang->Get('unableToRegisterEventListener'), $eventName, $e->getMessage());
}
}
}
}
if (!$success) {
$this->DeactivateModule();
} else {
if (!empty($this->baseTableName)) {
iwp_session::Kill('module_'.$tableObj->name.'_removetable');
}
$this->SetDefaultSettings();
$extraLang = '';
//if ($this->lang->Exists('moduleSuccessfullyActivated')) {
// $this->messages[] = $extraLang = $this->lang->Get('moduleSuccessfullyActivated');
//}else{
// $this->messages[] = $lang->Get('moduleSuccessfullyActivated');
//}
}
return $success;
}
public function GetEventsFile(){
if(is_null($this->eventsFile) || empty($this->eventsFile)){
$this->eventsFile = '{%IWP_MODULES_PATH%}/' . $this->moduleName . '/module.' . $this->moduleName . '.php';
}
return $this->eventsFile;
}
/**
* The base function that the child should extend from
*
* @return false
*/
public function AdminGetContentTypeArray ()
{
return false;
}
/**
* This loads a form field class that is included with this module
*
* @param string $field The name of the form field to be loaded. This should be located within the module directory
*
* @return object Returns the field object, or false otherwise
*/
public function GetModuleFieldCustom ($field)
{
if(is_file(IWP_MODULES_PATH . '/'. $this->moduleName . "/class.field.".$field.".php")){
include_once(IWP_MODULES_PATH . '/'. $this->moduleName . "/class.field.".$field.".php");
$className = "module_field_".$this->moduleName."_".$field;
$class = new $className($field);
$class->SetModuleName($this->moduleName);
return $class;
}
return false;
}
public static function getUriMatches(){
return array();
}
/**
* AdminConfigureWrapper
* This function is called by the control panel when the module's configuration dialog is to be presented. It will in-turn call the 'AdminConfigure' method which needs to be defined by the child module.
*
* @return void
*/
public function AdminConfigureWrapper ()
{
$this->form = new iwp_form();
$this->template->Assign('PageTitle', $this->lang->Get('ModuleNamePlural'));
$this->template->Assign('PageIntro', $this->lang->Get('ConfigureIntroduction'));
$this->LoadVars();
$variables = $this->AdminGetVariablesArray();
$this->AdminConfigure();
$fields = $this->form->Fields();
if (count($fields)) {
if (count($variables)) {
foreach ($fields as $key => $field) {
$value = $this->GetVar($key);
if ($value = $this->GetVar($key)) {
$field->Value($value);
}
}
}
$this->template->Assign('configFormFieldNamesJavascript', $this->form->GetFieldNamesJavascript());
$this->template->Assign('configFormJSFieldValidation', $this->form->GetJSFieldValidation());
$this->template->Assign('configFormOutput', $this->form->GetOutput());
}
$this->template->Assign('moduleCodename', $this->moduleName);
$this->template->ParseTemplate('modules.configure');
}
/**
* Returns a list of variable names that should be saved / loaded by the module configuration screen. This should be overridden by the child class if it wishes to make use of auto variable loading and saving.
*
* @return array
*/
public function AdminGetVariablesArray () {
return array();
}
/**
* This function is called by the control panel when the module's configuration dialog is saved. In turn, it will call AdminConfigureSave, which can be overridden by the child class to implement custom save routines.
*
* @return boolean TRUE on save success, otherwise FALSE
*/
public function AdminConfigureSaveWrapper ()
{
$this->LoadVars();
$variables = $this->AdminGetVariablesArray();
$dara = array();
if (count($variables)) {
foreach ($variables as $variable) {
if (isset($_POST[$variable])) {
$data[$variable] = $_POST[$variable];
} else {
$data[$variable] = '';
}
}
$return = $this->AdminConfigureSave($data);
if(is_array($return) && !empty($return)) {
// we have some errors unforunately
return $return;
}
// all went well so save our data
foreach ($data as $key => $value) {
$this->SetVar($key, $value);
}
}
return true;
}
/**
* AdminConfigureSave
* Should be overridden by the child class.
*
* @param array $data The data discovered by the control panel in the save request, passed as a reference, allowing the child class to read or modify data before it is committed, without needing to implement a full custom save solution.
* @return void
*/
public function AdminConfigureSave (&$data)
{
return true;
}
/**
* AdminConfigure
* If a module defines a configuration screen, this function should be overridden by the child class, but should *not* be called through a parent:: call.
*
* @return void
*/
public function AdminConfigure ()
{
$lang = iwp_language::GetInstance();
$this->template->Assign('configFormOutput', '<div style="margin-top:1em;">' . $lang->Get('ModuleHasNoConfigOptions') . '</div>');
}
/**
* This function is the same for all modules and is called to set the values of the form fields when editing a content type
*
* @return array Returns an array of errors if there are any
*/
public function AdminCheckContentTypeSubmission ()
{
$arrFields = $this->AdminGetContentTypeArray();
$errors = $empty = array();
if(isset($arrFields['fields']) && is_array($arrFields['fields'])){
foreach($arrFields['fields'] as $fieldname=>$data){
if($data['type'] == 'textbox') {
if(isset($data['required']) && $data['required'] == true){
if(isset($data['requirebind']) && isset($arrFields['fields'][$data['requirebind']])){
if(!isset($_POST['module_'.$this->moduleName.'_'.$data['requirebind']])){
continue;
}
}
if(!isset($_POST['module_'.$this->moduleName.'_'.$fieldname]) || is_blank($_POST['module_'.$this->moduleName.'_'.$fieldname])){
$errors[] = $this->lang->Get($fieldname.'Missing');
$empty[] = 'module_'.$this->moduleName.'_'.$fieldname;
}else{
iwp_admin_contenttypes::getInstance()->SetFormValue('module_'.$this->moduleName.'_'.$fieldname, htmlspecialchars($_POST['module_'.$this->moduleName.'_'.$fieldname], ENT_QUOTES, iwp_config::Get('charset')));
}
}
}elseif($data['type'] == 'checkbox'){
if(isset($_POST['module_'.$this->moduleName.'_'.$fieldname])){
iwp_admin_contenttypes::getInstance()->SetFormValue('module_'.$this->moduleName.'_'.$fieldname, 'on');
}
}elseif($data['type'] == 'radio'){
if(isset($_POST['module_'.$this->moduleName.'_'.$fieldname])){
iwp_admin_contenttypes::getInstance()->SetFormValue('module_'.$this->moduleName.'_'.$fieldname, htmlspecialchars($_POST['module_'.$this->moduleName.'_'.$fieldname], ENT_QUOTES, iwp_config::Get('charset')));
}
}
}
}
return array($errors, $empty);
}
/**
* This is called after a content type has been saved to save any options for the modules
*
* @return boolean
*/
public function AdminSaveContentTypeSubmission ()
{
$arrFields = $this->AdminGetContentTypeArray();
//$errors = $empty = array();
$ctype = iwp_admin_contenttypes::getInstance();
if(isset($arrFields['fields']) && is_array($arrFields['fields'])){
foreach($arrFields['fields'] as $fieldname=>$data){
if($data['type'] == 'textbox') {
$ctype->SetContentVar($fieldname, $_POST['module_'.$this->moduleName.'_'.$fieldname], $this->GetActiveId());
}elseif($data['type'] == 'checkbox'){
if(isset($_POST['module_'.$this->moduleName.'_'.$fieldname])){
$ctype->SetContentVar($fieldname, $_POST['module_'.$this->moduleName.'_'.$fieldname], $this->GetActiveId());
}else{
$ctype->DeleteContentVar($fieldname, $this->GetActiveId());
}
}elseif($data['type'] == 'radio'){
if(isset($_POST['module_'.$this->moduleName.'_'.$fieldname])){
$ctype->SetContentVar($fieldname, $_POST['module_'.$this->moduleName.'_'.$fieldname], $this->GetActiveId());
}
}
}
}
return true;
}
/**
* This function called by the module framework when the custom module section is called in the admin via index.php?section=module&action=custom&module={modulename}. This function should be overridden by a module extending on iwp_base to implement it's own "view" within the control panel (such as comments moderation by a comments module).
*
* @return void
*/
public function AdminCustom ()
{
// by default, this function does nothing unless a module implements it
return;
}
private $_moduleDataCache = array();
public function GetContentModuleData ($contentId, $forceReload = false)
{
if(!iwp_IsId($contentId)){
return array();
}
$tableName = $this->getTable();
if (!isset($this->_moduleDataCache[$tableName])) {
$this->_moduleDataCache[$tableName] = array();
}
if (!$forceReload && isset($this->_moduleDataCache[$tableName][$contentId])) {
return $this->_moduleDataCache[$tableName][$contentId];
}
$query = "select * from " . $tableName . " where " . $this->contentIdColumn . "=" . (int)$contentId;
$return = $this->db->FetchQuery($query);
if(is_array($return) && sizeof($return) > 0){
$this->_moduleDataCache[$tableName][$contentId] = $return;
return $return;
}
return array();
}
/**
* This function should be declared in all child classes
*
* @return boolean
*/
public function SaveField(){
return true;
}
/**
* This function should be declared in all child classes
*
* @return boolean
*/
public function ValidateSave(){
return true;
}
public function ShowPageByIniUri(){
iwp_controller::getInstance()->ShowPage('NotFound');
}
public function ShowPageByDbUri(){
iwp_controller::getInstance()->ShowPage('NotFound');
}
public function LoadUris($forceRefresh=false){
if(is_array($this->UriList) && sizeof($this->UriList) < 1 && !$forceRefresh){
return;
}
$this->urls->LoadModuleUris();
$this->UriList = $this->urls->GetModuleUrls($this->moduleName);
}
public function GetFrontEndTemplateName(){
return $this->moduleName;
}
public function GetListTemplateName(){
$name = $this->moduleName.'.list';
if(file_exists(IWP_MODULES_PATH . '/' . $this->moduleName . '/templates/' .$name)){
return $name;
}
return false;
}
public function GetFrontEndAppendSection(){
if($this->displayPosition != null){
return $this->displayPosition;
}
return 'contentModules';
}
public function GetCustomCSS(){ /** depreciated **/
$styleFile = IWP_MODULES_PATH . '/' . $this->moduleName . '/templates/styles.css';
if(file_exists($styleFile)){
return @file_get_contents($styleFile);
}else{
return false;
}
}
public function GetModuleCacheSalt(){
return false;
}
public function AppendContent(){
return $this->AppendContent;
}
public function GetListAppendSection(){
return $this->ListAppendSection;
}
public function GetContentTypeVars($id=null){
$content = iwp_content::getInstance();
if(!is_null($id) && iwp_IsId($id)){
$content->Load($id);
}
$contentType = $content->GetContentTypeInstance();
return $contentType->vars->GetVarsByModuleId($this->GetActiveId());
}
public function LoadListOutput(){
}
/**
* Returns a name for a cookie variable name which is unique to this module
*
* @param string $name Name of variable.
* @return string Module-specific name of variable.
*/
public function CookieName ($name)
{
return 'iwp_module_' . $this->moduleName . '_' . $name;
}
/**
* Determines if a value exists for the given cookie variable name
*
* @param string $name Name of variable.
* @return boolean Returns true if value exists, otherwise false
*/
public function CookieExists ($name)
{
return isset($_COOKIE[$this->CookieName($name)]);
}
/**
* Returns the set value of the given cookie variable name.
*
* @param string $name Name of variable.
* @return mixed|bool Returns the value of cookie variable, or false if the variable is not set.
*/
public function GetCookie ($name)
{
if ($this->CookieExists($name)) {
return $_COOKIE[$this->CookieName($name)];
}
return false;
}
/**
* Sets a cookie variable for this module. Must be called before any other output is sent to the browser.
*
* The parameters match the PHP setcookie() function. See the PHP manual for full details: http://php.net/setcookie
*
* @see setcookie
*
* @return bool If output exists prior to calling this function, SetCookie will fail and return FALSE. If setcookie() successfully runs, it will return TRUE. This does not indicate whether the user accepted the cookie.
*/
public function SetCookie ($name, $value = null, $expire = null, $path = null, $domain = null, $secure = null)
{
$name = $this->CookieName($name);
return setcookie($name, $value, $expire, $path, $domain, $secure);
}
/**
* Returns a list of content display fields to display in the content listing grid. This should be overridden by a module extending from iwp_module to return an array, if required.
*
* @return array|boolean Return an array of content display fields, or false if module does not define any.
*/
public function GetContentDisplayFields ()
{
return false;
}
public function Install(){
$this->RunModuleTableQuery();
}
public function SetDefaultSettings (){
return true;
}
public function CreateModuleTable(){
return true;
}
public function RunModuleTableQuery($tableName=null){
$this->CreateModuleTable();
if(!is_array($this->tableSchema)){
$sql = $this->tableSchema;
$tableName = $this->getTable();
}else{
if(is_null($tableName)){
return false;
}
$sql = $this->tableSchema[$tableName];
}
if(is_null($sql)){
return false;
}
if ($this->db->Query("DROP TABLE IF EXISTS `" . $this->db->Quote($tableName) . "`")) {
if ($this->db->Query($sql)) {
return true;
}
}
return false;
}
public function GetLayoutBlocks(){
if(is_array($this->layoutBlocks)){
return $this->layoutBlocks;
}
return array();
}
/**
* This function is called by the admin layout when a request to save a custom block against this module is made.
*
* Module-specific classes extending from this base class should implement this function to return data specific for that module.
*
* @param array $request The requested data for creating block content (usually this is just $_POST)
* @param array $insert The array to insert into the template_data table - passed in by reference and should be modified by the module to include name, title, content, newwindow and uri columns (as needed)
* @return boolean Returns false if a module does not implement saved blocks
*/
public function getSavedBlockInsert ($request, &$insert) {
return false;
}
/**
* This function is called by the admin layout class when a request to edit a saved custom block against this module is made.
*
* Module specific classes extending from this base class should implement this function to return template HTML specific for that module. The HTML will then appear in the modal used for editing the block.
*
* @param int $blockId Numeric block id from database
* @param array $data Data fetched by the layout class from the IWP_TABLE_TEMPLATE_DATA table
* @return mixed Return false if the module does not implement this function, otherwise return an HTML string
*/
public function getEditSavedBlockTemplate ($blockId, $data) {
return false;
}
/**
* Outputs a block for this module which is saved in the template_data table
*
* Module specific classes extending from this base class should implement this function to return HTML specific for that module. The HTML will then appear on the front end.
*
* @param int $blockId The block id to output
* @return string The resulting output HTML
*/
public function OutputSavedBlock ($blockId) {
return '';
}
/**
* Checks to see if the given module exists.
*
* @param String $name
* @return Boolean
*/
public static function isModule($name)
{
// follow module class naming convention
return class_exists('iwp_module_' . $name);
}
/**
* Checks to see if the module is activated by checking to see if its table exists. Since fetchOne will
* return an empty string if a result isn't found, we must check the returned result against the passed
* name. Sort of redundant.
*
* @param String $name
* @return Boolean
*/
public static function isActivated($name)
{
// first check to see if the module even exists
if (!self::isModule($name)) {
return false;
}
// now check to see if it is activated
$res = iwp_base::getInstance()->db->fetchOne('SELECT `codename` FROM ' . IWP_TABLE_MODULES . ' WHERE `codename` = "' . $name . '"');
// redundant; db::fetchOne() returns an empty string if not found
return $res === $name;
}
public function __get($name){
if($name == 'table'){
$this->table = new iwp_tablecreator($this->getTable());
return $this->table;
}
return parent::__get($name);
}
}