浏览代码

More cleanup

euromark 10 年之前
父节点
当前提交
a91e8ac7ac

+ 0 - 90
Lib/SpellLib.php

@@ -1,90 +0,0 @@
-<?php
-if (!defined('ENCHANT_MYSPELL')) {
-	define('ENCHANT_MYSPELL', 1);
-}
-if (!defined('ENCHANT_ISPELL')) {
-	define('ENCHANT_ISPELL', 2);
-}
-
-/**
- * Wrapper for the PHP Extension Enchant which provides basic spellchecking
- * @author Mark Scherer
- * @licence MIT
- *
- */
-class SpellLib {
-
-	const ENGINE_MYSPELL = ENCHANT_MYSPELL; # default engine
-
-	const ENGINE_ISPELL = ENCHANT_ISPELL;
-
-	/**
-	 * Available engines
-	 */
-	protected $_engines = [self::ENGINE_MYSPELL => 'myspell', self::ENGINE_ISPELL => 'ispell'];
-
-	/**
-	 * Available languages
-	 */
-	protected $_langs = ['en_GB', 'de_DE'];
-
-	protected $_Broker;
-
-	protected $_Dict;
-
-	//public $settings = array();
-
-	public function __construct($options = []) {
-		if (!function_exists('enchant_broker_init')) {
-			throw new InternalErrorException(sprintf('Module %s not installed', 'Enchant'));
-		}
-		$this->_Broker = enchant_broker_init();
-
-		$defaults = [
-			'path' => VENDORS . 'dictionaries' . DS,
-			'lang' => 'en_GB',
-			'engine' => static::ENGINE_MYSPELL
-		];
-		$defaults = array_merge($defaults, (array)Configure::read('Spell'));
-		$options = array_merge($defaults, $options);
-
-		if (!isset($this->_engines[$options['engine']])) {
-			throw new InternalErrorException(sprintf('Engine %s not found', (string)$options['engine']));
-		}
-		$engineFolder = $this->_engines[$options['engine']];
-		enchant_broker_set_dict_path($this->_Broker, $options['engine'], $options['path'] . $engineFolder . DS);
-
-		if (!enchant_broker_dict_exists($this->_Broker, $options['lang'])) {
-			throw new InternalErrorException(sprintf('Dictionary %s not found', $options['lang']));
-		}
-
-		$this->_Dict = enchant_broker_request_dict($this->_Broker, $options['lang']);
-	}
-
-	public function listDictionaries() {
-		return enchant_broker_list_dicts($this->_Broker);
-	}
-
-	public function listBrokers() {
-		return enchant_broker_describe($this->_Broker);
-	}
-
-	/**
-	 * @return bool Success
-	 */
-	public function check($word) {
-		return enchant_dict_check($this->_Dict, $word);
-	}
-
-	/**
-	 * @return array listOfSuggestions
-	 */
-	public function suggestions($word) {
-		return enchant_dict_suggest($this->_Dict, $word);
-	}
-
-	public function __destruct() {
-		enchant_broker_free($this->_Broker);
-	}
-
-}

+ 0 - 1
Lib/Utility/Utility.php

