Browse Source

refactor IMAP to work with inline attachments

euromark 13 years ago
parent
commit
8283a5cc48

+ 61 - 40
Controller/Component/MobileComponent.php

@@ -7,7 +7,7 @@ App::uses('Router', 'Routing');
  * Uses Session: User.mobile and User.nomobile
  * - mobile is the auto-detection (true/false)
  * - nomobile can be set by the user and overrides the default behavior/detection
- * (1=true/0=false or -1=null which will remove the override)
+ *   (1=true/0=false or -1=null which will remove the override)
  *
  * TODO: differentaite between "isMobile" and "has/wants mobile"
  * @author Mark Scherer
@@ -26,6 +26,7 @@ class MobileComponent extends Component {
 
 	protected $_defaults = array(
 		'engine' => 'cake',
+		'auto' => false, // auto set mobile views
 	);
 
 	/**
@@ -34,7 +35,7 @@ class MobileComponent extends Component {
 	public $themed = true;
 
 	public function __construct(ComponentCollection $collection, $settings = array()) {
-		$settings = am($this->_defaults, $settings);
+		$settings = array_merge($this->_defaults, $settings);
 		parent::__construct($collection, $settings);
 	}
 
@@ -52,33 +53,7 @@ class MobileComponent extends Component {
 			$this->Session->write('User.nomobile', $noMobile);
 
 		}
-		$this->setMobile();
-
-		$urlParams = Router::getParams(true);
-		if (!isset($urlParams['named'])) {
-			$urlParams['named'] = array();
-		}
-		if (!isset($urlParams['pass'])) {
-			$urlParams['pass'] = array();
-		}
-		$urlParams = am($urlParams, $urlParams['named'], $urlParams['pass']);
-		unset($urlParams['named']);
-		unset($urlParams['pass']);
-		if (isset($urlParams['prefix'])) {
-			unset($urlParams['prefix']);
-		}
-
-		if ($this->setMobile) {
-			$url = Router::url(am($urlParams, array('mobile' => 0)));
-			$this->Controller->set('desktopUrl', $url);
-
-		} else {
-			$url = Router::url(am($urlParams, array('mobile' => 1)));
-			$this->Controller->set('mobileUrl', $url);
-		}
-
-		Configure::write('User.mobile', $this->isMobile);
-		Configure::write('User.setMobile', $this->setMobile);
+		$this->isMobile();
 	}
 
 	/**
@@ -100,7 +75,7 @@ class MobileComponent extends Component {
 		*      (int) 0 => '/var/www/maps-cakephp2/app/View/'
 		* )
 		*/
-		$mobileViewFile = $viewDir[0] . $this->viewPath . DS . 'mobile' . DS . $this->params['action'] . '.ctp';
+		$mobileViewFile = $viewDir[0] . $this->viewPath . DS . 'Mobile' . DS . $this->params['action'] . '.ctp';
 
 		//Debugger::log($this->viewPath);
 		// use this to log the output to
@@ -113,7 +88,7 @@ class MobileComponent extends Component {
 			// and if a mobile view file has been
 			// created for the action, serve it instead
 			// of the default view file
-			$this->viewPath = $this->viewPath . '/mobile/';
+			$this->viewPath = $this->viewPath . '/Mobile/';
 		}
 	}
 
