Wednesday, January 1, 2014

Drupal-7 Creating Module based on node form

Hi,

Many times, we required to create custom node and the same we need to display as form in front end. In this case, we can create custom module Quick and Easily as below.

For eg. We have "contactinfo" node type and it's having fields like..

- Name
- Phone Number
- Message

First we need to create : contactinfo.info file

name = contactinfo module
description = contactinfo test module
package = contactinfo modules
core = 7.x

; Information added by Drupal.org packaging script on 2014-06-07
version = "7.x-1.x-dev"
core = "7.x"
project = "sandip"
datestamp = "1402151651"

Second We need to create : contactinfo.module file

/**
 * @file
 * An example of calling defualt Node and Block via Module
 */

/**
 * Implements hook_field_info().
 *
 * Provides the description of the field.
 */
function contactinfo_info() {
  return array(
    // We name our field as the associative name of the array.
    'contactinfo_basic_action' => array(
      'label' => t('Simple contact form creation'),
    ),
  );
}

function contactinfo_menu(){

    // Will be only used while we are dealing with ready made node form
    $items['contactinfo/test'] = array(
    'title' => t('Contact Info Form'),
    'page callback' => 'node_form_contactinfo',
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM,
    'file path' => drupal_get_path('module', 'node'),
    'file' => 'node.pages.inc',
  );
  return $items;
 
}

/*
 * Creating Sample Block
 */
function contactinfo_block_info(){
 
  $blocks['contactinfo_block'] = array(
    'info' => t('Create contactinfo block'),
    'status' => TRUE,
    'region' => 'sidebar_first',
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
  );
  return $blocks;
}

/*
 * Creating Sample Block view for contact info form
 */
function contactinfo_block_view($delta = '') {
  //  echo $delta;
  switch ($delta) {
    case 'contactinfo_block':
      module_load_include('inc', 'node', 'node.pages');
      $block['subject'] = t('Quick Contact');
      $block['content'] = node_form_contactinfo();
      break;
  }
  return $block;
}

/*
 * Function will display node on page as well as block
 */
function node_form_contactinfo(){

    //$nval = node_load(5);
    global $user;
    //echo $user->uid;
    $type = 'contactinfo';
    $form_id = $type . '_node_form';
    $node = new stdClass();
    $node->uid = $user->uid;
    $node->type = $type;
    node_object_prepare($node);
    $output = drupal_get_form($form_id, $node);
    return render($output);
}

/*
 * Default node form alter hook
 * You can add form CSS/Label as per your need.
 */
function contactinfo_form_contactinfo_node_form_alter(&$form, &$form_state, $form_id) {
    /* $form['field_phone'] = array(
    '#type' => 'textfield',
    '#title' => t('Phone Number/Mobile'),
    '#required' => false,
      );
   */
}

?>

                      ========= SAME CODE USING FORM API ============

/**
 * @file
 * An example of calling default Node and Block via Module
 */

/**
 * Implements hook_field_info().
 *
 * Provides the description of the field.
 */
function contactinfocustom_info() {
  return array(
    // We name our field as the associative name of the array.
    'contactinfocustom_basic_action' => array(
      'label' => t('Simple contact form creation'),
    ),
  );
}

function contactinfocustom_menu(){
 
     $items = array();  
    // Will be only used while we are dealing with ready made node form
    $items['contactinfocustom/test'] = array(
    'title' => t('Contact Info Custom Form '),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('contactinfocustom_getform'),  
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM
  );
  return $items;
 
}

/*
 * custom form creation
 */

function contactinfocustom_getform($form, &$form_state){
 
    $form = array();
 
    $form['title'] = array(
        "#title" => t('Name'),
        "#type" => t('textfield'),
        '#size' => 20,
        '#maxlength' => 20,
        "#required" => TRUE,
    );
 
    $form['field_phone'] = array(
    '#type' => 'textfield',
    '#title' => t('Phone Number/Mobile'),
          '#size' => 20,
        '#maxlength' => 10,
    '#required' => false,
      );
 
    $form['body'] = array(
    '#type' => 'textarea',
    '#title' => t('Information About You'),
    '#required' => false,
      );
 
     $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit')
      );
    return $form;
 
}

