Sunday, February 7, 2010

Changing Agora Forum using Joomla users' name rather username

Agora Forum is an excellent extension for Joomla as an Forum. Rather using bridge to phpBB which causes the system overhead (since it runs 2 system: Joomla & phpBB), we only run one system.

Anyway, the problem that I encounter is I don't want Agora using my Joomla username, but I prefer it to use Joomla name. But I've never found any settings or configurations about this. So the only way is to hack it a little. It is kinda hard to find where the code to change it, since I am not so familiar with its code anyway. But at least today, I've successfully change it to using name :D

I am not sure whether this setting is already sufficient or not. So there might be a additional hack in the future.

First of all I must create a function that change all the username in #__agora_users to name of #__users. For me, I create a component called com_tar_setforum in administrator, and put the code like this.

class Tar_setforumController{
...
function setUsername(){
$model = & $this->getModel('forum');

foreach($model->listIdUsers() as $value){
$model->updateUsername($value);
}
$link = JRoute::_('index.php?option=com_tar_setforum');
$this->setRedirect($link,'Nama berhasil di-set');
$this->redirect();
}
....
}


And put a model with function like this :
class Tar_setforumModelForum extends JModel{
function updateUsername($jos_id){
$query = "UPDATE #__agora_users SET username=(SELECT name FROM #__users WHERE id='$jos_id')
WHERE jos_id='$jos_id'";
$this->_db->Execute($query);
}
.....


But only update the name in the #__agora_users doesn't solve the problem. Somehow everytime users access the forum, the table is updated to old value. That's why we need to hack the Agora code.
Here what I change the code :

/components/com_agora/model/user.php
function loadCurrent(){
....
// Update loaded user to not load it again
foreach ($data as $param=>$value) {
$user[$param] = $value;
}

//Here my additional code
$user['username'] = $my->name;
$data['username'] = $my->name;

$this->edit($user['id'],$data);
....
}


and one more
/components/com_agora/model/online.php

function getOnline()
{
....
/*$query = 'SELECT a.id, a.username' .
' FROM #__session AS s INNER JOIN ##__users AS a ON s.userid=a.jos_id' .
' WHERE client_id = 0 AND s.guest=0';
*///commented. This is the old one. Replace with below codes
$query = 'SELECT a.id, u.name
FROM #__session AS s INNER JOIN ##__users AS a ON s.userid=a.jos_id
INNER JOIN #__users AS u ON u.id=s.userid
WHERE client_id = 0 AND s.guest=0';
....
if (count($sessions)) {
foreach ($sessions as $session) {
//$user_array[] = array('id' => $session->id, 'name' =>$session->username); //commented by Xiong
$user_array[] = array('id'=> $session->id, 'name'=>$session->name);
}
}
....
}


After changing this, it should can preserve the username in #__agora_users

Thursday, January 28, 2010

FireGesture causes TinyMCE's context menu disabled

If you enable the context menu on TinyMCE, then whenever you right click on the TinyMCE textarea it supposed to pop up a menus. But somehow my Firefox doesn't show anything. It seems like the right click doesn't show anything!

So the first thing come to my mind is must be one of my Firefox's add-ons causes this. Later by disabling all the add-ons, and restart the Firefox, the context menu is working!! :)
Then I just enable one by one add-ons until I enable the FireGesture, the context menu is not working again. Aha! I've found the culprit. :D

FireGesture is an add-on enables user to use mouse gesture (just like mouse gesture in Opera or Maxthon) to operate Firefox. Since FireGesture use right click, I think it somehow conflicts with TinyMCE context menu javascript. I haven't found the solution though except disabling this add-ons.

Update:
Later, I uninstalled FireGesture, and install All-In-One Gesture. It's doesn't conflict with TinyMCE. So this is my solution, but I hope one day I found the solution for FireGesture.

Tuesday, May 12, 2009

Upload to FTP using PHP script

For some reasons maybe you need to upload files to ftp. In my case, I need to upload the image files to ftp account because the capacity of the hosting is limited. So in order to upload the image to ftp account we using cURL. Here is the code


// FTP access parameters:
$host = 'www.ftp.com';
$usr = 'username';
$pwd = 'passw0rd';

// file to upload:
$local_file = 'test.png';
$ftp_path = 'test.png';

// connect to FTP server (port 21)
$conn_id = ftp_connect($host, 21) or die ("Cannot connect to host");

// send access parameters
ftp_login($conn_id, $usr, $pwd) or die("Cannot login");

// turn on passive mode transfers (some servers need this)
// ftp_pasv ($conn_id, true);

// perform file upload
$upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII);

// check upload status:
print (!$upload)? 'Cannot upload' : 'Upload complete';
print "\n";

/*
** Chmod the file (just as example)
*/

// If you are using PHP4 then you need to use this code:
// (because the "ftp_chmod" command is just available in PHP5+)
if (!function_exists('ftp_chmod')) {
function ftp_chmod($ftp_stream, $mode, $filename){
return ftp_site($ftp_stream, sprintf('CHMOD %o %s', $mode, $filename));
}
}

// try to chmod the new file to 666 (writeable)
if (ftp_chmod($conn_id, 0666, $ftp_path) !== false) {
print $ftp_path . " chmoded successfully to 666\n";
} else {
print "could not chmod $file\n";
}

