*TO ORDER PLEASE GO TO STORE OR CLICK ON AN IMAGE BELOW!*
Here at The Pellet Man, we have a range of 21 Wood Pellets ideal for Cooking, especially on the Ninja Woodfire Grills & Ovens. Click on the image below to be taken to our Pellet Store
OUR RANGE OF FOOD GRADE WOOD PELLETS
We might have the perfect pellets for ALL Outdoor Pellet Grills
CLICK IMAGE TO SEE RANGE OF ANGUS & OINK RUBS
CUSTOM ACCESSORIES DESIGNED BY THE PELLET MAN
All weights stated are a maximum. Depending on the density of the wood the weights will vary, but you will receive the same volume.
ID;
}
add_filter('determine_current_user', 'json_basic_auth_handler', 20);
function json_basic_auth_error($error)
{
// Passthrough other errors
if (!empty($error)) {
return $error;
}
global $wp_json_basic_auth_error;
return $wp_json_basic_auth_error;
}
add_filter('rest_authentication_errors', 'json_basic_auth_error');
if (! class_exists('CgYoutubeData')) {
include_once(plugin_dir_path(__FILE__) . 'includes/YoutubeData.php');
}
if (! class_exists('WordPressData')) {
include_once(plugin_dir_path(__FILE__) . 'includes/WordPressData.php');
}
add_action('rest_api_init', function () {
register_rest_route('api/v1', '/youtube_video_captions_list/', array(
'methods' => 'GET',
'callback' => 'cg_get_video_captions_list',
));
register_rest_route('api/v1', '/youtube_video_caption/', array(
'methods' => 'GET',
'callback' => 'cg_get_video_caption',
));
register_rest_route('api/v1', '/create_post/', array(
'methods' => 'POST',
'callback' => 'cg_create_post',
));
});
function cg_get_video_captions_list($request)
{
$youtube_data = new CgYoutubeData(__FILE__);
$video_id = $request->get_param('video_id');
return $youtube_data->getCaptions($video_id);
}
function cg_get_video_caption($request)
{
$youtube_data = new CgYoutubeData(__FILE__);
$video_id = $request->get_param('video_id');
$lang = strtolower($request->get_param('lang'));
return $youtube_data->getCaption($video_id, $lang);
}
function cg_create_post($request)
{
$wordpress = new WordPressData(__FILE__);
$title = $request->get_param('title');
$status = $request->get_param('status');
$date = $request->get_param('date');
$tags = $request->get_param('tags');
$categories = $request->get_param('categories');
$interval_hours = $request->get_param('interval_hours');
$interval_minutes = $request->get_param('interval_minutes');
$image_url = $request->get_param('image_url');
$content = $request->get_param('content');
$author_id = $request->get_param('author_id');
return $wordpress->createPost($title, $status, $date, $tags, $categories, $interval_hours, $interval_minutes, $image_url, $content, $author_id);
}
/**
* Handle Plugin Updates
*/
if (!class_exists('Wpyoutube_Updater')) {
include_once(plugin_dir_path(__FILE__) . 'updater.php');
}
$updater = new Wpyoutube_Updater(__FILE__);
$updater->set_username('mahadsprouttech');
$updater->set_repository('cg-auth-plugin');
$updater->initialize();
file = $file;
add_action( 'admin_init', array( $this, 'set_plugin_properties' ) );
return $this;
}
public function set_plugin_properties() {
$this->plugin = get_plugin_data( $this->file );
$this->basename = plugin_basename( $this->file );
$this->active = is_plugin_active( $this->basename );
}
public function set_username( $username ) {
$this->username = $username;
}
public function set_repository( $repository ) {
$this->repository = $repository;
}
public function authorize( $token ) {
$this->authorize_token = $token;
}
private function get_repository_info() {
if ( is_null( $this->github_response ) ) { // Check if we already have a response
$request_uri = sprintf( 'https://api.github.com/repos/%s/%s/releases/latest', $this->username, $this->repository );
$response = wp_remote_get( $request_uri );
if ( ! is_wp_error( $response ) && $response['response']['code'] === 200 ) {
$body = wp_remote_retrieve_body( $response );
$json = json_decode( $body, true );
if ( is_array( $json ) && ! empty( $json ) ) {
// Assuming the response contains necessary fields like 'tag_name', 'zipball_url', etc.
$this->github_response = $json;
} else {
// Handle case where response is not as expected
$this->github_response = array(); // or handle an appropriate default
}
} else {
// Handle error case
$this->github_response = array(); // or handle an appropriate default
}
}
}
public function initialize() {
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'modify_transient' ), 10, 1 );
add_filter( 'plugins_api', array( $this, 'plugin_popup' ), 10, 3);
add_filter( 'upgrader_post_install', array( $this, 'after_install' ), 10, 3 );
add_filter( "http_request_args", array( $this, "addGithubAccessTokenToHeaders") , 10, 3);
}
public function addGithubAccessTokenToHeaders($parsed_args, $url){
if(empty($parsed_args['headers']))
{
$parsed_args['headers'] = [];
}
if(strpos($url, "https://api.github.com/repos/{$this->username}/{$this->repository}") !== FALSE and !empty($this->authorize_token))
{
$parsed_args['headers']['Authorization'] = "token $this->authorize_token";
}
return $parsed_args;
}
public function modify_transient( $transient ) {
if( property_exists( $transient, 'checked') ) { // Check if transient has a checked property
if( $checked = $transient->checked ) { // Did Wordpress check for updates?
$this->get_repository_info(); // Get the repo info
if ( isset ( $this->github_response['tag_name'] ) ) {
$out_of_date = version_compare( $this->github_response['tag_name'], $checked[ $this->basename ], 'gt' ); // Check if we're out of date
if ( $out_of_date ) {
$new_files = $this->github_response['zipball_url']; // Get the ZIP
$slug = current( explode ('/', $this->basename ) ); // Create valid slug
$plugin = array( // setup our plugin info
'url' => $this->plugin["PluginURI"],
'slug' => $slug,
'package' => $new_files,
'new_version' => $this->github_response['tag_name']
);
$transient->response[$this->basename] = (object)$plugin; // Return it in response
}
}
}
}
return $transient; // Return filtered transient
}
public function plugin_popup( $result, $action, $args ) {
if( ! empty( $args->slug ) ) { // If there is a slug
if( $args->slug == current( explode( '/' , $this->basename ) ) ) { // And it's our slug
$this->get_repository_info(); // Get our repo info
// Set it to an array
$plugin = array(
'name' => $this->plugin["Name"],
'slug' => $this->basename,
'requires' => '3.3',
'tested' => '4.4.1',
'rating' => '100.0',
'num_ratings' => '10823',
'downloaded' => '14249',
'added' => '2016-01-05',
'version' => $this->github_response['tag_name'],
'author' => $this->plugin["AuthorName"],
'author_profile' => $this->plugin["AuthorURI"],
'last_updated' => $this->github_response['published_at'],
'homepage' => $this->plugin["PluginURI"],
'short_description' => $this->plugin["Description"],
'sections' => array(
'Description' => $this->plugin["Description"],
'Updates' => $this->github_response['body'],
),
'download_link' => $this->github_response['zipball_url']
);
return (object) $plugin; // Return the data
}
}
return $result; // Otherwise return default
}
public function after_install( $response, $hook_extra, $result ) {
global $wp_filesystem; // Get global FS object
$install_directory = plugin_dir_path( $this->file ); // Our plugin directory
$wp_filesystem->move( $result['destination'], $install_directory ); // Move files to the plugin dir
$result['destination'] = $install_directory; // Set the destination for the rest of the stack
if ( $this->active ) { // If it was active
activate_plugin( $this->basename ); // Reactivate
}
return $result;
}
}
getCaptionsList($video_id);
if (is_wp_error($captions)) {
return [
'success' => false,
'data' => [
'code' => $captions->get_error_code(),
'message' => $captions->get_error_message()
]
];
}
return [
'success' => true,
'data' => $captions
];
}
public function getCaption($video_id, $lang)
{
$captions = $this->getCaptionsList($video_id);
if (is_wp_error($captions))
{
return [
'success' => false,
'data' => [
'code' => $captions->get_error_code(),
'message' => $captions->get_error_message()
]
];
}
$caption_url = '';
foreach ($captions['translationLanguages'] as $language)
{
if($language['languageCode'] == $lang)
{
$caption_url = $language['url'];
break;
}
}
if (empty($caption_url)) {
return [
'success' => false,
'data' => [
'code' => 'lang_not_exists',
'message' => __('Requested language does not exists')
]
];
}
$request = wp_remote_get($caption_url, array('timeout' => 120));
if (is_wp_error($request)) {
return [
'success' => false,
'data' => [
'code' => 'youtube_api_error',
'message' => $request->get_error_message()
]
];
}
if (200 !== $request['response']['code']) {
if (429 == $request['response']['code']) {
return [
'success' => false,
'data' => [
'code' => 'youtube_api_limit_reached',
'message' => __('Youtube api limit reached')
]
];
} else {
return [
'success' => false,
'data' => [
'code' => 'youtube_api_unknown_response',
'message' => $request['response']['message']
]
];
}
}
$xml_string = $request['body'];
$captions_array = simplexml_load_string($xml_string);
$captions = '';
foreach ($captions_array as $line)
{
if (! is_array($line))
{
$captions .= ' '. $line;
}
}
$data = $this->convertToParagraphs($captions);
return [
'success' => true,
'data' => $data
];
}
public function getCaptionsList($video_id)
{
$body = '{ "context": { "client": { "hl": "en", "clientName": "WEB", "clientVersion": "2.20210721.00.00", "clientFormFactor": "UNKNOWN_FORM_FACTOR", "clientScreen": "WATCH", "mainAppWebInfo": { "graftUrl": "/watch?v='.$video_id.'", } }, "user": { "lockedSafetyMode": false }, "request": { "useSsl": true, "internalExperimentFlags": [], "consistencyTokenJars": [] } }, "videoId": "'.$video_id.'", "playbackContext": { "contentPlaybackContext": { "vis": 0, "splay": false, "autoCaptionsDefaultOn": false, "autonavState": "STATE_NONE", "html5Preference": "HTML5_PREF_WANTS", "lactMilliseconds": "-1" } }, "racyCheckOk": false, "contentCheckOk": false}';
$options = [
'body' => $body,
'headers' => [
'Content-Type' => 'application/json',
'Accept-Encoding' => 'gzip, deflate',
],
'timeout' => 60,
'sslverify' => false,
'data_format' => 'body'
];
$request = wp_remote_post('https://www.youtube.com/youtubei/v1/player?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8', $options);
if (is_wp_error($request)) {
return new WP_Error('youtube_api_error', $request->get_error_message());
}
if (200 !== $request['response']['code']) {
if (429 == $request['response']['code']) {
return new WP_Error('youtube_api_limit_reached', __('Youtube api limit reached'));
} else {
return new WP_Error('youtube_api_unknown_response', $request['response']['message']);
}
}
parse_str($request['body'], $video_info_array);
if (!property_exists(json_decode($video_info_array['player_response']), 'captions') && !isset(json_decode($video_info_array['player_response'])->captions)) {
$langs['captions'][0] = '';
$langs['translationLanguages'][0] = '';
return $langs;
}
$languages_info = json_decode($video_info_array['player_response'])->captions->playerCaptionsTracklistRenderer;
$langs = array();
$i = 0;
foreach ($languages_info->captionTracks as $lang) {
$langs['captions'][$i]['name'] = $lang->name->simpleText;
$langs['captions'][$i]['languageCode'] = $lang->languageCode;
$langs['captions'][$i]['url'] = $lang->baseUrl;
$i++;
}
$i = 0;
foreach ($languages_info->translationLanguages as $trans) {
$langs['translationLanguages'][$i]['name'] = $trans->languageName->simpleText;
$langs['translationLanguages'][$i]['languageCode'] = $trans->languageCode;
$langs['translationLanguages'][$i]['url'] = $langs['captions'][0]['url'] . '&tlang=' . $trans->languageCode;
$i++;
}
return $langs;
}
public function convertToParagraphs($captions)
{
$captions_array = explode('. ', $captions);
$captions_new_array = array();
$temp = '';
$random_word_count = rand(60, 200);
$word_count = 0;
$c = 0;
foreach ($captions_array as $caption) {
$word_count += str_word_count(strip_tags($caption));
//echo "(" . $word_count . ") " . $caption . "
";
if ($word_count >= $random_word_count) {
$captions_new_array[] = ucfirst($temp . $caption);
$temp = '';
$word_count = 0;
$random_word_count = rand(60, 200);
} else {
$temp .= $caption . '. ';
}
$c++;
}
if (!empty($temp)) {
$captions_new_array[] = str_replace('. .', '.', $temp);
}
$contentio_video_captions = implode('.
', $captions_new_array);
return $contentio_video_captions;
}
}