v. 2.1.0
Bp Library Package

The ultimate library to speed up Joomla! programming!

This product is Not Supported
Current version: 2.1.0
Maturity Stable
Release Date 18 May 2020 13:50
Compatibility Joomla 3.7.xJoomla 3.8.xJoomla 3.9.x
Downloads 9
Download

Be focused on your true core business!

Would you like to code your Joomla!'s extension 10 times faster?

How would your life change?

Interesting questions, isn't it?

Have a look:

This is a simple Joomla database query:


<?php
defined
('_JEXEC') or die('Restricted access');

// Get a db connection.
$db JFactory::getDbo();

// Create a new query object.
$query $db->getQuery(true);

// Select all records from the user profile table where key is "custom.".
// Order it by the ordering field.
$query->select('*');
$query->from($db->quoteName('#__user_profiles'));
$query->where($db->quoteName('profile_key') . ' = '$db->quote('custom'));
$query->order('ordering ASC');

// Reset the query using our newly populated query object.
$db->setQuery($query);

// Load the results as a list of stdClass objects.
$results $db->loadObjectList();

171 digits (comments excluded)

Now have a look at the same query using BPLibrary:


<?php
defined
('_JEXEC') or die('Restricted access');

$results BpDb::getList(   '#__user_profiles'
                            
, array('profile_key'=>'custom')
                            , array(
'order'=>array('ordering'=>'ASC')));

115 digits only!

56 digits shorter!

Nice, isn't it?

Now, how many query do you write in your extensions?

10? 56 * 10 = 560 digits shorter

30? 56 * 30 = 1680 digits shorter

50? 56 * 50 = 2800 digits shorter

Start to think about what you will do with the time you save.

And this is just to start!

What happens if the core CMS functions change name or syntax? How much time did you spend just to update your extensions? And we know how often it happens, don't we?

Including BPLibrary in your extensions all you will need is just to update the library. 😳

And the best is still to come.

With BPLibrary you Code As You Think (CAYT).

Have a look at the most common things you do developing a Joomla! extension. Use Bp class.

Want to add a css stylesheet in the header? use addCss


<?php
defined
('_JEXEC') or die('Restricted access');

Bp::addCss($my_css_document);

Want to add a javascript file in the header? use addJava


<?php
defined
('_JEXEC') or die('Restricted access');

Bp::addJava($my_java_document);

Want to add a javascript code directly in the header? use addJavaCode


<?php
defined
('_JEXEC') or die('Restricted access');

Bp::addJavaCode($java_code_snippet);

Want to use a model from anywhere? use BpDb::getModel


<?php
defined
('_JEXEC') or die('Restricted access');

BpDb::getModel($model_name);

Want to use another component's model? still use BpDb::getModel


<?php
defined
('_JEXEC') or die('Restricted access');

BpDb::getModel($model_name$site_or_admin$component_name);

Has the model another prefix? still use BpDb::getModel


<?php
defined
('_JEXEC') or die('Restricted access');

BpDb::getModel($model_name$site_or_admin$component_name$model_prefix);


Do you want to test your query and may be even log the query string if it fails? use BpDb::dbTry


<?php
defined
('_JEXEC') or die('Restricted access');

BpDb::dbTry($db$query);

Do you want to log the query anyway? pass extra array to BpDb::dbTry


<?php
defined
('_JEXEC') or die('Restricted access');

BpDb::dbTry($db$query, array('log' => true));


Do you want to get a specific result format? pass extra array to any BpDb method


<?php
defined
('_JEXEC') or die('Restricted access');

BpDb::dbTry($db$query, array('function' => 'loadObjectList'));


Nice, huh?


Let's go deeper, still using Bp class:

Want to get a variable value by searching anywhere? use get


<?php
defined
('_JEXEC') or die('Restricted access');

// search for 'my_var' variable. returns null if not found
Bp::get('my_var');

Want to get a variable value or a default value if not found? still use get


<?php
defined
('_JEXEC') or die('Restricted access');

// search for 'my_var' variable. returns 'default_value' if not found
Bp::get('my_var''default_value');

Want to get a variable value and filter it? still use get


<?php
defined
('_JEXEC') or die('Restricted access');

// search for 'my_var' variable and filter it as integer. returns 'default_value' if not found
Bp::get('my_var''default_value''int');

Want to get a variable by searching only in a specific superglobal? still use get


<?php
defined
('_JEXEC') or die('Restricted access');

// search for 'my_var' variable in post superglobal only and filters it as integer. returns 'default_value' if not found
Bp::get('my_var''default_value''int''post');