// close the FTP stream
ftp_close($conn_id);

?>

Monday, May 11, 2009

Reason why mother want you to use Linux

Today I found a funny article at here about the reasons why your mother would want you to use Linux. Seems like because yesterday is Mother's Day (Happy mother's day!!), the author create this funny articles.

Here I copy the article to here:

1. Since Linux is free, you have no more reason to ask her for money every time you install, upgrade, and get new software applications. Now instead of buying you a Windows Vista Ultimate Edition, she now has extra money to spare for a spa.

2. Because she loves you so much, she wants you and your computer to be free from virus always. In addition, most mothers want the house to be always clean, and just hearing the words like bacteria, fungi, and virus make them angry.

3. She wants you to learn new things and gain deeper knowledge on how computers work instead of playing Xbox all day. Linux will greatly enhance your computer skills since you are free to explore its inner workings.

4. You don't have to ask her for money to buy new computer hardware to cope up with the latest software since there are lightweight and resource-efficient Linux distros that could make your old computer fly. So another money saved and another spa for your mother.

5. She wants you stop using bad words after a BSOD. Linux rarely crashes so she should be happy hearing you say "Wow" instead of "F*@k!" or "S#%t!" :-)

Sunday, January 4, 2009

Connect guest with host in virtualbox

Now is the fifth semester in my study at university. My friends who take Networking must do a Network Programming project. So, you must create a application which can play game from different computer with some constraint. The server must on Linux, while the client application must in other system operation. Since, most of the student using Windows, no need to mention all of them using Windows. There still another constraint on client. The application must be graphical user interface (GUI). They are free to use any developing program to make. But most of them choose to use Visual Basic or Java.

Ok, since there are 2 friends of mine (Aping and Awui) is having this project, I help a little. First thing first, I suggest them to install Virtualbox in their computer. Why? Because we must run server and client on different system operation, I don't think there is other way except using Virtual Machine. Because their computer only installed Windows, then the guest OS on virtualbox is Linux. I install Ubuntu to Aping's Virtualbox and Kubuntu to Awui's. Why I installed different OS, you might wonder. I just want to do it, no any special reason. :p

Ok. After installing it now is the time for testing whether the guest computer (linux) can connect to the host (Windows). Actually they can access our boarding host LAN network and browsing Internet. But, guest computer can't ping to host computer and vice versa. Ok now is time for investigation.

I try using my own Virtualbox. I boot to my Windows XP, fire up my Virtualbox with CentOS 5.2 as guest. And try to ping. The result is same. So I try to browse in Internet to see, whether there is any information regarding this. I found out that by default the Virtualbox is using NAT as network on its guest. And because by using NAT, it make the guest computer appear to be connected directly to the network. This explain why I can browse internet or browse the LAN network but can't ping the host computer.
I try to find out, but most of forum suggest to read the manual. Nothing can be done, I download the manual then.

After read a while, at last I found the point in the manual. Actually its very simple indeed. I just need to set the NAT connection become Host Interface and select the host's network interface to connect with. Geez~ it's so simple. Ok then, so I close my CentOS (host) and change the setting in Setting->Networks. And run my CentOS once again. But this time is strange, the CentOS unable to ping the gateway causing it doesn't connect to anywhere, causing its eth0 is not set. Feeling strange, I try to googling. There, I found somebody claim that Redhat 5.2 cannot connect using Host Interface. As you know, CentOS is almost same with Redhat, except the name and the logo. Knowing this, I try my other guest computer. I run my Kubuntu 8.04 using Host Interface. Aha! This time, its eth0 is not empty. In fact the IP address is different with before. Usually if you using NAT to connect, the IP address will always 10.0.2.15. Now it change to other IP Address(I forgot what is it). Try to ping it from Windows command prompt. Bingo! It replies. So actually it is simple. You just need to change it to Host Interface. But as you can see CentOS 5.2 and Redhat 5.2 is somehow cannot detected the connection.

Friday, December 19, 2008

Adding username and password for Proxy authentication

Not long ago, because of some reasons, my ISP add user authentication on the proxy. Which means we must enter username and password everytime want to connect to Internet (HTTP protocol, other protocol such as YM and MSN don't need to set proxy). Last time to set proxy in terminal, we can use

export http_proxy="http://proxy:port"

Now since it need to authentication user, we must add a little. So, just add the username and password at here:

export http_proxy="http://username@password:proxy:port"

That's all.

Wednesday, December 10, 2008

Fix the ugly font in Firefox

After a long time, I finally have bought the 320 GB. And I have installed Kubuntu Intrepid Ibex (8.10), using KDE4 is quite awesome. But still I need to adept the new way. This time when I open my Firefox, the first thing I've notice is the font is too ugly :p

So I googling and found somebody also has a same opinion with me and also the solution to fix this. He give a first solution, but later I realize that actually I just need to do the second one.

http://ubuntusite.com/fix-get-best-firefox-font-linux/

What we need is to download :
http://www.fileden.com/files/2008/2/9/1749988/segoe_ui.zip
extract and put it in
~/.font

If you haven't have .font directory, just create it. Then I set the font in System Settings->Appearance->Fonts
Set all the fonts to become Segoe UI, click Apply

And that's it now my Firefox font is more decent.