Skip to content

Commit

Permalink
First stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
phproberto committed Jun 26, 2012
1 parent 9825c6c commit 6c96088
Show file tree
Hide file tree
Showing 15 changed files with 374 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# eclipse / aptana
.buildpath
.settings/
.project
# never ignore
!.gitignore
!index.html
!index.php
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plg_twbootstrap
plg_sys_twbootstrap
===============

Twitter bootstrap plugin for Joomla 2.5
9 changes: 9 additions & 0 deletions css/bootstrap-responsive.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions css/bootstrap.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions css/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body></body></html>
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body></body></html>
1 change: 1 addition & 0 deletions js/bootstrap.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions js/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body></body></html>
4 changes: 4 additions & 0 deletions js/jquery-1.7.2.min.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions language/en-GB/en-GB.plg_system_twbootstrap.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
PLG_SYS_TWBOOTSTRAP="System - Twitter Bootstrap"
PLG_SYS_TWBOOTSTRAP_XML_DESC="<p>System plugin to enable Twitter Bootstrap in Joomla 2.5.x. and make available his advanced features</p><p>By <a href="http://www.digitaldisseny.com">Digital Disseny, S.L.</a></p>"
PLG_SYS_TWBOOTSTRAP_FIELD_LOAD_JQUERY_LABEL="Load jQuery?"
PLG_SYS_TWBOOTSTRAP_FIELD_LOAD_JQUERY_DESC="Bootstrap requires jQuery. Select the way you want to load it"
PLG_SYS_TWBOOTSTRAP_VALUE_DO_NOT_LOAD="Do not load"
PLG_SYS_TWBOOTSTRAP_VALUE_LOAD_LOCALLY="Load locally"
PLG_SYS_TWBOOTSTRAP_VALUE_LOAD_GOOGLE="Load from Google"
PLG_SYS_TWBOOTSTRAP_FIELD_LOAD_BOOTSTRAP_LABEL="Load Bootstrap?"
PLG_SYS_TWBOOTSTRAP_FIELD_LOAD_BOOTSTRAP_DESC="Probably you should set this to YES :-)"
PLG_SYS_TWBOOTSTRAP_FIELD_BOOTSTRAP_MODE_LABEL="Bootstrap mode"
PLG_SYS_TWBOOTSTRAP_FIELD_BOOTSTRAP_MODE_DESC="Bootstrap can work in static (pixel widths) or in fluid mode (percentage widths)"
PLG_SYS_TWBOOTSTRAP_VALUE_FLUID="Fluid (%)"
PLG_SYS_TWBOOTSTRAP_VALUE_STATIC="Static (px)"
PLG_SYS_TWBOOTSTRAP_FIELD_COM_COLUMNS_LABEL="Component columns"
PLG_SYS_TWBOOTSTRAP_FIELD_COM_COLUMNS_DESC="Here you can set the component available columns. Used to customize views."
PLG_SYS_TWBOOTSTRAP_FIELD_LOAD_FRONTEND_BACKEND_LABEL="Where load Bootstrap?"
PLG_SYS_TWBOOTSTRAP_FIELD_LOAD_FRONTEND_BACKEND_DESC="You can use Bootstrap on frontend and/or in backend. Warning: for now backend will be broken if you enable it"
PLG_SYS_TWBOOTSTRAP_VALUE_FRONTEND="Only in frontend"
PLG_SYS_TWBOOTSTRAP_VALUE_BACKEND="Only in backend"
PLG_SYS_TWBOOTSTRAP_VALUE_BOTH="Both"
PLG_SYS_TWBOOTSTRAP_FIELD_ONLY_HTML_LABEL="Only for HTML content?"
PLG_SYS_TWBOOTSTRAP_FIELD_ONLY_HTML_DESC="Probably you only want to load Bootstrap for HTML content"
PLG_SYS_TWBOOTSTRAP_FIELD_DISABLE_MODAL_LABEL="Disable in modal windows"
PLG_SYS_TWBOOTSTRAP_FIELD_DISABLE_MODAL_DESC="Do not load Bootstrap in modal windows"
2 changes: 2 additions & 0 deletions language/en-GB/en-GB.plg_system_twbootstrap.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PLG_SYS_TWBOOTSTRAP="System - Twitter Bootstrap"
PLG_SYS_TWBOOTSTRAP_XML_DESC="<p>System plugin to enable Twitter Bootstrap in Joomla 2.5.x. and make available his advanced features</p><p>Developed by <a href="http://www.digitaldisseny.com">Digital Disseny, S.L.</a></p>"
1 change: 1 addition & 0 deletions language/en-GB/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body></body></html>
1 change: 1 addition & 0 deletions language/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body></body></html>
211 changes: 211 additions & 0 deletions twbootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
<?php
/*
* ------------------------------------------------------------------------
* Twitter Bootstrap plugin for Joomla
* ------------------------------------------------------------------------
* Copyright (C) 2012 Digital Disseny, S.L. All Rights Reserved.
* @license - GNU/GPL, http://www.gnu.org/licenses/gpl.html
* Author: Roberto Segura - Digital Disseny, S.L.
* Website: http://www.digitaldisseny.com
* ------------------------------------------------------------------------
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.plugin.plugin' );

class plgSystemTwbootstrap extends JPlugin
{
private $_params = null;

// plugin info constants
const TYPE = 'system';
const NAME = 'twbootstrap';

// paths
private $_pathPlugin = null;

// urls
private $_urlPlugin = null;
private $_urlJs = null;
private $_urlCss = null;

// css & js scripts calls
private $_cssCalls = array();
private $_jsCalls = array();

function __construct( &$subject ){

parent::__construct( $subject );

// Load plugin parameters
$this->_plugin = JPluginHelper::getPlugin( self::TYPE, self::NAME );
$this->_params = new JRegistry( $this->_plugin->params );

// init folder structure
$this->_initFolders();

// load plugin language
$this->loadLanguage ('plg_' . self::TYPE . '_' . self::NAME, JPATH_ADMINISTRATOR);

}

function onAfterInitialise()
{

// plugin parameters
$comColumns = $this->_params->get('comColumns',12);
$bootstrapMode = $this->_params->get('bootstrapMode','fluid');

// generate row and column classes
switch ($bootstrapMode) {
case 'fluid':
$bootstrapContainerClass = 'container-fluid';
$bootstrapRowClass = 'row-fluid';
break;
default:
$bootstrapContainerClass = 'container';
$bootstrapRowClass = 'row';
break;
}

// define constants | check if defined to allow override
if (!defined('BOOTSTRAP_VERSION')) {
define('BOOTSTRAP_VERSION','2.0.4');
}
if (!defined('BOOTSTRAP_COM_COLUMNS')) {
define('BOOTSTRAP_COM_COLUMNS',$comColumns);
}
if (!defined('BOOTSTRAP_CONTAINER_CLASS')) {
define('BOOTSTRAP_CONTAINER_CLASS',$bootstrapContainerClass);
}
if (!defined('BOOTSTRAP_ROW_CLASS')) {
define('BOOTSTRAP_ROW_CLASS',$bootstrapRowClass);
}

}

function onBeforeRender(){

// required objects
$app =& JFactory::getApplication();
$doc = JFactory::getDocument();

// url params
$jinput = $app->input;
$tmpl = $jinput->get('tmpl',null,'cmd');

// plugin parameters
$loadFrontBack = $this->_params->get('loadFrontBack','frontend');
$onlyHTML = $this->_params->get('onlyHTML',1);
$disableModal = $this->_params->get('disableModal',1);
$loadJquery = $this->_params->get('loadJquery', 0);
$loadBootstrap = $this->_params->get('loadBootstrap',0);

// check modals
$disabledTmpls = array('component', 'raw');
if ($disableModal && in_array($tmpl, $disabledTmpls)) {
return true;
}

// check HTML only
if ($onlyHTML && $doc->getType() != 'html') {
return true;
}

// site modifications
if ( ($app->isSite() && ($loadFrontBack == 'frontend' || $loadFrontBack == 'both'))
|| ($app->isAdmin() && ($loadFrontBack == 'backend' || $loadFrontBack == 'both')) )
{

// load jQuery ? jQuery is added to header to avoid non-ready errors
if ($loadJquery)
{
switch ($loadJquery) {
// load jQuery locally
case 1:
$jquery = $this->_urlJs . '/jquery-1.7.2.min.js';
break;
// load jQuery from Google
default:
$jquery = 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';
break;
}

// add script to header
$doc->addScript($jquery);
$doc->addScriptDeclaration('jQuery.noConflict();');
}

// load Bootstrap ?
if ($loadBootstrap) {

// Bootstrap CSS - loaded in header
$bootstrapCss = $this->_urlCss . '/bootstrap.min.css';
$doc->addStyleSheet($bootstrapCss);

// bootstrap JS - loaded before body ending
$bootstrapJs = $this->_urlJs . '/bootstrap.min.js';
$doc->addScript($bootstrapJs);
//$this->_addJsCall($bootstrapJs);
}

}

// get the document body
$body = JResponse::getBody();

// JS load
if (!empty($this->_jsCalls)) {
$jsIncludes = implode("\n\t", $this->_jsCalls);
$body = str_replace ("</body>", "\n\t" . $jsIncludes . "\n</body>", $body);
}

// CSS load
if (!empty($this->_cssCalls)) {
$cssHtml = implode("\n\t", $this->_cssCalls);
// css loads just after closing the head tag
$body = str_replace ("</head>", $cssHtml . "\n</head>", $body);
}

// set the modified body
JResponse::setBody($body);

return true;
}

private function _initFolders() {

// paths
$this->_pathPlugin = JPATH_PLUGINS . DIRECTORY_SEPARATOR . self::TYPE . DIRECTORY_SEPARATOR . self::NAME;

// urls
$this->_urlPlugin = JURI::root()."plugins/" . self::TYPE . "/" . self::NAME;
$this->_urlJs = $this->_urlPlugin . "/js";
$this->_urlCss = $this->_urlPlugin . "/css";
}

/**
* Add a css file declaration
* @author Roberto Segura - Digital Disseny, S.L.
* @version 23/04/2012
*
* @param string $cssUrl - url of css file
*/
private function _addCssCall($cssUrl) {
$cssCall = '<link rel="stylesheet" type="text/css" href="'.$cssUrl.'" >';
$this->_cssCalls[] = $cssCall;
}

/**
* Add a JS script declaration
* @author Roberto Segura - Digital Disseny, S.L.
* @version 21/05/2012
*
* @param string $jsUrl - url of the JS file
*/
private function _addJsCall($jsUrl) {
$jsCall = '<script src="'.$jsUrl.'" type="text/javascript"></script>';
$this->_jsCalls[] = $jsCall;
}
}
Loading

0 comments on commit 6c96088

Please sign in to comment.