10/12/09

Permalink 02:13:07 pm, by admin Email , 1138 words, 11772 views   English (US)
Categories: PHP

Basic native P4A File Manager

This code can be used as a P4A mask to provide very basic File Manager functionality outside of the RTE.

class fm extends p4a_base_mask
{
public $rootfolder = null;
public $htmlrootfolder = null;

//yes I know P4A has it's own system for this built around defined constants. Constants that we can't change! so lets do it here on a mask by mask basis.
public $valid_preview_images = array('gif','jpg','ico','png'); //'mp3','mp4','avi','pdf','doc','xls','odt','ods','txt'
public $valid_preview_text = array('txt');

public function __construct() {
parent::__construct();

$site = '/'.P4A::singleton()->user_data['user'];

$this->rootfolder = P4A_UPLOADS_DIR.$site;
$this->htmlrootfolder = P4A_UPLOADS_PATH.$site;

$iconpath = P4A_ROOT_URL.'/icons/default/16';
$this->setTitle('File Manager');

//File Handling
$this->build("P4A_Dir_Source", "fileset")
->setDir($this->rootfolder);

$this->build("P4A_Field", "upload_field")
->setLabel('Upload:')
->setUploadSubpath('')
->label->setWidth(50);
$this->upload_field->setType("file");
$this->intercept($this->upload_field, "afterUpload", "afterUpload");

$this->build("p4a_table",'table')
->setSource($this->fileset);
$this->table->addActionCol ('delete')
->cols->delete->setLabel('<img src="'.P4A_ROOT_URL.'/icons/default/16/actions/edit-delete.png" alt="[D]" title="Delete this file" />');
$this->intercept($this->table->cols->delete, 'afterClick', 'DeleteColClick');
$this->table->addActionCol ('preview')
->cols->preview->setLabel('<img src="'.P4A_ROOT_URL.'/icons/default/16/actions/thumbnail.png" alt="[P]" title="View this file" />');
$this->intercept($this->table->cols->preview, 'afterClick', 'TableRowClick');
$this->table->rows->addAction('afterClick');
$this->intercept($this->table->rows, 'afterClick', 'TableRowClick');

$this->build("P4A_Fieldset","f_table")
->setLabel('Files ['.str_replace($this->rootfolder,'.',$this->fileset->getDir()).']')
->anchorLeft($this->table)
->anchorCenter($this->upload_field);

//Directory Handling
$this->build("P4A_Toolbar","dtb")->setSize(16);
$this->dtb->addButton('new_',$iconpath.'/mimetypes/folder_green.png');
$this->dtb->addButton('home',$iconpath.'/actions/go-home.png');
$this->dtb->addButton('delete',$iconpath.'/actions/edit-delete.png');
$this->intercept($this->dtb->buttons->new_, 'onClick', 'createFolder');
$this->intercept($this->dtb->buttons->home, 'onClick', 'goFolderHome');
$this->intercept($this->dtb->buttons->delete, 'onClick', 'deleteFolder');

$navme = $this->build("P4A_Dir_Navigator","navme")
->setBaseDir($this->rootfolder);
$this->navme->addAction('afterClick');
$this->intercept($this->navme, 'afterClick', 'NavRowClick');

$this->build("P4A_Field", "create_folder_field")
->setWidth(100)
->label->setWidth(30)
->setLabel('New: ');

$this->build("P4A_Fieldset","f_navme")
->setLabel('Directory ['.str_replace($this->rootfolder,'.',$this->navme->getBaseDir()).']')
->setWidth(250)
->anchor($this->create_folder_field)
->anchorleft($this->dtb)
->anchor($this->navme);
//Preview Handling
$this->build("p4a_image","imagepreview")
->setStyleProperty('position','relative') //a bit of elbow room
->setStyleProperty('padding','10px'); //a bit of elbow room

$this->build("p4a_box","textpreview")
->setWidth(500)
->setStyleProperty('padding','10px'); //a bit of elbow room

$this->build("P4A_Button", "close_imagepreview_button")
->setSize(16)
->setLabel('Close Preview',false)
->setIcon($iconpath.'/actions/window-close.png')
->implement("onclick", $this, "closeImagePreview");

$this->build("P4A_Button", "close_textpreview_button")
->setSize(16)
->setLabel('Close Preview',false)
->setIcon($iconpath.'/actions/window-close.png')
->implement("onclick", $this, "closeTextPreview");

$this->build("P4A_Fieldset","f_imagepreview")
->setLabel('')
->setVisible(false)
->anchorRight($this->close_imagepreview_button)
->anchorCenter($this->imagepreview);

$this->build("P4A_Fieldset","f_textpreview")
->setLabel('')
->setVisible(false)
->anchorRight($this->close_textpreview_button)
->anchorCenter($this->textpreview);

//Display
$this->frame->anchor($this->f_navme)
->setWidth(700)
->addCssClass('mr_frame')
->addCssClass('ui-corner-all')
->anchorLeft($this->f_table)
->anchorCenter($this->f_imagepreview)
->anchorCenter($this->f_textpreview);

$this->build("P4A_Quit_Toolbar","toolbar");

$this->display("top",$this->toolbar);

$this->info('File Manager Loaded...');

}

public function closeImagePreview() {
$this->f_imagepreview->setVisible(false);
}
public function closeTextPreview() {
$this->f_textpreview->setVisible(false);
}

public function goFolderHome() {
$d = $this->rootfolder;
$this->f_navme->setLabel('Directory [.]');
$this->fileset->setDir($d)
->reload();
$this->navme->setCurrentSubdir($this->rootfolder);
$this->uploadfield->setUploadSubpath('');
$this->f_table->setLabel('Files [.]');
}

public function NavRowClick($a) {
$v = $this->navme->getCurrentSubdir();
$d = $this->rootfolder;
$this->f_table->setLabel('Files [./'.$v.']');
$this->f_navme->setLabel('Directory [./'.$v.']');
$this->fileset->setDir($d.'/'.$v)
->reload();
$this->uploadfield->setUploadSubpath($d.'/'.$v);
}

public function TableRowClick($o, $a) {
$f = $this->table->data->fields->filename->getValue();
$s = $this->table->data->fields->size->getValue();
$e = trim(end(explode(".", $f)));
if (in_array($e,$this->valid_preview_images)) {
$relativepathfilename = $this->navme->getCurrentSubdir().'/'.$f;
$this->imagepreview->setIcon($this->htmlrootfolder.'/'.$relativepathfilename);
$this->f_textpreview->setVisible(false);
$this->f_imagepreview->setLabel('Preview: '.$f)
->setVisible(true);
} elseif(in_array($e,$this->valid_preview_text)) {
$relativepathfilename = $this->navme->getCurrentSubdir().'/'.$f;
$fileContent = file_get_contents($this->rootfolder.'/'.$relativepathfilename,FILE_TEXT);
$this->textpreview->setValue('<pre>'.$fileContent.'</pre>');
$this->f_imagepreview->setVisible(false);
$this->f_textpreview->setLabel('Preview: '.$f)
->setVisible(true);

} else {
$this->info('Sorry. Preview unavailable for this file');
}
}

public function DeleteColClick($o, $a) {
$this->info('Deleting file...');
$fullpathfilename = $this->fileset->getDir().'/'.$this->table->data->fields->filename->getValue();
unlink($fullpathfilename);
$this->fileset->reload();
$this->info('Done...');
}

public function createFolder() {
$this->info('Creating...');
$v = $this->navme->getCurrentAbsoluteDir();
$folder = $this->create_folder_field->getNewValue();
if ($v == $this->rootfolder.'/') {
$fullnewpath = $v.$folder;
} else {
$fullnewpath = $v.'/'.$folder;
}
mkdir($fullnewpath,0777,true);
$this->create_folder_field->setNewValue(null);
$this->info('Done...');
}

public function afterUpload() {
$tmpname = $this->upload_field->getNewValue(0);
$name = $this->upload_field->getNewValue(6);
$fullpath = $this->fileset->getDir();

rename(P4A_UPLOADS_TMP_DIR . "/$tmpname", "$fullpath/".$name);
$this->upload_field->setNewValue(null);
$this->fileset->reload();
}

public function deleteFolder() {
$this->info('Deleting directory...');
$v = $this->navme->getCurrentAbsoluteDir();
$folder = $this->create_folder_field->getNewValue();
if ($v == $this->rootfolder.'/') {
$this->error('You cannot delete your root directory');
} else {
$fulldelpath = $v.'/'.$folder;
$oneup = realpath($fulldelpath.'/../');
$this->_delete_directory($fulldelpath);
$this->navme->setBaseDir($oneup); //move navme up one
$this->fileset->setDir($oneup) //move filelist up one
->reload();
$this->info('Done...');
}
}

function _delete_directory($dirname) { //remove containing files & directories then remove what I've asked for
if (is_dir($dirname))
$dir_handle = opendir($dirname);
if (!$dir_handle)
return false;
while($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname."/".$file))
unlink($dirname."/".$file);
else
$this->_delete_directory($dirname.'/'.$file);
}
}
closedir($dir_handle);
rmdir($dirname);
return true;
}

}

