/** * Register pingback comment. Used by pingback server * * @param AppModel $model * @param string $modelId * @param array $options * @param string $sourceUri * @param string $targetUri * @return boolean */ public function pingbackRegisterComment(&$model, $modelId, $sourceUri, $targetUri) { extract($this->settings[$model->alias]); if ($model->{$commentAlias}->hasAny(array($commentAlias . '.foreign_key' => $modelId, 'author_url' => $sourceUri))) { throw new XmlRpcResponseException(0, 'Pingback already registries in system.'); } $sourceBody = $this->loadPageContent($sourceUri); if (strpos($sourceBody, $targetUri) === false) { throw new XmlRpcResponseException(0, 'Source link is not detected in target blog.'); } $sourceBody = $this->cleanupPage($sourceBody); $title = $this->fetchTitle($sourceBody); $cite = $this->fetchPingbackCite($sourceBody, $sourceUri, $targetUri); $isSpam = false; $data = array('comment_type' => 'pingback', 'author_name' => $title . 'blog', 'author_url' => $sourceUri, 'title' => $title, 'foreign_key' => $modelId, 'model' => $model->alias, 'body' => $cite); if ($model->{$commentAlias}->Behaviors->enabled('Antispamable')) { $isSpam = $model->isSpam(); } $data['is_spam'] = $isSpam ? 'spam' : 'clean'; $modelData = $model->find('first', array('conditions' => array('id' => $modelId), 'recursive' => -1)); if (!empty($modelData[$model->alias][$requireApproveModelField])) { $data[$requireApproveCommentField] = 0; } $model->{$commentAlias}->create($data); return $model->{$commentAlias}->save(); }