Rashid’s Facebook Like Box Plugin for WordPress

I was searching for a plugin to add Facebook Like Box on my blog but I did not found any suitable plugin which suits my purpose. I found few plugins at WordPress.org but they don’t support my wordpress version. So I decided to write my own plugin. You can also download it and use it at your wordpress blog as well. Click here to download the plugin.

Installation:

Download the plugin.

Upload to your blog (/wp-content/plugins/).

Activate it.

Click the RA-FB Like Box.

Fill in the options.

Then go to widget and drag and drop Rashid’s Facebook Like Box in the area you want to display the plugin.

XPage – Sort View Column

I was searching for a work around to allow view column to be sortable by clicking on column header but I was not able to find any reliable solution using View Panel. Now I found a way to provide this feature using Repeat Control or Data Table.

Please go through the following code.

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var loView:NotesView = null;
var loEntryColl:NotesViewEntryCollection = null;
var loTreeMap:java.util.TreeMap = new java.util.TreeMap();
var lsSortBy = viewScope.get("sortBy");
try {
    loView = database.getView("view");
    if(null == lsSortBy || "" == lsSortBy) {
        lsSortBy = 0;
    }
    
    if(null != loView && loView.getEntryCount() > 0) {
        loEntryColl = loView.getAllEntries();
        var loEntry:NotesViewEntry = loEntryColl.getFirstEntry();
        var loTempEntry:NotesViewEntry = null;
        while(null != loEntry) {
            loDoc = loEntry.getDocument();
            var lsKey = loEntry.getColumnValues().get(lsSortBy);
            
            while(loTreeMap.containsKey(lsKey)) {
                lsKey += "~";
            }
            loTreeMap.put(lsKey, loEntry.getColumnValues());
            
            loTempEntry = loEntryColl.getNextEntry(loEntry);
            loEntry.recycle();
            loEntry = loTempEntry;
        }
    }
} catch(e) {
    print("Error : " + e);
} finally {
    if(null != loView) loView.recycle();
    if(null != loEntryColl) loEntryColl.recycle();
}
return loTreeMap.values();

In line 3 I am defining a TreeMap data structure. By definition TreeMap is sorted according to its natural ordering of its keys.

Since the data structure is always sorted so we can insert NotesViewEntry column values to the TreeMap and the corresponding column value (by which the view needs to be sorted) should be passed as key.

Look at line no 17 I am forming the key by which the view needs to be sorted. By default it is first column value.

At this point of time the only thing which creates problem is the duplicate values of the key. In TreeMap the value is overwritten if the key is already existing.

From line 18-21 I am appending additional character to make the key unique.

In line 37 I am returning value set from the TreeMap which is already sorted by key.

Rest of the code is quite easy to understand. I hope it may help in your application.

Debug Java From Lotus Notes Designer

We do not prefer to write agents in Java just because we are not able to debug the Java agent in Lotus Notes Designer. As we think Designer do not have any debugger for Java, but let me clarify that Lotus Notes Designer 8.5.x (also known as Domino Designer in Eclipse) has in-built Java debugger.

It is very clear that to write a Java agent we must extend AgentBase class and implement notesmain() function. So if our Java agent requires Domino Infrastructure to execute then how can we debug it? We have to make it a Java application to debug it. So we must define main function in our Java agent.

I am assuming the name of the agent class is MyAgent.

 

Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
protected Session _goSession;
protected AgentContext _goCtx;
        
public MyAgent(){}
public MyAgent(Session s, AgentContext c) {
    _goSession = s;
    _goCtx = c;
}
public static void main(String[] args) {
    Session s = null;    
    NotesThread.sinitThread();
    try {
        s = NotesFactory.createSession();
        // NotesMain(), the way Domino does
        MyAgent a = new MyAgent(s, s.getAgentContext());
        a.NotesMain();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (s != null) s.recycle();
        } catch (Exception x) {}
        NotesThread.stermThread();
    }            
} // end main

