Tuesday, September 21, 2010

Displaying data from myTinyTodo somewhere else

For my project bug tracking I use myTinyTodo. One day I decided that it would be nice to show my todo list to the beta users of my project. So here's a simple class which is doing the job.


/**
 * Class to read data from http://www.mytinytodo.net/ and display it somewhere else (as a part of your own application).
 * Allows to integrate your todo list into some other web-site.
 * You only need to comment line 68 in todo/ajax.php "exit;" for this class to work. THIS IS IMPORTANT!
 *
 * © 2010 spidgorny@gmail.com
 *
 */
class Todo {
    // structure: array('total' => 15, 'list' => array(...));
    protected $tasks = array();            // the data will be stored here

    /**
     * We imitate an AJAX request for the data and grab it with ob_get_clean().
     * Then we decode JSON data and voilà!
     *
     */
    function __construct($tab = 1) {
        $_GET['loadTasks'] = 1;
        $_GET['list'] = $tab;            // which tab to display
        $_GET['compl'] = 0;
        $_GET['sort'] = 0;
        $_GET['tz'] = 120;
        $_GET['rnd'] = rand();
        //debug($_GET);
        ob_start();
        require_once('todo/init.php');
        $GLOBALS['lang'] = Lang::instance();
        require_once('todo/ajax.php');
        $json = ob_get_clean();
        $this->tasks = json_decode($json, TRUE);
        //debug($this->tasks);
    }
}

Download: http://pastebin.com/FgQNapF3

No comments: