update
This commit is contained in:
parent
814643dd63
commit
40e5c4f41f
@ -8,7 +8,7 @@ Display the daily scripture from [https://github.com/trueChristian/daily-scriptu
|
||||
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
|
||||
+ *Name*: [Dailyscripture](https://www.vdm.io/)
|
||||
+ *First Build*: 22nd October, 2015
|
||||
+ *Last Build*: 4th January, 2022
|
||||
+ *Last Build*: 5th January, 2022
|
||||
+ *Version*: 1.0.0
|
||||
+ *Copyright*: Copyright (C) 2015. All Rights Reserved
|
||||
+ *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
267
helper.php
267
helper.php
@ -30,12 +30,44 @@ use Joomla\Registry\Registry;
|
||||
class ModDailyScriptureHelper
|
||||
{
|
||||
/**
|
||||
* Scripture
|
||||
* Params
|
||||
*
|
||||
* @var array
|
||||
* @var Registry
|
||||
* @since 1.0
|
||||
*/
|
||||
protected $scripture;
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* Scripture
|
||||
*
|
||||
* @var mix
|
||||
* @since 1.0
|
||||
*/
|
||||
protected $scripture = null;
|
||||
|
||||
/**
|
||||
* Type
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Telegram ID = Date
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0
|
||||
*/
|
||||
protected $telegramID = 440;
|
||||
|
||||
/**
|
||||
* Telegram Date = ID
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0
|
||||
*/
|
||||
protected $telegramDate = 1640995200;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -46,12 +78,25 @@ class ModDailyScriptureHelper
|
||||
*/
|
||||
public function __construct(Registry $params = null)
|
||||
{
|
||||
// set the global params
|
||||
$this->params = $params;
|
||||
// get the version
|
||||
$version = $params->get('version', 'kjv');
|
||||
// the link to the scripture for the day
|
||||
$path = "https://raw.githubusercontent.com/trueChristian/daily-scripture/master/scripture/$version/README.json";
|
||||
// get the scripture object
|
||||
$this->scripture = $this->getFileContents($path);
|
||||
$this->type = $params->get('type', 1);
|
||||
// implementation type = 1 = gitHub
|
||||
if ($this->type == 1)
|
||||
{
|
||||
// get the version
|
||||
$version = $params->get('version', 'kjv');
|
||||
// the link to the scripture for the day
|
||||
$path = "https://raw.githubusercontent.com/trueChristian/daily-scripture/master/scripture/$version/README.json";
|
||||
// get the scripture object
|
||||
$this->scripture = $this->getFileContents($path);
|
||||
}
|
||||
// implementation type = 2 = Telegram
|
||||
elseif ($this->type == 2)
|
||||
{
|
||||
$this->setTelegram();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,13 +110,193 @@ class ModDailyScriptureHelper
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if ($this->checkScripture($name))
|
||||
if ($this->type == 1 && $this->checkScripture($name))
|
||||
{
|
||||
return $this->scripture->{$name};
|
||||
}
|
||||
elseif ($this->type == 2 && $name === 'telegram' && isset($this->telegram))
|
||||
{
|
||||
return $this->telegram;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the Telegram script
|
||||
*
|
||||
* @return string data-color values
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
protected function setTelegram()
|
||||
{
|
||||
// get today
|
||||
$today = time();
|
||||
// get the difference
|
||||
$difference = $today - $this->telegramDate;
|
||||
// get the number of days
|
||||
$days = round($difference / (60 * 60 * 24));
|
||||
// add the days
|
||||
$day = $this->telegramID + $days;
|
||||
// validate the ID
|
||||
if (($id = $this->validateID($day)) > 0)
|
||||
{
|
||||
// get the width
|
||||
$width = $this->params->get('width', 100);
|
||||
// get the color
|
||||
$color = $this->getColor();
|
||||
// get the userpic
|
||||
$userpic = $this->getUserPic();
|
||||
// get the dark theme
|
||||
$dark = $this->getDarkTheme();
|
||||
// set the script
|
||||
$this->telegram = "<script async src=\"https://telegram.org/js/telegram-widget.js?15\" data-telegram-post=\"daily_scripture/$id\" data-width=\"$width%\"${color}${userpic}${dark}></script>";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* validate the current ID of the post
|
||||
*
|
||||
* @return int the post ID
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
protected function validateID($id)
|
||||
{
|
||||
// url to post
|
||||
$post_url = "https://t.me/daily_scripture/$id?embed=1";
|
||||
// try to get post (painful work around because of an ugly API)
|
||||
if (($post = $this->getFileContents($post_url, false)) !== false && strpos($post, 'tgme_widget_message_error') === false)
|
||||
{
|
||||
return $id;
|
||||
}
|
||||
// try again
|
||||
if ($id > 0)
|
||||
{
|
||||
return $this->validateID(--$id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the color
|
||||
*
|
||||
* @return string The telegram script
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
protected function getColor()
|
||||
{
|
||||
// get the color
|
||||
$color = $this->params->get('color', 1);
|
||||
// convert to color
|
||||
switch($color)
|
||||
{
|
||||
case 2:
|
||||
// Cyan
|
||||
$color = '13B4C6';
|
||||
$dark_color = '39C4E8';
|
||||
break;
|
||||
case 3:
|
||||
// Green
|
||||
$color = '29B127';
|
||||
$dark_color = '72E350';
|
||||
break;
|
||||
case 4:
|
||||
// Yellow
|
||||
$color = 'CA9C0E';
|
||||
$dark_color = 'F0B138';
|
||||
break;
|
||||
case 5:
|
||||
// Red
|
||||
$color = 'E22F38';
|
||||
$dark_color = 'F95C54';
|
||||
break;
|
||||
case 6:
|
||||
// White
|
||||
$color = '343638';
|
||||
$dark_color = 'FFFFFF';
|
||||
break;
|
||||
case 7:
|
||||
// custom color
|
||||
$color = strtoupper(trim($this->params->get('custom_color', 'F646A4'), '#'));
|
||||
$dark_color = null;
|
||||
break;
|
||||
default:
|
||||
// default
|
||||
$color = null;
|
||||
$dark_color = null;
|
||||
break;
|
||||
}
|
||||
// load colors if set
|
||||
if ($color)
|
||||
{
|
||||
$color = " data-color=\"$color\"";
|
||||
// load dark color if set
|
||||
if ($dark_color)
|
||||
{
|
||||
$color = "$color data-dark-color=\"$dark_color\"";
|
||||
}
|
||||
return $color;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* get the user pic state
|
||||
*
|
||||
* @return string data-userpic value
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
protected function getUserPic()
|
||||
{
|
||||
// get the author_photo
|
||||
$author_photo = $this->params->get('author_photo', 1);
|
||||
// convert to userpic
|
||||
switch($author_photo)
|
||||
{
|
||||
case 2:
|
||||
// Always show
|
||||
$userpic = 'true';
|
||||
break;
|
||||
case 3:
|
||||
// Always hide
|
||||
$userpic = 'false';
|
||||
break;
|
||||
default:
|
||||
// Auto
|
||||
$userpic = null;
|
||||
break;
|
||||
}
|
||||
// load userpic if set
|
||||
if ($userpic)
|
||||
{
|
||||
$userpic = " data-userpic=\"$userpic\"";
|
||||
return $userpic;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* get the dark theme state
|
||||
*
|
||||
* @return string data-dark value
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
protected function getDarkTheme()
|
||||
{
|
||||
// get the theme
|
||||
$theme = $this->params->get('theme', 1);
|
||||
// only load if dark theme is set
|
||||
if ($theme == 2)
|
||||
{
|
||||
return " data-dark=\"1\"";
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* get the file content
|
||||
*
|
||||
@ -81,15 +306,22 @@ class ModDailyScriptureHelper
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
protected function getFileContents($path)
|
||||
protected function getFileContents($path, $json = true)
|
||||
{
|
||||
// use basic file get content for now
|
||||
if (($content = @file_get_contents($path)) !== FALSE)
|
||||
{
|
||||
// return if found
|
||||
if ($this->checkJson($content))
|
||||
if ($json)
|
||||
{
|
||||
return json_decode($content);
|
||||
if ($this->checkJson($content))
|
||||
{
|
||||
return json_decode($content);
|
||||
}
|
||||
}
|
||||
elseif ($this->checkString($content))
|
||||
{
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
// use curl if available
|
||||
@ -110,9 +342,16 @@ class ModDailyScriptureHelper
|
||||
// close the connection
|
||||
curl_close($ch);
|
||||
// return if found
|
||||
if ($this->checkJson($content))
|
||||
if ($json)
|
||||
{
|
||||
return json_decode($content);
|
||||
if ($this->checkJson($content))
|
||||
{
|
||||
return json_decode($content);
|
||||
}
|
||||
}
|
||||
elseif ($this->checkString($content))
|
||||
{
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -2,7 +2,28 @@ MOD_DAILYSCRIPTURE="Dailyscripture"
|
||||
MOD_DAILYSCRIPTURE_DESCRIPTION="Display the daily scripture from https://github.com/trueChristian/daily-scripture."
|
||||
MOD_DAILYSCRIPTURE_XML_DESCRIPTION="<h1>Dailyscripture (v.1.0.0)</h1> <div style='clear: both;'></div><p>Display the daily scripture from https://github.com/trueChristian/daily-scripture.</p><p>Created by <a href='https://www.vdm.io/' target='_blank'>Llewellyn van der Merwe</a><br /><small>Development started 1st January, 2022</small></p>"
|
||||
MOD_DAILYSCRIPTURE_THERE_WAS_AN_ERROR_PLEASE_TRY_AGAIN_LATTER="There was an error, please try again latter."
|
||||
MOD_DAILYSCRIPTURE_TYPE_LABEL="Implementation Type"
|
||||
MOD_DAILYSCRIPTURE_TYPE_DESCRIPTION="What kind of implementation would you like to use. Direct from gitHub the main source, or directly from Telegram its official channel"
|
||||
MOD_DAILYSCRIPTURE_DIRECT_FROM_GITHUB="Direct from gitHub"
|
||||
MOD_DAILYSCRIPTURE_DIRECT_FROM_TELEGRAM="Direct from Telegram"
|
||||
MOD_DAILYSCRIPTURE_LINK_LABEL="Show Link"
|
||||
MOD_DAILYSCRIPTURE_LINK_DESCRIPTION="Should we show the link to the daily scripture channel on Telegram."
|
||||
MOD_DAILYSCRIPTURE_YES="Yes"
|
||||
MOD_DAILYSCRIPTURE_NO="No"
|
||||
MOD_DAILYSCRIPTURE_NO="No"
|
||||
MOD_DAILYSCRIPTURE_WIDTH_LABEL="Width"
|
||||
MOD_DAILYSCRIPTURE_AUTHOR_PHOTO_LABEL="Author Photo"
|
||||
MOD_DAILYSCRIPTURE_AUTO="Auto"
|
||||
MOD_DAILYSCRIPTURE_ALWAYS_SHOW="Always show"
|
||||
MOD_DAILYSCRIPTURE_ALWAYS_HIDE="Always hide"
|
||||
MOD_DAILYSCRIPTURE_COLOR_LABEL="Color"
|
||||
MOD_DAILYSCRIPTURE_DEFAULT="Default"
|
||||
MOD_DAILYSCRIPTURE_CYAN="Cyan"
|
||||
MOD_DAILYSCRIPTURE_GREEN="Green"
|
||||
MOD_DAILYSCRIPTURE_YELLOW="Yellow"
|
||||
MOD_DAILYSCRIPTURE_RED="Red"
|
||||
MOD_DAILYSCRIPTURE_WHITE="White"
|
||||
MOD_DAILYSCRIPTURE_CUSTOM="Custom"
|
||||
MOD_DAILYSCRIPTURE_CUSTOM_COLOR_LABEL="Custom Color"
|
||||
MOD_DAILYSCRIPTURE_THEME_LABEL="Theme"
|
||||
MOD_DAILYSCRIPTURE_LIGHT_THEME="Light Theme"
|
||||
MOD_DAILYSCRIPTURE_DARK_THEME="Dark Theme"
|
@ -2,7 +2,28 @@ MOD_DAILYSCRIPTURE="Dailyscripture"
|
||||
MOD_DAILYSCRIPTURE_DESCRIPTION="Display the daily scripture from https://github.com/trueChristian/daily-scripture."
|
||||
MOD_DAILYSCRIPTURE_XML_DESCRIPTION="<h1>Dailyscripture (v.1.0.0)</h1> <div style='clear: both;'></div><p>Display the daily scripture from https://github.com/trueChristian/daily-scripture.</p><p>Created by <a href='https://www.vdm.io/' target='_blank'>Llewellyn van der Merwe</a><br /><small>Development started 1st January, 2022</small></p>"
|
||||
MOD_DAILYSCRIPTURE_THERE_WAS_AN_ERROR_PLEASE_TRY_AGAIN_LATTER="There was an error, please try again latter."
|
||||
MOD_DAILYSCRIPTURE_TYPE_LABEL="Implementation Type"
|
||||
MOD_DAILYSCRIPTURE_TYPE_DESCRIPTION="What kind of implementation would you like to use. Direct from gitHub the main source, or directly from Telegram its official channel"
|
||||
MOD_DAILYSCRIPTURE_DIRECT_FROM_GITHUB="Direct from gitHub"
|
||||
MOD_DAILYSCRIPTURE_DIRECT_FROM_TELEGRAM="Direct from Telegram"
|
||||
MOD_DAILYSCRIPTURE_LINK_LABEL="Show Link"
|
||||
MOD_DAILYSCRIPTURE_LINK_DESCRIPTION="Should we show the link to the daily scripture channel on Telegram."
|
||||
MOD_DAILYSCRIPTURE_YES="Yes"
|
||||
MOD_DAILYSCRIPTURE_NO="No"
|
||||
MOD_DAILYSCRIPTURE_NO="No"
|
||||
MOD_DAILYSCRIPTURE_WIDTH_LABEL="Width"
|
||||
MOD_DAILYSCRIPTURE_AUTHOR_PHOTO_LABEL="Author Photo"
|
||||
MOD_DAILYSCRIPTURE_AUTO="Auto"
|
||||
MOD_DAILYSCRIPTURE_ALWAYS_SHOW="Always show"
|
||||
MOD_DAILYSCRIPTURE_ALWAYS_HIDE="Always hide"
|
||||
MOD_DAILYSCRIPTURE_COLOR_LABEL="Color"
|
||||
MOD_DAILYSCRIPTURE_DEFAULT="Default"
|
||||
MOD_DAILYSCRIPTURE_CYAN="Cyan"
|
||||
MOD_DAILYSCRIPTURE_GREEN="Green"
|
||||
MOD_DAILYSCRIPTURE_YELLOW="Yellow"
|
||||
MOD_DAILYSCRIPTURE_RED="Red"
|
||||
MOD_DAILYSCRIPTURE_WHITE="White"
|
||||
MOD_DAILYSCRIPTURE_CUSTOM="Custom"
|
||||
MOD_DAILYSCRIPTURE_CUSTOM_COLOR_LABEL="Custom Color"
|
||||
MOD_DAILYSCRIPTURE_THEME_LABEL="Theme"
|
||||
MOD_DAILYSCRIPTURE_LIGHT_THEME="Light Theme"
|
||||
MOD_DAILYSCRIPTURE_DARK_THEME="Dark Theme"
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension type="module" version="4" client="site" method="upgrade">
|
||||
<name>MOD_DAILYSCRIPTURE</name>
|
||||
<creationDate>4th January, 2022</creationDate>
|
||||
<creationDate>5th January, 2022</creationDate>
|
||||
<author>Llewellyn van der Merwe</author>
|
||||
<authorEmail>joomla@vdm.io</authorEmail>
|
||||
<authorUrl>https://www.vdm.io/</authorUrl>
|
||||
@ -36,6 +36,21 @@
|
||||
addrulepath="/modules/mod_dailyscripture/rules"
|
||||
addfieldpath="/modules/mod_dailyscripture/fields"
|
||||
>
|
||||
<!-- Type Field. Type: List. (joomla) -->
|
||||
<field
|
||||
type="list"
|
||||
name="type"
|
||||
label="MOD_DAILYSCRIPTURE_TYPE_LABEL"
|
||||
description="MOD_DAILYSCRIPTURE_TYPE_DESCRIPTION"
|
||||
class="list_class"
|
||||
multiple="false"
|
||||
default="1">
|
||||
<!-- Option Set. -->
|
||||
<option value="1">
|
||||
MOD_DAILYSCRIPTURE_DIRECT_FROM_GITHUB</option>
|
||||
<option value="2">
|
||||
MOD_DAILYSCRIPTURE_DIRECT_FROM_TELEGRAM</option>
|
||||
</field>
|
||||
<!-- Link Field. Type: Radio. (joomla) -->
|
||||
<field
|
||||
type="radio"
|
||||
@ -43,13 +58,90 @@
|
||||
label="MOD_DAILYSCRIPTURE_LINK_LABEL"
|
||||
description="MOD_DAILYSCRIPTURE_LINK_DESCRIPTION"
|
||||
class="btn-group btn-group-yesno"
|
||||
default="1">
|
||||
default="1"
|
||||
showon="type:1">
|
||||
<!-- Option Set. -->
|
||||
<option value="1">
|
||||
MOD_DAILYSCRIPTURE_YES</option>
|
||||
<option value="0">
|
||||
MOD_DAILYSCRIPTURE_NO</option>
|
||||
</field>
|
||||
<!-- Width Field. Type: Number. (joomla) -->
|
||||
<field
|
||||
type="number"
|
||||
name="width"
|
||||
label="MOD_DAILYSCRIPTURE_WIDTH_LABEL"
|
||||
default="100"
|
||||
class="text_area"
|
||||
min="10"
|
||||
max="100"
|
||||
step="10"
|
||||
showon="type:2"
|
||||
/>
|
||||
<!-- Author_photo Field. Type: List. (joomla) -->
|
||||
<field
|
||||
type="list"
|
||||
name="author_photo"
|
||||
label="MOD_DAILYSCRIPTURE_AUTHOR_PHOTO_LABEL"
|
||||
class="list_class"
|
||||
multiple="false"
|
||||
default="1"
|
||||
showon="type:2">
|
||||
<!-- Option Set. -->
|
||||
<option value="1">
|
||||
MOD_DAILYSCRIPTURE_AUTO</option>
|
||||
<option value="2">
|
||||
MOD_DAILYSCRIPTURE_ALWAYS_SHOW</option>
|
||||
<option value="3">
|
||||
MOD_DAILYSCRIPTURE_ALWAYS_HIDE</option>
|
||||
</field>
|
||||
<!-- Color Field. Type: List. (joomla) -->
|
||||
<field
|
||||
type="list"
|
||||
name="color"
|
||||
label="MOD_DAILYSCRIPTURE_COLOR_LABEL"
|
||||
class="list_class"
|
||||
multiple="false"
|
||||
default="1"
|
||||
showon="type:2">
|
||||
<!-- Option Set. -->
|
||||
<option value="1">
|
||||
MOD_DAILYSCRIPTURE_DEFAULT</option>
|
||||
<option value="2">
|
||||
MOD_DAILYSCRIPTURE_CYAN</option>
|
||||
<option value="3">
|
||||
MOD_DAILYSCRIPTURE_GREEN</option>
|
||||
<option value="4">
|
||||
MOD_DAILYSCRIPTURE_YELLOW</option>
|
||||
<option value="5">
|
||||
MOD_DAILYSCRIPTURE_RED</option>
|
||||
<option value="6">
|
||||
MOD_DAILYSCRIPTURE_WHITE</option>
|
||||
<option value="7">
|
||||
MOD_DAILYSCRIPTURE_CUSTOM</option>
|
||||
</field>
|
||||
<!-- Custom_color Field. Type: Color. (joomla) -->
|
||||
<field
|
||||
type="color"
|
||||
name="custom_color"
|
||||
default="1"
|
||||
label="MOD_DAILYSCRIPTURE_CUSTOM_COLOR_LABEL"
|
||||
showon="type:2[AND]color:7"
|
||||
/>
|
||||
<!-- Theme Field. Type: Radio. (joomla) -->
|
||||
<field
|
||||
type="radio"
|
||||
name="theme"
|
||||
label="MOD_DAILYSCRIPTURE_THEME_LABEL"
|
||||
class="btn-group btn-group-yesno"
|
||||
default="1"
|
||||
showon="type:2">
|
||||
<!-- Option Set. -->
|
||||
<option value="1">
|
||||
MOD_DAILYSCRIPTURE_LIGHT_THEME</option>
|
||||
<option value="2">
|
||||
MOD_DAILYSCRIPTURE_DARK_THEME</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
|
@ -37,8 +37,11 @@ defined('_JEXEC') or die('Restricted access');
|
||||
<?php if ($params->get('link', 1) == 1): ?>
|
||||
<a href="https://t.me/s/<?php echo $today->telegram; ?>" target="_blank"><?php echo $today->date; ?></a>
|
||||
<?php else: ?>
|
||||
<br />
|
||||
<?php echo $today->date; ?>
|
||||
<?php endif; ?>
|
||||
<?php elseif ($params->get('type', 1) == 2 && $today->telegram): ?>
|
||||
<?php echo $today->telegram; ?>
|
||||
<?php else: ?>
|
||||
<?php echo JText::_('MOD_DAILYSCRIPTURE_THERE_WAS_AN_ERROR_PLEASE_TRY_AGAIN_LATTER'); ?>
|
||||
<?php endif; ?>
|
||||
|
Loading…
Reference in New Issue
Block a user