Use text placeholders with replace


<?php
defined
('_JEXEC') or die('Restricted access');

// set a template text
$template "the {KEY1} {KEY2} on {KEY3} {KEY4}";

// set all keys / text pairs
$replace = array();
$replace['KEY1'] = 'cat';
$replace['KEY2'] = 'is';
$replace['KEY3'] = 'the';
$replace['KEY4'] = 'table';

// use replace method
$text Bp::replace($replace);

// $text now is 'the cat is on the table'

What if you have placeholders in squares? still use replace


<?php
defined
('_JEXEC') or die('Restricted access');

// set a template text
$template "the [KEY1] [KEY2] on [KEY3] [KEY4]";

// set all keys / text pairs
$replace = array();
$replace['KEY1'] = 'cat';
$replace['KEY2'] = 'is';
$replace['KEY3'] = 'the';
$replace['KEY4'] = 'table';

// use replace method
$text Bp::replace($replace'square');

// $text now is 'the cat is on the table'

What if you have placeholders mixed in squares and braces? still use replace


<?php
defined
('_JEXEC') or die('Restricted access');

// set a template text
$template "the [KEY1] {KEY2} on [KEY3] {KEY4}";

// set all keys / text pairs
$replace = array();
$replace['KEY1'] = 'cat';
$replace['KEY2'] = 'is';
$replace['KEY3'] = 'the';
$replace['KEY4'] = 'table';

// use replace method
$text Bp::replace($replace'both');

// $text now is 'the cat is on the table'

While coding, how many times you need to check the content of a variable? use vd


<?php
defined
('_JEXEC') or die('Restricted access');

/*
// NO MORE
echo '<pre>';
var_dump($my_var_to_check);
echo '</pre>';
*/

// NOW JUST vd
Bp::vd($my_var_to_check);

Nice?

You want to add custom system message here and there, don't you? use addMex


<?php
defined
('_JEXEC') or die('Restricted access');

/*
// NO MORE
$application = JFactory::getApplication();
$application->enqueueMessage('Message');
*/

// NOW JUST addMex - default is 'notice' type
Bp::addMex('Message');

58 digits shorter! And you do all the most common things with the same class: Bp

Don't waste your time to remember (or worse to search for) the right class / function / method / changed / so / many / times / documentation / in / pages / not / updated / or / worse / no / more / available anymore! Spend your time to rise money instead!

You develop multilingual extensions, don't you?

Have a look at what the method txt can do for you: use txt


<?php
defined
('_JEXEC') or die('Restricted access');

// Let's say you have in language file:
// MY_COMPONENT_TEXT_LANGUAGE_KEY_MONTH="Month"

// In your extension use
$month Bp::txt('MY_COMPONENT_TEXT_LANGUAGE_KEY_MONTH');

// $month is now 'Month'

What if you have plurals?

The only thing you have to do is to add the number to the method call: use txt


<?php
defined
('_JEXEC') or die('Restricted access');

// Let's say you have in language file:
// MY_COMPONENT_TEXT_LANGUAGE_KEY_MONTH="Month"
// MY_COMPONENT_TEXT_LANGUAGE_KEY_MONTH_MORE="Months"

// In your extension use
$month Bp::txt('MY_COMPONENT_TEXT_LANGUAGE_KEY_MONTH');

// $month is now 'Months'

You can even customize dynamically the translation text: use txt


<?php
defined
('_JEXEC') or die('Restricted access');

// Let's say you have in language file:
// MY_COMPONENT_TEXT_LANGUAGE_KEY_MONTH="Month"
// MY_COMPONENT_TEXT_LANGUAGE_KEY_MONTH_MORE="%d Months"

// In your extension use
$month Bp::txt('MY_COMPONENT_TEXT_LANGUAGE_KEY_MONTH');

// $month is now '4 Months'

Some languages have different plurals rules.
Let your customer customize their language translation file for specific plural!

Say the user's language requires specific rule for 4 units. All the user has to do is to add the appropriate key to its language file (or, even better, to its language's override file)


<?php
defined
('_JEXEC') or die('Restricted access');

// Let's say you have in language file:
// MY_COMPONENT_TEXT_LANGUAGE_KEY_MONTH="Month"
// MY_COMPONENT_TEXT_LANGUAGE_KEY_MONTH_4="the %dth month of the year is April"
// MY_COMPONENT_TEXT_LANGUAGE_KEY_MONTH_MORE="%d Months"

