Repaso al resto git-svn-id: https://192.168.0.254/svn/Proyectos.OriginalHouse_Web/trunk@52 54e8636e-a86c-764f-903d-b964358a1ae2
282 lines
12 KiB
PHP
282 lines
12 KiB
PHP
<?php
|
|
class SimpleXMLExtend extends SimpleXMLElement
|
|
{
|
|
public function addCData($nodename,$cdata_text,$namespace="")
|
|
{
|
|
$node = $this->addChild($nodename,'',$namespace); //Added a nodename to create inside the function
|
|
$node1 = dom_import_simplexml($node);
|
|
$no = $node1->ownerDocument;
|
|
$node1->appendChild($no->createCDATASection($cdata_text));
|
|
return $node;
|
|
}
|
|
}
|
|
|
|
header ('Content-type: text/html; charset=utf-8');
|
|
|
|
function leerFichero($archivo) {
|
|
|
|
if (!$muebles_xml = simplexml_load_file($archivo)) {
|
|
trigger_error('Error reading XML file',E_USER_ERROR);
|
|
}
|
|
|
|
$muebles = array();
|
|
$cont = 0;
|
|
foreach($muebles_xml as $mueble_xml) {
|
|
$muebles[$cont]['titulo'] = trim($mueble_xml->titulo);
|
|
$muebles[$cont]['slug'] = preg_replace("![^a-z0-9]+!i", "-", strtoupper(trim($muebles[$cont]['titulo'])));
|
|
$muebles[$cont]['precio'] = trim($mueble_xml->precio);
|
|
$muebles[$cont]['categoria_name'] = $mueble_xml->categoria_name;
|
|
$muebles[$cont]['categoria'] = $mueble_xml->categoria;
|
|
|
|
$muebles[$cont]['descripcion'] = '';
|
|
|
|
if (strlen($mueble_xml->medidas) > 0) {
|
|
$muebles[$cont]['descripcion'] .= trim($mueble_xml->medidas) . 'cm';
|
|
}
|
|
|
|
if (strlen($mueble_xml->obs) > 0) {
|
|
$muebles[$cont]['descripcion'] .= ' ' . trim($mueble_xml->obs);
|
|
}
|
|
|
|
if (strlen($mueble_xml->Obs) > 0) {
|
|
$muebles[$cont]['descripcion'] .= ' ' . trim($mueble_xml->Obs);
|
|
}
|
|
|
|
$cont++;
|
|
}
|
|
return $muebles;
|
|
}
|
|
|
|
|
|
function escribirFicheroXML($muebles, $archivo_salida) {
|
|
include "cabecera.php";
|
|
$xml = new SimpleXMLExtend($xmlstr);
|
|
$raiz = $xml->channel;
|
|
|
|
foreach($muebles as $mueble) {
|
|
$item = $raiz->addChild('item');
|
|
|
|
|
|
$item->addChild('title', $mueble['titulo']);
|
|
$item->addChild('link', 'http://localhost/originalhouse/?tcp_product='.$mueble['slug']);
|
|
$item->addChild('pubDate', 'Wed, 15 Jul 2011 00:00:00 +0000');
|
|
$item->addChild('dc:creator', 'rodax');
|
|
$guid = $item->addChild('guid', 'http://localhost/originalhouse/?tcp_product&p='.$mueble['slug']);
|
|
$guid->addAttribute('isPermaLink' , 'false');
|
|
$item->addChild('description', '');
|
|
$item->addCData('content:encoded', $mueble['descripcion'], 'http://purl.org/rss/1.0/modules/content/');
|
|
$item->addCData('excerpt:encoded', '', 'http://purl.org/rss/1.0/modules/excerpt/');
|
|
//<wp:post_id>227</wp:post_id>
|
|
$item->addChild('post_date', '2011-07-15 17:09:59', 'http://wordpress.org/export/1.1/');
|
|
$item->addChild('post_date_gmt', '2011-07-15 17:09:59', 'http://wordpress.org/export/1.1/');
|
|
$item->addChild('post_name', $mueble['slug'], 'http://wordpress.org/export/1.1/');
|
|
$item->addChild('status', 'publish', 'http://wordpress.org/export/1.1/');
|
|
$item->addChild('post_type', 'tcp_product', 'http://wordpress.org/export/1.1/');
|
|
|
|
$categoria = $item->addCData('category', $mueble['categoria']);
|
|
$categoria->addAttribute('domain', 'tcp_product_category');
|
|
$categoria->addAttribute('nicename', $mueble['categoria_name']);
|
|
|
|
$meta = $item->addChild('wp:postmeta', '', 'http://wordpress.org/export/1.1/');
|
|
$meta->addChild('wp:meta_key', 'tcp_price', 'http://wordpress.org/export/1.1/');
|
|
$meta->addCData('wp:meta_value', $mueble['precio'], 'http://wordpress.org/export/1.1/');
|
|
}
|
|
return $xml->asXML($archivo_salida);
|
|
}
|
|
|
|
|
|
/* INSERT INTO `wp_posts` (`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_status`, `comment_status`, `ping_status`, `post_name`, `post_modified`, `post_modified_gmt`, `post_parent`, `guid`, `menu_order`, `post_type`, `comment_count`) VALUES
|
|
(1, now(), now(), '85x130x45 cm', 'ACRO 66ML', 'publish', 'closed', 'open', 'ACRO 66ML', now(), now(), 0, 'http://localhost/originalhouse/?post_type=tcp_product&p=214', 0, 'tcp_product', 0),
|
|
* insert into wp_postmeta (post_id, meta_key, meta_value) values (227, 'tcp_price', 697);
|
|
*/
|
|
function escribirFichero($muebles, $categoria, $archivo_salida) {
|
|
|
|
$file = fopen($archivo_salida, "w+");
|
|
if (!$file) {
|
|
trigger_error('Error creando fichero de salida', E_USER_ERROR);
|
|
}
|
|
$cont = 0;
|
|
foreach($muebles as $mueble) {
|
|
generarRegistrosMueble($mueble, $cont, $categoria, $file);
|
|
$cont++;
|
|
}
|
|
fclose($file);
|
|
}
|
|
|
|
function generarRegistrosMueble($mueble, $orden, $categoria, $file) {
|
|
/* INSERT INTO `wp_posts` (`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_status`, `comment_status`, `ping_status`, `post_name`,
|
|
* `post_modified`, `post_modified_gmt`, `post_parent`, `guid`, `menu_order`, `post_type`, `comment_count`) VALUES
|
|
(1, now(), now(), '85x130x45 cm', 'ACRO 66ML', 'publish', 'closed', 'open', 'ACRO 66ML', now(), now(), 0, 'http://localhost/originalhouse/?post_type=tcp_product&p=214', 0, 'tcp_product', 0),
|
|
* insert into wp_postmeta (post_id, meta_key, meta_value) values (227, 'tcp_price', 697);
|
|
*/
|
|
|
|
$output = "INSERT INTO `wp_posts` (`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_status`, `comment_status`, `ping_status`, `post_name`, `post_modified`, `post_modified_gmt`, `post_parent`, `guid`, `menu_order`, `post_type`, `comment_count`) VALUES \n";
|
|
$output .= "(";
|
|
$output .= "1, now(), now(), ";
|
|
$output .= "'" . $mueble['descripcion'] . "', "; // post_content
|
|
$output .= "'" . $mueble['titulo'] . "', "; // post_title
|
|
$output .= "'publish', 'closed', 'open', ";
|
|
$output .= "'" . $mueble['slug'] . "', "; // post_name
|
|
$output .= "now(), now(), 0, ";
|
|
$output .= "'http://localhost/originalhouse/?tcp_product&p=".$mueble['slug']."', ";
|
|
$output .= "0, 'tcp_product', 0";
|
|
$output .= ");";
|
|
$output .= "\n";
|
|
fwrite($file, $output);
|
|
|
|
//
|
|
$output = "SET @last_id := LAST_INSERT_ID();\n";
|
|
fwrite($file, $output);
|
|
|
|
//INSERT INTO `wp_term_relationships` (`object_id`, `term_taxonomy_id`, `term_order`) VALUES
|
|
|
|
$output = "INSERT INTO `wp_term_relationships` (`object_id`, `term_taxonomy_id`, `term_order`) VALUES \n";
|
|
$output .= "(@last_id, ". $categoria . ", 0);\n";
|
|
fwrite($file, $output);
|
|
|
|
// metadatos
|
|
$output = "insert into wp_postmeta (post_id, meta_key, meta_value) values \n";
|
|
// precio
|
|
$output .= "(@last_id, 'tcp_price', '" . $mueble['precio'] . "'),\n";
|
|
//stock
|
|
$output .= "(@last_id, 'tcp_stock', -1),\n";
|
|
//tipo
|
|
$output .= "(@last_id, 'tcp_type', 'SIMPLE'),\n";
|
|
//order
|
|
$output .= "(@last_id, 'tcp_order', '". $orden . "'),\n";
|
|
//sku
|
|
$output .= "(@last_id, 'tcp_sku', '".$mueble['slug']."'),\n";
|
|
$output .= "(@last_id, 'tcp_tax_id', '0'),\n";
|
|
$output .= "(@last_id, 'tcp_back_end_label', ''),\n";
|
|
$output .= "(@last_id, 'tcp_hide_buy_button', ''),\n";
|
|
$output .= "(@last_id, 'tcp_exclude_range', ''),\n";
|
|
$output .= "(@last_id, 'tcp_is_downloadable', ''),\n";
|
|
$output .= "(@last_id, 'tcp_max_downloads', '0'),\n";
|
|
$output .= "(@last_id, 'tcp_days_to_expire', '0'),\n";
|
|
$output .= "(@last_id, 'tcp_is_visible', '1'),\n";
|
|
$output .= "(@last_id, 'tcp_weight', '0');\n";
|
|
|
|
fwrite($file, $output);
|
|
|
|
//SELECT * FROM `wp_posts` WHERE `post_type` = 'attachment' and `post_mime_type` = 'image/jpeg' and `post_name` = $mueble['slug']
|
|
|
|
//imagen
|
|
$output = "insert into wp_postmeta (post_id, meta_key, meta_value) \n";
|
|
$output .= "SELECT @last_id, '_thumbnail_id', wp_posts.id FROM `wp_posts` WHERE `post_type` = 'attachment' and `post_mime_type` = 'image/jpeg' and ";
|
|
$output .= "`post_title` = '" . $mueble['slug'] . "';\n\n\n";
|
|
fwrite($file, $output);
|
|
}
|
|
|
|
/*
|
|
* <title>ACRO 66ML</title>
|
|
<link>http://localhost/originalhouse/?tcp_product=acro-66ml</link>
|
|
<pubDate>Wed, 06 Jul 2011 17:09:59 +0000</pubDate>
|
|
<dc:creator>rodax</dc:creator>
|
|
<guid isPermaLink="false">http://localhost/originalhouse/?post_type=tcp_product&p=214</guid>
|
|
<description></description>
|
|
<content:encoded><![CDATA[85x130x45 cm]]></content:encoded>
|
|
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
|
|
<wp:post_id>227</wp:post_id>
|
|
<wp:post_date>2011-07-06 17:09:59</wp:post_date>
|
|
<wp:post_date_gmt>2011-07-06 17:09:59</wp:post_date_gmt>
|
|
<wp:comment_status>closed</wp:comment_status>
|
|
<wp:ping_status>closed</wp:ping_status>
|
|
<wp:post_name>acro-66ml</wp:post_name>
|
|
<wp:status>publish</wp:status>
|
|
<wp:post_parent>0</wp:post_parent>
|
|
<wp:menu_order>0</wp:menu_order>
|
|
<wp:post_type>tcp_product</wp:post_type>
|
|
<wp:post_password></wp:post_password>
|
|
<wp:is_sticky>0</wp:is_sticky>
|
|
<category domain="tcp_product_category" nicename="aparadores"><![CDATA[Aparadores]]></category>
|
|
<wp:postmeta>
|
|
<wp:meta_key>tcp_price</wp:meta_key>
|
|
<wp:meta_value><![CDATA[697]]></wp:meta_value>
|
|
</wp:postmeta>
|
|
*
|
|
|
|
*/
|
|
|
|
$archivo = 'armarios-cajoneras.xml';
|
|
$archivo_salida = 'salida-armarios-cajoneras.sql';
|
|
$muebles = leerFichero($archivo);
|
|
echo escribirFichero($muebles, 48, $archivo_salida);
|
|
|
|
|
|
$archivo = 'consolas.xml';
|
|
$archivo_salida = 'salida-consolas.sql';
|
|
$muebles = leerFichero($archivo);
|
|
echo escribirFichero($muebles, 50, $archivo_salida);
|
|
|
|
$archivo = 'estanterias.xml';
|
|
$archivo_salida = 'salida-estanterias.sql';
|
|
$muebles = leerFichero($archivo);
|
|
echo escribirFichero($muebles, 45, $archivo_salida);
|
|
|
|
$archivo = 'vitrinas.xml';
|
|
$archivo_salida = 'salida-vitrinas.sql';
|
|
$muebles = leerFichero($archivo);
|
|
echo escribirFichero($muebles, 46, $archivo_salida);
|
|
|
|
|
|
$archivo = 'mesas-centro.xml';
|
|
$archivo_salida = 'salida-mesas-centro.sql';
|
|
$muebles = leerFichero($archivo);
|
|
echo escribirFichero($muebles, 57, $archivo_salida);
|
|
|
|
|
|
$archivo = 'mesas-comedor.xml';
|
|
$archivo_salida = 'salida-mesas-comedor.sql';
|
|
$muebles = leerFichero($archivo);
|
|
echo escribirFichero($muebles, 56, $archivo_salida);
|
|
|
|
|
|
$archivo = 'mesas-rincon.xml';
|
|
$archivo_salida = 'salida-mesas-rincon.sql';
|
|
$muebles = leerFichero($archivo);
|
|
echo escribirFichero($muebles, 58, $archivo_salida);
|
|
|
|
|
|
$archivo = 'muebles-tv.xml';
|
|
$archivo_salida = 'salida-muebles-tv.sql';
|
|
$muebles = leerFichero($archivo);
|
|
echo escribirFichero($muebles, 49, $archivo_salida);
|
|
|
|
|
|
$archivo = 'sillas.xml';
|
|
$archivo_salida = 'salida-sillas.sql';
|
|
$muebles = leerFichero($archivo);
|
|
echo escribirFichero($muebles, 52, $archivo_salida);
|
|
|
|
|
|
$archivo = 'sofas.xml';
|
|
$archivo_salida = 'salida-sofas.sql';
|
|
$muebles = leerFichero($archivo);
|
|
echo escribirFichero($muebles, 51, $archivo_salida);
|
|
|
|
|
|
$archivo = 'sofas-cama.xml';
|
|
$archivo_salida = 'salida-sofas-cama.sql';
|
|
$muebles = leerFichero($archivo);
|
|
echo escribirFichero($muebles, 51, $archivo_salida);
|
|
|
|
|
|
/*if ($muebles_xml) {
|
|
foreach($muebles_xml as $mueble_xml) {
|
|
$muebles['id'] = $mueble_xml->Id;
|
|
$muebles['titulo'] = $mueble_xml->titulo;
|
|
$muebles['slug'] = preg_replace("![^a-z0-9]+!i", "-", strtolower($muebles[titulo]));
|
|
|
|
print_r($muebles);
|
|
}*/
|
|
/*foreach($muebles->children() as $child) {
|
|
echo $child->getName().":
|
|
";
|
|
|
|
foreach($child->children() as $subchild) {
|
|
echo "--->".$subchild->getName().": ".$subchild."
|
|
";
|
|
}
|
|
}*/
|
|
?>
|