Wednesday, October 23, 2013

Integrating Payment gateway in Phpfox

Phpfox integrated Paypal and 2checkout payment gateways by default. It is very easy to use in our custom pages.
Steps for Integrating payment gateway in a custom page in phpfox.

1-> Take Admincp -> Settings -> PaymentGateways.

make the gateway as active and input the 'id'.

We have successfully enabled the payment gateway in phpfox.

USER SIDE
We have a provision in user "Account Settings" for entering the 'Payment Methods' and "id's".

Functionality:

Module -> template -> default -> controller -> filename.html.php

// Including the Payment form by putting the below module block calling.
{module name='api.gateway.form'}

Then
Module -> include -> component -> controller -> filename.class.php


We  need to set param values for "gateway_data":


$this->setParam('gateway_data', array(
'item_number' => '1',
'currency_code' => 'USD',
'amount' => 10,
'item_name' => Testing,
'return' => $this->url()->makeUrl('modulename.index'),
'recurring' => '',
'recurring_cost' =>'' ,
'alternative_cost' => '',
'alternative_recurring_cost' => '',
)
);

We have successfully implemented the payment gateway in our custom page.
Please check it out...


Monday, September 30, 2013

Php FTP Functions ( phpfox )


This is a simple function to connect to an ftp and download the xml files from that ftp to a specified folder in our server

$ftp_server = 'abcdefg.com';      // FTP Server Address (exlucde ftp://)
        $ftp_user_name = 'abcuser';     // FTP Server Username
        $ftp_user_pass = 'abcpass';      // Password
        // Connect to FTP Server
        $conn_id = ftp_connect($ftp_server);
        // Login to FTP Server
        $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
        // Verify Log In Status
        if ((!$conn_id) || (!$login_result))
        {
           Phpfox_Error::set('FTP connection has failed!Attempted to connect to'. $ftp_server.' for user'. $ftp_user_name);
        } else {
           Phpfox::addMessage('Connected to '. $ftp_server .', for user '. $ftp_user_name);
        }
        $contents = ftp_nlist($conn_id, ".");
        foreach($contents as $currentFile)
        {
            // to check directory ('0') or file('1')
            $fType =  Phpfox::getService('moduleName')->is_ftp_dir($currentFile, $conn_id);
            $ext = pathinfo($currentFile, PATHINFO_EXTENSION);
            if($ext == 'xml')
            {        
                // define some variables
// check whether the xml is already downloaded and saved in Database
                $getxmlDetailsFromDb = Phpfox::getService('moduleName')->getxmlDetailsFromDb($currentFile);
                if($getxmlDetailsFromDb['xml_name'] =='')
                {
                    $local_file = Phpfox::getParam('core.dir_file').'xml/'.$currentFile;
                    $server_file = $currentFile;
                    // try to download $server_file and save to $local_file
                    if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY))
                    {
// inserting the downloaded xml name to DB by giving ftpconnect as download type which is used for future reference.
                        $uptype = 'ftpconnect';
                        $XMLtoDB = Phpfox::getService('moduleName')->insertXMLnameToDb($server_file,$uptype);
                    }
                }
               
            }
        }
         // close the FTP connection
        ftp_close($conn_id);

// reading xml datas from DB
        $getxmlDatas = Phpfox::getService('moduleName')->getxmlDatas();
        foreach ($getxmlDatas as $keyxml => $valueXML)
        {
            // reading each xml and fetching the datas.
            $xml=simplexml_load_file(Phpfox::getParam('core.dir_file').'xml/'.$valueXML['xml_name']);
// converting the xml object to array.
            $array = Phpfox::getService('moduleName')->object_to_array($xml);
}

// by printing this '$array' we will get the xml values as
echo '<pre>';
print_r($array);
echo '</pre>';


public function object_to_array($obj)
    {
        if(is_object($obj)) $obj = (array) $obj;
        if(is_array($obj))
        {
            $new = array();
            foreach($obj as $key => $val)
            {
                $new[$key] = $this->object_to_array($val);
            }
        }
        else $new = $obj;
        return $new;      
    }


Reference : php.net

Random Password Generation in php

This is a simple function to Generate random passwords in php applications



     /**
     * random password generator
     * @return type
     * @author Arun George <arun@arun-g.in>
     * @since 30-09-2013
     */
    public function randomPassword()
    {
        $Inputs = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
        $password = array(); //declare $password as an array
        $aLength = strlen($Inputs) - 1; //put the length -1 in cache
        for ($i = 0; $i < 8; $i++)
        {
            $num = rand(0, $aLength);
            $password[] = $Inputs[$num];
        }
        return implode($password); //turn the array into a string
    }

Friday, September 13, 2013

VIN Validation with PHP

Vehicle Identification Number Validation


$vin = '1G1YW2DW0A5108451';


function vinValidate($vin){
 
    $transliteration = array(
        'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8,
        'J'=>1, 'K'=>2, 'L'=>3, 'M'=>4, 'N'=>5, 'P'=>7, 'R'=>9,
        'S'=>2, 'T'=>3, 'U'=>4, 'V'=>5, 'W'=>6, 'X'=>7, 'Y'=>8, 'Z'=>9,
    );

    $weights = array(8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2);
       
        $vin = strtoupper($vin);
        $length = strlen($vin);
        $sum = 0;

        if($length != 17)
        {
            return array('status'=>false, 'message'=>'VIN is not the right length');
        }

        for($x=0; $x<$length; $x++)
        {
            $char = substr($vin, $x, 1);

            if(is_numeric($char))
            {
                $sum += $char * $weights[$x];
            }
            else
            {
                if(!isset($transliteration[$char]))
                {
                    return array('status'=>false, 'message'=>'VIN contains an invalid character.');
                }

                $sum += $transliteration[$char] * $weights[$x];
            }
        }

        $remainder = $sum % 11;
        $checkdigit = $remainder == 10 ? 'X' : $remainder;

        if(substr($vin, 8, 1) != $checkdigit)
        {
            return array('status'=>false, 'message'=>'The VIN is not valid.');
        }

        return array('status'=>true, 'message'=>'The VIN is valid.');
    }
   



Thanks coderelic

Wednesday, September 4, 2013

Very Simple PHP Captcha

Very Simple PHP Captcha :
Very easy and it requires only a couple lines of code. Please follow the below steps.

Step 1
The first step is to create a HTML form which is later submitted.
I assume you already have a HTML form, so I'll only focus on the captcha code and not all the other fields.
 
<?php
session_start();
echo '<form action="something.php" method="post">';
$rand_int1 = substr(mt_rand(),0,2);
$rand_int2 = substr(mt_rand(),0,1);
$rand_int3 = substr(mt_rand(),0,1);
$captcha_answer = $rand_int1 + $rand_int2 - $rand_int3;
$_SESSION['captcha_answer'] = $captcha_answer;
echo 'What is '.$rand_int1.' + '.$rand_int2.' - '.$rand_int3.'?<br>
<input type="text" name="captcha">
<input type="submit" value="Do captcha">
</form>';
?>


Step 2
The second step is collecting the form data and check if captcha is correct.
 
<?php
session_start();
$captcha = $_POST['captcha'];
$captcha_answer = $_SESSION['captcha_answer'];
 
if($captcha != $captcha_answer) {
    echo 'Captcha is incorrect!';
}
else {
    echo 'Captcha is correct, congratulations! :)';
}
?>


Thanks : ITDB

Tuesday, September 3, 2013

Function for Date Selection


Function for Date Selection. Its simply superb & cool...



<?PHP

    FUNCTION DateSelector($inName, $useDate=0)
    {
        /* create array so we can name months */
        $monthName = ARRAY(1=> "January", "February", "March",
            "April", "May", "June", "July", "August",
            "September", "October", "November", "December");

        /* if date invalid or not supplied, use current time */
        IF($useDate == 0)
        {
            $useDate = TIME();
        }

        /* make month selector */
        ECHO "<SELECT NAME=" . $inName . "Month>\n";
        FOR($currentMonth = 1; $currentMonth <= 12; $currentMonth++)
        {
            ECHO "<OPTION VALUE=\"";
            ECHO INTVAL($currentMonth);
            ECHO "\"";
            IF(INTVAL(DATE( "m", $useDate))==$currentMonth)
            {
                ECHO " SELECTED";
            }
            ECHO ">" . $monthName[$currentMonth] . "\n";
        }
        ECHO "</SELECT>";

        /* make day selector */
        ECHO "<SELECT NAME=" . $inName . "Day>\n";
        FOR($currentDay=1; $currentDay <= 31; $currentDay++)
        {
            ECHO "<OPTION VALUE=\"$currentDay\"";
            IF(INTVAL(DATE( "d", $useDate))==$currentDay)
            {
                ECHO " SELECTED";
            }
            ECHO ">$currentDay\n";
        }
        ECHO "</SELECT>";

        /* make year selector */
        ECHO "<SELECT NAME=" . $inName . "Year>\n";
        $startYear = DATE( "Y", $useDate);
        FOR($currentYear = $startYear - 5; $currentYear <= $startYear+5;$currentYear++)
        {
            ECHO "<OPTION VALUE=\"$currentYear\"";
            IF(DATE( "Y", $useDate)==$currentYear)
            {
                ECHO " SELECTED";
            }
            ECHO ">$currentYear\n";
        }
        ECHO "</SELECT>";

    }
?>

<HTML>
<BODY>
<FORM>
Choose a Date: <?PHP DateSelector( "Sample"); ?>
</FORM>
</BODY>
</HTML>

Thanks : Psoug

Tuesday, June 4, 2013

Peke Upload :- File Uploading with progress Bar


PekeUpload

It is a jQuery plugin that allows you to easily add multiple or single file upload functionality to your website. This plugin uses html5 only.

Some Features include:

Theming (Twitter Bootstrap ready)
Set File size limit
Set File extensions restrictions
Set custom error messages
Real-Time Progress Indicators
And others more...

Requirements

jQuery 1.4.x or greater
Web browser capable to render HTML5
If you're using Bootstrap, you will need bootstrap.css from v2.2.x or greater
A server capable of parsing PHP, ASP.Net, Cold Fusion, or similar server-side language

Implementation

Download pekeUpload zip from https://github.com/pekebyte/pekeUpload
Unzip pekeUpload zip and install it as per the documentation given.

This is a simple one which i have used till this time. This will work at the time of selecting a file. This will work without any errors in server. The only issue i faced is the jQuery conflit. You can fix it easily.


Tuesday, May 14, 2013

Form submission to 2 tables using forign key


Form submission

Module -> phpfox_sample -> Template -> Default -> Controller
usersubmit.html.php

<form name="form" method="post" action="{url link='product.usersubmit'}" enctype="multipart/form-data">
Name : <input type="text" name="val[name]"> <br><br>
Content : <input type="text" name="val[content]"><br><br>
<input type="submit" name="val[submit]" > </br>
</form>
{if isset($return)}
<br><br>
successfully Added<br><br>
User id : {$return.id}<br>
Privacy : {$return.privacy}
{/if}<br><br>


Module -> phpfox_sample -> Include -> Component -> Controller
userdisplay.class.php

class Product_Component_Controller_Usersubmit extends Phpfox_Component
{
public function process()
{
if($aVals = $this->request()->get('val')){
unset($aVals['submit']);
// d($aVals);
// exit();
$return = Phpfox::getService('product.usersubmit')->insert($aVals);
// $id = $return['id'];
// $privacy= $return['privacy'];
//$this->template()->assign(array('id'=>$id,'privacy'=>$privacy));
$this->template()->assign(array('return'=>$return));
}
}
}


Module -> phpfox_sample -> Include -> Service
userdisplayservice.class.php

class Product_Service_Usersubmit extends Phpfox_Service
{
/**
*function to insert value to database (two tables)
* @param type $argument
* @return type id, privacy
* @author Arun george <arun@arun-g.in>
* @since 22-11-2012
*
*/
function insert($argument)
{
$nameArray['name'] = $argument['name'];
$id =
$this->database()->insert(Phpfox::getT('newuser'),$nameArray);
$contentArray['content'] = $argument['content'];
$contentArray['privacy'] = $id;
$privacy = \
$this->database()->insert(Phpfox::getT('usercontent'),$contentArray);
$return['id'] = $id;
$return['privacy'] = $privacy;
return $return ;
}
}

Displaying values from DataBase based on some Conditions...


View

module -> phpfox_sample -> Template -> Default -> Controller
userdisplay.html.php
<form name="form2" method="post" action="{url link='product.userdisplay'}"
enctype="multipart/form-data">
Name : <select name="val[user_id]">
<option value="0">select </option>
{foreach from=$userdetails name=userdetail item=detailName}
<option value="{$detailName.u_id}">{$detailName.name} </option>
{/foreach}
</select>
<input type="submit" name="val[submit]" > </br>
</form>
<table style="border: 1px solid #0088CC; width: 500px; ">
{foreach from=$details name=detail item=detailValue}
<tr style="border: 1px solid #0088CC;">
<td style="border-right: 1px solid #0088CC;">{$detailValue.content}</td>
<td style="border-right: 1px solid #0088CC;">{$detailValue.privacy}</td>
</tr>
{/foreach}
</table>

module -> phpfox_sample -> Include -> Component -> Controller
userdisplay.class.php

class Product_Component_Controller_Userdisplay extends Phpfox_Component
{
$userdetails =
Phpfox::getService('product.userdisplayservice')->getUser();
if($userdetails)
$this->template()->assign(array('userdetails'=>$userdetails));
public function process()
{
if($aVals = $this->request()->get('val'))
{
unset($aVals['submit']);
$details = Phpfox::getService('product.userdisplayservice')->get($aVals);
if($details)
$this->template()->assign(array('details'=>$details));
}
}
}

module -> phpfox_sample ->Include -> Service
userdisplayservice.class.php

class Product_Service_Userdisplayservice extends Phpfox_Service
{
/**
*Function to get rows from table
* @return type
* @author Arun George <arun@arun-g.in>
* @since 20-11-2012
*/
function getUser()
{
$uname = $this->database()->select('*')
->from(Phpfox::getT('newuser'))
->execute('getSlaveRows');
// d($row);
return $uname;
}
/**
*Function to get rows from table
* @return type
* @author Arun George <arun@arun-g.in>
* @since 20-11-2012
*/
function get($aVals)
{
// d($aVals);
// exit();
//
$cond = '';
if($aVals['user_id']==1)
{
$cond = ' r.privacy IN(1,2,3)';
}
elseif($aVals['user_id']==2)
{
$cond = ' r.privacy IN(1,2)';
}
elseif($aVals['user_id']==3)
{
$cond = ' r.privacy IN(3)';
}
else{
$cond = ' r.privacy IN(0)';
}
$row = $this->database()->select('r.*')
->from(Phpfox::getT('usercontent'), 'r')
->where($cond)
->execute('getRows');
return $row;
}
}

Simple Form Submission and store value in Database with Display, Delete..


Module -> phpfox_sample -> Template -> Default -> Controller
formsubmit.html.php

<form name="form2" method="post" action="{url link='product.formsubmit'}"
enctype="multipart/form-data">
Name : <input type="text" name="val[name]"> <br>
User Name : <input type="text" name="val[user]"><br>
Password : <input type="password" name="val[pass]"></br>
E-mail : <input type="text" name="val[email]"><br>
<input type="submit" name="val[submit]" > </br>
</form>
<table style="border: 1px solid #0088CC; width: 500px; ">
<tr style="border: 1px solid #0088CC;"">
<td style="border-right: 1px solid #0088CC;">Name</td>
<td style="border-right: 1px solid #0088CC;">User</td>
<td style="border-right: 1px solid #0088CC;">E-mail</td>
<td></td>
</tr>
{foreach from=$details name=detail item=detailValue}
<tr id="delete_{$detailValue.id}" style="border: 1px solid #0088CC;">
<td style="border-right: 1px solid #0088CC;">{$detailValue.name}</td>
<td style="border-right: 1px solid #0088CC;">{$detailValue.user}</td>
<td style="border-right: 1px solid #0088CC;">{$detailValue.email}</td>
<td> <a href="#" onclick = "$.ajaxCall('product.delete', 'id={$detailValue.id}');"
> DELETE </a> </td>
</tr>
{/foreach}
</table>

module -> phpfox_sample -> Include -> Component -> Controller
formsubmit.class.php

class Phpfoxsample_Component_Controller_Forminsert extends Phpfox_Component
{
/**

* @author Arun George <arun@arun-g.in>
* @since 19-11-2012

*/
public function process()
{
//$this->template()->assign(array('members'=>$aMembers,'id'=>$id,'aPages'=>
$aPage,'currentUser'=>$currentUser));
if($aVals = $this->request()->get('val')){
unset($aVals['submit']);
//d($aVals); exit();
//Phpfox::getService('forminsertservice')->test($aVals);
Phpfox::getService('phpfoxsample.forminsertservice')->insert($aVals);
}
$details = Phpfox::getService('phpfoxsample.forminsertservice')->get();
$this->template()->setTitle('My First Form Posting');
if($details)
$this->template()->assign(array('details'=>$details));
}
}

Module -> phpfox_sample -> Include -> Service
formsubmit.class.php

class Product_Service_Formsubmit extends Phpfox_Service
{
/**
*function to insert value to database
* @param type $argument
* @return type id
* @author Arun George <arun@arun-g.in>
* @since 19-11-2012
*
*/
function insert($argument)
{
//d($argument);
//exit();
$id = $this->database()->insert(Phpfox::getT('formsubmit'), $argument);
return $id ;
}
/**
*Function to get rows from table
* @return type
* @author Arun George <arun@arun-g.in>
* @since 19-11-2012
*/
function get()
{
$row = $this->database()->select('*')
->from(Phpfox::getT('formsubmit'))
->execute('getSlaveRows');
// d($row);
return $row;
}
/**
* function to delete the entry from database
* @param type $id
* @author Arun George <arun@arun-g.in>
* @since 19-11-2012
*
*/
function delete($id)
{
$this->database()->delete(Phpfox::getT('formsubmit'), ' id = ' . (int) $id);
return true;
}
}

module -> phpfox_sample -> Include -> Component -> Ajax
ajax.class.php

/**
* [PHPFOX_HEADER]
*/
defined('PHPFOX') or exit('NO DICE!');
class Product_Component_Ajax_Ajax extends Phpfox_Ajax
{
/**
* Function to delete value using Ajax
* @author Arun George <arun@arun-g.in>
* @since 19-11-2012
*/
function delete()
{
$id = $this->get('id');
$return = Phpfox::getService('product.formsubmit')->delete($id);
$this->hide("#delete_".$id);
$this->alert('deleted');
}
}

Phpfox - Creating Your First Add-on : Creating A Module & Controller


Creating A Module

Extension >> Module >> Create New Module

Product : PhpFox Sample Product
Module ID: phpfox_sample better to place the name of product id itself
Add to Menu: YES
Sub Menu: Fill it if needed drop down menu’s
Info : Short discription about module

Then go to the folder structure and create

Module -> phpfox_sample

/include/
/include/component/
/include/component/ajax/
/include/component/block/
/include/component/controller/
/include/plugin/
/include/service/
/static/
/static/css/default/default/
/static/image/
/static/jscript/
/template/
/template/default/
/template/default/block/
/template/default/controller/

Creating a Controller

Controllers are PHP classes that control all the pages on phpFox.

module ->phpfoxsample -> include -> component -> controller
index.class.php

Phpfox - Creating Your First Add-on : Creating a Product


Creating a Product

Every Module or plugin in phpfox must belong to a product. Everything you create within the AdminCP requires that it be part of a product. All the menus, phrases, settings etc... that is provided with the script when you first install it is part of our product, which has the unique ID phpfox.

Log into your AdminCP and navigate to:

Extensions >> Product >> Create New Product

Product ID: unique product ID , must be lowercase ,
Name it as: phpfox_sample

Title : Title to display the product
Name it as : PhpFox Sample Product

Description :
Name it as : This is a sample product

Version :3.1
Product URL : ###.Com
Version Check URL : ###.com
Active : YES

SUBMIT

PHPFOX Knowledgebase


Follow this link to know more about Phpfox Installation, Upgrading, Admin Guide, editing css, templates, etc.. http://www.phpfox.com/kb/

(Only registered user can access the knowledgebase).

Knowledgebase will show you the below details

1). Getting Started with phpFox
       Installing the Product
       Upgrading the Product from v2 to v3
       Upgrading the Product
       Short URLs & Rewrite Rules
       Install Branding Removal

2). Administrator Guide
       Storing Images, Videos & Songs on Separate Servers (Phpfox CDN)
       Disable or enable a module (feature) - CMS
       Change site SEO settings.
       Change references to Phpfox (email signature, site name, site logo, etc)
       Enabling Facebook Connect

3). Design and Template
       Editing Your Sites CSS
       Editing Your Sites Templates
       Creating your site's looks
       Change your site's logo

4). AdminCP User Guide
5). Developer Documentation

I will describe something which comes under this developer documentation.

PHPFOX


PhpFox is a social network software that gives you the ability to create a unique community that includes many of the features found on sites like Facebook and MySpace.

PhpFox is a leading provider in social networking software that today powers thousands of communities that range from all sort of niche's and business models.

To learn more about phpFox and its features, please visit Phpfox features page http://www.phpfox.com/features/.
To view a demo of phpFox, please visit phpfox live demo http://www.phpfox.com/demos/.
If you would like to see phpFox live and in action you can find some of our clients communities from a simple google search.

History
Raymond Benc founded phpFox July 2005, which is when version 1.0.3 was released. Very first public release. Development of the first versions of phpFox took place in 2004, while Raymond was working on his own personal social network. During the development of phpFox Raymond saw the need from others to want to open their own social network and shifted his development of the product towards the public.
Our entire team is located all over the globe, which allows us to keep in touch with all of our clients within their respective time zones.
phpFox Inc. is a privately held company registered in Delaware, United States and Benc Enterprises AB is a privately held company registered in Sweden.
Start your social network today and learn why phpFox is "The Future of Social Networking".

-------------------------
I am Arun G. Currently I am working in PHPFOX project.
I would like to share some of my knowledge in phpfox with you, please follow my upcoming posts with label 'phpfox and arun-g'. I am posting this article without any profit intention. If anyone found any problem with this article, please let me know. I will remove the posts.

phpfox software packages is a paid one. Before you start using this software you should purchase it, follow the link. http://www.phpfox.com/pricing/

*---------------------------------------------------*