Integrate the module with KTML's security model

Due to security concerns, only specified methods can be called externally. This is done to prevent any hacks that might call a damaging external method without the permission of the page owner.

The list of allowed modules and methods is stored in the ktml4_security.class.php file inside the <site root>\includes\ktm\ folder as an array. You will have to add the new method in order to use it:

  1. Open the <site root>\includes\ktm\ktml4_security.class.php in a text editor.

  2. Locate the setGlobalKtmlForId function (by default it is the second function. It's definition should resemble this:

    function setGlobalKtmlForId($id) {

     

  3. Within the function's code block there is a block that defines entries in the arrModulesMethods array. By default there should be entries for the file, image, spellcheck, templates and xhtml modules. You need to add another entry for the date module after the xhtml module entry, and before the definition for the modulerights array:

    $tmpArr['modulerights'] = array();

     

  4. Create a new paragraph before the code shown above and add a new item to the array. The entry will register the date module and the getCurrentDate method to the KTML security:

    $arrModulesMethods['date'] = array('date' => array('getCurrentDate'));


    Note:
    If your module has more than one method that needs to be available to KTML, simply add each of their names in the array, separated by a comma.

 

 

Next you have to edit the page where KTML is applied, to instruct the control to load and prepare the date web service for use:

  1. Open the page containing the KTML control in Dreamweaver or another text editor.

  2. Locate the block of code that defines the KTML properties. It should resemble the following sample (may differ based on the particular configuration):

    $ktml4_obj1 = new ktml4("content_field", "../", dirname(__FILE__));
    $ktml4_obj1->setModuleProperty("filebrowser", "AllowedModule", "true", false);
    $ktml4_obj1->setModuleProperty("file", "UploadFolder", "uploads/files/", true);
    $ktml4_obj1->setModuleProperty("file", "UploadFolderUrl", "uploads/files/", true);
    $ktml4_obj1->setModuleProperty("file", "AllowedFileTypes", "doc,pdf,txt", true);
    $ktml4_obj1->setModuleProperty("media", "UploadFolder", "uploads/files/", true);
    $ktml4_obj1->setModuleProperty("media", "UploadFolderUrl", "uploads/files/", true);
    $ktml4_obj1->setModuleProperty("media", "AllowedFileTypes", "bmp,mov,mpg,avi,mpeg,swf,wmv,jpg,jpeg,gif,png", true);
    $ktml4_obj1->setModuleProperty("filebrowser", "MaxFileSize", "2000", true);
    $ktml4_obj1->setModuleProperty("filebrowser", "RejectedFolders", ".svn,.thumbnails", false);
    $ktml4_obj1->setModuleProperty("xhtml", "AllowedModule", "true", false);
    $ktml4_obj1->setModuleProperty("xhtml", "xhtml_view_source", "true", true);
    $ktml4_obj1->setModuleProperty("xhtml", "xhtml_save", "true", true);
    $ktml4_obj1->setModuleProperty("css", "PathToStyle", "includes/ktm/styles/KT_styles.css", true);
    $ktml4_obj1->Execute();

     

  3. Before the $ktml4_obj1->Execute(); you must add the date module loading line. The statement that loads the module is:

    $ktml4_obj1->setModuleProperty("date", "AllowedModule", "true", false);

     

  4. The setModuleProperty method uses four (4) parameters:

  5. Save the page. When loaded, it will also load the date module, and prepare it for use.

 

The last thing to do is edit the main ktml4 class file and add grant the date module the proper execution rights:

  1. Open the <site root>\includes\ktm\ktml4.class.php file in Dreamweaver or with another text editor.

  2. Locate the execute method's code block. The method definition is:

    function Execute() {

     

  3. Inside the method's code block there are a number of conditional regions that are used to set the correct permissions for modules. Add another one, with the code below:

    if (isset($this->properties['date']['AllowedModule']) && $this->properties['date']['AllowedModule'] == 'true') {
       $arr['rights'][] = 'date';
    }

     

  4. Save the file and close it.

 

At this point you are done creating the web service, and configuring it for use with KTML. In the next section you will learn how to integrate it in the KTML user interface, to make it available to users.