-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
79 lines (61 loc) · 2.8 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Plugin Name: Islam Daily Hadith (The Prophet Muhammad (SMAWA) and all 12 Imam Speech)
* Plugin URI: https://islamplus.net
* Description: This Plugin Developed for Free To showing Daily Shia Hadith On Wordpress Website
* Version: 0.0.1
* Author: Saber tabatabaee yazdi
* Author URI: https://github.com/saber13812002
*/
add_shortcode('islamplus_hadith', 'islamplusHadithController');
function islamplusHadithController($attr)
{
$context = isset($attr['context']) ? $attr['context'] : "hadith";
$language = isset($attr['language']) ? $attr['language'] : "arabic";
$theme = isset($attr['theme']) ? $attr['theme'] : "default";
$shortcode = getHaditByCallApi($context, $language, $theme);
/**
* To use it in php file (e.g. theme) use do_shortcode
* Usage example: echo do_shortcode("[sample_shortcode input_1='Windows XP']");
*/
return $shortcode;
}
function getHaditByCallApi($context, $language, $theme)
{
// create & initialize a curl session
$curl = curl_init();
// set our url with curl_setopt()
$url = "http://api.islamplus.net/api/" . $context . "/list?count=1&lang=fa";
curl_setopt($curl, CURLOPT_URL, $url);
// return the transfer as a string, also with setopt()
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
global $wp;
$current_url = home_url(add_query_arg(array(), $wp->request));
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'random: true',
'category: ethics',
'type: ' . $context,
'language: ' . $language,
'redirect_url: ' . $current_url,
'Content-Type: application/json',
));
// curl_exec() executes the started curl session
// $output contains the output string
$output = curl_exec($curl);
// close curl resource to free up system resources
// (deletes the variable made by curl_init)
curl_close($curl);
$islamplusHadithResponse = json_decode($output);
$islamplusHadith = $islamplusHadithResponse->Hadith[0];
$shortcode = "<p>";
$shortcode .= "$islamplusHadith->ArabicText <br>";
// $shortcode .= "<a href=$islamplusHadith->url/?redirect_url=$current_url> $islamplusHadith->Persian </a> <br>";
$shortcode .= "<a href=https://islamplus.net/English/hadithposter?hadithID=$islamplusHadith->HadithID&device=Mobile&lang=Persian> $islamplusHadith->Persian </a> <br>";
// $shortcode .= "<a href=$islamplusHadith->author_link>$islamplusHadith->author ";
// $shortcode .= " islamplus </a><br>";
// $shortcode .= "$islamplusHadith->text <br>";
// $shortcode .= "<a href=$islamplusHadith->author_link>$islamplusHadith->author </a> <br>";
// $shortcode .= "<a href=$islamplusHadith->resource_link/?redirect_url=$islamplusHadith->redirect_url>$islamplusHadith->resource </a><br>";
$shortcode .= "</p>";
return $shortcode;
}