Skip to content

Commit

Permalink
Move vacationReason to helper method to the Vacation rule object
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Mar 18, 2015
1 parent 52f18b8 commit 3219c1e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
33 changes: 33 additions & 0 deletions ingo/lib/Rule/System/Vacation.php
Expand Up @@ -206,4 +206,37 @@ public function __set($name, $data)
}
}

/**
* Returns the vacation reason with all placeholder replaced.
*
* @param string $reason The vacation reason including placeholders.
* @param integer $start The vacation start timestamp.
* @param integer $end The vacation end timestamp.
*
* @return string The vacation reason suitable for usage in the filter
* scripts.
*/
public static function vacationReason($reason, $start, $end)
{
global $injector, $prefs;

$format = $prefs->getValue('date_format');
$identity = $injector->getInstance('Horde_Core_Factory_Identity')
->create(Ingo::getUser());

$replace = array(
'%NAME%' => $identity->getName(),
'%EMAIL%' => $identity->getDefaultFromAddress(),
'%SIGNATURE%' => $identity->getValue('signature'),
'%STARTDATE%' => $start ? strftime($format, $start) : '',
'%ENDDATE%' => $end ? strftime($format, $end) : ''
);

return str_replace(
array_keys($replace),
array_values($replace),
$reason
);
}

}
2 changes: 1 addition & 1 deletion ingo/lib/Script/Maildrop.php
Expand Up @@ -309,7 +309,7 @@ protected function _generateVacation(Ingo_Rule $rule)
$this->_addItem(
Ingo::RULE_VACATION,
new Ingo_Script_String(
Ingo_Script_Util::vacationReason(
Ingo_Rule_System_Vacation::vacationReason(
$rule->reason,
$rule->start,
$rule->end
Expand Down
2 changes: 1 addition & 1 deletion ingo/lib/Script/Procmail/Recipe.php
Expand Up @@ -192,7 +192,7 @@ public function __construct($params = array(), $scriptparams = array())
$this->_action[] = ' | (formail -rI"Precedence: junk" \\';
$this->_action[] = ' -a"From: <' . $address . '>" \\';
$this->_action[] = ' -A"X-Loop: ' . $address . '" \\';
$reason = Ingo_Script_Util::vacationReason(
$reason = Ingo_Rule_System_Vacation::vacationReason(
$params['action-value']['reason'],
$params['action-value']['start'],
$params['action-value']['end']
Expand Down
2 changes: 1 addition & 1 deletion ingo/lib/Script/Sieve/Action/Vacation.php
Expand Up @@ -195,7 +195,7 @@ protected function _vacationCode()
return $code
. '"'
. Ingo_Script_Sieve::escapeString(
Ingo_Script_Util::vacationReason(
Ingo_Rule_System_Vacation::vacationReason(
$this->_vars['reason'],
$this->_vars['start'],
$this->_vars['end']
Expand Down
33 changes: 0 additions & 33 deletions ingo/lib/Script/Util.php
Expand Up @@ -88,37 +88,4 @@ public static function update($auto_update = true)
}
}

/**
* Returns the vacation reason with all placeholder replaced.
*
* @param string $reason The vacation reason including placeholders.
* @param integer $start The vacation start timestamp.
* @param integer $end The vacation end timestamp.
*
* @return string The vacation reason suitable for usage in the filter
* scripts.
*/
public static function vacationReason($reason, $start, $end)
{
global $injector, $prefs;

$format = $prefs->getValue('date_format');
$identity = $injector->getInstance('Horde_Core_Factory_Identity')
->create(Ingo::getUser());

$replace = array(
'%NAME%' => $identity->getName(),
'%EMAIL%' => $identity->getDefaultFromAddress(),
'%SIGNATURE%' => $identity->getValue('signature'),
'%STARTDATE%' => $start ? strftime($format, $start) : '',
'%ENDDATE%' => $end ? strftime($format, $end) : ''
);

return str_replace(
array_keys($replace),
array_values($replace),
$reason
);
}

}

0 comments on commit 3219c1e

Please sign in to comment.