Aug 27

Wondering how to check the content of an FCKEditor? You will love this simple code!!!

<?php
include("fckeditor/fckeditor.php") ;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title>FCKeditor - Sample</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="robots" content="noindex, nofollow">
		<script>

function getRTEText(fckinst){
  var oEditorHTML = FCKeditorAPI.GetInstance(fckinst).GetHTML();
  alert(oEditorHTML);
}
</script>
	</head>
	<body>

		<form action="request.php" method="post">

<?php
	$oFCKeditor = new FCKeditor('content');
	$oFCKeditor->BasePath = "fckeditor/";
	$oFCKeditor->Value = $content['message'];
	oFCKeditor->Config['UserFilesPath'];
	$oFCKeditor->Height = "440";
	$oFCKeditor->Create();
?>

			<br>
			<input type="button" onclick="javaScript:getRTEText('content');" value="check">
			<input type="submit" value="Submit">
		</form>
	</body>
</html>
Tagged with:
Aug 19

Some developers are linking downloadable files directly on their pages and the reason why we get stucked when accidentally clicked a “.pdf” or large “.txt” files. The function below will allow the user to force download the file instead of opening it in the browser.

<?
function force_download($file)
{
    $dir      = "../log/exports/";
    if ((isset($file))&&(file_exists($dir.$file))) {
       header("Content-type: application/force-download");
       header('Content-Disposition: inline; filename="' . $dir.$file . '"');
       header("Content-Transfer-Encoding: Binary");
       header("Content-length: ".filesize($dir.$file));
       header('Content-Type: application/octet-stream');
       header('Content-Disposition: attachment; filename="' . $file . '"');
       readfile("$dir$file");
    } else {
       echo "No file selected";
    } //end if

}//end function
?>
Tagged with:
Aug 18

This piece of code will help you strip links from a string.

<?php
function strip_urls($text, $repPat)
{
    if(!$repPat){
        $repPat = &quot;text [url]&quot;;
    }
    $aimpstr = 'STRIP_URL_IN_PHP';
    //change $aimpstr to anything you want.
    $impstr = md5($aimpstr);
    $text = str_replace('&lt;/a&gt;', '&lt;/a&gt;' . $impstr, $text);
    $text = explode($impstr, $text);
    $n = 0;
    $texta = array();
    $repPat = str_ireplace(array('text', 'url'), array('\\4', '\\2'), $repPat);
    foreach ($text as $text) {
        $texta[$n] = ereg_replace(&quot;&lt;a(.*)href=\&quot;(.*)\&quot;(.*)&gt;(.*)&lt;/a&gt;&quot;, $repPat, $text);
        $n++;
    }
    $textb = implode(&quot;&lt;/a&gt;&quot;, $texta);
    return $textb;
}

//EXAMPLES:
$string_of_text = '&lt;a href=&quot;http://blog.bauson.com/&quot;&gt;Jay-ar&lt;/a&gt; Bauson. &lt;a href=&quot;http://www.bosjef.com/&quot;&gt;Bosjef&lt;/a&gt; TEXT!';
echo strip_urls($string_of_text, &quot;text&quot;);
echo strip_urls($string_of_text, &quot;url&quot;);
echo strip_urls($string_of_text, &quot;text [url]&quot;);
echo strip_urls($string_of_text, NULL);
?>
Tagged with:
Aug 14

Have you tried using FCKEditor to allow your user to upload files? Its one of the best WYSIWYG(What You See Is What You Get), but how about considering FCKEditor to create their own gallery? User will have their own directory. Ahem!!!!

In your FCKeditor directory find the config.php for php connector:
fckeditor/editor/filemanager/browser/default/connectors/php/config.php
Add this code in the topmost of the file:

<?
php session_start();

then search for this code:

$Config['UserFilesPath'] = '';

and replace it with

$Config['UserFilesPath'] = '/userfiles/'.$_SESSION['member_id'].'/';

Note that $_SESSION['member_id'] can be changed to whatever youd like to be the identifier of your users. Be sure to authenticate your user and set their ID’s in the session variable.

**Some developers do have hard time configuring the filebrowser, they can upload but cannot browse what are in the server. To fix this issue, open the frmresourcelist.html
fckeditor/editor/filemanager/browser/default/frmresourcelist.html

Search for:

oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize )
{
	// Build the link to view the folder.
	var sLink = '<a href="#" onclick="OpenFolder(\'' + ProtectPath( folderPath ) + '\');return false;">' ;

and replace it to:

oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize )
{
	// Build the link to view the folder.
	var sLink = '<a href="#" onclick="OpenFile(\'http://YOURDOMAIN' + fileUrl.replace( /'/g, '\\\'') + '\');return false;">' ;
Tagged with:
Aug 13

Its been five(5) months now since we started parsing huge(500mb) XML files, the tasks were challenging because of the different format of feeds that we need to unify. We have designed a general parser that can return an array version of the feed but sometimes it fails because of unusual XML structure. Its good thing to have a general parser, but if you would like to start learning how to parse XML in PHP, use SimpleXML.

Save the code below as sample.xml

<Employees>
  <Employee id="033-1998-0371" Year="1998">
      <Name name="Jay-ar Bauson" age="21" />
      <Course>Bachelor of Science in Computer Science</Course>
  </Employee>
  <Employee id="245-2008-1830" Year="2009">
      <Name name="John Doe" age="26" />
      <Course>Bachelor of Science in Information Technology</Course>
  </Employee>
</Employees>

and save this as parser.php

<?php
$xml = simplexml_load_file('sample.xml');
foreach($xml as $row){
     echo "ID: ".$row->attributes()->id."<br/>";
     echo "Year: ".$row->attributes()->Year."<br/>";
     echo "Name: ".$row->Name->attributes()->name."<br/>";
     echo "Age: ".$row->Name->attributes()->age."<br/>";
     echo "Course: ".$row->Course."<hr/>";
}
?>

Executing parser.php from your browser will result something like:

ID: 033-1998-0371
Year: 1998
Name: Jay-ar Bauson
Age: 21
Course: Bachelor of Science in Computer Science
______________________________________________________
ID: 245-2008-1830
Year: 2009
Name: John Doe
Age: 26
Course: Bachelor of Science in Information Technology
______________________________________________________
Tagged with:
Aug 07

The Apache KeepAlive directive specifies that TCP/IP connections from clients to the Apache server are to be kept ‘alive’ for a given duration specified by the value of KeepAliveTimeout (the default is 15 seconds). This is useful when you serve out heavy HTML with embedded images or other resources, since browsers will open just one TCP/IP connection to the Apache server and all the resources from that page will be retrieved via that connection.

If, however, your Apache server handles small individual resources (such as images), then KeepAlive is overkill, since it will make every TCP connection linger for N seconds. Given a lot of clients, this can quickly saturate your Apache server in terms of network connections.

So…if you have a decent server that doesn’t seem to be overloaded in terms of CPU/memory, yet Apache is slow-to-unresponsive, check out the KeepAlive directive and try setting it to Off. Note that the default value is On.

Tagged with:
Aug 06

These functions are specially designed for dynamic pages, and work without error with zero, one, or more radio buttons. Also, because the radio length is saved before looping, this function is much faster. Finally, the functions are granted to the public domain.

Source Code

return the value of the radio button that is checked
return an empty string if none are checked, or there are no radio buttons

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

set the radio button with the given value as being checked
do nothing if there are no radio buttons
if the given value does not exist, all the radio buttons are reset to unchecked

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
Tagged with:
Jun 25

You might want to customize your favorite theme to add Google Adsense, but you are not familiar with the WordPress Framework.

Post a link of your theme and I will create an adsense version of it.

Here’s your chance to get an adsense ready version of you favorite WPtheme.

Cheers!

Tagged with:
Jun 20

You may find this useful to translate some part of your site content. ;)

Usage:

$google = new Google_API_translator();
$google->setOpts($text_info);
$google->translate();
echo $j->out;

<?php
class Google_API_translator {
    public $opts = array("text" => "", "language_pair" => "en|tl");
    public $out = "";

    function __construct() {
    }

    function setOpts($opts) {
        if($opts["text"] != "") $this->opts["text"] = $opts["text"];
        if($opts["language_pair"] != "") $this->opts["language_pair"] = $opts["language_pair"];
    }

    function translate() {
        $this->out = "";
        $google_translator_url = "http://translate.google.com/translate_t?langpair=".urlencode($this->opts["language_pair"])."&";
        $google_translator_data .= "text=".urlencode($this->opts["text"]);
        $gphtml = $this->postPage(array("url" => $google_translator_url, "data" => $google_translator_data));
        $out = substr($gphtml, strpos($gphtml, "<div id=result_box dir=\"ltr\">"));
        $out = substr($out, 29);
        $out = substr($out, 0, strpos($out, "</div>"));
        $this->out = utf8_encode($out);
        return $this->out;
    }

    // post form data to a given url using curl libs
    function postPage($opts) {
        $html = "";
        if($opts["url"] != "" && $opts["data"] != "") {
            $ch = curl_init($opts["url"]);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_HEADER, 1);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 15);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $opts["data"]);
            $html = curl_exec($ch);
            if(curl_errno($ch)) $html = "";
            curl_close ($ch);
        }
        return $html;
    }
}
?>
Tagged with:
Jun 19

To encrypt an array:


$encrypt=base64_encode(serialize($array));

To decrypt:


$decrypt=unserialize(base64_decode($encrypt));

This can be applied through URLs and storing directly to your DB.

Tagged with:
preload preload preload
Bless CV