Files
toppic-child/functions.php
2019-08-17 16:50:01 +02:00

566 lines
17 KiB
PHP
Executable File

<?php load_theme_textdomain('toppic-child', get_template_directory() . '-child/languages'); ?>
<?php
/*-----------------------------------------------------------------------------------*/
/* ENQUEUES STYLES
/*-----------------------------------------------------------------------------------*/
function kktfwp_parent_styles() {
//wp_enqueue_style( 'kk-reset', get_theme_file_uri('/css/reset.css'), array(), KKFW_VERSION );
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css', array( 'kk-icons', 'kk-reset', 'kk-default' ), wp_get_theme()->get('Version') );
}
add_action( 'wp_enqueue_scripts', 'kktfwp_parent_styles' );
/*
* Filter for disabling the update notice in admin panel
*
*/
//add_filter( 'kkHideUpdateNotice', 'kkHideUpdateNotice' );
function kkHideUpdateNotice() {
return true;
}
/*-----------------------------------------------------------------------------------*/
/* WRITE YOUR OWN FUNCTIONS BELOW
/*-----------------------------------------------------------------------------------*/
/*
<link rel='stylesheet' id='kk-lightbox-css' href='http://silverbook.local/wordpress/wp-content/themes/toppic/css/lightbox.css?ver=2.7' type='text/css' media='all' />
<script type='text/javascript' src='http://silverbook.local/wordpress/wp-content/themes/toppic/js/jquery.lightbox.js?ver=2.7'></script>
wp_enqueue_style( 'kk-lightbox', get_theme_file_uri( '/css/lightbox.css' ), '', KKFW_VERSION );
if(get_post_meta($postid, '_gallery_layout_value', true) !== 'Fullscreen' && !is_page_template('template-homepage.php')) {
wp_enqueue_script('kk-lightbox', get_theme_file_uri( '/js/jquery.lightbox.js' ), array( 'jquery' ), KKFW_VERSION, true);
head:
<link href="../dist/css/lightgallery.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
corps à la fin:
<script type="text/javascript">
$(document).ready(function(){
$('#lightgallery').lightGallery();
});
</script>
<script src="https://cdn.jsdelivr.net/picturefill/2.3.1/picturefill.min.js"></script>
<script src="../dist/js/lightgallery-all.min.js"></script>
<script src="../lib/jquery.mousewheel.min.js"></script>
function google_jquery() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js', false, '3.3.1');
//wp_register_script('jquery', get_stylesheet_directory_uri() . '/js/jquery.min.js', false, '3.3.1');
wp_enqueue_script('jquery');
}
}
add_action('init', 'google_jquery');
*/
/*function deregister_kklightbox() {
if ( is_page_template( 'page-ce-mois-ci.php' ) ) {
wp_deregister_script('kk-lightbox');
//wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', false, '3.1.1');
//wp_register_script('jquery', get_stylesheet_directory_uri() . '/js/jquery.min.js', false, '3.3.1');
//wp_enqueue_script('jquery');
wp_deregister_style('kk-lightbox-css');
}
}
add_action('init', 'deregister_kklightbox');
function register_lightGallery() {
if ( is_page_template( 'page-ce-mois-ci.php' ) ) {
// head
wp_enqueue_style( 'lightGallery', get_stylesheet_directory_uri() . '/lightGallery/dist/css/lightgallery.min.css' );
// jquery
// fin
wp_enqueue_script('lightGallery', get_theme_file_uri( '/lightGallery/lib/picturefill.min.js' ), array( 'jquery' ), KKFW_VERSION, true);
wp_enqueue_script('lightGallery', get_theme_file_uri( '/lightGallery/dist/js/lightgallery-all.min.js' ), array( 'jquery' ), KKFW_VERSION, true);
wp_enqueue_script('lightGallery', get_theme_file_uri( '/lightGallery/lib/jquery.mousewheel.min.js' ), array( 'jquery' ), KKFW_VERSION, true);
}
}
add_action( 'wp_enqueue_scripts', 'register_lightGallery' );
*/
/* Returns the name of one random file from within a directory
livre-d-or.php:39:
*/
function register_photoSwipe() {
if ( is_page_template( 'page-ce-mois-ci.php' ) ) {
// head
wp_enqueue_style( 'photoSwipe', get_stylesheet_directory_uri() . '/photoSwipe/photoswipe.css' );
// jquery
// fin
wp_enqueue_style('photoSwipe', get_theme_file_uri( '/photoSwipe/default-skin/default-skin.css' ), array( 'jquery' ), KKFW_VERSION, true);
wp_enqueue_script('photoSwipe', get_theme_file_uri( '/photoSwipe/photoswipe.min.js' ), array( 'jquery' ), KKFW_VERSION, true);
wp_enqueue_script('photoSwipe', get_theme_file_uri( '/photoSwipe/photoswipe-ui-default.min.js' ), array( 'jquery' ), KKFW_VERSION, true);
}
}
//add_action( 'wp_enqueue_scripts', 'register_photoSwipe' );
function getRandomFile($start_dir) {
chdir($start_dir);
$dir = opendir('.');
while (($myfile = readdir($dir)) !==false) {
if ($myfile != '.' && $myfile != '..' && is_file($myfile) && $myfile != 'resource.frk') {
$files[] = $myfile;
}
}
closedir($dir);
chdir('../');
srand ((float) microtime() * 10000000);
$file = array_rand($files);
return $files[$file];
}
function show_bookmark_list(){ ?>
<ul>
<?php
$args = array(
'title_before' => '<h3>',
'title_after' => '</h3>',
);
wp_list_bookmarks( $args ); ?>
</ul>
<?php
}
add_shortcode('show_bookmark_list', 'show_bookmark_list');
/*
ce-mois.php
ce-mois-ci.php
*functions.php - date_archive()
*/
function mois2 ($mois) {
switch ($mois)
{
case 00:
$mois = "00";
break;
case 1:
$mois = __('January','toppic-child');
break;
case 2:
$mois = __('February','toppic-child');
break;
case 3:
$mois = __('March','toppic-child');
break;
case 4:
$mois = __('April','toppic-child');
break;
case 5:
$mois = __('May','toppic-child');
break;
case 6:
$mois = __('June','toppic-child');
break;
case 7:
$mois = __('July','toppic-child');
break;
case 8:
$mois = __('August','toppic-child');
break;
case 9:
$mois = __('September','toppic-child');
break;
case 10:
$mois = __('October','toppic-child');
break;
case 11:
$mois = __('November','toppic-child');
break;
case 12:
$mois = __('December','toppic-child');
break;
}
return $mois;
}
/*
Retourne la liste des images d'un album Zenphoto
page-ce-mois-ci.php:259
*/
function imagesFromZPAlbum ($album, $connexion) {
$table = array();
$table['images'] = $connexion['zp_prefix'] . "images";
$table['albums'] = $connexion['zp_prefix'] . "albums";
// ****** Mysqli ****** //
/*
$conn = new mysqli($connexion['host'], $connexion['user'], $connexion['password'], $connexion['db_zenphoto']);
if ($conn->connect_error) {
trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
exit();
}
$conn->set_charset("utf8");
$excquery = "SELECT `id` FROM `" . $table['albums'] . "` WHERE `folder` = '" . $album . "'";
if ($result = $conn->query($excquery)) {
$result->data_seek(0);
$row = $result->fetch_row();
$id_album = $row[0];
$result->close();
}
$pictquery = "SELECT `filename`, `EXIFModel`, `EXIFDateTimeOriginal`, `EXIFExposureTime`, `EXIFFNumber`, `EXIFISOSpeedRatings`, `EXIFFocalLength`, `EXIFGPSLatitude`, `EXIFGPSLatitudeRef`, `EXIFGPSLongitude`, `EXIFGPSLongitudeRef`, `EXIFGPSAltitude`, `EXIFGPSAltitudeRef`, `desc`, `title` FROM `" . $table['images'] . "` WHERE `albumid` = ? ORDER BY `date` DESC";
$stmt = $conn->prepare($pictquery);
if($stmt === false) {
trigger_error('Wrong SQL: ' . $pictquery . ' Error: ' . $conn->error, E_USER_ERROR);
}
else {
$stmt->bind_param('i', $id_album);
$stmt->execute();
$fichier = $stmt->get_result()->fetch_all();
}
$stmt->close();
*/
/*
Array
(
[0] => Array
(
[0] => 11_2018.jpg
[1] => Canon EOS-1D Mark IV
[2] => 2018:11:04 11:05:09
[3] => 1/2000 sec
[4] => f/7,1
[5] => 500
[6] => 700 mm
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] => 11_2018
)
*/
// ****** /Mysqli ****** //
// ****** PDO ****** //
$charset = 'utf8';
$host = $connexion['host'];
$dbname = $connexion['db_zenphoto'];
$dsn = "mysql:host=$host;dbname=$dbname;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $connexion['user'], $connexion['password'], $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
$excquery = "SELECT `id` FROM `" . $table['albums'] . "` WHERE `folder` = '" . $album . "'";
$stmt = $pdo->query($excquery);
while ($row = $stmt->fetch()) {
//echo $row['id'] . "\n";
$id_album = $row['id'];
}
$pictquery = "SELECT `filename`, `EXIFModel`, `EXIFDateTimeOriginal`, `EXIFExposureTime`, `EXIFFNumber`, `EXIFISOSpeedRatings`, `EXIFFocalLength`, `EXIFLensInfo`, `EXIFGPSLatitude`, `EXIFGPSLatitudeRef`, `EXIFGPSLongitude`, `EXIFGPSLongitudeRef`, `EXIFGPSAltitude`, `EXIFGPSAltitudeRef`, `desc`, `title` FROM `" . $table['images'] . "` WHERE `albumid` = ? ORDER BY `date` DESC";
$stmt = $pdo->prepare($pictquery);
$stmt->execute([$id_album]);
$fichier = $stmt->fetchAll(PDO::FETCH_ASSOC);
/*
Array
(
[0] => Array
(
[filename] => 11_2018.jpg
[EXIFModel] => Canon EOS-1D Mark IV
[EXIFDateTimeOriginal] => 2018:11:04 11:05:09
[EXIFExposureTime] => 1/2000 sec
[EXIFFNumber] => f/7,1
[EXIFISOSpeedRatings] => 500
[EXIFFocalLength] => 700 mm
[EXIFLensInfo] => EF500mm f/4L IS USM
[EXIFGPSLatitude] =>
[EXIFGPSLatitudeRef] =>
[EXIFGPSLongitude] =>
[EXIFGPSLongitudeRef] =>
[EXIFGPSAltitude] =>
[EXIFGPSAltitudeRef] =>
[desc] =>
[title] => 11_2018
)
*/
//preprint($fichier);
// ****** /PDO ****** //
return $fichier;
}
function ZPGetTag ($filename, $album, $connexion) {
$table = array();
$table['images'] = $connexion['zp_prefix'] . "images";
$table['albums'] = $connexion['zp_prefix'] . "albums";
$table['obj_to_tag'] = $connexion['zp_prefix'] . "obj_to_tag";
$table['tags'] = $connexion['zp_prefix'] . "tags";
$charset = 'utf8';
$host = $connexion['host'];
$dbname = $connexion['db_zenphoto'];
$dsn = "mysql:host=$host;dbname=$dbname;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $connexion['user'], $connexion['password'], $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
// 1. id de l'image:
$query1 = "SELECT `id` FROM `" . $table['images'] . "` WHERE `filename` = ?";
$stmt = $pdo->prepare($query1);
$stmt->execute([$filename]);
//$fichier = $stmt->fetchAll(PDO::FETCH_ASSOC);
while ($row = $stmt->fetch()) {
//echo $row['id'] . "\n";
$id_image = $row['id'];
}
// 2. ids des tags de l'image:
$query2 = "SELECT `tagid` FROM `" . $table['obj_to_tag'] . "` WHERE `objectid` = ?";
$stmt = $pdo->prepare($query2);
$stmt->execute([$id_image]);
//$ids_tag = $stmt->fetchAll(PDO::FETCH_COLUMN);
while ($ids_tag = $stmt->fetch()) {
$query_tags .= " `id` = " . $ids_tag['tagid'] . " OR ";
}
// 3. Liste des tags correspondant aux ids:
$query_tags = substr($query_tags, 0, -4);;
$query3 = "SELECT `name` FROM `_tags` WHERE $query_tags";
$stmt = $pdo->prepare($query3);
$stmt->execute();
$tags = $stmt->fetchAll(PDO::FETCH_COLUMN);
return $tags;
}
/*
page-ce-mois-ci.php
*/
function displayRetina ($file,$album) {
global $ppage;
//preprint($file);
/*
Array
(
[filename] => 10_2018.jpg
[EXIFModel] => Canon EOS 5D Mark III
[EXIFDateTimeOriginal] => 2018:10:17 19:09:12
[EXIFExposureTime] => 1/250 sec
[EXIFFNumber] => f/4
[EXIFISOSpeedRatings] => 4000
[EXIFFocalLength] => 500 mm
[EXIFLensInfo] => EF500mm f/4L IS USM
[EXIFGPSLatitude] =>
[EXIFGPSLatitudeRef] =>
[EXIFGPSLongitude] =>
[EXIFGPSLongitudeRef] =>
[EXIFGPSAltitude] =>
[EXIFGPSAltitudeRef] =>
[desc] =>
[title] => 10_2018
)
*/
if ($ppage == "1") $fullpath = "../../zenphoto/";
else $fullpath = "../../../zenphoto/";
$thumbsize = 200;
$watermark = "thumb";
$name = explode(".", $file['filename']);
$thumbpath = "../zenphoto/cache/" . $album . "/";
$file_sd = $thumbpath . $name[0] . "_" . $thumbsize . "_" . $watermark .".jpg";
$file_hd = $thumbpath . $name[0] . "_" . ($thumbsize * 2) . "_" . $watermark .".jpg";
$th_sd = false;
$th_hd = false;
$thumb = array();
if (file_exists($file_hd)) {
$th_hd = true;
$size_hd = getimagesize($file_hd, $info);
$thumb['hd'] = array(
'url' => "../../" . $file_hd,
'width' => $size_hd[0],
'height' => $size_hd[1]
);
}
if (file_exists($file_sd)) {
$th_sd = true;
$size_sd = getimagesize($file_sd, $info);
$thumb['sd'] = array(
'url' => "../../" . $file_sd,
'width' => $size_sd[0],
'height' => $size_sd[1]
);
}
if (($th_sd == false) || ($th_hd == false)) {
$notfound = "../zenphoto/zp-core/images/err-imagenotfound.png";
$size_sd = getimagesize($notfound, $info);
$thumb['sd'] = array(
'url' => "../../" . $notfound,
'width' => $size_sd[0],
'height' => $size_sd[1]
);
}
if (($th_sd == true) && ($th_hd == true)) {
$standard = $thumb['sd']['url'] . ' 200w, ' . $thumb['hd']['url'] . ' 400w';
}
elseif ($th_sd == true) {
$standard = $thumb['sd']['url'] . ' 200w';
}
elseif ($th_hd == true) {
$standard = $thumb['hd']['url'] . ' 400w';
}
//print_r($standard);
$display = '<div class="album">';
$display .= '<div class="holder">';
$display .= '<a href="' . $fullpath . 'albums/'.$album.'/'.$file['filename'].'" title="'.date_archive($file['filename']).'" class="kk-lightbox">';
$display .= "<img width='" . $thumb['sd']['width'] . "' height='" . $thumb['sd']['height'] . "' src='" . $thumb['sd']['url'] . "' class='' alt='' srcset='" . $standard . "' sizes='(max-width: 200px) 100vw, 200px' />";
$display .= '</a>';
$display .= '</div>';
$display .= '<div class="albumdesc">';
$display .= '<a href="' . $fullpath . 'index.php?album='.$album.'&amp;image='.$file['filename'].'" title= "'.date_archive($file['filename']).'" class="">';
$display .= '<span class="exif">'.date_archive($file['filename']).'</span>';
$display .= '</a></div>';
$display .= '</div>' . "\r\n";
return $display;
}
/* SHORTCODE: Images sur Zenphoto */
function zenphoto_handler($atts) {
//utilise le cacheManager de zenphoto (extensions/utilitaires/cacheManager)
// ** Utilisation **
// [zenphoto album="lievres" image="2008-08-18_Lievre_8927.jpg"]
// [zenphoto album="sports-mecaniques/gp-france" image="2010-05-23_gp-france-2010_5321.jpg"]
// [zenphoto album="lievres"]
//
//taille des photos dans Worpress, theme Twenty Ten Child : 610x406
/*
$selector = dess_setting('dess_lightbox_select');
$zenphoto_url = dess_setting('dess_zenphoto');
$size = dess_setting('dess_zp_size');
*/
preprint($atts);
//require_once($_SERVER['DOCUMENT_ROOT'].'/Connections/cnx.php');
$selector = "meow-lightbox";
//$zenphoto_url = "https://silverbook.local/zenphoto/";
$zenphoto_url = "https://" . $_SERVER["SERVER_NAME"] . "/zenphoto/";
$size = 800;
$album = ! empty( $atts['album'] ) ? $atts['album'] : '';
$album = filter_var($album, FILTER_SANITIZE_STRING);
$image = ! empty( $atts['image'] ) ? $atts['image'] : '';
$image = filter_var($image, FILTER_SANITIZE_STRING);
$caption = ! empty( $atts['caption'] ) ? $atts['caption'] : '';
$caption = filter_var($caption, FILTER_SANITIZE_STRING);
$rnd = rand (1000, 9999);
//$size = 610;
$folder = false;
$zenphoto_img = "";
return $zenphoto_img;
}
add_shortcode( 'zenphoto', 'zenphoto_handler' );
/*
*functions.php - displayRetina() displayRetina()
*/
function date_archive ($chaine) {
$pieces = explode(".", $chaine);
$b = explode("_", $pieces[0]);
$mois = $b[0];
$an = $b[1];
$chaine = mois2($mois) . ' '. $an;
return $chaine;
}
function preprint($s, $return=false) {
$x = "<pre>";
$x .= print_r($s, 1);
$x .= "</pre>";
if ($return) return $x;
else print $x;
}