Skip to content
Permalink
Browse files

use the new showcases on home page

  • Loading branch information
plegall committed Mar 16, 2020
1 parent 7e57bf3 commit a386a4fadd61e53b954db2472f3a51c6b6da2b3c
Showing with 22 additions and 32 deletions.
  1. +16 −27 include/functions_piwigodotorg.php
  2. +1 −1 main.inc.php
  3. +5 −4 template/home.tpl
@@ -175,42 +175,31 @@ function porg_get_release_tpl($version)

function get_showcases($exclude_ids=array())
{
global $lang_info, $conf, $page;
global $user;

$cache_path = $conf['data_location'].'porg_showcases-'.$lang_info['code'].'.cache.php';
if (!is_file($cache_path) or filemtime($cache_path) < strtotime('1 hour ago'))
{
$url = 'https://' . $page['porg_domain_prefix'] . 'piwigo.org/showcase/ws.php?format=php&method=pwg.tags.getImages&tag_name=Featured';
include(PORG_PATH . '/data/showcases.data.php');

$content = @file_get_contents($url);
if ($content !== false)
{
$result = unserialize($content);
file_put_contents($cache_path, serialize($result['result']['images']));
}
}
$raw_images = unserialize(file_get_contents($cache_path));
$showcases_ids = array_diff(array_keys($showcases), $exclude_ids);
shuffle($showcases_ids);
$showcases_ids = array_slice($showcases_ids, 0 ,4);
$showcases_sample = array();

if (count($exclude_ids) > 0)
if ('en_UK' != $user['language'])
{
foreach ($raw_images as $idx => $showcase)
{
if (in_array($showcase['id'], $exclude_ids))
{
unset($raw_images[$idx]);
}
}
load_language('showcases.lang', PORG_PATH, array('language' => 'en_UK', 'no_fallback' => true));
}
/* Load user language translation */
load_language('showcases.lang', PORG_PATH);

$max = 4;
$rand_keys = array_rand($raw_images, $max);
$final_images = array();
foreach ($rand_keys as $showcase_id)
foreach ($showcases_ids as $showcase_id)
{
$final_images[] = $raw_images[$showcase_id];
$showcases_sample[] = array(
'id' => $showcase_id,
'name' => l10n('porg_showcases_'.$showcase_id.'_title'),
);
}

return $final_images;
return $showcases_sample;
}

function porg_get_testimonials_sample()
@@ -102,7 +102,7 @@ function porg_add_methods($arr)
'porg.home.refresh_showcases',
'ws_porg_home_refresh_showcases',
array(
'exclude' => array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY, 'type'=>WS_TYPE_ID),
'exclude' => array('default'=>null, 'flags'=>WS_PARAM_FORCE_ARRAY),
),
'Refresh showcases thumbnail'
);
@@ -8,6 +8,8 @@ $(document).ready(function() {
excludes.push(jQuery(this).data('showcaseid'));
});

var basesrc = jQuery(".showcases-home").data('basesrc');

$.ajax({
type: "POST",
url: "ws.php?method=porg.home.refresh_showcases&format=json",
@@ -19,8 +21,7 @@ $(document).ready(function() {
var showcases = jQuery.parseJSON(response['result']);
showcases.forEach(function (item, index) {
$('.showcase'+(index+1)).data('showcaseid', item.id);
$('.showcase'+(index+1)+' a').attr("href", item.tags[0].page_url).attr("title", item.name);
$('.showcase'+(index+1)+' a img').attr("src", item.derivatives.large.url);
$('.showcase'+(index+1)+' img').attr("src", basesrc+item.id+".jpg").attr("title", item.name);
});
},
});
@@ -160,11 +161,11 @@ $(document).ready(function() {

<div class="row text-center">
<h2>{'porg_showcase_title'|translate}</h2>
<div class="showcases-home">
<div class="showcases-home" data-basesrc="{$PORG_ROOT_URL}images/showcases/">
{foreach from=$SHOWCASES item=showcase name=showcases}
<div class="col-md-3 col-xs-12 showcases-content">
<div class="showcase showcase{$smarty.foreach.showcases.iteration}" data-showcaseid="{$showcase.id}">
<a href="{$showcase.tags[0].page_url}" title="{$showcase.name}"><img src="{$showcase.derivatives.large.url}" alt="{$showcase.name}"></a>
<img src="{$PORG_ROOT_URL}images/showcases/{$showcase.id}.jpg" alt="{$showcase.name}" title="{$showcase.name}">
</div>
</div>
{/foreach}

0 comments on commit a386a4f

Please sign in to comment.
You can’t perform that action at this time.