If no results exist in mysql table echo something else? - php

can someone please help me, i am trying to show different images based on the records i have for each user in my table 'permissions'. i am using .
if the records dont exist in the table i want to include a different file path i.e.
At the moment it brings up results if the users permission is set to 1 or 0 but i want to make it so that if no results are found in the table it shows something as a default.
code:
<?php if (logged_in()) {
$account_perms = account_perms();
while ($perms = mysql_fetch_array($account_perms)) {
if ($perms['privellages'] == '1') {
if ( mysql_num_rows( $perms ) > 0 )
include('includes/mod_profile/mod_photos/private.php');
}
}
$account_perms = account_perms();
while ($perms = mysql_fetch_array($account_perms)) {
if ($perms['privellages'] == '0') {
include('includes/mod_profile/mod_photos/private2.php');
}
}
$account_perms = account_perms();
while ($perms = mysql_fetch_array($account_perms)) {
if($perms->num_rows > 0) {
include('includes/mod_profile/mod_photos/private2.php');
}
}
} ?>

Try this:
<?
if (logged_in()) {
$account_perms = account_perms();
if (mysql_num_rows($account_perms)) {
while ($perms = mysql_fetch_array($account_perms)) {
if ($perms['privellages'] == '1') {
if (mysql_num_rows($perms) > 0)
include ('includes/mod_profile/mod_photos/private.php');
}
}
} else {
echo 'No records';
}
$account_perms = account_perms();
if (mysql_num_rows($account_perms)) {
while ($perms = mysql_fetch_array($account_perms)) {
if ($perms['privellages'] == '0') {
include ('includes/mod_profile/mod_photos/private2.php');
}
}
} else {
echo 'No records';
}
$account_perms = account_perms();
if (mysql_num_rows($account_perms)) {
while ($perms = mysql_fetch_array($account_perms)) {
if ($perms -> num_rows > 0) {
include ('includes/mod_profile/mod_photos/private2.php');
}
}
} else {
echo 'No records';
}
}
?>

Related

How do I add the file in the controller in Codeignator?

