首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >API用于发布有关Joomla和Drupal的文章

API用于发布有关Joomla和Drupal的文章
EN

Stack Overflow用户
提问于 2015-07-09 16:53:45
回答 2查看 250关注 0票数 0

Joomla和Drupal是否提供任何类型的API来发布文章?

我有用于内容创作的Ruby on Rails应用程序,需要将文章发布到不同的网站,这些网站运行在Joomla和Drupal上。

EN

回答 2

Stack Overflow用户

发布于 2015-07-09 17:04:48

例如,它可以通过在Joomla站点上运行的CLI脚本使用文章模型来完成。

一种建议是发布RSS或XML提要,然后可以通过Joomla CLI脚本定期导入。下面给出了一个CLI脚本示例。注意事项:

  • 在下面的示例中,数据是从CSV文件导入的,无论您的数据源是什么,您都必须对此进行修改。
  • catid是硬编码的-您可能希望将您的文章发布到不同的类别,在这种情况下,您将需要做更多的工作来潜在地查找类别It。
  • 它不包括标签等
  • 只是Joomla的解决方案,而不是Drupal

<代码>F29

我可以继续,但这是一个问答网站,而不是一个咨询机会...;-)

代码语言:javascript
复制
<?php

/**
 * @package    Joomla.Cli
 *
 * @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
// Initialize Joomla framework
        const _JEXEC = 1;

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
  require_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES'))
{
  define('JPATH_BASE', dirname(__DIR__));
  require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';

/**
 * Cron job to import data into articles
 *
 * @since  2.5
 */
class ImportArticlesCron extends JApplicationCli
{

  /**
   * Entry point for the script
   *
   * @return  void
   *
   * @since   2.5
   */
  public function doExecute()
  {

    // Import articles model
    JControllerForm::addModelPath(JPATH_ADMINISTRATOR . '/components/com_content/models');

    // Get an instance of the content model
    $model = $this->getModel('Article', 'ContentModel');

    // This example is using a csv file but there's no reason you couldn't import an XML file here
    while (($line = fgetcsv($handle, 0, $delimiter = '|')) !== FALSE)
    {
      $data = array();
      $data['introtext'] = '';
      $data['fulltext'] = $output;
      $data['id'] = '';
      $data['state'] = ($line[1] == 'True') ? 1 : 0;
      $data['title'] = iconv("ISO-8859-1", "UTF-8//TRANSLIT", $line[3]);
      $data['created'] = $line[2];
      $data['catid'] = 38;
      $data['language'] = 'en-GB';
      $data['metadesc'] = '';
      $data['metakey'] = '';

      //$data['publish_up'] = date('Y-m-d', strtotime($line[14]));
      //$data['publish_down'] = date('Y-m-d', strtotime($line[15]));
      $model = $this->getModel('Article', 'ContentModel');

      if (!$model->save($data))
      {
        $error = $model->getError();
      }
    }
  }

}

JApplicationCli::getInstance('ImportArticlesCron')->execute();
?>
票数 2
EN

Stack Overflow用户

发布于 2015-07-09 18:29:40

对于Joomla来说,这个问题的答案是否定的,因为没有web API可以远程发布文章。

我从来没有实现过这样的解决方案,所以我没有一个经过验证的答案。作为一名开发人员,我的第一个想法是构建一个自定义的API组件。也许,在此之前,我会查看JED,看看是否有人已经这样做了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31312640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档