Tutorial on integrating CKFinder/CKEditor into CakePHP with session CheckAuthentication.

“How to integrate CKEditor + CKFinder with Session CheckAuthentication into CakePHP”

 

In the process of web development such as CMS (Content Management System), there are many cases where you may find a WYSIWYG editor or a file manager useful.  However from my experience, I noticed that most web application frameworks provide from crappy to no backend interface for WYSIWYG editors or file managers or uploading functions.

In BeamStyle, we use the CakePHP web application framework.  The CakePHP framework is very easy to use and keeps our code clean.  That’s the reason why we are using it.  But of course, nothing is perfect.  The form filling API is crappy and there is no file management system.

To resolve such an issue, the use of external applications is unavoidable.

In this tutorial, I will introduce the method on how to setup CKEditor (WYSIWYG editor) and CKFinder (File Manager, Upload) with CakePHP with CakePHP Authentication.

== Requirements ==

1) CakePHP has already been setup and working. (http://cakephp.org/)

2) CakePHP Authentication has been setup and working inside CakePHP. (http://book.cakephp.org/view/172/Authentication)

== What you need to get ==

1) Download CKEditor (http://ckeditor.com/)

   – I used CKEditor 3.0.1, released on 16 October 2009

2) Download CKFinder (http://ckfinder.com/)

   – I used CKFinder 1.4.1.1, updated 02.10.2009

  

== Instructions ==

1) Extract your CKEditor and CKFinder into your /app/webroot/js/ directory

   It should look like the following:

     /app/webroot/js/ckeditor/

  /app/webroot/js/ckfinder/

2) Setup CKEditor in your view:

 a) Assuming that you already have your form and Javascript enabled in your controller, and your controller is named AdminController, and your Admin view is already password protected by CakePHP’s Authentication method (http://book.cakephp.org/view/172/Authentication), first you need to tell your view about the classname for CKEditor.  Let’s use the controller to tell the view about it because we want to follow some engineering ethics and the rules of MVC.

  


  class AdminController extends AppController {

   ...

   var $helpers = array('Form', 'Html', 'Javascript', 'Time');

  

   $ckeditorClass = 'CKEDITOR';

   $this->set('ckeditorClass', $ckeditorClass);

   ...

  }

 b) Since you will be integrating the CKFinder very soon when CKEditor is complete, let’s also define what’s required by CKFinder now, so we save some trouble later :p  The following specifies the path to the CKFinder application.

 

  class AdminController extends AppController {

   ...

   var $helpers = array('Form', 'Html', 'Javascript', 'Time');

  

   $ckeditorClass = 'CKEDITOR';

   $this->set('ckeditorClass', $ckeditorClass);

   

   $ckfinderPath = 'js/ckfinder/'

   $this->set('ckfinderPath', $ckfinderPath);

   ...

  }

c1) Now you need to link the javascript libraries for CKEditor and CKFinder into your template (for this example, let’s use the default template -> default.ctp)

 echo $javascript->link('ckeditor/ckeditor.js');

 echo $javascript->link('ckfinder/ckfinder.js'); 

 c2) Now you need to add a CakePHP textarea in your view.  So add it!  And let’s call it “newsContent” for now

 

  [app/views/admin/index.ctp]

  <?php echo $form->textarea('newsContent', array('class'=>$ckeditorClass)) ?>

c3) Now let’s edit the ckfinder’s config.php file so that everything will link perfectly ;-)

$baseUrl = ‘upload/’;

$baseDir = '/home/cakeroot/app/webroot/upload/';

 d) If you give a load on that page, you will see a crappy textarea in your page.

    You want to need to convert that into the trendy CKEditor!  And let’s add some default text to it too! XD

    So what you do is you assign a javascript variable to represent ur newsContent, and we called it “ck_newsContent”.

    After that, we set the contents of it using that variable.

  

  [app/views/admin/index.ctp]

  <?php echo $form->textarea('newsContent', array('class'=>$ckeditorClass)) ?>

  

  <script type="text/javascript">

  var ck_newsContent = CKEDITOR.replace( 'newsContent' );

  ck_newsContent.setData( '<p>Just click the <b>Image</b> or <b>Link</b> button, and then <b>&quot;Browse Server&quot;</b>.</p>' );

  </script>