You may need to add the necessary icons to the correct location in the

./icons

directory. I used the Open Source Crystal iconset.

This was developed using P4A v3.4.1

I'm sure this can be improved upon, feel free to do so and let me know...

Permalink 01:42:01 pm, by admin Email , 218 words, 7755 views   English (UK)
Categories: PHP

Upgrading the P4A FCKEditor File Manager

I use P4A a lot. One thing I've found though is that the default File Manager which comes with it's implementation of FCKEditor is a bit basic for my customers.

As a result, I now use TinyBrowser as a replacement. This article outlines how to implement it.

First off, download the latest TinyBrowser from http://www.lunarvis.com, currently this is v1.41.

Extract the contents of the TinyBrowser download into
./themes/default/widgets/rich_textarea/editor/filemanager/browser/tinybrowser

Edit ./themes/default/widgets/rich_textarea/rich_textarea.php and place the following code inside the first PHP code block:


// Introduced by Fear of Mice to support tinybrowser
$mydir = P4A_UPLOADS_DIR. '/' . $this->getUploadSubpath(); //set
$prep = false;
if (substr($mydir, 0, 7) == 'http://' || substr($mydir, 0, 8) == 'https://') { //Strip_Slashes
$prep = TRUE;
}
$mydir = str_replace('https://','',$mydir);
$mydir = str_replace('http://','',$mydir);
$mydir = preg_replace('|(/)+|','/',$mydir);
if($prep === TRUE) {
$mydir = prep_url($mydir);
}
$mydir=base64_encode($mydir); //encode it

