Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('_JEXEC', 1);
- define('JPATH_BASE', dirname(dirname(__FILE__)));
- define('DS', DIRECTORY_SEPARATOR);
- require_once(JPATH_BASE . DS . 'includes' . DS . 'defines.php');
- require_once(JPATH_BASE . DS . 'includes' . DS . 'framework.php');
- require_once(JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php');
- define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_BASE . DS . 'administrator' . DS . 'components' . DS . 'com_content');
- $mainframe = JFactory::getApplication('site');
- require_once(JPATH_ADMINISTRATOR . '/components/com_content/models/article.php');
- $string = file_get_contents("items.json");
- $json_str = json_decode($string, true);
- $title_default = 'No Title';
- $i = 0;
- $new_article = new ContentModelArticle();
- foreach ($json_str as $row) {
- $data = array(
- 'title' => isset($row['title'][0]) && strlen(trim($row['title'][0])) != 0 ? $row['title'][0] : $title_default,
- 'alias' => $row['alias'][0],
- 'introtext' => $row['content'],
- 'state' => 1,
- 'catid' => $row['catid'][0],
- /* don't hard code here! */
- 'created' => $row['pdate'],
- 'created_by' => 434,
- 'created_by_alias' => $row['poster'][0],
- 'publish_up' => $row['pdate'],
- 'urls' => json_encode($row['urls']),
- 'access' => 1,
- 'tags' => $row['tags'],
- 'metadata' => array(
- 'robots' => "",
- 'author' => implode(" ", $row['poster']),
- 'rights' => "",
- 'xreference' => ""
- )
- );
- ++$i;
- $new_article->save($data);
- echo 'Record ' . $i . ' for post ' . $data['alias'] . ' processed';
- echo "\r\n";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment