Skip to content

Commit

Permalink
Version 1 completed
Browse files Browse the repository at this point in the history
  • Loading branch information
gmansillo committed May 7, 2018
1 parent 9c42845 commit e31bec0
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 84 deletions.
74 changes: 37 additions & 37 deletions helper.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
<?php
/**
* @package Saint Of The Day
* @license GNU/GPL, see LICENSE.php
* @link https:// github.com/gmansillo/saintoftheday
*/
* @package Module Saint Of The Day for Joomla!
* @author Giovanni Mansillo
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
* @link https:// github.com/gmansillo/saintoftheday
*
**/

class ModSaintOfTheDayHelper
{
/**
* Retrieves contents via Evangelizo.org APIs
*
* @param type Inform about what you want to get
* @access public
*/
public static function getAPIFormattedLanguage() {
private static function translateISOLangToAPIFormat($iso_lang = 'en-GB') {

$result = "AM";
$iso_lang = strtolower($iso_lang);
$iso_lang = explode("-", $iso_lang);
$iso_lang = $iso_lang[0];

$lang = null;
$jlang = JFactory::getLanguage();
$apilang = array(
'' => 'AM', // american-us
'' => 'AR', // arabic
'' => 'DE', // german
'' => 'FR', // french
'' => 'GR', // greek (hellenic)
'' => 'IT', // italian
'' => 'MG', // malagasy
'' => 'NL', // dutch
'' => 'PL', // polish
'' => 'PT', // portuges
'' => 'SP', // spanish
'' => 'ARM' // armenian
'en' => 'AM', // american-us
'ar' => 'AR', // arabic
'de' => 'DE', // german
'fr' => 'FR', // french
'el' => 'GR', // greek (hellenic)
'it' => 'IT', // italian
'mg' => 'MG', // malagasy
'nl' => 'NL', // dutch
'pl' => 'PL', // polish
'pt' => 'PT', // portuges
'es' => 'SP', // spanish
'hy' => 'ARM' // armenian
);

if(array_key_exists($jlang, $apilang)) {
$lang = apilang[$jlang];
if(array_key_exists($iso_lang, $apilang)) {
$result = $apilang[$iso_lang];
}

return $lang;
return $result;
}

/**
Expand All @@ -45,25 +44,26 @@ public static function getAPIFormattedLanguage() {
* @param type Inform about what you want to get
* @access public
*/
public static function getDataFromAPI($type = 'saint', $lang = 'AM') {
public static function getDataFromAPI($type = 'saint', $lang = 'en-GB') {

$result = false;

$lang = self::translateISOLangToAPIFormat($lang);
$date = date("Ymd");
$url = "http:// feed.evangelizo.org/v2/reader.php?type=$type&lang=$lang&date=$date";
$url = "http://feed.evangelizo.org/v2/reader.php?date=$date&type=$type&lang=$lang";

if(extension_loaded('curl') && function_exists('curl_init')) {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);

} else {

$stream = fopen($url, 'r');
curl_close($ch);

} else if ($stream = fopen($url, 'r')) {
// fopen fallback
$result = stream_get_contents($stream);
fclose($stream);

}

return $result;
Expand Down
26 changes: 16 additions & 10 deletions mod_saintoftheday.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<?php
/**
* @package Saint Of The Day
* @license GNU/GPL, see LICENSE.php
* @link https:// github.com/gmansillo/saintoftheday
*/
* @package Module Saint Of The Day for Joomla!
* @author Giovanni Mansillo
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
* @link https:// github.com/gmansillo/saintoftheday
*
**/

// No direct access
defined('_JEXEC') or die;

jimport( 'joomla.application.module.helper' );

// Include the syndicate functions only once
require_once dirname(__FILE__) . '/helper.php';

require JModuleHelper::getLayoutPath('mod_saintoftheday');
$module = JModuleHelper::getModule('mod_saintoftheday');
$lang = JFactory::getLanguage()->getTag();
$params = new JRegistry();
$params->loadString($module->params);

$sod_title = ModSaintOfTheDayHelper::getDataFromAPI('liturgic_t', $lang);
$sod_list = ModSaintOfTheDayHelper::getDataFromAPI('saint', $lang);

$lang = ModSaintOfTheDayHelper::getAPIFormattedLanguage();
$params = JFactory::getParams('mod_saintoftheday');

if($params->get('show_title')) { $sod_title = ModSaintOfTheDayHelper::getDataFromAPI('liturgic_t', $lang); }
if($params->get('show_list')) { $sod_list = ModSaintOfTheDayHelper::getDataFromAPI('saint', $lang); }
require_once JModuleHelper::getLayoutPath('mod_saintoftheday');
33 changes: 2 additions & 31 deletions mod_saintoftheday.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,13 @@
<name>Saint Of The Day</name>
<author>Giovanni Mansillo</author>
<version>1.0.0</version>
<license>GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
<authorUrl>https:// github.com/gmansillo/saintoftheday</authorUrl>
<files>
<filename>mod_saintoftheday.xml</filename>
<filename module="mod_saintoftheday">mod_saintoftheday.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<folder>tmpl</folder>
<folder>lang</folder>
</files>
<config>
<field
name="show_title"
type="radio"
class="radio btn-group btn-group-yesno"
default="1"
label="MOD_SAINTOFTHEDAY_SHOW_TITLE_LABEL"
description="MOD_SAINTOFTHEDAY_SHOW_TITLE_DESC">
<option
value="1">JSHOW</option>
<option
value="0">JHIDE</option>
</field>
<field
name="show_list"
type="radio"
class="radio btn-group btn-group-yesno"
default="1"
label="MOD_SAINTOFTHEDAY_SHOW_LIST_LABEL"
description="MOD_SAINTOFTHEDAY_SHOW_LIST_DESC">
<option
value="1">JSHOW</option>
<option
value="0">JHIDE</option>
</field>

<!-- *' - « saint » : to get the saint of the day (with link to life)
*' - « liturgic_t » : to get the liturgic title -->
</config>

</extension>
21 changes: 15 additions & 6 deletions tmpl/default.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<?php
/**
* @package Saint Of The Day
* @license GNU/GPL, see LICENSE.php
* @link https:// github.com/gmansillo/saintoftheday
*/
* @package Module Saint Of The Day for Joomla!
* @author Giovanni Mansillo
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
* @link https:// github.com/gmansillo/saintoftheday
*
**/

// No direct access
defined('_JEXEC') or die;

if ($sod_title) echo '<p class="sod_title">'.$sod_title.'</p>';
if ($sod_list) echo '<p class="sod_list">'.$sod_list.'</p>';
?>

<p class="sod_title">
<?php echo $sod_title; ?>
</p>

<p class="sod_list">
<?php echo $sod_list; ?>
</p>

0 comments on commit e31bec0

Please sign in to comment.