[bitrix] export photos 3.0

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
CModule::IncludeModule("iblock");
$fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/upload/full_export_iblock_12/products.xml", "w+");
fwrite($fp, "<" . "?xml version=\"1.0\" encoding=\"UTF8\"?" . ">\n");
fwrite($fp, "<products>\n");
$new_path = "/upload/full_export_iblock_12/products_files";
$res = CIBlockElement::GetList(
array("show_counter" => "desc"),
array("IBLOCK_ID" => 12, "ACTIVE"=>"Y", "!PROPERTY_CML2_ARTICLE" => false),
false,
false,
array("ID", "IBLOCK_ID", "NAME", "CODE", "PREVIEW_PICTURE", "DETAIL_PICTURE"
/*,"PROPERTY_IS_NEW", "PROPERTY_IS_BESTSELLER", "PROPERTY_IS_SALE", "PROPERTY_IS_ARCHIVE"*/)
);
while ($ar_res = $res->Fetch()) {
fwrite($fp, "<item>\n");
fwrite($fp, "<name>".str_replace("&", "&amp;", $ar_res["NAME"])."</name>\n");
fwrite($fp, "<code>".$ar_res["CODE"]."</code>\n");
if($ar_res["PREVIEW_PICTURE"]) {
fwrite($fp, "<preview_picture_int>" . $ar_res["PREVIEW_PICTURE"] . "</preview_picture_int>\n");
$pPicture = CFile::GetPath($ar_res["PREVIEW_PICTURE"]);
$bdirName = str_replace("/upload/iblock","",$pPicture);
$new_dir_name = $_SERVER["DOCUMENT_ROOT"] . $new_path . dirname($bdirName);
if(!is_dir($new_dir_name)) mkdir($new_dir_name);
$bSaved = copy($_SERVER["DOCUMENT_ROOT"] . $pPicture, $_SERVER["DOCUMENT_ROOT"] . $new_path . $bdirName);
if($bSaved)
fwrite($fp, "<preview_picture>" . $new_path . $bdirName . "</preview_picture>\n");
}
if($ar_res["DETAIL_PICTURE"]) {
$dPicture = CFile::GetPath($ar_res["DETAIL_PICTURE"]);
fwrite($fp, "<detail_picture_int>" . $ar_res["DETAIL_PICTURE"] . "</detail_picture_int>\n");
$bdirName = str_replace("/upload/iblock","",$dPicture);
$new_dir_name = $_SERVER["DOCUMENT_ROOT"] . $new_path . dirname($bdirName);
if(!is_dir($new_dir_name)) mkdir($new_dir_name);
$bSaved = copy($_SERVER["DOCUMENT_ROOT"] . $dPicture, $_SERVER["DOCUMENT_ROOT"] . $new_path . $bdirName);
if($bSaved)
fwrite($fp, "<detail_picture>" . $new_path . $bdirName . "</detail_picture>\n");
}
$db_props = CIBlockElement::GetProperty(12, $ar_res["ID"], array("sort" => "asc"), Array("CODE"=>"MORE_PHOTO"));
$images = "";
while($ar_props = $db_props->Fetch()) {
if($ar_props["VALUE"]) {
$images .= "<file_int>" . $ar_props["VALUE"] . "</file_int>\n";
$file = CFile::GetPath($ar_props["VALUE"]);
$bdirName = str_replace("/upload/iblock","",$file);
$new_dir_name = $_SERVER["DOCUMENT_ROOT"] . $new_path . dirname($bdirName);
if(!is_dir($new_dir_name)) mkdir($new_dir_name);
$bSaved = copy($_SERVER["DOCUMENT_ROOT"] . $file, $_SERVER["DOCUMENT_ROOT"] . $new_path . $bdirName);
if($bSaved)
$images .= "<file>" . $new_path . $bdirName . "</file>\n";
}
}
if(!empty($images)) {
fwrite($fp, "<more_pictures>\n");
fwrite($fp, $images);
fwrite($fp, "</more_pictures>\n");
}
/*
if($ar_res["PROPERTY_IS_NEW_VALUE"])
fwrite($fp, "<new>".$ar_res["PROPERTY_IS_NEW_VALUE"]."</new>\n");
if($ar_res["PROPERTY_IS_BESTSELLER_VALUE"])
fwrite($fp, "<bestseller>".$ar_res["PROPERTY_IS_BESTSELLER_VALUE"]."</bestseller>\n");
if($ar_res["PROPERTY_IS_SALE_VALUE"])
fwrite($fp, "<sale>".$ar_res["PROPERTY_IS_SALE_VALUE"]."</sale>\n");
if($ar_res["PROPERTY_IS_ARCHIVE_VALUE"])
fwrite($fp, "<archive>".$ar_res["PROPERTY_IS_ARCHIVE_VALUE"]."</archive>\n");
*/
// if($ar_res["PROPERTY_MEGAVISOR_VALUE"])
// fwrite($fp, "<megavisor>".$ar_res["PROPERTY_MEGAVISOR_VALUE"]."</megavisor>\n");
// if($ar_res["PROPERTY_VIDEO_URL_VALUE"])
// fwrite($fp, "<video>".$ar_res["PROPERTY_VIDEO_URL_VALUE"]."</video>\n");
fwrite($fp, "</item>\n");
}
fwrite($fp, "</products>\n");
fclose($fp);