Thank you for getting back to me.
In fact I need to convert URI like this "\qnap-hostname\share*" to this format: "/mnt/qnap/*"
My plugin code is the following, in case it helps:
<?php
/* ----------------------------------------------------------------------
* QnapPathConverterPlugin.php
* ----------------------------------------------------------------------
*/
class QnapPathConverterPlugin extends BaseApplicationPlugin {
/**
* Plugin config
* @var Configuration
*/
var $opo_plugin_config = null;
public function __construct($ps_plugin_path) {
$this->description = _t('This plugin converts paths in the custom metadata field "media_uri" and removes double quotes.');
parent::__construct();
$this->opo_plugin_config = Configuration::load($ps_plugin_path . DIRECTORY_SEPARATOR . 'conf' . DIRECTORY_SEPARATOR . 'QnapPathConverter.conf');
}
/**
*
*/
public function checkStatus() {
return array(
'description' => $this->getDescription(),
'errors' => array(),
'warnings' => array(),
'available' => (bool) $this->opo_plugin_config->get('enabled')
);
}
public function hookInsertItem(&$pa_params) {
if($this->opo_plugin_config->get('enabled')) {
$this->convertPaths($pa_params);
}
return $pa_params;
}
public function hookUpdateItem(&$pa_params) {
if($this->opo_plugin_config->get('enabled')) {
$this->convertPaths($pa_params);
}
return $pa_params;
}
public function hookSaveItem(&$pa_params) {
if($this->opo_plugin_config->get('enabled')) {
$this->convertPaths($pa_params);
}
return $pa_params;
}
public function hookEditItem(&$pa_params) {
if($this->opo_plugin_config->get('enabled')) {
$this->convertPaths($pa_params);
}
return $pa_params;
}
/**
* Convert paths in the custom metadata field "media_uri" and remove double quotes
*
* @param array $params Plugin parameters, including the table instance to convert paths
*/
public function convertPaths(&$params) {
if(!($t_instance = caGetOption('instance', $params, null))) { return false; }
// Get the value of the custom metadata field "media_uri"
$vs_media_uri = $t_instance->get('media_uri');
// Remove all double quotes from the media_uri field
$vs_media_uri = str_replace('"', '', $vs_media_uri);
// Replace the path segment "\\QNAP-IP\share\" with "/mnt/qnap/"
$vs_media_uri = preg_replace('|\\\\QNAP-IP\\share\\|', '/mnt/qnap/', $vs_media_uri);
// Set the converted path back to the metadata field
$t_instance->set('media_uri', $vs_media_uri);
return true;
}
}
However I do not think my problem is related to the string manipulation itself as even when removing the preg_replace() part, I still get the same error in the GUI.
Again I am thankful for any help anyone could give me on this.