<?php @(require_once '../../wp-config.php'); cache_javascript_headers(); ?> var WPAjax = Class.create(); Object.extend(WPAjax.prototype, Ajax.Request.prototype); Object.extend(WPAjax.prototype, { WPComplete: false, // onComplete function WPError: false, // onWPError function initialize: function(url, responseEl) { var tempObj = this; this.transport = Ajax.getTransport(); if ( !this.transport ) return false; this.setOptions( { parameters: 'cookie=' + encodeURIComponent(document.cookie), onComplete: function(transport) { // transport = XMLHttpRequest object if ( tempObj.parseAjaxResponse() ) { if ( 'function' == typeof tempObj.WPComplete ) tempObj.WPComplete(transport); } else if ( 'function' == typeof tempObj.WPError ) // if response corresponds to an error (bad data, say, not 404) tempObj.WPError(transport); } }); this.url = url ? url : '<?php bloginfo('wpurl'); ?> /wp-admin/admin-ajax.php'; this.getResponseElement(responseEl); },
function bb_cache_javascript_headers() { bb_log_deprecated('function', __FUNCTION__, 'cache_javascript_headers'); cache_javascript_headers(); }
/** * Build the JS output for shadowbox.js * * Shadowbox.js is now built in a very specific order, * so to dynamically load what we want, we need to build * the JavaScript dynamically, this causes issues with * determining the path to shadowbox.js also, so we have to * do some hacks further down too. * * @since 3.0.3 * @param $tofile Boolean write output to file instead of echoing * @return none */ function build_shadowbox($tofile = false) { // If the user is filtering the url for shadowbox.js just bail out here if (has_filter('shadowbox-js')) { return; } $plugin_url = $this->plugin_url(); $plugin_dir = WP_PLUGIN_DIR . '/' . dirname($this->plugin_basename); // Ouput correct content-type, and caching headers if (!$tofile) { cache_javascript_headers(); } $output = ''; // Start build foreach (array('intro', 'core', 'util') as $include) { // Replace S.path with the correct path, so we don't have to rely on autodetection which is broken with this method if ($include == 'core') { $output .= str_replace('S.path=null;', "S.path='{$plugin_url}/shadowbox/';", file_get_contents("{$plugin_dir}/shadowbox/{$include}.js")); } else { $output .= file_get_contents("{$plugin_dir}/shadowbox/{$include}.js"); } } $library = $this->get_option('library'); $output .= file_get_contents("{$plugin_dir}/shadowbox/adapters/{$library}.js"); foreach (array('load', 'plugins', 'cache') as $include) { $output .= file_get_contents("{$plugin_dir}/shadowbox/{$include}.js"); } if ($this->get_option('useSizzle') == 'true' && $this->get_option('library') != 'jquery') { $output .= file_get_contents("{$plugin_dir}/shadowbox/find.js"); } $players = $this->get_option('players'); if (in_array('flv', $players) || in_array('swf', $players)) { $output .= file_get_contents("{$plugin_dir}/shadowbox/flash.js"); } $language = $this->get_option('language'); $output .= file_get_contents("{$plugin_dir}/shadowbox/languages/{$language}.js"); foreach ($players as $player) { $output .= file_get_contents("{$plugin_dir}/shadowbox/players/{$player}.js"); } foreach (array('skin', 'outro') as $include) { $output .= file_get_contents("{$plugin_dir}/shadowbox/{$include}.js"); } // if we are supposed to write to a file then do so if ($tofile) { $upload_dir = wp_upload_dir(); $shadowbox_dir = "{$upload_dir['basedir']}/shadowbox-js/"; $shadowbox_file = $shadowbox_dir . $this->md5() . '.js'; if (!is_dir($shadowbox_dir) && is_writable($upload_dir['basedir'])) { wp_mkdir_p($shadowbox_dir); } if (!file_exists($shadowbox_file) && is_dir($shadowbox_dir) && is_writable($shadowbox_dir)) { $fh = fopen($shadowbox_file, 'w+'); fwrite($fh, $output); fclose($fh); } } else { // otherwise just echo (backup call to admin-ajax.php for on the fly building) echo $output; die; } }
/** * Output full list tags (collection for bcomplete.js) * */ function ajaxHelperJsCollection() { global $simple_tags; if (is_null($simple_tags)) { exit; } $total = wp_count_terms('post_tag'); status_header(200); cache_javascript_headers(); echo 'collection = ['; $flag = false; $counter = 0; while ($counter * 200 < $total) { // Get tags $tags = $simple_tags->getTags('hide_empty=false&cloud_selection=count-desc&number=LIMIT ' . $counter * 200 . ', ' . 200, true); foreach ((array) $tags as $tag) { $tag_name = str_replace('"', '\\"', $tag->name); if ($flag === false) { echo '"' . $tag_name . '"'; $flag = true; } else { echo ', "' . $tag_name . '"'; } } unset($tags, $tag); // Increment counter $counter++; } echo '];'; exit; }
/** * Build the JS output for shadowbox.js * * Shadowbox.js is now built in a very specific order, * so to dynamically load what we want, we need to build * the JavaScript dynamically, this causes issues with * determining the path to shadowbox.js also, so we have to * do some hacks further down too. * * @since 3.0.3 * @param $tofile Boolean write output to file instead of echoing * @return mixed false if the file could not be built and a string of the file location if successful */ function build_shadowbox($tofile = false) { // If the user is filtering the url for shadowbox.js just bail out here if (has_filter('shadowbox-js')) { return; } $plugin_url = $this->plugin_url(); //$plugin_dir = WP_PLUGIN_DIR . '/' . dirname ( $this->plugin_basename ); $uploads = wp_upload_dir(); if (empty($uploads['error']) && !empty($uploads['basedir'])) { $baseurl = $uploads['baseurl']; $basedir = $uploads['basedir']; } else { $baseurl = WP_CONTENT_URL . '/uploads'; $basedir = WP_CONTENT_DIR . '/uploads'; } $shadowbox_dir = "{$basedir}/shadowbox-js/"; $shadowbox_src_dir = "{$shadowbox_dir}src"; $shadowbox_src_url = "{$baseurl}/shadowbox-js/src"; // Ouput correct content-type, and caching headers if (!$tofile) { cache_javascript_headers(); } $output = wp_cache_get($this->md5(), 'shadowbox-js'); if (empty($output)) { $output = ''; // Start build foreach (array('intro', 'core', 'util') as $include) { // Replace S.path with the correct path, so we don't have to rely on autodetection which is broken with this method if ($include == 'core') { $output .= str_replace('S.path=null;', "S.path='{$shadowbox_src_url}/';", file_get_contents("{$shadowbox_src_dir}/{$include}.js")); } else { $output .= file_get_contents("{$shadowbox_src_dir}/{$include}.js"); } } $library = $this->get_option('library'); $output .= file_get_contents("{$shadowbox_src_dir}/adapters/{$library}.js"); foreach (array('load', 'plugins', 'cache') as $include) { $output .= file_get_contents("{$shadowbox_src_dir}/{$include}.js"); } if ($this->get_option('useSizzle') == 'true' && $this->get_option('library') != 'jquery') { $output .= file_get_contents("{$shadowbox_src_dir}/find.js"); } $players = (array) $this->get_option('players'); if (in_array('flv', $players) || in_array('swf', $players)) { $output .= file_get_contents("{$shadowbox_src_dir}/flash.js"); } $language = $this->get_option('language'); $output .= file_get_contents("{$shadowbox_src_dir}/languages/{$language}.js"); foreach ($players as $player) { $output .= file_get_contents("{$shadowbox_src_dir}/players/{$player}.js"); } foreach (array('skin', 'outro') as $include) { $output .= file_get_contents("{$shadowbox_src_dir}/{$include}.js"); } wp_cache_set($this->md5(), 'shadowbox-js'); } // if we are supposed to write to a file then do so if ($tofile && $this->get_option('useCache') == 'true') { $shadowbox_file = $shadowbox_dir . $this->md5() . '.js'; if (!is_dir($shadowbox_dir) && is_writable($basedir)) { wp_mkdir_p($shadowbox_dir); } if (!file_exists($shadowbox_file) && is_dir($shadowbox_dir) && is_writable($shadowbox_dir)) { $fh = @fopen($shadowbox_file, 'w+'); @fwrite($fh, $output); @fclose($fh); $chmod = defined('FS_CHMOD_FILE') ? FS_CHMOD_FILE : 0644; if ((fileperms($shadowbox_dir) & 0777) != $chmod) { @chmod($shadowbox_file, $chmod); } } if (!file_exists($shadowbox_file)) { return false; } else { return $shadowbox_file; } } else { if (!$tofile) { // otherwise just echo (backup call to admin-ajax.php for on the fly building) die($output); } } }