After adding above code to your Java agent switch to Java Debugger Perspective and goto Debug Configuration and double click on Java Application in left side. Check stop in main option and click on debug button to start debugging.

I hope this helps you in debugging your Java agent. If any query feel free to write me back…:)

Disable X in Dojo Dialog

I found a trick to disable [x] on the top right corner of dojo dialog and force user to click on the close button to close the dialog box. Create a div element in your html web page and pass its id to following function to achieve this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function createDialog(id, heading) {
    var dialogWidget = dijit.byId(id);
    if( dialogWidget ) {
        dialogWidget.destroyRecursive(true);
    }
    dialogWidget = new dijit.Dialog(
                    { title: heading,
                   isContainer: true,
                   duration:600,
                   isContainer: true,
                   style:"width:600;height:300;overflow:auto;position:absolute;z-index:1000"},
                   dojo.byId(id));
    
    var dialog = dojo.byId(id);
    var dijitDialog = dijit.byId(id);
    dijitDialog.closeButtonNode.style.display = "none";
    dijitDialog._onKey = function(evt){
        key = evt.keyCode;
        if (key == dojo.keys.ESCAPE) {
            dojo.stopEvent(evt);
        }
    };
    if(dialog.parentNode) {
        dialog.parentNode.removeChild(dialog);
    }
    var form = document.forms[0];
    form.appendChild(dialog);
    dialogWidget.startup();
}

File Upload in CakePHP

In this post I will describe how to upload images in CakePHP. It will automatically upload and move the uploaded file to the wanted location. It will automatically rename the file if there is another file with same name exist. A lot of other features are also available.

  • Download Upload Component file and copy it to the location app/Controller/Component/UploadComponent.php
  • Initialize
    1
    var $components = array('Upload');
  • Your add action would looks like:
    PHP
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    public function add() {
        if ($this->request->is('post')) {
            if (!empty($this->request->data) && is_uploaded_file($this->request->data['Gallery']['image']['tmp_name'])) {
                
                $this->Upload->upload($this->data['Gallery']['image']);
                if ($this->Upload->uploaded) {
                    $this->Upload->file_new_name_body = 'image_resized';
                    $this->Upload->image_resize = true;
                    $this->Upload->image_x = 400;
                    $this->Upload->image_ratio_y = true;
                    $this->Upload->process(Configure::read('UploadPath'));
                    if ($this->Upload->processed) {
                        $this->Upload->clean();
                        $this->request->data['Gallery']['image'] = basename($this->Upload->file_dst_name);
                    } else {
                        $errors = $this->Upload->error;
                        $this->Session->setFlash(__($errors));
                        exit();
                    }
                }
            }
            $this->Gallery->create();
            if ($this->Gallery->save($this->request->data)) {
                $this->Session->setFlash(__('The gallery has been saved'));
                $this->redirect(array('controller' => 'galleries' ,'action' => 'index'));
            } else {
                $this->Session->setFlash(__('The gallery could not be saved. Please, try again.'));
            }
        }
    }

  • We have setup our controller. Now its time to setup view file add.ctp. The file file should look like following:

    PHP
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <div class="galleries form">
    < ?php echo $this->Form->create('Gallery', array('enctype' => 'multipart/form-data'));?>
        <fieldset>
            <legend>< ?php echo __('Add Gallery'); ?></legend>
        < ?php
            echo $this->Form->input('caption');
            echo $this->Form->input('desc');
            echo $this->Form->file('image');
        ?>
        </fieldset>
    < ?php echo $this->Form->end(__('Submit'));?>
    </div>
    <div class="actions">
        <h3>< ?php echo __('Actions'); ?></h3>
        <ul>
            <li>< ?php echo $this->Html->link(__('List Galleries'), array('action' => 'index'));?></li>
        </ul>
    </div>

  • All done.

UploadComponent class file is well document so you can always find all configuration setting for the uploaded images.