ADD random new article in joomla through php code

No comments
instruction

1) create a new php file  add code give below.
2) put this file in joomla folder of your project.
3) run this php file.


////////////////////////////////code////////////////////////////////////
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>


</body>
</html>

<?php

define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);

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

//define('JPATH_COMPONENT_ADMINISTRATOR', dirname(__FILE__) . "/administrator");
define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_BASE . DS . 'administrator' . DS . 'components' . DS . 'com_content');
require_once JPATH_BASE.'/includes/framework.php';
//$app = JFactory::getApplication('site');
//require_once JPATH_BASE.'/includes/framework.php';


//echo JPATH_BASE. "/administrator/components/com_content/models/article.php";
require_once JPATH_BASE. "/administrator/components/com_content/models/article.php";
                         //administrator/components/com_content/models


$app = JFactory::getApplication('site', array('session' => false));

$total=100;

for($i=0;$i<100;$i++){

    $title_script="title".$i;
    $main_discription="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod";

       $data = array(
          'catid' => 80, //newsarticles
          'title' => $title_script,
          'introtext' =>$main_discription,
          'fulltext' => '',
          'state' => 1,);
     

      $title_script="";
      $main_discription="";
      $new_article = new ContentModelArticle();
      //print_r($data);

      $new_article->save($data);

    // add progress bar
    $percent = intval($i/$total * 100)."%";
    echo '<script language="javascript">
    document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\">&nbsp;</div>";
    document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
    </script>';
    // This is for the buffer achieve the minimum size in order to flush data
    echo str_repeat(' ',1024*64);   
    // Send output to browser immediately
    flush();   
    // Sleep one second so we can see the delay
    sleep(1);
    echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
}

?>

////////////////////////////////////////////////////////////////////////////////

No comments :

Post a Comment