then replace:

rte.Config['LinkBrowserURL'] = rte.BasePath + 'editor/filemanager/browser/default/browser.html?Connector=<?php echo $connector ?>';

with

rte.Config['LinkBrowserURL'] = rte.BasePath + "editor/filemanager/browser/tinybrowser/tinybrowser.php?path=<?php echo $mydir ?>";

That's it. You should now have a nice File Manager which supports multiple uploads and thumbnails.

30/11/09

Permalink 12:40:10 pm, by admin Email , 51 words, 22476 views   English (UK)
Categories: PHP, Linux

CodeIgniter .htaccess for use with Heart Internet

Here's a working .htaccess file for CodeIgniter projects hosted on Heart Internet.

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]

*please note, I'm note endorsing the use of Heart Internet Hosting. You'll probably find better facilities elsewhere ;)

09/07/09

Permalink 01:33:25 pm, by admin Email , 417 words, 6299 views   English (UK)
Categories: Networking & Broadband

Rural Mobile Broadband - An Overview

Mobile broadband has the major benefit of allowing you to continue to use the Internet for all of things you would use it for whilst you are away from home. It is great for people who often travel or those who have to travel a long way to work. As long as the area you are in has at least decent coverage, it is possible to connect to the Internet through your mobile wherever you are. Mobile broadband doesn't require a fixed phone line, and there are plenty of options available where you only pay for the amount of time you spend on the Internet. Even if you don't subscribe to a mobile broadband service, you can still use either free WiFi hotspots to access mobile Internet or others by paying for the time you spend online by receiving a password.

