From c2ba6edbfc1436558054ba69d1afeb4ea7f44fa0 Mon Sep 17 00:00:00 2001 From: Manuel Dalla Lana Date: Mon, 21 Nov 2016 16:16:48 +0100 Subject: [PATCH 1/3] Set max-age to 24 hours for downloaded taxonomy file --- src/LukeSnowden/GoogleShoppingFeed/Feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LukeSnowden/GoogleShoppingFeed/Feed.php b/src/LukeSnowden/GoogleShoppingFeed/Feed.php index 2558228..e72e497 100644 --- a/src/LukeSnowden/GoogleShoppingFeed/Feed.php +++ b/src/LukeSnowden/GoogleShoppingFeed/Feed.php @@ -186,7 +186,7 @@ private function addItemsToFeed() { public function categories() { $cache = new Cache; $cache->setCacheDirectory($this->cacheDir); - $data = $cache->getOrCreate('google-feed-taxonomy.txt', array( 'max-age' => '860400' ), function() { + $data = $cache->getOrCreate('google-feed-taxonomy.txt', array( 'max-age' => '86400' ), function() { return file_get_contents("http://www.google.com/basepages/producttype/taxonomy.en-GB.txt"); }); return explode( "\n", trim($data) ); From 917577667fa2e76dd966bc18fc95e7cadc2e9920 Mon Sep 17 00:00:00 2001 From: Luke Snowden Date: Mon, 21 Nov 2016 15:49:15 +0000 Subject: [PATCH 2/3] update --- src/LukeSnowden/GoogleShoppingFeed/Feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LukeSnowden/GoogleShoppingFeed/Feed.php b/src/LukeSnowden/GoogleShoppingFeed/Feed.php index e72e497..f4dbfe3 100644 --- a/src/LukeSnowden/GoogleShoppingFeed/Feed.php +++ b/src/LukeSnowden/GoogleShoppingFeed/Feed.php @@ -187,7 +187,7 @@ public function categories() { $cache = new Cache; $cache->setCacheDirectory($this->cacheDir); $data = $cache->getOrCreate('google-feed-taxonomy.txt', array( 'max-age' => '86400' ), function() { - return file_get_contents("http://www.google.com/basepages/producttype/taxonomy.en-GB.txt"); + return file_get_contents("http://www.google.com/basepages/producttype/taxonomy.en-GB.txt"); }); return explode( "\n", trim($data) ); } From bdc904b1acb8514a1924f2440cbccbda216e757f Mon Sep 17 00:00:00 2001 From: Luke Snowden Date: Mon, 21 Nov 2016 15:50:56 +0000 Subject: [PATCH 3/3] update --- src/LukeSnowden/GoogleShoppingFeed/Feed.php | 234 +------------------- 1 file changed, 1 insertion(+), 233 deletions(-) diff --git a/src/LukeSnowden/GoogleShoppingFeed/Feed.php b/src/LukeSnowden/GoogleShoppingFeed/Feed.php index 3d27b99..a74f1df 100644 --- a/src/LukeSnowden/GoogleShoppingFeed/Feed.php +++ b/src/LukeSnowden/GoogleShoppingFeed/Feed.php @@ -6,237 +6,6 @@ use LukeSnowden\GoogleShoppingFeed\Item; use Gregwar\Cache\Cache; -<<<<<<< HEAD -class Feed { - - /** - * [$namespace description] - * @var string - */ - protected $namespace = 'http://base.google.com/ns/1.0'; - - /** - * [$version description] - * @var string - */ - protected $version = '2.0'; - - /** - * [$items Stores the list of items for the feed] - * @var array - */ - private $items = array(); - - /** - * [$channelCreated description] - * @var boolean - */ - private $channelCreated = false; - - /** - * [$feed The base for the feed] - * @var null - */ - private $feed = null; - - /** - * [$title description] - * @var string - */ - private $title = ''; - - /** - * [$cacheDir description] - * @var string - */ - private $cacheDir = 'cache'; - - /** - * [$description description] - * @var string - */ - private $description = ''; - - /** - * [$link description] - * @var string - */ - private $link = ''; - - /** - * [__construct description] - */ - public function __construct() { - $this->feed = new SimpleXMLElement( '' ); - } - - /** - * [title description] - * @param [type] $string [description] - * @return [type] [description] - */ - public function title( $string ) { - $this->title = (string)$string; - } - - /** - * [description description] - * @param [type] $string [description] - * @return [type] [description] - */ - public function description( $string ) { - $this->description = (string)$string; - } - - /** - * [link description] - * @param [type] $string [description] - * @return [type] [description] - */ - public function link( $string ) { - $this->link = (string)$string; - } - - /** - * [channel description] - * @return [type] [description] - */ - private function channel() { - if( ! $this->channelCreated ) { - $channel = $this->feed->addChild('channel'); - $channel->addChild( 'title', $this->title ); - $channel->addChild( 'link', $this->link ); - $channel->addChild( 'description', $this->description ); - $this->channelCreated = true; - } - } - - /** - * [createItem description] - * @return [type] [description] - */ - public function createItem() { - $this->channel(); - $item = new Item; - $index = 'index_' . md5( microtime() ); - $this->items[$index] = $item; - $item->setIndex( $index ); - return $item; - } - - /** - * [removeItemByIndex description] - * @param [type] $index [description] - * @return [type] [description] - */ - public function removeItemByIndex( $index ) { - unset( $this->items[$index] ); - } - - /** - * [standardiseSizeVarient description] - * @param [type] $value [description] - * @return [type] [description] - */ - public function standardiseSizeVarient( $value ) { - return $value; - } - - /** - * [standardiseSizeVarient description] - * @param [type] $value [description] - * @return [type] [description] - */ - public function standardiseColourVarient( $value ) { - return $value; - } - - /** - * [isVariant description] - * @param [type] $group [description] - * @return boolean [description] - */ - public function isVariant( $group ) { - if( preg_match( "#^\s*colou?rs?\s*$#is", trim( $group ) ) ) return 'color'; - if( preg_match( "#^\s*sizes?\s*$#is", trim( $group ) ) ) return 'size'; - if( preg_match( "#^\s*materials?\s*$#is", trim( $group ) ) ) return 'material'; - return false; - } - - /** - * [addItemsToFeed description] - */ - private function addItemsToFeed() { - foreach( $this->items as $item ) { - $feedItemNode = $this->feed->channel->addChild('item'); - foreach( $item->nodes() as $itemNode ) { - if( is_array( $itemNode ) ) { - foreach( $itemNode as $node ) { - $feedItemNode->addChild( $node->get('name'), $node->get('value'), $node->get('_namespace')); - } - } else { - $itemNode->attachNodeTo( $feedItemNode ); - } - } - } - } - - /** - * [categories description] - * @param [type] $selected [description] - * @return [type] [description] - */ - public function categories() { - $cache = new Cache; - $cache->setCacheDirectory($this->cacheDir); - $data = $cache->getOrCreate('google-feed-taxonomy.txt', array( 'max-age' => '86400' ), function() { - return file_get_contents("http://www.google.com/basepages/producttype/taxonomy.en-GB.txt"); - }); - return explode( "\n", trim($data) ); - } - - /** - * [categoriesAsSelect description] - * @param string $selected [description] - * @return [type] [description] - */ - public function categoriesAsSelect( $selected = '' ) { - $categories = $this->categories(); - unset($categories[0]); - $select = ''; - return $select; - } - - /** - * [asRss description] - * @return [type] [description] - */ - public function asRss( $output = false ) { - ob_end_clean(); - $this->addItemsToFeed(); - $data = html_entity_decode( $this->feed->asXml() ); - if( $output ) { - header('Content-Type: application/xml; charset=utf-8'); - die( $data ); - } - return $data; - } - - /** - * [removeLastItem description] - * @return [type] [description] - */ - public function removeLastItem(){ - array_pop( $this->items ); - } - -} -======= class Feed { @@ -425,7 +194,7 @@ public function categories() { $cache = new Cache; $cache->setCacheDirectory($this->cacheDir); - $data = $cache->getOrCreate('google-feed-taxonomy.txt', array( 'max-age' => '860400' ), function () { + $data = $cache->getOrCreate('google-feed-taxonomy.txt', array( 'max-age' => '86400' ), function () { return file_get_contents("http://www.google.com/basepages/producttype/taxonomy.en-GB.txt"); }); return explode("\n", trim($data)); @@ -474,4 +243,3 @@ public function removeLastItem() array_pop($this->items); } } ->>>>>>> master