function contactinfocustom_getform_validate($form, &$form_state){
 
    $values = $form_state['values'];
    if($values['title'] == ''){
         form_set_error('title', t('Set Any Error MSG'));
    }
 
}

function contactinfocustom_getform_submit($form, &$form_state){
 
    global $user;
    $values = $form_state['values'];
    $node = new stdClass();
    $node->type = "contactinfo";
    node_object_prepare($node);
 
    $node->title = $values['title'];
    $node->uid = $user->uid;
    $node->status = 1;
    $node->promote = 0;
    $node->language = LANGUAGE_NONE;
 
    $node->field_phone[$node->language][] = array('value' =>$values['field_phone'] ,);
    $node->body[$node->language][] = array('value' =>$values['body'] ,);
      if($node = node_submit($node)){
          node_save($node);
          drupal_set_message(t('Contact detail form data has been saved successfully.'));
       
       /* $params['puser']['subject'] = t('New Contact entry Found!!!');
        $params['puser']['message'] = t('Please check the admin panel for contact entry!!!');
     
$params['padmin']['subject'] = t('Thank you for submission!!!');
$params['padmin']['message'] = t('Thanks for contacting us');
$site_admin = variable_get('site_mail', '');

drupal_mail('personal_frm', 'puser', $values['email'], 'EN', $params);
drupal_mail('personal_frm', 'auser', $site_admin, 'EN', $params);
         */
      }
 
 
}

?>







Friday, September 10, 2010

How to make quick site in Joomla?

Hello Friends,


Based on my past experience with Joomla programming, I want share with you information about quick creating Joomla site.

What basic you should know?

If you want to make quick Joomla site then you must know about the install process of modules which is ready made available in Joomla.

Installation process is also very simple. Just need to download stable version from Joomla.org site.

Follow the guide line and  given document which is wizard base only next to next button process.

This process will create quick default Joomla site with default theme options.

Now what to do?

Suppose if your requirement is as below

1. Site should be looking Good (Need a Good Theme)
2. Dynamic content management which is already available at back-end (With easy to use editor..its called article management)
3. Contact us page which is ready made module in default Joomla installation.
4. Photo Gallery which is ready made module available in Joomla.org and easy to use.
5. Polling system which is now a day’s very popular.



If you have above simple requirement then you can complete site within ONE DAY. so follow below process.

1. Google is great guru. So try to find out the free "Joomla Themes". You will see lots of themes  "paid and
    free". Mostly tried with free one b'coz paid will ask for money ...ooops :)

   Don't worry; I have solution, all things can be easy either this or other way. Below is link where you must   found free download links which is paid in other sites.

   URL: http://www.amaderforum.com/

   Above site having lots free template link which is really nice and attractive and also its using rapid share. So be careful for the same.(Means one day only one thing download with some limited size).

   So if you get the free theme,  Just install it form back-end admin panel and it done.

2. If you get good theme then your 60 to 70% work over now. Just from back-end add your contents in related links it’s also easy..Right?

3. Contact Us: which is also readymade module you only need to link up it.

4. If you want nice photo gallery then lot free extension available at Joomla.org. But my preference is "POCHA Gallery” which is widely used on Joomla site and has lots of options to represent it. So Quick install it and upload your nice photos and things are over. Great..We are near to finish.

5. If you are popular in group then you can also use polling system for more popularity which is ready made module available in default Joomla setup and it’s easy to use... :)

So with nice theme your basic site is ready now. It will be better if you know what you want to do...

Okay...Guys...Why are you waiting just checked out, make nice site and need any help then i am always ready...just post your needs... :)

Cheers,
Sandip (Web Developer)

Saturday, March 27, 2010

Why Joomla's component not having the same MVC structure like joomla 1.5?

Hello Friends,

    I am working in joomla since 1 year and i have also worked on many components but when i got the new project with new component , every time i face the issue with standard coding format. Like joomla 1.5 having the MVC structure but the popular component which is paid one, but still not using the MVC structure.

There lots of component which very powerful and its using in many sites but still not having common MVC structure. so due to that joomla developer needs learn coding structure every time and facing the issue while learning the new component.

Advantage of the common structure : All have to learn the same flow and also having the fastest grow related to publish component. So please my suggestion is to when we follow the any structure like joomla then we should also have the strict standard format to create the new component, which beneficial to grow up whole joomla community.

Here is the list of component which is not follow joomla 1.5 standard:
1. Jomres (Very popular in hotel booking site)
2. Virtumart (Very popular in shopping cart implementation)

there are the other lots of component which is build with very poor standard and its not maintainable at the time of customization.

So if you are the joomla developer and the facing the issue with above points the please post your suggestion to improve the joomla's component standard.


Regards,
Sandip

Wednesday, March 17, 2010

2 Mins to place the Google map in Joomla

Hello All,

   I am working in joomla since last one year and sometimes, i really felt big the issue with google map because I have not found such good plugin OR Module which is display the map as many way as possible. So recently in joomla's plugin directory i have found such useful plugin which is working great with article and contact us page.



Mostly, we need the Google Map in (Contact us and Article pages) and this plugin is display the map in such a nice way with one line code.

Google Map display in article page:

Below is the syntax for the same

{mosmap lat='32.7659074'|lon='-117.2254277'|zoom='18'|rotation='1'|mapType='Hybrid'}

By changing the map type you can get multiple types of map views.

Google Map display in contact us page: This is little bit tricky but its work nice. you should need to change in main index.php file. Below is the code you need to put in index.php file



Add these lines at line 84 after $mainframe->render();:
JPluginHelper::importPlugin('content');
$tmp_row->text = JResponse::getBody();
$tmp_params = new JParameter(null);
$mainframe->triggerEvent('onMap', array( &$tmp_row, &$tmp_params ), true );
JResponse::setBody($tmp_row->text);

* So above code will work in contact us page. for more details please follow below link.
How to put Google Map Inside the Contact us page



* For downloading the plugin please follow below link.


Plugin download link

I have also done many R & D with this Plug-in. So please let me know if you have any issue with this plug-in. I will try my best to solve out it.

Regards,
Sandip

Sunday, February 21, 2010

JavaScript Date and Time Functions

Hi All,

   For the getting real time date time function solutions please visit below links.

1. JavaScript Date and Time Functions from Quackit.com
2. JavaScript Date and Time Functions from Bluesmoon.info
3. JavaScript Date and Time Functions from Blog.stevenlevithan.com

Saturday, February 13, 2010

Google Website Optimizer Plugin (Joomla! 1.5)

Hello All,

         Found great plug-in for the Joomla developers. Using this you can increasing your website traffic and optimize the code. So dont for getting more rewards use this plug-in as well as advice your clients to get more business.

Plugin Link:

Google Website Optimizer Plugin


For getting more info refer the Joomla org.

Direct path to Plugin

Dont miss above while working with great web-site of joomla.

Regards
Sandip Chhaya

Thursday, February 4, 2010

New EIOFAX.EXE - Threat report!

Hello All,

I have currently, faced with very strange virus definition. This virus is recently identified in this year 2010.

Behavior of virus:

This will load in registry of windows and automatically create its "EIOFAX.EXE" file in windows and load in place of "explorer.exe". Now, due to non-availability of "explorer.exe" windows will not show your desktop(no right click, no taskbar etc.) only will show window its own create "explorer". This virus will only increasing the disk space and create the big issue after few days.

Solution: From one of the blog I have found the solution like we need clean up that particular files from "REGEDIT". so it will not create that "EIOFAX.EXE".

Few Related Links:

1. EIOFAX.EXE Solution Link1
2. EIOFAX.EXE Solution Link2

Please let me know if anyone know better solution to remove about virus Threat.

Best Regards,
Sandip

Wednesday, January 20, 2010

About the multilingual language export/import

Hello All,