If you live in a rural area, it is likely that your part of the country has yet to be equipped with 3G technology, and instead only has a second generation network, meaning you are likely to suffer with limited coverage of your mobile broadband. To have a chance of overcoming this problem of poor coverage in rural areas, visit different mobile broadband provider's websites and use their coverage checker to find out the standard of coverage you can expect from their service. That way, you can pick the provider who offers your area the highest amount of coverage. If you do live in a place where only a 2G network is available, you should still be able to check your e-mails and perform other simple tasks via your mobile broadband connection.

Another problem with rural mobile broadband mobile broadband is that you are unlikely to receive the maximum connection speed advertised by the mobile broadband supplier you choose to use. Connection speeds are usually affected by the amount of mobile broadband users connected to the network you use in your area and if there is any electrical interference present in your rural area. Slow connections again can result from the rural area in which you live not having a third generation network, and only having 2G. Again check on suppliers' websites to see if any of the providers offer a superior connection speed to your area compared to other providers. If there are no companies with 3G networks in your rural area, unfortunately mobile broadband is not probably the way to go if you want to use the Internet quickly and for many different purposes.

Permalink 01:33:02 pm, by admin Email , 417 words, 4014 views   English (UK)
Categories: Delphi

Rural Mobile Broadband - An Overview

Mobile broadband has the major benefit of allowing you to continue to use the Internet for all of things you would use it for whilst you are away from home. It is great for people who often travel or those who have to travel a long way to work. As long as the area you are in has at least decent coverage, it is possible to connect to the Internet through your mobile wherever you are. Mobile broadband doesn't require a fixed phone line, and there are plenty of options available where you only pay for the amount of time you spend on the Internet. Even if you don't subscribe to a mobile broadband service, you can still use either free WiFi hotspots to access mobile Internet or others by paying for the time you spend online by receiving a password.

If you live in a rural area, it is likely that your part of the country has yet to be equipped with 3G technology, and instead only has a second generation network, meaning you are likely to suffer with limited coverage of your mobile broadband. To have a chance of overcoming this problem of poor coverage in rural areas, visit different mobile broadband provider's websites and use their coverage checker to find out the standard of coverage you can expect from their service. That way, you can pick the provider who offers your area the highest amount of coverage. If you do live in a place where only a 2G network is available, you should still be able to check your e-mails and perform other simple tasks via your mobile broadband connection.

Another problem with rural mobile broadband mobile broadband is that you are unlikely to receive the maximum connection speed advertised by the mobile broadband supplier you choose to use. Connection speeds are usually affected by the amount of mobile broadband users connected to the network you use in your area and if there is any electrical interference present in your rural area. Slow connections again can result from the rural area in which you live not having a third generation network, and only having 2G. Again check on suppliers' websites to see if any of the providers offer a superior connection speed to your area compared to other providers. If there are no companies with 3G networks in your rural area, unfortunately mobile broadband is not probably the way to go if you want to use the Internet quickly and for many different purposes.

18/03/09

Permalink 12:11:27 pm, by admin Email , 178 words, 5368 views   English (UK)
Categories: Linux

Citadel Backups

I'm now using this script to do a strategy #1 backup of my citadel server as a cron job.

It assumes you have a /root/backups/ directory and works on Ubuntu 8.10 Server with Citadel installed using "Easy Install"...

Basically, it shuts down citadel, waits for a bit for the service to complete shutting down, tars the citadel files to the selected location and restarts teh citadel service.

Enjoy.


#!/bin/sh
# Fear of Mice's Backup for Citadel
# http://www.fearofmice.co.uk/blog

CITADEL_DIR=/usr/local/citadel
TIMESTAMP=`date +%Y%m%d_%H%M%S`;
echo $TIMESTAMP


echo -n "Stopping Citadel... "
if $CITADEL_DIR/sendcommand DOWN >/dev/null 2>&1 ; then
sleep 10
echo "ok"
rm -f /usr/local/citadel/citadel.pid 2>/dev/null
echo "backing up..."
tar -cvf /root/backups/citadel_$TIMESTAMP.tar /etc/init.d/citadel /etc/init.d/webcit /usr/local/citadel/ > /root/backups/citadel_$TIMESTAMP.log
sleep 5
echo "backed up"
echo -n "Starting Citadel... "
if $CITADEL_DIR/citserver -d -h$CITADEL_DIR
then
echo "ok"
else
echo "Starting Citadel failed"
fi
else
echo "Stopping Citadel failed"
fi

