diff --git a/README.md b/README.md index 91152ba..f2d2e77 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/helper.php b/helper.php index 9c7fb0a..769c386 100644 --- a/helper.php +++ b/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 = ""; + } + } + + /** + * 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; diff --git a/language/en-GB/en-GB.mod_dailyscripture.ini b/language/en-GB/en-GB.mod_dailyscripture.ini index 7bc8bc4..b160dc3 100644 --- a/language/en-GB/en-GB.mod_dailyscripture.ini +++ b/language/en-GB/en-GB.mod_dailyscripture.ini @@ -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="

Dailyscripture (v.1.0.0)

Display the daily scripture from https://github.com/trueChristian/daily-scripture.

Created by Llewellyn van der Merwe
Development started 1st January, 2022

" 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" \ No newline at end of file +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" \ No newline at end of file diff --git a/language/en-GB/en-GB.mod_dailyscripture.sys.ini b/language/en-GB/en-GB.mod_dailyscripture.sys.ini index 7bc8bc4..b160dc3 100644 --- a/language/en-GB/en-GB.mod_dailyscripture.sys.ini +++ b/language/en-GB/en-GB.mod_dailyscripture.sys.ini @@ -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="

Dailyscripture (v.1.0.0)

Display the daily scripture from https://github.com/trueChristian/daily-scripture.

Created by Llewellyn van der Merwe
Development started 1st January, 2022

" 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" \ No newline at end of file +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" \ No newline at end of file diff --git a/mod_dailyscripture.xml b/mod_dailyscripture.xml index 1e479fe..d0a63ea 100644 --- a/mod_dailyscripture.xml +++ b/mod_dailyscripture.xml @@ -1,7 +1,7 @@ MOD_DAILYSCRIPTURE - 4th January, 2022 + 5th January, 2022 Llewellyn van der Merwe joomla@vdm.io https://www.vdm.io/ @@ -36,6 +36,21 @@ addrulepath="/modules/mod_dailyscripture/rules" addfieldpath="/modules/mod_dailyscripture/fields" > + + + + + + + default="1" + showon="type:1"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tmpl/default.php b/tmpl/default.php index ff8835e..7c28f8a 100644 --- a/tmpl/default.php +++ b/tmpl/default.php @@ -37,8 +37,11 @@ defined('_JEXEC') or die('Restricted access'); get('link', 1) == 1): ?> date; ?> +
date; ?> +get('type', 1) == 2 && $today->telegram): ?> + telegram; ?>