From de2912cd6ed9a86a084831c14136a619a37361ff Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 5 Aug 2016 01:19:46 +0200 Subject: [PATCH 1/4] Add social snippets on HTML head Support for Twitter Card, Open Graph (Facebook & Google+). --- index.php | 53 ++++++++++++++++++++++++++++++++------------ templates/movie.rain | 19 +++++++++++++++- 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/index.php b/index.php index 23ce96d..448114e 100644 --- a/index.php +++ b/index.php @@ -66,6 +66,7 @@ define('PAGINATION', $_CONFIG['pagination']); define('IMDB_LANGUAGE', $_CONFIG['languages'][$_CONFIG['language']][0]); define('ROBOTS', $_CONFIG['robots']); +define('BASE_URL', (empty($_SERVER['REQUEST_SCHEME']) ? 'http' : $_SERVER['REQUEST_SCHEME']).'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']).'/'); /** * Rain class @@ -267,6 +268,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 @@ -275,41 +287,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 = ''.PHP_EOL; $xml .= ''.PHP_EOL; $xml .= ''.PHP_EOL; - $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; $xml .= ''.$title.''.PHP_EOL; - $xml .= ''.$url.''.PHP_EOL; + $xml .= ''.BASE_URL.''.PHP_EOL; $xml .= 'RSS feed of '.$title.''.PHP_EOL; $xml .= ''.date("D, d M Y H:i:s O").''.PHP_EOL; - $xml .= ''.$url.''.PHP_EOL; + $xml .= ''.BASE_URL.''.PHP_EOL; $xml .= ''.$_CONFIG['language'].''.PHP_EOL; $xml .= ''.MYMOVIES.''.PHP_EOL; $xml .= ''.PHP_EOL; $xml .= ''.$title.''.PHP_EOL; - $xml .= ''.$url.'assets/img/movies_48x48.png'.PHP_EOL; - $xml .= ''.$url.''.PHP_EOL; + $xml .= ''.BASE_URL.'assets/img/movies_48x48.png'.PHP_EOL; + $xml .= ''.BASE_URL.''.PHP_EOL; $xml .= '48'.PHP_EOL; $xml .= '48'.PHP_EOL; $xml .= ''.PHP_EOL; foreach ($data as $id => $movie) { $xml .= ''.PHP_EOL; $xml .= ''. $movie['title'] .''.PHP_EOL; - $xml .= ''.$url.substr(Path::movie($movie['id']), 2).''.PHP_EOL; + $xml .= ''.BASE_URL.substr(Path::movie($movie['id']), 2).''.PHP_EOL; $xml .= ''.($movie['status']==Movie::SEEN ? 'Movie seen · Rated '.$movie['note'].'/10' : 'Movie not seen').'
'.htmlspecialchars_decode(htmlentities($movie['synopsis'], ENT_COMPAT, 'UTF-8')).']]>
'.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 .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; $xml .= ''.$movie['id'].''.PHP_EOL; $xml .= ''.date("D, d M Y H:i:s O", $movie['id']).''.PHP_EOL; foreach (explode(',', $movie['genre']) as $genre) { - $xml .= ''.trim(mb_convert_case($genre, MB_CASE_TITLE, "UTF-8")).''.PHP_EOL; + $xml .= ''.trim(mb_convert_case($genre, MB_CASE_TITLE, "UTF-8")).''.PHP_EOL; } - $xml .= ''.TITLE.''.PHP_EOL; + $xml .= ''.TITLE.''.PHP_EOL; $xml .= '
'.PHP_EOL; } $xml .= '
'.PHP_EOL; @@ -816,6 +823,18 @@ function displayNote($note) { $result .= ''; return $result.''.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 = ' + + + + + + + + + + + {include="page.menu"} @@ -12,7 +24,12 @@
+
+ +
+ +

Social share: it’s displayed when you post the URL of a movie page on Twitter, Facebook, … +
If not set, your login will be used.

+
+
diff --git a/templates/form.install.rain b/templates/form.install.rain index 37d8f32..838f66c 100644 --- a/templates/form.install.rain +++ b/templates/form.install.rain @@ -41,30 +41,39 @@
- +
- +
-
- +
+
- -

You can change it later if needed .

+ +

You can edit it later .

+ +
+ +

Social share: it’s displayed when you post the URL of a movie page on Twitter, Facebook, … +
If not set, your login will be used.

+
+
+ +
-

Used for IMDB search when importing information to add a movie.

+

Used for IMDB search when importing a movie.

@@ -79,4 +88,4 @@ {include="page.foot"} - \ No newline at end of file + diff --git a/templates/movie.rain b/templates/movie.rain index 3796b3f..1a1e32d 100644 --- a/templates/movie.rain +++ b/templates/movie.rain @@ -2,6 +2,7 @@ {include="page.head"} + @@ -62,6 +63,11 @@

{$movie['synopsis']}

+
diff --git a/templates/page.head.rain b/templates/page.head.rain index 4c68581..919618f 100644 --- a/templates/page.head.rain +++ b/templates/page.head.rain @@ -1,9 +1,10 @@ {if="!empty($page_title)"}{$page_title} · {/if}{#TITLE#} - + - + +