30/10/07

Permalink 09:23:53 pm, by admin Email , 148 words, 6022 views   English (UK)
Categories: Linux

Kubuntu: Opening URL files with Firefox

Firefox in both Windows and Linux lets you drag a tab to the Desktop which gets saved as a .url file. Inspecting these files shows the url in question is saved as text inside the file.

On Windows, Firefox is quite happy to open the browser at the url when double-clicking the .url file. In Linux (at least in KDE which my Kubuntu install uses) this doesn't happen. Firefox opens the file itself so you get a browser window containing the url text.

This is how I got Firefox on KDE to open my files as desired.

1 - create /bin/url.sh
#!/bin/bash
IFS=$'©'
FFOPENURL=$(less $1)
firefox $FFOPENURL

2 - Right-click a sample .url file, select "Open with" from the popup menu and enter /bin/url.sh in the edit box. Make sure you tick the "Remember application association for this file type" box. Click OK.

This should now work...

07/06/07

Permalink 07:50:27 pm, by admin Email , 419 words, 16535 views   English (UK)
Categories: Delphi

Feisty Kubuntu and Lotus Notes 8 Beta 3 - Howto

I've always been a big fan of Lotus Notes and have been "happily" using v7.01 under Wine. The new Lotus Notes 8 is built on Eclipse (another tool I use extensively) and so I've been keen to get any of the current beta versions to work. Beta 2 was a dead loss but Beta 3 seems to be that more usable.

Here's my step-by-step guide to get it up and running:

1. Ensure the Notes fonts will look nicer than the default
sudo dpkg-reconfigure fontconfig-config
select autohinter, automatic, no for bitmap fonts

2. Link sh to bash. The Feisty default is dash which causes "Generic LSE Failure" errors when you run the client after install.
$ sudo mv /bin/sh /bin/sh.orig
$ sudo ln -s /bin/bash /bin/sh

3. Extract the Notes Client download
$ cd ~/Desktop
$ mkdir Notes8Beta3
$ cd Notes8Beta3
$ tar xvf ../notes8_linux_beta3_prod.tar

4. You'll need to do this magic step to avoid a bug in the Installer:
$ sudo cp deploy/install.xml /root/
Basically copy install.xml into the root folder because that's where the Installer goes looking for it.

5. Run the GUI Installer
$ sudo ./setup.sh
You will now get the InstallShield GUI. Here is what I did in the GUI. It'll make sense when you go through it, and except for selecting all components, it's just the straight defaults.

Next (Intro screen)/I accept both terms/Next (License)/Accept default path (/opt/ibm/lotus/notes)/Next (Path)/Select all features/Next (Features)/Install (Summary)/ (Wait a while ) /Finish

6. Fix the /etc/lotus directory
After the install, you will have to change the parameters on the /etc/lotus directory.
$ sudo chmod -R 755 /etc/lotus
If you don't do this, you will get an error telling you that pernames.ntf can't be copied.

7. Application Icons
By default, the installer will create your Desktop icons. You may need to logout and back in again for them to be picked up. Failing that, the command line is:
$ /opt/ibm/lotus/notes/notes

8.The client will now launch. Eventually you will get the typical new-client wizard. If you've ever installed a Notes client before, it will all make sense...

Next (Welcome screen)
Name: {your name}
Server: (server name)
Next (User Information)
Next (Connect to server)
Network type: TCP/IP
Server address: (server address)
Next (Network Info)
File name: (Path to my ID file)
No (Do not copy to data folder)
(Password)/OK
Next (Setup additional services)/OK (Notes setup is complete!)

You should now have the Getting Started screen!

Good Luck!

<< Previous Page :: Next Page >>

fear of mice

This is the official blog of

We aim to post comments (and possibly solutions) to some of the more interesting IT Support issues we come across in our daily travels around the South Hams of Devon.

< Previous | Next >

November 2014
Mon Tue Wed Thu Fri Sat Sun
<< <     
          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

Search

Categories

Misc

XML Feeds

What is RSS?

Who's Online?

  • Guest Users: 1

powered by
b2evolution