* @author ThemePunch <info@themepunch.com>
* @link https://www.themepunch.com/
* @copyright 2024 ThemePunch
if(!defined('ABSPATH')) exit();
class RevSliderObjectLibrary extends RevSliderFunctions {
private $library_list = 'library.php';
private $library_download = 'download.php';
private $object_thumb_path = '/revslider/objects/thumbs/';
private $object_orig_path = '/revslider/objects/';
private $customsvgpath = '/revslider/svg/objects/';
private $sizes = array('75', '50', '25', '10');
public $allowed_types = array('thumb', 'video', 'video_thumb');
public $allowed_categories = array('svgcustom');
private $font_icon_paths;
const LIBRARY_VERSION = '2.0.0';
public function __construct(){
$this->upload_dir = wp_upload_dir();
$this->font_icon_paths = array(
RS_PLUGIN_PATH.'sr6/assets/fonts/font-awesome/css/font-awesome.css',
RS_PLUGIN_PATH.'sr6/assets/fonts/pe-icon-7-stroke/css/pe-icon-7-stroke.css'
$this->font_icon_paths = apply_filters('revslider_object_library_icon_paths', $this->font_icon_paths);
public function get_sizes(){
public function _get_list($force = false){
$rslb = RevSliderGlobals::instance()->get('RevSliderLoadBalancer');
$last_check = get_option('revslider-library-check');
if($last_check == false){ //first time called
update_option('revslider-library-check', time());
// Get latest object list
if(time() - $last_check > 1296000 || $force == true){ //30 days
update_option('revslider-library-check', time());
$validated = $this->_truefalse(get_option('revslider-valid', 'false'));
$code = ($validated === false) ? '' : get_option('revslider-code', '');
$hash = get_option('revslider-library-hash', '');
'library_version' => urlencode(self::LIBRARY_VERSION),
'hash' => urlencode($hash),
'code' => urlencode($code),
'version' => urlencode(RS_REVISION),
'product' => urlencode(RS_PLUGIN_SLUG)
$request = $rslb->call_url($this->library_list, $rattr, 'library');
if(!is_wp_error($request)){
if($response = maybe_unserialize($request['body'])){
if('actual' != $response){
$library = json_decode($response, true);
if(isset($library['hash'])) update_option('revslider-library-hash', $library['hash']);
update_option('rs-library', $library, false);
* check if given URL is an object from object library
public function _is_object($url){
$url = $this->get_correct_size_url($url, 100, true);
$upload_url = $this->upload_dir['baseurl'] . $this->object_orig_path;
$file_name = explode('/', $url);
$file_name = $file_name[count($file_name) - 1];
if(strpos($url, $upload_url) !== false){
//check now if handle is inside of the array of objects
$obj = $this->load_objects_with_svg();
$online = $obj['online']['objects'];
foreach($online as $object){
if($object['handle'] == $file_name){
* check if given URL is existing in the object library
public function _does_exist($url){
$url = str_replace($this->upload_dir['baseurl'] . $this->object_orig_path, '', $url);
return file_exists($this->upload_dir['basedir'] . $this->object_orig_path . $url);
* check if certain object needs to be redownloaded
public function _check_object_exist($object_url){
//then check if it is existing
if($this->_is_object($object_url)){
if(!$this->_does_exist($object_url)){ //if not, redownload if allowed
$fnwe = explode('/', $object_url);
$fnwe = $fnwe[count($fnwe) - 1];
$this->_get_object_thumb($fnwe, 'orig');
* get certain object handle by the given ID
public function get_object_handle_by_id($id){
$full = get_option('rs-library', array());
$objects = $this->get_val($full, 'objects', array());
foreach($objects as $obj){
$handle = $this->get_val($obj, 'handle');
* get certain objects thumbnail, download if needed and if not, simply return path
public function _get_object_thumb($object_handle, $type, $download = false){
if(intval($object_handle) > 0){
$object_handle = $this->get_object_handle_by_id($object_handle);
}else{ //check if we are original image and if not change it to original image
$object_handle = $this->get_object_handle_by_downsized($object_handle);
if($type == 'video_full'){
$object_handle = str_replace('.jpg', '.mp4', $object_handle);
$path = (in_array($type, $this->allowed_types, true)) ? $this->object_thumb_path : $this->object_orig_path;
$file = $this->upload_dir['basedir'] . $path . $object_handle;
$url_file = $this->upload_dir['baseurl'] . $path . $object_handle;
$validated = $this->_truefalse(get_option('revslider-valid', 'false'));
$_download = !is_file($file); //check if object thumb is already downloaded
if($validated === false && !in_array($type, $this->allowed_types, true)){
return array('error' => __('Plugin not activated', 'revslider'));
$mimes = array_merge($this->get_val($SR_GLOBALS, array('mime_types', 'image')), array('mp4' => 'video/mp4'));
$file_type = wp_check_filetype($object_handle, $mimes);
if($this->get_val($file_type, 'ext', false) === false || $this->get_val($file_type, 'type', false) === false) return array('error' => __('Bad File Format', 'revslider'));
// Check folder permission and define file location
if($_download && $download === true && wp_mkdir_p($this->upload_dir['basedir'].$path)){
$file = $this->upload_dir['basedir'] . $path . $object_handle;
if($validated === false && !in_array($type, $this->allowed_types, true)){
$error = __('Plugin not activated', 'revslider');
$rslb = RevSliderGlobals::instance()->get('RevSliderLoadBalancer');
$code = ($validated === false) ? '' : get_option('revslider-code', '');
'library_version' => urlencode(self::LIBRARY_VERSION),
'version' => urlencode(RS_REVISION),
'handle' => urlencode($object_handle),
'download' => urlencode($type),
'product' => urlencode(RS_PLUGIN_SLUG)
if(!in_array($type, $this->allowed_types, true)){
$rattr['code'] = urlencode($code); //push code only if needed
$http_force = true; //force http
$image_data = $rslb->call_url($this->library_download, $rattr, 'library', $http_force);
if(!is_wp_error($image_data) && isset($image_data['body']) && isset($image_data['response']) && isset($image_data['response']['code']) && $image_data['response']['code'] == '200'){
$image_data = $image_data['body'];
//check body for errors in here
$check = json_decode($image_data, true);
if(isset($check['error'])){
$error = $check['error'];
}elseif(trim($image_data) == ''){
$error = __('No data received', 'revslider');
$error = __('Error downloading object', 'revslider');
if($image_data !== false && $image_data !== ''){
@file_put_contents($file, $image_data);
if($type == 'video' || $type == 'video_thumb'){
$this->create_image_dimensions($object_handle);
}else{//could not connect to server
$error = __('Error downloading object', 'revslider');
}else{//use default image
$error = __('Error downloading object', 'revslider');
return array('error' => $error);
//get dimensions of image
$imgsize = @getimagesize($file);
$width = $this->get_val($imgsize, '0');
$height = $this->get_val($imgsize, '1');
$url_file = $object_handle;
return array('error' => false, 'url' => $url_file, 'width' => $width, 'height' => $height);
* gets the original image name if the given one is not the orig file
public function get_object_handle_by_downsized($object_handle){
$object_handle = basename($object_handle);
$tmp = explode('.', $object_handle);
$_tmp = explode('-', $tmp[0]);
//check last if it has an x or is an integeter like 50
if(strpos($e, 'x') !== false){
$_e = str_replace('x', '', $e);
$x = (intval($_e) > 0) ? true : $x;
$object_handle = ($x === true || in_array($e, $this->sizes)) ? str_replace('-'.$e, '', $object_handle): $object_handle;
//check again last if it is an integeter like 50
$object_handle = (in_array($e, $this->sizes)) ? str_replace('-'.$e, '', $object_handle) : $object_handle;
* import object layer from ThemePunch Server
public function _get_object_layers($object_id){
$rslb = RevSliderGlobals::instance()->get('RevSliderLoadBalancer');
if(intval($object_id) > 0){
$object_handle = $this->get_object_handle_by_id($object_id);
$error = __('Error downloading layers', 'revslider');
return array('error' => $error);
$validated = $this->_truefalse(get_option('revslider-valid', 'false'));
if($validated === false){
$error = __('Plugin not activated', 'revslider');
$code = ($validated === false) ? '' : get_option('revslider-code', '');
'code' => urlencode($code),
'library_version' => urlencode(self::LIBRARY_VERSION),
'version' => urlencode(RS_REVISION),
'handle' => urlencode($object_handle),
'download' => urlencode('layers'),
'product' => urlencode(RS_PLUGIN_SLUG)
$layers_data = $rslb->call_url($this->library_download, $rattr, 'library');
if(!is_wp_error($layers_data) && isset($layers_data['body']) && isset($layers_data['response']) && isset($layers_data['response']['code']) && $layers_data['response']['code'] == '200'){
$layers_data = $layers_data['body'];
//check body for errors in here
$check = json_decode($layers_data, true);
if(isset($check['error'])){
$error = $check['error'];
}elseif(trim($layers_data) == ''){
$error = __('No data received', 'revslider');
$error = __('Error downloading layers data', 'revslider');
//could not connect to server
$error = ($layers_data === false && $error == '') ? __('Error downloading layers data', 'revslider') : $error;
if($error !== '') return array('error' => $error);
$data = json_decode($layers_data, true);
$data = (empty($data)) ? json_decode(stripslashes($layers_data), true) : $data;
foreach($data as $k => $v){
$svg_source = $this->get_val($data[$k], array('svg', 'source'));
$t = explode('/wp-content/plugins/revslider/', $svg_source);
if(is_array($t) && count($t) == 2){
$this->set_val($data, array($k, 'svg', 'source'), RS_PLUGIN_URL.$t[1]);
return array('error' => false, 'data' => $data);
* import object to media library
public function _import_object($file_path){
$obj_handle = basename($file_path);
$file = $this->upload_dir['basedir'] . $this->object_orig_path . $obj_handle;
$url_file = $this->upload_dir['baseurl'] . $this->object_orig_path . $obj_handle;
$image_handle = @fopen($file_path, 'r');
if($image_handle != false){
$image_data = stream_get_contents($image_handle);
if($image_data !== false){
@file_put_contents($file, $image_data);
$this->create_image_dimensions($obj_handle);
return array('path' => $url_file);
public function load_objects_with_svg(){
$obj = array('svg' => $this->get_svg_sets_full());
$online = get_option('rs-library', array());
$obj['online'] = $online;
public function get_svg_categories(){
$svgs = $this->get_svg_sets_url();
foreach($svgs as $cat => $svg){
if(trim($cat) !== '' && !isset($svg_cat[$cat])) $svg_cat[$cat] = ucwords($cat);
public function load_objects($type = 'all'){
$full = get_option('rs-library', array());
$objects = $this->get_val($full, 'objects', array());
$favorite = RevSliderGlobals::instance()->get('RevSliderFavorite');;
foreach($objects as $key => $obj){
if($type !== $obj['type']){
$t = ($obj['type'] == '3') ? 'video' : $t;
$objects[$key]['title'] = $this->get_val($obj, 'name');
unset($objects[$key]['name']);
$img = $this->get_val($obj, 'handle');
$objects[$key]['img'] = $this->get_val($obj, 'handle');
if($type == '3' || $type == '4'){
$objects[$key]['video_thumb'] = array(
'url' => $this->get_val($obj, 'video'),
$objects[$key]['orig'] = $this->get_val($img, 'orig', '');
unset($objects[$key]['type']);
$tags = $this->get_val($obj, 'tags', array());
$new_tags[] = $this->get_val($tag, 'handle');
$objects[$key]['tags'] = $new_tags;