Showing posts with label Coldfusion. Show all posts
Showing posts with label Coldfusion. Show all posts

Monday, 31 January 2011

Filtering/Cleaning URLs, html tags from the string/text

Cleaning up all URLs, html tags from the string/text

/*
* @param string $text = the text for filtering url, links, html tags.
* @return array filtered text;
*/
static function text_cleaner($string) {
$string = htmlentities(strip_tags($string, '
')); // stripping the html tags
$U = explode(' ',$string);
$W =array();

foreach ($U as $k => $u) {
if (stristr($u,".")) { //only preg_match if there is a dot
if (self::containsTLD($u) === true) {
unset($U[$k]);
return self::text_cleaner( implode(' ',$U));
}
}
}
return implode(' ',$U);

/* For testing the function.
* echo $url = "aaaa.com Here is helllow.com another funny site badurl.badone somesite.ca/worse.jpg but this badsite.com www.tinyurl.com/55555 and http://www.tinyurl.com/55555 and img.hostingsite.com/badpic.jpg";
* echo '
';
* echo "Cleaned: " . $v->text_cleaner($url);
* */
}

static function containsTLD($string) {
preg_match(
"/(AC($|\/)|\.AD($|\/)|\.COM($|\/)|\.AE($|\/)|\.AERO($|\/)|\.AF($|\/)|\.AG($|\/)|\.AI($|\/)|\.AL($|\/)|\.AM($|\/)|\.AN($|\/)|\.AO($|\/)|\.AQ($|\/)|\.AR($|\/)|\.ARPA($|\/)|\.AS($|\/)|\.ASIA($|\/)|\.AT($|\/)|\.AU($|\/)|\.AW($|\/)|\.AX($|\/)|\.AZ($|\/)|\.BA($|\/)|\.BB($|\/)|\.BD($|\/)|\.BE($|\/)|\.BF($|\/)|\.BG($|\/)|\.BH($|\/)|\.BI($|\/)|\.BIZ($|\/)|\.BJ($|\/)|\.BM($|\/)|\.BN($|\/)|\.BO($|\/)|\.BR($|\/)|\.BS($|\/)|\.BT($|\/)|\.BV($|\/)|\.BW($|\/)|\.BY($|\/)|\.BZ($|\/)|\.CA($|\/)|\.CAT($|\/)|\.CC($|\/)|\.CD($|\/)|\.CF($|\/)|\.CG($|\/)|\.CH($|\/)|\.CI($|\/)|\.CK($|\/)|\.CL($|\/)|\.CM($|\/)|\.CN($|\/)|\.CO($|\/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.VC($|\/)|\.VE($|\/)|\.VG($|\/)|\.VI($|\/)|\.VN($|\/)|\.VU($|\/)|\.WF($|\/)|\.WS($|\/)|\.XN--0ZWM56D($|\/)|\.XN--11B5BS3A9AJ6G($|\/)|\.XN--80AKHBYKNJ4F($|\/)|\.XN--9T4B11YI5A($|\/)|\.XN--DEBA0AD($|\/)|\.XN--G6W251D($|\/)|\.XN--HGBK6AJ7F53BBA($|\/)|\.XN--HLCJ6AYA9ESC7A($|\/)|\.XN--JXALPDLP($|\/)|\.XN--KGBECHTV($|\/)|\.XN--ZCKZAH($|\/)|\.YE($|\/)|\.YT($|\/)|\.YU($|\/)|\.ZA($|\/)|\.ZM($|\/)|\.ZW)/i",
$string,
$M);
$has_tld = (count($M) > 0) ? true : false;
return $has_tld;
}

Wednesday, 12 May 2010

How to CURL the site using PHP CURL Spider in your site.

\< ? php
/ * Before Running this Curl. First Goto
*
* 1. Enable the PHP CURL library in you apache configuration.
* 2. First open the "php.ini" file of your apache or php configuration file.
* for example, in Xampp on Windows, goto /xampp/php/php.ini.
* 3. then open that file and find the ";extension=php_curl.dll" and remove the semicolumn(;) from that line and change into "extension=php_curl.dll".
* 4. Finally, Restart the Apache Server.
* 5. Run the following file by providing necessary curl_url and and curled_filename.
* 6. Goto the index-curled.html file to check the curled result.
* * /

$url_to_curl = "http://localhost/mysite/";
$curled_filename = "index-curled.html";

$ch = curl_init($url_to_curl);
$fp = fopen($curled_filename, "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

if(!curl_errno($ch))
{
$info = curl_getinfo($ch);
echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
}

curl_exec($ch);
curl_close($ch);
fclose($fp);

? >
In Coldfusion CURL CURLING,
We can use the [ cfhttp ] tag for curl.
and [ cffile ] to save the file

Sunday, 6 December 2009

Creating a MySQL Datasource in Coldfusion(CF) Server

Before we can create a ColdFusion datasource we need to create a empty MySQL database to point the datasource at.

Create Empty Database

To create an empty MySQL database for your ShadoCMS site use your favorite client to connect to your database server and create the database as you normally would but with the following encoding settings:

Character Set utf8
Collation utf8_unicode_ci

Create Datasource

You now need to create a new datasource in the ColdFusion Administrator and point it to the new empty database you have just created.

Login to the ColdFusion Administrator on the server at http://localhost/cfide/administrator/.

Click on the “Datasources” link in the left navigation.

Enter the name of the new site in the “Add New Datasource” box, select the "MySQL (4/5)" driver, and click "Add".

On the next screen, fill in the following connection details:

CF Data Source Name (The name of your ShadoCMS site you want to create) eg “emptysite”
Database (The name of your database) eg “emptysite”
Server (The name of your database server) eg “localhost”
Port 3306
Username [your database username]
Password [your database password]
Advanced Settings:
Connection String
Enter text: “useUnicode=true&characterEncoding=UTF-8”

Click “Submit”. You should be informed that the datasource was updated successfully.

Creating a Shado Site

Now that you have a empty database and a ColdFusion datasource setup you now need to create a ShadoCMS site.

This is the way to connect mysql to Coldfusion server's datasource.

Friday, 13 November 2009

To reload the Parent Window from Clild Window by Javascript


< a href="#" onClick="javascript:parent.location.reload()" > Click to Reload Parent window < /a >

Thursday, 12 November 2009

HTML to PDF, generate PDF with HTML data,

To generate the HTML contents in PDF datatype or .pdf file format. Use the following steps:

1. Download the dompdf from
    http://code.google.com/p/dompdf/
or http://sourceforge.net/projects/dompdf/

2. Upzip(if necessary) and keep the dompdf/ folder at your's project root directory.

then, make a function to generate pdf file for download or write a file to the disk as;

/* function to generate the .pdf file for download. */

function get_generate_pdf ($htmlContent, $filename)
{
require_once ("../dompdf/dompdf_config.inc.php");

$dompdf = new DOMPDF();
$dompdf -> load_html($htmlContent);
$dompdf -> render();

$dompdf -> stream($filename);
}

/* function to write the .pdf file with HTML Contents. */
function get_write_pdf_file ($htmlContent, $filename)
{
require_once ("../dompdf/dompdf_config.inc.php");

$dompdf = new DOMPDF();
$dompdf -> load_html($htmlContent);
$dompdf -> render();

$pdfContent = $dompdf -> output();
file_put_contents($filename, $pdfContent);
}

/* function to write the file Contents. */
function get_write_file ($content, $filename, $mode="w")
{
$fp = @fopen ($file, $mode);

if ( ! is_resource($fp)) { return false; }

fwrite ($fp, $content);
fclose ($fp);
}

$htmlContent = "< html >< head >< title >SamplePDF file< /title >< /head >
< body >< strong >You can include any kinda html content in this body format.< /strong >< /body >< /html >";

$filename = "sample_pdf_file.pdf";

/* Calling above function for html content in pdf attachment file format. */
get_generate_pdf ($htmlContent, $filename)

/* Calling above function for html content in pdf attachment file format. */
get_generate_pdf ($htmlContent, $filename);

Friday, 6 November 2009

PDF and PHP, Generate PDFs with PHP

There is a lot of PHP code available to generate PDF but most of it requires downloading and installing php extensions. In a shared hosting environment you don't always have access to php configuration, which is why ezPDF is nice. ezPDF is open source PDF generation PHP. See below for an example of 'on the fly' pdf generation, using ezPDF.

include_once ('class.ezpdf.php');
//ezpdf: from http://www.ros.co.nz/pdf/?
//docs: http://www.ros.co.nz/pdf/readme.pdf
//note: xy origin is at the bottom left

//data
$colw = array( 80 , 40, 220, 80, 40 );//column widths
$rows = array(
array('company','size','desc','cost','instock'),
array("WD", "80GB","WD800AAJS SATA2 7200rpm 8mb" ,"$36.90","Y"),
array("WD","160GB","WD1600AAJS SATA300 8mb 7200rpm" ,"$39.87","Y"),
array("WD", "80GB","800jd SATA2 7200rpm 8mb" ,"$41.90","Y"),
array("WD","250GB","WD2500AAKS SATA300 16mb 7200rpm" ,"$49.88","Y"),
array("WD","320GB","WD3200AAKS SATA300 16mb 7200rpm" ,"$49.90","Y"),
array("WD","160GB","1600YS SATA raid 16mb 7200rpm" ,"$59.90","Y"),
array("WD","500GB","500gb WD5000AAKS SATA2 16mb 7200rpm","$64.90","Y"),
array("WD","250GB","2500ys SATA raid 7200rpm 16mb" ,"$69.90","Y"),
);

//x is 0-600, y is 0-780 (origin is at bottom left corner)
$pdf =& new Cezpdf('LETTER');

$image = imagecreatefrompng("background.png");
$pdf->addImage($image,0,0,611);

$pdf->selectFont("fonts/Helvetica.afm");
$pdf->setColor(0/255,0/255,0/255);
$pdf->addText(80,620,10,"List of Hard Drives");

$pdf->setLineStyle(0.5);
$pdf->line(80,615,540,615);
$pdf->setStrokeColor(0,0,0);

$pdf->setColor(0/255,0/255,0/255);
$pdf->addText(30,16,8,"Created ".date("m/d/Y"));

$total=0;
$curr_x=80;
$curr_y=600;
foreach($rows as $r)
{
$xoffset = $curr_x;
foreach($r as $i=>$data)
{
$pdf->setColor(0/255,0/255,0/255);
$pdf->addText( $xoffset, $curr_y , 10, $data );
$xoffset+=$colw[$i];
}
$curr_y-=20;
}

$pdf->ezStream();
?>


Demo:
Download Demo PDF (dynamically generated with php)
Download all-in-one example.zip 349KB (includes ezPDF)

Notes:
* The above code generates a 1 page pdf, but a multi-page PDF is possible using the $pdf->ezNewPage() function. Any $pdf->addText() or $pdf->addImage() calls after that point are added to the new page.
* The size of a LETTER page in ezPDF is 612x792 (w by h in pixels)
* The (x,y) origin (0,0) is at the bottom left of a PDF page

Further Reading
* ezPDF and
* ezPDF API Docs[pdf]
* pdf-php at sourceforge

Friday, 30 October 2009

Regular Expression (Validation) Examples in PHP

The Regular Expressions quickly covers the basics of regular-expression syntax, then delves into the mechanics of expression-processing, common pitfalls, performance issues, and implementation-specific differences. Written in an engaging style and sprinkled with solutions to complex real-world problems, MRE offers a wealth information that you use. I will start with some simple usage examples of the regular expressions and continue with a huge list of cases for various situations where we would normally need a regex to operate. We will use simple functions which return TRUE or FALSE. $regex will serve as our regular expression to match against and $text will be our text (pretty obvious):
function do_reg($text, $regex)
{
 if (preg_match($regex, $text)) {
  return TRUE;
 }
 else {
  return FALSE;
 }
}
The next function will get the part of a given string ($text) matched by the regex ($regex) using a group srorage ($regs). By changing the $regs[0] to $regs[1] we can use a capturing group (in this case griup 1) to match against. The capturing group can also have a name ($regs['groupname']):
function do_reg($text, $regex, $regs)
{
 if (preg_match($regex, $text, $regs)) {
  $result = $regs[0];
 }
 else {
  $result = "";
 }
 return $result;
}  

The following function will return an array of all regex matches in a given string ($text):
function do_reg($text, $regex)
{
 preg_match_all($regex, $text, $result, PREG_PATTERN_ORDER);
 return $result = $result[0];
}

Next we can iterate (loop) over all matches in a string ($text) and output the results:
function do_reg($text, $regex, $regs)
{
 preg_match_all($regex, $text, $result, PREG_PATTERN_ORDER);
  for ($i = 0; $i < count($result[0]); $i++) {
  $result[0][$i];
 }
}  

Extending the above one we can iterate over all matches ($text) and capture groups in a string ($text):
function do_reg($text, $regex)
{
 preg_match_all($regex, $text, $result, PREG_SET_ORDER);
 for ($matchi = 0; $matchi < count($result); $matchi++) {
  for ($backrefi = 0; $backrefi < count($result[$matchi]); $backrefi++) {
   $result[$matchi][$backrefi];
  }
 }
} 

EXAMPLES:
For Date

$date_regex = "/^(0[1-9]|[12][0-9]|3[01])[\-\/\.](0[1-9]|1[012])[\-\/\.](19|20)[\d][\d]$/";
$date_regex = "/^(0[1-9]|[12][0-9]|3[01])[\-\/.](0[1-9]|1[012])[\-\/.](19|20)[\d][\d]$/";


//Date d/m/yy and dd/mm/yyyy
//1/1/00 through 31/12/99 and 01/01/1900 through 31/12/2099
//Matches invalid dates such as February 31st
'\b(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}\b'

//Date dd/mm/yyyy
//01/01/1900 through 31/12/2099
//Matches invalid dates such as February 31st
'(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}'

//Date m/d/y and mm/dd/yyyy
//1/1/99 through 12/31/99 and 01/01/1900 through 12/31/2099
//Matches invalid dates such as February 31st
//Accepts dashes, spaces, forward slashes and dots as date separators
'\b(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}\b'

//Date mm/dd/yyyy
//01/01/1900 through 12/31/2099
//Matches invalid dates such as February 31st
'(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}'

//Date yy-m-d or yyyy-mm-dd
//00-1-1 through 99-12-31 and 1900-01-01 through 2099-12-31
//Matches invalid dates such as February 31st
'\b(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])\b'

//Date yyyy-mm-dd
//1900-01-01 through 2099-12-31
//Matches invalid dates such as February 31st
'(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])' 
/-------------------------------------------------------------------------------/ For Address /-------------------------------------------------------------------------------/
//Address: State code (US)
'/\\b(?:A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])\\b/'

//Address: ZIP code (US)
'\b[0-9]{5}(?:-[0-9]{4})?\b' 
/-------------------------------------------------------------------------------/ For Email /-------------------------------------------------------------------------------/
//Email address
//Use this version to seek out email addresses in random documents and texts.
//Does not match email addresses using an IP address instead of a domain name.
//Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum.
//Including these increases the risk of false positives when applying the regex to random documents.
'\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b'

//Email address (anchored)
//Use this anchored version to check if a valid email address was entered.
//Does not match email addresses using an IP address instead of a domain name.
//Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum.
//Requires the "case insensitive" option to be ON.
'^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$'

//Email address (anchored; no consecutive dots)
//Use this anchored version to check if a valid email address was entered.
//Improves on the original email address regex by excluding addresses with consecutive dots such as john@aol...com
//Does not match email addresses using an IP address instead of a domain name.
//Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum.
//Including these increases the risk of false positives when applying the regex to random documents.
'^[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$'

//Email address (no consecutive dots)
//Use this version to seek out email addresses in random documents and texts.
//Improves on the original email address regex by excluding addresses with consecutive dots such as john@aol...com
//Does not match email addresses using an IP address instead of a domain name.
//Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum.
//Including these increases the risk of false positives when applying the regex to random documents.
'\b[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b'

//Email address (specific TLDs)
//Does not match email addresses using an IP address instead of a domain name.
//Matches all country code top level domains, and specific common top level domains.
'^[A-Z0-9._%-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|biz|info|jobs|museum|name)$'

//Email address: Replace with HTML link
'\b(?:mailto:)?([A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4})\b' 
/-------------------------------------------------------------------------------/ For Credit Cards /-------------------------------------------------------------------------------/
//Credit card: All major cards
'^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$'

//Credit card: American Express
'^3[47][0-9]{13}$'

//Credit card: Diners Club
'^3(?:0[0-5]|[68][0-9])[0-9]{11}$'

//Credit card: Discover
'^6011[0-9]{12}$'

//Credit card: MasterCard
'^5[1-5][0-9]{14}$'

//Credit card: Visa
'^4[0-9]{12}(?:[0-9]{3})?$'

//Credit card: remove non-digits
'/[^0-9]+/'

//Delimiters: Replace commas with tabs
//Replaces commas with tabs, except for commas inside double-quoted strings
'((?:"[^",]*+")|[^,]++)*+,'

/-------------------------------------------------------------------------------/ For HTML /-------------------------------------------------------------------------------/
//HTML comment
''

//HTML file
//Matches a complete HTML file. Place round brackets around the .*? parts you want to extract from the file.
//Performance will be terrible on HTML files that miss some of the tags
//(and thus won't be matched by this regular expression). Use the atomic version instead when your search
//includes such files (the atomic version will also fail invalid files, but much faster).
'.*?.*?.*?.*?]*>.*?.*?'

//HTML file (atomic)
//Matches a complete HTML file. Place round brackets around the .*? parts you want to extract from the file.
//Atomic grouping maintains the regular expression's performance on invalid HTML files.
'(?>.*?)(?>.*?)(?>.*?)(?>.*?]*>)(?>.*?).*?'

//HTML tag
//Matches the opening and closing pair of whichever HTML tag comes next.
//The name of the tag is stored into the first capturing group.
//The text between the tags is stored into the second capturing group.
'<([A-Z][A-Z0-9]*)[^>]*>(.*?)'

//HTML tag
//Matches the opening and closing pair of a specific HTML tag.
//Anything between the tags is stored into the first capturing group.
//Does NOT properly match tags nested inside themselves.
'<%TAG%[^>]*>(.*?)'

//HTML tag
//Matches any opening or closing HTML tag, without its contents.
']*>' 

Friday, 6 February 2009

Do you know how to retieve the form value from bean in MVC Framework in Coldfusion ?

While working with MVC framework, if you want to retrieve the value from UI form elements to bean file of model.
Sometimes, we have this kinda problem, we are not able to retrieve value from bean. To resolve the value which are provided to UI, at that time, the Name of function on Bean file should be exactly same as the elements NAME value in UI.

Lets take a small example here,
you make a userBean.cfc at with the following content;

< cfcomponent output="false" name="userBean" displayName="Users Bean" >
< cfset variables.instance.username = "" / >
< cfset variables.instance.password = "" / >

< cffunction name="setUsername" returnType="void" access="public" output="false" >
< cfargument name="username" type="string" required="true" >
< cfset variables.instance.username = arguments.username >
< /cffunction >

< cffunction name="getUsername" returnType="string" access="public" output="false" >
< cfreturn variables.instance.username >
< /cffunction >

< cffunction name="setPassword" returnType="void" access="public" output="false" >
< cfargument name="password" type="string" required="true" >
< cfset variables.instance.password = arguments.password >
< /cffunction >

< cffunction name="getPassword" returnType="string" access="public" output="false" >
< cfreturn variables.instance.password >
< /cffunction >
< /cfcomponent >

you have a UI file as login.cfm at with the following content;
 
< cfform action="#viewstate.getValue('myself')#adminLoggedIn" method="post" >
< span >Sign In< /span >
< label for="username" >Email:< /label >
< cfinput type="text" name="username" value=""/ >< br / >
< label for="password" >Password:< /label >
< cfinput type="password" name="password" value=""/ >< br / >
< input type="submit" value="Submit" / >
< /cfform >

Now, if you go through above Bean file (userBean.cfc) & UI file (login.cfm),
the name= "username" and name="password" of login.cfm file have same name as the function name of userBean.cfc file as
setUsername();
getUsername();
setPassword();
getPassword();

Which do really work out.

if name value of login form and function name after have get/set prefix should be exactly same, otherwise it will not work out.