public function initialize() { $this->editAction = $this->modx->getObject('modAction', array('namespace' => 'core', 'controller' => 'resource/update')); $this->defaultSortField = $this->modx->getOption('articles.default_article_sort_field', null, 'createdon'); if ($this->getParentContainer()) { $settings = $this->container->getContainerSettings(); if ($this->modx->getOption('commentsEnabled', $settings, true)) { $quipCorePath = $this->modx->getOption('quip.core_path', null, $this->modx->getOption('core_path', null, MODX_CORE_PATH) . 'components/quip/'); if ($this->modx->addPackage('quip', $quipCorePath . 'model/')) { $this->commentsEnabled = true; } } } return parent::initialize(); }
/** * If set, import any comments from Quip * @param modResource $resource * @return boolean */ public function importComments(modResource &$resource) { $threadFormat = $this->config['modx-commentsThreadNameFormat']; if (empty($threadFormat)) { return true; } $imported = true; $threadFormat = str_replace(array('[[*id]]', '[[+id]]'), $resource->get('id'), $threadFormat); /** @var quipThread $thread */ $thread = $this->modx->getObject('quipThread', array('name' => $threadFormat)); if ($thread) { $newThreadName = 'article-b' . $this->container->get('id') . '-' . $resource->get('id'); $sql = 'UPDATE ' . $this->modx->getTableName('quipComment') . ' SET ' . $this->modx->escape('thread') . ' = "' . $newThreadName . '"' . ' WHERE ' . $this->modx->escape('thread') . ' = "' . $thread->get('name') . '"'; if (!$this->debug) { $this->modx->exec($sql); } $sql = 'UPDATE ' . $this->modx->getTableName('quipThread') . ' SET ' . $this->modx->escape('name') . ' = "' . $newThreadName . '"' . ' WHERE ' . $this->modx->escape('name') . ' = "' . $thread->get('name') . '"'; if (!$this->debug) { $this->modx->exec($sql); } $imported = true; } else { $this->modx->log(modX::LOG_LEVEL_ERROR, '[Articles] Could not find Quip Thread with thread name: ' . $threadFormat); } return $imported; }
/** * Used to set values on the resource record sent to the template for derivative classes * * @return void */ public function prepareResource() { $settings = $this->resource->getProperties('articles'); if (empty($settings)) { $settings = array(); } $defaultContainerTemplate = $this->modx->getOption('articles.default_container_template', $settings, false); if (empty($defaultContainerTemplate)) { /** @var modTemplate $template */ $template = $this->modx->getObject('modTemplate', array('templatename' => 'sample.ArticlesContainerTemplate')); if ($template) { $defaultContainerTemplate = $template->get('id'); } } $this->resourceArray['template'] = $defaultContainerTemplate; $defaultArticleTemplate = $this->modx->getOption('articles.default_article_template', $settings, false); if (empty($defaultArticleTemplate)) { /** @var modTemplate $template */ $template = $this->modx->getObject('modTemplate', array('templatename' => 'sample.ArticleTemplate')); if ($template) { $defaultArticleTemplate = $template->get('id'); } } $this->resourceArray['setting_articleTemplate'] = $defaultArticleTemplate; foreach ($settings as $k => $v) { $this->resourceArray['setting_' . $k] = $v; } }
/** * Import comments into Quip * * @param Article $article * @param SimpleXMLElement $item * @return boolean */ public function importComments(Article $article, SimpleXMLElement $item) { $settings = $this->container->getContainerSettings(); $threadKey = 'article-b' . $this->container->get('id') . '-' . $article->get('id'); /** @var quipThread $thread */ $thread = $this->modx->newObject('quipThread'); $thread->fromArray(array('createdon' => $article->get('publishedon'), 'moderated' => $this->modx->getOption('commentsModerated', $settings, 1), 'moderator_group' => $this->modx->getOption('commentsModeratorGroup', $settings, 'Administrator'), 'moderators' => $this->modx->getOption('commentsModerators', $settings, ''), 'resource' => $article->get('id'), 'idprefix' => 'qcom')); $thread->set('name', $threadKey); if (!$this->debug) { $thread->save(); } /** @var SimpleXMLElement $wp */ $wp = $item->children('wp', true); $idMap = array(); /** @var SimpleXMLElement $commentXml */ foreach ($wp->comment as $commentXml) { $commentId = (int) $this->getXPath($commentXml, 'wp:comment_id'); $commentParent = (int) $this->getXPath($commentXml, 'wp:comment_parent'); /** @var SimpleXMLElement $commentWp */ $commentWp = $commentXml->children('wp', true); /** @var quipComment $comment */ $comment = $this->modx->newObject('quipComment'); $comment->fromArray(array('thread' => $threadKey, 'parent' => array_key_exists($commentParent, $idMap) ? $idMap[$commentParent] : 0, 'author' => $this->matchCreator((string) $commentWp->comment_author), 'body' => $this->parseContent((string) $commentWp->comment_content), 'createdon' => (string) $commentWp->comment_date, 'approved' => (bool) $commentWp->comment_approved, 'name' => (string) $commentWp->comment_author, 'email' => (string) $commentWp->comment_author_email, 'website' => (string) $commentWp->comment_author_url, 'ip' => (string) $commentWp->comment_author_IP, 'resource' => $article->get('id'), 'idprefix' => 'qcom'), '', true); if (!$this->debug) { $comment->save(); } $idMap[$commentId] = $comment->get('id'); } return true; }
/** * Used to set values on the resource record sent to the template for derivative classes * * @return void */ public function prepareResource() { $settings = $this->resource->getProperties('articles'); if (is_array($settings) && !empty($settings)) { foreach ($settings as $k => $v) { $this->resourceArray['setting_' . $k] = $v; } } }
/** * Import comments into Quip * * @param SimpleXMLElement $entry * @return boolean */ public function importComment(SimpleXMLElement $entry) { $settings = $this->container->getContainerSettings(); $dc = $entry->children('thr', true)->attributes(); $url = (string) $dc['href']; if (empty($this->hrefMap[$url])) { return false; } $articleId = $this->hrefMap[$url]; if ($this->debug) { $article = $this->modx->newObject('Article'); $article->set('id', 1); } else { /** @var Article $article */ $article = $this->modx->getObject('Article', $articleId); if (empty($article)) { return false; } } $threadKey = 'article-b' . $this->container->get('id') . '-' . $article->get('id'); /** @var quipThread $thread */ $thread = $this->modx->newObject('quipThread'); $thread->fromArray(array('createdon' => $article->get('publishedon'), 'moderated' => $this->modx->getOption('commentsModerated', $settings, 1), 'moderator_group' => $this->modx->getOption('commentsModeratorGroup', $settings, 'Administrator'), 'moderators' => $this->modx->getOption('commentsModerators', $settings, ''), 'resource' => $article->get('id'), 'idprefix' => 'qcom')); $thread->set('name', $threadKey); if (!$this->debug) { $thread->save(); } $email = (string) $entry->author->email; if ($email == '*****@*****.**') { $email = ''; } $commentId = (string) $entry->id; $creator = $this->matchCreator((string) $entry->author->name); if (empty($creator) && !empty($email)) { $creator = $this->matchCreator($email, 1, 'email'); } /** @var quipComment $comment */ $comment = $this->modx->newObject('quipComment'); $comment->fromArray(array('thread' => $threadKey, 'parent' => 0, 'author' => $creator, 'body' => (string) $entry->content, 'createdon' => strftime('%Y-%m-%d %H:%M:%S', strtotime((string) $entry->published)), 'approved' => strftime('%Y-%m-%d %H:%M:%S', strtotime((string) $entry->published)), 'name' => (string) $entry->author->name, 'email' => $email, 'website' => (string) $entry->author->uri, 'ip' => '', 'resource' => $article->get('id'), 'idprefix' => 'qcom'), '', true); $this->commentMap[$commentId] = $comment->get('id'); if (!$this->debug) { $comment->save(); } return true; }
public function beforeSave() { $afterSave = parent::beforeSave(); // Make sure this is not saved anywhere it shouldn't be $parent = $this->modx->getObject('modResource', $this->object->get('parent')); if ($parent) { $this->modx->log(1, print_r($parent->toArray(), true)); } /* if ($parent) { $this->object->setProperties($container->getProperties('articles'),'articles'); } */ // $this->isPublishing = $this->object->isDirty('published') && $this->object->get('published'); return $afterSave; }
/** * Override cleanup to send only back needed params * @return array|string */ public function cleanup() { $this->object->removeLock(); $this->clearCache(); $returnArray = $this->object->get(array_diff(array_keys($this->object->_fields), array('content', 'ta', 'introtext', 'description', 'link_attributes', 'pagetitle', 'longtitle', 'menutitle', 'articles_container_settings', 'properties'))); foreach ($returnArray as $k => $v) { if (strpos($k, 'tv') === 0) { unset($returnArray[$k]); } if (strpos($k, 'setting_') === 0) { unset($returnArray[$k]); } } $returnArray['class_key'] = $this->object->get('class_key'); $this->workingContext->prepare(true); $returnArray['preview_url'] = $this->modx->makeUrl($this->object->get('id'), $this->object->get('context_key'), '', 'full'); return $this->success('', $returnArray); }