<?
require( $_SERVER [ "DOCUMENT_ROOT" ]. "/bitrix/header.php" );
CModule :: IncludeModule ( "iblock" );
?>
<?
### CONFIG ###
$file = "delfin_test.dat1" ;
### TOOLS ###
function getIpsum ( $cnt , $what )
{
$url = "http://www.lipsum.com/feed/html?amount=$cnt&what=$what" ;
$text = file_get_contents ( $url );
preg_match ( "'<div id=\"lipsum\"[^>]*?>(.*?)</div>'si" , $text , $matches );
return $matches [ 1 ];
}
?>
<?
include( $file );
$obSect = new CIBlockSection ;
$obItem = new CIBlockElement ;
while ( list( $IBLOCK_ID , $arrCfg ) = each ( $cfg ) )
{
$sectCnt = 0 ;
$itemCnt = 0 ;
$sect = array();
$time = strtotime ( "-60 days" );
if ( $arrCfg [ "sect_count" ] > 0 )
{
for ( $i = 0 ; $i < $arrCfg [ "sect_count" ]; $i ++)
{
$sectCnt ++;
$arSect = Array(
"IBLOCK_ID" => $IBLOCK_ID ,
"NAME" => str_replace ( "#NUM#" , $sectCnt , $arrCfg [ "sect_name_tpl" ])
);
$ID = $obSect -> Add ( $arSect );
if ( $ID > 0 )
$sect [] = $ID ;
else
echo $obSect -> LAST_ERROR ;
}
}
else
{
$sect [] = 0 ;
}
reset ( $sect );
while ( list(, $SECTION_ID ) = each ( $sect ) )
{
for ( $i = 0 ; $i < $arrCfg [ "items_count" ]; $i ++)
{
$itemCnt ++;
$arTmp = explode ( ":" , $arrCfg [ "item_preview_txt" ]);
if ( $arTmp [ 0 ] == "ipsum" )
{
$arTmp = explode ( "#" , $arTmp [ 1 ]);
$preview = getIpsum ( $arTmp [ 0 ], $arTmp [ 1 ]);
}
$arTmp = explode ( ":" , $arrCfg [ "item_detail_txt" ]);
if ( $arTmp [ 0 ] == "ipsum" )
{
$arTmp = explode ( "#" , $arTmp [ 1 ]);
$detail = getIpsum ( $arTmp [ 0 ], $arTmp [ 1 ]);
}
$arItem = Array(
"ACTIVE" => "Y" ,
"IBLOCK_ID" => $IBLOCK_ID ,
"IBLOCK_SECTION" => $SECTION_ID ,
"NAME" => str_replace ( "#NUM#" , $itemCnt , $arrCfg [ "item_name_tpl" ]),
"ACTIVE_FROM" => ConvertTimeStamp ( $time + $itemCnt * 24 * 60 * 60 ),
"PREVIEW_TEXT" => $preview ,
"DETAIL_TEXT" => $detail ,
"PREVIEW_TEXT_TYPE" => "html" ,
"DETAIL_TEXT_TYPE" => "html" ,
);
$ID = $obItem -> Add ( $arItem );
if ( $ID > 0 )
$items [] = $ID ;
else
echo $obItem -> LAST_ERROR ;
}
}
}
?>
<?
$cfg = Array(
1 => Array(
"sect_count" => 3 ,
"items_count" => 5 ,
"sect_name_tpl" => " β#NUM#" ,
"item_name_tpl" => " β#NUM#" ,
"item_preview_txt" => "ipsum:20#words" ,
"item_detail_txt" => "ipsum:5#paras" ,
),
2 => Array(
"sect_count" => 0 ,
"items_count" => 15 ,
"item_name_tpl" => " β#NUM#" ,
"item_preview_txt" => "ipsum:20#words" ,
"item_detail_txt" => "ipsum:5#paras" ,
),
3 => Array(
"sect_count" => 0 ,
"items_count" => 10 ,
"item_name_tpl" => " β#NUM#" ,
"item_preview_txt" => "ipsum:2#paras" ,
"item_detail_txt" => "ipsum:7#paras" ,
),
4 => Array(
"sect_count" => 0 ,
"items_count" => 10 ,
"item_name_tpl" => " β#NUM#" ,
"item_preview_txt" => "ipsum:5#words" ,
"item_detail_txt" => "ipsum:2#paras" ,
),
5 => Array(
"sect_count" => 0 ,
"items_count" => 10 ,
"item_name_tpl" => " β#NUM#" ,
"item_preview_txt" => "ipsum:3#words" ,
"item_detail_txt" => "ipsum:3#paras" ,
),
6 => Array(
"sect_count" => 5 ,
"items_count" => 8 ,
"item_name_tpl" => " β#NUM#" ,
"sect_name_tpl" => " β#NUM#" ,
"item_preview_txt" => "ipsum:20#words" ,
"item_detail_txt" => "ipsum:2#paras" ,
),
);
?>
Source: https://habr.com/ru/post/44359/
All Articles