From 571f77d86d676ab373f25bec6893542eca18f2ad Mon Sep 17 00:00:00 2001 From: sergkash7 <55360924+sergkash7@users.noreply.github.com> Date: Wed, 25 Mar 2020 10:03:34 +0300 Subject: [PATCH 1/6] Update composer.json --- composer.json | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 397ad1b..37db9aa 100644 --- a/composer.json +++ b/composer.json @@ -1,14 +1,11 @@ { - "name": "linclark/microdata-php", + "name": "zoonru/z-microdata-php", "description": "Extracts microdata from HTML using PHP.", "autoload": { "psr-4": { - "linclark\\MicrodataPHP\\": ["src/", "tests/src/"] + "Zoon\\ZMicrodataPHP\\": "src/" } }, "license": "MIT", - "minimum-stability": "dev", - "require-dev": { - "phpunit/phpunit": "4.1.x-dev" - } + "minimum-stability": "dev" } From 36bd40ddd14b744eae24e8c07a12ae61c5687f73 Mon Sep 17 00:00:00 2001 From: sergkash Date: Wed, 25 Mar 2020 10:13:56 +0300 Subject: [PATCH 2/6] Changed namespace --- .gitignore | 1 + .travis.yml | 10 ---- README.md | 8 ++- phpunit.xml.dist | 10 ---- src/MicrodataPhp.php | 2 +- src/MicrodataPhpDOMDocument.php | 2 +- src/MicrodataPhpDOMElement.php | 2 +- tests/data/itemtype.html | 10 ---- tests/data/nested_item.html | 21 ------- tests/data/person.html | 32 ----------- tests/data/recipe.html | 48 ---------------- tests/data/recipeItempropContent.html | 59 ------------------- tests/src/MicrodataPhpTest.php | 83 --------------------------- 13 files changed, 10 insertions(+), 278 deletions(-) delete mode 100644 .travis.yml delete mode 100644 phpunit.xml.dist delete mode 100644 tests/data/itemtype.html delete mode 100644 tests/data/nested_item.html delete mode 100644 tests/data/person.html delete mode 100644 tests/data/recipe.html delete mode 100644 tests/data/recipeItempropContent.html delete mode 100644 tests/src/MicrodataPhpTest.php diff --git a/.gitignore b/.gitignore index 5708e16..6a78056 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ composer.lock vendor/* +.idea/* diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 893a453..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -language: php -php: - - 5.5 - - 5.4 - - 5.3 - -before_script: - - composer --prefer-source --dev install - -script: phpunit --coverage-text diff --git a/README.md b/README.md index 50f859c..55c8210 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ -MicrodataPHP [![Build Status](https://travis-ci.org/linclark/MicrodataPHP.svg?branch=2.0.x)](https://travis-ci.org/linclark/MicrodataPHP) +ZMicrodataPHP (forked) ============ +``` +composer require zoon +``` + Microdata is a syntax for embedding machine-readable metadata in HTML. MicrodataPHP is a PHP library for extracting microdata from HTML documents. It @@ -11,7 +15,7 @@ Example use: ``` require 'vendor/autoload.php'; -use linclark\MicrodataPHP\MicrodataPhp; +use Zoon\ZMicrodataPHP\MicrodataPhp; $url = 'http://example.com'; $md = new MicrodataPhp($url); diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 32bb2c7..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - ./tests - - - - diff --git a/src/MicrodataPhp.php b/src/MicrodataPhp.php index 1f83aae..efc3fc0 100644 --- a/src/MicrodataPhp.php +++ b/src/MicrodataPhp.php @@ -10,7 +10,7 @@ * Copyright (c) 2009-2011 Philip Jägenstedt */ -namespace linclark\MicrodataPHP; +namespace Zoon\ZMicrodataPHP; /** * Extracts microdata from HTML. diff --git a/src/MicrodataPhpDOMDocument.php b/src/MicrodataPhpDOMDocument.php index 094c7ae..26d63d1 100644 --- a/src/MicrodataPhpDOMDocument.php +++ b/src/MicrodataPhpDOMDocument.php @@ -1,6 +1,6 @@ - - - Test itemtype - - -
-
- - diff --git a/tests/data/nested_item.html b/tests/data/nested_item.html deleted file mode 100644 index 94d9946..0000000 --- a/tests/data/nested_item.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - Test itemtype - - -
-
-
-
test
-
-
- Addresse: - Rheinstraße 66, - 55116 - Mainz, - Germany -
-
-
- \ No newline at end of file diff --git a/tests/data/person.html b/tests/data/person.html deleted file mode 100644 index 0573422..0000000 --- a/tests/data/person.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - An Example Person - - - -
- Jane Doe - - Professor - -
- - 20341 Whitworth Institute - 405 N. Whitworth - - Seattle, - WA - 98052 -
- (425) 123-4567 - jane-doe@xyz.edu - Jane's home page: - - Graduate students: - Alice Jones - Bob Smith -
- - - diff --git a/tests/data/recipe.html b/tests/data/recipe.html deleted file mode 100644 index 717e7c7..0000000 --- a/tests/data/recipe.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - - recipe test - - -
- Mom's World Famous Banana Bread - By , - - May 8, 2009 - Banana bread on a plate - This classic banana bread recipe comes - from my mom -- the walnuts add a nice texture and flavor to the banana - bread. - Prep Time: - - 15 minutes - Cook time: - - 1 hour - Yield: 1 loaf - -
- Nutrition facts: - 240 calories, - 9 grams fat -
- Ingredients: - - 3 or 4 ripe bananas, smashed - - 1 egg - - 3/4 cup of sugar - ... - Instructions: - - Preheat the oven to 350 degrees. Mix in the ingredients in a bowl. Add - the flour last. Pour the mixture into a loaf pan and bake for one hour. - - 140 comments: - - From Janel, May 5 -- thank you, great recipe! - ... -
- - diff --git a/tests/data/recipeItempropContent.html b/tests/data/recipeItempropContent.html deleted file mode 100644 index 4c11d98..0000000 --- a/tests/data/recipeItempropContent.html +++ /dev/null @@ -1,59 +0,0 @@ - - - - - recipe itemprop content - - - - - - - - recipe test - - -
- Mom's World Famous Banana Bread - By , - - May 8, 2009 - Banana bread on a plate - This classic banana bread recipe comes - from my mom -- the walnuts add a nice texture and flavor to the banana - bread. - Prep Time: - 1 hour, 10 minutes - Cook time: - 15 minutes - - Yield: 1 loaf - -
- Nutrition facts: - 240 calories, - 9 grams fat -
- Ingredients: - - 3 or 4 ripe bananas, smashed - - 1 egg - - 3/4 cup of sugar - ... - Instructions: - - Preheat the oven to 350 degrees. Mix in the ingredients in a bowl. Add - the flour last. Pour the mixture into a loaf pan and bake for one hour. - - 140 comments: - - From Janel, May 5 -- thank you, great recipe! - ... -
- - - - - - \ No newline at end of file diff --git a/tests/src/MicrodataPhpTest.php b/tests/src/MicrodataPhpTest.php deleted file mode 100644 index 6402174..0000000 --- a/tests/src/MicrodataPhpTest.php +++ /dev/null @@ -1,83 +0,0 @@ -getConfig('person.html'); - $microdata = new MicrodataPhp($config); - $data = $microdata->obj(); - - $name = $data->items[0]->properties['name'][0]; - - $this->assertEquals($name, "Jane Doe", "The name matches."); - } - - public function testItemtype() { - $config = $this->getConfig('itemtype.html'); - $microdata = new MicrodataPhp($config); - $data = $microdata->obj(); - - $type = $data->items[0]->type; - - $this->assertCount(2, $type, 'Incorrect number of itemtypes found.'); - $this->assertTrue(in_array('http://schema.org/ComedyEvent', $type) && in_array('http://schema.org/DanceEvent', $type), 'Incorrect types extracted.'); - } - - public function testNestedItem() { - $config = $this->getConfig('nested_item.html'); - $microdata = new MicrodataPhp($config); - $data = $microdata->obj(); - - $address = $data->items[0]->properties['location'][0]->properties['address'][0]; - - $this->assertTrue(is_object($address), 'Nested item should be returned as an object.'); - $this->assertEquals($address->properties['addressCountry'][0], "Germany", 'addressCountry property of nested item should be Germany.'); - } - - /** - * test recipe prep time - */ - public function testRecipePrepTimeType() { - $config = $this->getConfig('recipe.html'); - $microdata = new MicrodataPhp($config); - $data = $microdata->obj(); - - $this->assertEquals("PT15M", $data->items[0]->properties['prepTime'][0], 'recipe prepTime should be PT15M'); - } - - /** - * test recipe prep time - */ - public function testRecipePrepTimeContentType() { - $config = $this->getConfig('recipeItempropContent.html'); - $microdata = new MicrodataPhp($config); - $data = $microdata->obj(); - - $this->assertEquals("PT1H10M", $data->items[0]->properties['prepTime'][0], 'recipe prepTime should be PT1H10M'); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testConstructorNoUrlOrHtml() { - $config = array(); - new MicrodataPhp($config); - } - - protected function getConfig($file) { - return array('html' => file_get_contents(__DIR__ . '/../data/' . $file)); - } -} From 272707a87f366e62ae81873e74f55978619187e9 Mon Sep 17 00:00:00 2001 From: sergkash7 <55360924+sergkash7@users.noreply.github.com> Date: Wed, 25 Mar 2020 10:25:54 +0300 Subject: [PATCH 3/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 55c8210..28903a7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ZMicrodataPHP (forked) ============ ``` -composer require zoon +composer require zoonru/z-microdata-php ``` Microdata is a syntax for embedding machine-readable metadata in HTML. From 15345acaa4bab90eb976d0503575c310f4aef053 Mon Sep 17 00:00:00 2001 From: sergkash7 <55360924+sergkash7@users.noreply.github.com> Date: Wed, 25 Mar 2020 10:33:50 +0300 Subject: [PATCH 4/6] Update composer.json --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 37db9aa..2bee385 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,5 @@ "Zoon\\ZMicrodataPHP\\": "src/" } }, - "license": "MIT", - "minimum-stability": "dev" + "license": "MIT" } From 4d9b235e8816b0e9728f5daae98cced6c22a7000 Mon Sep 17 00:00:00 2001 From: sergkash Date: Thu, 26 Mar 2020 11:10:07 +0300 Subject: [PATCH 5/6] Fixed class name --- README.md | 7 ------- src/MicrodataPhp.php | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 28903a7..621c2dd 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,3 @@ print $data->items[0]->properties['name'][0]; // Get a property of a nested item. print $data->items[0]->properties['hiringOrganization'][0]->properties['name'][0]; ``` - -Requirements -============ -- Autoloading (e.g. the autoloader provided by [Composer](https://getcomposer.org/)) -- PHP 5.3+ - -Check out the 1.x branch for older setups. diff --git a/src/MicrodataPhp.php b/src/MicrodataPhp.php index efc3fc0..de36b9a 100644 --- a/src/MicrodataPhp.php +++ b/src/MicrodataPhp.php @@ -40,8 +40,8 @@ public function __construct($config) { } $dom = new MicrodataPhpDOMDocument(); - $dom->registerNodeClass('DOMDocument', 'linclark\MicrodataPHP\MicrodataPhpDOMDocument'); - $dom->registerNodeClass('DOMElement', 'linclark\MicrodataPHP\MicrodataPhpDOMElement'); + $dom->registerNodeClass('DOMDocument', MicrodataPhpDOMDocument::class); + $dom->registerNodeClass('DOMElement', MicrodataPhpDOMElement::class); $dom->preserveWhiteSpace = false; // Prepare the DOM using either the URL or HTML string. From f255ebb80631a15e5c7e4c3356d7f0fb27da0eb2 Mon Sep 17 00:00:00 2001 From: Maxim Tiuriaev Date: Thu, 26 Mar 2020 13:29:56 +0300 Subject: [PATCH 6/6] =?UTF-8?q?MAIN-13745=20=D0=A4=D0=B8=D0=BA=D1=81=20?= =?UTF-8?q?=D1=81=D0=BA=D0=BB=D0=B5=D0=B8=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=B2=20=D1=80=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B2=D0=B5=D1=80=D1=81=D1=82?= =?UTF-8?q?=D0=BA=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MicrodataPhpDOMElement.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/MicrodataPhpDOMElement.php b/src/MicrodataPhpDOMElement.php index 95f019e..f3be717 100644 --- a/src/MicrodataPhpDOMElement.php +++ b/src/MicrodataPhpDOMElement.php @@ -148,7 +148,11 @@ public function itemValue() { if ($this->getAttribute('content')) { return $this->getAttribute('content'); } else { - return $this->textContent; + $text = ''; + foreach ($this->childNodes as $node) { + $text .= $node->textContent . ' '; + } + return trim($text); } } }