getRequest()->getHost().'/redirector/index?xnipObjectId='.sfContext::getInstance()->getRequest()->getParameter('id').'&url='.$url; return $redirectUrl; } public static function addRedirectToLinks($html) { $pattern = '/(href=["\'])(http[s]?.*)(["\'])/iU'; $parsedHtml = preg_replace_callback( $pattern, create_function( '$matches', 'return $matches[1].XnipUtils::getRedirectUrl($matches[2]).$matches[3];' ), $html ); return $parsedHtml; } public static function returnWeblink($code) { $code = urldecode($code); $protocols = Array('http://', 'https://', 'ftp://'); foreach($protocols as $key => $protocol) { if (strpos($code, $protocol) !== false) { return $code; } } return 'http://'.$code; } public static function idDecrypt($id) { $new = ''; $str = (string)$id; $dcm = array_flip(array ('v','r','z','n','q','m','a','e','p','j','w')); for($i = 0; $i < strlen($str); $i++) { $new .= $dcm[$str{$i}]; } return $new/3; #return str_rot13(base64_decode($id)); } public static function idEncrypt($id) { $new = ''; $str = (string)($id*3); $dcm = array ('v','r','z','n','q','m','a','e','p','j','w'); for($i = 0; $i < strlen($str); $i++) { $new .= $dcm[$str{$i}]; } return $new; //return base64_encode(str_rot13($id)); } public static function formatIssue($issue) { $issueElems = explode(' ',$issue,3); $year = ($issueElems[0]); $nr = (isset($issueElems[1])) ? $issueElems[1].'/' : ''; $remain = (isset($issueElems[3])) ? ' '.$issueElems[3] : ''; return $nr.$year.$remain; } public static function formatFolders($folders, $isSet = true) { $f = array(); if (count($folders)) { foreach($folders as $folder) { // sfContext::getInstance()->getLogger()->log('folder: '.$folder."\n"); if ($isSet) { if ($folder->isSet) $f[] = $folder->name; } else { $f[] = $folder->name; } } } return implode(' | ',(array)$f); } public static function rm_rr($dir) { $files = glob( $dir . '*', GLOB_MARK ); foreach( $files as $file ) { if( substr( $file, -1 ) == '/' ) XnipUtils::rm_rr( $file ); else unlink( $file ); } rmdir( $dir ); } public static function formatAddress($address) { if(!$address) { return NULL; } else { $formattedAddress = array(); if(isset($address['country'])) { sfContext::getInstance()->getConfiguration()->loadHelpers('I18N'); switch((string)$address['country']) { case 'CA': case 'US': if(isset($address['housenumber']) || isset($address['street'])) $formattedAddress[] = $address['housenumber'].' '.$address['street']; if(isset($address['adress-extension'])) $formattedAddress[] = $address['address-extension']; if(isset($address['city']) || isset($address['state']) || isset($address['zip'])) $formattedAddress[] = $address['city'].', '.$address['state'].' '.$address['zip']; if(isset($address['country'])) $formattedAddress[] = format_country($address['country']); break; default: if(isset($address['housenumber']) || isset($address['street'])) $formattedAddress[] = $address['street'].' '.$address['housenumber']; if(isset($address['adress-extension'])) $formattedAddress[] = $address['address-extension']; if(isset($address['state'])) $formattedAddress[] = $address['state']; if(isset($address['city']) || isset($address['zip'])) $formattedAddress[] = $address['zip'].' '.$address['city']; if(isset($address['country'])) $formattedAddress[] = format_country($address['country']); break; } } return implode(array_filter($formattedAddress),'
'); } } public static function getLinkClass($url) { $portals = array('facebook','twitter','youtube','myspace','linkedin','xing'); foreach($portals as $portal) { if(strpos($url,$portal)) return $portal; } return null; } public static function isTouch($request) { if (!$request) $request = sfContext::getInstance()->getRequest(); return ( (preg_match('#iPhone#i', $request->getHttpHeader('User-Agent')) || preg_match('#Mobile/.+Safari#i', $request->getHttpHeader('User-Agent')) || preg_match('#Android#i', $request->getHttpHeader('User-Agent')) ) && !preg_match('#iPad#i', $request->getHttpHeader('User-Agent')) ); } public static function isHomeScreenTouch($request = null) { if (!$request) $request = sfContext::getInstance()->getRequest(); return preg_match('#iPhone#i', $request->getHttpHeader('User-Agent')) && !preg_match('#Mobile/.+Safari#i', $request->getHttpHeader('User-Agent')); } } ?>