Do you need a PHP programmer?
Use my services as a freelance PHP programmer by hiring me to do PHP programming on your website project.

I have built many custom PHP applications like project managers, classified ad websites and content management systems. I also work with open source applications such as WordPress, online shopping cart websites like Magento and develop content management systems like Joomla.

Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Thursday, January 31, 2013

Module Block User Online / Visitor Counter Prestashop 1.5

Hi guys, Are you looking for block user online / visitor counter widget in prestashop 1.5?
Download module here.

1. unzip it. put blockuseronline directory module in prestashop\modules.
2. go to your admin panel. (www.myshop.com/adminxxx)
3. On main menu choose Modules -> Modules
4. All modules will appear.
5. On left side menu, choose other modules (on the bottom).
6. Install block user online modules then visitor counter widget will appear in your front page

This is sample image of the result:



Best regard,
Bayu Prawira

Monday, January 28, 2013

View Counter (Update field +1) - Cakephp

Hi Hallo,
This week (29 jan 2013), I still work in my current project with cakephp framework.
Today I find small problem but I will always share with you guys. I work on I called view counter, where if there any client view detail of any property in my site, it will update field count in database +1.
Maybe it look easy if we do with php and sql. But how we can do it with cakephp framework?

I'm googling, and found this code below:

$this->Article->updateAll(
             array('Property.count' => 'Property.count + 1'),
             array('Property.id' => 5)
);


Hope it can help,
But if you still have any question, write your comment below.

Kind regard,
Bayu Prawira

Thursday, January 24, 2013

Get date of one week based on week number - php

Hi, ,
There are many kind of php function you can use for datetime manipulation. But today I will share a short code that you can use for get date of one week based on your week number.

I have created a function that you can use or develop
Let see my function below :

<?php
 function get_date_in_week($year,$week_number){
  $date = array();
  
  // 1 week 7 days
  for($day = 1; $day <= 7; $day++){
   
   $set_date = strtotime($year."W".($week_number<10?'0':'').$week_number.$day);
   
   if(date('Y',$set_date) == $year){
    $date['year-'.$year]['week-'.$week_number]['day-'.$day] = date('j', $set_date);
   }
   
  }
  
  return $date;
  
 }
?>


Now, you can simple to use, just call the function then you will get date of one week based on your week number.

<pre>
 <?php
  $year = '2013';
  $week_number = '2';
  print_r(get_date_in_week($year,$week_number));
 ?>
</pre>


The result will be like this :

Array
(
    [year-2013] => Array
        (
            [week-2] => Array
                (
                    [day-1] => 7
                    [day-2] => 8
                    [day-3] => 9
                    [day-4] => 10
                    [day-5] => 11
                    [day-6] => 12
                    [day-7] => 13
                )

        )

)

Hope it can helps.
But if you still need help, just write your comment below.
I will try to find out.

Kind regard,
Bayu Prawira

Monday, December 24, 2012

Add New Font for Dompdf

Hi Hallo,
In this post we will talk about PDF file conversion exactly DomPDF.
It allows direct conversion of HTML files to PDF files. But I found some issues when I was using this module, when I tried to generate pdf file, the result was not same as my html file. Some of fonts didn't apply in the pdf file. I goggled the web and found some solutions. And now I solved it.
I will share how to add your own font for dompdf,

1. For the simple step please go here DOMPDF web-base
2. Complete the form and upload your own font


  Make sure your dompdf version same with version in the form and Go

3. Download and extra the result (.zip). then Copy the contents of the result( .tff, .ufm) to your DOMPDF fonts folder (typically located at dompdf/lib/fonts).

4. If you have not previously installed fonts, you can rename the file dompdf_font_family_cache.sample(this file from the archive) to be dompdf_font_family_cache.dist.php (located at dompdf/lib/fonts). If you have previously installed fonts you will need to copy the relevant entry from the sample file into dompdf_font_family_cache.dist.php file.
Below is example for add some entry to dompdf_font_family_cache.dist.php


5.  Once you have taken these steps your font should be installed and ready to use.

Hope it can help, but if you still have any question
Please feel free to write your comment below.

