/** * 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; }
/** * 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; }
public function loadCustomCssJs() { $this->prepareResource(); $managerUrl = $this->context->getOption('manager_url', MODX_MANAGER_URL, $this->modx->_userConfig); $articlesAssetsUrl = $this->modx->getOption('articles.assets_url', null, $this->modx->getOption('assets_url', null, MODX_ASSETS_URL) . 'components/articles/'); $connectorUrl = $articlesAssetsUrl . 'connector.php'; $articlesJsUrl = $articlesAssetsUrl . 'js/'; $this->resourceArray['articles_container_settings'] = $this->resource->getContainerSettings(); $this->resourceArray['isfolder'] = true; $this->addJavascript($managerUrl . 'assets/modext/util/datetime.js'); $this->addJavascript($managerUrl . 'assets/modext/widgets/element/modx.panel.tv.renders.js'); $this->addJavascript($managerUrl . 'assets/modext/widgets/resource/modx.grid.resource.security.js'); $this->addJavascript($managerUrl . 'assets/modext/widgets/resource/modx.panel.resource.tv.js'); $this->addJavascript($managerUrl . 'assets/modext/widgets/resource/modx.panel.resource.js'); $this->addJavascript($managerUrl . 'assets/modext/sections/resource/create.js'); $this->addJavascript($articlesJsUrl . 'articles.js'); $this->addJavascript($articlesJsUrl . 'container/container.common.js'); $this->addJavascript($articlesJsUrl . 'container/container.articles.grid.js'); $this->addLastJavascript($articlesJsUrl . 'container/create.js'); $this->addHtml(' <script type="text/javascript"> // <![CDATA[ Articles.assets_url = "' . $articlesAssetsUrl . '"; Articles.connector_url = "' . $connectorUrl . '"; MODx.config.publish_document = "' . $this->canPublish . '"; MODx.onDocFormRender = "' . $this->onDocFormRender . '"; MODx.ctx = "' . $this->resource->get('context_key') . '"; Ext.onReady(function() { MODx.load({ xtype: "articles-page-articles-container-create" ,resource: "' . $this->resource->get('id') . '" ,record: ' . $this->modx->toJSON($this->resourceArray) . ' ,publish_document: "' . $this->canPublish . '" ,canSave: ' . ($this->canSave ? 1 : 0) . ' ,canEdit: ' . ($this->canEdit ? 1 : 0) . ' ,canCreate: ' . ($this->canCreate ? 1 : 0) . ' ,canDuplicate: ' . ($this->canDuplicate ? 1 : 0) . ' ,canDelete: ' . ($this->canDelete ? 1 : 0) . ' ,show_tvs: ' . (!empty($this->tvCounts) ? 1 : 0) . ' ,mode: "create" }); }); // ]]> </script>'); /* load RTE */ $this->loadRichTextEditor(); }
/** * 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); }
public function loadCustomCssJs() { $managerUrl = $this->context->getOption('manager_url', MODX_MANAGER_URL, $this->modx->_userConfig); $articlesAssetsUrl = $this->modx->getOption('articles.assets_url', null, $this->modx->getOption('assets_url', null, MODX_ASSETS_URL) . 'components/articles/'); $quipAssetsUrl = $this->modx->getOption('quip.assets_url', null, $this->modx->getOption('assets_url', null, MODX_ASSETS_URL) . 'components/quip/'); $connectorUrl = $articlesAssetsUrl . 'connector.php'; $articlesJsUrl = $articlesAssetsUrl . 'js/'; $this->addJavascript($managerUrl . 'assets/modext/util/datetime.js'); $this->addJavascript($managerUrl . 'assets/modext/widgets/element/modx.panel.tv.renders.js'); $this->addJavascript($managerUrl . 'assets/modext/widgets/resource/modx.grid.resource.security.js'); $this->addJavascript($managerUrl . 'assets/modext/widgets/resource/modx.panel.resource.tv.js'); $this->addJavascript($managerUrl . 'assets/modext/widgets/resource/modx.panel.resource.js'); $this->addJavascript($managerUrl . 'assets/modext/sections/resource/update.js'); $this->addJavascript($articlesJsUrl . 'articles.js'); $this->addJavascript($articlesJsUrl . 'container/container.common.js'); $this->addJavascript($articlesJsUrl . 'container/container.articles.grid.js'); $this->addJavascript($articlesJsUrl . 'container/articles.import.window.js'); $this->addLastJavascript($articlesJsUrl . 'container/update.js'); $this->addCss($quipAssetsUrl . 'css/mgr.css'); $this->addJavascript($quipAssetsUrl . 'js/quip.js'); $this->addJavascript($quipAssetsUrl . 'js/widgets/comments.grid.js'); $this->addHtml('<script type="text/javascript"> Ext.onReady(function() { Quip.config = ' . $this->modx->toJSON(array()) . '; Quip.config.connector_url = "' . $quipAssetsUrl . 'connector.php"; Quip.request = ' . $this->modx->toJSON($_GET) . '; }); </script>'); $settings = $this->resource->getContainerSettings(); $this->resourceArray['articles_container_settings'] = $settings; $this->addHtml(' <script type="text/javascript"> // <![CDATA[ Articles.assets_url = "' . $articlesAssetsUrl . '"; Articles.connector_url = "' . $connectorUrl . '"; Articles.commentsEnabled = ' . ($this->modx->getOption('commentsEnabled', $settings, true) ? 1 : 0) . '; MODx.config.publish_document = "' . $this->canPublish . '"; MODx.onDocFormRender = "' . $this->onDocFormRender . '"; MODx.ctx = "' . $this->resource->get('context_key') . '"; Ext.onReady(function() { MODx.load({ xtype: "articles-page-container-update" ,resource: "' . $this->resource->get('id') . '" ,record: ' . $this->modx->toJSON($this->resourceArray) . ' ,publish_document: "' . $this->canPublish . '" ,preview_url: "' . $this->previewUrl . '" ,locked: ' . ($this->locked ? 1 : 0) . ' ,lockedText: "' . $this->lockedText . '" ,canSave: ' . ($this->canSave ? 1 : 0) . ' ,canEdit: ' . ($this->canEdit ? 1 : 0) . ' ,canCreate: ' . ($this->canCreate ? 1 : 0) . ' ,canDuplicate: ' . ($this->canDuplicate ? 1 : 0) . ' ,canDelete: ' . ($this->canDelete ? 1 : 0) . ' ,show_tvs: ' . (!empty($this->tvCounts) ? 1 : 0) . ' ,mode: "update" }); }); // ]]> </script>'); /* load RTE */ $this->loadRichTextEditor(); }