From 24d0f0a945e34b3f643b2e31b118498deddcb43a Mon Sep 17 00:00:00 2001 From: tomolimo Date: Tue, 7 Jun 2016 10:05:00 +0200 Subject: [PATCH] Release 2.0.0 Changed filter mechanism: simplified it. Two kind of filters: type 0 for ticket content and type 1 for ticket title. Filters are now complete regex from / to / Added a web interface to edit filters --- README.md | 9 ++ front/filter.form.php | 76 ++++++++++ front/filter.php | 16 ++ hook.php | 223 +++++++++++++-------------- inc/filter.class.php | 343 ++++++++++++++++++++++++++++++++++++++++++ inc/menu.class.php | 42 ++++++ setup.php | 16 +- ticketcleaner.xml | 25 ++- 8 files changed, 623 insertions(+), 127 deletions(-) create mode 100644 front/filter.form.php create mode 100644 front/filter.php create mode 100644 inc/filter.class.php create mode 100644 inc/menu.class.php diff --git a/README.md b/README.md index 9e3b388..86a6acd 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,12 @@ New home for Ticket Cleaner GLPi plugin Currently mirrors https://forge.glpi-project.org/projects/ticketcleaner + + +# Release 2.0.0 +Beware that this new release will not keep your existing filters. You'll have to input them again with the new interface that permits to edit them directly into GLPi. +Your former filters will be copied into a backup table that you may edit via your preferred mySQL query editor (table name is `backup_glpi_plugin_ticketcleaner_filters`). +You'll have to combine your former filters to get the new ones that will be entered into the new table, or to create new one from scratch. + +This version also brings the possibility to debug your regex using the GLPi debug mode (see wiki). + diff --git a/front/filter.form.php b/front/filter.form.php new file mode 100644 index 0000000..eaeac09 --- /dev/null +++ b/front/filter.form.php @@ -0,0 +1,76 @@ +. +-------------------------------------------------------------------------- + */ + +/** @file + * @brief + */ + +include ('../../../inc/includes.php'); + +if (empty($_GET["id"])) { + $_GET["id"] = ''; +} + +Session::checkLoginUser(); + +$filter = new PluginTicketcleanerFilter(); +if (isset($_POST["add"])) { + $filter->check(-1, CREATE, $_POST); + + $newID = $filter->add($_POST); + if ($_SESSION['glpibackcreated']) { + Html::redirect($filter->getFormURL()."?id=".$newID); + } else { + Html::back(); + } + +} else if (isset($_POST["purge"])) { + $filter->check($_POST["id"], PURGE); + $filter->delete($_POST,1); + + $filter->redirectToList(); + +} else if (isset($_POST["update"])) { + + $filter->check($_POST["id"], UPDATE); + + $filter->update($_POST); + + Html::back(); + +} else { + Html::header(__('Ticket Cleaner - Filters','ticketcleaner'), $_SERVER['PHP_SELF'] , "config", "PluginTicketcleanerMenu", "ticketcleanerfilter"); + $filter->display($_GET); + Html::footer(); +} +?> diff --git a/front/filter.php b/front/filter.php new file mode 100644 index 0000000..8ed0a14 --- /dev/null +++ b/front/filter.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/hook.php b/hook.php index eef70a5..2bce656 100644 --- a/hook.php +++ b/hook.php @@ -2,7 +2,7 @@ // ---------------------------------------------------------------------- // Original Author of file: Olivier Moron -// Purpose of file: Provides cleaning of Ticket, for title, description +// Purpose of file: Provides cleaning of Ticket, for title, description // and followups. // It cleans text for creation and edition (from email or from web interface) // and it cleans attached pictures to emails @@ -12,32 +12,32 @@ /** * Summary of loadSha1IntoDB * This function checks if an update of SHA is mandatory - * The check is based on last modification date of folder 'pictures' + * The check is based on last modification date of folder 'pictures' * If last modification date is more recent than the saved date in DB, * then a refreh is started. - * - * Will save the file name and SHA into DB, in table 'glpi_plugin_ticketcleaner_picturehashes' + * + * Will save the file name and SHA into DB, in table 'glpi_plugin_ticketcleaner_picturehashes' * for each file found in the 'pictures' folder */ function loadSha1IntoDB(){ global $DB; - + // now fill the table // get files from plugin pictures folder $dir = GLPI_ROOT . "/plugins/ticketcleaner/pictures" ; $files = scandir( $dir ) ; - + $lastupdate ="" ; $query = "SELECT * FROM `glpi_plugin_ticketcleaner_picturehashes_lastupdate`;" ; $res = $DB->query($query) ; if($DB->numrows($res) > 0) { $row = $DB->fetch_array($res) ; - $lastupdate = $row['lastupdate']; + $lastupdate = $row['lastupdate']; } - + $stats = stat($dir); $datetime = date( "YmdHis", $stats['mtime'] ); - + if( $datetime > $lastupdate ) { // means picture folder has been modified since last update $DB->query("TRUNCATE TABLE glpi_plugin_ticketcleaner_picturehashes") ; //or die("error on 'truncate' glpi_plugin_ticketcleaner_picturehashes ". $DB->error()) ; // compute hash for each file and then insert it in DB with REPLACE INTO to prvent double entries @@ -48,8 +48,8 @@ function loadSha1IntoDB(){ $DB->query($query) or die("error on 'insert' into glpi_plugin_ticketcleaner_picturehashes with ".$pict." hash: ". $DB->error()); } } - - if( count($files) ) + + if( count($files) ) Toolbox::logInFile('TicketCleaner', "Loading of sha1 files from '".$dir."' into DB done.\n" ) ; else Toolbox::logInFile('TicketCleaner', "No files in '".$dir."'.\n" ) ; @@ -57,7 +57,7 @@ function loadSha1IntoDB(){ // update of lastupdate into DB, with $datetime $query = "REPLACE INTO `glpi_plugin_ticketcleaner_picturehashes_lastupdate` SET lastupdate='".$datetime."', id=1;" ; $res = $DB->query($query) ; - + } } @@ -69,84 +69,96 @@ function loadSha1IntoDB(){ */ function plugin_ticketcleaner_install() { global $DB ; - + if (!TableExists("glpi_plugin_ticketcleaner_picturehashes_lastupdate")) { $query = "CREATE TABLE `glpi_plugin_ticketcleaner_picturehashes_lastupdate` ( `id` INT(10) NOT NULL AUTO_INCREMENT, `lastupdate` VARCHAR(50) NULL, - PRIMARY KEY (`id`) + PRIMARY KEY (`id`) ) COLLATE='utf8_general_ci' - ENGINE=MyISAM; + ENGINE=InnoDB; "; - + $DB->query($query) or die("error creating glpi_plugin_ticketcleaner_picturehashes_lastupdate " . $DB->error()); } - - + + if (!TableExists("glpi_plugin_ticketcleaner_picturehashes")) { $query = "CREATE TABLE `glpi_plugin_ticketcleaner_picturehashes` ( `id` INT(10) NOT NULL AUTO_INCREMENT, `hash` CHAR(40) NOT NULL, `filename` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`), - INDEX `hash` (`hash`) + INDEX `hash` (`hash`) ) COLLATE='utf8_general_ci' - ENGINE=MyISAM; + ENGINE=InnoDB; "; $DB->query($query) or die("error creating glpi_plugin_ticketcleaner_picturehashes " . $DB->error()); } - + loadSha1IntoDB() ; // also done on the fly - + + if( TableExists("backup_glpi_plugin_ticketcleaner_filters") ) { + $query = "DROP TABLE `backup_glpi_plugin_ticketcleaner_filters`;"; + $DB->query($query) or die("error droping old backup_glpi_plugin_ticketcleaner_filters" . $DB->error()); + } + + if( TableExists("glpi_plugin_ticketcleaner_filters") && FieldExists( 'glpi_plugin_ticketcleaner_filters', 'filter' ) ) { + + $query = "RENAME TABLE `glpi_plugin_ticketcleaner_filters` TO `backup_glpi_plugin_ticketcleaner_filters`;"; + $DB->query($query) or die("error renaming glpi_plugin_ticketcleaner_filters to backup_glpi_plugin_ticketcleaner_filters" . $DB->error()); + } + if (!TableExists("glpi_plugin_ticketcleaner_filters")) { - $query = "CREATE TABLE `glpi_plugin_ticketcleaner_filters` ( - `id` INT(10) NOT NULL AUTO_INCREMENT, - `type` INT(1) NOT NULL, - `order` INT(2) NOT NULL, - `filter` VARCHAR(255) NOT NULL, - `regex` VARCHAR(255) NOT NULL, - `replacement` VARCHAR(255) NOT NULL DEFAULT '' , - `description` TEXT NULL, - `active` INT(1) NULL DEFAULT NULL, - PRIMARY KEY (`id`), - INDEX `type` (`type`) - ) - COLLATE='utf8_general_ci' - ENGINE=MyISAM; - "; + $query = " + CREATE TABLE `glpi_plugin_ticketcleaner_filters` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL, + `type` INT(1) NOT NULL DEFAULT '1', + `order` INT(11) NOT NULL, + `regex` VARCHAR(255) NOT NULL, + `replacement` VARCHAR(255) NOT NULL DEFAULT '', + `is_active` INT(1) NOT NULL DEFAULT '0', + `comment` TEXT NULL, + `date_mod` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `type` (`type`) + ) + COLLATE='utf8_general_ci' + ENGINE=InnoDB + ;"; $DB->query($query) or die("error creating glpi_plugin_ticketcleaner_filters " . $DB->error()); - - } - + } + return true; } /** * Summary of plugin_ticketcleaner_uninstall - * Drop tables containing SHA and last update date, + * Drop tables containing SHA and last update date, * but keeps the filters * @return true or 'die'! */ function plugin_ticketcleaner_uninstall() { global $DB; - + // Current version tables if (TableExists("glpi_plugin_ticketcleaner_picturehashes")) { $query = "DROP TABLE `glpi_plugin_ticketcleaner_picturehashes`"; $DB->query($query) or die("error deleting glpi_plugin_ticketcleaner_picturehashes"); } - + if (TableExists("glpi_plugin_ticketcleaner_picturehashes_lastupdate")) { $query = "DROP TABLE `glpi_plugin_ticketcleaner_picturehashes_lastupdate`"; $DB->query($query) or die("error deleting glpi_plugin_ticketcleaner_picturehashes_lastupdate"); } - - + + return true; } @@ -169,99 +181,80 @@ class PluginTicketCleaner { * 0: regex for begin of signature * 1: regex for end of signature * 2 : filters of this type are used to delete (or replace) any text that will match a regex from content of Tickets or content of Followups - * 3 : filters of this type are used to delete (or replace) any text that will match a regex from name (=title) of Tickets + * 3 : filters of this type are used to delete (or replace) any text that will match a regex from name (=title) of Tickets * orders (0 - n): used to apply filters in this defined order * see filter examples in Plugin website */ public static function cleanText($parm) { global $DB ; - + $is_content = array_key_exists('content', $parm->input) ; $is_name = array_key_exists('name', $parm->input) ; - - if( $is_content || $is_name ) { + + if( $is_content || $is_name ) { // load filters from DB $filters = array( ) ; - $query = "SELECT * FROM glpi_plugin_ticketcleaner_filters WHERE active=1 ORDER BY type, `order`;" ; - + $query = "SELECT * FROM glpi_plugin_ticketcleaner_filters WHERE is_active=1 ORDER BY type, `order`;" ; + // preparation for starts of filter foreach ($DB->request($query) as $filter){ - if($filter['type'] == 0){ - if( array_key_exists('start', $filters ) ) - $filters['start'] .= '|' ; - else - $filters['start'] = '' ; - $filters['start'] .= $filter['regex'] ; - } - elseif($filter['type'] == 1){ - if( array_key_exists('end', $filters ) ) - $filters['end'] .= '|' ; - else - $filters['end'] = '' ; - $filters['end'] .= $filter['regex'] ; - } - elseif($filter['type'] == 2){ - $filters['replace'][] = array( 'regex' => $filter['regex'], 'replacement' => $filter['replacement'] ) ; - } - elseif($filter['type'] == 3){ - $filters['replace_in_title'][] = array( 'regex' => $filter['regex'], 'replacement' => $filter['replacement'] ) ; - } + $filters[ $filter['type'] ][] = $filter ; } - } - - if( $is_content ) { - // deletes signature from description field $parm->input['content'] - // deletes duplicated \r\n - // deletes [cid:...] - - $ptn = '/('.$filters['start'].').*?('.$filters['end'].')/iu' ; - - // applies filter - $parm->input['content'] = preg_replace( $ptn, '', $parm->input['content'] ) ; - - foreach($filters['replace'] as $ptn){ - $parm->input['content'] = preg_replace( '/'.$ptn['regex'].'/iu', $ptn['replacement'], $parm->input['content'] ) ; - } - } - if( $is_name ) { - foreach($filters['replace_in_title'] as $ptn){ - $parm->input['name'] = preg_replace( '/'.$ptn['regex'].'/iu', $ptn['replacement'], $parm->input['name'] ) ; - } - } + if( $is_content && isset($filters[ PluginTicketcleanerFilter::DESCRIPTION_TYPE ])) { + $temp_content = html_entity_decode( $parm->input['content'], ENT_QUOTES); + if( isset($_SESSION['glpi_use_mode']) && ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE)) { + Toolbox::logInFile('TicketCleaner', "\tInitial text content: " . $temp_content . "\n" ) ; + } + foreach($filters[ PluginTicketcleanerFilter::DESCRIPTION_TYPE ] as $ptn){ + $temp_content = preg_replace( $ptn['regex'], $ptn['replacement'], $temp_content ); + if( isset($_SESSION['glpi_use_mode']) && ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE)) { + Toolbox::logInFile('TicketCleaner', "\tAfter filter: " . $ptn['name'] . "\t text: " . $temp_content . "\n" ) ; + } + } + $parm->input['content'] = htmlentities( $temp_content, ENT_QUOTES) ; + } + + if( $is_name && isset($filters[ PluginTicketcleanerFilter::TITLE_TYPE ]) ) { + foreach($filters[ PluginTicketcleanerFilter::TITLE_TYPE ] as $ptn){ + $parm->input['name'] = preg_replace( $ptn['regex'], $ptn['replacement'], $parm->input['name'] ) ; + } + } + + } } /** * Summary of cleanImages * @param $parm contains current object (i.e. a Ticket or a TicketFollowup) - * For each picture a log is written into TicketCleaner log file to indicate + * For each picture a log is written into TicketCleaner log file to indicate * if it has been deleted or not */ public static function cleanImages($parm){ global $DB ; - + // this ticket has been created via email receiver. // has any FILE attached to it? - if( array_key_exists('name', $parm->input) - && array_key_exists('_mailgate', $parm->input) - && array_key_exists('filename', $_FILES) + if( array_key_exists('name', $parm->input) + && array_key_exists('_mailgate', $parm->input) + && array_key_exists('filename', $_FILES) && array_key_exists('tmp_name', $_FILES['filename']) ) { - + // if necessary will reload sha1 loadSha1IntoDB() ; - + $msg_log = "Ticket: '".$parm->input['name']."'\n"; - + // signature FILES are deleted from array $_FILES - + // load pictures signatures from DB $files_hash = array( ) ; $query = "SELECT hash FROM glpi_plugin_ticketcleaner_picturehashes" ; - + foreach ($DB->request($query) as $data){ $files_hash[] = $data['hash'] ; } - + $deleted = false ; foreach( $_FILES['filename']['tmp_name'] as $loc_key => $loc_file) { $loc_type = $_FILES['filename']['type'][$loc_key] ; @@ -269,7 +262,7 @@ public static function cleanImages($parm){ $loc_deleted = false ; if( stripos( $loc_type, "IMAGE/") !== false){ $loc_sha = sha1_file( $loc_file ) ; - + if( in_array($loc_sha, $files_hash) ) { unset($_FILES['filename']['size'][$loc_key]) ; unset($_FILES['filename']['name'][$loc_key]) ; @@ -286,9 +279,9 @@ public static function cleanImages($parm){ else $msg_log .= "\tFile: '".$loc_file."'\ttype: '".$loc_type."'\n" ; } - + Toolbox::logInFile('TicketCleaner', $msg_log ) ; - + if( $deleted ){ // to re-index the arrays $_FILES['filename']['size'] = array_values( $_FILES['filename']['size'] ) ; @@ -306,24 +299,24 @@ public static function cleanImages($parm){ */ public static function plugin_pre_item_add_ticketcleaner($parm) { global $DB, $GLOBALS ; - - PluginTicketCleaner::cleanText($parm) ; - PluginTicketCleaner::cleanImages($parm) ; + PluginTicketCleaner::cleanText($parm) ; + + PluginTicketCleaner::cleanImages($parm) ; } - + /** * Summary of plugin_pre_item_add_ticketcleaner_followup * @param $parm contains current object (i.e. a Ticket or a TicketFollowup) */ public static function plugin_pre_item_add_ticketcleaner_followup($parm) { global $DB ; - + PluginTicketCleaner::cleanText($parm) ; - + PluginTicketCleaner::cleanImages($parm) ; - + } /** @@ -333,7 +326,7 @@ public static function plugin_pre_item_add_ticketcleaner_followup($parm) { public static function plugin_pre_item_update_ticketcleaner($parm) { PluginTicketCleaner::cleanText($parm) ; } - + /** * Summary of plugin_pre_item_update_ticketcleaner_followup * @param $parm contains current object (i.e. a Ticket or a TicketFollowup) @@ -341,7 +334,7 @@ public static function plugin_pre_item_update_ticketcleaner($parm) { public static function plugin_pre_item_update_ticketcleaner_followup($parm) { PluginTicketCleaner::cleanText($parm) ; } - + } ?> \ No newline at end of file diff --git a/inc/filter.class.php b/inc/filter.class.php new file mode 100644 index 0000000..724cb47 --- /dev/null +++ b/inc/filter.class.php @@ -0,0 +1,343 @@ +1) { + return __('Filters','ticketcleaner'); + } + return __('Filter','ticketcleaner'); + } + + /** + * Summary of getSearchOptions + * @return mixed + */ + function getSearchOptions() { + global $LANG; + + $tab = array(); + + $tab['common'] = __('Filter','ticketcleaner'); + + $tab[1]['table'] = $this->getTable(); + $tab[1]['field'] = 'name'; + $tab[1]['name'] = __('Name'); + $tab[1]['datatype'] = 'itemlink'; + $tab[1]['searchtype'] = 'contains'; + $tab[1]['massiveaction'] = false; + $tab[1]['itemlink_type'] = $this->getType(); + + $tab[8]['table'] = $this->getTable(); + $tab[8]['field'] = 'is_active'; + $tab[8]['name'] = __('Active'); + $tab[8]['massiveaction'] = true; + $tab[8]['datatype'] = 'bool'; + + $tab[4]['table'] = $this->getTable(); + $tab[4]['field'] = 'comment'; + $tab[4]['name'] = __('Comments'); + $tab[4]['massiveaction'] = true; + $tab[4]['datatype'] = 'text'; + + $tab[19]['table'] = $this->getTable(); + $tab[19]['field'] = 'date_mod'; + $tab[19]['name'] = __('Last update'); + $tab[19]['datatype'] = 'datetime'; + $tab[19]['massiveaction'] = false; + + //$tab[802]['table'] = $this->getTable(); + //$tab[802]['field'] = 'css_selector_value'; + //$tab[802]['name'] = __('Value CSS selector', 'ticketcleaner'); + //$tab[802]['massiveaction'] = false; + //$tab[802]['datatype'] = 'dropdown'; + + $tab[900]['table'] = $this->getTable(); + $tab[900]['field'] = 'type'; + $tab[900]['name'] = __('Type', 'ticketcleaner'); + $tab[900]['massiveaction'] = false; + $tab[900]['searchtype'] = 'equals'; + $tab[900]['datatype'] = 'specific'; + + $tab[901]['table'] = $this->getTable(); + $tab[901]['field'] = 'order'; + $tab[901]['name'] = __('Order', 'ticketcleaner'); + $tab[901]['massiveaction'] = false; + //$tab[901]['searchtype'] = 'equals'; + + $tab[902]['table'] = $this->getTable(); + $tab[902]['field'] = 'regex'; + $tab[902]['name'] = __('RegEx', 'ticketcleaner'); + $tab[902]['massiveaction'] = false; + + $tab[903]['table'] = $this->getTable(); + $tab[903]['field'] = 'replacement'; + $tab[903]['name'] = __('Replacement', 'ticketcleaner'); + $tab[903]['massiveaction'] = false; + + + return $tab; + } + + /** + * @since version 0.84 + * + * @param $field + * @param $values + * @param $options array + **/ + static function getSpecificValueToDisplay($field, $values, array $options=array()) { + + if (!is_array($values)) { + $values = array($field => $values); + } + switch ($field) { + + + case 'type': + return self::getFilterTypeName($values[$field]); + } + return parent::getSpecificValueToDisplay($field, $values, $options); + } + + /** + * @since version 0.84 + * + * @param $field + * @param $name (default '') + * @param $values (default '') + * @param $options array + * + * @return string + **/ + static function getSpecificValueToSelect($field, $name='', $values='', array $options=array()) { + + if (!is_array($values)) { + $values = array($field => $values); + } + $options['display'] = false; + switch ($field) { + + case 'type': + $options['value'] = $values[$field]; + return self::dropdownType($name, $options); + } + return parent::getSpecificValueToSelect($field, $name, $values, $options); + } + + + + /** + * Dropdown of ticket type + * + * @param $name select name + * @param $options array of options: + * - value : integer / preselected value (default 0) + * - toadd : array / array of specific values to add at the begining + * - on_change : string / value to transmit to "onChange" + * - display : boolean / display or get string (default true) + * + * @return string id of the select + **/ + static function dropdownType($name, $options=array()) { + + $params['value'] = 0; + $params['toadd'] = array(); + $params['on_change'] = ''; + $params['display'] = true; + + if (is_array($options) && count($options)) { + foreach ($options as $key => $val) { + $params[$key] = $val; + } + } + + $items = array(); + if (count($params['toadd']) > 0) { + $items = $params['toadd']; + } + + $items += self::getFilterTypes(); + + return Dropdown::showFromArray($name, $items, $params); + } + + /** + * Get ticket types + * + * @return array of types + **/ + static function getFilterTypes() { + + $options[self::DESCRIPTION_TYPE] = self::getFilterTypeName(self::DESCRIPTION_TYPE); + $options[self::TITLE_TYPE] = self::getFilterTypeName(self::TITLE_TYPE); + + return $options; + } + + + /** + * Get ticket type Name + * + * @param $value type ID + **/ + static function getFilterTypeName($value) { + + switch ($value) { + case self::DESCRIPTION_TYPE : + return __('Description', 'ticketcleaner'); + + case self::TITLE_TYPE : + return __('Title','ticketcleaner'); + + default : + // Return $value if not defined + return $value; + } + } + + /** + * @since version 0.85 + * + * @see CommonGLPI::getTabNameForItem() + **/ + function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { + + if (static::canView()) { + $nb = 0; + switch ($item->getType()) { + + case 'PluginTicketcleanerFilter' : + return PluginTicketcleanerFilter::getTypeName(Session::getPluralNumber()); + } + } + return ''; + } + + + function defineTabs($options=array()) { + + // $ong = array('empty' => $this->getTypeName(1)); + $ong = array(); + $this->addDefaultFormTab($ong); + //$this->addStandardTab(__CLASS__, $ong, $options); + + //$this->addStandardTab('PluginTicketcleanerFilter', $ong, $options); + + return $ong; + } + + function showForm ($ID, $options=array('candel'=>false)) { + global $DB, $CFG_GLPI, $LANG; + + if ($ID > 0) { + $this->check($ID,READ); + } + + $canedit = $this->can($ID,UPDATE); + $options['canedit'] = $canedit ; + + $this->initForm($ID, $options); + + + $this->showFormHeader($options); + + echo ""; + echo "".__("Name")." :"; + echo ""; + echo "".__("Comments")." :"; + echo ""; + echo ""; + + echo ""; + echo "".__("Active")." :"; + echo "" ; + Html::showCheckbox(array('name' => 'is_active', + 'checked' => $this->fields['is_active'] + )); + echo ""; + + echo ""; + + echo ""; + echo "".__('Type', 'ticketcleaner')." :"; + //echo ""; + echo ""; + $opt = array('value' => $this->fields["type"]); + self::dropdownType('type', $opt); + echo ""; + echo ""; + + echo ""; + echo "".__('order', 'ticketcleaner')." :"; + echo ""; + echo ""; + + echo ""; + echo "".__('RegEx', 'ticketcleaner')." :"; + echo ""; + echo ""; + + echo ""; + echo "".__("Replacement", 'ticketcleaner')." :"; + echo ""; + echo ""; + + if( version_compare(GLPI_VERSION,'9.1','lt') ) { + echo ""; + echo "".__('Last modification')." :"; + echo Html::convDateTime($this->fields["date_mod"]); + echo ""; + } + + + echo " "; + echo ""; + + echo ""; + echo ""; + + $this->showFormButtons($options ); + //$this->addDivForTabs(); + + } + + function prepareInputForAdd($input) { + if(isset( $input['regex'] ) ) { + $input['regex'] = html_entity_decode( $input['regex']) ; + } + return $input ; + } + + function prepareInputForUpdate($input) { + if(isset( $input['regex'] ) ) { + $input['regex'] = html_entity_decode( $input['regex']) ; + } + + return $input ; + } + + +} + diff --git a/inc/menu.class.php b/inc/menu.class.php new file mode 100644 index 0000000..2254918 --- /dev/null +++ b/inc/menu.class.php @@ -0,0 +1,42 @@ + 'ticketcleanerfilter'); + + foreach ($itemtypes as $itemtype => $option) { + $menu['options'][$option]['title'] = $itemtype::getTypeName(Session::getPluralNumber()); + switch( $itemtype ) { + case 'PluginTicketcleanerFilter': + $menu['options'][$option]['page'] = $itemtype::getSearchURL(false); + $menu['options'][$option]['links']['search'] = $itemtype::getSearchURL(false); + if ($itemtype::canCreate()) { + $menu['options'][$option]['links']['add'] = $itemtype::getFormURL(false); + } + break ; + default : + $menu['options'][$option]['page'] = PluginTicketcleanerFilter::getSearchURL(false); + break ; + } + + } + return $menu; + } + + +} \ No newline at end of file diff --git a/setup.php b/setup.php index 11e3364..fb3775c 100644 --- a/setup.php +++ b/setup.php @@ -2,7 +2,7 @@ // ---------------------------------------------------------------------- // Original Author of file: Olivier Moron -// Purpose of file: Provides cleaning of Ticket, for title, description +// Purpose of file: Provides cleaning of Ticket, for title, description // and followups. // It cleans text for creation and edition (from email or from web interface) // and it cleans attached pictures to emails @@ -19,9 +19,9 @@ function plugin_init_ticketcleaner() { global $PLUGIN_HOOKS; Plugin::registerClass('PluginTicketCleaner', array('classname' => 'PluginTicketCleaner')); - + $PLUGIN_HOOKS['csrf_compliant']['ticketcleaner'] = true; - + $PLUGIN_HOOKS['pre_item_add']['ticketcleaner'] = array( 'Ticket' => array('PluginTicketCleaner', 'plugin_pre_item_add_ticketcleaner'), 'TicketFollowup' => array('PluginTicketCleaner', 'plugin_pre_item_add_ticketcleaner_followup') @@ -30,19 +30,23 @@ function plugin_init_ticketcleaner() { 'Ticket' => array('PluginTicketCleaner', 'plugin_pre_item_update_ticketcleaner'), 'TicketFollowup' => array('PluginTicketCleaner', 'plugin_pre_item_update_ticketcleaner_followup') ); - + if (Config::canUpdate()) { + // Display a menu entry + $PLUGIN_HOOKS['menu_toadd']['ticketcleaner'] = array('config' => 'PluginTicketcleanerMenu'); + } + } /** * Summary of plugin_version_ticketcleaner - * @return name and version of the plugin + * @return name and version of the plugin */ function plugin_version_ticketcleaner(){ global $LANG; return array ('name' => 'Ticket Cleaner', - 'version' => '1.2.3', + 'version' => '2.0.0', 'author' => 'Olivier Moron', 'homepage' => '', 'minGlpiVersion' => '0.83.8'); diff --git a/ticketcleaner.xml b/ticketcleaner.xml index 24274e1..bb86bd5 100644 --- a/ticketcleaner.xml +++ b/ticketcleaner.xml @@ -10,17 +10,22 @@ - - + + https://github.com/tomolimo/ticketcleaner https://github.com/tomolimo/ticketcleaner/releases https://github.com/tomolimo/ticketcleaner/issues - https://forge.glpi-project.org/projects/ticketcleaner/wiki + https://github.com/tomolimo/ticketcleaner/wiki - Olivier Moron + Olivier Moron @@ -40,7 +45,15 @@ 0.90 - 1.2.3 + 2.0.0 + 0.85 + + + 2.0.0 + 0.90 + + + 2.0.0 9.1