Recently i am facing the lots of issue while making multilingual sites export/import with MySql database.

I have done certain thing for doing export/import.

1. First make the table which is support UTF-8 format. Generally, utf-8 general_ci.
2. Also set the "SET NAME UTF-8" format for multiple languages.
3. Now ,using php header I have generate the CSV file. but the file is containing the special character so its not readable.
Now , for the solution i have also changed microsoft word language support extension but still getting special character in CSV.

So need the solution for the same. please help me.

Also suggest if we can use other format while export/import with mySql table.

Regards,
sandip

Monday, July 13, 2009

Good Icon SIte

Hi,

For finding the good icons visit below site.



Friday, July 10, 2009

For Getting Good JQuery Script

Hi Friends,

For getting the good JQuery Tutorial visit the http://www.reddit.com/r/javascript


Simple Image Cropping Class

Hello Everyone,

I have found one simple image cropping class and its really work nice. so anyone who have trouble with image cropping the use this simple class.

Here is the Class:

loadImage('original1.png');
* $cc->cropBySize(100, 100, ccBOTTOMRIGHT);
* $cc->saveImage('final1.png');
*
* $cc->flushImages(false);
*
* $cc->cropByPercent(15, 50, ccCENTER);
* $cc->saveImage('final2.jpg', 90);
*
* $cc->flushImages(true);
*
* $cc->loadImage('original3.png');
* $cc->cropToDimensions(67, 37, 420, 255);
* $cc->showImage('png');
*/


define("ccTOPLEFT", 0);
define("ccTOP", 1);
define("ccTOPRIGHT", 2);
define("ccLEFT", 3);
define("ccCENTRE", 4);
define("ccCENTER", 4);
define("ccRIGHT", 5);
define("ccBOTTOMLEFT", 6);
define("ccBOTTOM", 7);
define("ccBOTTOMRIGHT", 8);


/**
* This class extends the cropCanvas class purely to support and class name
* change and facilitate backwards compatability.
*/
class canvasCrop extends CropCanvas
{
/**
* Class constructor.
*
* @param string $debug
* @return cavasCrop
* @access public
*/
function cavasCrop($debug = false)
{
parent::CropCanvas($debug);
}
}

/**
* The newly renamed class.
*/
class CropCanvas
{
var $_imgOrig = null;
var $_imgFinal = null;
var $_showDebug = false;
var $gdInfo = array();

/**
* Class constructor.
*
* @param string $debug
* @return cropCanvas
* @access public
*/
function CropCanvas($debug = false)
{
$this->setDebugging($debug);
$this->gdInfo = $this->getGDInfo();
}

/**
* Toggles debugging.
*
* @param bool $do
* @return void
* @access public
*/
function setDebugging($do = false)
{
$this->_showDebug = ($do === true) ? true : false;
}

/**
* Load an image from the file system.
*
* An image is loaded using the appropriate function by automatically
* determining the file extension and then seeing if there is support
* for it in the user's installation of GD.
*
* @param string $filename
* @return bool
* @access public
*/
function loadImage($filename)
{
$ext = strtolower($this->_getExtension($filename));
$func = 'imagecreatefrom' . ($ext == 'jpg' ? 'jpeg' : $ext);
if (!$this->_isSupported($filename, $ext, $func, false)) {
return false;
}

$this->_imgOrig = $func($filename);
if ($this->_imgOrig == null) {
$this->_debug("The image could not be created from the '$filename' file using the '$func' function.");
return false;
}

return true;
}

/**
* Load an image from a string (eg. from a database table)
*
* @param string $string
* @return bool
* @access public
*/
function loadImageFromString($string)
{
$this->_imgOrig = imagecreatefromstring($string);
if (!$this->_imgOrig) {
$this->_debug('The image (supplied as a string) could not be created.');
return false;
}

return true;
}

/**
* Save the cropped image
*
* @param string $filename
* @param int $quality
* @param string $forcetype
* @return bool
* @access public
*/
function saveImage($filename, $quality = 90, $forcetype = '')
{
if ($this->_imgFinal == null) {
$this->_debug('There is no cropped image to save.');
return false;
}

$ext = ($forcetype == '') ? $this->_getExtension($filename) : strtolower($forcetype);
$func = 'image' . ($ext == 'jpg' ? 'jpeg' : $ext);
if (!$this->_isSupported($filename, $ext, $func, true)) {
return false;
}

$saved = false;
switch($ext) {
case 'gif':
if ($this->gdInfo['Truecolor Support'] && imageistruecolor($this->_imgFinal)) {
imagetruecolortopalette($this->_imgFinal, false, 255);
}
case 'png':
$saved = $func($this->_imgFinal, $filename);
break;
case 'jpg':
$saved = $func($this->_imgFinal, $filename, $quality);
break;
}

if ($saved == false) {
$this->_debug("The image could not be saved to the '$filename' file as the file type '$ext' using the '$func' function.");
return false;
}

return true;
}

/**
* Shows the masked image without any saving
*
* @param string $type
* @param int $quality
* @return bool
* @access public
*/
function showImage($type = 'png', $quality = 90)
{
if ($this->_imgFinal == null) {
$this->_debug('There is no cropped image to show.');
return false;
}

$type = strtolower($type);
$func = 'image' . ($type == 'jpg' ? 'jpeg' : $type);
$head = 'image/' . ($type == 'jpg' ? 'jpeg' : $type);

if (!$this->_isSupported('[showing file]', $type, $func, false)) {
return false;
}

header("Content-type: $head");
switch($type) {
case 'gif':
if ($this->gdInfo['Truecolor Support'] && imageistruecolor($this->_imgFinal)) {
imagetruecolortopalette($this->_imgFinal, false, 255);
}
case 'png':
$func($this->_imgFinal);
break;
case 'jpg':
$func($this->_imgFinal, '', $quality);
break;
}

return true;
}

/**
* Determines the dimensions for cropping image by a certain amount.
*
* @param int $x
* @param int $y
* @param int $position
* @return bool
* @access public
*/
function cropBySize($x, $y, $position = ccCENTRE)
{
$nx = (!$x) ? imagesx($this->_imgOrig) : imagesx($this->_imgOrig) - $x;
$ny = (!$y) ? imagesy($this->_imgOrig) : imagesy($this->_imgOrig) - $y;
return ($this->_cropSize(-1, -1, $nx, $ny, $position));
}

/**
* Determines the dimensions for cropping image to a certain size.
*
* @param int $x
* @param int $y
* @param int $position
* @return bool
* @access public
*/
function cropToSize($x, $y, $position = ccCENTRE)
{
return ($this->_cropSize(-1, -1, ($x <= 0 ? 1 : $x), ($y <= 0 ? 1 : $y), $position)); } /** * Used for cropping at a specific location (given start x/y and end x/y). * * @param int $sx * @param int $sy * @param int $ex * @param int $ey * @return bool * @access public */ function cropToDimensions($sx, $sy, $ex, $ey) { return ($this->_cropSize($sx, $sy, abs($ex - $sx), abs($ey - $sy), null));
}

/**
* Determines the dimensions for cropping image by a certain amount.
*
* Calculations based on the size given as a percentage of the image size.
*
* @param int $px
* @param int $py
* @param int $position
* @return bool
* @access public
*/
function cropByPercent($px, $py, $position = ccCENTRE)
{
$nx = (!$px) ? imagesx($this->_imgOrig) : (imagesx($this->_imgOrig) - (($px / 100) * imagesx($this->_imgOrig)));
$ny = (!$py) ? imagesy($this->_imgOrig) : (imagesy($this->_imgOrig) - (($py / 100) * imagesy($this->_imgOrig)));
return ($this->_cropSize(-1, -1, $nx, $ny, $position));
}

/**
* Determines the dimensions for cropping image to a certain size.
*
* Calculations based on the size given as a percentage of the image size.
*
* @param int $px
* @param int $py
* @param int $position
* @return bool
* @access public
*/
function cropToPercent($px, $py, $position = ccCENTRE)
{
$nx = (!$px) ? imagesx($this->_imgOrig) : (($px / 100) * imagesx($this->_imgOrig));
$ny = (!$py) ? imagesy($this->_imgOrig) : (($py / 100) * imagesy($this->_imgOrig));
return ($this->_cropSize(-1, -1, $nx, $ny, $position));
}

/**
* Determines cropping dimensions based on threshold level.
*
* The threshold scale is 0 (black) to 255 (white).
*
* @param int $threshold
* @return bool
* @access public
*/
function cropByAuto($threshold = 254)
{
if ($threshold < threshold =" 0;"> 255) {
$threshold = 255;
}
$sizex = imagesx($this->_imgOrig);
$sizey = imagesy($this->_imgOrig);
$sx = $sy = $ex = $ey = -1;
for ($y = 0; $y < $sizey; $y++) { for ($x = 0; $x < $sizex; $x++) { if ($threshold >= $this->_getThresholdValue($this->_imgOrig, $x, $y)) {
if ($sy == -1) {
$sy = $y;
} else {
$ey = $y;
}
if ($sx == -1) {
$sx = $x;
} else {
if ($x < $sx) { $sx = $x; } else if ($x > $ex) {
$ex = $x;
}
}
}
}
}
return ($this->_cropSize($sx, $sy, abs($ex - $sx), abs($ey - $sy), ccTOPLEFT));
}

/**
* Destroy the resources used by the images.
*
* @param bool $original
* @return void
* @access public
*/
function flushImages($original = true)
{
imagedestroy($this->_imgFinal);
$this->_imgFinal = null;
if ($original) {
imagedestroy($this->_imgOrig);
$this->_imgOrig = null;
}
}

/**
* Creates the cropped image based on passed parameters
*
* @param int $ox Original image width
* @param int $oy Original image height
* @param int $nx New width
* @param int $ny New height
* @param int $position Where to place the crop
* @return bool
*/
function _cropSize($ox, $oy, $nx, $ny, $position)
{
if ($this->_imgOrig == null) {
$this->_debug('The original image has not been loaded.');
return false;
}
if (($nx <= 0) || ($ny <= 0)) { $this->_debug('The image could not be cropped because the size given is not valid.');
return false;
}
if (($nx > imagesx($this->_imgOrig)) || ($ny > imagesy($this->_imgOrig))) {
$this->_debug('The image could not be cropped because the size given is larger than the original image.');
return false;
}
if ($ox == -1 || $oy == -1) {
list($ox, $oy) = $this->_getCopyPosition($nx, $ny, $position);
}
if ($this->gdInfo['Truecolor Support']) {
$this->_imgFinal = imagecreatetruecolor($nx, $ny);
imagecopyresampled($this->_imgFinal, $this->_imgOrig, 0, 0, $ox, $oy, $nx, $ny, $nx, $ny);
} else {
$this->_imgFinal = imagecreate($nx, $ny);
imagecopyresized($this->_imgFinal, $this->_imgOrig, 0, 0, $ox, $oy, $nx, $ny, $nx, $ny);
}
return true;
}

/**
* Determine position of the crop.
*
* @param int $nx
* @param int $ny
* @param int $position
* @return array
*/
function _getCopyPosition($nx, $ny, $position)
{
$ox = imagesx($this->_imgOrig);
$oy = imagesy($this->_imgOrig);

switch($position) {
case ccTOPLEFT:
return array(0, 0);
case ccTOP:
return array(ceil(($ox - $nx) / 2), 0);
case ccTOPRIGHT:
return array(($ox - $nx), 0);
case ccLEFT:
return array(0, ceil(($oy - $ny) / 2));
case ccCENTRE:
return array(ceil(($ox - $nx) / 2), ceil(($oy - $ny) / 2));
case ccRIGHT:
return array(($ox - $nx), ceil(($oy - $ny) / 2));
case ccBOTTOMLEFT:
return array(0, ($oy - $ny));
case ccBOTTOM:
return array(ceil(($ox - $nx) / 2), ($oy - $ny));
case ccBOTTOMRIGHT:
return array(($ox - $nx), ($oy - $ny));
}

return array();
}

/**
* Determines the intensity value of a pixel at the passed co-ordinates.
*
* @param resource $im
* @param int $x
* @param int $y
* @return float
*/
function _getThresholdValue($im, $x, $y)
{
$rgb = imagecolorat($im, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
return (($r + $g + $b) / 3);
}

/**
* Get the extension of a file name
*
* @param string $file
* @return string
*/
function _getExtension($file)
{
$ext = '';
if (strrpos($file, '.')) {
$ext = strtolower(substr($file, (strrpos($file, '.') ? strrpos($file, '.') + 1 : strlen($file)), strlen($file)));
}
return $ext;
}

/**
* Validate whether image reading/writing routines are valid.
*
* @param string $filename
* @param string $extension
* @param string $function
* @param bool $write
* @return bool
* @access private
*/
function _isSupported($filename, $extension, $function, $write = false)
{
$giftype = ($write) ? ' Create Support' : ' Read Support';
$support = strtoupper($extension) . ($extension == 'gif' ? $giftype : ' Support');

if (!isset($this->gdInfo[$support]) || $this->gdInfo[$support] == false) {
$request = ($write) ? 'saving' : 'reading';
$this->_debug("Support for $request the file type '$extension' cannot be found.");
return false;
}
if (!function_exists($function)) {
$request = ($write) ? 'save' : 'read';
$this->_debug("The '$function' function required to $request the '$filename' file cannot be found.");
return false;
}

return true;
}

/**
* Gathers the GD version information
*
* Sometimes a check for the GD version like this:
*
* (function_exists('imagecreatetruecolor')) ? 2 : 1;
*
* can fail (at least, in my experience). This method retrieves the GD
* information based on what phpinfo() reports to be installed.
*
* @param bool $justVersion
* @return array
* @access public
*/
function getGDInfo($justVersion = false)
{
$gdinfo = array();

if (function_exists('gd_info')) {
$gdinfo = gd_info();
} else {
$gd = array(
'GD Version' => '',
'FreeType Support' => false,
'FreeType Linkage' => '',
'T1Lib Support' => false,
'GIF Read Support' => false,
'GIF Create Support' => false,
'JPG Support' => false,
'PNG Support' => false,
'WBMP Support' => false,
'XBM Support' => false
);
ob_start();
phpinfo();
$buffer = ob_get_contents();
ob_end_clean();
foreach (explode("\n", $buffer) as $line) {
$line = array_map('trim', (explode('|', strip_tags(str_replace('', '|', $line)))));
if (isset($gd[$line[0]])) {
if (strtolower($line[1]) == 'enabled') {
$gd[$line[0]] = true;
} else {
$gd[$line[0]] = $line[1];
}
}
}
$gdinfo = $gd;
}

if (isset($gdinfo['JIS-mapped Japanese Font Support'])) {
unset($gdinfo['JIS-mapped Japanese Font Support']);
}
if (function_exists('imagecreatefromgd')) {
$gdinfo['GD Support'] = true;
}
if (function_exists('imagecreatefromgd2')) {
$gdinfo['GD2 Support'] = true;
}
if (preg_match('/^(bundled|2)/', $gdinfo['GD Version'])) {
$gdinfo['Truecolor Support'] = true;
} else {
$gdinfo['Truecolor Support'] = false;
}
if ($gdinfo['GD Version'] != '') {
$match = array();
if (preg_match('/([0-9\.]+)/', $gdinfo['GD Version'], $match)) {
$foo = explode('.', $match[0]);
$gdinfo['Version'] = array('major' => $foo[0], 'minor' => $foo[1], 'patch' => $foo[2]);
}
}

return ($justVersion) ? $gdinfo['Version'] : $gdinfo;
}

/**
* Display some simple textual deugging.
*
* @param string $string
* @return void
* @access private
*/
function _debug($string)
{
if ($this->_showDebug) {
echo '

', $string, "

\n";
}
}
}

?>

Friday, December 26, 2008

Basic PHP Learning Sites Useful for Beginners

Hello Everyone..

On web development, now a days PHP is very popular for making fastest web site developing. this technology is gives better control over MySql database and with combination of both we can create small and large sites as per requirement.

So, why should we wait …just learn from below links..

http://oreilly.com/catalog/9780596005603/

http://www.w3schools.com/PHP/DEfaULT.asP

http://serendipitsolutions.com/vanillaforum/comments.php?DiscussionID=5

http://www.php.net/tut.php

MySQL Store Procedure Basic Examples.

Hello Everyone,

STEP -1

Now, I want to know about MySQL Store Proceduer (SP) , Trigger , View etc. available in MySql. So, I am searching many sites for best examples. off course MySql manual is best one for learning above things. but we can learn better with more examples.

For that I have search few sites like..

http://www.devshed.com/c/a/MySQL/Examining-MySQL-50/2/

http://guyh.textdriven.com/MySqlSpp/MyExamples.html

Above both are relay good sites.

As off my learning curve I am posting few things for all MySql DBA. So, If you found any other good example then you are free to post.

From above site I have made one simple SP as below..

DELIMITER $$

DROP PROCEDURE IF EXISTS `mass_testsite`.`testing`$$

CREATE PROCEDURE `mass_testsite`.`testing`(IN par1 VARCHAR(100), OUT par2 VARCHAR(100))

BEGIN

UPDATE adminactivitylog SET userName = ‘Blog’ where userName=par1;
SELECT userName from adminactivitylog where userName = ‘Blog’ INTO par2;

END$$

DELIMITER ;

For Run SP you have use CALL function

For Eg.

SET @par1 = ‘mark’;
call `mass_testsite`.`testing`(@par1, @userName);
SELECT @userName;

Need to learn More….

STEP -2

How to use WHILE….DO…END WHILE?
/*****
WHILE …DO
END WHILE
*****/
DELIMITER $$
DROP PROCEDURE IF EXISTS `db5`.`t3`$$
CREATE PROCEDURE `db5`.`t3`()
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT ’string’*/
BEGIN
DECLARE v INT;
SET v = 0;
WHILE v < 5 DO
INSERT INTO t VALUES(v);
SET v = v + 1;
END WHILE;
END$$
DELIMITER ;

How to use REPEAT….UNTIL…END REPEAT?
/*****
REPEAT;
UNTIL … /*** No semicoloan ****/
END REPEAT;
*****/

DELIMITER $$
DROP PROCEDURE IF EXISTS `db5`.`t3`$$
CREATE PROCEDURE `db5`.`t3`()
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT ’string’*/
BEGIN
DECLARE v INT;
SET v = 0;
REPEAT
INSERT INTO t VALUES(v);
SET v = v + 1;
UNTIL v >= 5 /****** NEED TO CHECK THIS POINT *******/
END REPEAT;
END$$
DELIMITER ;

/*****
LOOP;

END LOOP;
*****/

How to use LOOP…END LOOP?

DELIMITER $$
DROP PROCEDURE IF EXISTS `db5`.`t3`$$
CREATE PROCEDURE `db5`.`t3`()
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT ’string’*/
BEGIN
DECLARE v INT;
SET v = 0;
label_1: LOOP
INSERT INTO t VALUES(v);
SET v = v + 1;
IF v > 5 THEN
LEAVE label_1;
END IF;
END LOOP;

END$$
DELIMITER ;

/*****
ITERATE - Means start loop again.
LEAVE - Break out loop.
*****/

Free E-books link…

Free PHP Books

The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition

PHP 5 Power Programming

Practical PHP Programming

PHP Manual

Build Your Own Database Driven Website Using PHP & MySQL

Free MySql Books

MySQL Reference Manual

Free Ajax Books

Ajax in Action

Foundations of Ajax

Ajax Patterns and Best Practices

Pro JSF and Ajax: Building Rich Internet Components

Pragmatic Ajax : A Web 2.0 primer