load_options(); } /** * Function to be called when the plugin is activated */ function activate() { global $enh_links_widget; $active_version = $this->options['active_version']; if (!isset($active_version) || $active_version=='') { $active_version = get_option('wp-ptviewer_version'); } if ($active_version==$this->current_version) { // do nothing } else { if ($active_version=='') { } else if ($active_version<'2.0.0') { $this->options['jar_url'] = get_option('wp-ptviewer_jar_url'); $this->options['default_applet_width'] = get_option('wp-ptviewer_default_applet_width'); $this->options['default_applet_height'] = get_option('wp-ptviewer_default_applet_height'); $this->options['default_image_path'] = get_option('wp-ptviewer_default_image_path'); $this->options['default_div_class'] = get_option('wp-ptviewer_default_div_class'); delete_option('wp-ptviewer_version'); delete_option('wp-ptviewer_jar_url'); delete_option('wp-ptviewer_default_applet_width'); delete_option('wp-ptviewer_default_applet_height'); delete_option('wp-ptviewer_default_image_path'); delete_option('wp-ptviewer_default_div_class'); } } // Update version number & save new options $this->options['active_version'] = $this->current_version; $this->save_options(); } /** * Add the administration menus */ function add_admin_menus() { add_options_page( __('WP PT-Viewer', WP_PTVIEWER_I18N_DOMAIN), __('WP PT-Viewer', WP_PTVIEWER_I18N_DOMAIN), 8, 'wp-ptviewer/includes/options-page.php' ); } /** * Add the CSS file to the HEAD section */ function add_css() { echo ""; } /** * Shortcode callback */ function do_ptviewer_shortcode($atts, $content=null) { $errors = ''; $output = ''; // Extract attributes //-- extract(shortcode_atts(array( 'image' => '', 'href' => '', 'imagewidth' => '', 'imageheight' => '', 'horizon' => '', 'hfov' => '', 'auto' => '', 'width' => $this->options['default_applet_width'], 'height' => $this->options['default_applet_height'], 'cssclass' => $this->options['default_div_class'], 'debug' => 0 ), $atts)); // Start building the output HTML //-- $output .= '
'; // Get image url //-- $image_url = ''; if ($image=='' && $href=='') { $errors .= "" . __("PT Viewer tag error: no image specified in the shortcode.", WP_PTVIEWER_I18N_DOMAIN) . "
"; } else { if ($image!='') { $image_url = $this->options['default_image_path'] . $image; } else { $image_url = $href; } } // Check parameters //-- if ($imagewidth=='' || $imageheight=='' || $horizon=='' || $hfov=='') { $errors .= "" . __("PT Viewer tag error: a required parameter has not been provided.", WP_PTVIEWER_I18N_DOMAIN) . "
"; } // Compute the applet tag //-- if ($errors=='') { $output .= $this->get_applet_html($width, $height, $image_url, $imagewidth, $imageheight, $horizon, $hfov, $auto); } // Append the shortcode's content if not null. Allow nested shortcodes. //-- if ($content!=null) { $output .= "
" . do_shortcode($content) . "
"; } // Append the errors //-- if ($errors!='' || $debug!=0) { $output .= '
'; $output .= '
' . $errors . '
'; $output .= '
'; $output .= "

PT Viewer tag debugging (you might have made a typo in your tag or tag parameters):

"; $output .= '
'; } // Close our initial DIV tag and exit //-- $output .= '
'; return $output; } /** * Get the html code for the applet */ function get_applet_html($applet_width, $applet_height, $image_url, $image_width, $image_height, $horizon, $hfov , $auto) { // Compute the output parameters //-- $fovPerPixel = $hfov / $image_width; $pwidth = (int) (360 / $fovPerPixel); $pheight = (int) (180 / $fovPerPixel); $x = (int)( ($pwidth - $image_width) / 2 ); $y = (int)( $pheight / 2 - $horizon ); $panmin = (int) ((-$image_width / 2) * $fovPerPixel); $panmax = (int) (($image_width / 2) * $fovPerPixel); $tiltmin = (int) (-($image_height - $horizon) * $fovPerPixel); $tiltmax = (int) ($horizon * $fovPerPixel); // Output the html code //-- $htmlCode = ""; if ($hfov>100) { $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; } else { $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; $htmlCode .= ''; } return $htmlCode; } /** * Load the options from database (set default values in case options are not set) */ function load_options() { $this->options = get_option(WP_PTVIEWER_PLUGIN_OPTIONS); if ( !is_array($this->options) ) { $this->options = array( 'active_version' => '', 'jar_url' => (get_option('siteurl') . '/wp-content/plugins/wp-ptviewer/applets/ptviewer.jar'), 'default_image_path' => (get_option('siteurl') . '/wp-content/uploads/'), 'default_applet_width' => '500', 'default_applet_height' => '300', 'default_div_class' => 'ptviewer' ); add_option(WP_PTVIEWER_PLUGIN_OPTIONS, $this->options); } } /** * Save options to database */ function save_options() { update_option(WP_PTVIEWER_PLUGIN_OPTIONS, $this->options); } } // class WPPtViewerPlugin } // if (!class_exists("WPPtViewerPlugin")) //############################################################################ ?>