fix: escape generated feed tag values and remove new lines from public pages meta description

fixes #57, #46
This commit is contained in:
Yassine Doghri 2020-10-12 19:21:50 +00:00
parent 8053d3521b
commit 6238a43863
4 changed files with 49 additions and 26 deletions

View File

@ -65,13 +65,13 @@ class CategorySeeder extends Seeder
'id' => 6, 'id' => 6,
'code' => 'government', 'code' => 'government',
'apple_category' => 'Government', 'apple_category' => 'Government',
'google_category' => 'Government & Organizations', 'google_category' => 'Government & Organizations',
], ],
[ [
'parent_id' => 0, 'parent_id' => 0,
'id' => 7, 'id' => 7,
'code' => 'health_and_fitness', 'code' => 'health_and_fitness',
'apple_category' => 'Health & Fitness', 'apple_category' => 'Health & Fitness',
'google_category' => 'Health', 'google_category' => 'Health',
], ],
[ [
@ -85,15 +85,15 @@ class CategorySeeder extends Seeder
'parent_id' => 0, 'parent_id' => 0,
'id' => 9, 'id' => 9,
'code' => 'kids_and_family', 'code' => 'kids_and_family',
'apple_category' => 'Kids & Family', 'apple_category' => 'Kids & Family',
'google_category' => 'Kids & Family', 'google_category' => 'Kids & Family',
], ],
[ [
'parent_id' => 0, 'parent_id' => 0,
'id' => 10, 'id' => 10,
'code' => 'leisure', 'code' => 'leisure',
'apple_category' => 'Leisure', 'apple_category' => 'Leisure',
'google_category' => 'Games & Hobbies', 'google_category' => 'Games & Hobbies',
], ],
[ [
'parent_id' => 0, 'parent_id' => 0,
@ -107,35 +107,35 @@ class CategorySeeder extends Seeder
'id' => 12, 'id' => 12,
'code' => 'news', 'code' => 'news',
'apple_category' => 'News', 'apple_category' => 'News',
'google_category' => 'News & Politics', 'google_category' => 'News & Politics',
], ],
[ [
'parent_id' => 0, 'parent_id' => 0,
'id' => 13, 'id' => 13,
'code' => 'religion_and_spirituality', 'code' => 'religion_and_spirituality',
'apple_category' => 'Religion & Spirituality', 'apple_category' => 'Religion & Spirituality',
'google_category' => 'Religion & Spirituality', 'google_category' => 'Religion & Spirituality',
], ],
[ [
'parent_id' => 0, 'parent_id' => 0,
'id' => 14, 'id' => 14,
'code' => 'science', 'code' => 'science',
'apple_category' => 'Science', 'apple_category' => 'Science',
'google_category' => 'Science & Medicine', 'google_category' => 'Science & Medicine',
], ],
[ [
'parent_id' => 0, 'parent_id' => 0,
'id' => 15, 'id' => 15,
'code' => 'society_and_culture', 'code' => 'society_and_culture',
'apple_category' => 'Society & Culture', 'apple_category' => 'Society & Culture',
'google_category' => 'Society & Culture', 'google_category' => 'Society & Culture',
], ],
[ [
'parent_id' => 0, 'parent_id' => 0,
'id' => 16, 'id' => 16,
'code' => 'sports', 'code' => 'sports',
'apple_category' => 'Sports', 'apple_category' => 'Sports',
'google_category' => 'Sports & Recreation', 'google_category' => 'Sports & Recreation',
], ],
[ [
'parent_id' => 0, 'parent_id' => 0,
@ -155,8 +155,8 @@ class CategorySeeder extends Seeder
'parent_id' => 0, 'parent_id' => 0,
'id' => 19, 'id' => 19,
'code' => 'tv_and_film', 'code' => 'tv_and_film',
'apple_category' => 'TV & Film', 'apple_category' => 'TV & Film',
'google_category' => 'TV & Film', 'google_category' => 'TV & Film',
], ],
[ [
'parent_id' => 1, 'parent_id' => 1,
@ -176,7 +176,7 @@ class CategorySeeder extends Seeder
'parent_id' => 1, 'parent_id' => 1,
'id' => 22, 'id' => 22,
'code' => 'fashion_and_beauty', 'code' => 'fashion_and_beauty',
'apple_category' => 'Fashion & Beauty', 'apple_category' => 'Fashion & Beauty',
'google_category' => '', 'google_category' => '',
], ],
[ [
@ -372,7 +372,7 @@ class CategorySeeder extends Seeder
'parent_id' => 9, 'parent_id' => 9,
'id' => 50, 'id' => 50,
'code' => 'pets_and_animals', 'code' => 'pets_and_animals',
'apple_category' => 'Pets & Animals', 'apple_category' => 'Pets & Animals',
'google_category' => '', 'google_category' => '',
], ],
[ [
@ -386,7 +386,7 @@ class CategorySeeder extends Seeder
'parent_id' => 10, 'parent_id' => 10,
'id' => 52, 'id' => 52,
'code' => 'animation_and_manga', 'code' => 'animation_and_manga',
'apple_category' => 'Animation & Manga', 'apple_category' => 'Animation & Manga',
'google_category' => '', 'google_category' => '',
], ],
[ [
@ -428,7 +428,7 @@ class CategorySeeder extends Seeder
'parent_id' => 10, 'parent_id' => 10,
'id' => 58, 'id' => 58,
'code' => 'home_and_garden', 'code' => 'home_and_garden',
'apple_category' => 'Home & Garden', 'apple_category' => 'Home & Garden',
'google_category' => '', 'google_category' => '',
], ],
[ [
@ -645,7 +645,7 @@ class CategorySeeder extends Seeder
'parent_id' => 15, 'parent_id' => 15,
'id' => 89, 'id' => 89,
'code' => 'places_and_travel', 'code' => 'places_and_travel',
'apple_category' => 'Places & Travel', 'apple_category' => 'Places & Travel',
'google_category' => '', 'google_category' => '',
], ],
[ [

View File

@ -14,12 +14,14 @@ class SimpleRSSElement extends SimpleXMLElement
{ {
/** /**
* Adds a child with $value inside CDATA * Adds a child with $value inside CDATA
* @param unknown $name *
* @param unknown $value * @param string $name The name of the child element to add.
* @param string $value [optional] If specified, the value of the child element.
* @param string $namespace [optional] If specified, the namespace to which the child element belongs.
*/ */
public function addChildWithCDATA($name, $value = null, $namespace = null) public function addChildWithCDATA($name, $value = null, $namespace = null)
{ {
$new_child = $this->addChild($name, null, $namespace); $new_child = parent::addChild($name, null, $namespace);
if ($new_child !== null) { if ($new_child !== null) {
$node = dom_import_simplexml($new_child); $node = dom_import_simplexml($new_child);
@ -29,4 +31,25 @@ class SimpleRSSElement extends SimpleXMLElement
return $new_child; return $new_child;
} }
/**
* Adds a child element to the XML node with escaped $value if specified.
* Override of addChild method as SimpleXMLElement's addChild method doesn't escape ampersand
*
* @param string $name The name of the child element to add.
* @param string $value [optional] If specified, the value of the child element.
* @param string $namespace [optional] If specified, the namespace to which the child element belongs.
*/
public function addChild($name, $value = null, $namespace = null)
{
$new_child = parent::addChild($name, null, $namespace);
if ($new_child !== null) {
$node = dom_import_simplexml($new_child);
$no = $node->ownerDocument;
$node->appendChild($no->createTextNode(esc($value)));
}
return $new_child;
}
} }

View File

@ -5,8 +5,8 @@
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<title><?= $episode->title ?></title> <title><?= $episode->title ?></title>
<meta name="description" content="<?= strip_tags( <meta name="description" content="<?= trim(
$episode->description_html preg_replace('/\s+/', ' ', strip_tags($episode->description_html))
) ?>"/> ) ?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="shortcut icon" type="image/png" href="/favicon.ico" /> <link rel="shortcut icon" type="image/png" href="/favicon.ico" />

View File

@ -6,8 +6,8 @@
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<title><?= $podcast->title ?></title> <title><?= $podcast->title ?></title>
<meta name="description" content="<?= strip_tags( <meta name="description" content="<?= trim(
$podcast->description_html preg_replace('/\s+/', ' ', strip_tags($podcast->description_html))
) ?>"/> ) ?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="shortcut icon" type="image/png" href="/favicon.ico" /> <link rel="shortcut icon" type="image/png" href="/favicon.ico" />