Skip to content

Commit

Permalink
Merge v1.2.0 #20: Social share
Browse files Browse the repository at this point in the history
Add social share buttons
Add social snippets support
  • Loading branch information
Devenet authored Aug 6, 2016
2 parents 89a393b + 95f3323 commit c9f05de
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 30 deletions.
66 changes: 50 additions & 16 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
define('PHPPREFIX','<?php /* ');
define('PHPSUFFIX',' */ ?>');
define('MYMOVIES', 'MyMovies');
define('MYMOVIES_VERSION', '1.1.2');
define('MYMOVIES_VERSION', '1.2.0');
define('INACTIVITY_TIMEOUT', 3600);
define('RSS', 'movies.rss');
define('RSS_BOXOFFICE', 'box-office.rss');
Expand Down Expand Up @@ -60,12 +60,17 @@
//ob_start();
$tpl = new RainTPL();

if (!is_file($_CONFIG['settings'])) { define('TITLE', $_CONFIG['title']); define('ROBOTS', $_CONFIG['robots']); install($tpl); }
if (!is_file($_CONFIG['settings'])) { define('TITLE', $_CONFIG['title']); define('ROBOTS', $_CONFIG['robots']); define('AUTHOR', 'Nicolas Devenet'); install($tpl); }
require($_CONFIG['settings']);
define('TITLE', $_CONFIG['title']);
define('PAGINATION', $_CONFIG['pagination']);
define('IMDB_LANGUAGE', $_CONFIG['languages'][$_CONFIG['language']][0]);
define('ROBOTS', $_CONFIG['robots']);
define('AUTHOR', empty($_CONFIG['author']) ? $_CONFIG['login'] : $_CONFIG['author'] );
define('BASE_LANG', $_CONFIG['language']);
define('BASE_URL', (empty($_SERVER['REQUEST_SCHEME']) ? 'http' : $_SERVER['REQUEST_SCHEME']).'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']).'/');

$tpl->assign('MyMoviesVersion', preg_replace('#(\d+\.\d+)(\.\d+)#', '$1', MYMOVIES_VERSION));

