Saturday, 30 November 2013

Low-level PHP Mail Script

How to send an email with PHP without using the built-in mail() function

http://www.stringcat.com/company_blog/2012/10/13/complete-php-low-level-mailer-script-with-to-replyto-cc-bcc-and-attachments/

Tuesday, 26 November 2013

Buddypress Message Auto-complete, inclusion of Non-friends

You have to edit the file wp-content/plugins/buddypress/bp-messages/bp-messages-loader.php

on line 92

change

        $this->autocomplete_all = defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL');

to

        $this->autocomplete_all = define( 'BP_MESSAGES_AUTOCOMPLETE_ALL','true' );

Thursday, 21 November 2013

The buddypress bp global object

http://codex.buddypress.org/developer/the-bp-global/

Increasing the php file upload size limit

The default file upload size limit specified in php.ini is 2MB and the post size limit is 8MB. You can increase both to 25MB by modifying the appropriate lines to this:

upload_max_filesize = 25M
post_max_size = 25M

Location of php.ini

In the terminal type

php --ini

To view the locations and names of all the ini files that were parsed.

Solution Selling - A sales method

http://en.wikipedia.org/wiki/Solution_selling

Running an Android VM in Linux

http://www.cnx-software.com/2013/03/01/how-to-run-android-apps-in-linux-with-androvm/

Installing Microsoft Fuzzy Lookup

You need a Windows 7 system with Office 2010 or higher. You also need .net framework 4, and Visual Studio 2010 Tools for Office Runtime.


.net 4 framework: www.microsoft.com/en-in/download/details.aspx?id=17718

VS 2010 tools for office runtime: http://www.microsoft.com/en-us/download/details.aspx?id=40790

To download MS Fuzzy Lookup for Excel:

http://www.microsoft.com/en-in/download/details.aspx?id=15011

Cloning a disk on Linux

https://wiki.archlinux.org/index.php/Disk_Cloning

Create a tar archive preserving all attributes

tar --selinux --acls --xattrs  -cvf file.tar /var/www
 
http://www.cyberciti.biz/faq/linux-tar-rsync-preserving-acls-selinux-contexts/ 

Wednesday, 20 November 2013

Backup entire installed OS