// In your extension use
$month Bp::txt('MY_COMPONENT_TEXT_LANGUAGE_KEY_MONTH');

// $month is now 'the 4th month of the year is April'

Don't lie, you are thinking we have some refuse in our example as it's always the same method call, aren't you?

That's the power!
Let the method do the dirty work!

Nice, huh?

And this is only the apex of the iceberg!

Last but not least... it's FREE!

Download the package and walk through the code to discover all you can do faster and easier.

  • Features List

    Empty list

  • Releases
  • Changes Log
    Version Change
    v. 2.1.0  
      changed BpFile::isDir Now the method can create the folder if not exists and assign chmod.
      added BpDb::optimize Method to optimize a db table
     
    v. 2.0.9  
      fixed BpForm::parseFormUk fixed a bug
      added BpFile::isDir check if a dir exists and can create it with several chmod options
      changed BpUsr::getAccessGroupName Now it can return even the complete list
     
    v. 2.0.8  
      fixed Bp::getMenuParams Mis typo
     
    v. 2.0.7  
      fixed BpDate::addTime didn't subtract time
      changed BpUsr::getBrowser now it uses JBrowser and return more extended info
      changed BpUsr::getIpInfo as conseguenze of BpUsr::getBrowser changes, return more extended info
      added BpDb::dbTry passing extra array 'return' => 'function' you will get the query result directly instead of $db object
      fixed BpMail::cleanAddress wrong result
      fixed BpMail::send Recipients names were not treated as array
      deprecated Bp::isExt Use Bp::isExtension instead. It will be removed in v.3.0
      added Bp::addCssStyle add a css style declaration in HEAD section
      added Bp::passToJ method to pass var value to java/jquery script
      changed Bp::txt now it can be used with strings too, passing a string as second argument
      changed Bp::getMenuParams Enhanced the option to get active menu params
      changed Bp::getViewMenuId Enhanced the option to get active menu id associated with the current view
      added Bp::registry Retrieve a json encoded string to array (only, at the moment)
      added Bp::parseUrl Return an array with parsed url passed as argument (server's referer if not argument is passed)
      changed Bp::getUser Now a specific user id may be passed as argument (current user is default)
      changed Bp::updateUserSess Now a specific user id may be passed as argument (current user is default)
     
    v. 2.0.6  
      fixed Bp::getUrl('site') failed to return valid data
      added Bp::getMenuParams get the active menu params (if any), false otherwise
      added Bp::getConfig get the Joomla's installation configuration object
      added Bp::arrayToObject transform recursively an array into object
      added Bp::ObjectToArray transform recursively an object into array
      deprecated Bp::getModel DEPRECATED (will be removed in 3.0) use BpDb::getModel instead
      deprecated Bp::isAdminSide DEPRECATED (will be removed in 3.0) use Bp::isAdmin instead
      added Bp::isSite check if the call comes from the site side
      added Bp::isAdmin check if the current side is administrator
      added Bp::getActiveMenuId get the active menu ID if any, false otherwise
      added Bp::getViewMenuId retrieve the supplied (or current if not supplied) view menu id if any
      added Bp::escape escape a string when you can't use Joomla's native escape
      added Bp::enqMex alias of Bp::addMex - we will see in the future which one will be removed
      added Bp::getPageHeading get the page heading based on menu params or fall in general if missing
      added Bp::getMex retrieve all system messages or clean up the messages queue passing true as param
      added Bp::versionCompare needed because version_compare fails (ie: on 1.10.82 vs 1.10.83)
      added Bp::getVersion returns the library current version
      added Bp::updateUserSess update the user session, required after ACL changes
      fixed BpDate::addTime fixed sign - when time < 0
      added BpDb::getItem get a db row using the model with all its rules
      added BpDb::getTable alias of getInstance, public access
      added BpDb::getModel get the model object
      changed BpDb::getInstance optimized
      added BpDb::getDate returns the current UTC date to format Y-d-m H:i:s
      changed BpDb all query methods: passing $extra['log'] => true $query will be logged before executed
      fixed BpFile::exists failed with hard mode enabled
      fixed BpForm::setValue didn't return the form object
      fixed BpForm::setAttribute didn't return the form object
      deprecated BpUsr::getGeoData DEPRECATED (will be removed in 3.0) use getIpInfo instead
      added BpUsr::getIpInfo use in the same way as getGeoData
      added BpUsr::isBot return true is the current user is a recognized bot crawler
      added BpUsr::logout logout a user
     
powered by Bp Release

Comments

powered by Bp Comments