public function getProductInfo($l) { /* Image Url's: list view:http://img6a.flixcart.com/image/computer/m/h/8/lenovo-ideapad-notebook-125x125-imadd4f7jrzuchmg.jpeg thumbnail:http://img6a.flixcart.com/image/computer/m/h/8/lenovo-ideapad-notebook-400x400-imadd4f7jrzuchmg.jpeg small thumbnail:http://img6a.flixcart.com/image/computer/m/h/8/lenovo-ideapad-notebook-100x100-imadd4f7jrzuchmg.jpeg Available dimensions: 100X100 125X125 200X200 400X400 */ echo "<h5>Link:" . $l->link . "</h5>"; $ch = curl_init($l->link); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); $content = curl_exec($ch); if ($content === false) { echo "Waittt:::" . $content; echo 'Curl error: ' . curl_error($ch); flush(); return false; } $dom = new DOMDocument(); @$dom->loadHTML($content); $data = array(); $data['product_code'] = $l->product_code; $title = $dom->getElementById("specifications"); if (is_object($title)) { foreach ($title->childNodes as $c1) { if (isset($c1->tagName) && $c1->tagName == "h3" && $c1->getAttribute("class") == "item_desc_title fk-uppercase") { $data['title'] = $c1->nodeValue; if (substr_count($data['title'], "Specifications of") > 0) { $data['title'] = str_replace("Specifications of", "", $data['title']); } break; } } } else { $title = $dom->getElementsByTagName("title"); foreach ($title as $c1) { if (isset($c1->tagName) && $c1->tagName == "title") { $data['title'] = $c1->nodeValue; break; } } } $data['title'] = trim($data['title']); $price = $dom->getElementsBytagName("meta"); foreach ($price as $p) { if (isset($p->tagName) && $p->tagName == "meta" && $p->getAttribute("itemprop") == "price") { $data['price'] = trim($p->getAttribute("content")); break; } } foreach ($price as $p) { if (isset($p->tagName) && $p->tagName == "meta" && $p->getAttribute("itemprop") == "ratingValue") { $data['star_rate'] = trim($p->getAttribute("content")); break; } } $data['link'] = $l->link; $data['parent_link'] = $l->parent_link; $specifications = $dom->getElementsBytagName("td"); $c = 0; foreach ($specifications as $s) { //specs-key //specs-value fk-data if ($s->nodeValue == null) { continue; } if ($s->getAttribute("class") == "specs-key") { $key = $s->nodeValue; if (isset($data['brand']) && strtolower($s->nodeValue) == "brand") { $key = "processor_brand"; } // echo $s->nodeValue; $c++; } else { if ($s->getAttribute("class") == "specs-value fk-data") { $value = $s->nodeValue; //echo ":".$s->nodeValue; $c++; } } if ($c == 2) { $data[strtolower(str_replace(' ', '_', trim($key)))] = trim($value); $c = 0; //echo "<hr/>"; } } $description = $dom->getElementsByTagName("ul"); if ($description) { foreach ($description as $d) { $class = $d->getAttribute("class"); if (isset($d->tagName) && $d->tagName == "ul" && ($class == "fk-key-features" || $class == "feature_bullet")) { $data['description'] = trim($this->getInnerHTML($d)); break; } if (!isset($data['description'])) { $description = $dom->getElementById("description"); if ($description) { foreach ($description->childNodes as $c) { if (isset($c->tagName) && $c->tagName == "div" && $c->getAttribute("class") == "item_desc_text line") { $data['description'] = trim($this->getInnerHTML($c)); $data['description'] = str_replace('<div style="float:right"> </div>', '', $data['description']); } } } } } // $data['description']=DOMinnerHTML($description); } $video = $dom->getElementsByTagName("param"); foreach ($video as $c1) { if (isset($c1->tagName) && $c1->tagName == "param" && $c1->getAttribute("name") == "movie") { $data['video_url'] = $c1->getAttribute("value"); break; } } $images = $dom->getElementsBytagName("span"); foreach ($images as $img) { /* if($l->category_name=="mobile") { $class="mi-thumb thumbs thumbs-small"; } else if($l->category_name=="laptop") { $class="thumbs thumbs-small"; } */ if (isset($img->tagName) && $img->tagName == "span" && $img->getAttribute("class") == "mi-thumb thumbs thumbs-small") { foreach ($img->childNodes as $c1) { if (isset($c1->tagName) && $c1->tagName == "img") { $img_url = $c1->getAttribute("src"); $very_small = $img_url; $small = str_replace('100x100', '125x125', $img_url); $medium = str_replace('100x100', '200x200', $img_url); $large = str_replace('100x100', '400x400', $img_url); $data['images']['large'][] = $large; $data['images']['medium'][] = $medium; $data['images']['small'][] = $small; $data['images']['very_small'][] = $very_small; break; } } } else { continue; } } if (!isset($data['images'])) { $images = $dom->getElementsBytagName("meta"); foreach ($images as $img) { if (isset($img->tagName) && $img->tagName == "meta" && $img->getAttribute("name") == "og_image") { $img_url = $img->getAttribute("content"); $medium = $img_url; $very_small = str_replace('200x200', '100x100', $img_url); $small = str_replace('200x200', '125x125', $img_url); $large = str_replace('200x200', '400x400', $img_url); $data['images']['large'][] = $large; $data['images']['medium'][] = $medium; $data['images']['small'][] = $small; $data['images']['very_small'][] = $very_small; break; } else { continue; } } } return $data; }
/** * Replace labels shown in list view with icons (if found) * * @param string $data Data * @param string $view List/details * @param string $tmpl Template * * @since 3.0 - icon_folder is a bool - search through template folders for icons * * @return string data */ protected function replaceWithIcons($data, $view = 'list', $tmpl = null) { if ($data == '') { $this->iconsSet = false; return $data; } $params = $this->getParams(); $listModel = $this->getListModel(); $iconFile = (string) $params->get('icon_file', ''); if ((int) $params->get('icon_folder', 0) === 0 && $iconFile === '') { $this->iconsSet = false; return $data; } if (in_array($listModel->getOutPutFormat(), array('csv', 'rss'))) { $this->iconsSet = false; return $data; } $cleanData = empty($iconFile) ? FabrikString::clean(strip_tags($data)) : $iconFile; $cleanDatas = array($this->getElement()->name . '_' . $cleanData, $cleanData); $opts = array('forceImage' => true); //If subdir is set prepend file name with subdirectory (so first search through [template folders]/subdir for icons, e.g. images/subdir) $iconSubDir = $params->get('icon_subdir', ''); if ($iconSubDir != '') { $iconSubDir = rtrim($iconSubDir, '/') . '/'; $iconSubDir = ltrim($iconSubDir, '/'); array_unshift($cleanDatas, $iconSubDir . $cleanData); //search subdir first } foreach ($cleanDatas as $cleanData) { foreach ($this->imageExtensions as $ex) { $img = FabrikHelperHTML::image($cleanData . '.' . $ex, $view, $tmpl, array(), false, $opts); if ($img !== '') { $this->iconsSet = true; $opts = new stdClass(); $opts->position = 'top'; $opts = json_encode($opts); $data = '<span>' . $data . '</span>'; // See if data has an <a> tag if (class_exists('DOMDocument')) { $html = new DOMDocument(); /** * The loadXML() chokes if data has & in it. But we can't htmlspecialchar() it, as that removes * the HTML markup we're looking for. So we need to ONLY change &'s which aren't already part of * any HTML entities which may be in the data. So use a negative lookahead regex, which finds & followed * by anything except non-space the ;. Then after doing the loadXML, we have to turn the &s back in * to &, to avoid double encoding 'cos we're going to do an htmpsepecialchars() on $data in a few lines. */ $data = preg_replace('/&(?!\\S+;)/', '&', $data); $html->loadXML($data); $data = str_replace('&', '&', $data); $as = $html->getElementsBytagName('a'); } if ($params->get('icon_hovertext', true)) { $aHref = '#'; $target = ''; if (class_exists('DOMDocument') && $as->length) { // Data already has an <a href="foo"> lets get that for use in hover text $a = $as->item(0); $aHref = $a->getAttribute('href'); $target = $a->getAttribute('target'); $target = 'target="' . $target . '"'; } $data = htmlspecialchars($data, ENT_QUOTES); $img = '<a class="fabrikTip" ' . $target . ' href="' . $aHref . '" opts=\'' . $opts . '\' title="' . $data . '">' . $img . '</a>'; } elseif (!empty($iconFile)) { /** * $$$ hugh - kind of a hack, but ... if this is an upload element, it may already be a link, and * we'll need to replace the text in the link with the image * After ages dicking around with a regex to do this, decided to use DOMDocument instead! */ if (class_exists('DOMDocument') && $as->length) { $img = $html->createElement('img'); $src = FabrikHelperHTML::image($cleanData . '.' . $ex, $view, $tmpl, array(), true, array('forceImage' => true)); $img->setAttribute('src', $src); $as->item(0)->nodeValue = ''; $as->item(0)->appendChild($img); return $html->saveHTML(); } } return $img; } } } return $data; }
/** * Replace labels shown in table view with icons (if found) * * @param string $data data * @param string $view list/details * @param string $tmpl template * * @since 3.0 - icon_folder is a bool - search through template folders for icons * * @return string data */ protected function _replaceWithIcons($data, $view = 'list', $tmpl = null) { if ($data == '') { $this->iconsSet = false; return $data; } $params = $this->getParams(); if ((int) $params->get('icon_folder', 0) === 0) { $this->iconsSet = false; return $data; } $listModel = $this->getListModel(); if (in_array($listModel->getOutPutFormat(), array('csv', 'rss'))) { $this->iconsSet = false; return $data; } /** * Jaanus added this and following if/else; sometimes we need permanent image * (e.g logo of the website where the link always points, like Wikipedia's W) */ $iconfile = $params->get('icon_file', ''); $cleanData = $iconfile === '' ? FabrikString::clean(strip_tags($data)) : $iconfile; foreach ($this->_imageExtensions as $ex) { $f = JPath::clean($cleanData . '.' . $ex); $img = FabrikHelperHTML::image($cleanData . '.' . $ex, $view, $tmpl); if ($img !== '') { $this->iconsSet = true; $opts = new stdClass(); $opts->position = 'top'; $opts = json_encode($opts); $data = '<span>' . $data . '</span>'; if ($params->get('icon_hovertext', true)) { $data = htmlspecialchars($data, ENT_QUOTES); $img = '<a class="fabrikTip" href="#" opts=\'' . $opts . '\' title="' . $data . '">' . $img . '</a>'; } elseif (!empty($iconfile)) { /** * $$$ hugh - kind of a hack, but ... if this is an upload element, it may already be a link, and * we'll need to replace the text in the link with the image * After ages dicking around with a regex to do this, decided to use DOMDocument instead! */ $html = new DOMDocument(); $html->loadXML($data); $as = $html->getElementsBytagName('a'); if ($as->length) { $img = $html->createElement('img'); $img->setAttribute('src', FabrikHelperHTML::image($cleanData . '.' . $ex, $view, $tmpl, array(), true)); $as->item(0)->nodeValue = ''; $as->item(0)->appendChild($img); return $html->saveHTML(); } } return $img; } } $this->iconsSet = false; return $data; }
/** * Replace labels shown in list view with icons (if found) * * @param string $data Data * @param string $view List/details * @param string $tmpl Template * * @since 3.0 - icon_folder is a bool - search through template folders for icons * * @return string data */ protected function replaceWithIcons($data, $view = 'list', $tmpl = null) { if ($data == '') { $this->iconsSet = false; return $data; } $params = $this->getParams(); $listModel = $this->getListModel(); $iconFile = (string) $params->get('icon_file', ''); if ((int) $params->get('icon_folder', 0) === 0 && $iconFile === '') { $this->iconsSet = false; return $data; } if (in_array($listModel->getOutPutFormat(), array('csv', 'rss'))) { $this->iconsSet = false; return $data; } $cleanData = empty($iconFile) ? FabrikString::clean(strip_tags($data)) : $iconFile; $cleanDatas = array($this->getElement()->name . '_' . $cleanData, $cleanData); $opts = array('forceImage' => true); foreach ($cleanDatas as $cleanData) { foreach ($this->imageExtensions as $ex) { $f = JPath::clean($cleanData . '.' . $ex); $img = FabrikHelperHTML::image($cleanData . '.' . $ex, $view, $tmpl, array(), false, $opts); if ($img !== '') { $this->iconsSet = true; $opts = new stdClass(); $opts->position = 'top'; $opts = json_encode($opts); $data = '<span>' . $data . '</span>'; // See if data has an <a> tag if (class_exists('DOMDocument')) { $html = new DOMDocument(); $html->loadXML($data); $as = $html->getElementsBytagName('a'); } if ($params->get('icon_hovertext', true)) { $ahref = '#'; $target = ''; if (class_exists('DOMDocument') && $as->length) { // Data already has an <a href="foo"> lets get that for use in hover text $a = $as->item(0); $ahref = $a->getAttribute('href'); $target = $a->getAttribute('target'); $target = 'target="' . $target . '"'; } $data = htmlspecialchars($data, ENT_QUOTES); $img = '<a class="fabrikTip" ' . $target . ' href="' . $ahref . '" opts=\'' . $opts . '\' title="' . $data . '">' . $img . '</a>'; } elseif (!empty($iconFile)) { /** * $$$ hugh - kind of a hack, but ... if this is an upload element, it may already be a link, and * we'll need to replace the text in the link with the image * After ages dicking around with a regex to do this, decided to use DOMDocument instead! */ if (class_exists('DOMDocument') && $as->length) { $img = $html->createElement('img'); $img->setAttribute('src', FabrikHelperHTML::image($cleanData . '.' . $ex, $view, $tmpl, array(), true)); $as->item(0)->nodeValue = ''; $as->item(0)->appendChild($img); return $html->saveHTML(); } } return $img; } } } return $data; }