All posts by Pramod T P
Create widget – Socialengine
1) Create a folder with a meaningful name in “application/widgets”. here I use “phpcodez” .
Type the following commands from socialengine installation directory
cd application
mkdir phpcodez
2) Then create 3 files “Controller.php” ,”index.tpl” and ”manifest.php” in the new folder “phpcodez”
gedit Controller.php
gedit index.tpl
gedit manifest.php
As you know the socialengine follows MVC structure . So controller lies in “Controller.php”
and view lies in “index.tpl” . The file “manifest.php“ ,will tell the system that a new widget has been added .
3) Paste the below given code in “Controller.php”
<?php
class Widget_phpcodezController extends Engine_Content_Widget_Abstract {
public function indexAction() {
$this->view->title=’PHPCodez’;
}
}
?>
The “indexAction()” function will be invoked when the widget called .
So we must prepare the data to be passed to the view . Here variable are declared and initialized as follows
$this->view->VARIABLE_NAME .
4) Paste the below given code in “index.tpl”
<?php
echo $this->title;
?>
We can print the values of the variable as shown above .
5) Paste the below given code in “manifest.php”
<?php
return array(
‘package’ => array(
‘type’ => ‘widget’,
‘name’ => ‘phpcodez’,
‘version’ => ‘4.0.0’,
‘revision’ => ‘$Revision: 8822 $’,
‘path’ => ‘application/widgets/phpcodez’,
‘repository’ => ‘socialengine.net’,
‘title’ => ‘PHPCodez’,
‘description’ => ‘Displays a “powered by PHPCodez” link.’,
‘author’ => ‘Webligo Developments’,
‘directories’ => array(
‘application/widgets/phpcodez’,
),
),
// Backwards compatibility
‘type’ => ‘widget’,
‘name’ => ‘phpcodez’,
‘version’ => ‘4.0.0’,
‘revision’ => ‘$PHPCodez: 8822 $’,
‘title’ => ‘phpcodez’,
‘description’ => ‘Displays a “powered by PHPCodez” link.’,
‘author’ => ‘Webligo Developments’,
‘category’ => ‘Widgets’,
)
?>
It tells the system that a new widget has been added .
NOTE : If any database operation is required , create a model and let the controller interact with it .
php_uname
Example
<?php
echo php_uname();
?>
Ouput
Linux phpcodez-System-Product-Name 2.6.35-22-generic #35-Ubuntu SMP Sat Oct 16 20:36:48 UTC 2010 i686
realpath
Example
<?php
chdir(‘/usr/local/’);
echo realpath(‘./../../var/www/’);
?>
Ouput
/var/www
Installing ionCube
1) Chnage directory to /usr/local/
cd /usr/local/
2) Download ionCube loaders
wget http://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86.tar.gz
3) Extract the file
tar zxvf ioncube_loaders_lin_x86.tar.gz
4) Add reference to your php.ini file
a) Chnage sirectory to apache2
cd /etc/php5/apache2/
b) Make sure that you have the back up of php.ini file
sudo cp php.ini php.ini.bck
c) Edit the php.ini file and add the referance
sudo gedit php.ini
zend_extension = /usr/local/ioncube/ioncube_loader_lin_5.2.so
5) Restart apache
/etc/init.d/apache2 restart
DateTime::modify()
Example
<?php
$date = new DateTime(‘2006-05-17’);
$date->modify(‘+2 day’);
echo $date->format(‘Y-m-d’);
?>
Output
2006-05-19
date_modify
<?php
$date = date_create(‘2007-05-17’);
date_modify($date, ‘+2 day’);
echo date_format($date, ‘Y-m-d’);
?>
Output
2007-05-19
DateTime::setISODate()
<?php
$date = new DateTime();
$date->setISODate(2007, 7);
echo $date->format(‘Y-m-d’) ;
?>
Output
2007-02-12
date_isodate_set
Example
<?php
$date1 = date_create();
date_isodate_set($date1, 2007, 2);
echo date_format($date1, ‘Y-m-d’);
?>
Output
2007-01-08
DateInterval::format()
<?php
$interval = new DateInterval(‘P12Y14DT16H18M’);
echo $interval->format(‘%d days’);
?>
Output
14 days