@@ -124,15 +99,44 @@ class MobileComponent extends Component {
 	 */
 	public function setMobile() {
 		if ($this->isMobile === null) {
-			$mobile = $this->isMobile();
-			$this->isMobile = $mobile;
+			$this->isMobile();
 		}
 		$noMobile = $this->Session->read('User.nomobile');
 		if (!$this->isMobile && $noMobile === null || $noMobile) {
 			$this->setMobile = false;
+		} else {
+			$this->setMobile = true;
+		}
+
+		$urlParams = Router::getParams(true);
+		if (!isset($urlParams['named'])) {
+			$urlParams['named'] = array();
+		}
+		if (!isset($urlParams['pass'])) {
+			$urlParams['pass'] = array();
+		}
+		$urlParams = array_merge($urlParams, $urlParams['named'], $urlParams['pass']);
+		unset($urlParams['named']);
+		unset($urlParams['pass']);
+		if (isset($urlParams['prefix'])) {
+			unset($urlParams['prefix']);
+		}
+
+		if ($this->setMobile) {
+			$url = Router::url(array_merge($urlParams, array('mobile' => 0)));
+			$this->Controller->set('desktopUrl', $url);
+
+		} else {
+			$url = Router::url(array_merge($urlParams, array('mobile' => 1)));
+			$this->Controller->set('mobileUrl', $url);
+		}
+
+		Configure::write('User.mobile', $this->isMobile);
+		Configure::write('User.setMobile', $this->setMobile);
+
+		if (!$this->isMobile) {
 			return;
 		}
-		$this->setMobile = true;
 
 		if (!$this->themed) {
 	 		$this->serveMobileIfAvailable();
@@ -149,13 +153,30 @@ class MobileComponent extends Component {
 	 * @return bool $success
 	 */
 	public function isMobile() {
-		$isMobile = $this->Session->read('User.mobile');
-		if ($isMobile !== null) {
-			return $isMobile;
+		if ($this->isMobile !== null) {
+			return $this->isMobile;
+		}
+
+		$wantsMobile = null;
+		if (isset($this->Controller->request->params['named']['mobile'])) {
+			if ($this->Controller->request->params['named']['mobile'] == '-1') {
+				$this->Session->delete('User.mobile');
+			} else {
+				$wantsMobile = (bool)$this->Controller->request->params['named']['mobile'];
+			}
+		}
+		if ($wantsMobile) {
+			$this->isMobile = $wantsMobile;
+			return $this->isMobile;
+		}
+
+		$this->isMobile = $this->Session->read('User.mobile');
+		if ($this->isMobile !== null) {
+			return $this->isMobile;
 		}
-		$isMobile = (int)$this->detect();
-		$this->Session->write('User.mobile', $isMobile);
-		return $isMobile;
+		$this->isMobile = (int)$this->detect();
+		$this->Session->write('User.mobile', $this->isMobile);
+		return $this->isMobile;
 	}
 
 	/**

+ 13 - 7
Lib/EmailLib.php

@@ -83,11 +83,14 @@ class EmailLib extends CakeEmail {
 	 * @return resource EmailLib
 	 * 2011-11-02 ms
 	 */
-	public function addAttachment($file, $name = null) {
+	public function addAttachment($file, $name = null, $fileInfo = array()) {
+		$fileInfo['file'] = $file;
 		if (!empty($name)) {
-			return $this->addAttachments(array($name=>$file));
+			$fileInfo = array($name => $fileInfo);
+		} else {
+			$fileInfo = array($fileInfo);
 		}
-		return $this->addAttachments($file);
+		return $this->addAttachments($fileInfo);
 	}
 
 	/**
@@ -98,8 +101,7 @@ class EmailLib extends CakeEmail {
 	 * @return mixed ressource EmailLib or string $contentId
 	 * 2011-11-02 ms
 	 */
-	public function addBlobAttachment($content, $name, $mimeType = null) {
-		$fileInfo = array();
+	public function addBlobAttachment($content, $name, $mimeType = null, $fileInfo = array()) {
 		$fileInfo['content'] = $content;
 		$fileInfo['mimetype'] = $mimeType;
 		$file = array($name=>$fileInfo);
@@ -435,7 +437,12 @@ class EmailLib extends CakeEmail {
 			$msg[] = '--' . $boundary;
 			$msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
 			$msg[] = 'Content-Transfer-Encoding: base64';
-			$msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
+			if (
+				!isset($fileInfo['contentDisposition']) ||
+				$fileInfo['contentDisposition']
+			) {
+				$msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
+			}
 			$msg[] = '';
 			$msg[] = $data;
 			$msg[] = '';
@@ -686,7 +693,6 @@ class EmailLib extends CakeEmail {
 			}
 		}
 		*/
-
 		try {
 			$this->_debug = parent::send($message);
 		} catch (Exception $e) {

+ 2 - 1
Lib/Error/MyErrorHandler.php

@@ -1,6 +1,7 @@
 <?php
 App::uses('ErrorHandler', 'Error');
 App::uses('CakeRequest', 'Network');
+App::uses('Router', 'Routing');
 App::uses('Utility', 'Tools.Utility');
 
 class MyErrorHandler extends ErrorHandler {
@@ -131,7 +132,7 @@ class MyErrorHandler extends ErrorHandler {
 		if (strpos($_SERVER['REQUEST_URI'], '/test.php?') === 0) {
 			return null;
 		}
-		$currentUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'n/a';
+		$currentUrl = Router::url(); //isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'n/a';
 		$refererUrl = Utility::getReferer(); //Router::getRequest()->url().'
 		App::uses('CakeSession', 'Model/Datasource');
 		$uid = CakeSession::read('Auth.User.id');

+ 71 - 67
Lib/ImapLib.php

@@ -123,7 +123,7 @@ class ImapLib {
 	 * 2011-10-25 ms
 	 */
 	public function connect($user, $pass, $server, $port = null) {
-		if (!$this->dependenciesMatches()) {
+		if (!$this->dependenciesMatch()) {
 			return false;
 		}
 
@@ -134,9 +134,13 @@ class ImapLib {
 		$this->settings[self::S_USER] = $user;
 		$this->settings[self::S_PASSWORD] = $pass;
 		$connector = $this->buildConnector();
-		//die($connector);
-		$this->stream = @imap_open($connector, $user, $pass);
+
+		//$options = OP_DEBUG;
+		$this->stream = @imap_open($connector, $user, $pass, $options);
 		if (false === $this->stream) {
+			if ($error = $this->checkConnection()) {
+				throw new ImapException($error);
+			}
 			return false;
 		}
 		return true;
@@ -150,16 +154,10 @@ class ImapLib {
 	}
 
 	public function msgCount() {
-		if ($error = $this->checkConnection()) {
-			throw new ImapException($error);
-		}
 		return imap_num_msg($this->stream);
 	}
 
 	public function listMailboxes($current = true) {
-		if ($error = $this->checkConnection()) {
-			return $error;
-		}
 		if (is_bool($current)) {
 			if ($current) {
 				$current = '%';
@@ -176,16 +174,10 @@ class ImapLib {
 	}
 
 	public function expunge() {
-		if ($error = $this->checkConnection()) {
-			return $error;
-		}
 		return imap_expunge($this->stream);
 	}
 
 	public function close($expunge = false) {
-		if ($error = $this->checkConnection()) {
-			return $error;
-		}
 		if ($expunge) {
 			return @imap_close($this->stream, CL_EXPUNGE);
 		} else {
@@ -204,68 +196,61 @@ class ImapLib {
 	 * 2011-11-17 ms
 	 */
 	public function msgList($msg_list = array()) {
-		if ($this->stream) {
-			$return = array();
+		$return = array();
 
-			if (is_array($msg_list) || count($msg_list) == 0) {
-				try {
-					$count = $this->msgCount();
-				} catch (Exception $e) {
-					return $e->getMessage();
-				}
-				for ($i = 1; $i <= $count; $i++) {
-					$header = imap_headerinfo($this->stream, $i);
-					foreach ($header as $id => $value) {
-						# fix to remove whitespaces
-						$header->Msgno = trim($header->Msgno);
-
-						// Simple array
-						if (!is_array($value)) {
-							$return[$header->Msgno][$id] = $value;
-						} else {
-							foreach ($value as $newid => $array_value) {
-								foreach ($value[0] as $key => $aValue) {
-									$return[$header->Msgno][$id][$key] = quoted_printable_decode($aValue);
-								}
+		if (empty($msg_list)) {
+			$count = $this->msgCount();
+			for ($i = 1; $i <= $count; $i++) {
+				$header = imap_headerinfo($this->stream, $i);
+				$msgNo = trim($header->Msgno);
+				foreach ($header as $id => $value) {
+					# fix to remove whitespaces
+
+
+					// Simple array
+					if (!is_array($value)) {
+						$return[$msgNo][$id] = $value;
+					} else {
+						foreach ($value as $newid => $array_value) {
+							foreach ($value[0] as $key => $aValue) {
+								$return[$msgNo][$id][$key] = quoted_printable_decode($aValue);
 							}
 						}
-						// Let's add the body
-						$return[$header->Msgno]['body'] = imap_fetchbody($this->stream, $header->Msgno, 1);
-
-						//lets add attachments
-						$return[$header->Msgno]['structure'] = imap_fetchstructure($this->stream, $header->Msgno, 1);
-						$return[$header->Msgno]['attachments'] = $this->attachments($header);
 					}
+
 				}
+				// Let's add the body
+				$return[$msgNo]['body'] = imap_fetchbody($this->stream, $msgNo, 1);
+
+				//lets add attachments
+				$return[$msgNo]['structure'] = imap_fetchstructure($this->stream, $msgNo);
+				//debug(imap_fetchstructure($this->stream, $header->Msgno, FT_UID));
+				$return[$msgNo]['attachments'] = $this->attachments($header);
 			}
-			// We want to search a specific array of messages
-			else {
-				foreach ($msg_list as $i) {
-					$header = imap_headerinfo($this->stream, $i);
-					foreach ($header as $id => $value) {
-						// Simple array
-						if (!is_array($value)) {
-							$return[$header->Msgno][$id] = $value;
-						} else {
-							foreach ($value as $newid => $array_value) {
-								foreach ($value[0] as $key => $aValue) {
-									$return[$header->Msgno][$id][$key] = $this->_quoted_printable_encode($aValue);
-								}
+		}
+		// We want to search a specific array of messages
+		else {
+			foreach ($msg_list as $i) {
+				$header = imap_headerinfo($this->stream, $i);
+				foreach ($header as $id => $value) {
+					// Simple array
+					if (!is_array($value)) {
+						$return[$header->Msgno][$id] = $value;
+					} else {
+						foreach ($value as $newid => $array_value) {
+							foreach ($value[0] as $key => $aValue) {
+								$return[$header->Msgno][$id][$key] = $this->_quoted_printable_encode($aValue);
 							}
 						}
-						// Let's add the body too!
-						$return[$header->Msgno]['body'] = imap_fetchbody($this->stream, $header->Msgno, 0);
-						$return[$header->Msgno]['structure'] = imap_fetchstructure($this->stream, $header->Msgno);
-						$return[$header->Msgno]['attachments'] = $this->attachments($header);
 					}
+					// Let's add the body too!
+					$return[$header->Msgno]['body'] = imap_fetchbody($this->stream, $header->Msgno, 0);
+					$return[$header->Msgno]['structure'] = imap_fetchstructure($this->stream, $header->Msgno);
+					$return[$header->Msgno]['attachments'] = $this->attachments($header);
 				}
 			}
-
-			#$return['num_of_msgs'] = count($return);
-			return $return;
 		}
-
-		return imap_last_error();
+		return $return;
 	}
 
 	/**
@@ -273,7 +258,10 @@ class ImapLib {
 	 * 2011-09-02 ms
 	 */
 	public function attachments($header) {
-		$structure = imap_fetchstructure($this->stream, $header->Msgno, FT_UID);
+		$structure = imap_fetchstructure($this->stream, $header->Msgno);
+		if (!$structure) {
+			return false;
+		}
 		$parts = $structure->parts;
 		$fpos = 2;
 		$message = array();
@@ -323,6 +311,22 @@ class ImapLib {
 
 				$fpos++;
 				$attachments[] = $attachment;
+			} else { // inline attachments etc
+				$attachment["pid"] = $i;
+				$attachment["type"][$i] = $message["attachment"]["type"][$part->type] . "/" . strtolower($part->subtype);
+				$attachment["subtype"][$i] = strtolower($part->subtype);
+				$ext = $part->subtype;
+				$params = $part->parameters;
+				//CakeLog::write('import', print_r($part, true)); die('TEST');
+				$mege = "";
+				$data = "";
+				$mege = imap_fetchbody($this->stream, $header->Msgno, $fpos);
+				$attachment['filename'] = !is_object($part->parameters) ? $part->parameters[0]->value : '';
+				$attachment['data'] = $this->_getDecodedValue($mege, $part->type);
+				$attachment['filesize'] = strlen($attachment['data']);
+
+				$fpos++;
+				$attachments[] = $attachment;
 			}
 		}
 		return $attachments;
@@ -503,7 +507,7 @@ class ImapLib {
 	 * @return bool $success
 	 * 2011-10-25 ms
 	 */
-	public function dependenciesMatches() {
+	public function dependenciesMatch() {
 		if (!function_exists('imap_open')) {
 			trigger_error('imap_open not available. Please install extension/module.');
 			return false;

+ 3 - 0
README.md

@@ -14,6 +14,9 @@ Installing the Plugin is pretty much as with every other CakePHP Plugin.
 * Put the files in `APP/Plugin/Tools`
 * Make sure you have `CakePlugin::load('Tools')` or `CakePlugin::loadAll()` in your bootstrap
 
+You can also use packagist now:
+https://packagist.org/packages/dereuromark/tools-cakephp
+
 That's it
 
 ## The basics

+ 20 - 67
Test/Case/View/Helper/CommonHelperTest.php

@@ -5,52 +5,49 @@ App::uses('View', 'View');
 App::uses('MyCakeTestCase', 'Tools.TestSuite');
 
 /**
- * Datetime Test Case
- *
- * @package cake.tests
- * @subpackage cake.tests.cases.libs.view.helpers
+ * 2012-11-23 ms
  */
 class CommonHelperTest extends MyCakeTestCase {
-/**
- * setUp method
- *
- * @access public
- * @return void
- */
+
+	public $Common;
+
 	public function setUp() {
 		$this->Common = new CommonHelper(new View(null));
 	}
 
-
+	/**
+	 */
 	public function testMetaCanonical() {
 		$is = $this->Common->metaCanonical('/some/url/param1');
 		$this->out(h($is));
-		$this->assertEquals('<link rel="canonical" href="/some/url/param1" />', trim($is));
+		$this->assertEquals('<link rel="canonical" href="'.$this->Common->url('/some/url/param1').'" />', trim($is));
 	}
 
+	/**
+	 */
 	public function testMetaAlternate() {
 		$is = $this->Common->metaAlternate('/some/url/param1', 'de-de');
 		$this->out(h($is));
-		$this->assertEquals('<link href="http://'.HTTP_HOST.'/some/url/param1" rel="alternate" hreflang="de-de" />', trim($is));
+		$this->assertEquals('<link href="http://'.HTTP_HOST.$this->Common->url('/some/url/param1').'" rel="alternate" hreflang="de-de" />', trim($is));
 
 		$is = $this->Common->metaAlternate(array('controller'=>'some', 'action'=>'url'), 'de', true);
 		$this->out(h($is));
-		$this->assertEquals('<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="de" />', trim($is));
+		$this->assertEquals('<link href="http://'.HTTP_HOST.$this->Common->url('/some/url').'" rel="alternate" hreflang="de" />', trim($is));
 
 		$is = $this->Common->metaAlternate(array('controller'=>'some', 'action'=>'url'), array('de', 'de-ch'), true);
 		$this->out(h($is));
-		$this->assertEquals('<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="de" />'.PHP_EOL.'<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="de-ch" />', trim($is));
+		$this->assertEquals('<link href="http://'.HTTP_HOST.$this->Common->url('/some/url').'" rel="alternate" hreflang="de" />'.PHP_EOL.'<link href="http://'.HTTP_HOST.$this->Common->url('/some/url').'" rel="alternate" hreflang="de-ch" />', trim($is));
 
 		$is = $this->Common->metaAlternate(array('controller'=>'some', 'action'=>'url'), array('de' => array('ch', 'at'), 'en'=>array('gb', 'us')), true);
 		$this->out(h($is));
-		$this->assertEquals('<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="de-ch" />'.PHP_EOL.
-			'<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="de-at" />'.PHP_EOL.
-			'<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="en-gb" />'.PHP_EOL.
-			'<link href="http://'.HTTP_HOST.'/some/url" rel="alternate" hreflang="en-us" />', trim($is));
+		$this->assertEquals('<link href="http://'.HTTP_HOST.$this->Common->url('/some/url').'" rel="alternate" hreflang="de-ch" />'.PHP_EOL.
+			'<link href="http://'.HTTP_HOST.$this->Common->url('/some/url').'" rel="alternate" hreflang="de-at" />'.PHP_EOL.
+			'<link href="http://'.HTTP_HOST.$this->Common->url('/some/url').'" rel="alternate" hreflang="en-gb" />'.PHP_EOL.
+			'<link href="http://'.HTTP_HOST.$this->Common->url('/some/url').'" rel="alternate" hreflang="en-us" />', trim($is));
 	}
 
-
-
+	/**
+	 */
 	public function testEsc() {
 		$is = $this->Common->esc('Some Cool Text with <b>Html</b>');
 		$this->assertEquals($is, 'Some Cool Text with &lt;b&gt;Html&lt;/b&gt;');
@@ -58,7 +55,7 @@ class CommonHelperTest extends MyCakeTestCase {
 		$is = $this->Common->esc('Some Cool Text'.PHP_EOL.'with <b>Html</b>');
 		$this->assertEquals($is, 'Some Cool Text<br />'.PHP_EOL.'with &lt;b&gt;Html&lt;/b&gt;');
 
-		$is = $this->Common->esc('Some Cool'.PHP_EOL.' 2 indends and'.PHP_EOL.' 5 indends'.PHP_EOL.'YEAH');
+		$is = $this->Common->esc('Some Cool'.PHP_EOL.'  2 indends and'.PHP_EOL.'     5 indends'.PHP_EOL.'YEAH');
 		$this->assertEquals($is, 'Some Cool<br />'.PHP_EOL.'&nbsp;&nbsp;2 indends and<br />'.PHP_EOL.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5 indends<br />'.PHP_EOL.'YEAH');
 
 		$options = array('tabsToSpaces'=>2);
@@ -67,51 +64,6 @@ class CommonHelperTest extends MyCakeTestCase {
 
 	}
 
-	/**
-	 * test minimizeUrl
-	 *
-	 * @access public
-	 * @return void
-	 * 2009-03-11 ms
-	 */
-	public function testMinimizeUrl() {
-
-		$url = 'http://www.test.de';
-		$this->assertEquals($url, $this->Common->minimizeUrl($url,20));
-
-		$url = 'http://www.test.de';
-		$this->assertEquals($url, $this->Common->minimizeUrl($url,18));
-
-		$url = 'http://www.test.de';
-		$this->assertEquals('www.test.de', $this->Common->minimizeUrl($url,17));
-
-		$url = 'http://www.testpage.de';
-		$this->assertEquals('ww&#8230;ge.de', $this->Common->minimizeUrl($url,10));
-
-		$url = 'http://www.testpage.de';
-		$this->assertEquals('ww...ge.de', $this->Common->minimizeUrl($url,10, array('placeholder'=>'...')));
-
-		# without full http://
-		$url = 'www.testpage.de';
-		$this->assertEquals($url, $this->Common->minimizeUrl($url,15));
-
-		$url = 'www.testpage.de';
-		$this->assertEquals('www.te&#8230;ge.de', $this->Common->minimizeUrl($url,14));
-
-	}
-
-
-	/**
-	 * test shortenText
-	 *
-	 * @access public
-	 * @return void
-	 * 2009-03-11 ms
-	 */
-	public function testShortenText() {
-
-	}
-
 
 /**
  * tearDown method
@@ -122,5 +74,6 @@ class CommonHelperTest extends MyCakeTestCase {
 	public function tearDown() {
 		unset($this->Common);
 	}
+
 }
 

+ 44 - 0
Test/Case/View/Helper/TextExtHelperTest.php

@@ -193,4 +193,48 @@ class TextExtHelperTest extends MyCakeTestCase {
 		$this->assertEquals($result, $expected);
 	}
 
+	/**
+	 * test minimizeUrl
+	 *
+	 * @access public
+	 * @return void
+	 * 2009-03-11 ms
+	 */
+	public function testMinimizeUrl() {
+
+		$url = 'http://www.test.de';
+		$this->assertEquals($url, $this->Text->minimizeUrl($url,20));
+
+		$url = 'http://www.test.de';
+		$this->assertEquals($url, $this->Text->minimizeUrl($url,18));
+
+		$url = 'http://www.test.de';
+		$this->assertEquals('www.test.de', $this->Text->minimizeUrl($url,17));
+
+		$url = 'http://www.testpage.de';
+		$this->assertEquals('ww&#8230;ge.de', $this->Text->minimizeUrl($url,10));
+
+		$url = 'http://www.testpage.de';
+		$this->assertEquals('ww...ge.de', $this->Text->minimizeUrl($url,10, array('placeholder'=>'...')));
+
+		# without full http://
+		$url = 'www.testpage.de';
+		$this->assertEquals($url, $this->Text->minimizeUrl($url,15));
+
+		$url = 'www.testpage.de';
+		$this->assertEquals('www.te&#8230;ge.de', $this->Text->minimizeUrl($url,14));
+
+	}
+
+	/**
+	 * test shortenText
+	 *
+	 * @access public
+	 * @return void
+	 * 2009-03-11 ms
+	 */
+	public function testShortenText() {
+
+	}
+
 }

+ 4 - 15
View/Helper/DatetimeHelper.php

@@ -155,22 +155,11 @@ class DatetimeHelper extends TimeHelper {
 			//$span = '<span class="published '..'">';	// -1/-2 = ago | 1/2 = ahead | 0 = today
 			//$spanEnd = '</span>';
 		}
-		if (isset($this->Html)) {
-			return $this->Html->tag('span', $niceDate, $attr);
+		if (!isset($this->Html)) {
+			//TODO: fixme
+			$this->loadHelpers(array('Html'));
 		}
-		//TODO: fix me here
-		trigger_error('HtmlHelper not found');
-		$a = array();
-		foreach ($attr as $key => $val) {
-			$a[] = $key.'="'.$val.'"';
-		}
-		$attr = '';
-		if (!empty($a)) {
-			$attr .= ' '.implode(' ', $a);
-		}
-		$span = '<span'.$attr.'>';
-		$spanEnd = '</span>';
-		return $span . $niceDate . $spanEnd;
+		return $this->Html->tag('span', $niceDate, $attr);
 	}
 
 

+ 3 - 3
View/Helper/FormExtHelper.php

@@ -644,7 +644,7 @@ class FormExtHelper extends FormHelper { // Maybe FormHelper itself some day?
 </script>
 		';
 
-			$options = am(array('id' => $modelName.$fieldName), $options);
+			$options = array_merge(array('id' => $modelName.$fieldName), $options);
 			$select = $this->text($field, $options);
 			return '<div class="input date'.(!empty($error)?' error':'').'">'.$this->label($modelName.'.'.$field, $options['label']).''.$select.''.$error.'</div>'.$script;
 		}
@@ -854,7 +854,7 @@ jQuery(\''.$selector.'\').maxlength('.$this->Js->object($settings, array('quoteK
 				$selector = $settings;
 				$settings = array();
 			}
-			$settings = am($this->charCountOptions, $options, $settings);
+			$settings = array_merge($this->charCountOptions, $options, $settings);
 			$js .= 'jQuery(\''.$selector.'\').charCount('.$this->Js->object($settings, array('quoteKeys'=>false)).');';
 		}
 		$js = $this->documentReady($js);
@@ -973,7 +973,7 @@ jQuery(\''.$selector.'\').maxlength('.$this->Js->object($settings, array('quoteK
 		$defaults = array(
 	 		'class' => 'checkboxToggle'
 		);
-		$options = am($defaults, $options);
+		$options = array_merge($defaults, $options);
 		return $script . parent::checkbox($fieldName, $options);
 	}