How to integrate fckeditor in smarty application?
Integration of fckeditor in smarty application
1 . in libs\plugins write the foolowing file called function.fckeditor.php
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*//**
* Smarty function plugin
* Requires PHP >= 4.3.0
* ————————————————————-
* Type: function
* Name: fckeditor
* Version: 1.0
* Author: gazoot (gazoot care of gmail dot com)
* Purpose: Creates a FCKeditor, a very powerful textarea replacement.
* ————————————————————-
* @param InstanceName Editor instance name (form field name)
* @param BasePath optional Path to the FCKeditor directory. Need only be set once on page. Default: /FCKeditor/
* @param Value optional data that control will start with, default is taken from the javascript file
* @param Width optional width (css units)
* @param Height optional height (css units)
* @param ToolbarSet optional what toolbar to use from configuration
* @param CheckBrowser optional check the browser compatibility when rendering the editor
* @param DisplayErrors optional show error messages on errors while rendering the editor
*
* Default values for optional parameters (except BasePath) are taken from fckeditor.js.
*
* All other parameters used in the function will be put into the configuration section,
* CustomConfigurationsPath is useful for example.
* See http://wiki.fckeditor.net/Developer%27s_Guide/Configuration/Configurations_File for more configuration info.
*/
function smarty_function_fckeditor($params, &$smarty)
{
if(!isset($params['InstanceName']) || empty($params['InstanceName']))
{
$smarty->trigger_error(‘fckeditor: required parameter “InstanceName” missing’);
}static $base_arguments = array();
static $config_arguments = array();// Test if editor has been loaded before
if(!count($base_arguments)) $init = TRUE;
else $init = FALSE;// BasePath must be specified once.
if(isset($params['BasePath']))
{
$base_arguments['BasePath'] = $params['BasePath'];
}
else if(empty($base_arguments['BasePath']))
{
$base_arguments['BasePath'] = ‘/FCKeditor/’;
}$base_arguments['InstanceName'] = $params['InstanceName'];
if(isset($params['Value']))
$base_arguments['Value'] = $params['Value'];
else
$base_arguments['Value'] = ”;if(isset($params['Width'])) $base_arguments['Width'] = $params['Width'];
if(isset($params['Height'])) $base_arguments['Height'] = $params['Height'];
if(isset($params['ToolbarSet'])) $base_arguments['ToolbarSet'] = $params['ToolbarSet'];
if(isset($params['CheckBrowser'])) $base_arguments['CheckBrowser'] = $params['CheckBrowser'];
if(isset($params['DisplayErrors'])) $base_arguments['DisplayErrors'] = $params['DisplayErrors'];// Use all other parameters for the config array (replace if needed)
$other_arguments = array_diff_assoc($params, $base_arguments);
$config_arguments = array_merge($config_arguments, $other_arguments);$out = ”;
if($init)
{
$out .= ‘<script type=”text/javascript” src=”‘ . $base_arguments['BasePath'] . ‘fckeditor.js”></script>’;
}$out .= “\n<script type=\”text/javascript\”>\n”;
$out .= “var oFCKeditor = new FCKeditor(‘” . $base_arguments['InstanceName'] . “‘);\n”;foreach($base_arguments as $key => $value)
{
if(!is_bool($value))
{
// Fix newlines, javascript cannot handle multiple line strings very well.
$value = ‘”‘ . preg_replace(“/[\r\n]+/”, ‘” + $0″‘, addslashes($value)) . ‘”‘;
}
$out .= “oFCKeditor.$key = $value; “;
}foreach($config_arguments as $key => $value)
{
if(!is_bool($value))
{
$value = ‘”‘ . preg_replace(“/[\r\n]+/”, ‘” + $0″‘, addslashes($value)) . ‘”‘;
}
$out .= “oFCKeditor.Config[\"$key\"] = $value; “;
}$out .= “\noFCKeditor.Create();\n”;
$out .= “</script>\n”;return $out;
}/* vim: set expandtab: */
?>
2 download the fckeditor from the http://www.fckeditor.net/ and save it in the smarty folder
3 in the php file we include the fckeditor.php file
4 in the tpl file we write the following code
{fckeditor BasePath=”../includes/fckeditor/” InstanceName=”news_desc” Width=”650px” Height=”300px” Value=”$news_desc”}
Simple steps to install php5 in ubuntu
1. Open a terminal box in Ubuntu.
2. Edit /etc/apt/sources.list
Comment out the following two lines. (Add a “#” to the front)
# deb http://us.archive.ubuntu.com/ubuntu dapper universe main restricted universe
# deb http://security.ubuntu.com/ubuntu dapper-security universe
3. Run command
sudo apt-get update
4.Run the following commands:
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
sudo /etc/init.d/apache2 restart
5. Apache installed in var/www folder.
We get the address by latitude and longitude -using php code
How did we get the complete address with using of longitude and latitude using google map API and php code.
The following is may useful script to detect the address.
1) Signup for API key Google Map.
2) Follow the below php code:
<?php
if(isset($_GET['latitude']))
{
$latitude=$_GET['latitude'];
}
if(isset($_GET['longitude']))
{
$longitude=$_GET['longitude'];
}
$key= “Your API Key”;
Call the below function to get the address:
$data=translateLatLngtoAddress($latitude,$longitude,$key);
echo “<pre>”;
var_dump($data);
echo “</pre>”;
Function for get the data :
function translateLatLngtoAddress($lat,$long,$key)
{
$lat=mb_convert_encoding($lat, ‘UTF-8′,mb_detect_encoding($lat, ‘UTF-8, ISO-8859-1′, true));
$long=mb_convert_encoding($long, ‘UTF-8′,mb_detect_encoding($long, ‘UTF-8, ISO-8859-1′, true));$url=”http://maps.google.com/maps/geo?q=$lat,$long&output=csv&sensor=false&key=”.$key;
$response = getGeolocation($url);if (substr($response, 0, 3) === ‘200′) {
return $geo = explode(‘,’, $response);
}
return false;
}
Function is for get the location is getGeolocation:
function getGeolocation($url)
{$init = curl_init();
curl_setopt($init, CURLOPT_URL, $url);
curl_setopt($init, CURLOPT_HEADER,0);
curl_setopt($init, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($init, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($init);
curl_close($init);
return $response;
}
Hope that it may be useful.
Thank you,
Good news for Mobile holders
Coming January 2010, consumers need to pay only Rs. 19 and change their service provider, even as they retain the same mobile number.
Q9SSHVAJSA57
Select the age from birthday in mysql ?
Hi,
following is user table:
CREATE TABLE IF NOT EXISTS `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fname` varchar(255) NOT NULL,
`mname` varchar(255) NOT NULL,
`lname` varchar(255) NOT NULL,
`createdat` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`birthday` date NOT NULL,
PRIMARY KEY (`id`)
);
insert one row into table:
INSERT INTO `user` (`id`, `fname`, `mname`, `lname`, `createdat`, `birthday`) VALUES
(1, ‘Anil’, ‘Kumar’, ‘Panigrahi’, ‘2009-11-19 11:04:27′, ‘1983-02-14′),
To retrieve age from the table:
SELECT YEAR( NOW( ) ) - YEAR( birthday ) - IF( MONTH( NOW( ) ) < MONTH( birthday ) , 1, 0 ) - IF( MONTH( NOW( ) ) = MONTH( birthday )
AND DAYOFMONTH( NOW( ) ) < DAYOFMONTH( birthday ) , 1, 0 ) AS age, birthday, now( )
FROM user;
Hope that it will be useful.
Auto post into Blogspot using php code?
Hi, the following code will help to auto post into blogspot using php code.
<?php session_start();
$email = “blogger_email@gmail.com”;
$pass = “password”;
$blogID= urlencode(“blogger_id”); // like 6304924319904337556// Do Not Modify Below Code
if(!isset($_SESSION['sessionToken'])) {$ch = curl_init(“https://www.google.com/accounts/ClientLogin?Email=$email&Passwd=$pass&service=blogger&accountType=GOOGLE”);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
$result = curl_exec($ch);
$resultArray = curl_getinfo($ch);
curl_close($ch);
$arr = explode(“=”,$result);
$token = $arr[3];
$_SESSION['sessionToken'] = $token;
}$entry = “<entry xmlns=’http://www.w3.org/2005/Atom’>
<title type=’text’>Title of blog post </title>
<content type=’xhtml’>
This is testing contnetto post in blog post.
</content>
</entry>”;
$len = strlen($entry);
$headers = array(“Content-type: application/atom+xml”,”Content-Length: {$len}”,”Authorization: GoogleLogin auth={$_SESSION['sessionToken']}”,”$entry”);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, “https://www.blogger.com/feeds/$blogID/posts/default”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_setopt($ch, CURLOPT_POST, true);
$result = curl_exec($ch);
$ERROR_CODE = curl_getinfo($ch);
curl_close($ch);echo ‘<pre>’;
print_r($headers);
var_dump($result);
print_r($ERROR_CODE);
exit;?>
Hope that it will be useful.
Thank you,
How to install drupal in localhost?
Drupal Installation procedure:
1) Download the zip file from http://www.drupal.org that is drupal 5.20 version.
2) Unzip that file and place that folder at www follder
3) Run that file at browser :
http://localhost/drupal/
4) The Drupal installer requires write permissions to
./sites/default/settings.php
during the installation process. So we need to change the file permission of settings.php file.
5) Creare database in phpmyadmin and give the details at the second screen of installation procedure.
6) After that we need to chnage the file permisstion of
./sites/default/settings.php ,
remove the write permisstion.
7) Now we can sucessfully run the drupal site like :
http://localhost/drupal/
Hope that it will be useful.
How to enable curl in ubuntu system?
Hi, The following command to work on enable curl in ubuntu system,
go to terminal :
Once run the commands if you do not install the php.
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
sudo /etc/init.d/apache2 restart
After that run the following commands to enable curl :
sudo apt-get install php5-curl
sudo apt-get install php5-common ( this has JSON support )
sudo /etc/init.d/apache2 restart
Mysql Views
Hi,
Following syntax is to create view in mysql.
One table user : id,fname,mname,lname,created_at
then create a table in the mysql
After that create a view.
Create or replace view user_view as select id, concat(fname,’ ‘,mname,’ ‘,lname),created_at from user;
Then it created a View.
Grabbing thumbnail image from youtube using php code
The following code is to grabbing the thumbnail image from youtube.
<?
/**
* Function: youtube thumb grabber
*
* @description :
* @param $ : video code, url type (embed/url),size (small/Large),thumb link
* @return : thumb path
* @author : Mamun.
* @last -modified-by: Mamun.
*/
if (! function_exists(‘youtube_thumb_grabber’ ))
{function youtube_thumb_grabber($video_code, $link_type = “embed”, $size = “small”, $thumb_link = “”)
{
if ($video_code != ”)
{
if ($link_type == “embed”)
{$splited_data = explode(“=”,$video_code);
$video_unique_code = substr(strrchr($splited_data[4],”/”),1,-strlen(strrchr($splited_data[4],”&”)));
}
else if ($link_type == “url”)
{
$splited_data = explode(“=”,$video_code);
$video_unique_code = substr($splited_data[1],0,-strlen(strrchr($splited_data[1],”&”)));
}
else
{
return;
}if($size == “small”)
{
return “<a href=\”$thumb_link\”><img src=\”http://img.youtube.com/vi/$video_unique_code/2.jpg\” alt=\”No image\” /></a>”;
}
else if ($size == “large”)
{
return “<a href=\”$thumb_link\”><img src=\”http://img.youtube.com/vi/$video_unique_code/0.jpg\” alt=\”No image\” /></a>”;
}
else
{
return “<a href=\”$thumb_link\”><img src=\”http://img.youtube.com/vi/$video_unique_code/2.jpg\” alt=\”No image\” /></a>”;}
}
}
}$video_title_url=”http://www.youtube.com/watch?v=ed3Vd39USYQ”;
$video_code=”<object width=\”560\” height=\”340\”><param name=\”movie\” value=\”http://www.youtube.com/v/ed3Vd39USYQ&hl=en_US&fs=1&\”></param><param name=\”allowFullScreen\” value=\”true\”></param><param name=”allowscriptaccess” value=”always”></param><embed src=”http://www.youtube.com/v/ed3Vd39USYQ&hl=en_US&fs=1&” type=\”application/x-shockwave-flash\” allowscriptaccess=\”always\” allowfullscreen=\”true\” width=\”560\” height=\”340\”></embed></object>”;echo youtube_thumb_grabber($video_code,”embed”,”large”,$video_title_url);
?>
Hope that this will be useful.


Comments