Kind regard,
Bayu Prawira

Tuesday, May 29, 2012

Table and Model Name - Cakephp

Hi everyone,

Long time I have no post something.
Today I will write something about "Table and Model Name in Cakephp".
As you know, in Cakephp we should write the name of table in plural.
I mean for example if you want make table with name "user" you should make it like "users" and "post" should be "posts".

So how to handle table names that are written in singular with "...y"?
hehe ... just so simple, I make an example with table name "entry" and it should be "entries". :D

But for Model name in cakephp you should write the name in singular.
you already have a table "entries", than in your app\models , you should make a new file for model. The name of the file is "entry.php" (in singular 'user.php, post.php').
And below is basic code for Model Name :


class Entry extends AppModel {
 var $name = 'Entry';
}

How about if we use underscore in our table names??
for example you have table name "categories_lists", how will we make the Model name?
I show you the simple way,
in your app\models, create a new file with name "categories_list.php".
write this code inside of the file :

class CategoriesList extends AppModel {
 var $name = 'CategoriesList';
}

Ok, that's all
if you have any question, just write your comment below :D
Thanks for your visit.

warm regard from bali :)

Monday, April 16, 2012

Replace space and all Illegal character on string - PHP

Hi, ,
Do you search for how to replace/remove illegal character (@#$%^&* etc) in your text string?
On this post I will share you simple code to make it.
This code will only allowed numbers (0-9) and characters (a-z).

my code :

<?php
    $string = 'by^#^we%%&bs.b_((logs+)&#@pot.()*)(~co!~@#_+m';
    $string = preg_replace('/[^0-9 a-z]+/i', '', $string);
    
    echo $string;
?>

And below is code for replace multiple space on your text string

<?php
    $string = 'by   webs.   blog  spot.  com';
    $string = str_replace(array(' '),array(''),$string);
    
    echo $string;
?>

Hope it will useful for all,
If you have questions or suggestions, please write your comment below.

Good Luck :)

Thursday, April 12, 2012

Cut a string after X characters -- PHP

Hi guys, ,
In this my post, let's we talk about string manipulation using PHP code.
There are many functions of php that you can use to manipulation your string.
But now I will share you a simple way how to cut a string after x characters.
We will use 2 manipulation functions of php, they are strlen ( for count characters of your string ) and substr ( for cut characters of your string ).

This is my code :

<?php  
    if(isset($_POST['submit'])){          
            
            $text = $_POST['text'];
            
            //check if you have value in text.  
            if(empty($text)){  
               echo "<h3>Error: Please complete the form.<a href=\"$_SERVER[PHP_SELF]\">back</a></h3>";  
               exit(); //exit the script and don't process the rest of it!  
            }  
            
            $limit = 10; //limit the char will cut
            if (strlen($text) > $limit) {
                $text = substr($text, 0, $limit) . '...'; //if $text more than $limit char will replace with (...)
            } else {
                $text = $text;
            }
                   
            //success message, redirect to main page.          
            $msg = urlencode("Result of your string : <h4>$text</h4> <a href=\"cut_string.php\">Try again?</a>");  
                header("Location: cut_string.php?msg=$msg");  
                exit();  
              
          
    }else{  
            //if there is a message, display it  
            if(isset($_GET['msg']))  
            {  
                //but decode it first!  
    
                echo "<p>".urldecode($_GET['msg'])."</p>";  
            }  
            //the upload form  
        echo "  
        <h1>Simple code to cut a string after X characters PHP - <a href=\"http://bywebs.blogspot.com\">bywebs.blogspot.com</a></h1>
        <form action=\"$_SERVER[PHP_SELF]\" method=\"post\"enctype=\"multipart/form-data\">\n  
        <p>Your text:<input type=\"text\" name=\"text\" /></p>\n  
        <p><input type=\"submit\" name=\"submit\" value=\"Submit\" /></p>";  
    }  
?>

Just a simple code :)
Let's try for your self, for the complete file you can "Download Here".
Hope it useful for all, if you have any question, you can write your comment below :)

Good Luck :)

