Initial Commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_AddressFormat extends Zend_View_Helper_Abstract {
|
||||
|
||||
|
||||
public function AddressFormat($indirizzo,$cap,$comune,$provincia,$regione){
|
||||
|
||||
$str = '';
|
||||
|
||||
if(strlen(trim($indirizzo)) > 0){
|
||||
$str.= utf8_encode($indirizzo) . '<br>';
|
||||
}
|
||||
|
||||
if(strlen(trim($comune)) > 0){
|
||||
$str .= utf8_encode($comune);
|
||||
}
|
||||
|
||||
if(strlen(trim($cap)) > 0){
|
||||
$str .= ' - '.$cap;
|
||||
}
|
||||
|
||||
if(strlen(trim($provincia)) > 0){
|
||||
$str .= ' ('.utf8_encode($provincia).')';
|
||||
}
|
||||
|
||||
if(strlen(trim($regione)) > 0){
|
||||
$str .= ' - '.utf8_encode($regione);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_AllowedIp extends Zend_View_Helper_Abstract
|
||||
{
|
||||
protected $_ipManager;
|
||||
|
||||
public function allowedIp()
|
||||
{
|
||||
if (null === $this->_ipManager) {
|
||||
$this->_ipManager = new App_Service_IpManager();
|
||||
}
|
||||
|
||||
return $this->_ipManager->allowedIp();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_AuthInfo extends Zend_View_Helper_Abstract
|
||||
{
|
||||
protected $_authService;
|
||||
|
||||
public function authInfo($info = null)
|
||||
{
|
||||
if (null === $this->_authService) {
|
||||
$this->_authService = new App_Service_Auth();
|
||||
}
|
||||
if (null === $info) {
|
||||
return $this;
|
||||
}
|
||||
if (false === $this->isLoggedIn()) {
|
||||
return null;
|
||||
}
|
||||
return $this->_authService->getIdentity()->$info;
|
||||
}
|
||||
|
||||
public function isLoggedIn()
|
||||
{
|
||||
return $this->_authService->getAuth()->hasIdentity();
|
||||
}
|
||||
|
||||
public function checkPermission($resourceName)
|
||||
{
|
||||
if ($this->isLoggedIn()) {
|
||||
return $this->_authService->checkPermission($resourceName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_CleanFiltersParam extends Zend_View_Helper_Abstract {
|
||||
|
||||
public function CleanFiltersParam($params,$removeEmptyValue = true)
|
||||
{
|
||||
unset($params['controller']);
|
||||
unset($params['module']);
|
||||
unset($params['action']);
|
||||
unset($params['method']);
|
||||
unset($params['page']);
|
||||
unset($params['count']);
|
||||
unset($params['order']);
|
||||
unset($params['tipoOrder']);
|
||||
unset($params['filtrato']);
|
||||
unset($params['orwhere']);
|
||||
unset($params['reset']);
|
||||
|
||||
if($removeEmptyValue){
|
||||
//Elimino i campi vuoti tranne le select vuote
|
||||
foreach ($params as $key => $val) {
|
||||
if (empty($val) && $val !== '0') unset($params[$key]);
|
||||
|
||||
//Elimino anche i paramtri di operazione
|
||||
if (preg_match('/OP$/',$key)){
|
||||
unset($params[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_Config extends Zend_View_Helper_Abstract
|
||||
{
|
||||
protected $_configService;
|
||||
|
||||
public function config($info = null)
|
||||
{
|
||||
if (null === $this->_configService) {
|
||||
$this->_configService = new App_Service_ConfigManager();
|
||||
}
|
||||
if (null === $info) {
|
||||
return $this;
|
||||
}
|
||||
return $this->_configService->get($info);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_Currency extends Zend_View_Helper_Abstract {
|
||||
|
||||
public function Currency($number)
|
||||
{
|
||||
$currency = new Zend_Currency('it_IT');
|
||||
if ($number == null) return null;
|
||||
return $currency->toCurrency($number);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_EncodeText extends Zend_View_Helper_Abstract {
|
||||
|
||||
/**
|
||||
* Funzione che di default passata una stringa la formatta con i ritorni a capo e la codifica in utf_8
|
||||
* OPZIONI PARAMETRO return:
|
||||
*
|
||||
* @param string $string
|
||||
* @return string $string
|
||||
*/
|
||||
|
||||
public function encodeText($string){
|
||||
return str_replace("\n","<br>",utf8_encode($string));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_ExtractData extends Zend_View_Helper_Abstract
|
||||
{
|
||||
public function ExtractData($data=null,$return=null,$withtime = false)
|
||||
{
|
||||
if($data==null) return null;
|
||||
if(!$withtime){
|
||||
$val=explode('-',$data);
|
||||
}
|
||||
else{
|
||||
$datetime = explode(' ',$data);
|
||||
$val = explode('-',$datetime[0]);
|
||||
$time = $datetime[1];
|
||||
}
|
||||
switch($return){
|
||||
case'0':
|
||||
case'day':
|
||||
return $val['2'];
|
||||
break;
|
||||
case'1':
|
||||
case'month':
|
||||
return $val['1'];
|
||||
break;
|
||||
case'mese':
|
||||
return ucfirst(strftime('%B',mktime(0,0,0,$val['1'],1,2013)));
|
||||
break;
|
||||
case'monthname':
|
||||
return ucfirst(strftime('%B',mktime(0,0,0,$data,1,2013)));
|
||||
break;
|
||||
case'3':
|
||||
case'year':
|
||||
case'y':
|
||||
return $val['0'];
|
||||
break;
|
||||
case'yy':
|
||||
return substr($val['0'],2,3);
|
||||
break;
|
||||
case 'withtime':
|
||||
if ($val[2] == '00' && $val[1] == '00' && $val[0] == '0000') {
|
||||
return null;
|
||||
} else {
|
||||
if($withtime)
|
||||
return implode('/',array_reverse($val)) . " ".substr($time,0,5);
|
||||
else
|
||||
return implode('/',array_reverse($val));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if($val[2]=='00'&&$val[1]=='00'&&$val[0]=='0000'){
|
||||
return null;
|
||||
}else{
|
||||
$data= $val[2] . '/'.$val[1] . '/'.$val[0];
|
||||
return $data;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function formatData($data,$format){
|
||||
$data = new DateTime($data);
|
||||
return $data -> format($format);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_FormatData extends Zend_View_Helper_Abstract
|
||||
{
|
||||
public function FormatData($data,$format){
|
||||
$data = new DateTime($data);
|
||||
return $data -> format($format);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_GetDomainData extends Zend_View_Helper_Abstract
|
||||
{
|
||||
|
||||
public function GetDomainData($domain_name, $key_name, $type = 'name')
|
||||
{
|
||||
|
||||
$domain = App_Constants_Domains::DOMAINS[$domain_name];
|
||||
if (!$domain) {
|
||||
return $key_name;
|
||||
// throw new Zend_Exception("Dominio non trovato");
|
||||
}
|
||||
|
||||
$data = $domain[$key_name];
|
||||
if (!$data) {
|
||||
return $key_name;
|
||||
// throw new Zend_Exception("Valore di dominio non trovato");
|
||||
}
|
||||
|
||||
return $data[$type];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_MatchUrl extends Zend_View_Helper_Abstract {
|
||||
|
||||
public function MatchUrl($text){
|
||||
|
||||
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
|
||||
|
||||
preg_match_all($reg_exUrl, $text, $matches);
|
||||
$usedPatterns = array();
|
||||
foreach($matches[0] as $pattern){
|
||||
if(!array_key_exists($pattern, $usedPatterns)){
|
||||
$usedPatterns[$pattern]=true;
|
||||
$text = str_replace($pattern, '<a href="'.$pattern.'" rel="nofollow" target="_blank" >'.$pattern.'</a>', $text);
|
||||
}
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_SlashesText extends Zend_View_Helper_Abstract {
|
||||
|
||||
/**
|
||||
* Funzione che di default passata una stringa la formatta con i ritorni a capo e la codifica in utf_8
|
||||
* OPZIONI PARAMETRO return:
|
||||
*
|
||||
* @param string $string
|
||||
* @return string $string
|
||||
*/
|
||||
|
||||
public function slashesText($string){
|
||||
return addslashes(htmlspecialchars($string));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_VariabiliSito extends Zend_View_Helper_Abstract
|
||||
{
|
||||
protected $_service;
|
||||
|
||||
public function variabilisito($info = null)
|
||||
{
|
||||
if (null === $this->_service) {
|
||||
$this->_service = new App_Service_VariabiliSito();
|
||||
}
|
||||
if (null === $info) {
|
||||
return $this;
|
||||
}
|
||||
return $this->_service->get($info);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
class Zend_View_Helper_WrapText extends Zend_View_Helper_Abstract {
|
||||
|
||||
/**
|
||||
* Funzione che di default passata una stringa la taglia e la restituisce senza troncare le parole
|
||||
* OPZIONI PARAMETRO return:
|
||||
*
|
||||
* @param string $string|integer $lenght
|
||||
* @return string $data
|
||||
*/
|
||||
public function WrapText($string,$lenght = 100) {
|
||||
|
||||
if(strlen($string)>$lenght){
|
||||
return $this->truncateHtml($string,$lenght);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* truncateHtml can truncate a string up to a number of characters while preserving whole words and HTML tags
|
||||
*
|
||||
* @param string $text String to truncate.
|
||||
* @param integer $length Length of returned string, including ellipsis.
|
||||
* @param string $ending Ending to be appended to the trimmed string.
|
||||
* @param boolean $exact If false, $text will not be cut mid-word
|
||||
* @param boolean $considerHtml If true, HTML tags would be handled correctly
|
||||
*
|
||||
* @return string Trimmed string.
|
||||
*/
|
||||
function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) {
|
||||
if ($considerHtml) {
|
||||
// if the plain text is shorter than the maximum length, return the whole text
|
||||
if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
|
||||
return $text;
|
||||
}
|
||||
// splits all html-tags to scanable lines
|
||||
preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER);
|
||||
$total_length = strlen($ending);
|
||||
$open_tags = array();
|
||||
$truncate = '';
|
||||
foreach ($lines as $line_matchings) {
|
||||
// if there is any html-tag in this line, handle it and add it (uncounted) to the output
|
||||
if (!empty($line_matchings[1])) {
|
||||
// if it's an "empty element" with or without xhtml-conform closing slash
|
||||
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) {
|
||||
// do nothing
|
||||
// if tag is a closing tag
|
||||
} else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) {
|
||||
// delete tag from $open_tags list
|
||||
$pos = array_search($tag_matchings[1], $open_tags);
|
||||
if ($pos !== false) {
|
||||
unset($open_tags[$pos]);
|
||||
}
|
||||
// if tag is an opening tag
|
||||
} else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) {
|
||||
// add tag to the beginning of $open_tags list
|
||||
array_unshift($open_tags, strtolower($tag_matchings[1]));
|
||||
}
|
||||
// add html-tag to $truncate'd text
|
||||
$truncate .= $line_matchings[1];
|
||||
}
|
||||
// calculate the length of the plain text part of the line; handle entities as one character
|
||||
$content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2]));
|
||||
if ($total_length+$content_length> $length) {
|
||||
// the number of characters which are left
|
||||
$left = $length - $total_length;
|
||||
$entities_length = 0;
|
||||
// search for html entities
|
||||
if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) {
|
||||
// calculate the real length of all entities in the legal range
|
||||
foreach ($entities[0] as $entity) {
|
||||
if ($entity[1]+1-$entities_length <= $left) {
|
||||
$left--;
|
||||
$entities_length += strlen($entity[0]);
|
||||
} else {
|
||||
// no more characters left
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$truncate .= substr($line_matchings[2], 0, $left+$entities_length);
|
||||
// maximum lenght is reached, so get off the loop
|
||||
break;
|
||||
} else {
|
||||
$truncate .= $line_matchings[2];
|
||||
$total_length += $content_length;
|
||||
}// if the maximum length is reached, get off the loop
|
||||
if($total_length>= $length) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (strlen($text) <= $length) {
|
||||
return $text;
|
||||
} else {
|
||||
$truncate = substr($text, 0, $length - strlen($ending));
|
||||
}
|
||||
}
|
||||
// if the words shouldn't be cut in the middle...
|
||||
if (!$exact) {
|
||||
// ...search the last occurance of a space...
|
||||
$spacepos = strrpos($truncate, ' ');
|
||||
if (isset($spacepos)) {
|
||||
// ...and cut the text in this position
|
||||
$truncate = substr($truncate, 0, $spacepos);
|
||||
}
|
||||
}
|
||||
// add the defined ending to the text
|
||||
$truncate .= $ending;
|
||||
if($considerHtml) {
|
||||
// close all unclosed html-tags
|
||||
foreach ($open_tags as $tag) {
|
||||
$truncate .= '</' . $tag . '>';
|
||||
}
|
||||
}
|
||||
return $truncate;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user