View Single Post
  #1  
Old 04-04-2012, 09:53 PM
cellow cellow is offline
 
Join Date: Oct 2006
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default headjs for vbulletin

Could somebody with skills code this wordpress plugin also for vb3 and vb4?

http://wordpress.org/extend/plugins/headjs-plus/

this framework will load all jscripts asynchronous, so the page will endup load faster for the user...

the code looks like this:

PHP Code:
<?php
/**
Plugin Name: HeadJS Plus
Plugin URI: http://wordpress.org/extend/plugins/headjs-plus/
Description: A plugin to load <a href="http://headjs.com">HeadJS</a> in Wordpress to speedup loading.
Version: 0.96.1
Author: Ramoonus
Author URI: http://www.ramoonus.nl/
*/

// when its not declared
if (!class_exists('headJS_loader')) {
/*
 * headJS_loader is the class that handles ALL of the plugin functionality. It helps us avoid name collisions
 * http://codex.wordpress.org/Writing_a_Plugin#Avoiding_Function_Name_Collisions
 * @package headJS_loader
 */
class headJS_loader {

    
/* Initializes the plugin and sets up all actions and hooks necessary.     */
    
function headJS_loader() {
    
        
/* No need to run on admin / rss / xmlrpc */
        
if (!is_admin() && !is_feed() && !defined('XMLRPC_REQUEST')) {
            
$this->_pluginName 'headjs-plus';
            
add_action('init', array($this'pre_content'), 99998);
            
add_action('wp_footer', array($this'post_content'));
        }
        
    }
    
    
/* Buffer the output so we can play with it. */
    
function pre_content() {
    
        
ob_start(array($this'modify_buffer'));

        
/* Variable for sanity checking */
        
$this->buffer_started true;

    }
    
    
/**
     * Modify the buffer.  Search for any js tags in it and replace them with Head JS calls.
     *
     * @return string buffer
     */
    
function modify_buffer($buffer) {
    
        
$script_array = array();
        
/* Look for any script tags in the buffer */
        
preg_match_all('/<script([^>]*?)><\/script>/i'$buffer$script_tags_match);        
        if (!empty(
$script_tags_match[0])) {
            foreach (
$script_tags_match[0] as $script_tag) {
                if (
strpos(strtolower($script_tag), 'text/javascript') !== false) {
                    
preg_match('/src=[\'"]([^\'"]+)/'$script_tag$src_match);
                    if (
$src_match[1]) {
                        
/* Remove the script tags */
                        
$buffer str_replace($script_tag''$buffer);
                        
/* Save the script location */
                        
$script_array[] = $src_match[1];
                    }
                }
            }
        }
    
        
/* Sort out the Head JS */
        
$headJS '<script type="text/javascript" src="' get_bloginfo('wpurl') . '/wp-content/plugins/' $this->_pluginName '/js/head.min.js"></script>';
        
        if (!empty(
$script_array)) {
            
$script_array array_unique($script_array);
            
$i=0;
            foreach (
$script_array as $script_location) {
                
/* Load the scripts into a .js */
                
if ($i != 0) { $js_files .= "\n    "; }
                
$js_files .= '.js("' $script_location '")';
                
$i++;
            }
            
$headJS .= "\n<script>\nhead" $js_files ";\n</script>";
        }
        
        
/* Write Head JS before the end of head */
        
$buffer str_replace('</head>'$headJS "\n</head>"$buffer);
        
        return 
$buffer;
    }
    
    
/* After we are done modifying the contents, flush everything out to the screen.     */
    
function post_content() {
      
// sanity checking
      
if ($this->buffer_started) {
        
ob_end_flush();
      }
    }
    
// class headJS_loader
// if !class_exists('headJS_loader')

/* 
 * Instantiate our class
 */
if (class_exists('headJS_loader')) {
  
$headJS_loader = new headJS_loader();
}
?>
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01178 seconds
  • Memory Usage 1,824KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete