Author Archives: Nik Chankov

How Converged Networks Will Revolutionize Telecommunications

Phone calls aren’t what they used to be. The antiquated system of wires and telephones that once crisscrossed the country becomes increasingly irrelevant as more companies and consumers switch to voice calling over data networks.

Called Voice over IP, this technology uses high speed Internet connections, private networks and internal LANs to deliver enhanced telephone services at a lower price. Very soon, data networks will handle nearly three-quarters of all phone calls. As different types of networks converge, they soon will handle almost every form of communication.
Continue reading

Quick tip: WordPress – How to make Contact Form 7 working with qTranslate

On my recent project I had to create multilingual site and we decided to add multiple languages using qTranslate plugin.

The site of course has “Contact us” page and we decided to use Contact Form 7 plugin because it’s rich and flexible plugin for creating contact forms.

So far so good, but we detected that when the language is different than the default one, the form submission is redirecting to the default language page and because the forms are different they didn’t handle properly the errors as well as the thankyou message.
Continue reading

CSS Web design for your website

As can be supported by anyone who has ever tried it, starting your own website can be a complicated and somewhat intimidating process. It is not always as simple as just naming your page and uploading content, as there are a number of complex setup-related factors that must go into your site before it is up and functional, at least if you want it to appear professional and well constructed. This is why many people turn to professional companies like Network Solutions, which specialize in website hosting and allow you, not shortcuts, but easier methods for setting your website up the way you imagine it. Continue reading

Simple value getter and setter for CakePHP

This snipped I’ve wrote, because I think it’s convenient to have something like this in cake.

Put this in AppModel (/youur_cake_project/app/app_model.php)

<?php
class AppModel extends Model {
    /**
     * handy method for getting and setting value in a model.
     * For setter: it's not validating anything, so bear in mind...
     * Usage:
     *   Getter:
     *    $this->MyModel->id = 5;
     *    $this->MyModel->value('name'); //retun value of column name for the id 5
     *   Setter
     *    $this->MyModel->id = 5;
     *    $this->MyModel->value('name', 'BlaBla'); //set the name of row with id 5 to BlaBla
     */

      public function value($field, $value = null){
    if(func_num_args() == 1){ //getter
        $result = $this->field($field);
        if($result){
        return $result;
        }
    } else { //setter
        if($this->saveField($field, $value)){
        return true;
        }
    }
    return false;
     }
}?>

Getter:

$this->YourModel->id = 5; //set the id of the model
$this->YourModel->value('name');//return the value of the row with id 5

Setter:

$this->MyModel->id = 5; //set the id of the model
$this->MyModel->value('name', 'BlaBla'); //set the name of row with id 5 to BlaBla

As you can see it’s not a rocket science, and it’s uses cake’s functions for this, but I thought it’s convenient to have such function.

jQuery tip – skip $(document).ready() event

If you are new to jQuery you will notice that almost everything is wrapped with

     $(document).ready(function(){
           //your fancy javascript code here...
     });

What does it do? It check if all HTML tags are loaded and if so, execute your code. Easy as that. But if you are new to jQuery it’s really strange way of writing JS code :).

Did you know that this is not so required?

Actually if you move your JavaScript code at the end of the page you don’t need to wrap your code with that.

Hope this will be handy for someone.

Extending CakePHP Facebook plugin

Currently I am working on an application which require Facebook authentication for it’s users. As you may guess its written in CakePHP, and I’ve searched on Internet for a plugin which integrate Facebook in CakePHP application.

There is one very good CakePHP Facebook plugin written from Nick Baker, and I give a try. It’s really good plugin which provides everything for integration of Facebook (even the Facebook API) in your site. Full list example of functionality can be seen here.

Although, I’ve notice that the site is getting slow when the user is connected on the Facebook. Digging in the code I’ve noticed that the initialize() function which is responsible for the initialisation of the plugin request every time the data for the logged user from the Facebook, and this of course slows down the Application itself, because initialize() is called on every page refresh in every site.

What I’ve did – a little optimisation of the code. Here is the explanation how the improved core works:

  1. on init (initialize() function) it just assign the FB instance to the component and getting the Facebook session. This doesn’t require FB call.
  2. There is an extra parameter which could be provided to the plugin’s settings – noAuth. If this parameter is set the plugin wont attempt to login using the Auth component in the site. By default this parameter isn’t set, but it’s more convenient to have it, because in some cases like mine, I don’t use user Auth on the site except the Facebook’s. Here is a sample how to set noAuth for the plugin:
    class AppController extends Controller {
    $components = array('Facebook.Connect'=&gt;array('noAuth'=&gt;true));
    }
  3. Finally in your AppController::beforeFilter() you can use following in order to get the logged user’s details:
    class AppController extends Controller {
    function beforeFilter(){
    $fb = $this-&gt;Connect-&gt;user();
    }
    }

    This call has been already cached and you don’t need to worry about extra calls to Facebook site.

Another think which I’ve seen in the comments for the Nick’s article is the request to disconnect (unsubscribe) from the application without logging out of the Facebook. That’s why I’ve added a function disconnect() which doing exactly this.

Usage:

<?php
    echo $this->Facebook->disconnect(array(
                     'label'=>__('exit', true),
                     'confirm'=>__('Are you sure?', true)
                     ));
    ;?>

Possible options which could be provided in the function:

  • label – string text for the link
  • redirect – action to which user will be redirected after the logged out. If it’s not set the page will be reload.
  • confirm – javascript confirm message (for example “Are you sure?”) before user disconnected from the application.

I’ve added the confirm option in the logout as well (with the same functionality), as well as there is a new option parameter custom which will force the link creation instead or fbml logout link, because in the original implementation custom link is used only if you pass redirect action, but in some cases it need only to reload the page without any redirection and it’s convenient to have a custom link.

And finally where is the extended plugin? Of course in guthub. CakePHP-Facebook-Plugin

Update: The changes are already accepted and included in the original author of the plugin and you can found them at Plugin’s home page

CakePHP saveAll() quick tip

Saving data with Model->saveAll() is really time savior. There is something specifics while saving multiple records of a single model.

The data provided from the form should be in the numerically indexed array of records like this:

Array
(
    [Article] => Array(
            [0] => Array
                (
                            [title] => title 1
                        )
            [1] => Array
                (
                            [title] => title 2
                        )
                )
)

Your code for saving this data with saveAll() should look like this:

$this->Article->saveAll($data['Article']);

Ok, but if you pass only

$this->Article->saveAll($data);

it won’t work. So if you want to save multiple records of a single model provide the proper data. It took me 1/2 hour to detect that this is the problem.

Of course this is written in the CookBook, but somebody need to read it carefully 😉