diff --git a/Core/Comments/Config/config.php b/Core/Comments/Config/config.php index 332229a96..314700a31 100755 --- a/Core/Comments/Config/config.php +++ b/Core/Comments/Config/config.php @@ -1,36 +1,26 @@ - * - * - * - */ +/** + * Configuration defaults for the comments plugin + * + * Default options should always be overlaoded in the backend via the + * congfigs plugin. + * + * @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) + * @link http://www.infinitas-cms.org + * @package Infinitas.Comments + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + * @since 0.8a + * + * @author Carl Sutton + */ - $config['Comments'] = array( - /** - * configuration - */ - 'auto_moderate' => true, // automatically accept and acticvate comments that are not spam - 'purge' => '4 weeks', // automatic spam purge - 'time_limit' => '4 weeks', // after this time commets are closed - 'fields' => 'username,email,website,comment', // fileds for the form - - /** - * rating params - */ - 'spam_threshold' => -25, // below this things are just ignored - 'maximum_links' => 2, // number of links before things are considered spammy - 'minimum_length' => 20 // below this its spammy - ); \ No newline at end of file +$config['Comments'] = array( + 'auto_moderate' => true, // automatically accept and acticvate comments that are not spam + 'purge' => '4 weeks', // automatic spam purge + 'time_limit' => '4 weeks', // after this time commets are closed + 'fields' => 'username,email,website,comment', // fileds for the form + + 'spam_threshold' => -25, // below this things are just ignored + 'maximum_links' => 2, // number of links before things are considered spammy + 'minimum_length' => 20 // below this its spammy +); \ No newline at end of file diff --git a/Core/Comments/Controller/CommentsAppController.php b/Core/Comments/Controller/CommentsAppController.php index a39f3330e..e71eba627 100644 --- a/Core/Comments/Controller/CommentsAppController.php +++ b/Core/Comments/Controller/CommentsAppController.php @@ -1,118 +1,109 @@ element('modules/comment', array('plugin' => 'comments')); - * - * // more advanced for wierd setups - * // when you dont use conventions you will need to tell infinitas what is what - * $this->element( - * 'modules/comment', - * array( - * 'plugin' => 'comments', - * 'content' => $model, - * 'modelName' => 'Model' - * ) - * ); - * @endcode - * - * @todo currently passing foreign_id which is not needed, the comment element - * should figure this out as the model is being passed. it can be obtained from - * the data using ->primaryKey - * - * That is all there is to it. Should you wish to do something really different - * you can overlaod the comment module in a theme. you can also change the - * plugin that is passed in the second param to anything you like should you - * overload it, just remember where and create the file in the corresponding - * directory. The other option is to just define your own comment element and - * call it in your view. Take note of the core one as there are some conditions - * that need to be met like setting the action of the form and the data that - * should be passed in. - * - * - * @section categories-code How it works - * - * Currently the comments are saved by a method in AppController::comment() so - * that you can just set the action to 'comment' and it will work as all controllers - * extend AppController they inherit the method. - * - * After the comment is submitted it under goes a rating and a score is determined - * for. It can then based on the configuration be accepted and marked as active - * automatically if it has passed, or if its edge case will be marked as pending - * for admin to later activte it. Comments with very low scores can be set to - * not save. - * - * @image html sql_comments_plugin.png "Comments Plugin table structure" - * - * @todo record ip addresses of people repeatedly entering comments and block - * them for a set time with the ip blocking stuff simmilar to the brute force - * attacks. can help reduce sever load by blackholing spam bots. - * - * @todo limit comments to x per hour or something (setting) - * - * @section categories-see-also Also see - * @ref EventCore - * @ref FilterHelper - * @ref GravatarHelper - * @ref ExpandableBehavior - * @ref ExpandableBehavior - */ +/** + * @page Comments-Plugin Comments plugin + * + * @section charts-overview What is it + * + * The Comments plugin allows you to add comments to any row of data for your + * entire application by simply adding some fields to your database and including + * the elements where needed. + * + * The comments can be anything, not only comments in the sence of blogs. For + * example they could also be used for notes on shop orders, communication in + * a bugtracker etc. + * + * The fields used in the comments are flexible, having only the comment field + * and the users email address as required fields for the form. Adding extra + * fields to the form will be saved in a EAV table handled by the ExpandableBehavior + * + * @section categories-usage How to use it + * + * To get comments running in your plugin you will need to do a few things, first + * of which is adding a field to the table you wish to allow users to comment on + * The field should be called 'comment_count' and should be of type INT() MEDIUMINT() + * or any other integer type field you would require. + * + * After that has been done you will need to include the element for the comment + * form and latest comments in your views where you would like to see it. Example + * usage is below. + * + * The comments plugin uses a nifty rating system that checks a number of + * configurable details of the comment and gives it a score. If the score is + * too low it is regarded as spam. If it is below the threshold it will not + * even be saved. A number of factors are included in the score such as the lenght + * of the comment, the number of previous comments that were accepted and number + * of links that are in the comment body. + * + * @code + * // simple when using the correct conventions + * // infinitas will figure out the title, and where to save the comment + * echo $this->element('modules/comment', array('plugin' => 'comments')); + * + * // more advanced for wierd setups + * // when you dont use conventions you will need to tell infinitas what is what + * $this->element( + * 'modules/comment', + * array( + * 'plugin' => 'comments', + * 'content' => $model, + * 'modelName' => 'Model' + * ) + * ); + * @endcode + * + * That is all there is to it. Should you wish to do something really different + * you can overlaod the comment module in a theme. you can also change the + * plugin that is passed in the second param to anything you like should you + * overload it, just remember where and create the file in the corresponding + * directory. The other option is to just define your own comment element and + * call it in your view. Take note of the core one as there are some conditions + * that need to be met like setting the action of the form and the data that + * should be passed in. + * + * + * @section categories-code How it works + * + * Currently the comments are saved by a method in AppController::comment() so + * that you can just set the action to 'comment' and it will work as all controllers + * extend AppController they inherit the method. + * + * After the comment is submitted it under goes a rating and a score is determined + * for. It can then based on the configuration be accepted and marked as active + * automatically if it has passed, or if its edge case will be marked as pending + * for admin to later activte it. Comments with very low scores can be set to + * not save. + * + * @image html sql_comments_plugin.png "Comments Plugin table structure" + * + * @section categories-see-also Also see + * @ref EventCore + * @ref FilterHelper + * @ref GravatarHelper + * @ref ExpandableBehavior + */ - App::uses('AppController', 'Controller'); +App::uses('AppController', 'Controller'); - /** - * CommentsAppController is the base class that all comments controllers extend - * - * @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) - * @link http://www.infinitas-cms.org - * @package Infinitas.Comments - * @license http://www.opensource.org/licenses/mit-license.php The MIT License - * @since 0.8a - * - * @author Carl Sutton - */ - class CommentsAppController extends AppController{ - /** - * some helpers to load for this plugin - * - * @var array - */ - public $helpers = array( - 'Libs.Gravatar' - ); - } \ No newline at end of file +/** + * CommentsAppController is the base class that all comments controllers extend + * + * @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) + * @link http://www.infinitas-cms.org + * @package Infinitas.Comments + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + * @since 0.8a + * + * @author Carl Sutton + */ + +class CommentsAppController extends AppController{ + +/** + * some helpers to load for this plugin + * + * @var array + */ + public $helpers = array( + 'Libs.Gravatar' + ); +} \ No newline at end of file diff --git a/Core/Comments/Controller/Component/CommentsComponent.php b/Core/Comments/Controller/Component/CommentsComponent.php index ff1ea3c30..6e666b28b 100644 --- a/Core/Comments/Controller/Component/CommentsComponent.php +++ b/Core/Comments/Controller/Component/CommentsComponent.php @@ -1,51 +1,51 @@ Controller->request->data[$this->Controller->modelClass.'Comment'])) { - $message = 'Your comment has been saved and will be available after admin moderation.'; - if (Configure::read('Comments.auto_moderate') === true) { - $message = 'Your comment has been saved and is active.'; - } - - $this->Controller->request->data[$this->Controller->modelClass.'Comment']['ip_address'] = $this->Controller->request->clientIp(); - $this->Controller->request->data[$this->Controller->modelClass.'Comment']['class'] = $this->Controller->request->plugin . '.' . $this->Controller->modelClass; - - if (!empty($this->Controller->request->data[$this->Controller->modelClass.'Comment']['om_non_nom'])) { - $this->Controller->Session->write('Spam.bot', true); - $this->Controller->Session->write('Spam.detected', time()); - - $this->Controller->notice( - __d('comments', 'Not so fast spam bot.'), - array( - 'redirect' => '/?bot=true' - ) - ); - } - - if ($this->Controller->{$this->Controller->modelClass}->createComment($this->Controller->request->data)) { - $this->Controller->notice( - __d('comments', $message), - array('redirect' => true) - ); - } - - $this->Controller->notice('not_saved'); +App::uses('InfinitasComponent', 'Libs.Controller/Component'); +/** + * Comments component + * + * + */ + +class CommentsComponent extends InfinitasComponent { + +/** + * Allow posting comments to any controller + * + * @return void + */ + public function actionComment() { + $modelClass = $this->Controller->modelClass . 'Comment'; + if (!empty($this->Controller->request->data[])) { + $message = 'Your comment has been saved and will be available after admin moderation.'; + if (Configure::read('Comments.auto_moderate') === true) { + $message = 'Your comment has been saved and is active.'; } - return $this->Controller->render(null, null, App::pluginPath('Comments') . 'View' . DS . 'InfinitasComments' . DS . 'add.ctp'); + $this->Controller->request->data[$modelClass]['ip_address'] = $this->Controller->request->clientIp(); + $this->Controller->request->data[$modelClass]['class'] = $this->Controller->request->plugin . '.' . $this->Controller->modelClass; + + if (!empty($this->Controller->request->data[$modelClass]['om_non_nom'])) { + $this->Controller->Session->write('Spam.bot', true); + $this->Controller->Session->write('Spam.detected', time()); + + $this->Controller->notice( + __d('comments', 'Not so fast spam bot.'), + array( + 'redirect' => '/?bot=true' + ) + ); + } + + if ($this->Controller->{$this->Controller->modelClass}->createComment($this->Controller->request->data)) { + $this->Controller->notice( + __d('comments', $message), + array('redirect' => true) + ); + } + + $this->Controller->notice('not_saved'); } - } \ No newline at end of file + + return $this->Controller->render(null, null, App::pluginPath('Comments') . 'View' . DS . 'InfinitasComments' . DS . 'add.ctp'); + } +} \ No newline at end of file diff --git a/Core/Comments/Controller/InfinitasCommentsController.php b/Core/Comments/Controller/InfinitasCommentsController.php index 41c84b922..5ae6a451d 100644 --- a/Core/Comments/Controller/InfinitasCommentsController.php +++ b/Core/Comments/Controller/InfinitasCommentsController.php @@ -21,6 +21,7 @@ */ class InfinitasCommentsController extends CommentsAppController { + /** * View a list of comments * @@ -78,24 +79,20 @@ public function admin_index() { $class = ClassRegistry::init(ucfirst($comment[$this->modelClass]['class'])); if (isset($class->contentable) && $class->contentable) { $class = ClassRegistry::init('Contents.GlobalContent'); - $list = $class->find( - 'list', - array( - 'fields' => array( - $class->alias . '.id', - $class->alias . '.title' - ), - 'conditions' => array( - $class->alias . '.foreign_key' => $comment[$this->modelClass]['foreign_id'] - ) + $list = $class->find('list', array( + 'fields' => array( + $class->alias . '.id', + $class->alias . '.title' + ), + 'conditions' => array( + $class->alias . '.foreign_key' => $comment[$this->modelClass]['foreign_id'] ) - ); + )); if (empty($list)) { $list = array(__d('comments', 'Invalid Record')); } $comment[$this->modelClass]['post'] = current($list); - } - else { + } else { $class->id = $comment[$this->modelClass]['foreign_id']; $comment[$this->modelClass]['post'] = $class->field($class->displayField); } @@ -116,10 +113,9 @@ public function admin_index() { /** * Reply to comments * - * @todo reply to the comment. + * @return void */ public function admin_reply() { - } /** @@ -224,5 +220,4 @@ private function __removeSpam() { ) ); } - } \ No newline at end of file diff --git a/Core/Comments/Lib/CommentsEvents.php b/Core/Comments/Lib/CommentsEvents.php index 3c08836d8..f8787357b 100644 --- a/Core/Comments/Lib/CommentsEvents.php +++ b/Core/Comments/Lib/CommentsEvents.php @@ -12,6 +12,7 @@ */ class CommentsEvents extends AppEvents { + /** * get the plugin information * @@ -139,5 +140,4 @@ public function onUserProfile(Event $event) { 'element' => 'profile' ); } - } \ No newline at end of file diff --git a/Core/Comments/Model/Behavior/CommentableBehavior.php b/Core/Comments/Model/Behavior/CommentableBehavior.php index 58dc8b413..a1164bd5b 100644 --- a/Core/Comments/Model/Behavior/CommentableBehavior.php +++ b/Core/Comments/Model/Behavior/CommentableBehavior.php @@ -12,7 +12,7 @@ * * Allows you to attach a comment to any model in your application * Moderates/Validates comments to check for spam. - * Validates comments based on a point system. High points is an automatic approval, + * Validates comments based on a point system. High points is an automatic approval, * where as low points is marked as spam or deleted. * * Based on Jonathan Snooks outline. @@ -25,12 +25,6 @@ * * @author Jose Diaz-Gonzalez - http://github.com/josegonzalez/cakephp-commentable-behavior * @author Carl Sutton - * - * @todo this code should be refactored into a spam filter lib that can be used - * all over (eg: email contact forms) the comment model can just check in beforeSave - * that it is not spam, could even be a validation rule. - * - * @todo add a rating method for amount of text with no links vs total amount of text */ class CommentableBehavior extends ModelBehavior { @@ -76,7 +70,7 @@ public function setup(Model $Model, $settings = array()) { $default['blacklist_keywords'] = explode(',', Configure::read('Website.blacklist_keywords')); $default['blacklist_words'] = explode(',', Configure::read('Website.blacklist_words')); $default['conditions'] = array('Comment.class' => $Model->alias); - $default['class'] = $Model->name.'Comment'; + $default['class'] = $Model->name . 'Comment'; if (!isset($this->__settings[$Model->alias])) { $this->__settings[$Model->alias] = $default; @@ -245,7 +239,6 @@ private function __mxRecord($email) { if (empty($host[1])) { return false; - continue; } if (function_exists('getmxrr')) { diff --git a/Core/Configs/Controller/ConfigsAppController.php b/Core/Configs/Controller/ConfigsAppController.php index 6cdbaef4c..2920bcfee 100644 --- a/Core/Configs/Controller/ConfigsAppController.php +++ b/Core/Configs/Controller/ConfigsAppController.php @@ -36,5 +36,5 @@ */ class ConfigsAppController extends AppController { - + } \ No newline at end of file diff --git a/Core/Configs/Controller/ConfigsController.php b/Core/Configs/Controller/ConfigsController.php index 299d23c07..44fc802b1 100644 --- a/Core/Configs/Controller/ConfigsController.php +++ b/Core/Configs/Controller/ConfigsController.php @@ -20,6 +20,7 @@ */ class ConfigsController extends ConfigsAppController { + /** * List configs in the database * @@ -64,7 +65,7 @@ public function admin_add() { $value = Configure::read($this->request->params['named']['Config.key']); switch(true) { case is_int($value): - $this->request->data['Config']['type'] = 'integer'; + $this->request->data['Config']['type'] = 'integer'; break; case is_bool($value): @@ -77,8 +78,7 @@ public function admin_add() { $this->request->data['Config']['type'] = 'array'; $this->request->data['Config']['value'] = $array[0]; $this->request->data['Config']['options'] = $value; - } - else{ + } else { $this->request->data['Config']['type'] = 'string'; } } diff --git a/Core/Configs/Lib/ConfigsEvents.php b/Core/Configs/Lib/ConfigsEvents.php index ae4e0f22e..0278e237f 100644 --- a/Core/Configs/Lib/ConfigsEvents.php +++ b/Core/Configs/Lib/ConfigsEvents.php @@ -20,6 +20,7 @@ */ class ConfigsEvents extends AppEvents { + /** * get the cache config for this plugin * diff --git a/Core/Configs/Model/Config.php b/Core/Configs/Model/Config.php index f811f0361..5c6141fee 100755 --- a/Core/Configs/Model/Config.php +++ b/Core/Configs/Model/Config.php @@ -20,6 +20,7 @@ */ class Config extends ConfigsAppModel { + /** * Custom table * @@ -94,8 +95,8 @@ public function __construct($id = false, $table = null, $ds = null) { ) ), 'options' => array( - 'customOptionCheck' => array( - 'rule' => 'customOptionCheck', + 'validateCustomOptionCheck' => array( + 'rule' => 'validateCustomOptionCheck', 'message' => __d('configs', 'Please enter some valid options') ) ) @@ -105,13 +106,11 @@ public function __construct($id = false, $table = null, $ds = null) { /** * validate the options based on what type is set for the row * - * @todo this should be renamed to validateCustomOptionCheck - * * @param array $data the field being validated * * @return boolean */ - public function customOptionCheck($data) { + public function validateCustomOptionCheck($data) { if (!isset($this->data[$this->alias]['type']) || empty($this->data[$this->alias]['type'])) { return true; } @@ -119,7 +118,6 @@ public function customOptionCheck($data) { switch($this->data[$this->alias]['type']) { case 'string': return true; - break; case 'integer': if (!empty($data['options']) && is_int($data['options'])) { @@ -131,7 +129,6 @@ public function customOptionCheck($data) { if (empty($data['options']) || is_int($data['options'])) { return false; } - //@todo needs a bit more work return is_string($data['options']); case 'bool': @@ -142,7 +139,6 @@ public function customOptionCheck($data) { case 'array': return $this->getJson($this->data[$this->alias]['value'], array(), false); - break; } return false; @@ -218,7 +214,7 @@ public function getConfig($format = false) { * * @return array */ - private function _formatConfigs($configs = array(), $json = false) { + protected function _formatConfigs($configs = array(), $json = false) { if (empty($configs)) { return false; } @@ -240,14 +236,11 @@ private function _formatConfigs($configs = array(), $json = false) { * @return array */ public function getInstallSetupConfigs() { - return $this->find( - 'all', - array( - 'conditions' => array( - $this->alias . '.key LIKE ' => 'Website.%' - ) + return $this->find('all', array( + 'conditions' => array( + $this->alias . '.key LIKE ' => 'Website.%' ) - ); + )); } /** @@ -267,34 +260,24 @@ public function generateCode($config) { } } + $_config = $config[$this->alias]['value']; if (is_bool($config[$this->alias]['value'])) { + $_config = 'false'; if ($config[$this->alias]['value']) { $_config = 'true'; } - - else{ - $_config = 'false'; - } - } - - else if (is_array($config[$this->alias]['value'])) { + } else if (is_array($config[$this->alias]['value'])) { $_config = 'array('; foreach ($config[$this->alias]['value'] as $k => $v) { - $_config .= !is_int($k) ? '\''.$k.'\'' : $k; - $_config .= '=> \''.$v.'\','; + $_config .= !is_int($k) ? '\'' . $k . '\'' : $k; + $_config .= '=> \'' . $v . '\','; } $_config .= ')'; + } else if (is_string($config[$this->alias]['value'])) { + $_config = '\'' . $config[$this->alias]['value'] . '\''; } - else if (is_string($config[$this->alias]['value'])) { - $_config = '\''.$config[$this->alias]['value'].'\''; - } - - else{ - $_config = $config[$this->alias]['value']; - } - - return 'Configure::write(\''.$config[$this->alias]['key'].'\', '.$_config.');'; + return 'Configure::write(\'' . $config[$this->alias]['key'] . '\', ' . $_config . ');'; } /** @@ -313,5 +296,4 @@ public function availableConfigs() { return $configs; } - } \ No newline at end of file diff --git a/Core/Configs/Model/ConfigsAppModel.php b/Core/Configs/Model/ConfigsAppModel.php index f7ff93524..364459b2c 100644 --- a/Core/Configs/Model/ConfigsAppModel.php +++ b/Core/Configs/Model/ConfigsAppModel.php @@ -21,11 +21,11 @@ */ class ConfigsAppModel extends AppModel { + /** * Custom prefix * * @var string */ public $tablePrefix = 'core_'; - } \ No newline at end of file diff --git a/Core/Configs/Test/Case/Model/ConfigTest.php b/Core/Configs/Test/Case/Model/ConfigTest.php index d19ae405e..67c6b526b 100644 --- a/Core/Configs/Test/Case/Model/ConfigTest.php +++ b/Core/Configs/Test/Case/Model/ConfigTest.php @@ -1,5 +1,4 @@ Config->customOptionCheck(array('options' => 'no type set yet so dont validate')); + $result = $this->Config->validateCustomOptionCheck(array('options' => 'no type set yet so dont validate')); $this->assertTrue($result); - /** - * test string inputs - */ + + // test string inputs $this->Config->data['Config']['type'] = 'string'; $data['options'] = 'abc'; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertTrue($result); $data['options'] = 123; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertTrue($result); $data['options'] = null; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertTrue($result); - /** - * test integer inputs - */ + // test integer inputs $this->Config->data['Config']['type'] = 'integer'; $data['options'] = null; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertFalse($result); $data['options'] = 'text'; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertFalse($result); $data['options'] = 123; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertTrue($result); - /** - * test dropdowns inputs - */ + // test dropdowns inputs $this->Config->data['Config']['type'] = 'dropdown'; $data['options'] = null; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertFalse($result); $data['options'] = 'text'; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertTrue($result); $data['options'] = 'option1,option2,option3,option4'; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertTrue($result); $data['options'] = 'option1, option2, option3, option4'; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertTrue($result); $data['options'] = 'option1 ,option2 ,option3 ,option4'; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertTrue($result); $data['options'] = 'option1 ,option2, option3 ,option4'; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertTrue($result); $data['options'] = 123; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertFalse($result); - /** - * test bool - */ + // test bool $this->Config->data['Config']['type'] = 'bool'; $data['options'] = null; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertFalse($result); $data['options'] = true; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertFalse($result); $data['options'] = false; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertFalse($result); $data['options'] = 'true,false'; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertTrue($result); $data['options'] = 'false,true'; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertTrue($result); - /** - * test array - */ + // test array $this->Config->data['Config']['type'] = 'array'; $data = array(); $this->Config->data['Config']['value'] = null; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertFalse($result); $this->Config->data['Config']['value'] = '{}'; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertFalse($result); $this->Config->data['Config']['value'] = 'some text'; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertFalse($result); // see more tests for checking json in the app model tests $this->Config->data['Config']['value'] = '{"hello":"world"}'; - $result = $this->Config->customOptionCheck($data); + $result = $this->Config->validateCustomOptionCheck($data); $this->assertTrue($result); } @@ -211,7 +207,7 @@ public function testGetConfigs() { * test cache is cleared after calling save */ public function testCacheRelatedStuff() { - return; // @todo broken tests + $this->skipIf(true); $result = Cache::read('global_configs'); $this->assertTrue($result, 'There is nothing in the cache'); $cacheConfigs = $this->Config->getConfig(); diff --git a/Core/Configs/Test/Fixture/ConfigFixture.php b/Core/Configs/Test/Fixture/ConfigFixture.php index 808313627..6fab8894a 100755 --- a/Core/Configs/Test/Fixture/ConfigFixture.php +++ b/Core/Configs/Test/Fixture/ConfigFixture.php @@ -6,7 +6,9 @@ * @since 0.9b1 */ class ConfigFixture extends CakeTestFixture { + public $name = 'Config'; + public $table = 'core_configs'; public $fields = array( diff --git a/Core/Contact/Config/config.php b/Core/Contact/Config/config.php index 2c20fc188..5eedeb763 100755 --- a/Core/Contact/Config/config.php +++ b/Core/Contact/Config/config.php @@ -8,5 +8,7 @@ 'Europe', 'North America', 'South America' - ) + ), + 'phone_regex' => '/\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/', + 'phone_regex' => '/\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/', ); \ No newline at end of file diff --git a/Core/Contact/Controller/AddressesController.php b/Core/Contact/Controller/AddressesController.php index 7a63a92f5..da3a643a2 100644 --- a/Core/Contact/Controller/AddressesController.php +++ b/Core/Contact/Controller/AddressesController.php @@ -16,7 +16,9 @@ * * @author Carl Sutton */ + class ContactAddressesController extends ContactAppController { + /** * Add new contact address * diff --git a/Core/Contact/Controller/BranchesController.php b/Core/Contact/Controller/BranchesController.php index 21ff20ba6..5aa5af375 100644 --- a/Core/Contact/Controller/BranchesController.php +++ b/Core/Contact/Controller/BranchesController.php @@ -20,16 +20,13 @@ */ class BranchesController extends ContactAppController { + /** * View all available branch records * - * @todo remove recursive 0 - * * @return void */ public function index() { - $this->Branch->recursive = 0; - $branches = $this->Paginator->paginate( null, $this->Filter->filter diff --git a/Core/Contact/Controller/ContactAppController.php b/Core/Contact/Controller/ContactAppController.php index a7163d3ba..cd2415e65 100644 --- a/Core/Contact/Controller/ContactAppController.php +++ b/Core/Contact/Controller/ContactAppController.php @@ -1,86 +1,86 @@ - */ - App::uses('AppController', 'Controller'); - class ContactAppController extends AppController { - /** - * Helpers used within this plugin - * - * @var array - */ - public $helpers = array( - 'Contact.Vcf', - 'Html', - 'Google.StaticMap' - ); +App::uses('AppController', 'Controller'); - public function beforeFilter() { - parent::beforeFilter(); +/** + * The main contact's plugin model + * + * this is extended by the other models in contact plugin + * + * @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) + * @link http://www.infinitas-cms.org + * @package Infinitas.Contact + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + * @since 0.7a + * + * @author Carl Sutton + */ - $this->RequestHandler->setContent('vcf', 'text/x-vcard'); +class ContactAppController extends AppController { - return true; - } - } \ No newline at end of file +/** + * Helpers used within this plugin + * + * @var array + */ + public $helpers = array( + 'Contact.Vcf', + 'Html', + 'Google.StaticMap' + ); + + public function beforeFilter() { + parent::beforeFilter(); + + $this->RequestHandler->setContent('vcf', 'text/x-vcard'); + + return true; + } +} \ No newline at end of file diff --git a/Core/Contact/Controller/ContactsController.php b/Core/Contact/Controller/ContactsController.php index 5cb08485b..53f7b419b 100644 --- a/Core/Contact/Controller/ContactsController.php +++ b/Core/Contact/Controller/ContactsController.php @@ -20,6 +20,7 @@ */ class ContactsController extends ContactAppController { + /** * View a contacts details * @@ -30,28 +31,25 @@ public function view() { $this->notice('invalid'); } - $contact = $this->Contact->find( - 'first', - array( - 'conditions' => array( - 'Contact.slug' => $this->request->params['slug'], - 'Contact.active' => 1 - ), - 'contain' => array( - 'Branch' => array( - 'fields' => array( - 'id', - 'name', - 'slug', - 'active' - ), - 'ContactAddress' => array( - 'Country' - ) + $contact = $this->Contact->find('first', array( + 'conditions' => array( + 'Contact.slug' => $this->request->params['slug'], + 'Contact.active' => 1 + ), + 'contain' => array( + 'Branch' => array( + 'fields' => array( + 'id', + 'name', + 'slug', + 'active' + ), + 'ContactAddress' => array( + 'Country' ) ) ) - ); + )); if (!$contact['Branch']['active']) { $this->notice('invalid'); @@ -119,5 +117,4 @@ public function admin_edit($id = null) { $branches = $this->Contact->Branch->find('list'); $this->set(compact('branches')); } - } \ No newline at end of file diff --git a/Core/Contact/Lib/ContactEvents.php b/Core/Contact/Lib/ContactEvents.php index e0fb7aeaa..68e66908b 100644 --- a/Core/Contact/Lib/ContactEvents.php +++ b/Core/Contact/Lib/ContactEvents.php @@ -14,7 +14,8 @@ * @author Carl Sutton */ -class ContactEvents extends AppEvents{ +class ContactEvents extends AppEvents { + /** * load the admin menu * diff --git a/Core/Contact/Model/Branch.php b/Core/Contact/Model/Branch.php index 52339314f..9485eaf7e 100755 --- a/Core/Contact/Model/Branch.php +++ b/Core/Contact/Model/Branch.php @@ -20,6 +20,7 @@ */ class Branch extends ContactAppModel { + /** * hasMany relations * @@ -38,7 +39,6 @@ class Branch extends ContactAppModel { 'Contact.ContactAddress' ); - /** * Behaivors to load * @@ -84,16 +84,16 @@ public function __construct($id = false, $table = null, $ds = null) { ), 'phone' => array( 'phone' => array( - 'rule' => array('phone', '/\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/'), // @todo Configure::read('Website.phone_regex')), + 'rule' => array('phone', Configure::read('Contact.phone_regex')), 'message' => __d('contact', 'The number does not seem to be valid'), 'allowEmpty' => true ) ), 'fax' => array( 'phone' => array( - 'rule' => array('phone', '/\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/'), // @todo Configure::read('Website.phone_regex')), + 'rule' => array('phone', Configure::read('Contact.phone_regex')), 'message' => __d('contact', 'Please enter a valid fax number'), - 'allowEmpty' => true + 'allowEmpty' => true ) ), 'time_zone_id' => array( @@ -108,9 +108,6 @@ public function __construct($id = false, $table = null, $ds = null) { /** * BeforeFind callback * - * @todo list all the time zones so that the current time can be shown - * of different branches. - * * @param array $queryData the find data * * @return boolean @@ -118,5 +115,5 @@ public function __construct($id = false, $table = null, $ds = null) { public function beforeFind($queryData) { return true; } - + } \ No newline at end of file diff --git a/Core/Contact/Model/Contact.php b/Core/Contact/Model/Contact.php index e892250c1..d9db4867d 100755 --- a/Core/Contact/Model/Contact.php +++ b/Core/Contact/Model/Contact.php @@ -10,8 +10,6 @@ * * The Contact model handles the CRUD for user details. * - * @todo link up the contacts to users in the User table - * * @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) * @link http://www.infinitas-cms.org * @package Infinitas.Contacts.Model @@ -22,6 +20,7 @@ */ class Contact extends ContactAppModel { + /** * Behaviors to load * @@ -43,8 +42,8 @@ class Contact extends ContactAppModel { public $belongsTo = array( 'Branch' => array( 'className' => 'Contact.Branch', - 'counterCache' => 'user_count', - 'counterScope' => array('Contact.active' => 1) + 'counterCache' => 'user_count', + 'counterScope' => array('Contact.active' => 1) ) ); @@ -77,14 +76,14 @@ public function __construct($id = false, $table = null, $ds = null) { 'phone' => array( 'rule' => array('phone', '/\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/'), //Configure::read('Website.phone_regex')), 'message' => __d('contact', 'The number does not seem to be valid'), - 'allowEmpty' => true + 'allowEmpty' => true ) ), 'mobile' => array( 'phone' => array( 'rule' => array('phone', '/\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/'), //Configure::read('Website.phone_regex')), 'message' => __d('contact', 'Please enter a valid mobile number'), - 'allowEmpty' => true + 'allowEmpty' => true ) ), 'email' => array( @@ -103,5 +102,4 @@ public function __construct($id = false, $table = null, $ds = null) { ) ); } - } \ No newline at end of file diff --git a/Core/Contact/Model/ContactAddress.php b/Core/Contact/Model/ContactAddress.php index 126eecc16..13782df27 100755 --- a/Core/Contact/Model/ContactAddress.php +++ b/Core/Contact/Model/ContactAddress.php @@ -1,63 +1,76 @@ 'CONCAT(ContactAddress.street, ", ", ContactAddress.city, ", ", ContactAddress.province)' - ); +/** + * ContactAddress + * + * @package Infinitas.Contact.Model + */ - public $belongsTo = array( - 'Contact.Country' - ); +/** + * ContactAddress + * + * @package Infinitas.Contact.Model + */ - public function getAddressByUser($userId = null, $type = 'list') { - if (!$userId) { - return false; - } - - $contain = array(); - if ($type === 'all') { - $contain = array( - 'Country' - ); - } - - $address = $this->find( - $type, - array( - 'conditions' => array( - 'ContactAddress.foreign_key' => $userId, - 'ContactAddress.plugin' => 'management', - 'ContactAddress.model' => 'user' - ), - 'contain' => $contain - ) - ); +class ContactAddress extends ContactAppModel { + +/** + * the table prefix for this plugin + * + * @var string + */ + public $tablePrefix = ''; + + public $virtualFields = array( + 'address' => 'CONCAT(ContactAddress.street, ", ", ContactAddress.city, ", ", ContactAddress.province)' + ); + + public $belongsTo = array( + 'Contact.Country' + ); - return $address; + public function getAddressByUser($userId = null, $type = 'list') { + if (!$userId) { + return false; } - /** - * Find a list of addresses for the currently selected plugin that may - * be related to what they user is looking for. - * - * @param array $conditions the conditions to search for - * @return array - */ - public function getAddressesByRelated($conditions = array()) { - return $this->find( - 'list', - array( - 'conditions' => (array)$conditions - ) + $contain = array(); + if ($type === 'all') { + $contain = array( + 'Country' ); } - } \ No newline at end of file + + $address = $this->find( + $type, + array( + 'conditions' => array( + 'ContactAddress.foreign_key' => $userId, + 'ContactAddress.plugin' => 'management', + 'ContactAddress.model' => 'user' + ), + 'contain' => $contain + ) + ); + + return $address; + } + +/** + * get related addresses + * + * Find a list of addresses for the currently selected plugin that may + * be related to what they user is looking for. + * + * @param array $conditions the conditions to search for + * + * @return array + */ + public function getAddressesByRelated($conditions = array()) { + return $this->find( + 'list', + array( + 'conditions' => (array)$conditions + ) + ); + } +} \ No newline at end of file diff --git a/Core/Contact/Model/ContactAppModel.php b/Core/Contact/Model/ContactAppModel.php index 85a80b5d0..56c64e914 100644 --- a/Core/Contact/Model/ContactAppModel.php +++ b/Core/Contact/Model/ContactAppModel.php @@ -1,23 +1,24 @@ - */ +/** + * The main contact's plugin model + * + * this is extended by the other models in contact plugin + * + * @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) + * @link http://www.infinitas-cms.org + * @package Infinitas.Contact + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + * @since 0.7a + * + * @author Carl Sutton + */ - class ContactAppModel extends AppModel { - /** - * the table prefix for this plugin - * - * @var string - */ - public $tablePrefix = 'contact_'; - } \ No newline at end of file +class ContactAppModel extends AppModel { + +/** + * the table prefix for this plugin + * + * @var string + */ + public $tablePrefix = 'contact_'; +} \ No newline at end of file diff --git a/Core/Contact/Model/Country.php b/Core/Contact/Model/Country.php index 351528508..d3101426f 100755 --- a/Core/Contact/Model/Country.php +++ b/Core/Contact/Model/Country.php @@ -18,11 +18,11 @@ */ class Country extends ContactAppModel { + /** * Custom display field * * @var string */ public $displayField = 'printable_name'; - } diff --git a/Core/Contact/Model/TimeZone.php b/Core/Contact/Model/TimeZone.php index e2dd0f774..65c732644 100755 --- a/Core/Contact/Model/TimeZone.php +++ b/Core/Contact/Model/TimeZone.php @@ -18,6 +18,7 @@ */ class TimeZone extends ContactAppModel { + /** * Remove table prefix * @@ -45,7 +46,6 @@ public function find($type = 'first', $query = array()) { switch($type) { case 'list': return $return; - break; case 'all': foreach ($return as $key => $value) { @@ -57,8 +57,6 @@ public function find($type = 'first', $query = array()) { ); } return $data; - break; } } - } \ No newline at end of file diff --git a/Core/Contact/Test/Case/Lib/ContactEventsTest.php b/Core/Contact/Test/Case/Lib/ContactEventsTest.php index bd6157e64..c024088ae 100644 --- a/Core/Contact/Test/Case/Lib/ContactEventsTest.php +++ b/Core/Contact/Test/Case/Lib/ContactEventsTest.php @@ -9,5 +9,5 @@ App::uses('InfinitasEventTestCase', 'Events.Test/Lib'); class ContactEventsTest extends InfinitasEventTestCase { - + } \ No newline at end of file diff --git a/Core/Contact/Test/Case/Model/BranchTest.php b/Core/Contact/Test/Case/Model/BranchTest.php index cbd2f15f3..e91ad1db2 100644 --- a/Core/Contact/Test/Case/Model/BranchTest.php +++ b/Core/Contact/Test/Case/Model/BranchTest.php @@ -22,7 +22,5 @@ public function tearDown() { } public function testSomething() { - } - } \ No newline at end of file diff --git a/Core/Contact/Test/Case/Model/ContactAddressTest.php b/Core/Contact/Test/Case/Model/ContactAddressTest.php index 73f1f652d..c09e5611b 100644 --- a/Core/Contact/Test/Case/Model/ContactAddressTest.php +++ b/Core/Contact/Test/Case/Model/ContactAddressTest.php @@ -22,7 +22,5 @@ public function tearDown() { } public function testSomething() { - } - -} \ No newline at end of file +} diff --git a/Core/Contact/Test/Case/Model/ContactTest.php b/Core/Contact/Test/Case/Model/ContactTest.php index e14dae373..5c307385a 100644 --- a/Core/Contact/Test/Case/Model/ContactTest.php +++ b/Core/Contact/Test/Case/Model/ContactTest.php @@ -3,7 +3,15 @@ class ContactTest extends CakeTestCase { - public $fixtures = array('plugin.contact.contact'); +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.contact.contact' + ); + /** * @brief set up at the start */ @@ -21,6 +29,5 @@ public function tearDown() { } public function testSomething() { - } } \ No newline at end of file diff --git a/Core/Contact/Test/Case/Model/CountryTest.php b/Core/Contact/Test/Case/Model/CountryTest.php index 367f04f40..cee4e963e 100644 --- a/Core/Contact/Test/Case/Model/CountryTest.php +++ b/Core/Contact/Test/Case/Model/CountryTest.php @@ -38,7 +38,5 @@ public function tearDown() { } public function testSomething() { - } - } diff --git a/Core/Contact/Test/Case/Model/TimeZoneTest.php b/Core/Contact/Test/Case/Model/TimeZoneTest.php index 1811fe4cf..80dbb41e3 100644 --- a/Core/Contact/Test/Case/Model/TimeZoneTest.php +++ b/Core/Contact/Test/Case/Model/TimeZoneTest.php @@ -38,7 +38,5 @@ public function tearDown() { } public function testSomething() { - } - } diff --git a/Core/Contact/Test/Case/View/Helper/ContactsHelperTest.php b/Core/Contact/Test/Case/View/Helper/ContactsHelperTest.php index 66fa171d7..eb5c9e2d1 100644 --- a/Core/Contact/Test/Case/View/Helper/ContactsHelperTest.php +++ b/Core/Contact/Test/Case/View/Helper/ContactsHelperTest.php @@ -4,6 +4,7 @@ App::uses('Controller', 'Controller'); class ContactsHelperTest extends CakeTestCase { + /** * @brief set up at the start */ @@ -21,7 +22,5 @@ public function tearDown() { } public function testSomething() { - } - } \ No newline at end of file diff --git a/Core/Contact/Test/Case/View/Helper/VcfHelperTest.php b/Core/Contact/Test/Case/View/Helper/VcfHelperTest.php index b73b7fb2d..bcc9e87b1 100644 --- a/Core/Contact/Test/Case/View/Helper/VcfHelperTest.php +++ b/Core/Contact/Test/Case/View/Helper/VcfHelperTest.php @@ -22,7 +22,5 @@ public function tearDown() { } public function testSomething() { - } - } \ No newline at end of file diff --git a/Core/Contact/Test/Fixture/BranchFixture.php b/Core/Contact/Test/Fixture/BranchFixture.php index 4deef0612..b2469aa9a 100755 --- a/Core/Contact/Test/Fixture/BranchFixture.php +++ b/Core/Contact/Test/Fixture/BranchFixture.php @@ -6,7 +6,9 @@ * @since 0.9b1 */ class BranchFixture extends CakeTestFixture { + public $name = 'Branch'; + public $table = 'contact_branches'; public $fields = array( diff --git a/Core/Contact/Test/Fixture/ContactAddressFixture.php b/Core/Contact/Test/Fixture/ContactAddressFixture.php index 742afd03c..f331756b2 100755 --- a/Core/Contact/Test/Fixture/ContactAddressFixture.php +++ b/Core/Contact/Test/Fixture/ContactAddressFixture.php @@ -6,7 +6,9 @@ * @since 0.9b1 */ class ContactAddressFixture extends CakeTestFixture { + public $name = 'ContactAddress'; + public $table = 'contact_addresses'; public $fields = array( diff --git a/Core/Contact/Test/Fixture/ContactFixture.php b/Core/Contact/Test/Fixture/ContactFixture.php index 7e2c87625..0d5bc1b64 100755 --- a/Core/Contact/Test/Fixture/ContactFixture.php +++ b/Core/Contact/Test/Fixture/ContactFixture.php @@ -6,7 +6,9 @@ * @since 0.9b1 */ class ContactFixture extends CakeTestFixture { + public $name = 'Contact'; + public $table = 'contact_contacts'; public $fields = array( diff --git a/Core/Contact/Test/Fixture/CountryFixture.php b/Core/Contact/Test/Fixture/CountryFixture.php index ce419d016..ff5403e5b 100755 --- a/Core/Contact/Test/Fixture/CountryFixture.php +++ b/Core/Contact/Test/Fixture/CountryFixture.php @@ -6,8 +6,9 @@ * @since 0.9b1 */ class CountryFixture extends CakeTestFixture { + public $name = 'Country'; - + public $table = 'contact_countries'; public $fields = array( diff --git a/Core/Contact/Test/Fixture/TimeZoneFixture.php b/Core/Contact/Test/Fixture/TimeZoneFixture.php index 6eb29611d..0e121eda6 100644 --- a/Core/Contact/Test/Fixture/TimeZoneFixture.php +++ b/Core/Contact/Test/Fixture/TimeZoneFixture.php @@ -6,11 +6,12 @@ * @since 0.9b1 */ class TimeZoneFixture extends CakeTestFixture { + public $name = 'TimeZone'; public $fields = array( 'indexes' => array( - + ), 'tableParameters' => array() ); diff --git a/Core/Contact/View/Helper/ContactsHelper.php b/Core/Contact/View/Helper/ContactsHelper.php index e560ddba1..ce6f42ee2 100644 --- a/Core/Contact/View/Helper/ContactsHelper.php +++ b/Core/Contact/View/Helper/ContactsHelper.php @@ -5,9 +5,6 @@ * * Currently can output a business card type markup for contacts. * - * @todo contact forms. pass in a contact row and a form will be made using the - * supplied email address etc. - * * @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) * @link http://www.infinitas-cms.org * @package Infinitas.Contact.helpers @@ -18,6 +15,7 @@ */ class ContactsHelper extends AppHelper { + /** * Helpers to load * @@ -73,7 +71,7 @@ protected function _output($details) { 'avitar' => null, 'user' => null, 'company' => null, - 'mobile' => null, + 'mobile' => null, 'landline' => null, 'email' => null, 'address' => null diff --git a/Core/Contact/View/Helper/VcfHelper.php b/Core/Contact/View/Helper/VcfHelper.php index 166dcc495..a6dbf58b8 100644 --- a/Core/Contact/View/Helper/VcfHelper.php +++ b/Core/Contact/View/Helper/VcfHelper.php @@ -1,171 +1,183 @@ - */ - App::uses('AppHelper', 'View/Helper'); - class VcfHelper extends AppHelper { - /** - * map element names to vcard elements - * - * @var array - */ - protected $_elements = array( - 'name' => 'N:%last%;%first%;%middle%;%title%', - 'fullName' => 'FN:%value%', - 'organization' => 'ORG:%value%', - 'title' => 'TITLE:%value%', - 'workPhone' => 'TEL;WORK:%value%', - 'homePhone' => 'TEL;HOME:%value%', - 'cellPhone' => 'TEL;CELL:%value%', - 'address' => 'ADR', - 'birthday' => 'BDAY:%value%', - 'email' => 'EMAIL;INTERNET:%value%', - 'timezone' => 'TZ:%value%', - 'url' => 'URL:%value%', - 'version' => 'VERSION:%value%', - 'image' => 'PHOTO;VALUE=URL:%value%', - ); +/** + * VcfHelper + * + * @package Infinitas.Contact.Helper + */ + +App::uses('AppHelper', 'View/Helper'); + +/** + * VcfHelper is used to generate vCards for the saved contacts + * + * Helps with the creation of vCard files + * + * @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) + * @link http://www.infinitas-cms.org + * @package Infinitas.Contact.Helper + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + * @since 0.7a + * + * @author markstory + * @author Carl Sutton + */ + +class VcfHelper extends AppHelper { + +/** + * map element names to vcard elements + * + * @var array + */ + protected $_elements = array( + 'name' => 'N:%last%;%first%;%middle%;%title%', + 'fullName' => 'FN:%value%', + 'organization' => 'ORG:%value%', + 'title' => 'TITLE:%value%', + 'workPhone' => 'TEL;WORK:%value%', + 'homePhone' => 'TEL;HOME:%value%', + 'cellPhone' => 'TEL;CELL:%value%', + 'address' => 'ADR', + 'birthday' => 'BDAY:%value%', + 'email' => 'EMAIL;INTERNET:%value%', + 'timezone' => 'TZ:%value%', + 'url' => 'URL:%value%', + 'version' => 'VERSION:%value%', + 'image' => 'PHOTO;VALUE=URL:%value%', + ); + +/** + * Separator between values. + * + * @var string + */ + protected $_separator = ':'; + +/** + * End of line character + * + * @var string + */ + protected $_eol = "\n"; + +/** + * End of attribute terminator. + * + * @var string + */ + protected $_terminator = ';'; - /** - * Separator between values. - * - * @var string - */ - protected $_separator = ':'; - - /** - * End of line character - * - * @var string - **/ - protected $_eol = "\n"; - - /** - * End of attribute terminator. - * - * @var string - */ - protected $_terminator = ';'; - - /** - * Overloaded call method - * - * @param string $method Name of method called - * @param mixed $params Params for method. - * - * @return mixed - */ - public function __call($method, $params) { - if (isset($this->_elements[$method])) { - array_unshift($params, $method); - return $this->dispatchMethod('attr', $params); - } - trigger_error($method . ' is not a valid element.', E_USER_WARNING); +/** + * Overloaded call method + * + * @param string $method Name of method called + * @param mixed $params Params for method. + * + * @return mixed + */ + public function __call($method, $params) { + if (isset($this->_elements[$method])) { + array_unshift($params, $method); + return $this->dispatchMethod('attr', $params); } + trigger_error($method . ' is not a valid element.', E_USER_WARNING); + } - /** - * begin a vcard - * - * @return string - */ - public function begin() { - return "BEGIN:VCARD" . $this->_eol; +/** + * begin a vcard + * + * @return string + */ + public function begin() { + return "BEGIN:VCARD" . $this->_eol; + } + +/** + * End a vcard + * + * @return string + */ + public function end() { + return "END:VCARD" . $this->_eol; + } + +/** + * Create a new attribute for the vCard + * + * @see VcfHelper::__call() + * + * @param string $type Type of element to make + * @param string $value Value to put into the card + * + * @return boolean|string + */ + public function attr($type, $values) { + if (empty($values)) { + return false; } - /** - * End a vcard - * - * @return string - */ - public function end() { - return "END:VCARD" . $this->_eol; + if (is_string($values)) { + $values = array('value' => $values); } - /** - * Create a new attribute for the vCard - * - * @see VcfHelper::__call() - * - * @param string $type Type of element to make - * @param string $value Value to put into the card - * - * @return mixed False on non-existant type or empty values, string on success - */ - public function attr($type, $values) { - if (empty($values)) { - return false; - } - if (is_string($values)) { - $values = array('value' => $values); - } - - if ($type != 'image') { - $values = $this->_escape($values); - } - - if (!isset($this->_elements[$type])) { - return false; - } - $out = String::insert($this->_elements[$type], - $values, array('clean' => true, 'before' => '%', 'after' => '%') - ); - return $out . $this->_eol; + if ($type != 'image') { + $values = $this->_escape($values); } - /** - * Create an Address element. Takes the following keys - * - * - street - * - city - * - province - * - postal - * - country - * - * @param string $type The type of address you are making - * @param array $values Array of values for the address see above - * - * @return sting the address line - */ - public function address($type, $values = array()) { - $empty = array( - 'street' => '', - 'city' => '', - 'province' => '', - 'postal' => '', - 'country' => '', - ); - $values = array_merge($empty, $values); - $values['key'] = $this->_elements['address']; - $values['type'] = strtoupper($type); - - $format = "%key%;%type%:;;%street%;%city%;%province%;%postal%;%country%;"; - $adrEl = String::insert($format, $values, array('before' => '%', 'after' => '%', 'clean' => true)); - $labelFormat = "LABEL;POSTAL;%type%;ENCODING=QUOTED-PRINTABLE:%street%=0D=0A%city%, %province% %postal%=0D=0A%country%"; - $labelEl = String::insert($labelFormat, $values, array('before' => '%', 'after' => '%', 'clean' => true)); - - return $adrEl . $this->_eol . $labelEl . $this->_eol; + if (!isset($this->_elements[$type])) { + return false; } + $out = String::insert($this->_elements[$type], + $values, array('clean' => true, 'before' => '%', 'after' => '%') + ); + return $out . $this->_eol; + } + +/** + * Create an Address element. Takes the following keys + * + * - street + * - city + * - province + * - postal + * - country + * + * @param string $type The type of address you are making + * @param array $values Array of values for the address see above + * + * @return sting + */ + public function address($type, $values = array()) { + $empty = array( + 'street' => '', + 'city' => '', + 'province' => '', + 'postal' => '', + 'country' => '', + ); + $values = array_merge($empty, $values); + $values['key'] = $this->_elements['address']; + $values['type'] = strtoupper($type); + + $format = "%key%;%type%:;;%street%;%city%;%province%;%postal%;%country%;"; + $adrEl = String::insert($format, $values, array('before' => '%', 'after' => '%', 'clean' => true)); + $labelFormat = "LABEL;POSTAL;%type%;ENCODING=QUOTED-PRINTABLE:%street%=0D=0A%city%, %province% %postal%=0D=0A%country%"; + $labelEl = String::insert($labelFormat, $values, array('before' => '%', 'after' => '%', 'clean' => true)); - /** - * Escape values for vcard - * - * @param mixed $values Values either string or array. - * - * @return string - */ - protected function _escape($values) { - $find = array(':'); - $replace = array('\:'); - return is_array($values) ? array_map(array($this, '_escape'), $values) : str_replace($find, $replace, $values); + return $adrEl . $this->_eol . $labelEl . $this->_eol; + } + +/** + * Escape values for vcard + * + * @param mixed $values Values either string or array. + * + * @return string + */ + protected function _escape($values) { + if (is_array($values)) { + return array_map(array($this, '_escape'), $values); } - } \ No newline at end of file + + return str_replace(array(':'), array('\:'), $values); + } +} \ No newline at end of file