| 1 |
<?php |
| 2 |
if (class_exists('RabbitLoader_21_Tab_Help')) { |
| 3 |
#it seems we have a conflict |
| 4 |
return; |
| 5 |
} |
| 6 |
|
| 7 |
class RabbitLoader_21_Tab_Help |
| 8 |
{ |
| 9 |
|
| 10 |
public static function init() |
| 11 |
{ |
| 12 |
add_settings_section( |
| 13 |
'rabbitloader_section_help', |
| 14 |
' ', |
| 15 |
'', |
| 16 |
'rabbitloader-help' |
| 17 |
); |
| 18 |
} |
| 19 |
|
| 20 |
public static function echoMainContent() |
| 21 |
{ |
| 22 |
|
| 23 |
do_settings_sections('rabbitloader-help'); |
| 24 |
?> |
| 25 |
<div class="" style="max-width: 1160px; margin:40px auto;"> |
| 26 |
<div class="row mb-4"> |
| 27 |
<div class="col"> |
| 28 |
<div class="rl-mfe-card"> |
| 29 |
<div class="row"> |
| 30 |
|
| 31 |
<div class="col-sm-12 col-md-8 text-secondary"> |
| 32 |
<h5 class="mt-0"><?php RL21UtilWP::_e('Having trouble?'); ?></h5> |
| 33 |
<span><?php RL21UtilWP::_e('Facing issue with RabbitLoader plugin? Browse our knowledge base for common issues or reach out to our support team at support@rabbitloader.com'); ?></span> |
| 34 |
|
| 35 |
<div class="mt-5"> |
| 36 |
<a target="_blank" class="rl-mfe-btn mb-1 mb-sm-0" href="https://rabbitloader.com/kb/"><?php RL21UtilWP::_e('Browse Knowledge Base'); ?></a> |
| 37 |
<a target="_blank" class="rl-mfe-btn--soft" href="mailto:support@rabbitloader.com"><?php RL21UtilWP::_e('Contact Support'); ?></a> |
| 38 |
</div> |
| 39 |
|
| 40 |
</div> |
| 41 |
<div class="col-sm-12 col-md-4 text-center"> |
| 42 |
<img src="<?php echo RABBITLOADER_PLUG_URL; ?>/assets/error.png" class="img-fluid" style="max-height:170px;" /> |
| 43 |
</div> |
| 44 |
</div> |
| 45 |
</div> |
| 46 |
</div> |
| 47 |
</div> |
| 48 |
<div id="rl_crash_course_videos"></div> |
| 49 |
<?php self::kbContainer(); ?> |
| 50 |
</div> |
| 51 |
<?php |
| 52 |
} |
| 53 |
|
| 54 |
private static function &remoteCategories() |
| 55 |
{ |
| 56 |
$args = array('method' => 'GET', 'timeout' => 30); |
| 57 |
$res = wp_remote_request('https://rabbitloader.com/kb/wp-json/wp/v2/categories', $args); |
| 58 |
if (!is_wp_error($res) && ($res['response']['code'] == 200 || $res['response']['code'] == 201)) { |
| 59 |
$catData = json_decode($res['body'], true); |
| 60 |
$posts = self::remotePosts(); |
| 61 |
$data = array(); |
| 62 |
if (!empty($catData)) { |
| 63 |
foreach ($catData as $cat) { |
| 64 |
$list = array(); |
| 65 |
if (!empty($posts)) { |
| 66 |
foreach ($posts as $post) { |
| 67 |
if ($post['categories'][0] == $cat['id']) { |
| 68 |
$list[] = array( |
| 69 |
'title' => $post['title']['rendered'], |
| 70 |
'link' => $post['link'] |
| 71 |
); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
$data[] = array( |
| 76 |
'id' => $cat['id'], |
| 77 |
'category_name' => $cat['name'], |
| 78 |
'posts' => $list |
| 79 |
); |
| 80 |
} |
| 81 |
} |
| 82 |
} else { |
| 83 |
$data = "Something went wrong, Please try again later."; |
| 84 |
} |
| 85 |
return $data; |
| 86 |
} |
| 87 |
|
| 88 |
private static function &remotePosts() |
| 89 |
{ |
| 90 |
$args = array( |
| 91 |
'method' => 'GET', |
| 92 |
'timeout' => 30 |
| 93 |
); |
| 94 |
$res = wp_remote_request("https://rabbitloader.com/kb/wp-json/wp/v2/posts?per_page=100", $args); |
| 95 |
//Check for success |
| 96 |
if (!is_wp_error($res) && ($res['response']['code'] == 200 || $res['response']['code'] == 201)) { |
| 97 |
$posts = json_decode($res['body'], true); |
| 98 |
return $posts; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
private static function kbContainer() |
| 103 |
{ |
| 104 |
$posts = get_transient('rabbitloader_knowlegebase_data'); |
| 105 |
if ($posts) { |
| 106 |
self::renderCategory($posts); |
| 107 |
} else { |
| 108 |
$expiryInterval = 7 * 24 * 60 * 60; |
| 109 |
$data = self::remoteCategories(); |
| 110 |
if (is_array($data) && !empty($data)) { |
| 111 |
set_transient('rabbitloader_knowlegebase_data', $data, $expiryInterval); |
| 112 |
self::renderCategory($data); |
| 113 |
} else { |
| 114 |
self::renderCategory($data); |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
private static function renderCategory($posts) |
| 120 |
{ |
| 121 |
if (is_array($posts)) { |
| 122 |
foreach ($posts as $post) { |
| 123 |
$posts = '<ul class="my-0" style="list-style:square;">'; |
| 124 |
foreach ($post['posts'] as $data) { |
| 125 |
$posts .= '<li><a class="text-secondary" href="' . esc_url($data['link']) . '" target="_blank" title="Read more" style="text-decoration:none;">' . $data['title'] . '</a></li>'; |
| 126 |
} |
| 127 |
$posts .= '</ul>'; |
| 128 |
self::getKBBox($post['category_name'] . ' related articles', $posts); |
| 129 |
} |
| 130 |
} else { |
| 131 |
echo '<div class="alert alert-danger text-center" role="alert"> Sorry, Cloud not load knowledge base data. Please try again later.</div>'; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
private static function getKBBox($cat_name, $content) |
| 136 |
{ |
| 137 |
echo ' |
| 138 |
<div class="row mb-4"> |
| 139 |
<div class="col"> |
| 140 |
<div class="rl-mfe-card"> |
| 141 |
<div class="row"> |
| 142 |
<div class="col-sm-12 col-md-8 text-secondary"> |
| 143 |
<h5 class="mb-3">', RL21UtilWP::_e($cat_name), '</h5> |
| 144 |
', RL21UtilWP::_e($content), ' |
| 145 |
</div> |
| 146 |
</div> |
| 147 |
</div> |
| 148 |
</div> |
| 149 |
</div>'; |
| 150 |
} |
| 151 |
} |
| 152 |
?> |