Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.
Help keep Vanilla free:var BaseUrl = '/talk/';$Head->AddScript('http://maps.google.com/maps?file=api&v=1&key='.$Context->Configuration['GOOGLEMAP_KEY']);
$Head->AddScript('http://maps.google.com/maps?file=api&v=1&key='.$Context->Configuration['GOOGLEMAP_KEY'],'~',350,0);
$Head->AddScript('http://maps.google.com/maps?file=api&v=1&key='.$Context->Configuration['GOOGLEMAP_KEY'], ''); or better $Head->AddScript('http://maps.google.com/maps?file=api&v=1&key='.$Context->Configuration['GOOGLEMAP_KEY'], '', 450);$Head->AddScript('http://maps.google.com/maps?file=api&v=1&key='.$Context->Configuration['GOOGLEMAP_KEY'], ''); will create <script src="/community/http://maps.google.com/maps?file=api&v=1&key=xxxxxxxxx"...$Head->AddScript('js/tinymce/jscripts/tiny_mce/tiny_mce.js');$Head->AddScript('js/tinymce/jscripts/tiny_mce/tiny_mce.js', '~', 450, 0);AddScriptaculous();Notice: unserialize() [function.unserialize]: Error at offset 872 of 917 bytes in C:\AppServ\www\Vanilla\extensions\VanillaPacker\md5.php on line 2
Warning: Invalid argument supplied for foreach() in C:\AppServ\www\Vanilla\extensions\VanillaPacker\default.php on line 92Installation:
NOTE: This installation requires modifying core Vanilla files. You will need to be comfortable editing .php files.
1. Install this package in /extensions/VanillaPacker/
2. Back up all your files
3. Copy the files from /extensions/VanillaPacker/upload on top of the vanilla one (There is only the files needed to be cached)
4. Be sure that /js/cache/, /themes/vanilla/style/default/cache and conf/packer.php are writable.
5. Apply manually the changes documented in /extensions/VanillaPacker/ManualPatch*.txt. Only apply the changes relating to the Vanilla that you have
6. Go to "Settings" > "extension", to "Vanilla Packer".
7. Go to "Settings" > "js/css packer settings" to check if the installation was successful.
8. You might have to copy some images used by the other extension into your style folder(s).
FILE:
\appg\database.php
FIND:
?>
INSERT BEFORE:
// HACK : START : PACKER
$DatabaseTables['FilesToPack'] = 'FilesToPack';
$DatabaseTables['CssMedia'] = 'CssMedia';
$DatabaseColumns['FilesToPack']['FileID'] = 'FileID';
$DatabaseColumns['FilesToPack']['FilePath'] = 'FilePath';
$DatabaseColumns['CssMedia']['MediaID'] = 'MediaID';
$DatabaseColumns['CssMedia']['MediaName'] = 'MediaName';
// HACK : END : PACKER
FILE:
\appg\init_people.php
FIND:
$Head->AddScript('js/global.js');
$Head->AddStyleSheet($Context->StyleUrl.'people.css', 'screen', 100, '');
REPLACE WITH:
// HACK : START : PACKER
// $Head->AddScript('js/global.js');
// $Head->AddStyleSheet($Context->StyleUrl.'people.css', 'screen', 100, '');
$Head->AddScript('js/global.js', '~', '290', 1, 0);
//need a path relative to vanilla root
$StylePath = $Context->StyleUrl;
$StylePath = ereg_replace("^".$Context->Configuration['WEB_ROOT'], '', $StylePath);
$Head->AddStyleSheet($StylePath.'people.css', 'screen', 100, '~', 1);
// HACK : END : PACKER
FILE:
\appg\init_vanilla.php
FIND:
$Head->AddScript('js/global.js');
$Head->AddScript('js/vanilla.js');
$Head->AddScript('js/ajax.js');
$Head->AddScript('js/ac.js');
$Head->AddStyleSheet($Context->StyleUrl.'vanilla.css', 'screen', 100, '');
$Head->AddStyleSheet($Context->StyleUrl.'vanilla.print.css', 'print', 101, '');
REPLACE WITH:
// HACK : START : PACKER
//$Head->AddScript('js/global.js');
//$Head->AddScript('js/vanilla.js');
//$Head->AddScript('js/ajax.js');
//$Head->AddScript('js/ac.js');
//$Head->AddStyleSheet($Context->StyleUrl.'vanilla.css', 'screen', 100, '');
//$Head->AddStyleSheet($Context->StyleUrl.'vanilla.print.css', 'print', 101, '');
$Head->AddScript('js/global.js', '~', '290', 1, 0);
$Head->AddScript('js/vanilla.js', '~', '291', 1, 0);
$Head->AddScript('js/ajax.js', '~', '292', 1, 0);
$Head->AddScript('js/ac.js', '~', '293', 1, 0);
//need a path relative to vanilla root
$StylePath = $Context->StyleUrl;
$StylePath = ereg_replace("^".$Context->Configuration['WEB_ROOT'], '', $StylePath);
$Head->AddStyleSheet($StylePath.'vanilla.css', 'screen', 100, '~', 1);
$Head->AddStyleSheet($StylePath.'vanilla.print.css', 'print', 101, '~', 1);
// HACK : END : PACKER
FILE:
\library\Framework\Framework.Control.Head.php
FIND:
var $Meta; // An associative array of meta tags/content to be added to the head.
INSERT AFTER:
// HACK : START : PACKER
var $_Scripts;
var $_StyleSheets;
var $PackManager;
// HACK : END : PACKER
FIND:
function AddScript($ScriptLocation, $ScriptRoot = '~') {
if (!is_array($this->Scripts)) $this->Scripts = array();
if ($ScriptRoot == '~') $ScriptRoot = $this->Context->Configuration['WEB_ROOT'];
$ScriptPath = $ScriptLocation;
if ($ScriptRoot != '') $ScriptPath = ConcatenatePath($ScriptRoot, $ScriptLocation);
if (!in_array($ScriptPath, $this->Scripts)) $this->Scripts[] = $ScriptPath;
}
REPLACE WITH:
// HACK : START : PACKER
// function AddScript($ScriptLocation, $ScriptRoot = '~') {
// if (!is_array($this->Scripts)) $this->Scripts = array();
// if ($ScriptRoot == '~') $ScriptRoot = $this->Context->Configuration['WEB_ROOT'];
// $ScriptPath = $ScriptLocation;
// if ($ScriptRoot != '') $ScriptPath = ConcatenatePath($ScriptRoot, $ScriptLocation);
// if (!in_array($ScriptPath, $this->Scripts)) $this->Scripts[] = $ScriptPath;
// }
/*$Position:
Position in the list of script. You should try to the appropriate:
100-199: for libraries that can't be packed (e.g. YUI hosted on yahoo servers);
200-299: for libraries that can be packed (e.g. jQuery);
300-399: for script that can be pack;
400+: for script that can't be packed.
*/
function AddScript($ScriptLocation, $ScriptRoot = '~', $Position = '350', $ToPack = 1, $ToMinify = 0) {
if (!is_array($this->_Scripts)) $this->_Scripts = array();
if ($ScriptRoot == '~') {
$ScriptRoot = $this->Context->Configuration['WEB_ROOT'];
} else {
//the script need a relative path to the forum to merge it
//If you specify you specify a web root it can't be merge
$ToPack = 0;
}
$Location = $ScriptLocation;
if ($ScriptRoot != '') $Location = ConcatenatePath($ScriptRoot, $ScriptLocation);
$this->InsertItemAt($this->_Scripts,
array('Location' => $Location, 'Path' => $ScriptLocation, 'ToPack' => $ToPack, 'ToMinify' => $ToMinify),
$Position);
}
// HACK : END : PACKER
FIND:
function AddStyleSheet($StyleSheetLocation, $Media = '', $Position = '100', $StyleRoot = '~') {
if ($StyleRoot == '~') $StyleRoot = $this->Context->Configuration['WEB_ROOT'];
if (!is_array($this->StyleSheets)) $this->StyleSheets = array();
$StylePath = $StyleSheetLocation;
if ($StylePath != '') $StylePath = ConcatenatePath($StyleRoot, $StyleSheetLocation);
$this->InsertItemAt($this->StyleSheets,
array('Sheet' => $StylePath, 'Media' => $Media),
$Position);
}
REPLACE WITH:
// HACK : START : PACKER
// function AddStyleSheet($StyleSheetLocation, $Media = '', $Position = '100', $StyleRoot = '~') {
// if ($StyleRoot == '~') $StyleRoot = $this->Context->Configuration['WEB_ROOT'];
// if (!is_array($this->StyleSheets)) $this->StyleSheets = array();
// $StylePath = $StyleSheetLocation;
// if ($StylePath != '') $StylePath = ConcatenatePath($StyleRoot, $StyleSheetLocation);
// $this->InsertItemAt($this->StyleSheets,
// array('Sheet' => $StylePath, 'Media' => $Media),
// $Position);
// }
function AddStyleSheet($StyleSheetLocation, $Media = '', $Position = '100', $StyleRoot = '~', $ToPack = 1) {
if (!is_array($this->_StyleSheets)) $this->_StyleSheets = array();
if ($StyleRoot == '~') {
$StyleRoot = $this->Context->Configuration['WEB_ROOT'];
} else {
$ToPack = 0;
}
$Sheet = $StyleSheetLocation;
if ($StyleRoot != '') $Sheet = ConcatenatePath($StyleRoot, $StyleSheetLocation);
$Media = strtolower($Media);
$this->InsertItemAt($this->_StyleSheets,
array('Sheet' => $Sheet, 'Path' => $StyleSheetLocation, 'Media' => $Media, 'ToPack' => $ToPack),
$Position);
}
// HACK : END : PACKER
FIND:
$this->Meta = array();
INSERT AFTER:
// HACK : START : PACKER
$this->PackManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'PackManager');
// HACK : END : PACKER
FIND:
}
?>
INSERT BEFORE:
// HACK : START : PACKER
function _SortScripts(){
if (is_array($this->_Scripts)) {
$Pack = new Pack($this->Context);
$Pack->Extension = 'js';
$this->Scripts = array();
ksort($this->_Scripts);
if($this->Context->Configuration['PACKER_ON']){
foreach ($this->_Scripts as $Script) {
$url = '';
if ($Script['ToPack']){
$Pack->AddFile($Script['Path'], $Script['ToMinify']);
} else {
if ($url = $this->PackManager->GetPackUrl($Pack)){
$this->Scripts[] = $url;
}
$Pack->files_to_merge = array();
$this->Scripts[] = $Script['Location'];
}
}
$url = '';
if ($url = $this->PackManager->GetPackUrl($Pack)){
$this->Scripts[] = $url;
}
} else {
foreach ($this->_Scripts as $Script) {
$this->Scripts[] = $Script['Location'];
}
}
}
}
function _SortSheets(){
if(is_array($this->_StyleSheets)){
$Pack = $this->Context->ObjectFactory->NewContextObject($this->Context, 'Pack');
$Pack->Extension = 'css';
$this->StyleSheets = array();
ksort($this->_StyleSheets);
if($this->Context->Configuration['PACKER_ON']){ //check if we should pack the sheets
foreach ($this->_StyleSheets as $Sheet) {
$url = '';
if($Sheet['ToPack']){ //check is this sheet will be packed with the others
$Pack->AddFile($Sheet['Path'], $Sheet['Media']); // we just add it to the list of sheets to pack
} else {
if($url = $this->PackManager->GetPackUrl($Pack)){ // we pack the sheets that need to be packed
$this->StyleSheets[] = array('Sheet' => $url, 'Media' => 'all');
}
$Pack->files_to_merge = array(); // start a need pack
$Pack->files_to_merge_by_id = array();
$this->StyleSheets[] = $Sheet; //add this sheet alone to the head.
}
}
$url = '';
if($url = $this->PackManager->GetPackUrl($Pack)){ // pack the remaining script that need to be pack
$this->StyleSheets[] = array('Sheet' => $url, 'Media' => 'all');
}
} else { //We don't pack them
foreach ($this->_StyleSheets as $Sheet) {
$this->StyleSheets[] = $Sheet;
}
}
}
}
// HACK : END : PACKER
FILE:
\library\People\People.Control.RoleForm.php
FIND:
global $Head;
$Head->AddScript('js/prototype.js');
$Head->AddScript('js/scriptaculous.js');
REPLACE WITH:
// HACK : START : PACKER
// global $Head;
// $Head->AddScript('js/prototype.js');
// $Head->AddScript('js/scriptaculous.js');
AddScriptaculous();
// HACK : END : PACKER
FILE:
\library\Vanilla\Vanilla.Control.CategoryForm.php
FIND:
global $Head;
$Head->AddScript('js/prototype.js');
$Head->AddScript('js/scriptaculous.js');
REPLACE WITH:
// HACK : START : PACKER
// global $Head;
// $Head->AddScript('js/prototype.js');
// $Head->AddScript('js/scriptaculous.js');
AddScriptaculous();
// HACK : END : PACKER
The reduction in HTTP requests is far more effective than the minifying of the javascript.
// Check the Low-Cal Vanilla is installed
if ($Configuration['LOWCALVANILLA_TOOLS_PATH']) {
// Include Low-Cal Vanilla tools file.
// Important: Use require_once or include_once to not load it again if it is already done.
require_once($Configuration['LOWCALVANILLA_TOOLS_PATH']);
// Add your script
LowCalVanilla_AddScript($Context, $Head, 'extensions/MyExtension/script.js');
// Add a library
// Use the position argument (300 by default) to be sure it will be added first
LowCalVanilla_AddScript($Context, $Head, 'extensions/MyExtension/jQuery-min.js', 100);
} else {
$Head->AddScript('extensions/MyExtension/jQuery-min.js');
$Head->AddScript('extensions/MyExtension/script.js');
}
FILE:
\library\Framework\Framework.Control.Head.php
FIND:
if (is_array($this->StyleSheets)) ksort($this->StyleSheets);
REPLACE WITH:
// HACK : START : PACKER
//if (is_array($this->StyleSheets)) ksort($this->StyleSheets);
$this->_SortSheets();
$this->_SortScripts();
// HACK : END : PACKER