@@ -53,7 +53,6 @@ class Utility {
 
 		if ($options['callback']) {
 			foreach ($tokens as $key => $token) {
-				debug($token);
 				$tokens[$key] = $options['callback']($token);
 			}
 		}

+ 0 - 97
Test/Case/Lib/SpellLibTest.php

@@ -1,97 +0,0 @@
-<?php
-
-App::uses('SpellLib', 'Tools.Lib');
-App::uses('MyCakeTestCase', 'Tools.TestSuite');
-
-class SpellLibTest extends MyCakeTestCase {
-
-	public $SpellLib;
-
-	public function setUp() {
-		parent::setUp();
-
-		$this->skipIf(!function_exists('enchant_broker_init'), __d('tools', 'Module %s not installed', 'Enchant'));
-
-		$this->SpellLib = new SpellLib();
-	}
-
-	public function tearDown() {
-		parent::tearDown();
-
-		unset($this->SpellLib);
-	}
-
-	public function testObject() {
-		$this->assertInstanceOf('SpellLib', $this->SpellLib);
-	}
-
-	public function testList() {
-		$res = $this->SpellLib->listBrokers();
-		//debug($res);
-		$this->assertTrue(is_array($res) && count($res) > 1);
-		$this->assertTrue(in_array($res[0]['name'], ['ispell', 'myspell']));
-
-		$res = $this->SpellLib->listDictionaries();
-		//debug($res);
-		$this->assertTrue(is_array($res) && count($res) > 1);
-		$this->assertTrue(in_array($res[0]['lang_tag'], ['de_DE', 'en_GB']));
-	}
-
-	public function testDefaults() {
-		$word = 'house';
-		$res = $this->SpellLib->check($word);
-		$this->assertTrue($res);
-
-		$word = 'soong';
-		$res = $this->SpellLib->check($word);
-		$this->assertFalse($res);
-		$suggestions = $this->SpellLib->suggestions($word);
-		//debug($suggestions);
-		$this->assertTrue(is_array($suggestions) && count($suggestions) > 1);
-		$this->assertTrue(in_array('song', $suggestions));
-
-		$word = 'bird';
-		$res = $this->SpellLib->check($word);
-		$this->assertTrue($res);
-	}
-
-	public function testGerman() {
-		$this->SpellLib = new SpellLib(['lang' => 'de_DE']);
-
-		$word = 'Wand';
-		$res = $this->SpellLib->check($word);
-		$this->assertTrue($res);
-
-		$word = 'Hauz';
-		$res = $this->SpellLib->check($word);
-		$this->assertFalse($res);
-		$suggestions = $this->SpellLib->suggestions($word);
-		//debug($suggestions);
-		$this->assertTrue(is_array($suggestions) && count($suggestions) > 1);
-		$this->assertTrue(in_array('Haus', $suggestions));
-
-		$word = 'Mäuse';
-		$res = $this->SpellLib->check($word);
-		$this->assertTrue($res);
-	}
-
-	public function testConfigureConfiguration() {
-		Configure::write('Spell.lang', 'de_DE');
-		$this->SpellLib = new SpellLib();
-
-		$word = 'Mäuse';
-		$res = $this->SpellLib->check($word);
-		$this->assertTrue($res);
-
-		Configure::write('Spell.lang', 'en_GB');
-		$this->SpellLib = new SpellLib();
-
-		$word = 'Mäuse';
-		$res = $this->SpellLib->check($word);
-		$this->assertFalse($res);
-		$suggestions = $this->SpellLib->suggestions($word);
-		$this->assertTrue(is_array($suggestions) && count($suggestions) > 0);
-		$this->assertTrue(in_array('Mouse', $suggestions));
-	}
-
-}

+ 42 - 0
Test/Case/View/Helper/HcardHelperTest.php

@@ -0,0 +1,42 @@
+<?php
+
+App::uses('HcardHelper', 'Tools.View/Helper');
+App::uses('MyCakeTestCase', 'Tools.TestSuite');
+App::uses('CakeText', 'Utility');
+App::uses('View', 'View');
+
+/**
+ * A wrapper for HCard
+ *
+ * @author Mark Scherer
+ * @license http://opensource.org/licenses/mit-license.php MIT
+ */
+class HcardHelperTest extends MyCakeTestCase {
+
+	public $Hcard;
+
+	public function setUp() {
+		parent::setUp();
+
+		$this->Hcard = new HcardHelper(new View(null));
+	}
+
+	public function tearDown() {
+		parent::tearDown();
+	}
+
+	public function testObject() {
+		$this->assertInstanceOf('HcardHelper', $this->Hcard);
+	}
+
+	public function testAddress() {
+		$res = $this->Hcard->address();
+		$this->assertTrue(!empty($res));
+	}
+
+	public function testAddressFormatHtml() {
+		$res = $this->Hcard->addressFormatHtml();
+		$this->assertTrue(!empty($res));
+	}
+
+}

+ 0 - 165
View/Helper/BootstrapHelper.php

@@ -1,165 +0,0 @@
-<?php
-App::uses('AppHelper', 'View/Helper');
-
-/**
- * Generic html snippets to display some specific widgets like accordion
- *
- * Note:
- * This is meant to work with TwitterBootstrap (Layout and Script), but
- * should also work with other custom solutions (if they use the same selectors).
- *
- * Dependencies:
- * The respective JS plugins for the widgets.
- *
- * @license http://opensource.org/licenses/mit-license.php MIT
- * @author Mark Scherer
- * @php 5
- * @version 1.0
- */
-class BootstrapHelper extends AppHelper {
-
-	public $helpers = ['Html', 'Form'];
-
-	protected $_count = 1;
-
-	protected $_items = [];
-
-	public function xx() {
-		//
-	}
-
-	/**
-	 * Complete typeahead form input element
-	 *
-	 * @param fieldName
-	 * @param options:
-	 * - data (array of strings)
-	 * - items (defaults to 8)
-	 * @return string html
-	 */
-	public function typeahead($fieldName, $options = [], $inputOptions = []) {
-		$inputOptions['data-provide'] = 'typeahead';
-		//$inputOptions['data-source'] = $this->_formatSource($options['data']);
-		if (!empty($options['items'])) {
-			$inputOptions['data-items'] = (int)$options['items'];
-		}
-		$class = 'typeahead_' . strtolower(Inflector::slug($fieldName)); // str_replace('.', '_', $fieldName);
-		$inputOptions['class'] = empty($inputOptions['class']) ? $class : $inputOptions['class'] . ' ' . $class;
-
-		$script = '
-	$(\'.' . $class . '\').typeahead({
-		source: ' . $this->_formatSource($options['data']) . '
-	})
-';
-		$script = PHP_EOL . '<script>' . $script . '</script>';
-		return $this->Form->input($fieldName, $inputOptions) . $script;
-	}
-
-	public function _formatSource($elements) {
-		//$res = array();
-		//return '[\''.implode('\',\'', $elements).'\']';
-		return json_encode($elements);
-	}
-
-	/**
-	 * Complete carousel container
-	 *
-	 * @param array $items (heading, content, active)
-	 * @param id
-	 * @param array $options
-	 * @return string html
-	 */
-	public function carousel($items, $id = null, $globalOptions = []) {
-		$res = '<div id="myCarousel" class="carousel">
-	<div class="carousel-inner">
-		' . $this->carouselItems($items, $globalOptions) . '
-	</div>
-	' . $this->carouselControl() . '
-</div>';
-		return $res;
-	}
-
-	public function carouselControl() {
-		$res = '<a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
-	<a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>';
-		return $res;
-	}
-
-	/**
-	 * Items of a carousel container
-	 *
-	 * @param array $items (heading, content, active)
-	 * - active (visible, true/false)
-	 * @return string html
-	 */
-	public function carouselItems($items, $options = []) {
-		$res = [];
-		foreach ($items as $key => $item) {
-			$active = '';
-			if ($key == 0 && !isset($item['active']) || !empty($item['active'])) {
-				$active = ' active';
-			}
-			$tmp = $item['content'];
-			if (!empty($item['heading'])) {
-				$tmp .= '<div class="carousel-caption">' . $item['heading'] . '</div>';
-			}
-			$tmp = '<div class="item' . $active . '">' . $tmp . '</div>';
-			$res[] = $tmp;
-		}
-		$res = implode(PHP_EOL, $res);
-		return $res;
-	}
-
-	/**
-	 * Complete accordion container
-	 *
-	 * @param array $records (heading, content, options)
-	 * @param id
-	 * @param array $options
-	 * @return string html
-	 */
-	public function accordion($records, $id = null, $globalOptions = []) {
-		$res = '<div class="accordion" id="accordion' . $id . '">';
-		foreach ($records as $record) {
-			$options = $globalOptions;
-			extract($record);
-			$res .= $this->accordionGroup($heading, $content, $options);
-		}
-		$res .= '</div>';
-		return $res;
-	}
-
-	/**
-	 * A single group of an accordion container
-	 *
-	 * @param string $heading
-	 * @param string $content
-	 * @param array $options
-	 * - active (collapsed, true/false)
-	 * @return string html
-	 */
-	public function accordionGroup($heading, $content, $options = []) {
-		$i = $this->_count;
-		$this->_count++;
-		$in = '';
-		if ($i == 1 && !isset($options['active']) || !empty($options['active'])) {
-			$in = ' in';
-		}
-
-		$res = '<div class="accordion-group">';
-		$res .= '	<div class="accordion-heading">';
-
-		$res .= '		<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse' . $i . '">';
-		$res .= $heading;
-		$res .= '		</a>';
-		$res .= '	</div>';
-		$res .= '	<div id="collapse' . $i . '" class="accordion-body collapse' . $in . '">';
-		$res .= '	<div class="accordion-inner">';
-		$res .= $content;
-		$res .= '	</div>';
-		$res .= '	</div>';
-		$res .= '</div>';
-		return $res;
-	}
-
-}

