homepage, twitter card, improves

This commit is contained in:
Diego Najar 2017-07-11 23:53:53 +02:00
parent 325d6f79d5
commit c3271298eb
26 changed files with 288 additions and 130 deletions

View File

@ -83,5 +83,10 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
// ============================================================================ // ============================================================================
// Main after POST // Main after POST
// ============================================================================ // ============================================================================
$allPublishedPages = buildAllpages(false);
// Homepage select options
$homepageOptions = array();
foreach($allPublishedPages as $key=>$page) {
$homepageOptions[$key] = $page->title();
}

View File

@ -28,6 +28,18 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
'tip'=>$L->g('the-url-of-your-site') '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::legend(array('value'=>$L->g('Website or Blog')));
HTML::formSelect(array( HTML::formSelect(array(

View File

@ -4,15 +4,14 @@
// Variables // Variables
// ============================================================================ // ============================================================================
// Array with pages, each page is a Object Page // Array with pages, each page is a Page Object
$pages = array(); $pages = array();
// Page filtered by the user, is a Object Page // Page filtered by the user, is a Page Object
$page = $Page = false; $page = $Page = false;
// Array with pages order by parent // Array with pages order by parent
// This variable is initializade only when the site is order by position // This variable is initializade only when the site is order by position to not degradate the peromance on blogs
// This is for not degradate the peromance on blogs
/* /*
array( array(
PARENT => array(), // all parent pages PARENT => array(), // all parent pages
@ -24,7 +23,15 @@ array(
*/ */
$pagesByParent = array(PARENT=>array()); $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(); $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 // Build specific page
if( $Url->whereAmI()==='page' ) { if( $Url->whereAmI()==='page' ) {
// Build the page // Build the page

View File

@ -280,10 +280,14 @@ class dbSite extends dbJSON
return $short; return $short;
} }
// Returns the current homepage. // Returns the current homepage, FALSE if not defined homepage
public function homepage() public function homepage()
{ {
return $this->getField('homepage'); $homepage = $this->getField('homepage');
if( empty($homepage) ) {
return false;
}
return $homepage;
} }
// Set the locale. // Set the locale.

View File

@ -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 // Returns TRUE if the plugin is enabled, FALSE otherwise
function pluginEnabled($pluginName) { function pluginEnabled($pluginName) {
global $plugins; global $plugins;

View File

@ -392,10 +392,10 @@ class Page {
// Returns the parent method output, if the page doesn't have a parent returns FALSE // Returns the parent method output, if the page doesn't have a parent returns FALSE
public function parentMethod($method) public function parentMethod($method)
{ {
global $pages; $parentKey = $this->parentKey();
if( $parentKey ) {
if( isset($pages[$this->parentKey()]) ) { $page = buildPage($parentKey);
return $pages[$this->parentKey()]->{$method}(); return $page->{$method}();
} }
return false; return false;

View File

@ -81,6 +81,11 @@ class Url
return $this->slug; return $this->slug;
} }
public function setSlug($slug)
{
$this->slug = $slug;
}
public function activeFilter() public function activeFilter()
{ {
return $this->activeFilter; return $this->activeFilter;

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Open Graph",
"description": "Open Graph ви позволява да свържете вашето съдържание със социални мрежи."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Open Graph",
"description": "Plugin zur Verwendung des Open Graph Protocols."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Open Graph",
"description": "Plugin zur Verwendung des Open Graph Protocols."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Twitter Card",
"description": ""
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Open Graph",
"description": "Mejora las publicaciones en las redes sociales con este plugin."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Open Graph",
"description": "Permets à nimporte quelle page web de devenir lobjet enrichi dun graphe social. Par exemple, il est utilisé sur Facebook pour permettre à une page web de bénéficier des mêmes fonctionnalités que nimporte quel autre objet sur Facebook."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Open Graph",
"description": "Open Graph protocol(OGP)を有効にすると、Webページがソーシャルグラフ上のリッチなオブジェクトになります。"
}
}

View File

@ -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."
}
}

View File

@ -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."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Open Graph",
"description": "Протокол Open Graph дает возможность связывать свой контент с социальными сетями."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Open Graph",
"description": "Протокол Open Graph дозволяє ділитися будь-якою веб-сторінкою у соціальних мережах."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "開放社交關係圖",
"description": "開放社交關係圖協定可以讓任何網頁變成豐富的物件"
}
}

View File

@ -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": ""
}

View File

@ -0,0 +1,81 @@
<?php
class pluginTwitterCard extends Plugin {
public function siteHead()
{
global $Url;
global $Site;
global $WHERE_AM_I;
global $pages;
global $page;
$data = array(
'card' =>'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.'<!-- Twitter Card -->'.PHP_EOL;
$html .= '<meta property="twitter:card" content="'.$data['card'].'">'.PHP_EOL;
$html .= '<meta property="twitter:site" content="'.$data['site'].'">'.PHP_EOL;
$html .= '<meta property="twitter:title" content="'.$data['title'].'">'.PHP_EOL;
$html .= '<meta property="twitter:description" content="'.$data['description'].'">'.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 .= '<meta property="twitter:image" content="'.$data['image'].'">'.PHP_EOL;
return $html;
}
// Returns the first image from the HTML content
private function getImage($content)
{
$dom = new DOMDocument();
$dom->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">'.$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;
}
}

View File

@ -1,10 +1,8 @@
<!doctype html> <!doctype html>
<html lang="<?php echo $Site->language() ?>"> <html lang="<?php echo $Site->language() ?>">
<head> <head>
<!-- Meta tags --> <!-- Meta tags -->
<?php include('php/head.php') ?> <?php include('php/head.php') ?>
</head> </head>
<body> <body>
@ -24,17 +22,10 @@
<!-- Content --> <!-- Content -->
<?php <?php
if( ($Url->whereAmI()=='home') || ($Url->whereAmI()=='tag') ) if($WHERE_AM_I=='page') {
{ include(THEME_DIR_PHP.'page.php');
include('php/home.php'); } else {
} include(THEME_DIR_PHP.'home.php');
elseif($Url->whereAmI()=='post')
{
include('php/post.php');
}
elseif($Url->whereAmI()=='page')
{
include('php/page.php');
} }
?> ?>

View File

@ -0,0 +1,2 @@
<?php
$GITHUB_BASE_URL = 'https://github.com/dignajar/bludit-documentation-english/tree/master/';

View File

@ -1,47 +0,0 @@
<h1 class="subhead"><?php echo $Language->get('Recent posts') ?></h1>
<?php foreach ($posts as $Post): ?>
<section class="post">
<!-- Plugins Post Begin -->
<?php Theme::plugins('postBegin') ?>
<!-- Post header -->
<header class="post-header">
<!-- Post title -->
<h2 class="post-title">
<a href="<?php echo $Post->permalink() ?>"><?php echo $Post->title() ?></a>
</h2>
<!-- Post date and author -->
<div class="post-meta">
<span class="date"><?php echo $Post->date() ?></span>
</div>
</header>
<!-- Post content -->
<div class="post-content">
<?php
// Call the method with FALSE to get the first part of the post
echo $Post->content(false)
?>
</div>
<?php if($Post->readMore()) { ?>
<a class="read-more" href="<?php echo $Post->permalink() ?>"><?php $Language->printMe('Read more') ?></a>
<?php } ?>
<!-- Plugins Post End -->
<?php Theme::plugins('postEnd') ?>
</section>
<?php endforeach; ?>
<!-- Paginator for posts -->
<?php
echo Paginator::html();
?>

View File

@ -1,26 +1,29 @@
<h1 class="subhead"><?php echo isset($pages[$Page->parentKey()])?$pages[$Page->parentKey()]->title().' -> ':'' ?><?php echo $Page->title() ?></h1> <h1 class="subhead">
<?php
echo $pagesByParent[PARENT][$page->parentKey()]->title();
echo ' -> ';
echo $page->title();
?>
</h1>
<section class="page"> <section class="page">
<!-- Plugins Page Begin -->
<?php Theme::plugins('pageBegin') ?> <?php Theme::plugins('pageBegin') ?>
<!-- page header -->
<header class="page-header"> <header class="page-header">
<!-- page title -->
<h2 class="page-title"> <h2 class="page-title">
<a href="<?php echo $Page->permalink() ?>"><?php echo $Page->title() ?></a> <a href="<?php echo $Page->permalink() ?>"><?php echo $Page->title() ?></a>
</h2> </h2>
</header> </header>
<!-- page content -->
<div class="page-content"> <div class="page-content">
<?php echo $Page->content() ?> <?php echo $Page->content() ?>
</div> </div>
<!-- Plugins Page End --> <div class="edit-this-page">
<?php Theme::plugins('pageEnd') ?> <?php
echo '<a href="'.$GITHUB_BASE_URL.$Page->key().'/'.FILENAME.'">Edit this page</a>';
?>
</div>
<?php Theme::plugins('pageEnd') ?>
</section> </section>

View File

@ -1,31 +0,0 @@
<h1 class="subhead"><?php echo $Language->get('Post') ?></h1>
<section class="post">
<!-- Plugins Post Begin -->
<?php Theme::plugins('postBegin') ?>
<!-- Post header -->
<header class="post-header">
<!-- Post title -->
<h2 class="post-title">
<a href="<?php echo $Post->permalink() ?>"><?php echo $Post->title() ?></a>
</h2>
<!-- Post date and author -->
<div class="post-meta">
<span class="date"><?php echo $Post->date() ?></span>
</div>
</header>
<!-- Post content -->
<div class="post-content">
<?php echo $Post->content() ?>
</div>
<!-- Plugins Post End -->
<?php Theme::plugins('postEnd') ?>
</section>