Current File : /home/karenpetzb/application/modules/backoffice/controllers/CsvController.php |
<?php
class Backoffice_CsvController extends Modules_Backoffice_Controllers_MainController
{
function init()
{
$this->view->title = "Administration";
$this->view->currentMenu = "Export";
$this->isConnectedWithRole('isStats');
}
function indexAction()
{
$this->_forward('/export');
}
function exporthelloAction() {
try {
$this->_helper->viewRenderer->setNeverRender();
$this->view->titlePage = "Exporter le fichier CSV";
$this->view->messageSuccess = "";
$this->view->messageError = "";
$fichier = new FichierExcel();
$fichier->Colonne("Nom du produit;Description du produit;Lien image du produit;Url vers la fiche produit sur le site du client;Lien vers une documentation sur le produit au format pdf;Identifiant unique du produit;Mot cl� 1;Mot cl� 2;Mot cl� 3;Mot cl� 4;Mot cl� 5;Mot cl� 6;Mot cl� 7;Mot cl� 8;Mot cl� 9;Mot cl� 10;Prix HT en �;Domaine d'utilisation;Marque du produit;Frais de port;Delai de livraison;Garantie;Disponibilit�;Quantit� minimum;EAN");
$sql = "SELECT p.ID ID, p.NOM NOM, p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.DESCRIPTIONLONG DESCLONG, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
p.DOCNAME DOCNAME, p.DOCURL DOCURL, p.IDBREND IDBREND,
p.isPROMO isPROMO, pic.URL URLIMAGE, sb.BREND BREND, sb.URL BRENDURL, p.IDCATEGORY IDCATEGORY, c.NOM CATEGORYNOM, c.NAVNOM CATEGORYNAV,
p.DESCRIPTIONTECH DESCTECH, p.DESCRIPTIONNORME DESCNORME, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
FROM product p
LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID
LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
LEFT JOIN category AS c ON c.ID = p.IDCATEGORY
WHERE p.isACTIVE = 0
AND pic.POSITION = 1
GROUP BY ID
ORDER BY p.ID ASC";
$product = new Product();
$productChild = new ProductChild();
$listProducts = $product->getAdapter()->fetchAll($sql);
foreach ($listProducts as $row) {
$sqlChild = "
SELECT pc.ID ID ,pc.REFERENCE REFERENCE,pc.DESIGNATION DESIGNATION,pc.PRIX PRIX, pc.isPROMO isPROMO ,
pc.IMAGEPROMO IMAGEPROMO,pc.isDEVIS isDEVIS, pc.QUANTITYMIN QUANTITYMIN
FROM productchild AS pc
WHERE pc.IDPRODUCT = ".$row['ID']."
ORDER BY pc.PRIX ASC";
$productChildTemp = $productChild->getAdapter()->fetchAll($sqlChild);
$navnom = $this->verifyNavigationString($row['NAVNOM'], $row['NOM'], '');
$urlImage = $this->baseUrl_SiteCommerceUrl."/".$row['URLIMAGE'];
//$urlPage = $this->baseUrl_SiteCommerceUrl."/produits/detail/page/".$navnom."/p/".$row['ID'];
$urlPage = $this->getUrlPage(array('NAVNOM_URLPARENTS' => $row['NAVNOM_URLPARENTS'], 'PAGE' => $navnom, 'ID' => $row['ID']));
$motcle = array();
$navnomStrip = explode("-", $navnom);
for ($index = 0; $index < sizeof($navnomStrip); $index++) {
$word = $navnomStrip[$index];
if (strlen($word) > 3){
array_push($motcle, $word);
}
}
if (sizeof($motcle) < 10) {
$navnomcat = explode("-", $row['CATEGORYNAV']);
for ($index = 0; $index < sizeof($navnomcat); $index++) {
$word = $navnomcat[$index];
if (strlen($word) > 3){
array_push($motcle, $word);
}
}
if (sizeof($motcle) < 10) {
$brend = $row['BREND'];
array_push($motcle, $brend);
}
if (sizeof($motcle) < 10) {
for ($index = sizeof($motcle); $index < 10; $index++) {
array_push($motcle, $this->siteName);
}
}
}
$reference = "";
$prix = "";
$description = "";
foreach ($productChildTemp as $rowChild) {
$reference = $rowChild['REFERENCE'];
$prix = $rowChild['PRIX'];
$descTemp = $row['DESCSHORT']." ".$rowChild['DESIGNATION'];
$description = $this->cleanUp($descTemp);
$description = addslashes($description);
break;
}
$fichier->Insertion('"'.$row['NOM'].'";"'.$description.'";"'.$urlImage.'";"'.$urlPage.'";"'.$row['DOCURL'].'";"'.$reference.'";"'.$motcle[0].'";"'.$motcle[1].'";"'.$motcle[2].'";"'.$motcle[3].'";"'.$motcle[4].'";"'.$motcle[5].'";"'.$motcle[6].'";"'.$motcle[7].'";"'.$motcle[8].'";"'.$motcle[9].'";'.$prix.';;"'.$row['BREND'].'";;"48H par TNT";;0;;');
}
$fichier->output('hellopro_fr');
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
}
}
function exportleguideAction() {
try {
$this->_helper->viewRenderer->setNeverRender();
$this->view->titlePage = "Exporter le fichier CSV";
$this->view->messageSuccess = "";
$this->view->messageError = "";
$fichier = new FichierExcel();
$fichier->Colonne("categorie;identifiant_unique;titre;description;prix;url_produit;url_image;frais_de_livraison;disponibilite;delais_de_livraison;garantie;reference_modele;D3E;marque;ean;prix_barre;type_promotion;devise;occasion;URL_mobile");
$sql = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.DESCRIPTIONLONG DESCLONG, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
p.DOCNAME DOCNAME, p.DOCURL DOCURL, p.IDBREND IDBREND,
p.isPROMO isPROMO, pic.URL URLIMAGE, sb.BREND BREND, sb.URL BRENDURL, p.IDCATEGORY IDCATEGORY, c.NOM CATEGORYNOM,
p.DESCRIPTIONTECH DESCTECH, p.DESCRIPTIONNORME DESCNORME, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
FROM product p
LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID
LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
LEFT JOIN category AS c ON c.ID = p.IDCATEGORY
WHERE p.isACTIVE = 0
AND pic.POSITION = 1
GROUP BY ID
ORDER BY p.ID ASC";
$product = new Product();
$productChild = new ProductChild();
$listProducts = $product->getAdapter()->fetchAll($sql);
foreach ($listProducts as $row) {
$sqlChild = "
SELECT pc.ID ID ,pc.REFERENCE REFERENCE,pc.DESIGNATION DESIGNATION,pc.PRIX PRIX, pc.isPROMO isPROMO ,
pc.IMAGEPROMO IMAGEPROMO,pc.isDEVIS isDEVIS, pc.QUANTITYMIN QUANTITYMIN
FROM productchild AS pc
WHERE pc.IDPRODUCT = ".$row['ID']."
ORDER BY pc.PRIX ASC";
$productChildTemp = $productChild->getAdapter()->fetchAll($sqlChild);
$navnom = $this->verifyNavigationString($row['NAVNOM'], $row['NOM'], '');
$urlImage = $this->baseUrl_SiteCommerceUrl."/".$row['URLIMAGE'];
//$urlPage = $this->baseUrl_SiteCommerceUrl."/produits/detail/".$navnom."/p/".$row['ID'];
$urlPage = $this->getUrlPage(array('NAVNOM_URLPARENTS' => $row['NAVNOM_URLPARENTS'],'PAGE' => $navnom, 'ID' => $row['ID']));
$fraislivraison = "";
$garantie="";
$reference = "";
$prix = "";
$description = "";
foreach ($productChildTemp as $rowChild) {
$reference = $rowChild['REFERENCE'];
$prix = $rowChild['PRIX'];
$descTemp = $row['DESCSHORT']." ".$rowChild['DESIGNATION'];
$description = $this->cleanUp($descTemp);
$description = addslashes($description);
break;
}
$fichier->Insertion('"'.$row['CATEGORYNOM'].'";"'.$reference.'";"'.$row['NOM'].'";"'.$description.'";"'.$prix.'";"'.$urlPage.'";"'.$urlImage.'";"'.$fraislivraison.'";"0";"48 heures";"'.$garantie.'";;;;;;;;;');
}
$fichier->output('leguide_fr');
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
}
}
function exportkelkooAction() {
try {
$this->_helper->viewRenderer->setNeverRender();
$this->view->titlePage = "Exporter le fichier CSV";
$this->view->messageSuccess = "";
$this->view->messageError = "";
$fichier = new FichierText();
$fichier->Colonne("id|model|brand|description|price|url|merchantcat|image|ean|sku|used|availability|deliveryprice|deliveryTime|deliveryinfo|warranty|ecotax|catkkid|taggingmatching|voucher|voucherdesc|voucherurl|vouchercode|voucherstart|voucherend|pricenorebate|percentagepromo|promostart|promoend|offertype|flag|shopinfo|validity");
$sql = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.DESCRIPTIONLONG DESCLONG, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
p.DOCNAME DOCNAME, p.DOCURL DOCURL, p.IDBREND IDBREND,
p.isPROMO isPROMO, pic.URL URLIMAGE, sb.BREND BREND, sb.URL BRENDURL, p.IDCATEGORY IDCATEGORY, c.NOM CATEGORYNOM, c.NAVNOM CATEGORYNAV, c.DESCRIPTION CATEGORYDESC,
p.DESCRIPTIONTECH DESCTECH, p.DESCRIPTIONNORME DESCNORME, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
FROM product p
LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID
LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
LEFT JOIN category AS c ON c.ID = p.IDCATEGORY
WHERE p.isACTIVE = 0
AND pic.POSITION = 1
GROUP BY ID
ORDER BY p.ID ASC";
$product = new Product();
$productChild = new ProductChild();
$listProducts = $product->getAdapter()->fetchAll($sql);
foreach ($listProducts as $row) {
$sqlChild = "
SELECT pc.ID ID ,pc.REFERENCE REFERENCE,pc.DESIGNATION DESIGNATION,pc.PRIX PRIX, pc.isPROMO isPROMO ,
pc.IMAGEPROMO IMAGEPROMO,pc.isDEVIS isDEVIS, pc.QUANTITYMIN QUANTITYMIN
FROM productchild AS pc
WHERE pc.IDPRODUCT = ".$row['ID']."
ORDER BY pc.PRIX ASC";
$productChildTemp = $productChild->getAdapter()->fetchAll($sqlChild);
$navnom = $this->verifyNavigationString($row['NAVNOM'], $row['NOM'], '');
$urlImage = $this->baseUrl_SiteCommerceUrl."/".$row['URLIMAGE'];
//$urlPage = $this->baseUrl_SiteCommerceUrl."/produits/detail/page/".$navnom."/p/".$row['ID'];
$urlPage = $this->getUrlPage(array('NAVNOM_URLPARENTS' => $row['NAVNOM_URLPARENTS'],'PAGE' => $navnom, 'ID' => $row['ID']));
$motcle = array();
$navnomStrip = explode("-", $navnom);
for ($index = 0; $index < sizeof($navnomStrip); $index++) {
$word = $navnomStrip[$index];
if (strlen($word) > 3){
array_push($motcle, $word);
}
}
if (sizeof($motcle) < 10) {
$navnomcat = explode("-", $row['CATEGORYNAV']);
for ($index = 0; $index < sizeof($navnomcat); $index++) {
$word = $navnomcat[$index];
if (strlen($word) > 3){
array_push($motcle, $word);
}
}
if (sizeof($motcle) < 10) {
$brend = $row['BREND'];
array_push($motcle, $brend);
}
if (sizeof($motcle) < 10) {
for ($index = sizeof($motcle); $index < 10; $index++) {
array_push($motcle, $this->siteName);
}
}
}
$reference = "";
$prix = "";
$description = "";
foreach ($productChildTemp as $rowChild) {
$reference = $rowChild['REFERENCE'];
$prix = $rowChild['PRIX'];
$descTemp = $row['DESCSHORT']." ".$rowChild['DESIGNATION'];
$description = $this->cleanUp($descTemp);
$description = str_replace("|", "", $description);
$description = addslashes($description);
break;
}
$catkid = "";
$shopinfo = $this->siteName." : ".str_replace("|", "", $this->cleanUp($row['CATEGORYDESC']));
$validity = "";
$fichier->Insertion('"'.$reference.'"|"'.$row['NOM'].'"|"'.$row['BREND'].'"|"'.$description.'"|'.$prix.'|"'.$urlPage.'"|"'.$row['CATEGORYNOM'].'"|"'.$urlImage.'"||||1||"Sous 48 heures"|"Livraison TNT Express"|||'.$catkid.'|"'.$motcle[0].' '.$motcle[1].' '.$motcle[2].' '.$motcle[3].' '.$motcle[4].'"|||||||||||single||"'.$shopinfo.'"|"'.$validity.'"');
}
$fichier->output('kelkoo_fr');
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
}
}
function exportciaoAction() {
try {
$this->_helper->viewRenderer->setNeverRender();
$this->view->titlePage = "Exporter le fichier CSV";
$this->view->messageSuccess = "";
$this->view->messageError = "";
$fichier = new FichierExcel();
$fichier->Colonne("Name;Brand;MNP;Deeplink;Imagelink;Price;ShippingCost;Delivery;Merchant;Category;SKU;offerID;Description");
$sql = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.DESCRIPTIONLONG DESCLONG, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
p.DOCNAME DOCNAME, p.DOCURL DOCURL, p.IDBREND IDBREND,
p.isPROMO isPROMO, pic.URL URLIMAGE, sb.BREND BREND, sb.URL BRENDURL, p.IDCATEGORY IDCATEGORY, c.NOM CATEGORYNOM, c.NAVNOM CATEGORYNAV,
p.DESCRIPTIONTECH DESCTECH, p.DESCRIPTIONNORME DESCNORME, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
FROM product p
LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID
LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
LEFT JOIN category AS c ON c.ID = p.IDCATEGORY
WHERE p.isACTIVE = 0
AND pic.POSITION = 1
GROUP BY ID
ORDER BY p.ID ASC";
$product = new Product();
$productChild = new ProductChild();
$listProducts = $product->getAdapter()->fetchAll($sql);
foreach ($listProducts as $row) {
$sqlChild = "
SELECT pc.ID ID ,pc.REFERENCE REFERENCE,pc.DESIGNATION DESIGNATION,pc.PRIX PRIX, pc.isPROMO isPROMO ,
pc.IMAGEPROMO IMAGEPROMO,pc.isDEVIS isDEVIS, pc.QUANTITYMIN QUANTITYMIN
FROM productchild AS pc
WHERE pc.IDPRODUCT = ".$row['ID']."
ORDER BY pc.PRIX ASC";
$productChildTemp = $productChild->getAdapter()->fetchAll($sqlChild);
$navnom = $this->verifyNavigationString($row['NAVNOM'], $row['NOM'], '');
$urlImage = $this->baseUrl_SiteCommerceUrl."/".$row['URLIMAGE'];
//$urlPage = $this->baseUrl_SiteCommerceUrl."/produits/detail/page/".$navnom."/p/".$row['ID'];
$urlPage = $this->getUrlPage(array('NAVNOM_URLPARENTS' => $row['NAVNOM_URLPARENTS'],'PAGE' => $navnom, 'ID' => $row['ID']));
$reference = "";
$prix = "";
$description = "";
foreach ($productChildTemp as $rowChild) {
$reference = $rowChild['REFERENCE'];
$prix = $rowChild['PRIX'];
$descTemp = $row['DESCSHORT']." ".$rowChild['DESIGNATION'];
$description = $this->cleanUp($descTemp);
$description = addslashes($description);
break;
}
$fichier->Insertion('"'.$row['NOM'].'";"'.$row['BREND'].'";;"'.$urlPage.'";"'.$urlImage.'";'.$prix.';;"48h";;"'.$row['CATEGORYNOM'].'";"EUR";"'.$reference.'";"'.$description.'"');
}
$fichier->output('ciao_fr');
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
}
}
public function sitemapxmlAction() {
try {
$this->view->titlePage = "Exporter le sitemap";
$this->view->messageSuccess = "";
$this->view->messageError = "";
if ($this->_request->isPost()) {
//get the form params
$params = $this->_request->getPost();
$changefreq = $params['changefreq'];
$priority = $params['priority'];
$isImageActive = $params['all_image'];
$isCheckLinkActive = $params['checklink'];
$isCustomNavnomActive = $params['all_navnom'];
// Instance de la class DomDocument
$doc = new DOMDocument();
// Definition de la version et l'encodage
$doc->version = '1.0';
$doc->encoding = 'UTF-8';
$isImage = true;
if ($isImageActive == "N") { $isImage = false; }
$body_elt = $doc->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset');
$doc->appendChild($body_elt);
if ($isImage) {
$body_elt->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:image', 'http://www.google.com/schemas/sitemap-image/1.1');
//$body_elt->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:video', 'http://www.google.com/schemas/sitemap-video/1.1');
}
$isDupliateByNavNom = false;
$isCheckLink = false;
if ($isCheckLinkActive == "Y") { $isCheckLink = true; }
$isCustomNavnom = false;
if ($isCustomNavnomActive == "Y") { $isCustomNavnom = true; }
$countDefault = $this->sitemapAddUrlDefault($doc, $body_elt, $isCheckLink);
$countProduct = $this->sitemapAddUrlProducts($doc, $body_elt, $changefreq, $priority, $isDupliateByNavNom,$isImage, $isCheckLink, $isCustomNavnom);
$countCategorie = $this->sitemapAddUrlCategories($doc, $body_elt, $changefreq, $priority, $isDupliateByNavNom,$isImage, $isCheckLink);
$countCategorie2 = $this->sitemapAddUrlCategories2($doc, $body_elt, $changefreq, $priority, $isDupliateByNavNom,$isImage, $isCheckLink);
$countServices = $this->sitemapAddUrlInfos($doc, $body_elt, $changefreq, $priority, $isDupliateByNavNom,$isImage, $isCheckLink);
$this->view->messageSuccess = "Le Sitemap a �t� remplac�.";
if ($countProduct['RESULT'] == 'SUCCESS') {
$this->view->messageSuccess .= " Produits : <b>".$countProduct['OK']."</b> urls,";
} else {
$this->view->messageError .= "Erreur sur les produits : ".$countProduct['OK']." urls OK, script interrompu. ".$countProduct['RESULT'];
}
if ($countCategorie['RESULT'] == 'SUCCESS') {
$this->view->messageSuccess .= " Cat�gories : <b>".$countCategorie['OK']."</b> urls,";
} else {
$this->view->messageError .= "Erreur sur les cat�gories : ".$countCategorie['OK']." urls OK, script interrompu. ".$countCategorie['RESULT'];
}
if ($countCategorie2['RESULT'] == 'SUCCESS') {
$this->view->messageSuccess .= " Cat�gories subsidiaires : <b>".$countCategorie2['OK']."</b> urls,";
} else {
$this->view->messageError .= "Erreur sur les cat�gories subsidiaires : ".$countCategorie2['OK']." urls OK, script interrompu. ".$countCategorie2['RESULT'];
}
if ($countServices['RESULT'] == 'SUCCESS') {
$this->view->messageSuccess .= " Informations : <b>".$countServices['OK']."</b> urls,";
} else {
$this->view->messageError .= "Erreur sur les informations : ".$countServices['OK']." urls OK, script interrompu. ".$countServices['RESULT'];
}
if ($countDefault['RESULT'] == 'SUCCESS') {
$this->view->messageSuccess .= " Connexions : <b>".$countDefault['OK']."</b> urls,";
} else {
$this->view->messageError .= "Erreur sur les connexions : ".$countDefault['OK']." urls OK, script interrompu. ".$countDefault['RESULT'];
}
$this->view->messageSuccess .= " Total de liens : <b>".($countProduct['OK']+$countCategorie['OK']+$countCategorie2['OK']+$countServices['OK']+$countDefault['OK'])."</b>";
if ($isCheckLink) {
$this->view->messageSuccess .= " V�rification des liens -> OK : <b>".($countProduct['OK']+$countCategorie['OK']+$countCategorie2['OK']+$countServices['OK']+$countDefault['OK'])."</b>";
$this->view->messageError .= " V�rification des liens -> Liens morts : <b>".($countProduct['NOK']+$countCategorie['NOK']+$countCategorie2['NOK']+$countServices['NOK']+$countDefault['NOK'])."</b>";
}
$doc->formatOutput = true;
// Sauver le document XML sous le nom simple.xml
$doc->save('sitemap.xml');
//echo $doc->saveXML();
if($this->pingBingForSitemap()) {
$this->view->messageSuccess .= ", Mise � niveau de Bing";
}
if($this->pingGoogleForSitemap()) {
$this->view->messageSuccess .= ", Mise � niveau de Google";
}
}
} catch (Zend_Exception $e) {
$this->log('Erreur lors de la generation du sitemap XML : '.$e->getMessage(),'err');
$this->view->messageError = "Erreur lors de la g�n�ration du sitemap XML : ".$e->getMessage();
}
}
private function pingBingForSitemap() {
return $this->sendUrlPostByRequest('http://www.bing.com/ping?sitemap='.$this->baseUrl_SiteCommerceUrl.'/sitemap.xml');
}
private function pingGoogleForSitemap() {
return $this->sendUrlPostByRequest('http://www.google.com/webmasters/sitemaps/ping?sitemap='.$this->baseUrl_SiteCommerceUrl.'/sitemap.xml');
}
private function sendUrlPostByRequest($url) {
$a = @get_headers($url);
if ($a) {
if (strstr($a[0],'200')) {
return true;
}
}
return false;
}
private function isLinkDead ($url) {
if ($this->sendUrlPostByRequest($url)) {
return false;
}
return true;
}
private function sitemapAddUrlProducts($doc, $body_elt, $changefreq, $priority, $isDupliateByNavNom, $isImage, $isCheckLink, $isCustomNavnom) {
try {
$countOk = 0;
$countNOk = 0;
$filter = new Zend_Filter();
$filter ->addFilter(new Zend_Filter_StripTags())
->addFilter(new Zend_Filter_StringTrim())
->addFilter(new Zend_Filter_CustomAccent())
->addFilter(new Zend_Filter_Alnum(array('allowwhitespace' => true)));
$filterLight = new Zend_Filter();
$filterLight->addFilter(new Zend_Filter_StripTags())
->addFilter(new Zend_Filter_StringTrim());
$sql = "SELECT p.ID ID, p.NOM NOM, p.NAVNOM NAVNOM, pic.URL URLIMAGE,
p.CUSTOM_NAVNOM1 CUSTOM_NAVNOM1 ,p.CUSTOM_NAVNOM2 CUSTOM_NAVNOM2 ,
p.CUSTOM_NAVNOM3 CUSTOM_NAVNOM3, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
FROM product p
LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID
LEFT JOIN category c ON p.IDCATEGORY = c.ID
WHERE p.isACTIVE = 0
AND pic.POSITION = 1
GROUP BY ID
ORDER BY p.ID ASC";
$product = new Product();
$listProducts = $product->getAdapter()->fetchAll($sql);
$picture = new Picture();
$date = new Zend_Date();
$currentDate = $date->toString('YYYY-MM-dd');
$type = 1;
foreach ($listProducts as $row) {
$url_elt = $doc->createElement('url');
$body_elt->appendChild($url_elt);
$navnom = $this->verifyNavigationString($row['NAVNOM'], $row['NOM'], '');
$urlPage = $this->getUrlPageProduct(array('NAVNOM_URLPARENTS' => $row['NAVNOM_URLPARENTS'],'PAGE' => $navnom, 'ID' => $row['ID'], 'TYPE' => $type));
$loc_elt = $doc->createElement('loc', $urlPage);
$url_elt->appendChild($loc_elt);
if ($isImage) {
$listPicture = $picture->fetchAll('IDPRODUCT = '.$row['ID']);
foreach ($listPicture as $pic) {
$image_elt = $doc->createElement('image:image');
$url_elt->appendChild($image_elt);
$urlImage = $this->baseUrl_SiteCommerceUrl."/".$pic['URL'];
$imageloc_elt = $doc->createElement('image:loc',$urlImage);
$image_elt->appendChild($imageloc_elt);
$string1 = $filter->filter($pic['STRING1']);
if (isset($string1) && !empty($string1)) {
$imagetitle_elt = $doc->createElement('image:title', $string1);
$image_elt->appendChild($imagetitle_elt);
}
$string2 = $filter->filter($pic['STRING2']);
if (isset($string2) && !empty($string2)) {
$imagecaption_elt = $doc->createElement('image:caption', $string2);
$image_elt->appendChild($imagecaption_elt);
}
}
}
$lastmod_elt = $doc->createElement('lastmod', $currentDate);
$changefreq_elt = $doc->createElement('changefreq', $changefreq);
$priority_elt = $doc->createElement('priority', $priority);
$url_elt->appendChild($lastmod_elt);
$url_elt->appendChild($changefreq_elt);
$url_elt->appendChild($priority_elt);
if ($isCheckLink && $this->isLinkDead($urlPage)) { $countNOk++;
} else { $countOk++; }
if ($isCustomNavnom) {
for ($index = 1; $index < 4; $index++) {
$navnomTemp = $filterLight->filter($row['CUSTOM_NAVNOM'.$index]);
if (!empty($navnomTemp)) {
$url_elt = $doc->createElement('url');
$body_elt->appendChild($url_elt);
$navnom = $this->verifyNavigationString($navnomTemp, $navnomTemp, '');
$urlPage = $this->getUrlPageProduct(array('NAVNOM_URLPARENTS' => $row['NAVNOM_URLPARENTS'],'PAGE' => $navnom, 'ID' => $row['ID'], 'TYPE' => $type));
$loc_elt = $doc->createElement('loc', $urlPage);
$url_elt->appendChild($loc_elt);
if ($isImage) {
$listPicture = $picture->fetchAll('IDPRODUCT = '.$row['ID']);
//$urlPage = $this->baseUrl_SiteCommerceUrl."/produits/detail/page/".$navnom."/p/".$row['ID'];
foreach ($listPicture as $pic) {
$image_elt = $doc->createElement('image:image');
$url_elt->appendChild($image_elt);
$urlImage = $this->baseUrl_SiteCommerceUrl."/".$pic['URL'];
$imageloc_elt = $doc->createElement('image:loc',$urlImage);
$image_elt->appendChild($imageloc_elt);
$string1 = $filter->filter($pic['STRING1']);
if (isset($string1) && !empty($string1)) {
$imagetitle_elt = $doc->createElement('image:title', $string1);
$image_elt->appendChild($imagetitle_elt);
}
$string2 = $filter->filter($pic['STRING2']);
if (isset($string2) && !empty($string2)) {
$imagecaption_elt = $doc->createElement('image:caption', $string2);
$image_elt->appendChild($imagecaption_elt);
}
}
}
$lastmod_elt = $doc->createElement('lastmod', $currentDate);
$changefreq_elt = $doc->createElement('changefreq', $changefreq);
$priority_elt = $doc->createElement('priority', $priority);
$url_elt->appendChild($lastmod_elt);
$url_elt->appendChild($changefreq_elt);
$url_elt->appendChild($priority_elt);
if ($isCheckLink && $this->isLinkDead($urlPage)) { $countNOk++;
} else { $countOk++; }
}
}
}
}
} catch (Zend_Exception $e) {
$this->log('Erreur lors de la generation du sitemapAddUrlProducts : '.$e->getMessage(),'err');
return array('OK' => $countOk, 'NOK' => $countNOk, 'RESULT' => $e->getMessage());
}
return array('OK' => $countOk, 'NOK' => $countNOk, 'RESULT' => 'SUCCESS');
}
private function sitemapAddUrlCategories($doc, $body_elt, $changefreq, $priority, $isDupliateByNavNom, $isImage, $isCheckLink) {
try {
$countOk = 0;
$countNOk = 0;
$filter = new Zend_Filter();
$filter ->addFilter(new Zend_Filter_StripTags())
->addFilter(new Zend_Filter_StringTrim())
->addFilter(new Zend_Filter_CustomAccent())
->addFilter(new Zend_Filter_Alnum(array('allowwhitespace' => true)));
$sql = "SELECT c.ID ID, c.NOM NOM, c.URL URL, c.NAVNOM NAVNOM, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
FROM category c WHERE c.isACTIVE = 1";
$categorie = new Category();
$listCats = $categorie->getAdapter()->fetchAll($sql);
$date = new Zend_Date();
$currentDate = $date->toString('YYYY-MM-dd');
$type = 1;
foreach ($listCats as $row) {
$url_elt = $doc->createElement('url');
$body_elt->appendChild($url_elt);
$navnom = $this->verifyNavigationString($row['NAVNOM'], $row['NOM'], '');
$urlPage = $this->getUrlPageCategory(array('NAVNOM_URLPARENTS' => $row['NAVNOM_URLPARENTS'], 'PAGE' => $navnom, 'ID' => $row['ID'], 'TYPE' => $type));
$loc_elt = $doc->createElement('loc', $urlPage);
$url_elt->appendChild($loc_elt);
if ($isImage) {
if (isset($row['URL']) && !empty($row['URL'])) {
$image_elt = $doc->createElement('image:image');
$url_elt->appendChild($image_elt);
$urlImage = $this->baseUrl_SiteCommerceUrl."/".$row['URL'];
$imageloc_elt = $doc->createElement('image:loc',$urlImage);
$image_elt->appendChild($imageloc_elt);
$string1 = $filter->filter($row['NOM']);
if (isset($string1) && !empty($string1)) {
$imagetitle_elt = $doc->createElement('image:title', $string1);
$image_elt->appendChild($imagetitle_elt);
}
}
}
$lastmod_elt = $doc->createElement('lastmod', $currentDate);
$changefreq_elt = $doc->createElement('changefreq', $changefreq);
$priority_elt = $doc->createElement('priority', $priority);
$url_elt->appendChild($lastmod_elt);
$url_elt->appendChild($changefreq_elt);
$url_elt->appendChild($priority_elt);
if ($isCheckLink && $this->isLinkDead($urlPage)) { $countNOk++;
} else { $countOk++; }
}
} catch (Zend_Exception $e) {
$this->log('Erreur lors de la generation du sitemapAddUrlCategories : '.$e->getMessage(),'err');
return array('OK' => $countOk, 'NOK' => $countNOk, 'RESULT' => $e->getMessage());
}
return array('OK' => $countOk, 'NOK' => $countNOk, 'RESULT' => 'SUCCESS');
}
private function sitemapAddUrlCategories2($doc, $body_elt, $changefreq, $priority, $isDupliateByNavNom, $isImage, $isCheckLink) {
try {
$countOk = 0;
$countNOk = 0;
$filter = new Zend_Filter();
$filter ->addFilter(new Zend_Filter_StripTags())
->addFilter(new Zend_Filter_StringTrim())
->addFilter(new Zend_Filter_CustomAccent())
->addFilter(new Zend_Filter_Alnum(array('allowwhitespace' => true)));
$sql = "SELECT c.ID ID, c.NOM NOM, c.URL URL, c.NAVNOM NAVNOM, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
FROM category2 c WHERE c.isACTIVE = 1";
$categorie = new Category();
$listCats = $categorie->getAdapter()->fetchAll($sql);
$date = new Zend_Date();
$currentDate = $date->toString('YYYY-MM-dd');
$type = 2;
foreach ($listCats as $row) {
$url_elt = $doc->createElement('url');
$body_elt->appendChild($url_elt);
$navnom = $this->verifyNavigationString($row['NAVNOM'], $row['NOM'], '');
$urlPage = $this->getUrlPageCategory(array('NAVNOM_URLPARENTS' => $row['NAVNOM_URLPARENTS'], 'PAGE' => $navnom, 'ID' => $row['ID'], 'TYPE' => $type));
$loc_elt = $doc->createElement('loc', $urlPage);
$url_elt->appendChild($loc_elt);
if ($isImage) {
if (isset($row['URL']) && !empty($row['URL'])) {
$image_elt = $doc->createElement('image:image');
$url_elt->appendChild($image_elt);
$urlImage = $this->baseUrl_SiteCommerceUrl."/".$row['URL'];
$imageloc_elt = $doc->createElement('image:loc',$urlImage);
$image_elt->appendChild($imageloc_elt);
$string1 = $filter->filter($row['NOM']);
if (isset($string1) && !empty($string1)) {
$imagetitle_elt = $doc->createElement('image:title', $string1);
$image_elt->appendChild($imagetitle_elt);
}
}
}
$lastmod_elt = $doc->createElement('lastmod', $currentDate);
$changefreq_elt = $doc->createElement('changefreq', $changefreq);
$priority_elt = $doc->createElement('priority', $priority);
$url_elt->appendChild($lastmod_elt);
$url_elt->appendChild($changefreq_elt);
$url_elt->appendChild($priority_elt);
if ($isCheckLink && $this->isLinkDead($urlPage)) {
$countNOk++;
} else { $countOk++; }
}
}
catch (Zend_Exception $e) {
$this->log('Erreur lors de la generation du sitemapAddUrlCategories2 : '.$e->getMessage(),'err');
return array('OK' => $countOk, 'NOK' => $countNOk, 'RESULT' => $e->getMessage());
}
return array('OK' => $countOk, 'NOK' => $countNOk, 'RESULT' => 'SUCCESS');
}
private function sitemapAddUrlInfos($doc, $body_elt, $changefreq, $priority, $isDupliateByNavNom,$isImage, $isCheckLink) {
try {
$countOk = 0;
$countNOk = 0;
$footers = new FooterContent();
$listFooter = $footers->fetchAll();
$date = new Zend_Date();
$currentDate = $date->toString('YYYY-MM-dd');
$type = 1;
foreach ($listFooter AS $row) {
$urlPage = $this->getUrlPageInfo(array('TITRE' => $row['TITRE'], 'ID' => $row['ID'], 'URL' => $row['URL'], 'TYPE' => $type));
$url_elt = $doc->createElement('url');
$body_elt->appendChild($url_elt);
$loc_elt = $doc->createElement('loc', $urlPage);
$url_elt->appendChild($loc_elt);
$lastmod_elt = $doc->createElement('lastmod', $currentDate);
$changefreq_elt = $doc->createElement('changefreq', $changefreq);
$priority_elt = $doc->createElement('priority', $priority);
$url_elt->appendChild($lastmod_elt);
$url_elt->appendChild($changefreq_elt);
$url_elt->appendChild($priority_elt);
if ($isCheckLink && $this->isLinkDead($urlPage)) { $countNOk++;
} else { $countOk++; }
}
} catch (Zend_Exception $e) {
$this->log('Erreur lors de la generation du sitemapAddUrlInfos : '.$e->getMessage(),'err');
return array('OK' => $countOk, 'NOK' => $countNOk, 'RESULT' => $e->getMessage());
}
return array('OK' => $countOk, 'NOK' => $countNOk, 'RESULT' => 'SUCCESS');
}
private function sitemapAddUrlDefault($doc, $body_elt, $isCheckLink) {
try {
$countOk = 0;
$countNOk = 0;
$date = new Zend_Date();
$currentDate = $date->toString('YYYY-MM-dd');
$addArray = array();
$addArray[0]['loc'] = $this->baseUrl_SiteCommerceUrl."/";
$addArray[0]['changefreq'] = "monthly";
$addArray[0]['priority'] = "0.9";
$addArray[1]['loc'] = $this->baseUrl_SiteCommerceUrl."/mon-panier.html";
$addArray[1]['changefreq'] = "monthly";
$addArray[1]['priority'] = "0.9";
$addArray[2]['loc'] = $this->baseUrl_SiteCommerceUrl."/connectez-vous.html";
$addArray[2]['changefreq'] = "monthly";
$addArray[2]['priority'] = "0.9";
$addArray[3]['loc'] = $this->baseUrl_SiteCommerceUrl."/enregistrez-vous.html";
$addArray[3]['changefreq'] = "monthly";
$addArray[3]['priority'] = "0.9";
$addArray[4]['loc'] = $this->baseUrl_SiteCommerceUrl."/services/faq/";
$addArray[4]['changefreq'] = "monthly";
$addArray[4]['priority'] = "0.9";
$addArray[5]['loc'] = $this->baseUrl_SiteCommerceUrl."/retrouver-mon-mot-de-passe.html";
$addArray[5]['changefreq'] = "monthly";
$addArray[5]['priority'] = "0.9";
for ($i = 0; $i < sizeof($addArray); $i++) {
$url_elt = $doc->createElement('url');
$body_elt->appendChild($url_elt);
$loc_elt = $doc->createElement('loc', $addArray[$i]['loc']);
$url_elt->appendChild($loc_elt);
$lastmod_elt = $doc->createElement('lastmod', $currentDate);
$changefreq_elt = $doc->createElement('changefreq', $addArray[$i]['changefreq']);
$priority_elt = $doc->createElement('priority', $addArray[$i]['priority']);
$url_elt->appendChild($lastmod_elt);
$url_elt->appendChild($changefreq_elt);
$url_elt->appendChild($priority_elt);
if ($isCheckLink && $this->isLinkDead($addArray[$i]['loc'])) { $countNOk++;
} else { $countOk++; }
}
} catch (Zend_Exception $e) {
$this->log('Erreur lors de la generation du sitemapAddUrlDefault : '.$e->getMessage(),'err');
return array('OK' => $countOk, 'NOK' => $countNOk, 'RESULT' => $e->getMessage());
}
return array('OK' => $countOk, 'NOK' => $countNOk, 'RESULT' => 'SUCCESS');
}
private function cleanUp($value) {
$result = $value;
$filter = new Zend_Filter();
$filter->addFilter(new Zend_Filter_StringTrim())
->addFilter(new Zend_Filter_StripTags());
$result =$filter->filter($result);
$result = html_entity_decode($result,ENT_QUOTES,"ISO-8859-1");
$result = str_replace("\r\n", "", $result);
$result = str_replace('"',"'",$result);
$result = str_replace(';',"'",$result);
return $result;
}
private function getUrlPage($params) {
//produit
return $this->baseUrl_SiteCommerceUrl."/".Utils_Tool::getFormattedUrlProduct($params['NAVNOM_URLPARENTS'], $params['PAGE'], $params['ID']);
}
private function getUrlPageProduct($params) {
//produit
switch ($params['TYPE']) {
case 1 :
return $this->baseUrl_SiteCommerceUrl."/".Utils_Tool::getFormattedUrlProduct($params['NAVNOM_URLPARENTS'], $params['PAGE'], $params['ID']);
break;
}
}
private function getUrlPageCategory($params) {
//category
switch ($params['TYPE']) {
case 1 :
return $this->baseUrl_SiteCommerceUrl."/".Utils_Tool::getFormattedUrlCategory($params['NAVNOM_URLPARENTS'], $params['PAGE'], $params['ID']);
break;
case 1 :
return $this->baseUrl_SiteCommerceUrl."/".Utils_Tool::getFormattedUrlCategory2($params['NAVNOM_URLPARENTS'], $params['PAGE'], $params['ID']);
break;
}
}
private function getUrlPageInfo($params) {
//Info
$navnom = $this->verifyNavigationString("", $params['TITRE'], "");
$urlPage = "";
if (empty($params['URL'])) {
switch ($params['TYPE']) {
case 1 :
$urlPage = $this->baseUrl_SiteCommerceUrl."/info-".$params['ID']."/".$navnom.".html";
break;
}
} else {
$urlPage = "http://".$params['URL'];
}
return $urlPage;
}
}
?>