function startup(&$controller) { $this->data['model'] = $this->controller->modelClass; $model = null; if (!empty($this->controller->{$this->data['model']})) { $model = $this->controller->{$this->data['model']}; } else { $model = ClassRegistry::init($this->data['model']); } if (!empty($this->controller->{$this->data['model']}->Comment)) { $this->Comment = $this->controller->{$this->data['model']}->Comment; } else { $this->Comment = ClassRegistry::init('Comment.Comment'); $this->controller->modelNames[] = 'Comment'; $this->controller->Comment = $this->Comment; } if (!empty($this->controller->data['Comment'])) { $this->Comment->create(); $cdata = $this->controller->data['Comment']; unset($cdata['user_id']); if (!empty($this->controller->user['User']['id'])) { $cdata['user_id'] = $this->controller->user['User']['id']; } //debug($cdata); App::import('Lib', 'Comment.CommentConfig'); $adminValidation = CommentConfig::load('adminValidation'); $cdata['active'] = empty($adminValidation) || $adminValidation['defaultActive']; $success = $this->Comment->save($cdata); $success = !empty($success); if ($success && $adminValidation) { $comment = $model->find('first', array('conditions' => array($model->primaryKey => $cdata['foreign_key']), 'recursive' => -1)); $comment['Comment'] = $cdata; $comment['Comment']['id'] = $this->Comment->id; if (!empty($comment[$model->alias][$model->displayField])) { $displayVal = $comment[$model->alias][$model->displayField]; } else { $displayVal = $model->alias . ' id :' . $comment[$model->alias][$model->primaryKey]; } $site = $this->EmailUtils->get_base_server_name(); $defConf = array('subject' => __('%site% - New comment', true), 'to' => $this->EmailUtils->defaultEmail(), 'sender' => $this->EmailUtils->defaultEmail(), 'replyTo' => null, 'sendAs' => 'html', 'template' => 'Comment.admin_validation', 'layout' => null); $conf = array_merge($defConf, (array) $adminValidation); $conf['subject'] = str_replace('%site%', $site, $conf['subject']); $this->EmailUtils->setConfig($conf); $this->EmailUtils->set('comment', $comment); $this->EmailUtils->set('site', $site); $this->EmailUtils->set('displayVal', $displayVal); if (!$this->EmailUtils->send()) { } else { } } $this->data['postSuccess'] = $success; } //debug($this->Comment->validationErrors); }
function load($path = true) { $_this =& CommentConfig::getInstance(); if (!$_this->loaded) { config('plugins/comment'); $config = Configure::read('Comment'); $config = Set::merge($_this->defaultConfig, $config); $config = $_this->_parseTrueToDefault($config); Configure::write('Comment', $config); $_this->loaded = true; } if (!empty($path)) { return Configure::read('Comment' . ($path !== true ? '.' . $path : '')); } }
function beforeValidate() { App::import('Lib', 'Comment.CommentConfig'); $minChar = CommentConfig::load('minChar'); if (!empty($minChar)) { $this->validate['text'] = array('minlength' => array('rule' => array('minlength', $minChar), 'message' => sprintf(__('Your text must contain at least %s characters', true), $minChar))); } else { unset($this->validate['text']); } if (empty($this->data[$this->alias]['user_id'])) { $this->validate['name'] = array('notempty' => array('rule' => array('notempty'))); $this->validate['email'] = array('notempty' => array('rule' => array('notempty')), 'email' => array('rule' => array('email', true))); } else { unset($this->validate['name']); unset($this->validate['email']); } }