Joomla和Drupal是否提供任何类型的API来发布文章?
我有用于内容创作的Ruby on Rails应用程序,需要将文章发布到不同的网站,这些网站运行在Joomla和Drupal上。
发布于 2015-07-09 17:04:48
例如,它可以通过在Joomla站点上运行的CLI脚本使用文章模型来完成。
一种建议是发布RSS或XML提要,然后可以通过Joomla CLI脚本定期导入。下面给出了一个CLI脚本示例。注意事项:
<代码>F29
我可以继续,但这是一个问答网站,而不是一个咨询机会...;-)
<?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();
?>发布于 2015-07-09 18:29:40
对于Joomla来说,这个问题的答案是否定的,因为没有web API可以远程发布文章。
我从来没有实现过这样的解决方案,所以我没有一个经过验证的答案。作为一名开发人员,我的第一个想法是构建一个自定义的API组件。也许,在此之前,我会查看JED,看看是否有人已经这样做了。
https://stackoverflow.com/questions/31312640
复制相似问题