Simple Upload and Resize Image using php

According to my post title above, now I will share a simple code about make upload and resize image using php. Exactly the code I got from searching on google, but I have made a little modification so now the code become a bit nicer than before. hehe ;).

 Let's take look for my code:

 Resize.php

<?php

if(isset($_POST['submit']))
    {        
        //directory destination , make sure this directory is writable!
        $path_thumbs = "C:\\bayu";
        $path_big = "C:\\bayu\\thumb";
        
        //the new width of the resized image, in pixels.
        $img_thumb_width = 100; // 

        $extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed)
        //List of allowed extensions if extlimit = yes
        $limitedext = array(".gif",".jpg",".png",".jpeg",".bmp");
        
        //the image -> variables
        $file_type = $_FILES['vImage']['type'];
        $file_name = $_FILES['vImage']['name'];
        $file_size = $_FILES['vImage']['size'];
        $file_tmp = $_FILES['vImage']['tmp_name'];

        //check if you have selected a file.
        if(!is_uploaded_file($file_tmp)){
           echo "Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
           exit(); //exit the script and don't process the rest of it!
        }
       //check the file's extension
       $ext = strrchr($file_name,'.');
       $ext = strtolower($ext);
       //the file extension is not allowed!
       if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
          echo "Wrong file extension.  <br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>";
          exit();
       }
       //so, whats the file's extension?
       $getExt = explode ('.', $file_name);
       $file_ext = $getExt[count($getExt)-1];

       //create a random file name
       $rand_name = md5(time());
       $rand_name= rand(0,999999999);
       //the new width variable
       $ThumbWidth = $img_thumb_width;

       //////////////////////////
       // CREATE THE THUMBNAIL //
       //////////////////////////
       
       //keep image type
       if($file_size){
          if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
               $new_img = imagecreatefromjpeg($file_tmp);
           }elseif($file_type == "image/x-png" || $file_type == "image/png"){
               $new_img = imagecreatefrompng($file_tmp);
           }elseif($file_type == "image/gif"){
               $new_img = imagecreatefromgif($file_tmp);
           }
           //list the width and height and keep the height ratio.
           list($width, $height) = getimagesize($file_tmp);
           //calculate the image ratio
           $imgratio=$width/$height;
           if ($imgratio>1){
              $newwidth = $ThumbWidth;
              $newheight = $ThumbWidth/$imgratio;
           }else{
                 $newheight = $ThumbWidth;
                 $newwidth = $ThumbWidth*$imgratio;
           }
           //function for resize image.
           if (function_exists(imagecreatetruecolor)){
           $resized_img = imagecreatetruecolor($newwidth,$newheight);
           }else{
                 die("Error: Please make sure you have GD library ver 2+");
           }
           //the resizing is going on here!
           imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
           //finally, save the image
           imagejpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
           imagedestroy ($resized_img);
           imagedestroy ($new_img);
           
           
        }

        //ok copy the finished file to the thumbnail directory
        move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext");
             
        //success message, redirect to main page.        
        $msg = urlencode("$title was uploaded! <a href=\"Resize.php\">Upload More?</a>");
            header("Location: Resize.php?msg=$msg");
            exit();
        
    
}else{
        //if there is a message, display it
        if(isset($_GET['msg']))
        {
            //but decode it first!
            echo "<p>".urldecode($_GET['msg'])."</p>";
        }
        //the upload form
    echo "
    <form action=\"$_SERVER[PHP_SELF]\" method=\"post\"enctype=\"multipart/form-data\">\n
    <p>File:<input type=\"file\" name=\"vImage\" /></p>\n
    <p><input type=\"submit\" name=\"submit\" value=\"Submit\" /></p>";
}

?> 

Upss, ,  it's long enough, but never mind because I'm sure the code will work as well.
Notice : make sure the directory destination , is writable!
       $path_thumbs = "C:\\bayu";
       $path_big = "C:\\bayu\\thumb";

or you can change it as you want. :)
for the complete file you can "Download here"
Okay, that's all.!!
if you have any question just write your comment below :)

Good Luck!!