sudo rsync -aAXv /* /mnt/backup_vol --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found}


The above command will backup all the OS files with the regular attributes and SELinux attributes. rsync also allows the backups to updated. The backup path should be to a Linux filesystem.

To restore the OS from the backup, and more details see: https://wiki.archlinux.org/index.php/Full_System_Backup_with_rsync

Create tar archive and exclude files and directories

http://stackoverflow.com/questions/984204/shell-command-to-tar-directory-excluding-certain-files-folders

Linux: How to create a filesystem in a file

There are two steps. One should create a large empty file. Then that file should be partitioned and formatted.

To create the empty file on a Linux filesystem, use fallocate:


fallocate -l 10G path/to/file/image.img


This won't work in non-Linux file systems such as FAT32. For those you can used the dd command to create a file full of zeroes.

dd if=/dev/zero of=/path/to/file/image.img -bs=10M -count=20480


The above command will create a 200gb file. The calculation is 204800 / 10 = 20480. The block size should be the size of the storage device's buffer. The speed of creation of the file depends on the size of the block size.

After creating the file, the filesystem should be created. mke2fs will give a warning but you can proceed after entering 'y'.

mke2fs -t ext4 /path/to/file


To mount the filesystem of the file, create a directory in the /mnt directory, and then mount it using the mount command. The filesystem won't show up as a device in the file manager but will function as a separate filesystem when you navigate to the mount directory.

sudo mkdir /mnt/backup_vol
sudo mount -o loop /path/to/disk_image /mnt/backup_vol


The filesystem can be accessed from /mnt/backup_vol

To unmount the filesystem:

sudo umount /mnt/backup_vol


Reference: http://freecode.com/articles/virtual-filesystem-building-a-linux-filesystem-from-an-ordinary-file

Friday, 15 November 2013

Renaming a wordpress theme

http://www.davidjrush.com/blog/2012/09/renaming-your-wordpress-theme/

PHP: put printed data into a variable

http://stackoverflow.com/questions/4798142/php-capture-print-require-output-in-variable

PHP get the current URL

To get the actual URL (non necessarily the one shown in the address bar because of URL rewriting):

 
 
$actual_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
 
To get the URL shown in the address bar:

$displayed_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Manually creating a Buddypress menu

The simplest method:

bp_get_displayed_user_nav();

But this works only when the current page is a member page (url is http://host/members/username). Because the function generates a menu with relative links.

The below code will replace the relative links with absolute ones:


$bp_user_link = bp_loggedin_user_domain();
  ob_start();
 bp_get_displayed_user_nav();
 $the_user_nav = ob_get_clean();
 
 print str_replace('Profile</a></li>','Profile</a></li>'.$messages_code,str_replace('href="','href="'.$bp_user_link,$the_user_nav));

bp_loggedin_user_domain gives the url http://host/members/username/

Since bp_get_displayed_user_nav directly prints the code, to capture the code in a variable we have to use ob_start();

One odd thing is that this command will not output the Messages menu in non-member pages. Therefore this has to be obtained separately.

  $bp_user_link = bp_loggedin_user_domain();
  $messages_count = messages_get_unread_count();
  $messages_code = "<li><a id='user-messages' href='{$bp_user_link}messages/'>Messages

<span>$messages_count</span>
</a></li>\n\n"


Putting it together:



$bp_user_link = bp_loggedin_user_domain();
$messages_count = messages_get_unread_count();
$messages_code = "<li><a id='user-messages' href='{$bp_user_link}messages/'>Messages 

<span>$messages_count</span>
</a></li>\n\n";

      $current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
      ob_start();
      bp_get_displayed_user_nav();
      $the_user_nav = ob_get_clean();
     
      print str_replace('Profile</a></li>','Profile</a></li>'.$messages_code,str_replace('href="','href="'.$bp_user_link,$the_user_nav));


$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
ob_start();
bp_get_displayed_user_nav();
$the_user_nav = ob_get_clean();
print str_replace('Profile','Profile'.$messages_code,str_replace('href="','href="'.$bp_user_link,$the_user_nav));
This code works on a stand-alone page. However, when the code should be modified when putting it in a template. Because the same template is used in member and non-member pages.

$current_url_part = "$_SERVER[REQUEST_URI]";
$current_url_part_9 = substr($current_url_part,0,9);

if(!($current_url_part_9 == "/members/" && $current_url_part != "/members/")) // the second check is because the members page is simply http://192.168.42.20/members/, it doesn't have the username after it
{
 /* put an if over here where you check wether the url is under members. if so, show the regular bp_get_displayed_user_nav */
$bp_user_link = bp_loggedin_user_domain();
$messages_count = messages_get_unread_count();
$messages_code = "<li><a id='user-messages' href='{$bp_user_link}messages/'>Messages<span> $messages_count</span>
</a></li>\n\n";
//print $messages_code;
ob_start();
bp_get_displayed_user_nav();
$the_user_nav = ob_get_clean();
 
print str_replace('Profile</a></li>','Profile</a></li>'.$messages_code,str_replace('href="','href="'.$bp_user_link,$the_user_nav));
}
else
{
bp_get_displayed_user_nav();
}     
For the message count to be dynamically updated, the following html structure should be used since there is jquery that keeps the count updated:

<a id="user-messages">

<span><?php echo messages_get_unread_count(); ?></span>
</a>

Tuesday, 12 November 2013

PHP if alternative syntax

http://php.net/manual/en/control-structures.alternative-syntax.php

Monday, 11 November 2013

Disable selinux temporarily

sudo setenforce 0

To check the status of selinux:

/usr/sbin/getenforce


Apache .htaccess directives not working

check the following settings in /etc/httpd/conf/httpd.conf

http://httpd.apache.org/docs/current/mod/core.html#allowoverride

Apache location of configuration file in Fedora

The httpd.conf file is located in

/etc/httpd/conf

Monday, 4 November 2013