Thursday, 7 February 2013

Generate the Unique Alias or Unique string in PHP or Joomla

Generate the Unique Alias or Unique string in PHP or Joomla The below code is to check the Alias in joomla 2.8
/**
  * Find unique Alias name if current doesn't exist.
  * @param string $alias
  * 
  * @return string Return the unique alias value.
  */
 protected function getUniqueAlias($alias)
 {
  $alias_ini = $alias;
  $i = 0;
  
  while ($this->isAliasExist($alias))
  {
   $alias = $alias_ini .'-'.++$i;   
  }
  return $alias;
 }
 
 /**
  * Check the 'alais' in the database.
  *
  * @return boolean If found return true else falase.
  */
 protected function isAliasExist($alias) 
 {
  // Initialise variables.
  $db  = $this->getDbo();
  $query = $db->getQuery(true);
  
  $query->select('m.id, m.alias');
  $query->from('#__bmembers m');
  $query->where('m.alias="'.$alias.'"');
  $db->setQuery((string)$query);
  
  $results = $db->loadObjectList();
  
  return (count($results)>0) ? true : false;
 }


Tuesday, 5 February 2013

To clear $query object, to dump the query and nesting loop in Joomla

To clear the previous values from the query var.
/* This needs to be added while using nesting loop to clear the previous query in Joomla Component Writing. */
$query = $db->getQuery(true);
This is to print the built query or dump query.
/* This is to print the built query or dump query. */
echo $query->dump();
Find the sample query as below;
  $data = array();       
  $query->select('c.id, c.alias, c.title');
  $query->from('#__categories c');
  $query->where('c.alias not in ("admin") and c.extension="com_bmember" and published="1"');
  $query->order('c.title asc');
  $db->setQuery((string)$query);
  $categories = $db->loadObjectList();
  
  if (is_array($categories) && ($categories)>0)
  {
   $i=0;
   foreach ($categories as $category)
   {
    $data[$i]['catid'] = $category->id;
    $data[$i]['category'] = $category->title;
    $data[$i]['attributes'] = array();
    
    $query = $db->getQuery(true); // This needs to be added while using nesting loop to clear the previous query.
    $query->select('af.id, af.attribute, af.alias');
    $query->from('#__bmember_attribute_fields af');
    $query->where('af.catid="'.$category->id.'" and af.state="1"');
    $db->setQuery((string)$query);
    $rows = $db->loadObjectList();
    $query->order('af.attributes asc');
    $i++;
   }
  }

Tuesday, 15 January 2013

Enable Use Lightbox in Joomla 2.5/3.0


If you decided that you want to have a lightbox on your Joomla site, you probably know what is it about. But, let’s just mention that the Lightbox is a JavaScript technique to display images and content using modal dialogs. Why do you need this? Because it’s clean, nice looking, effective and easy for implementation.
We will learn how to display
  •     images in modal popup window
  •     external content
First thing we have to do is to add a bit of JavaScript support to our page.
To do this, paste the following code in the top of your main template file (ex. index.php) :


 When you did this, just use the link in the following format in your article or page.

< a href=”my-url” class=”modal”> Image or Text for a popup < /a>


For displaying content in the modal popup window you need a bit more code:

< a 
href="/sample/lightbox.html?map=1&act=3"
 class="modal" rel="{handler: 'iframe', size: {x: 575, y: 300}}">link
 to a modal popup with a dimension of 600px by 300px< /a> 

 It’s pretty much same as displaying images, expect we have “rel” attribute where we are saying that iframe should be used, and we also define exact size of the window were our content will be displayed.

source

Tuesday, 11 December 2012

SQL_CALC_FOUND_ROWS / FOUND_ROWS() does not work in PHP

$s1 = $sql->query('select SQL_CALC_FOUND_ROWS * from db limit 0, 3');
$s2 = $sql->query('select FOUND_ROWS()');
if($row = $s2->fetch_row()) printf('%d/%d', $s1->num_rows, $row[0]);
Sometime, when we run something analogous to above example on the mysql command line, it would work; but running it from php, it failed. The second query has to "know about" the first one, so for some reason its persistence/memory linking the two queries was getting messed up by the php.

(It turns out that Wordpress uses this type of query to do its pagination - so our larger problem was that the pagination in a wordpress install suddenly stopped working when we moved to php 5.2.6 ... eventually tracked it down to the FOUND_ROWS()).

Just for the sake of posting for people who may run into this in the future... for me it was the php setting "mysql.trace_mode" - this defaulted "on" in 5.2.6 instead of "off" like previously, and for some reason prevents the FOUND_ROWS() from working.

As a "fix", we could either put this in every php page (actually, in a common "include"):
ini_set("mysql.trace_mode", "0");
or add this to the .htaccess:
php_value mysql.trace_mode "0"

Friday, 16 November 2012

Install SQLYog with Wine in Ubuntu 12.04

First, download the SQLYog from here. Before that, make sure that you have already installed the wine into your machine, if you don't know how to install wine, refer to this link.

Afterwards, run the following command in terminal (use CTRL+ALT+T to open terminal).

wine /home/rc/Downloads/SQLYog-10.4.0-2-trial.exe 

Then, it should execute the .exe file, and just follow the SQLYog installation as like normally.
However, if you stuck with some error like below;
  wine is not owned by you , err msg.....

In that case, just run the below command (where rc is the shell user). Then run the above command again once the below command is successfully executed.

sudo chown -R rc:rc ~/.wine 


Enjoy !!!

Install Wine in Ubuntu 12.04, or Linux or Linux Mint


Wine enables Linux, Mac, FreeBSD, and Solaris users to run Windows applications without a copy of Microsoft Windows. Wine is free software under constant development. Other platforms may benefit as well. 
Wine 1.5.4 has just been released and this brief tutorial is going to show you how to install it in Ubuntu 12.04. Wine is an open source application which lets you install and run programs designed for Microsoft Windows systems in Linux systems. Not all your Windows programs will run with Wine, but many popular software that you depend on which run in Windows will run perfectly in Ubuntu using Wine.
With this release, comes many enhancements and bug fixes from the previous released version. You can now run Microsoft Office 2003, 2007 properly, Adobe Premier Pro, support for .NET 4.0 and many other software. For a more detailed release note, click here.
To get started, Open the Terminal ( can use press Ctrl+Alt+T on your keyboard to open Terminal). When it opens, run the commands below to add Wine PPA.

sudo add-apt-repository ppa:ubuntu-wine/ppa
sudo apt-get install winetricks

Finally, run the commands below to update your system and install Wine 1.5
sudo apt-get update && sudo apt-get install wine1.5

Thursday, 15 November 2012

Ubuntu: Upgrade error due to another package management application running


Ubuntu: Upgrade error due to another package management application running 


Please, try some of these steps in order:
If you haven't already done so reboot your machine and try running the update again.
Try to run one of the below command or all on command line as;
sudo apt-get clean
sudo do-release-upgrade
sudo rm /var/lib/dpkg/lock 
Manually remove the lock file and try running the update again.