ckeditor_wysiwyg

 

 e)  Now, if you just load the page and click on the image icon (circled in red in the above image), u will see Image Properties window showing up like below (Except without the “Server Browser” button)

ckeditor_image

f) So what is that server browser button?  Well, that is in fact the CKFinder.  Let’s add that!

  

  [app/views/admin/index.ctp]

  <?php echo $form->textarea('newsContent', array('class'=>$ckeditorClass)) ?>

  

  <script type="text/javascript">

  var ck_newsContent = CKEDITOR.replace( 'newsContent' );

  ck_newsContent.setData( '<p>Just click the <b>Image</b> or <b>Link</b> button, and then <b>&quot;Browse Server&quot;</b>.</p>' );

  CKFinder.SetupCKEditor( ck_newsContent, '<?php echo $ckfinderPath ?>') ;

  </script>

g) After you add the above code and try again and you will see the button.  If you click on the button, you may find the following restriction screen >__<

ckfinder_restrict

h) Yes that’s right.  You need authentication check!  Let’s do that!

 Open up app/webroot/js/ckfinder/config.php

And first thing, implement your CheckAuthentication() function, like the following:

function CheckAuthentication()

{

 if( isset($_SESSION['Auth']['User']) )

 {

  return true;

 }

 return false;

}

i) Now, because CakePHP uses a different session name (Not the default name), we gotta tell CKFinder to look inside THAT CAKEPHP SESSION!

 

 Add the following at the very top of the config.php file, right below <?php

<?php

// Start CakePHP Session

session_name("CAKEPHP");

session_start();

j) Let’s but not least, let’s add an upload folder and grant 757 Permissions to it:

->  app/webroot/upload

 

ckfinder_allow

k) Now try loading up the Server Browser rom step (g) again and happy surfing!

New Web Design Project – Dressing Room Launched

Beamstyle is proud to announce that we have launched Dressing Room, which is an e-commerce website selling woman dresses and goods.
Dressing Room

Please feel free to browse the website and let us know what you think.

Things To Consider When Choosing a Web Hosting Service

Realibility

This is the most important factor when choosing a web hosting service. Nothing else matters when your users simply cannot access your web site. A realiable web hosting service should provide at least 99% server uptime and 24/7 technical support.

Email

If you need services related to email such as mailing list, webmail, auto respond / forward, etc, make sure you check with the web hosting service. Ask for any restrictions or limitations and ensure that it is suitable for your needs.

Disk Space / Data Transfer

Nowadays, more web hosting are fairly generous in terms of disk space and data transfer. If your web site is relatively new then this likely won’t be an issue for you. However, once you have your web site running on your web hosting, you should monitor your disk space and data transfer usage reguarly to ensure that you do not exceed the limits.

Web Language Support

If you plan to run any scripted web pages such as blog, e-commerce, or CMS, find out what your web language and database requirements are and ask if your web hosting service can provide such features in their hosting packages.

Security

If you plan on creating an e-commerce web site or any web site that involves payment, then ensure your web hosting service provides Secure Socket Layer (SSL) support. This allows you to encrypt the data sent between you and your customer such as credit card numbers and other personally identifiable information. You may also want to check if the web hosting service provides any SSL Certificate services.

Location

Your web hosting service location may have an impact on your web site’s user experience.  A web page that takes a long time to load can be very frustrating to your users. Typically, it takes a longer time to load a web page that is hosted in a foreign country than a local one. If your target audience is from Hong Kong, then a Hong Kong based web hosting service would be more suitable. Similarly, if your target audience is from the United States, then you may want to consider an United States based web hosting service.

Estimation Management – Part II

There are seven steps that are used in project estimation management.

Assigning Estimator

Project Manager should assign a member of a project team to be the Estimator. In general, the Project Manager, Business Analyst or Product Analyst of a project can be the Estimator.

Collecting Information

Estimator should collect all available documents and information of a proposed system. In Proposal and Initiation stage, Estimator should gather the client requirements and use them as an input to the subsequent procedures. In Design and Build stage, Estimator should collect the latest version of Requirement Specification and Design Specification before starting the estimation.

Estimating Project Size

Estimator should estimate the size of the code working and documentation working based on the business and technical requirements, and historical data. Estimator should estimate the size of code working in terms of intermediate measurement units required by different estimation methods. Different estimation methods use different intermediate measurement units to represent the size of code working. Besides code working size estimation, Estimator should estimate the size of documentation working. For documentation working, the size measurement unit is number of page.

Regardless of the method used, the Estimator shall document the estimation result and any assumptions made when perform the estimation.

Estimating Manpower Effort

Estimator should convert the intermediate measurement units to total project effort. Estimator should consider the software and programming language used, system architecture and the development lifecycle that a proposed system will be followed for design, develop, test, deploy and documentation. Besides, Estimator should also consider the effort used in the activities of a project. Estimator should use historical performance indicators to estimate the project effort when possible. If estimator has to change the estimation formula, the rationale and assumption of this change should be documented. In addition, Estimator should estimate the effort of each documentation working based on the estimation of number of pages and past experience of similar projects and record in the documentation working list work sheet.

In the Build stage, Estimator should create a Product Assignment Form for each code working and estimate the man days required to complete a PAF based on the complexity of a Work Product and the experience level of the programmer.

Estimating Resource & Schedule

Estimator should estimate the number of team members who will be working in a project and determine the duration each team member involves in.

Once manpower resource is determined, estimator should spread the resource measurement data into a calendar schedule. Estimator should decide the time interval of the calendar schedule depending on the duration of a project, expected completion date of all major milestones and other constraints and document them into the Resource & Manpower Cost Sheet and the Milestones Sheet. Estimator should record any assumptions used in estimating the resource and schedule. In addition, Estimator should determine computer resources and the schedule they are required. Computer resources include development workstations, system integration test servers, UAT servers, network bandwidth, load test servers etc. Estimator should fill in computer resource name, deadline, criticality, cost and other columns on the Critical Computer Resource Worksheet.

In the Build stage, Estimator should fill in estimated start and finish date of each PAF. Estimator should assign PAFs to each programmer in a project team with the consideration of the skill set of the programmer and the complexity of the product as described above.

Estimating Cost

Estimator should calculate manpower cost according to the daily rates of the corresponding position of team members. Estimator should document the cost in Resource and Manpower Cost Sheet of the corresponding estimation worksheet. Also, Estimator should then sum up total project cost that may include manpower cost, hardware and software purchases or rentals, training courses, and others.

Verify Estimation

Project Manager should verify the estimation made in different stages. After the estimation is verified, Project Manager should put it in a project plan for progress tracking. Throughout a project period, Project Manager should track the size, effort, schedule and cost of the project. If Project Manager finds that the actual size, effort, schedule or cost are deviated from the project plan and beyond the pre-defined tolerance level, appropriate action has to be taken in conjunction with the Project Planning and Tracking Process.

Estimation Management – Part I

A project plan consists of two main elements that effort and time form the basis for tracking the progress of a project. Project manager requires estimate these two elements as accurate as possible. Therefore, estimation management process involves an analysis of a proposed or active project to produce a forecast of the project’s effort and time. Proper project planning and tracking is not possible without a sound and reliable estimate.

 

The estimation is one of the most challenging and important activities in software development. If the effort of a project is not estimated at the beginning, appropriate resources cannot be mobilized and deployed timely to the project. If the time is not estimated, it is impossible to perform critical path analysis during the project life cycle.

 

Not having a sound and reliable estimation can be just as bad as not having estimation at all.  Under-estimating project will lead to under-staffing it and deadlines will be missed.  On the other hand, over-estimating project will affect the firm’s sustainability as more than necessary resources are engaged in the project.

 

The following results are expected to be achieved by defining and implementing a good estimation management process:

  • Appropriate resources are being involved in a project at the right time
  •  An objective measurement is in place to reflect how well a project is progressing

Estimation Management includes the software development and implementation, system maintenance and consulting.

 

According to Capability Maturity Model (CMM), the management estimation should be done by two roles:

 

Roles

Responsibilities

Project Manager

·         Assign a project team member to be Estimator

·         Verify the estimation done by Estimator

Estimator

·         Collect and analyse all available information for estimation

·         Estimate the project size

·         Estimate the manpower and other resources

·         Estimate the schedule

·         Estimate the cost

 

Estimation management can be divided in several steps: assigning estimator, collecting information, estimating project size, estimating manpower effort, estimating resource & schedule, estimating cost and verify estimation

 

Next blog will discuss each step in detail.