'."\n"; if($output_legacy_version){ $code = yofla_360_output_legacy($attributes,$product_url,$product_path); } else{ $code = yofla_360_output_element($attributes,$file_path_config,$product_url,$rotatetool_js_url); } $html .= $code; $html .= "\n".''."\n"; return $html; } /** * Outputs the code as html element and not iframe * * @param $attributes * @param $file_path_config * @param $product_url * @param $rotatetool_js_url * @return string */ function yofla_360_output_element($attributes,$file_path_config,$product_url,$rotatetool_js_url){ $html = ''; //get unique productid $product_id = yofla_360_get_product_id($file_path_config); // set unique div id $div_id = "productRotation_".$product_id; // get width, height $width = $attributes['width']; $height = $attributes['height']; $html .= "
"; //cloud based player url $yofla_360_settings = get_option( 'yofla_360_options' ); if ( isset($yofla_360_settings['license_id']) ){ if(strlen($yofla_360_settings['license_id']) > 0){ $rotatetool_js_url = YOFLA_PLAYER_URL.'?id='.$yofla_360_settings['license_id']; } } wp_enqueue_script( 'yofla_360_player', $rotatetool_js_url); return $html; } /** * Outputs the Product Rotation code as iframe * * @param $attributes * @param $product_url * @param $product_path * @return string */ function yofla_360_output_legacy($attributes,$product_url,$product_path){ // $html = ''; // get width, height $width = $attributes['width_original']; $height = $attributes['height_original']; $iframe_name = 'iframe'.$width.'x'.$height.'.html'; $iframe_path = $product_path.$iframe_name; $iframe_url = $product_url.$iframe_name; if(file_exists($iframe_path)){ //no action, iframe already generated } else{ //load template $template_file_path = YOFLA_360_PATH.'includes/template-iframe-legacy.tpl'; $template_string = file_get_contents($template_file_path); //modify template $search = array('{width}','{height}'); $replace = array($width,$height); $new_html = str_replace($search,$replace,$template_string); //save file file_put_contents($iframe_path,$new_html); } //output iframe $html .= ''; return $html; } /** * Ads default values to attributes * * @param $attributes * @return mixed */ function yofla_360_process_attributes($attributes) { //defaults $defaults = array( 'width' => '500', 'height' => '375', ); //enhance provided attributes with defaults foreach ($defaults as $default => $value) { if (!array_key_exists($default, $attributes)) { $attributes[$default] = $value; } } //check src parameter if (!isset($attributes['src'])){ $html = yofla_360_format_error('[src] parameter is not set!'); $attributes['error'] = $html; } else{ $attributes['src'] = yofla_360_format_provided_src_attribute($attributes['src']); } //cache original width,height values $attributes['width_original'] = $attributes['width']; $attributes['height_original'] = $attributes['height']; //enhance width/height with px or % if(substr($attributes['width'],-1) != 'x' || substr($attributes['width'],-1) != '%'){ $attributes['width'] = $attributes['width']."px"; } if(substr($attributes['height'],-1) != 'x' || substr($attributes['height'],-1) != '%'){ $attributes['height'] = $attributes['height']."px"; } return $attributes; } /** * Adds trailing and leading slash to string * * @param $src * @return string */ function yofla_360_format_provided_src_attribute($src) { if (substr($src,-1) != '/') $src .= '/'; if (substr($src,0,1) != '/') $src = '/'.$src; return $src; } /** * Adds html code to error message that is returned to page * * @param $msg * @return string */ function yofla_360_format_error($msg){ $str = '
360 Plugin Error: '.$msg.'!
'; return $str; } /** * Extract unique product_id from config.js file. * * @param $file_path_config * @return mixed */ function yofla_360_get_product_id($file_path_config){ $config_file = file_get_contents($file_path_config); $first_line = strtok($config_file,"\n"); preg_match('/_(\d*)/',$first_line,$matches); $product_id = $matches[1]; return $product_id; }