From c3271298eb8acc3cea3d66befcbfc9974e7dd3e2 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Tue, 11 Jul 2017 23:53:53 +0200 Subject: [PATCH] homepage, twitter card, improves --- .../admin/controllers/settings-advanced.php | 7 +- bl-kernel/admin/views/settings-advanced.php | 12 +++ bl-kernel/boot/rules/69.pages.php | 37 ++++++--- bl-kernel/dbsite.class.php | 8 +- bl-kernel/functions.php | 26 ++++++ bl-kernel/page.class.php | 8 +- bl-kernel/url.class.php | 5 ++ bl-plugins/twitter-card/languages/bg_BG.json | 7 ++ bl-plugins/twitter-card/languages/de_CH.json | 7 ++ bl-plugins/twitter-card/languages/de_DE.json | 7 ++ bl-plugins/twitter-card/languages/en_US.json | 7 ++ bl-plugins/twitter-card/languages/es_AR.json | 7 ++ bl-plugins/twitter-card/languages/fr_FR.json | 7 ++ bl-plugins/twitter-card/languages/ja_JP.json | 7 ++ bl-plugins/twitter-card/languages/nl_NL.json | 7 ++ bl-plugins/twitter-card/languages/pl_PL.json | 7 ++ bl-plugins/twitter-card/languages/ru_RU.json | 7 ++ bl-plugins/twitter-card/languages/uk_UA.json | 7 ++ bl-plugins/twitter-card/languages/zh_TW.json | 7 ++ bl-plugins/twitter-card/metadata.json | 10 +++ bl-plugins/twitter-card/plugin.php | 81 +++++++++++++++++++ bl-themes/docs/index.php | 19 ++--- bl-themes/docs/init.php | 2 + bl-themes/docs/php/home.php | 47 ----------- bl-themes/docs/php/page.php | 41 +++++----- bl-themes/docs/php/post.php | 31 ------- 26 files changed, 288 insertions(+), 130 deletions(-) create mode 100644 bl-plugins/twitter-card/languages/bg_BG.json create mode 100644 bl-plugins/twitter-card/languages/de_CH.json create mode 100644 bl-plugins/twitter-card/languages/de_DE.json create mode 100644 bl-plugins/twitter-card/languages/en_US.json create mode 100644 bl-plugins/twitter-card/languages/es_AR.json create mode 100644 bl-plugins/twitter-card/languages/fr_FR.json create mode 100644 bl-plugins/twitter-card/languages/ja_JP.json create mode 100644 bl-plugins/twitter-card/languages/nl_NL.json create mode 100644 bl-plugins/twitter-card/languages/pl_PL.json create mode 100644 bl-plugins/twitter-card/languages/ru_RU.json create mode 100644 bl-plugins/twitter-card/languages/uk_UA.json create mode 100644 bl-plugins/twitter-card/languages/zh_TW.json create mode 100644 bl-plugins/twitter-card/metadata.json create mode 100644 bl-plugins/twitter-card/plugin.php delete mode 100644 bl-themes/docs/php/home.php delete mode 100644 bl-themes/docs/php/post.php diff --git a/bl-kernel/admin/controllers/settings-advanced.php b/bl-kernel/admin/controllers/settings-advanced.php index 55bc6dd9..fdcd4cb0 100644 --- a/bl-kernel/admin/controllers/settings-advanced.php +++ b/bl-kernel/admin/controllers/settings-advanced.php @@ -83,5 +83,10 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) // ============================================================================ // Main after POST // ============================================================================ +$allPublishedPages = buildAllpages(false); - +// Homepage select options +$homepageOptions = array(); +foreach($allPublishedPages as $key=>$page) { + $homepageOptions[$key] = $page->title(); +} \ No newline at end of file diff --git a/bl-kernel/admin/views/settings-advanced.php b/bl-kernel/admin/views/settings-advanced.php index 3a4bcc70..481ae35b 100644 --- a/bl-kernel/admin/views/settings-advanced.php +++ b/bl-kernel/admin/views/settings-advanced.php @@ -28,6 +28,18 @@ HTML::formOpen(array('class'=>'uk-form-horizontal')); 'tip'=>$L->g('the-url-of-your-site') )); + HTML::legend(array('value'=>$L->g('Home page'))); + + HTML::formSelect(array( + 'name'=>'homepage', + 'label'=>$L->g('Default home page'), + 'options'=>$homepageOptions, + 'selected'=>$Site->homepage(), + 'class'=>'uk-width-1-3 uk-form-medium', + 'tip'=>'', + 'addEmptySpace'=>true + )); + HTML::legend(array('value'=>$L->g('Website or Blog'))); HTML::formSelect(array( diff --git a/bl-kernel/boot/rules/69.pages.php b/bl-kernel/boot/rules/69.pages.php index d81aed5e..66064cc2 100644 --- a/bl-kernel/boot/rules/69.pages.php +++ b/bl-kernel/boot/rules/69.pages.php @@ -4,27 +4,34 @@ // Variables // ============================================================================ -// Array with pages, each page is a Object Page +// Array with pages, each page is a Page Object $pages = array(); -// Page filtered by the user, is a Object Page +// Page filtered by the user, is a Page Object $page = $Page = false; // Array with pages order by parent -// This variable is initializade only when the site is order by position -// This is for not degradate the peromance on blogs +// This variable is initializade only when the site is order by position to not degradate the peromance on blogs /* -array( - PARENT => array(), // all parent pages - parentKey1 => array(), // all children of parentKey1 - parentKey2 => array(), // all children of parentKey2 - ... - parentKeyN => array(), // all children of parentKeyN -) + array( + PARENT => array(), // all parent pages + parentKey1 => array(), // all children of parentKey1 + parentKey2 => array(), // all children of parentKey2 + ... + parentKeyN => array(), // all children of parentKeyN + ) */ $pagesByParent = array(PARENT=>array()); -// Array with all published pages, the array is a key=>Page-object +// Array with pages, +/* + array( + pageKey1 => Page Object, + pageKey2 => Page Object, + ... + pageKeyN => Page Object, + ) +*/ $pagesByKey = array(); // ============================================================================ @@ -46,6 +53,12 @@ if( $dbPages->scheduler() ) { )); } +if( $Site->homepage() && $Url->whereAmI()==='home' ) { + $Url->setWhereAmI('page'); + $slug = $Site->homepage(); + $Url->setSlug($slug); +} + // Build specific page if( $Url->whereAmI()==='page' ) { // Build the page diff --git a/bl-kernel/dbsite.class.php b/bl-kernel/dbsite.class.php index e93d1b51..6f594723 100644 --- a/bl-kernel/dbsite.class.php +++ b/bl-kernel/dbsite.class.php @@ -280,10 +280,14 @@ class dbSite extends dbJSON return $short; } - // Returns the current homepage. + // Returns the current homepage, FALSE if not defined homepage public function homepage() { - return $this->getField('homepage'); + $homepage = $this->getField('homepage'); + if( empty($homepage) ) { + return false; + } + return $homepage; } // Set the locale. diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 6d12f623..5d3e4bc6 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -171,6 +171,32 @@ function buildPagesByParent($allPages=true) { } } +// Returns an Array with all pages existing on the system +// (boolean) $allPages, TRUE returns all pages with any status, FALSE all published pages +/* + array( + pageKey1 => Page object, + pageKey2 => Page object, + ... + pageKeyN => Page object, + ) +*/ +function buildAllpages($allPages=true) { + global $dbPages; + + $tmp = array(); + $keys = array_keys($dbPages->db); + foreach($keys as $pageKey) { + $page = buildPage($pageKey); + if($page!==false) { + if($allPages || $page->published()) { + $tmp[$page->key()] = $page; + } + } + } + return $tmp; +} + // Returns TRUE if the plugin is enabled, FALSE otherwise function pluginEnabled($pluginName) { global $plugins; diff --git a/bl-kernel/page.class.php b/bl-kernel/page.class.php index ee2fc267..25318fd2 100644 --- a/bl-kernel/page.class.php +++ b/bl-kernel/page.class.php @@ -392,10 +392,10 @@ class Page { // Returns the parent method output, if the page doesn't have a parent returns FALSE public function parentMethod($method) { - global $pages; - - if( isset($pages[$this->parentKey()]) ) { - return $pages[$this->parentKey()]->{$method}(); + $parentKey = $this->parentKey(); + if( $parentKey ) { + $page = buildPage($parentKey); + return $page->{$method}(); } return false; diff --git a/bl-kernel/url.class.php b/bl-kernel/url.class.php index bdaacaef..bb235065 100644 --- a/bl-kernel/url.class.php +++ b/bl-kernel/url.class.php @@ -81,6 +81,11 @@ class Url return $this->slug; } + public function setSlug($slug) + { + $this->slug = $slug; + } + public function activeFilter() { return $this->activeFilter; diff --git a/bl-plugins/twitter-card/languages/bg_BG.json b/bl-plugins/twitter-card/languages/bg_BG.json new file mode 100644 index 00000000..b8f89d08 --- /dev/null +++ b/bl-plugins/twitter-card/languages/bg_BG.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Open Graph", + "description": "Open Graph ви позволява да свържете вашето съдържание със социални мрежи." + } +} \ No newline at end of file diff --git a/bl-plugins/twitter-card/languages/de_CH.json b/bl-plugins/twitter-card/languages/de_CH.json new file mode 100644 index 00000000..d954200c --- /dev/null +++ b/bl-plugins/twitter-card/languages/de_CH.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Open Graph", + "description": "Plugin zur Verwendung des Open Graph Protocols." + } +} diff --git a/bl-plugins/twitter-card/languages/de_DE.json b/bl-plugins/twitter-card/languages/de_DE.json new file mode 100644 index 00000000..937d2e79 --- /dev/null +++ b/bl-plugins/twitter-card/languages/de_DE.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Open Graph", + "description": "Plugin zur Verwendung des Open Graph Protocols." + } +} \ No newline at end of file diff --git a/bl-plugins/twitter-card/languages/en_US.json b/bl-plugins/twitter-card/languages/en_US.json new file mode 100644 index 00000000..b30d887e --- /dev/null +++ b/bl-plugins/twitter-card/languages/en_US.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Twitter Card", + "description": "" + } +} \ No newline at end of file diff --git a/bl-plugins/twitter-card/languages/es_AR.json b/bl-plugins/twitter-card/languages/es_AR.json new file mode 100644 index 00000000..b154c459 --- /dev/null +++ b/bl-plugins/twitter-card/languages/es_AR.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Open Graph", + "description": "Mejora las publicaciones en las redes sociales con este plugin." + } +} \ No newline at end of file diff --git a/bl-plugins/twitter-card/languages/fr_FR.json b/bl-plugins/twitter-card/languages/fr_FR.json new file mode 100644 index 00000000..adcade7d --- /dev/null +++ b/bl-plugins/twitter-card/languages/fr_FR.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Open Graph", + "description": "Permets à n’importe quelle page web de devenir l’objet enrichi d’un graphe social. Par exemple, il est utilisé sur Facebook pour permettre à une page web de bénéficier des mêmes fonctionnalités que n’importe quel autre objet sur Facebook." + } +} \ No newline at end of file diff --git a/bl-plugins/twitter-card/languages/ja_JP.json b/bl-plugins/twitter-card/languages/ja_JP.json new file mode 100644 index 00000000..bfa01ff9 --- /dev/null +++ b/bl-plugins/twitter-card/languages/ja_JP.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Open Graph", + "description": "Open Graph protocol(OGP)を有効にすると、Webページがソーシャルグラフ上のリッチなオブジェクトになります。" + } +} \ No newline at end of file diff --git a/bl-plugins/twitter-card/languages/nl_NL.json b/bl-plugins/twitter-card/languages/nl_NL.json new file mode 100644 index 00000000..f490d38d --- /dev/null +++ b/bl-plugins/twitter-card/languages/nl_NL.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Open Graph", + "description": "De Open Graph protocol kan van elke webpagina een rich object in een sociale grafiek maken." + } +} diff --git a/bl-plugins/twitter-card/languages/pl_PL.json b/bl-plugins/twitter-card/languages/pl_PL.json new file mode 100644 index 00000000..41b92e0a --- /dev/null +++ b/bl-plugins/twitter-card/languages/pl_PL.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Open Graph", + "description": "Protokół Open Graph zezwala stronie na stosowanie meta tagów używanych w serwisach społecznościowych." + } +} \ No newline at end of file diff --git a/bl-plugins/twitter-card/languages/ru_RU.json b/bl-plugins/twitter-card/languages/ru_RU.json new file mode 100644 index 00000000..f88f1371 --- /dev/null +++ b/bl-plugins/twitter-card/languages/ru_RU.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Open Graph", + "description": "Протокол Open Graph дает возможность связывать свой контент с социальными сетями." + } +} diff --git a/bl-plugins/twitter-card/languages/uk_UA.json b/bl-plugins/twitter-card/languages/uk_UA.json new file mode 100644 index 00000000..01fc7398 --- /dev/null +++ b/bl-plugins/twitter-card/languages/uk_UA.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "Open Graph", + "description": "Протокол Open Graph дозволяє ділитися будь-якою веб-сторінкою у соціальних мережах." + } +} diff --git a/bl-plugins/twitter-card/languages/zh_TW.json b/bl-plugins/twitter-card/languages/zh_TW.json new file mode 100644 index 00000000..0a59b71d --- /dev/null +++ b/bl-plugins/twitter-card/languages/zh_TW.json @@ -0,0 +1,7 @@ +{ + "plugin-data": + { + "name": "開放社交關係圖", + "description": "開放社交關係圖協定可以讓任何網頁變成豐富的物件" + } +} \ No newline at end of file diff --git a/bl-plugins/twitter-card/metadata.json b/bl-plugins/twitter-card/metadata.json new file mode 100644 index 00000000..a5c64fc0 --- /dev/null +++ b/bl-plugins/twitter-card/metadata.json @@ -0,0 +1,10 @@ +{ + "author": "Bludit", + "email": "", + "website": "https://plugins.bludit.com", + "version": "2.0", + "releaseDate": "2017-05-26", + "license": "MIT", + "compatible": "2.0", + "notes": "" +} \ No newline at end of file diff --git a/bl-plugins/twitter-card/plugin.php b/bl-plugins/twitter-card/plugin.php new file mode 100644 index 00000000..05006330 --- /dev/null +++ b/bl-plugins/twitter-card/plugin.php @@ -0,0 +1,81 @@ +'summary', + 'site' =>'', + 'title' =>$Site->title(), + 'description' =>$Site->description(), + 'image' =>'' + ); + + switch($WHERE_AM_I) { + // The user filter by page + case 'page': + $data['title'] = $page->title(); + $data['description'] = $page->description(); + $data['image'] = $page->coverImage($absolute=true); + + $content = $page->content(); + break; + + // The user is in the homepage + default: + $content = ''; + // The image it's from the first page + if(isset($pages[0]) ) { + $data['image'] = $pages[0]->coverImage($absolute=true); + $content = $pages[0]->content(); + } + break; + } + + $html = PHP_EOL.''.PHP_EOL; + $html .= ''.PHP_EOL; + $html .= ''.PHP_EOL; + $html .= ''.PHP_EOL; + $html .= ''.PHP_EOL; + + // If the page doesn't have a coverImage try to get an image from the HTML content + if( empty($data['image']) ) { + // Get the image from the content + $src = $this->getImage($content); + if($src!==false) { + $data['image'] = DOMAIN.$src; + } + } + + $html .= ''.PHP_EOL; + return $html; + } + + // Returns the first image from the HTML content + private function getImage($content) + { + $dom = new DOMDocument(); + $dom->loadHTML(''.$content); + $finder = new DomXPath($dom); + + $images = $finder->query("//img"); + + if($images->length>0) { + // First image from the list + $image = $images->item(0); + // Get value from attribute src + $imgSrc = $image->getAttribute('src'); + // Returns the image src + return $imgSrc; + } + + return false; + } +} diff --git a/bl-themes/docs/index.php b/bl-themes/docs/index.php index 027a6b57..8ab0d93e 100644 --- a/bl-themes/docs/index.php +++ b/bl-themes/docs/index.php @@ -1,10 +1,8 @@ - - @@ -24,18 +22,11 @@ whereAmI()=='home') || ($Url->whereAmI()=='tag') ) - { - include('php/home.php'); - } - elseif($Url->whereAmI()=='post') - { - include('php/post.php'); - } - elseif($Url->whereAmI()=='page') - { - include('php/page.php'); - } + if($WHERE_AM_I=='page') { + include(THEME_DIR_PHP.'page.php'); + } else { + include(THEME_DIR_PHP.'home.php'); + } ?> diff --git a/bl-themes/docs/init.php b/bl-themes/docs/init.php index e69de29b..f23b3afe 100644 --- a/bl-themes/docs/init.php +++ b/bl-themes/docs/init.php @@ -0,0 +1,2 @@ +get('Recent posts') ?> - - - -
- - - - - -
- - -

- title() ?> -

- - - - -
- - -
- content(false) - ?> -
- - readMore()) { ?> - printMe('Read more') ?> - - - - - -
- - - - - \ No newline at end of file diff --git a/bl-themes/docs/php/page.php b/bl-themes/docs/php/page.php index 113ba388..a8ffb59f 100644 --- a/bl-themes/docs/php/page.php +++ b/bl-themes/docs/php/page.php @@ -1,26 +1,29 @@ -

parentKey()])?$pages[$Page->parentKey()]->title().' -> ':'' ?>title() ?>

+

+parentKey()]->title(); + echo ' -> '; + echo $page->title(); +?> +

+ - - + - - - - -
- content() ?> -
- - - +
+ key().'/'.FILENAME.'">Edit this page'; + ?> +
+
\ No newline at end of file diff --git a/bl-themes/docs/php/post.php b/bl-themes/docs/php/post.php deleted file mode 100644 index bbec271b..00000000 --- a/bl-themes/docs/php/post.php +++ /dev/null @@ -1,31 +0,0 @@ -

get('Post') ?>

- -
- - - - - -
- - -

- title() ?> -

- - - - -
- - -
- content() ?> -
- - - - -
\ No newline at end of file