function TS_VCSC_ShowInformation($item_id, $item_vc = true) { global $VISUAL_COMPOSER_EXTENSIONS; if ($item_vc == true || $item_id == "") { $item_id = $VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_API_ItemID; } $api_path = "https://api.envato.com/v2/market/catalog/item?id=" . $item_id; $api_last = get_option('ts_vcsc_extend_settings_envatoCheck', 0); $api_current = time(); $api_data = get_option('ts_vcsc_extend_settings_envatoData', ''); if ($api_data == "" || $api_last + 3600 < $api_current) { /* Fetch data using the WordPress function wp_remote_get() */ if (function_exists('wp_remote_get') && strlen($item_id) != 0) { $response = wp_remote_get($api_path, array('user-agent' => 'Visual Composer Extensions (7190695) by Tekanewa Scripts', 'httpversion' => '1.1', 'headers' => array('Authorization' => 'Bearer ' . $VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_API_Token))); } else { if (function_exists('wp_remote_post') && strlen($item_id) != 0) { $response = wp_remote_post($api_path, array('user-agent' => 'Visual Composer Extensions (7190695) by Tekanewa Scripts', 'httpversion' => '1.1', 'headers' => array('Authorization' => 'Bearer ' . $VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_API_Token))); } } /* Check for errors, if there are some errors return false */ if (is_wp_error($response) or wp_remote_retrieve_response_code($response) != 200) { $item = false; } else { /* Transform the JSON string into a PHP array */ $item = json_decode(wp_remote_retrieve_body($response), true); /* Check for incorrect data */ if (!is_array($item)) { $item = false; } } if ($item == false && $api_data != "") { $item = $api_data; } } else { $item = $api_data; } if ($item === false) { echo '<p style="text-align: justify;">Oops... Something went wrong. Could not retrieve item information from Envato.</p>'; } else { // Parse Item Data $ts_vcsc_extend_envatoItem_Data = array(); $ts_vcsc_extend_envatoItem_Name = isset($item["name"]) ? $item["name"] : "N/A"; $ts_vcsc_extend_envatoItem_User = isset($item["author_username"]) ? $item["author_username"] : "******"; $ts_vcsc_extend_envatoItem_Rating = isset($item["rating"]["rating"]) ? $item["rating"]["rating"] : "N/A"; $ts_vcsc_extend_envatoItem_Votes = isset($item["rating"]["count"]) ? $item["rating"]["count"] : "N/A"; $ts_vcsc_extend_envatoItem_Sales = isset($item["number_of_sales"]) ? $item["number_of_sales"] : "N/A"; $ts_vcsc_extend_envatoItem_Price = isset($item["price_cents"]) ? $item["price_cents"] : "N/A"; $ts_vcsc_extend_envatoItem_Thumb = isset($item["thumbnail_url"]) ? $item["thumbnail_url"] : "N/A"; $ts_vcsc_extend_envatoItem_Link = isset($item["url"]) ? $item["url"] : "N/A"; $ts_vcsc_extend_envatoItem_Release = isset($item["published_at"]) ? $item["published_at"] : "N/A"; $ts_vcsc_extend_envatoItem_Update = isset($item["updated_at"]) ? $item["updated_at"] : "N/A"; $ts_vcsc_extend_envatoItem_Check = time(); // Populate Data Array $ts_vcsc_extend_envatoItem_Data["name"] = $ts_vcsc_extend_envatoItem_Name; $ts_vcsc_extend_envatoItem_Data["author_username"] = $ts_vcsc_extend_envatoItem_User; $ts_vcsc_extend_envatoItem_Data["rating"]["rating"] = $ts_vcsc_extend_envatoItem_Rating; $ts_vcsc_extend_envatoItem_Data["rating"]["count"] = $ts_vcsc_extend_envatoItem_Votes; $ts_vcsc_extend_envatoItem_Data["number_of_sales"] = $ts_vcsc_extend_envatoItem_Sales; $ts_vcsc_extend_envatoItem_Data["price_cents"] = $ts_vcsc_extend_envatoItem_Price; $ts_vcsc_extend_envatoItem_Data["thumbnail_url"] = $ts_vcsc_extend_envatoItem_Thumb; $ts_vcsc_extend_envatoItem_Data["url"] = $ts_vcsc_extend_envatoItem_Link; $ts_vcsc_extend_envatoItem_Data["published_at"] = $ts_vcsc_extend_envatoItem_Release; $ts_vcsc_extend_envatoItem_Data["updated_at"] = $ts_vcsc_extend_envatoItem_Update; // Create HTML Output $ts_vcsc_extend_envatoItem_HTML = ''; $ts_vcsc_extend_envatoItem_HTML .= ' <div class="ts_vcsc_envato_item"> <div class="ts_vcsc_title">' . $ts_vcsc_extend_envatoItem_Name . '</div> <div class="ts_vcsc_wrap"> <div class="ts_vcsc_top"> <div class="ts_vcsc_rating"><span class="ts_vcsc_desc">Rating</span>' . TS_VCSC_GetEnvatoStars(round($ts_vcsc_extend_envatoItem_Rating)) . '</div> </div> <div class="ts_vcsc_middle"> <div class="ts_vcsc_sales"> <span class="ts_vcsc_img_sales"></span> <div class="ts_vcsc_text"> <span class="ts_vcsc_num">' . number_format($ts_vcsc_extend_envatoItem_Sales, 0) . '</span> <span class="ts_vcsc_desc">Sales</span> </div> </div> <div class="ts_vcsc_thumb"> <img src="' . $ts_vcsc_extend_envatoItem_Thumb . '" alt="' . $ts_vcsc_extend_envatoItem_Name . '" width="80" height="80"/> </div> <div class="ts_vcsc_price"> <span class="ts_vcsc_img_price"></span> <div class="ts_vcsc_text"> <span class="ts_vcsc_num"><span>$</span>' . round($ts_vcsc_extend_envatoItem_Price / 100) . '</span> <span class="ts_vcsc_desc">only</span> </div> </div> </div> <div class="ts_vcsc_bottom"> <a href="' . $ts_vcsc_extend_envatoItem_Link . '" target="_blank"></a> </div> </div> </div>'; if ($item_vc == true) { update_option('ts_vcsc_extend_settings_envatoData', $ts_vcsc_extend_envatoItem_Data); update_option('ts_vcsc_extend_settings_envatoInfo', $ts_vcsc_extend_envatoItem_HTML); update_option('ts_vcsc_extend_settings_envatoLink', $ts_vcsc_extend_envatoItem_Link); update_option('ts_vcsc_extend_settings_envatoPrice', $ts_vcsc_extend_envatoItem_Price); update_option('ts_vcsc_extend_settings_envatoRating', TS_VCSC_GetEnvatoStars($ts_vcsc_extend_envatoItem_Rating)); update_option('ts_vcsc_extend_settings_envatoSales', $ts_vcsc_extend_envatoItem_Sales); update_option('ts_vcsc_extend_settings_envatoCheck', $ts_vcsc_extend_envatoItem_Check); } else { echo $ts_vcsc_extend_envatoItem_HTML; } } }
function TS_VCSC_ShowInformation($item_id, $item_vc = true) { if ($item_vc == true) { $item_id = '7190695'; } $item = TS_VCSC_GetItemInfo($item_id); if ($item === false) { return '<p style="text-align: justify;">Oops... Something went wrong. Could not retrieve item information from Envato.</p>'; } $item = $item['item']; extract($item); $ts_vcsc_extend_envatoItem_Name = $item; $ts_vcsc_extend_envatoItem_User = $user; $ts_vcsc_extend_envatoItem_Rating = $rating; $ts_vcsc_extend_envatoItem_Sales = $sales; $ts_vcsc_extend_envatoItem_Price = $cost; $ts_vcsc_extend_envatoItem_Thumb = $thumbnail; $ts_vcsc_extend_envatoItem_Image = $live_preview_url; $ts_vcsc_extend_envatoItem_Link = $url; $ts_vcsc_extend_envatoItem_Release = $uploaded_on; $ts_vcsc_extend_envatoItem_Update = $last_update; $ts_vcsc_extend_envatoItem_HTML = ''; $ts_vcsc_extend_envatoItem_HTML .= ' <div class="ts_vcsc_envato_item"> <div class="ts_vcsc_title">' . $ts_vcsc_extend_envatoItem_Name . '</div> <div class="ts_vcsc_wrap"> <div class="ts_vcsc_top"> <div class="ts_vcsc_rating"><span class="ts_vcsc_desc">Rating</span>' . TS_VCSC_GetEnvatoStars($ts_vcsc_extend_envatoItem_Rating) . '</div> </div> <div class="ts_vcsc_middle"> <div class="ts_vcsc_sales"> <span class="ts_vcsc_img_sales"></span> <div class="ts_vcsc_text"> <span class="ts_vcsc_num">' . $ts_vcsc_extend_envatoItem_Sales . '</span> <span class="ts_vcsc_desc">Sales</span> </div> </div> <div class="ts_vcsc_thumb"> <img src="' . $ts_vcsc_extend_envatoItem_Thumb . '" alt="' . $ts_vcsc_extend_envatoItem_Name . '" width="80" height="80"/> </div> <div class="ts_vcsc_price"> <span class="ts_vcsc_img_price"></span> <div class="ts_vcsc_text"> <span class="ts_vcsc_num"><span>$</span>' . round($ts_vcsc_extend_envatoItem_Price) . '</span> <span class="ts_vcsc_desc">only</span> </div> </div> </div> <div class="ts_vcsc_bottom"> <a href="' . $ts_vcsc_extend_envatoItem_Link . '" target="_blank"></a> </div> </div> </div>'; if ($item_vc == true) { update_option('ts_vcsc_extend_settings_envatoInfo', $ts_vcsc_extend_envatoItem_HTML); update_option('ts_vcsc_extend_settings_envatoLink', $ts_vcsc_extend_envatoItem_Link); update_option('ts_vcsc_extend_settings_envatoPrice', $ts_vcsc_extend_envatoItem_Price); update_option('ts_vcsc_extend_settings_envatoRating', TS_VCSC_GetEnvatoStars($ts_vcsc_extend_envatoItem_Rating)); update_option('ts_vcsc_extend_settings_envatoSales', $ts_vcsc_extend_envatoItem_Sales); } else { echo $ts_vcsc_extend_envatoItem_HTML; } }