+ 12 - 6
View/Helper/HcardHelper.php

@@ -28,10 +28,12 @@ class HcardHelper extends AppHelper {
 	];
 
 	/**
+	 * @param array $data
+	 *
 	 * @return string HTML
 	 */
-	public function addressFormatHtml($data = null, $format = 'General') {
-		if ($data === null) {
+	public function addressFormatHtml(array $data = [], $format = 'General') {
+		if (!$data) {
 			$data = $this->_defaults;
 		}
 		$text = '';
@@ -43,10 +45,12 @@ class HcardHelper extends AppHelper {
 	}
 
 	/**
+	 * @param array $data
+	 *
 	 * @return string
 	 */
-	public function addressFormatRaw($data = null, $format = 'General') {
-		if ($data === null) {
+	public function addressFormatRaw(array $data = [], $format = 'General') {
+		if (!$data) {
 			$data = $this->_defaults;
 		}
 		$text = $data['given_name'] . ' ' . $data['family_name'] . "\n";
@@ -61,10 +65,12 @@ class HcardHelper extends AppHelper {
 	}
 
 	/**
+	 * @param array $data
+	 *
 	 * @return string
 	 */
-	public function address($data) {
-		if ($data === null) {
+	public function address(array $data = []) {
+		if (!$data) {
 			$data = $this->_defaults;
 		}
 		$text = '<div class="adr">';