mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 12:48:24 +01:00
Issue #3291 Trigger gsitemap event on admin_ui_update .
New universal adminUI events added: admin_ui_create, admin_ui_created, admin_ui_update, admin_ui_updated, admin_ui_delete, admin_ui_deleted. Event data now includes the table that was modified and the configured admin-ui $pluginName
This commit is contained in:
parent
0de1ad8df4
commit
1d080e4f9d
@ -214,7 +214,7 @@ class e_admin_request
|
|||||||
* If $key is array, $value is not used.
|
* If $key is array, $value is not used.
|
||||||
* If $value is null, (string) $key is unset
|
* If $value is null, (string) $key is unset
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string|array $key
|
||||||
* @param object $value [optional]
|
* @param object $value [optional]
|
||||||
* @return e_admin_request
|
* @return e_admin_request
|
||||||
*/
|
*/
|
||||||
@ -669,7 +669,7 @@ class e_admin_response
|
|||||||
* @param string $namespace
|
* @param string $namespace
|
||||||
* @param boolean $reset
|
* @param boolean $reset
|
||||||
* @param boolean|string $glue
|
* @param boolean|string $glue
|
||||||
* @return unknown
|
* @return string|array
|
||||||
*/
|
*/
|
||||||
function getTitle($namespace = 'default', $reset = false, $glue = ' ')
|
function getTitle($namespace = 'default', $reset = false, $glue = ' ')
|
||||||
{
|
{
|
||||||
@ -1920,7 +1920,7 @@ class e_admin_controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Request proxy method
|
* Request proxy method
|
||||||
* @param string $key
|
* @param string|array $key
|
||||||
* @param mixed $value [optional]
|
* @param mixed $value [optional]
|
||||||
* @return e_admin_controller
|
* @return e_admin_controller
|
||||||
*/
|
*/
|
||||||
@ -3331,7 +3331,7 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
/**
|
/**
|
||||||
* Get extended (UI) Form instance
|
* Get extended (UI) Form instance
|
||||||
*
|
*
|
||||||
* @return e_admin_form_ui
|
* @return e_admin_form_ui|mixed
|
||||||
*/
|
*/
|
||||||
public function getUI()
|
public function getUI()
|
||||||
{
|
{
|
||||||
@ -4091,7 +4091,7 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
$fields[$field]['__tableField'] = $att['alias'] ? $att['alias'] : $this->getIfTableAlias(true, true).'.'.$att['field'];
|
$fields[$field]['__tableField'] = $att['alias'] ? $att['alias'] : $this->getIfTableAlias(true, true).'.'.$att['field'];
|
||||||
$fields[$field]['__tableFrom'] = $this->getIfTableAlias(true, true).'.'.$att['field'].($att['alias'] ? ' AS '.$att['alias'] : '');
|
$fields[$field]['__tableFrom'] = $this->getIfTableAlias(true, true).'.'.$att['field'].($att['alias'] ? ' AS '.$att['alias'] : '');
|
||||||
}
|
}
|
||||||
else
|
// else
|
||||||
{
|
{
|
||||||
// $fields[$field]['__tableField'] = $this->getJoinData($fields[$field]['table'], '__tablePath').$field;
|
// $fields[$field]['__tableField'] = $this->getJoinData($fields[$field]['table'], '__tablePath').$field;
|
||||||
}
|
}
|
||||||
@ -4444,7 +4444,7 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(E107_DEBUG_LEVEL == E107_DBG_SQLQUERIES)
|
// if(E107_DEBUG_LEVEL == E107_DBG_SQLQUERIES)
|
||||||
{
|
{
|
||||||
// e107::getDebug()->log(print_a($filter,true));
|
// e107::getDebug()->log(print_a($filter,true));
|
||||||
// e107::getMessage()->addInfo(print_a($filter,true));
|
// e107::getMessage()->addInfo(print_a($filter,true));
|
||||||
@ -4747,19 +4747,12 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
// $model->addMessageInfo(print_a($_posted,true));
|
// $model->addMessageInfo(print_a($_posted,true));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger Admin-ui event. 'pre'
|
$id = $model->getId();
|
||||||
if($triggerName = $this->getEventTriggerName($_posted['etrigger_submit'])) // 'create' or 'update';
|
|
||||||
{
|
|
||||||
$id = $model->getId();
|
|
||||||
$eventData = array('newData'=>$_posted,'oldData'=>$old_data,'id'=> $id);
|
|
||||||
$model->addMessageDebug('Admin-ui Trigger fired: <b>'.$triggerName.'</b>');
|
|
||||||
$this->_log('Triggering Event: '.$triggerName. " (before)");
|
|
||||||
if(E107_DBG_ALLERRORS >0 )
|
|
||||||
{
|
|
||||||
$model->addMessageDebug($triggerName.' data: '.print_a($eventData,true));
|
|
||||||
}
|
|
||||||
|
|
||||||
if($halt = e107::getEvent()->trigger($triggerName, $eventData))
|
// Trigger Plugin Admin-ui event. 'pre'
|
||||||
|
if($triggerName = $this->getEventTriggerName($this->getEventName(), $_posted['etrigger_submit'])) // 'create' or 'update';
|
||||||
|
{
|
||||||
|
if($halt = $this->triggerEvent($triggerName, $_posted,$old_data,$id))
|
||||||
{
|
{
|
||||||
$model->setMessages();
|
$model->setMessages();
|
||||||
return false;
|
return false;
|
||||||
@ -4791,20 +4784,9 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
e107::getAddonConfig('e_admin',null,'process', $this, $id);
|
e107::getAddonConfig('e_admin',null,'process', $this, $id);
|
||||||
|
|
||||||
// Trigger Admin-ui event. 'post'
|
// Trigger Admin-ui event. 'post'
|
||||||
if($triggerName = $this->getEventTriggerName($_posted['etrigger_submit'],'after')) // 'created' or 'updated';
|
if($triggerName = $this->getEventTriggerName( $this->getEventName(), $_posted['etrigger_submit'],'after')) // 'created' or 'updated';
|
||||||
{
|
{
|
||||||
unset($_posted['etrigger_submit'], $_posted['__after_submit_action'], $_posted['submit_value'], $_posted['e-token']);
|
$this->triggerEvent($triggerName, $_posted, $old_data, $id);
|
||||||
|
|
||||||
$pid = $this->getPrimaryName();
|
|
||||||
$_posted[$pid] = $id; // add in the primary ID field.
|
|
||||||
$eventData = array('newData'=>$_posted,'oldData'=>$old_data,'id'=> $id); // use $_posted as it may include unsaved data.
|
|
||||||
$model->addMessageDebug('Admin-ui Trigger fired: <b>'.$triggerName.'</b>');
|
|
||||||
$this->_log('Triggering Event: '.$triggerName." (after)");
|
|
||||||
if(E107_DBG_ALLERRORS >0 )
|
|
||||||
{
|
|
||||||
$model->addMessageDebug($triggerName.' data: '.print_a($eventData,true));
|
|
||||||
}
|
|
||||||
e107::getEvent()->trigger($triggerName, $eventData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($callbackAfter && method_exists($this, $callbackAfter))
|
if($callbackAfter && method_exists($this, $callbackAfter))
|
||||||
@ -4832,19 +4814,62 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trigger 2 events. The $triggerName event, and a matching generic admin_ui_xxxxx event.
|
||||||
|
* @param string $triggerName
|
||||||
|
* @param array $_posted
|
||||||
|
* @param array $old_data
|
||||||
|
* @param int $id
|
||||||
|
* @return false|mixed
|
||||||
|
*/
|
||||||
|
protected function triggerEvent($triggerName, $_posted, $old_data, $id)
|
||||||
|
{
|
||||||
|
unset($_posted['etrigger_submit'], $_posted['__after_submit_action'], $_posted['submit_value'], $_posted['e-token']);
|
||||||
|
|
||||||
|
$pid = $this->getPrimaryName();
|
||||||
|
$_posted[$pid] = $id; // add in the primary ID field.
|
||||||
|
|
||||||
|
$eventData = array( // use $_posted as it may include unsaved data.
|
||||||
|
'newData' => $_posted,
|
||||||
|
'oldData' => $old_data,
|
||||||
|
'id' => $id,
|
||||||
|
'table' => $this->getTableName(),
|
||||||
|
'plugin' => $this->getPluginName(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->_log('Triggering Event: ' . $triggerName);
|
||||||
|
|
||||||
|
$tmp = explode("_", $triggerName);
|
||||||
|
$name = end($tmp);
|
||||||
|
|
||||||
|
$adminTriggerName = 'admin_ui_'.$name;
|
||||||
|
|
||||||
|
|
||||||
|
e107::getMessage()->addDebug("Event triggers fired (<b>".$triggerName."</b>, <b>". $adminTriggerName."</b>)
|
||||||
|
<a class='e-expandit' href='#view-event-data-".$name."'>Toggle data</a>
|
||||||
|
<div id='view-event-data-".$name."' class='e-hideme'>" . print_a($eventData, true)."</div>"
|
||||||
|
);
|
||||||
|
|
||||||
|
if($halt = e107::getEvent()->trigger($adminTriggerName, $eventData))
|
||||||
|
{
|
||||||
|
return $halt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return e107::getEvent()->trigger($triggerName, $eventData);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a custom event trigger name
|
* Return a custom event trigger name
|
||||||
* @param null $type Usually 'Create' or 'Update'
|
* @param null $type Usually 'Create' or 'Update'
|
||||||
* @param string $when ' before or after
|
* @param string $when ' before or after
|
||||||
* @return bool|string
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
public function getEventTriggerName($type=null, $when='before')
|
public function getEventTriggerName($name, $type=null, $when='before')
|
||||||
{
|
{
|
||||||
$plug = $this->getEventName();
|
if(empty($name) || empty($type))
|
||||||
|
|
||||||
if(empty($plug) || empty($type))
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($when === 'after')
|
if($when === 'after')
|
||||||
@ -4852,7 +4877,7 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
$type .= 'd'; // ie. 'created' or 'updated'.
|
$type .= 'd'; // ie. 'created' or 'updated'.
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'admin_'.strtolower($plug).'_'.strtolower($type);
|
return 'admin_'.strtolower($name).'_'.strtolower($type);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5075,7 +5100,7 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
/**
|
/**
|
||||||
* Catch batch submit
|
* Catch batch submit
|
||||||
* @param string $batch_trigger
|
* @param string $batch_trigger
|
||||||
* @return none
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function ListBatchTrigger($batch_trigger)
|
public function ListBatchTrigger($batch_trigger)
|
||||||
{
|
{
|
||||||
@ -5095,7 +5120,7 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
/**
|
/**
|
||||||
* Catch batch submit
|
* Catch batch submit
|
||||||
* @param string $batch_trigger
|
* @param string $batch_trigger
|
||||||
* @return none
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function GridBatchTrigger($batch_trigger)
|
public function GridBatchTrigger($batch_trigger)
|
||||||
{
|
{
|
||||||
@ -5658,7 +5683,7 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
/**
|
/**
|
||||||
* Batch default (field) trigger
|
* Batch default (field) trigger
|
||||||
* @param array $selected
|
* @param array $selected
|
||||||
* @return void
|
* @return int|null
|
||||||
*/
|
*/
|
||||||
protected function handleListBatch($selected, $field, $value)
|
protected function handleListBatch($selected, $field, $value)
|
||||||
{
|
{
|
||||||
@ -5681,7 +5706,7 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
|
|
||||||
if($field === 'options') // reserved field type. see: admin -> media-manager - batch rotate image.
|
if($field === 'options') // reserved field type. see: admin -> media-manager - batch rotate image.
|
||||||
{
|
{
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -5703,7 +5728,7 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
/**
|
/**
|
||||||
* Catch delete submit
|
* Catch delete submit
|
||||||
* @param string $batch_trigger
|
* @param string $batch_trigger
|
||||||
* @return none
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function ListDeleteTrigger($posted)
|
public function ListDeleteTrigger($posted)
|
||||||
{
|
{
|
||||||
@ -5729,21 +5754,14 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
$data = $model->getData();
|
$data = $model->getData();
|
||||||
if($this->beforeDelete($data, $id))
|
if($this->beforeDelete($data, $id))
|
||||||
{
|
{
|
||||||
|
|
||||||
$eventData = array('oldData'=>$data,'id'=> $id);
|
if($triggerName = $this->getEventTriggerName($this->getEventName(),'delete')) // trigger for before.
|
||||||
|
|
||||||
if($triggerName = $this->getEventTriggerName('delete')) // trigger for before.
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if(E107_DBG_ALLERRORS >0 )
|
if($halt = $this->triggerEvent($triggerName, null, $data, $id))
|
||||||
{
|
|
||||||
$this->getTreeModel()->addMessageDebug('Admin-ui Trigger fired: <b>'.$triggerName.'</b> with data '.print_a($eventData,true));
|
|
||||||
}
|
|
||||||
|
|
||||||
if($halt = e107::getEvent()->trigger($triggerName, $eventData))
|
|
||||||
{
|
{
|
||||||
$this->getTreeModel()->setMessages();
|
$this->getTreeModel()->setMessages();
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5751,13 +5769,9 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
|
|
||||||
if($this->afterDelete($data, $id, $check))
|
if($this->afterDelete($data, $id, $check))
|
||||||
{
|
{
|
||||||
if($triggerName = $this->getEventTriggerName('deleted')) // trigger for after.
|
if($triggerName = $this->getEventTriggerName($this->getEventName(), 'deleted')) // trigger for after.
|
||||||
{
|
{
|
||||||
if(E107_DBG_ALLERRORS > 0)
|
$this->triggerEvent($triggerName, null, $data, $id);
|
||||||
{
|
|
||||||
$this->getTreeModel()->addMessageDebug('Admin-ui Trigger fired: <b>'.$triggerName.'</b>'); //FIXME - Why doesn't this display?
|
|
||||||
}
|
|
||||||
e107::getEvent()->trigger($triggerName, $eventData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->getTreeModel()->setMessages();
|
$this->getTreeModel()->setMessages();
|
||||||
@ -5825,7 +5839,7 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
|
|
||||||
$this->addTitle();
|
$this->addTitle();
|
||||||
|
|
||||||
if($this->getQuery('filter_options'))
|
// if($this->getQuery('filter_options'))
|
||||||
{
|
{
|
||||||
// var_dump($this);
|
// var_dump($this);
|
||||||
// $this->addTitle("to-do"); // display filter option when active.
|
// $this->addTitle("to-do"); // display filter option when active.
|
||||||
@ -6270,6 +6284,7 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
*/
|
*/
|
||||||
public function beforePrefsSave($new_data, $old_data)
|
public function beforePrefsSave($new_data, $old_data)
|
||||||
{
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -6277,7 +6292,7 @@ class e_admin_ui extends e_admin_controller_ui
|
|||||||
*/
|
*/
|
||||||
public function afterPrefsSave()
|
public function afterPrefsSave()
|
||||||
{
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
81
e107_plugins/gsitemap/e_event.php
Normal file
81
e107_plugins/gsitemap/e_event.php
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* e107 website system
|
||||||
|
*
|
||||||
|
* Copyright (C) 2008-2013 e107 Inc (e107.org)
|
||||||
|
* Released under the terms and conditions of the
|
||||||
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||||
|
* XXX HIGHLY EXPERIMENTAL AND SUBJECT TO CHANGE WITHOUT NOTICE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('e107_INIT')) { exit; }
|
||||||
|
|
||||||
|
|
||||||
|
class gsitemap_event // plugin-folder + '_event'
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure functions/methods to run when specific e107 events are triggered.
|
||||||
|
* For a list of events, please visit: http://e107.org/developer-manual/classes-and-methods#events
|
||||||
|
* Developers can trigger their own events using: e107::getEvent()->trigger('plugin_event',$array);
|
||||||
|
* Where 'plugin' is the folder of their plugin and 'event' is a unique name of the event.
|
||||||
|
* $array is data which is sent to the triggered function. eg. myfunction($array) in the example below.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function config()
|
||||||
|
{
|
||||||
|
|
||||||
|
$event = array();
|
||||||
|
|
||||||
|
$event[] = array(
|
||||||
|
'name' => "admin_ui_updated", /* when this is triggered... (@see http://e107.org/developer-manual/classes-and-methods#events) */
|
||||||
|
'function' => "update", // ..run this function (see below).
|
||||||
|
);
|
||||||
|
|
||||||
|
return $event;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function update($data) // the method to run.
|
||||||
|
{
|
||||||
|
e107::getMessage()->addDebug("GSITEMAP TRIGGERRED!!") ;
|
||||||
|
|
||||||
|
|
||||||
|
if(empty($data['table']) || empty($data['newData']))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
switch ($data['table'])
|
||||||
|
{
|
||||||
|
case "news":
|
||||||
|
$update = array(
|
||||||
|
'gsitemap_url' => e107::getUrl()->create('news/view/item', $data['newData'], array('full' => 1)),
|
||||||
|
'WHERE' => "gsitemap_table = 'news' AND gsitemap_table_id = ".(int) $data['id']
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "page":
|
||||||
|
// code
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($update))
|
||||||
|
{
|
||||||
|
if(e107::getDb()->update('gsitemap', $update)!==false)
|
||||||
|
{
|
||||||
|
e107::getMessage()->addDebug("Gsitemap updated: ".print_a($update,true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} //end class
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user