I am using Codeignator. My issue is, How do I add the file in the controller?
Let's explain in detail
I have code in the controller something like this below code. Just notice that if-else condition is twice.
foreach($order_list as $order) {
if (is_array($order)) {
foreach($order as $r) {
if ($r - > status == -1) {
//button
} elseif($r - > status == 1) {
//button
} elseif($r - > status == 2) {
//button
} elseif($r - > status == 3) {
//button
} else {
//button
}
// It will increase more in future
}
} else {
// same if-else code
if ($r - > status == -1) {//button}
elseif($r - > status == 1) {//button}
elseif($r - > status == 2) {//button}
elseif($r - > status == 3) {//button }
else {//button}
// It will increase more in future
}
}
So I thought, I will create a new file and add it something like this
foreach($order_list as $order) {
if (is_array($order)) {
foreach($order as $r) {
//externalfile.php
}
} else {
//externalfile.php
}
}
externalfile.php
if ($r - > status == -1) {
//button
} elseif($r - > status == 1) {
//button
} elseif($r - > status == 2) {
//button
} elseif($r - > status == 3) {
//button
} else {
//button
}
Why I am doing like this because I don't know to increase the number of lines and I don't want to change any condition or text or any HTML twice in the future.
Would you help me out or any other idea to solve this?
Actual code.
foreach($order_list as $order) {
if(is_array($order)){
foreach($order as $r) {
$encryption_id=base64_encode($this->encryption->encrypt($r->cust_id));
$this->myCode($r);//added here
$data[] = array(
"Sr_No" => $n,
"cust_id" =>$encryption_id,//encrpt the id
"Name"=>$r->c_firstname."".$r->c_lastname
);
$n++;
}
} else{
$this->myCode($r);//added here
}
}
public function myCode($status) {
if ($status== -1) {
$order_status='Action name';
} elseif($status == 0) {
$order_status='Action name';
} elseif($status == 1) {
$order_status='Action name';
} else {
$order_status='Action name';
}
}
I think it's best to add an another method to your controller
public function myCode($status) {
if ($status == -1) {//button}
elseif($status == 1) {//button}
elseif($status == 2) {//button}
elseif($status == 3) {//button }
else {//button}
}
You should call it the following:
$this->myCode($order_list);
for example:
foreach($order_list as $order) {
if (is_array($order)) {
foreach($order as $r) {
$this->myCode($r);
//some else
}
} else {
$this->myCode($order);
}
}

How to get the result of elseif in php to jquery

PHP
$name = karlaxis;
if ($name == "") {
return false;
} elseif ($name != karlaxis) {
return false;
} else {
return true;
}
jQuery
$.post("#name-form").attr("action").serializearray(), function(result){
if (result == false) {
console.log("result of the IF CONDITION");
} elseif (result == false) { //the result of ELSEIF in php
console.log("result of the ELSEIF CONDITION");
} else {
console.log("result of the ELSE CONDITION");
}
})
Now, how to get the result of the elseif?
How to code that one?
If it is very important to get the result of different conditions, you can do a simple trick with your code. Rather than returning bool you may return int values like 0,1,2 where 0 is for IF, 1 is for ELSE IF, 2 is for ELSE.
php:
$name = karlaxis;
if($name == ""){
return 0;
}elseif($name != karlaxis){
return 1;
}else{
return 2;
}
jquery:
$.post("#name-form").attr("action").serializearray(), function(result){
IF(result == 0){
console.log("result of the IF CONDITION");
}ELSE IF(result == 1){ //the result of ELSEIF in php
console.log("result of the ELSEIF CONDITION");
}ELSE{
console.log("result of the ELSE CONDITION");
}
})

PHP strpos dont works properly(Path Generator)

I wanted to create a function that generates an image path from an array.The function has one argument and that argument is for you to decide from which folder you want to choose images.
So I have 90 elements in an array and each element is a path.Now I don't want a .png image so I wanted to create something like this(but it didn't work for me):
public function getRandomPath($RoboticOrArenag)
{
if ($RoboticOrArenag == 'Robotic' || $RoboticOrArenag == 'robotic') {
$countofarray = count($this->allImagesRobotic);
} else if ($RoboticOrArenag == 'Arenag' || $RoboticOrArenag == 'arenag') {
$countofarray = count($this->allImagesArenag);
} else {
$RoboticOrArenag = 0;
}
$randomNumber = rand(0, $countofarray);
if ($RoboticOrArenag == 'Robotic' || $RoboticOrArenag == 'robotic') {
if($randomNumber==50){
$randomNumber--;
}
else if ($randomNumber==0){
$randomNumber++;
}
$randomNumberPath = $this->allImagesRobotic[$randomNumber];
} else if ($RoboticOrArenag == 'Arenag' || $RoboticOrArenag == 'arenag') {
if($randomNumber==33){
$randomNumber--;
}
else if ($randomNumber==0){
$randomNumber++;
}
$randomNumberPath = $this->allImagesArenag[$randomNumber];
while(strpos($randomNumberPath, '.png') == true){
$randomNumber = rand(0, $countofarray);
$randomNumberPath = $this->allImagesArenag[$randomNumber];
}
} else {
$randomNumberPath = 0;
}
$randomPath = "/img/$RoboticOrArenag/$randomNumberPath";
return $randomPath;
}

PHP code won't work after adding html taggs

So I made PHP code that is used for signature, that is not problem right now the problem is that when I add <html></html> tags on the beginning of the code it won't show anything that I have done in PHP. So when I put html tags or make space in front of php there is nothing in page, but when I remove them everything work fine. I'm not expert in PHP so..
<?php
include_once("functions.php");
$sign = !isset($_GET['s']) ? 1 : $_GET['s'];
$uname = !isset($_GET["name"]) ? "None" : $_GET['name'];
// Connection & Website Settings
$ftpad = "";
$ftpuser = "";
$ftppass = "";
$comm = "SAMP";
$weburl = "www.incoming.com";
$usersdir = "/scriptfiles/Users";
//
$ftpcon = ftp_connect($ftpad,4112) or die("Error|I can't connect to the database: $ftpad, contact web master");
$login = ftp_login($ftpcon,$ftpuser,$ftppass);
$uname = "";
$name = $_GET['name'];
ftp_pasv($ftpcon,true);
$fhandle = fopen("tempsign_".hash('sha256',"$name").".tmp","w+");
ftp_fget($ftpcon,$fhandle,"$usersdir/$name.ini",FTP_ASCII);
$str = parse_ini_file2("tempsign_".hash('sha256',"$ime").".tmp");
fclose($fhandle);
$skin = $str['Skin'];
$rImg = ImageCreateFromPNG("./signs/1.png");
if (file_exists("./signs/skins/$skin.jpg"))
{
$skinImg = ImageCreateFromjpeg("./signs/skins/$skin.jpg");
}
else
{
$skinImg = ImageCreateFromjpeg("./signs/skins/0.jpg");
}
$cor_black = imagecolorallocate($rImg,0,0,0);
$cor_blue = imagecolorallocate($rImg,0,0,255);
$cor_lblue = imagecolorallocate($rImg,30,144,255);
$cor_green = imagecolorallocate($rImg,69,139,116);
$cor_red = imagecolorallocate($rImg,220,20,65);
$cor_wh = imagecolorallocate($rImg,255,255,255);
$cor_n = imagecolorallocate($rImg,246,74,14);
if(ftp_size($ftpcon,"$usersdir/$name.ini") == -1 || $ime == "None")
{
?>
<tr>
<center><td align="center" valign="top"><img src="logo.png" width="400" height="155" alt="logo" /></td></center>
</tr>
<style type="text/css">
body{
background-color:#000;
background-image:url(backg.png);
}
.
</style>
<?php
echo "<center><br/><br/><br/><br/><font color='#FF3333'>Error | That signature doesn't exist! Possible reasons:<br/><br/></font></center>";
echo "<center><font color='#0FB9FC'>1. You didn't enter your username in field for that<br/></font></center>";
echo "<center><font color='#0FB9FC'>2. You entered wrong username(Example Your_Name)<br/></font></center>";
echo "<center><font color='#0FB9FC'>3. Username that you entered isn't in our databse<br/></font></center>";
return 1;
}
else
{
ftp_pasv($ftpcon,true);
$fhandle = fopen("tempsign_".hash('sha256',"$name").".tmp","w+");
ftp_fget($ftpcon,$fhandle,"$usersdir/$name.ini",FTP_ASCII);
$str = parse_ini_file2("tempsign_".hash('sha256',"$name").".tmp");
fclose($fhandle);
imagettftext($rImg,12,0,11,39,$cor_n,"font.TTF",urldecode($name));
imagettftext($rImg,12,0,11,79,$cor_n,"font.TTF",urldecode($str['Level']));
imagettftext($rImg,12,0,173,120,$cor_n,"font.TTF",urldecode($str['Points']));
imagettftext($rImg,12,0,173,80,$cor_n,"font.TTF",urldecode($str['Hours']));
imagecopymerge($rImg, $skinImg, 308,6,0,0,80,100,100);
}
if($str['Sex'] == 0) { imagettftext($rImg,12,0,10,122,$cor_n,"font.TTF","Male"); }
else if($str['Sex'] == 1) { imagettftext($rImg,12,0,10,122,$cor_n,"font.TTF","Female"); }
if($str['GM'] > 0)
{
imagettftext($rImg, 13,0,5,161,$cor_green,"font.TTF","GameSupport");}
if($str['Admin'] > 0)
{
imagettftext($rImg, 13,0,5,161,$cor_red,"font.TTF","Admin");}
if($str['Leader'] > 0)
{
if($str['Leader'] == 1) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","LSPD"); }
else if($str['Leader'] == 2) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","FBI"); }
else if($str['Leader'] == 3) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","CNN"); }
else if($str['Leader'] == 4) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","La Cocaina"); }
else if($str['Leader'] == 5) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","La Cosa Nostra"); }
else if($str['Leader'] == 6) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Terror Squad Crew"); }
else if($str['Leader'] == 7) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","GSF"); }
else if($str['Leader'] == 8) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Yakuza"); }
else if($str['Leader'] == 9) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Russian Mafia"); }
else if($str['Leader'] == 10) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Underground Racers"); }
else if($str['Leader'] == 11) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Hitman Agency"); }
}
else if($str['Member'] > 0)
{
if($str['Member'] == 1) { imagettftext($rImg,13,0,171,40,$cor_wh,"font.TTF","LSPD"); }
else if($str['Member'] == 2) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","FBI"); }
else if($str['Member'] == 3) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","CNN"); }
else if($str['Member'] == 4) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","La Cocaine"); }
else if($str['Member'] == 5) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","La Cosa Nostra"); }
else if($str['Member'] == 6) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Terror Squad Crew"); }
else if($str['Member'] == 7) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","GSF"); }
else if($str['Member'] == 8) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Yakuza"); }
else if($str['Member'] == 9) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Russian Mafia"); }
else if($str['Member'] == 10) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Underground Racers"); }
else if($str['Member'] == 11) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Hitman Agency"); }
}
else
{
imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Civil");
}
ftp_close($ftpcon);
unset($str);
unset($ftpad);
unset($ftpuser);
unset($ftppass);
unset($ftpcon);
unset($login);
header('Content-type: image/png');
imagepng($rImg);
imagepng($skinImg);
?>
</style>
Please check your below code:
<?php
//Error reporting section
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include_once("functions.php");
$sign = !isset($_GET['s']) ? 1 : $_GET['s'];
$uname = !isset($_GET["name"]) ? "None" : $_GET['name'];
// Connection & Website Settings
$ftpad = "";
$ftpuser = "";
$ftppass = "";
$comm = "SAMP";
$weburl = "www.incoming.com";
$usersdir = "/scriptfiles/Users";
$ftpcon = ftp_connect($ftpad,4112) or die("Error|I can't connect to the database: $ftpad, contact web master");
$login = ftp_login($ftpcon,$ftpuser,$ftppass);
$uname = "";
$name = $_GET['name'];
ftp_pasv($ftpcon,true);
$fhandle = fopen("tempsign_".hash('sha256',"$name").".tmp","w+");
ftp_fget($ftpcon,$fhandle,"$usersdir/$name.ini",FTP_ASCII);
$str = parse_ini_file2("tempsign_".hash('sha256',"$ime").".tmp");
fclose($fhandle);
$skin = $str['Skin'];
$rImg = ImageCreateFromPNG("./signs/1.png");
if (file_exists("./signs/skins/$skin.jpg"))
{
$skinImg = ImageCreateFromjpeg("./signs/skins/$skin.jpg");
}
else
{
$skinImg = ImageCreateFromjpeg("./signs/skins/0.jpg");
}
$cor_black = imagecolorallocate($rImg,0,0,0);
$cor_blue = imagecolorallocate($rImg,0,0,255);
$cor_lblue = imagecolorallocate($rImg,30,144,255);
$cor_green = imagecolorallocate($rImg,69,139,116);
$cor_red = imagecolorallocate($rImg,220,20,65);
$cor_wh = imagecolorallocate($rImg,255,255,255);
$cor_n = imagecolorallocate($rImg,246,74,14);
if(ftp_size($ftpcon,"$usersdir/$name.ini") == -1 || $ime == "None")
{
?><tr>
<center><td align="center" valign="top"><img src="logo.png" width="400" height="155" alt="logo" /></td></center>
</tr>
<style type="text/css">
body{
background-color:#000;
background-image:url(backg.png);
}
</style><?php
echo "<center><br/><br/><br/><br/><font color='#FF3333'>Error | That signature doesn't exist! Possible reasons:<br/><br/></font></center>";
echo "<center><font color='#0FB9FC'>1. You didn't enter your username in field for that<br/></font></center>";
echo "<center><font color='#0FB9FC'>2. You entered wrong username(Example Your_Name)<br/></font></center>";
echo "<center><font color='#0FB9FC'>3. Username that you entered isn't in our databse<br/></font></center>";
return 1;
}
else
{
ftp_pasv($ftpcon,true);
$fhandle = fopen("tempsign_".hash('sha256',"$name").".tmp","w+");
ftp_fget($ftpcon,$fhandle,"$usersdir/$name.ini",FTP_ASCII);
$str = parse_ini_file2("tempsign_".hash('sha256',"$name").".tmp");
fclose($fhandle);
imagettftext($rImg,12,0,11,39,$cor_n,"font.TTF",urldecode($name));
imagettftext($rImg,12,0,11,79,$cor_n,"font.TTF",urldecode($str['Level']));
imagettftext($rImg,12,0,173,120,$cor_n,"font.TTF",urldecode($str['Points']));
imagettftext($rImg,12,0,173,80,$cor_n,"font.TTF",urldecode($str['Hours']));
imagecopymerge($rImg, $skinImg, 308,6,0,0,80,100,100);
}
if($str['Sex'] == 0) { imagettftext($rImg,12,0,10,122,$cor_n,"font.TTF","Male"); }
else if($str['Sex'] == 1) { imagettftext($rImg,12,0,10,122,$cor_n,"font.TTF","Female"); }
if($str['GM'] > 0){ imagettftext($rImg, 13,0,5,161,$cor_green,"font.TTF","GameSupport");}
if($str['Admin'] > 0){ imagettftext($rImg, 13,0,5,161,$cor_red,"font.TTF","Admin");}
if($str['Leader'] > 0){
if($str['Leader'] == 1) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","LSPD"); }
else if($str['Leader'] == 2) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","FBI"); }
else if($str['Leader'] == 3) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","CNN"); }
else if($str['Leader'] == 4) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","La Cocaina"); }
else if($str['Leader'] == 5) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","La Cosa Nostra"); }
else if($str['Leader'] == 6) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Terror Squad Crew"); }
else if($str['Leader'] == 7) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","GSF"); }
else if($str['Leader'] == 8) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Yakuza"); }
else if($str['Leader'] == 9) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Russian Mafia"); }
else if($str['Leader'] == 10) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Underground Racers"); }
else if($str['Leader'] == 11) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Hitman Agency"); }
}
else if($str['Member'] > 0)
{
if($str['Member'] == 1) { imagettftext($rImg,13,0,171,40,$cor_wh,"font.TTF","LSPD"); }
else if($str['Member'] == 2) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","FBI"); }
else if($str['Member'] == 3) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","CNN"); }
else if($str['Member'] == 4) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","La Cocaine"); }
else if($str['Member'] == 5) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","La Cosa Nostra"); }
else if($str['Member'] == 6) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Terror Squad Crew"); }
else if($str['Member'] == 7) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","GSF"); }
else if($str['Member'] == 8) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Yakuza"); }
else if($str['Member'] == 9) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Russian Mafia"); }
else if($str['Member'] == 10) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Underground Racers"); }
else if($str['Member'] == 11) { imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Hitman Agency"); }
}
else
{
imagettftext($rImg,13,0,171,40,$cor_n,"font.TTF","Civil");
}
ftp_close($ftpcon);
unset($str);
unset($ftpad);
unset($ftpuser);
unset($ftppass);
unset($ftpcon);
unset($login);
header('Content-type: image/png');
imagepng($rImg);
imagepng($skinImg);
?>

Display files with syntax highlighting using PHP

I am working on a web based application using php (not using Java), in which I am required to display source code files (java,c,c++,Python etc..) with syntax highlighting on the web page. I am clueless on as to how to display the source code files. Any help will be appreciated.
One of the options is use a existing syntax highlighter like a google one.
Setting it up is very simple. All you have to do for basic usage is include the code in your html page in <pre> sections and apply a class attribute that is programming language.
<pre name="code" class="c-sharp">
class Foo
{
}
</pre>
16 Free Javascript Code Syntax Highlighters For Better Programming has a very exhaustive list of lot of options. repeated here in case the site ever goes down
SyntaxHighlighter
GeSHi - Generic Syntax Highlighter
quickhighlighter
google-code-prettify
pygments.
HIGHLIGHT.JS
Lighter.js – Syntax Highlighter written in MooTools
SHJS – Syntax Highlighting in JavaScript
CodePress – Online Real Time Syntax Highlighting Editor
Chili jQuery code highlighter plugin
Highlight – Code & Syntax highlighting by Andre Simon
BeautyOfCode: jQuery Plugin for Syntax Highlighting
JUSH – JavaScript Syntax Highlighter
Ultraviolet – Syntax Highlighting Engine
DlHighlight – JavaScript Syntax Highlighting Engine
Syntax highlighter for JavaScript
Syntax highlighter is used to show the source code program is colorful, so the reader can easily read/understand your code after integration. In this program, I added various elements (reserve words, parenthesis, comment, and quotes etc..) for highlighting. You can add/modify this code based on your Web Application/Programming Blog.
This syntax highlighter code is independent to any language, so you add integration with any programming language.
Please find the source code from my tech blog - http://www.algonuts.info/how-to-develop-a-source-code-syntax-highlighter-using-php.html
<?php
include_once("keywords.php");
class highlighter {
private $fileName;
private $fileNameColor;
private $fileExtension;
private $parenthesisColor;
private $insideParenthesisColor;
private $keywordColor;
private $backGroundColor;
private $borderColor;
private $leftBorderColor;
private $quotesColor;
private $commentColor;
public function __construct() {
$this->fileName = "";
$this->fileExtension = "";
//Color Configuration
$this->fileNameColor = "#286090";
$this->keywordColor = "green";
$this->backGroundColor = "#fdfefe";
$this->borderColor = "#e3e3e3";
$this->leftBorderColor = "#605a56";
$this->parenthesisColor = "#ec7700";
$this->insideParenthesisColor = "#ec7700";
$this->bracketColor = "#ec7700";
$this->insideBracketColor = "#ec7700";
$this->quotesColor = "#6a2c70";
$this->commentColor = "#b8b0b0";
}
public function applycolor($fileLocation = "") {
if($fileLocation == "")
{ return; }
else
{
if(file_exists($fileLocation)) {
$temp = explode("/",$fileLocation);
$this->fileName = trim(end($temp));
$temp = explode(".",$this->fileName);
$this->fileExtension = trim(end($temp));
$fileContent = trim(file_get_contents($fileLocation, true));
$fileContent = htmlentities($fileContent,ENT_NOQUOTES);
if($fileContent == "")
{ return; }
}
else
{ return; }
}
$line = 1;
$outputContent = "<div class=\"divblock\"><b>".$line."</b> ";
$characterBuffer = "";
$blockFound = 0;
$blockFoundColor = array();
$parenthesisFound = 0;
$bracketFound = 0;
$counter = 0;
$lastCharacter = "";
$contentSize = strlen($fileContent);
while($counter < $contentSize) {
$character = $fileContent[$counter];
$code = intval(ord($character));
if($blockFound == 0 && (($code >= 97 && $code <= 122) || ($code >= 65 && $code <= 90))) //Fnd alphabetic characters
{ $characterBuffer .= $character; }
else
{
if($code == 10) { //Find EOL (End of Line)
if($this->checker($characterBuffer))
{ $characterBuffer = "<font color='".$this->keywordColor."'>".$characterBuffer."</font>"; }
$line++;
if($blockFound == 0)
{ $outputContent .= $characterBuffer."</div>".$character."<div class=\"divblock\"><b>".$line."</b> "; }
else
{ $outputContent .= $characterBuffer."</font></div>".$character."<div class=\"divblock\"><b>".$line."</b> <font color='".$blockFoundColor[$blockFound-1]."'>"; }
$characterBuffer = "";
}
else if($code == 32) { //Find Space
if($characterBuffer != "") {
if($this->checker($characterBuffer))
{ $outputContent .= "<font color='".$this->keywordColor."'>".$characterBuffer."</font>".$character; }
else
{ $outputContent .= $characterBuffer.$character; }
$characterBuffer = "";
}
else
{ $outputContent .= $character; }
}
else if($character == "\"" || $character == "'") { //Find Quotes
if($characterBuffer != "")
{
if($this->checker($characterBuffer))
{ $outputContent .= "<font color='".$this->keywordColor."'>".$characterBuffer."</font>"; }
else
{ $outputContent .= $characterBuffer; }
$characterBuffer = "";
}
$outputContent .= "<font color='".$this->quotesColor."'>".$character;
$foundCharacter = $character;
$counter++;
while($counter < $contentSize) {
$character = $fileContent[$counter];
if($character == $foundCharacter) {
$outputContent .= $character;
if($lastCharacter == "\\") {
$lastCharacter = "";
}
else
{ break; }
}
else if($character == "\\" && $lastCharacter == "\\") {
$outputContent .= $character;
$lastCharacter = "";
}
else
{
$lastCharacter = $character;
$code = intval(ord($character));
if($code != 10)
{ $outputContent .= $character; }
else
{
$line++;
$outputContent .= "</font></div>".$character."<div class=\"divblock\"><b>".$line."</b> <font color='".$this->quotesColor."'>";
}
}
$counter++;
}
$outputContent .= "</font>";
}
else if($character == "(" || $character == ")") { //Find Parenthesis
if($characterBuffer != "")
{
if($this->checker($characterBuffer))
{ $outputContent .= "<font color='".$this->keywordColor."'>".$characterBuffer."</font>"; }
else
{ $outputContent .= $characterBuffer; }
$characterBuffer = "";
}
if($parenthesisFound == 0) {
$blockFoundColor[$blockFound] = $this->insideParenthesisColor;
$outputContent .= "<font color='".$this->parenthesisColor."'>".$character."</font><font color='".$this->insideParenthesisColor."'>";
$parenthesisFound++;
$blockFound++;
}
else
{
if($character == "(") {
$parenthesisFound++;
}
if($character == ")") {
$parenthesisFound--;
}
if($parenthesisFound == 0) {
$outputContent .= "</font><font color='".$this->parenthesisColor."'>".$character."</font>";
$blockFound--;
unset($blockFoundColor[$blockFound]);
}
else
{ $outputContent .= $character; }
}
}
else if($character == "[" || $character == "]") { //Find Bracket
if($characterBuffer != "")
{
if($this->checker($characterBuffer))
{ $outputContent .= "<font color='".$this->keywordColor."'>".$characterBuffer."</font>"; }
else
{ $outputContent .= $characterBuffer; }
$characterBuffer = "";
}
if($bracketFound == 0) {
$blockFoundColor[$blockFound] = $this->insideBracketColor;
$outputContent .= "<font color='".$this->bracketColor."'>".$character."</font><font color='".$this->insideBracketColor."'>";
$bracketFound++;
$blockFound++;
}
else
{
if($character == "[") {
$bracketFound++;
}
if($character == "]") {
$bracketFound--;
}
if($bracketFound == 0) {
$outputContent .= "</font><font color='".$this->bracketColor."'>".$character."</font>";
$blockFound--;
unset($blockFoundColor[$blockFound]);
}
else
{ $outputContent .= $character; }
}
}
else if($character == "/" && (isset($fileContent[$counter+1]) && ($fileContent[$counter+1] == "*" || $fileContent[$counter+1] == "/"))) { //Find Comment
if($characterBuffer != "")
{
if($this->checker($characterBuffer))
{ $outputContent .= "<font color='".$this->keywordColor."'>".$characterBuffer."</font>"; }
else
{ $outputContent .= $characterBuffer; }
$characterBuffer = "";
}
$blockFound++;
$outputContent .= "<font color='".$this->commentColor."'>".$fileContent[$counter].$fileContent[$counter+1];
if($fileContent[$counter+1] == "*") {
$counter += 2;
$checkCharacter = "*";
while($counter < $contentSize) {
$outputContent .= $fileContent[$counter];
if($fileContent[$counter] == $checkCharacter) {
if($checkCharacter == "*")
{ $checkCharacter = "/"; }
else
{
$blockFound--;
$outputContent .= "</font>";
break;
}
}
$counter++;
}
}
else
{
$counter += 2;
while($counter < $contentSize) {
$character = $fileContent[$counter];
$code = intval(ord($character));
if($code == 10) {
$counter--;
$blockFound--;
$outputContent .= "</font>";
break;
}
$outputContent .= $character;
$counter++;
}
}
}
else if($characterBuffer != "")
{
if($this->checker($characterBuffer))
{ $outputContent .= "<font color='".$this->keywordColor."'>".$characterBuffer."</font>".$character; }
else
{ $outputContent .= $characterBuffer.$character; }
$characterBuffer = "";
}
else
{ $outputContent .= $character; }
}
$counter++;
}
$outputContent .= "</div>";
$rerurnData = "<div class='filenamestyle' style='color:".$this->fileNameColor.";'>".$this->fileName."</div>"; //Show filename
$rerurnData .= "<div><pre><div class='codebox' style='background-color:".$this->backGroundColor.";border: 1px solid ".$this->borderColor.";border-left: 4px solid ".$this->leftBorderColor.";'>".$outputContent."</div></pre></div>";
return $rerurnData;
}
private function checker($value) {
global $languageKeywords;
if(isset($languageKeywords[$this->fileExtension])) {
$value = trim($value);
if(in_array($value,$languageKeywords[$this->fileExtension]))
{ return 1; }
else
{ return 0; }
}
}
}
?>

Categories