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