jindan

Untitled

Jul 29th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2. define('_JEXEC', 1);
  3. define('JPATH_BASE', dirname(dirname(__FILE__)));
  4. define('DS', DIRECTORY_SEPARATOR);
  5.  
  6. require_once(JPATH_BASE . DS . 'includes' . DS . 'defines.php');
  7. require_once(JPATH_BASE . DS . 'includes' . DS . 'framework.php');
  8. require_once(JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php');
  9.  
  10. define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_BASE . DS . 'administrator' . DS . 'components' . DS . 'com_content');
  11.  
  12. $mainframe = JFactory::getApplication('site');
  13.  
  14. require_once(JPATH_ADMINISTRATOR . '/components/com_content/models/article.php');
  15.  
  16. $string        = file_get_contents("items.json");
  17. $json_str      = json_decode($string, true);
  18. $title_default = 'No Title';
  19. $i             = 0;
  20. $new_article   = new ContentModelArticle();
  21. foreach ($json_str as $row) {
  22.     $data = array(
  23.         'title' => isset($row['title'][0]) && strlen(trim($row['title'][0])) != 0 ? $row['title'][0] : $title_default,
  24.         'alias' => $row['alias'][0],
  25.         'introtext' => $row['content'],
  26.         'state' => 1,
  27.         'catid' => $row['catid'][0],
  28.         /* don't hard code here! */
  29.         'created' => $row['pdate'],
  30.         'created_by' => 434,
  31.         'created_by_alias' => $row['poster'][0],
  32.         'publish_up' => $row['pdate'],
  33.         'urls' => json_encode($row['urls']),
  34.         'access' => 1,
  35.         'tags' => $row['tags'],
  36.         'metadata' => array(
  37.             'robots' => "",
  38.             'author' => implode(" ", $row['poster']),
  39.             'rights' => "",
  40.             'xreference' => ""
  41.         )
  42.     );
  43.     ++$i;
  44.    
  45.     $new_article->save($data);
  46.    
  47.     echo 'Record ' . $i . ' for post ' . $data['alias'] . ' processed';
  48.     echo "\r\n";
  49. }
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment