<?php
/*
ConvBmarks 0.1
Author: Jayesh Sheth
Email: jay [at] moztips.com
http://www.moztips.com/code/winbinder/convrc/

Purpose:
This program converts Mozilla Bookmark RDF files to Wiki syntax files. 
It uses an XSL stylesheet written by Juliano Ravasi Ferraz.

Requirements:
* Windows
* WinBinder extension for PHP 5 - http://www.hypervisual.com/winbinder/index.php
* PHP 5 - http://www.php.net
* LibXSLT and LibXML extensions / built-in support for PHP 5

Pre-installation:
Unzip the zip file and open the unmork.html file in Mozilla Firefox. Use the 'Export Bookmarks' button (and ignore any warning) to export your Firefox bookmarks to a Bookmarks RDF file. Remember where this file is saved.

Installation:

You need PHP 5 and WinBinder, plus the libxml and libxslt extensions for it to work.
This will not work with PHP 4.

You have two options:
* Install the entire WinBinder + PHP 5 package from http://www.hypervisual.com/winbinder/index.php and then manually add in the php_xsl.dll file to the PHP 5 extensions dirctory
* Just download the WinBinder dll file, and install PHP 5 file yourself by unzipping the PHP 5 zip file to a directory. Copy the WinBinder dll to the PHP 5 extensions folder.

Make sure you have the php_xsl.dll extension in your extensions directory before proceeding. 

If you don't have it, you can download the whole Windows PHP 5 zip file from http://www.php.net, and locate the php_xsl.dll file in that file.

Then make sure the extensions section of your php.ini file looks like this:

extension_dir = "ext/"            ; Directory in which the loadable extensions (modules) reside.
extension=php_winbinder.dll
extension=php_xsl.dll

Running:
If .phpw extensions are already associated with the php-win.exe file that comes with the WinBinder distribution,
simply double click on this (convrc.phpw) file.

If it is not, first associate .phpw files with the php-win.exe program, and then double click on it.

You can also invoke it via the command line (if you need to add debug messages to be outputted):
C:\WinBinder\PHP\PHP5\php.exe C:\WinBinder\Code\convbmarks\convbmarks.phpw

Usage:

Once the program is running, use the button to open the Mozilla RDF file which you exported.
In the same directory where this script exists, a file called output.txt will be saved.
If you need your bookmarks converted to a different format, simply modify the XSL file as necessary, or drop me a note (although I cannot promise anything before hand.)

Programming Note: 
I am new to using WinBinder, so this program is not written as well as it should be. 
For example, instead of using identifiers such as 'IDC_BUTTON1002', I should use something like 'BUTTON_OPEN_RCFILE'.

Feedback:
Please send feedback to jay [at] moztips.com.
*/
require("/winbinder/Code/inc/winbinder.php");   // Include WinBinder library

define("APPNAME",    "ConvBmarks 0.1");    // Application name

// Control identifiers

if(!defined("IDD_DLG1001")) define("IDD_DLG1001"1001);
if(!
defined("IDC_BUTTON1002")) define("IDC_BUTTON1002"1002);
if(!
defined("IDC_STATIC1004")) define("IDC_STATIC1004"1004);
if(!
defined("IDC_STATIC1005")) define("IDC_STATIC1005"1005);
if(!
defined("IDC_STATIC1006")) define("IDC_STATIC1006"1006);
if(!
defined("IDC_STATIC1008")) define("IDC_STATIC1008"1008);
if(!
defined("IDC_STATIC1009")) define("IDC_STATIC1009"1009);

// Create window
$mainwin wb_create_window(NULL100"Mozilla Bookmarks Converter"WBC_CENTERWBC_CENTER500400WBC_INVISIBLE WBC_NOTIFY32);
wb_set_handler($mainwin"process_main");

// Insert controls

wb_create_control($mainwinPushButton"Open Mozilla Bookmarks RDF File"1095020025IDC_BUTTON1002WBC_VISIBLE WBC_ENABLED);
wb_create_control($mainwinLabel"Convert Mozilla Bookmarks RDF file to Wiki-formatted File"10939926IDC_STATIC1004WBC_VISIBLE WBC_ENABLED WBC_CENTER);
wb_create_control($mainwinLabel"Input file name (RDF):"1012042330IDC_STATIC1005WBC_VISIBLE WBC_ENABLED WBC_MULTILINE);
wb_create_control($mainwinLabel"Outputted file (text):"1018042316IDC_STATIC1006WBC_VISIBLE WBC_ENABLED WBC_MULTILINE);
// wb_create_control($mainwin, Label, "Output file name will go here", 10, 219, 425, 30, IDC_STATIC1008, WBC_VISIBLE | WBC_ENABLED | WBC_MULTILINE);
wb_create_control($mainwinLabel"File conversion status:"1026942930IDC_STATIC1009WBC_VISIBLE WBC_ENABLED WBC_MULTILINE);

// End controls

// Enter application loop
wb_set_visible($mainwintrue);
wb_main_loop();

// Event Handler Function 
function process_main($window$id)
{
    static 
$file_filter = array(
        array(
"RDF Text Files",    "*.txt"),
        array(
"All files",            "*.*")
    );
    switch(
$id
    {
        case 
IDC_BUTTON1002:
        
// wb_exec("../../release_notes.txt");
        // wb_message_box($window, "Hello from me", 'Message - Yoo Hoo ', WBC_OK);
        
$filename wb_sys_dlg_open($window"Get file name"$file_filter);
        if(
$filename)
        {
            
wb_set_text(wb_get_control($window,  IDC_STATIC1005), 'Input file name: ' $filename);
            
            
/*
            wb_message_box(NULL, "Filename: $filename2 ", 'Message', WBC_OK);
            */
            
            
$filename2 'output' '.txt';
            
wb_set_text(wb_get_control($window,  IDC_STATIC1006), 'Output file name: ' $filename2);
            
            
// From Adam Trachtenberg's book, upgrading to PHP 5, page 148
            // Load XSL Template
            
$xsl = new DOMDocument();
            
$xsl->load('mozbookmarks2wiki.xsl.xml');
            
            
// Create new XSLTProcessor
            
$xslt = new XSLTProcessor();
            
// Load stylesheet
            
$xslt->importStylesheet($xsl);
            
            
// Load XML input file
            
$xml = new DOMDocument();
            
$xml->load($filename);
            
            
// Transform to a file
            
$results $xslt->transformToURI($xml$filename2);
            
            if (
$results)
            {
                
wb_set_text(wb_get_control($window,  IDC_STATIC1009), "Conversion successful: $filename2.");
            }
            else
            {
                
wb_set_text(wb_get_control($window,  IDC_STATIC1009), 'Error: conversion failed.');
            }
            
        }
        break;
        
        case 
IDCLOSE:        // IDCLOSE is predefined
        
wb_destroy_window($window);
        break;
    }
    
    
    
}
?>