/**
* Rain class
Expand Down Expand Up @@ -267,6 +272,17 @@ public function previousMovie($current_id) {
return false;
}

// return the full URI to image linked to a given movie
public static function CompleteImageURI($movie)
{
global $_CONFIG;
$img = !empty($movie['link_image']) ? $movie['link_image'] : BASE_URL.'assets/img/movie.jpg';
// if img is hosted in local, we have to add server URL before...
if (substr( $img, 0, strlen($_CONFIG['images'].'/') ) === $_CONFIG['images'].'/') { $img = BASE_URL.$img; }

return $img;
}

/*
* Write an RSS file with the movies $data given
* $data: movies to write
Expand All @@ -275,41 +291,36 @@ public function previousMovie($current_id) {
*/
private function updateRSS($data, $title, $file) {
global $_CONFIG;
$url = (empty($_SERVER['REQUEST_SCHEME']) ? 'http' : $_SERVER['REQUEST_SCHEME']).'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']).'/';
$xml = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
$xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'.PHP_EOL;
$xml .= '<channel>'.PHP_EOL;
$xml .= '<atom:link href="'.$url.$file.'" rel="self" type="application/rss+xml" />'.PHP_EOL;
$xml .= '<atom:link href="'.BASE_URL.$file.'" rel="self" type="application/rss+xml" />'.PHP_EOL;
$xml .= '<title>'.$title.'</title>'.PHP_EOL;
$xml .= '<link>'.$url.'</link>'.PHP_EOL;
$xml .= '<link>'.BASE_URL.'</link>'.PHP_EOL;
$xml .= '<description>RSS feed of '.$title.'</description>'.PHP_EOL;
$xml .= '<pubDate>'.date("D, d M Y H:i:s O").'</pubDate>'.PHP_EOL;
$xml .= '<copyright>'.$url.'</copyright>'.PHP_EOL;
$xml .= '<copyright>'.BASE_URL.'</copyright>'.PHP_EOL;
$xml .= '<language>'.$_CONFIG['language'].'</language>'.PHP_EOL;
$xml .= '<generator>'.MYMOVIES.'</generator>'.PHP_EOL;
$xml .= '<image>'.PHP_EOL;
$xml .= '<title>'.$title.'</title>'.PHP_EOL;
$xml .= '<url>'.$url.'assets/img/movies_48x48.png</url>'.PHP_EOL;
$xml .= '<link>'.$url.'</link>'.PHP_EOL;
$xml .= '<url>'.BASE_URL.'assets/img/movies_48x48.png</url>'.PHP_EOL;
$xml .= '<link>'.BASE_URL.'</link>'.PHP_EOL;
$xml .= '<width>48</width>'.PHP_EOL;
$xml .= '<height>48</height>'.PHP_EOL;
$xml .= '</image>'.PHP_EOL;
foreach ($data as $id => $movie) {
$xml .= '<item>'.PHP_EOL;
$xml .= '<title>'. $movie['title'] .'</title>'.PHP_EOL;
$xml .= '<link>'.$url.substr(Path::movie($movie['id']), 2).'</link>'.PHP_EOL;
$xml .= '<link>'.BASE_URL.substr(Path::movie($movie['id']), 2).'</link>'.PHP_EOL;
$xml .= '<description><![CDATA[<strong>'.($movie['status']==Movie::SEEN ? 'Movie seen &middot; Rated '.$movie['note'].'/10' : 'Movie not seen').'</strong><br />'.htmlspecialchars_decode(htmlentities($movie['synopsis'], ENT_COMPAT, 'UTF-8')).']]></description>'.PHP_EOL;
// trasform image url if needed
$img = !empty($movie['link_image']) ? $movie['link_image'] : $url.'assets/img/movie.jpg';
// if img is hosted in local, we have to add $url before...
if (substr( $img, 0, strlen($_CONFIG['images'].'/') ) === $_CONFIG['images'].'/') { $img = $url.$img; }
$xml .= '<enclosure url="'.$img.'" length="42" type="image/jpeg" />'.PHP_EOL;
$xml .= '<enclosure url="'.Movies::CompleteImageURI($movie).'" length="42" type="image/jpeg" />'.PHP_EOL;
$xml .= '<guid isPermaLink="false">'.$movie['id'].'</guid>'.PHP_EOL;
$xml .= '<pubDate>'.date("D, d M Y H:i:s O", $movie['id']).'</pubDate>'.PHP_EOL;
foreach (explode(',', $movie['genre']) as $genre) {
$xml .= '<category domain="'.$url.'?genre='.trim(mb_convert_case($genre, MB_CASE_LOWER, "UTF-8")).'">'.trim(mb_convert_case($genre, MB_CASE_TITLE, "UTF-8")).'</category>'.PHP_EOL;
$xml .= '<category domain="'.BASE_URL.'?genre='.trim(mb_convert_case($genre, MB_CASE_LOWER, "UTF-8")).'">'.trim(mb_convert_case($genre, MB_CASE_TITLE, "UTF-8")).'</category>'.PHP_EOL;
}
$xml .= '<source url="'.$url.$file.'">'.TITLE.'</source>'.PHP_EOL;
$xml .= '<source url="'.BASE_URL.$file.'">'.TITLE.'</source>'.PHP_EOL;
$xml .= '</item>'.PHP_EOL;
}
$xml .= '</channel>'.PHP_EOL;
Expand Down Expand Up @@ -625,6 +636,7 @@ function writeSettings() {
$file .= '$_CONFIG[\'hash\']='.var_export($_CONFIG['hash'], TRUE).'; ';
$file .= '$_CONFIG[\'salt\']='.var_export($_CONFIG['salt'], TRUE).'; ';
$file .= '$_CONFIG[\'title\']='.var_export($_CONFIG['title'], TRUE).'; ';
$file .= '$_CONFIG[\'author\']='.var_export($_CONFIG['author'], TRUE).'; ';
$file .= '$_CONFIG[\'robots\']='.var_export($_CONFIG['robots'], TRUE).'; ';
$file .= '$_CONFIG[\'language\']='.var_export($_CONFIG['language'], TRUE).'; ';
$file .= '$_CONFIG[\'pagination\']='.var_export($_CONFIG['pagination'], TRUE).'; ';
Expand Down Expand Up @@ -816,6 +828,18 @@ function displayNote($note) {
$result .= '<i class="icon-star-empty"></i>';
return $result.'</div>'.PHP_EOL;
}
// Convert note into HTML stars
function displaySimpleNote($note) {
$note = $note/2;
$full_stars = floor($note);
$half_star = (2*$note) % 2;
$result = '';
for ($i=0; $i<$full_stars; $i++)
$result .= '';
if ($half_star == 1)
$result .= '';
return $result;
}
// remplace status by icon
function displayStatus($status) {
$result = '<span class="tip" data-title="';
Expand Down Expand Up @@ -904,6 +928,7 @@ function install($tpl) {
$_CONFIG['salt'] = sha1(uniqid('',true).'_'.mt_rand());
$_CONFIG['hash'] = sha1($_CONFIG['login'].$_POST['password'].$_CONFIG['salt']);
$_CONFIG['title'] = empty($_POST['title']) ? 'MyMovies' : htmlspecialchars(trim($_POST['title']));
$_CONFIG['author'] = empty($_POST['author']) ? $_CONFIG['login'] : htmlspecialchars(trim($_POST['author']));
$_CONFIG['language'] = !empty($_POST['locale']) && array_key_exists($_POST['locale'], $_CONFIG['languages']) ? $_POST['locale'] : 'en';
writeSettings();
header('Location: '.$_SERVER['REQUEST_URI']);
Expand Down Expand Up @@ -941,6 +966,14 @@ function moviePage() {
$tpl->assign('movies_count', $movies->count());
$tpl->assign('movie_next', $movies->nextMovie($movie['id']));
$tpl->assign('movie_previous', $movies->previousMovie($movie['id']));
$social_url = str_replace('./', BASE_URL, Path::movie($movie['id']));
$tpl->assign('social', [
'title' => $movie['title'],
'description' => ($movie['status']==Movie::SEEN ? displaySimpleNote($movie['note']) : 'Not seen yet').''. displaySynopsis($movie['synopsis'], 250),
'image' => Movies::CompleteImageURI($movie),
'twitter' => urlencode(($movie['status']==Movie::SEEN ? 'I’ve seen' : 'I want to see').''.$movie['title'].'” via #MyMovies '.$social_url),
'url' => $social_url
]);
$tpl->draw('movie');
exit();
}
Expand Down Expand Up @@ -1021,6 +1054,7 @@ function settingsPage() {
if (!empty($_POST['pagination'])) { $_CONFIG['pagination'] = max(2, $_POST['pagination']+0); }
if (!empty($_POST['robots'])) { $_CONFIG['robots'] = parseRobots(in_array('index', $_POST['robots']), in_array('follow', $_POST['robots']), in_array('archive', $_POST['robots']) ); }
else { $_CONFIG['robots'] = parseRobots(false, false, false); }
$_CONFIG['author'] = empty($_POST['author']) ? $_CONFIG['login'] : htmlspecialchars(trim($_POST['author']));
writeSettings();
header('Location: '.Path::settings().'&update');
exit();
Expand Down
10 changes: 9 additions & 1 deletion templates/admin.settings.rain
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<div class="form-group espace-top-lg">
<label for="title" class="control-label col-md-2">Title</label>
<div class="col-md-8">
<input type="text" class="form-control" id="title" name="title" placeholder=MyMovies" value="{#TITLE#}" />
<input type="text" class="form-control" id="title" name="title" placeholder="MyMovies" value="{#TITLE#}" />
</div>
</div>
<div class="form-group">
Expand All @@ -63,6 +63,14 @@
</label>
</div>
</div>
<div class="form-group">
<label for="author" class="control-label col-md-2">Author</label>
<div class="col-md-8">
<input type="text" class="form-control" id="author" name="author" placeholder="Nicolas Devenet" value="{#AUTHOR#}" />
<p class="help-block">Social share: it’s displayed when you post the URL of a movie page on Twitter, Facebook, …
<br>If not set, your login will be used.</p>
</div>
</div>


<div class="clearfix"></div>
Expand Down
25 changes: 17 additions & 8 deletions templates/form.install.rain
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,39 @@
<div class="form-group">
<label for="login" class="control-label col-md-2">Login</label>
<div class="col-md-8">
<input type="text" class="form-control" id="login" name="login" placeholder="Username" autofocus/>
<input type="text" class="form-control" id="login" name="login" placeholder="Username" autofocus required/>
</div>
</div>
<div class="form-group">
<label for="password" class="control-label col-md-2">Password</label>
<div class="col-md-8">
<input type="password" class="form-control" id="password" name="password" placeholder="Password" />
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required/>
</div>
</div>

<div class="form-group espace-top-lg">
<label for="title" class="control-label col-md-2">Title of the page</label>
<div class="form-group espace-top-lg no-espace-bottom">
<label for="title" class="control-label col-md-2">Title</label>
<div class="col-md-8">
<input type="text" class="form-control" id="title" name="title" value="{#MYMOVIES#}" />
<p class="help-block">You can change it later if needed <i class="icon-smile"></i>.</p>
<input type="text" class="form-control" id="title" name="title" placeholder="{#MYMOVIES#}" value="{#MYMOVIES#}" />
<p class="help-block">You can edit it later <i class="icon-smile"></i>.</p>
</div>
</div>
<div class="form-group">
<label for="author" class="control-label col-md-2">Author</label>
<div class="col-md-8">
<input type="text" class="form-control" id="author" name="author" placeholder="Nicolas Devenet" />
<p class="help-block">Social share: it’s displayed when you post the URL of a movie page on Twitter, Facebook, …
<br>If not set, your login will be used.</p>
</div>
</div>

<div class="form-group espace-top-lg">
<label for="login" class="control-label col-md-2">Prefered language</label>
<div class="col-md-8">
<select class="form-control" id="locale" name="locale">
{$locales}
</select>
<p class="help-block">Used for IMDB search when importing information to add a movie.</p>
<p class="help-block">Used for IMDB search when importing a movie.</p>
</div>
</div>

Expand All @@ -79,4 +88,4 @@

{include="page.foot"}
</body>
</html>
</html>
30 changes: 28 additions & 2 deletions templates/movie.rain
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
<!doctype html>
<html>
<html lang="{#BASE_LANG#}" itemscope itemtype="http://schema.org/Article">
<head>
{include="page.head"}
<link rel="canonical" href="{$social.url}" />
<meta name="description" content="{$social.description}" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@devenet" />
<meta name="twitter:title" content="{$social.title}" />
<meta name="twitter:description" content="{$social.description}" />
<meta name="twitter:image" content="{$social.image}">
<meta property="og:title" content="{$social.title}" />
<meta property="og:type" content="article" />
<meta property="og:url" content="{$social.url}" />
<meta property="og:image" content="{$social.image}" />
<meta property="og:description" content="{$social.description}" />
<meta property="og:site_name" content="{#TITLE#}" />
<meta itemprop="name" content="{$social.title}">
<meta itemprop="description" content="{$social.description}">
<meta itemprop="image" content="{$social.image}">
</head>
<body>
{include="page.menu"}
Expand All @@ -12,7 +28,12 @@
<div class="col-lg-12">
<div class="page-header">
<h2>
{if="isLogged()"}<span class="movie-tools"><a href="{$id|Path::edit}" class="text-success tip" title="Edit&nbsp;movie" data-placement="right"><i class="icon-pencil"></i></a> <a href="{$id|Path::delete}&amp;token={$token}" class="text-danger tip" title="Delete&nbsp;movie" data-placement="right" onclick="return confirmDeleteMovie('{$movie['title']}')"><i class="icon-trash"></i></a></span>{/if}
{if="isLogged()"}
<span class="movie-tools">
<a href="{$id|Path::edit}" class="text-success tip" title="Edit&nbsp;movie" data-placement="right"><i class="icon-pencil"></i></a>
<a href="{$id|Path::delete}&amp;token={$token}" class="text-danger tip" title="Delete&nbsp;movie" data-placement="right" onclick="return confirmDeleteMovie('{$movie['title']}')"><i class="icon-trash"></i></a>
</span>
{/if}
{$movie['title']}
<!--<span class="pull-right espace-right {if="$movie['status'] == Movie::SEEN"}text-success{else}text-warning{/if}">{$displayStatus}</span>-->
</h2>
Expand Down Expand Up @@ -42,6 +63,11 @@
<div class="clearfix visible-sm"></div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<p class="synopsis">{$movie['synopsis']}</p>
<ul class="list-inline social-share espace-top-lg text-center">
<li><a href="https://twitter.com/home?status={$social.twitter}" rel="external" title="Share on Twitter" class="btn tip" data-placement="top"><span class="icon-twitter"></span></a></li>
<li><a href="https://www.facebook.com/sharer/sharer.php?u={$social.url|urlencode}" rel="external" title="Share on Facebook" class="btn tip" data-placement="top"><span class="icon-facebook"></span></a></li>
<li><a href="https://plus.google.com/share?url={$social.url|urlencode}" rel="external" title="Share on Google+" class="btn tip" data-placement="top"><span class="icon-google-plus"></span></a></li>
</ul>
</div>
</div>

Expand Down
7 changes: 4 additions & 3 deletions templates/page.head.rain
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<meta charset="utf-8" />
<title>{if="!empty($page_title)"} {$page_title} &middot; {/if}{#TITLE#}</title>
<title>{if="!empty($page_title)"}{$page_title} &middot; {/if}{#TITLE#}</title>

<meta name="author" content="Nicolas Devenet">
<meta name="author" content="{#AUTHOR#}">
<meta name="robots" content="{#ROBOTS#}">
<meta name="copyright" content="{#TITLE#}">
<meta name="copyright" content="Nicolas Devenet">
<meta name="generator" content="{#MYMOVIES#} v{$MyMoviesVersion}" />

<link rel="apple-touch-icon" sizes="57x57" href="assets/icon/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="assets/icon/apple-touch-icon-60x60.png">
Expand Down

0 comments on commit c9f05de

Please sign in to comment.