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..621c2dd 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 zoonru/z-microdata-php +``` + 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); @@ -23,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/composer.json b/composer.json index 397ad1b..2bee385 100644 --- a/composer.json +++ b/composer.json @@ -1,14 +1,10 @@ { - "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" - } + "license": "MIT" } 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..de36b9a 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. @@ -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. 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 @@ getAttribute('content')) { return $this->getAttribute('content'); } else { - return $this->textContent; + $text = ''; + foreach ($this->childNodes as $node) { + $text .= $node->textContent . ' '; + } + return trim($text); } } } diff --git a/tests/data/itemtype.html b/tests/data/itemtype.html deleted file mode 100644 index d3606e5..0000000 --- a/tests/data/itemtype.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - 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)); - } -}