Basic files of the plugin

parent 01c78ae8
<?php
if (!defined('FLICKR_API_KEY'))
define('FLICKR_API_KEY','4197236ed82c48d3271fb72ca2c7923c');
if (!defined('FLICKR_API_SECRET'))
define('FLICKR_API_SECRET','3a6a468e58118091');
// to get flickr user id
// https://www.webfx.com/tools/idgettr/
if (!defined('FLICKR_USERID'))
define('FLICKR_USERID','32796764@N08');
if (!defined('FLICKR_USERNAME'))
define('FLICKR_USERNAME','');
if (!defined('FLICKR_SET1'))
define('FLICKR_SET1','72157626186253384'); // food photoset
if (!defined('FLICKR_SET2'))
define('FLICKR_SET2','72157662442917857'); // humanity heritage
if (!defined('FLICKR_SET2'))
define('FLICKR_SET2','72157662441726607'); // the river
?>
<?php
/*
Plugin Name: Turismo mal plugin
Description: This plugin connects with flickr API and show photos from the demanded photosets.
Version: 0.1
Author: Montera34
Author URI: https://montera34.com
License: GPLv3
Text Domain: turismomal
Domain Path: /lang/
*/
// VARIABLES
// TODO: to include in plugin config page in dashboard
include('flickr.config.php');
// CSV data file vars
$csv = array(
'filename' => plugin_basename( dirname( __FILE__ ) ) . '/content/testimonies.csv',
'line_length' => "1024", // max line lengh (increase in case you have longer lines than 1024 characters)
'delimiter' => ",", // field delimiter character
'enclosure' => '"' // field enclosure character
);
function turismomal_get_photoset_photo($photosets = array(FLICKR_SET1, FLICKR_SET2, FLICKR_SET3),$size = 'b') {
// $size can be s (75x75), m (240px), z (640px), b (full)
$photoset = array_rand($photosets);
$url = "https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=".FLICKR_API_KEY."&photoset_id=".$photoset."&user_id=".FLICKR_USERID."&format=json&nojsoncallback=1";
$response = json_decode(file_get_contents($url));
$photos = $response->photoset->photo;
$photo = array_rand($photos);
$photo_url = "https://farm".$photo->farm.".staticflickr.com/".$photo->server."/".$photo->id."_".$photo->secret."_".$size.".jpg";
$photo_out = "<img src='".$photo_url."' alt='".$photo->title."' />";
return $photo_out;
}
function turismomal_get_testimony() {
global $csv;
// open the data file
$fp = fopen($csv['filename'],'r');
// get data and store it in array
if ( $fp !== FALSE ) { // if the file exists and is readable
// data array generation
$data = array();
$count = 0;
while ( ($fp_csv = fgetcsv($fp,$csv['line_length'],$csv['delimiter'],$csv['enclosure'])) !== FALSE ) { // begin main loop
$count++;
if ( $count == 1 )
continue;
$data[] = $fp_csv[0];
}
fclose($fp); // close file pointer
$line = array_rand($data);
return $line;
}
else {
return $cvs_filename. "doesn't exist or is not readable. Check it.";
} // end if file exist and readable
}
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment