Tuesday, September 15, 2009

Members as Affiliates

I have been asked (several times) how to make it easier for members of the dolphin site to be considered affiliates. Instead of the member needing to sign up as an affiliate, they are one just by joining the site.

The best way is to automatically create the user's affiliate account when they join the site.

First - you have to remove the `aff`` table 'autoincrement' from the `ID`  field.

Then open join.php and find:::


echo _t( '_Join complete' );
echo '
';
echo _t( $sStatusText );


After it paste:::

$sql = "SELECT * FROM Profiles WHERE ID = '".$iMemID."'";
$theUser = db_res( $sql );
$useInfo = mysql_fetch_assoc( $theUser );
$pr_id = $useInfo['ID'];
$pr_Name = $useInfo['NickName'];
$pr_email = $useInfo['Email'];
$pr_Password = $useInfo['Password'];
$pr_DateReg = $useInfo['DateReg'];
$sql = "
INSERT INTO  `aff` (
`ID` ,
`Name` ,
`email` ,
`Password` ,
`Percent` ,
`seed` ,
`RegDate` ,
`Status` 
)
VALUES (
'".$pr_id."',  '".$pr_Name."',  '".$pr_email."',  '".$pr_Password."',  '50',  '0',  '".$pr_DateReg."',  'Active'
);
";
$addAff = db_res( $sql );




Friday, September 4, 2009

Backup Dolphin Automatically using Cpanel

// PHP script to allow periodic cPanel backups automatically, optionally to a remote FTP server.
// This script contains passwords.  KEEP ACCESS TO THIS FILE SECURE! (place it in your home dir, not /www/)

// ********* THE FOLLOWING ITEMS NEED TO BE CONFIGURED *********

// Info required for cPanel access
$cpuser = "username"; // Username used to login to CPanel
$cppass = "password"; // Password used to login to CPanel
$domain = "domain.com"; // Domain name where CPanel is run
$skin = "x"; // Set to cPanel skin you use (script won't work if it doesn't match). Most people run the default x theme

// Info required for FTP host
$ftpuser = "username"; // Username for FTP account
$ftppass = "password"; // Password for FTP account
$ftphost = "ftp.domain.com"; // Full hostname or IP address for FTP host
$ftpmode = "ftp"; // FTP mode ("ftp" for active, "passiveftp" for passive)

// Notification information
$notifyemail = "myemail@domain.com"; // Email address to send results

// Secure or non-secure mode
$secure = 1; // Set to 1 for SSL (requires SSL support), otherwise will use standard HTTP

// Set to 1 to have web page result appear in your cron log
$debug = 1;

// *********** NO CONFIGURATION ITEMS BELOW THIS LINE *********

if ($secure) {
   $url = "ssl://".$domain;
   $port = 2083;
} else {
   $url = $domain;
   $port = 2082;
}

$socket = fsockopen($url,$port);
if (!$socket) { echo "Failed to open socket connection… Bailing out!\n"; exit; }

// Encode authentication string
$authstr = $cpuser.":".$cppass;
$pass = base64_encode($authstr);

$params = "dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&submit=Generate Backup";

// Make POST to cPanel
fputs($socket,"POST /frontend/".$skin."/backup/dofullbackup.html?".$params." HTTP/1.0
");
fputs($socket,"Host: $domain
");
fputs($socket,"Authorization: Basic $pass
");
fputs($socket,"Connection: Close
");
fputs($socket,"
");

// Grab response even if we don't do anything with it.
while (!feof($socket)) {
  $response = fgets($socket,4096);
  if ($debug) echo $response;
}

fclose($socket);

?>

Changing the join form in Dolphin 7

Dolphin's join form currently uses 'Profile Fields' that you add and manage in the fields builder admin panel. This makes normal use very simple for the junior webmaster. What if you want to seamlessly integrate the dolphin community with your current membership system and prefer to use your current join process.

This was a bit of a trick to figure out. Although now that I've finished, it's bark was worse than its bite ;)

Open the join.php file and locate :

    function showJoinForm() {
        $aJoinFormParams = array(
            'couple_enabled' => $this->bCoupleEnabled,
            'couple'         => $this->bCouple,
            'page'           => $this->iPage,
            'hiddens'        => $this->genHiddenFieldsArray(),
            'errors'         => $this->aErrors,
            'values'         => $this->aValues,
        );
        //echoDbg($this -> oPF);
        echo $this->oPF->getFormCode($aJoinFormParams);
    }
And change to this:
    function showJoinForm() {
        $aJoinFormParams = array(
            'couple_enabled' => $this->bCoupleEnabled,
            'couple'         => $this->bCouple,
            'page'           => $this->iPage,
            'hiddens'        => $this->genHiddenFieldsArray(),
            'errors'         => $this->aErrors,
            'values'         => $this->aValues,
        );
        //echoDbg($this -> oPF);
ob_start();

include("../folder/old_registration.php");
$ret = ob_get_clean();
        echo $ret; //$this->oPF->getFormCode($aJoinFormParams);
    }
Now look at the above pasted text: there is a line:
include("../folder/old_registration.php");
Change this to use the registration form from your current site or application.
Then open your join.php in the browser (to view) and modify the old registration form's CSS or internal style to fit within the dolphin 7 join page and look like it belongs.
You will also need to open the form processing function within your old registration form and add the function to insert the user into the 'Profiles' table of the Dolphin 7 database.
Contact me for help for a custom integration of Dolphin 7 with your current web site.
I will cover integrating the login process so its a single login to dolphin and your current site application, upon request, or comments.

Thursday, September 3, 2009

Customizing your Dolphin Community - a popular topic

Now let's look at PHP within Dolphin and pull it together. I hope this post will help you customize your dolphin (community) site. We'll start by dissecting a simple page from the Dolphin community builder application.

You should read the previous post ( a simple PHP primer ) before reading this popular blog entry on customizing your dolphin web site. It will help you see the very basic PHP skill you should have before customizing your web site yourself.

Let's go ahead and open the file (dolphin root directory) /faq.php - this is the simplest file to start with, when customizing your Boonex community software.

After the Boonex copyright, you will notice the next 2 lines.

require_once( './inc/header.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
These lines include important files for the dolphin framework and should not be removed.

Next in the dolphin page framework we tell it:
$_page['name_index'] = 13;
$_page['css_name'] = 'faq.css';
$_page['name_index'] Tells dolphin to use that numbered template (from the tmpl_uni directory) These template files are called page_xxx.html in your template directory (templates/tmpl_xxx/)

$_page['css_name'] Tells dolphin to include that named css file (for style) 
NOTE: For it to pickup and use the CSS file you reference in this setting, the css file must be in the /templates/tmpl_uni/css/ directory.

Then you will notice more PHP....

if ( !( $logged['admin'] = member_auth( 1, false ) ) )
{
if ( !( $logged['member'] = member_auth( 0, false ) ) )
{
if ( !( $logged['aff'] = member_auth( 2, false ) ) )
{
$logged['moderator'] = member_auth( 3, false );
}
}
}
This is where dolphin looks for the security details.. what level is the current user logged in as. Again, do not alter this yet - we can cover the user-level access in another post about Dolphin security.

Here Dolphin will set some page content but get the actual content from your specific dolphin install and admin settings.

$_page['header'] = _t( "_FAQ_H" );
$_page['header_text'] = _t( "_FAQ_H1", $site['title'] );
Take notice of the function this calls:

$_page['header'] = (we want that variable to be set at runtime)

_t( "_FAQ_H" ); This is what we want to set it to: This is actually the language function, it uses the function _t to get the value from the language settings (managed in dolphin admin panel)

For this example - the function _t uses the language entry _FAQ_H -- which means: in the language file there is an item (key) called _FAQ_H with a value that will replace the _FAQ_H at run time.
You will also notice the use of another variable (being passed to the _t function (  $site['title'] ) this is set in the header.inc.php file in your /inc/ directory and references the site title, you chose during install (or later edited when customizing your dolphin site.
Now the server has processed the above and is creating the HTML content to send to your visitors web browser. It still does not have the bulk of the page - the actual content.

Content is created by the PageCompPageMainCode() function.

$_page_cont[$_ni]['page_main_code'] = PageCompPageMainCode();

$_page_cont[$_ni]['page_main_code']  is what we want to replace with the results of the PageCompPageMainCode() function. Which, if you look at the template file you will see it as 
__page_main_code__ -> and notice where it will place those results in a basic HTML structure.

Lets dissect that function for better understanding how to make changes to it and customize your dolphin community to get out of the cookie cutter contents of such an open source application.

function PageCompPageMainCode()
{
global $oTemplConfig;
    $ret = _t( "_FAQ_INFO" );
    return DesignBoxContent(_t( "_FAQ_H1", $site['title'] ), $ret, $oTemplConfig -> PageCompThird_db_num );
}

 $ret = _t( "_FAQ_INFO" ); -- This is setting the $ret (the HTML code we want in the main content of the page) - it gets the _FAQ_INFO value from that key's entry in the language file. and puts it in the variable $ret

Then... we want to put that value into a Design Block on that page....

return DesignBoxContent(_t( "_FAQ_H1", $site['title'] ), $ret, $oTemplConfig -> PageCompThird_db_num );

Here the PHP 'returns' the design box with the header _FAQ_H1, the site title and then (3rd variable) the actual content from the language key. The final setting there PageCompThird_db_num chooses the type of design box -- border, no border etc.

We can cover those in more details in another post - hopefully this will introduce the very basics of manipulating dolphin into a truly customized social community.

Much more to learn as we move forward creating your unique dolphin site.

See you next time.


PHP (Not as scary as you think)

Where do you start?!
Let's look at the basics to start with. Getting PHP to write things to the web browser, what variables are and how to use them...examples you can use in just about every web page you create.
Let’s start with the most basic one.
The PHP Echo command
We’re going to tell PHP to output something to the screen. Keep in mind that PHP can be used in conjunction with HTML, but we are not showing the code in this example, to keep it simple:
(I hate the “Hello World” sample that every other book in the world uses, so I’m using “Dolphin Community” instead.)
Let’s dissect the command example bit by bit, shall we? It helps to do this when you are looking at a LOT of PHP code...because, trust me, it can look like a jumbled blurry mess sometimes if you don’t take it piece by piece! Next page, please, if you will...
- tells the server to process this as php code...
echo “Dolphin Community” ; - tells the server to write what’s in the quotes to the screen, and that the semicolon is ending this particular command...
?> - tells the webserver, “OK, I’m done with PHP for now. Back to regular HTML”.
Pretty simple when you look at it that way, yes?
“OK, that’s cool..but what if I want to see quotes on my screen?”
This can be done by “escaping” the PHP code for what you want to show up in quotes. Let’s use the example from above...
If you wanted to see quotes around Dolphin Community, you would use the following code instead:
Using \” tells PHP that you want a quotation mark to appear. Remember this - we’re going to use it later!
Pull some Strings...
In PHP, as a general rule, a String is any line of text contained within quotation marks. You can use either double quotation marks (“) or single quotation marks also known as apostrophes (‘) in a string. Strings could be considered the building blocks of PHP, considering most all data is going to come from what’s in a string.
$double = "quotation marks."; 
$single = 'single quotes.'; 
?> 
When using single quotes, you need to “escape” the apostrophe with the slash (just like you would with double quotation marks) if you wish to display it in the output text...
echo 'Let\'s start our own social network\'s with Boonex'; 
?> 
Special commands within strings...
There are some “secret commands” you can use within strings to manipulate the output text: 
\n:  makes a new line 
\r:  a carriage return 
\t:  a tab
\$:  shows a dollar sign - remember PHP will be looking for a variable if you want to display a dollar sign and don’t use a slash...and throw an ugly error! 
Using Variables
A Variable in PHP, simply put, is one thing that means another thing or things - a “container” if you will. It can represent text, numbers, calculations, and more. 
Variables are quite powerful, and if you mess ‘em up, they’ll come get you in the middle of the night.
Declaring a variable is easy. No spaces in the variable name, please - PHP doesn’t like that...
$This_thing = “The Other Thing”;
?>
Now before you go off saying “What the heck would I need THAT for?”, remember that variables are very useful...especially if you are PHP Include-ing other files (Like the foreshadowing there? Do ya?) 
Real World Usage For Variables
Here’s an example of how you can use a variable in the real world: show the current date on your website.
$today = date("F j, Y");
echo "$today";
?>
This example sets the date command as a variable called “$today”, and uses echo to display it on the screen.
And now, for a quick tangent...
More about the “DATE” command - it is very versatile and flexible - see the guide below to use it to it’s potential!
 SHAPE  \* MERGEFORMAT 
And now...back to Variables!
ECHOing more that one Variable at a time
You can use the ECHO command we learned earlier to display more than one variable at a time. Combining variables can be extremely useful. Take a look at this example...
$phrase1 = "That's No Moon,";
$phrase2 = "It's a Space Station!";
echo "$phrase1 $phrase2";
?>
This code example will show up in your web browser like this:
Neat, huh?
So, you can see where this might be useful, I hope?
You can also echo text and variables in the same statement by putting periods around the variable....like so...
$items = 3; 
echo "You have purchased ".$items." items."; 
?> 

Wednesday, September 2, 2009

Add/Remove 'Actions' - Dolphin profile view

You can change the options in the actions menu (on the profile view page) by following these simple steps.

Open:
/templates/base/scripts/BxBaseProfileView.php

Find the function:
showBlockActionsMenu()

You will  find within this function are the links. Add and remove links in this area.
BEWARE:: Make sure you keep the code entact, and follow the other links as guides. For instance - one link opens a standard page within the same browser - other links have an OnClick event - which opens a pop up window.

As long as you are careful to add a new link in the exact fashion, or remove a link by taking away the entire line (from $ret .= all the way to and including the semi-colin. ( ; ) - you will be able to completely customize this area of your dolphin community.