Advertisement
Guest User

Displaying data from myTinyTodo somewhere else

a guest
Sep 21st, 2010
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Class to read data from http://www.mytinytodo.net/ and display it somewhere else (as a part of your own application).
  5.  * Allows to integrate your todo list into some other web-site.
  6.  * You only need to comment line 68 in todo/ajax.php "exit;" for this class to work. THIS IS IMPORTANT!
  7.  *
  8.  * © 2010 spidgorny@gmail.com
  9.  * http://spidgorny.blogspot.com/2010/09/displaying-data-from-mytinytodo.html
  10.  */
  11. class Todo extends Controller {
  12.     protected $tasks = array();         // the data will be stored here
  13.                                         // structure: array('total' => 15, 'list' => array(...));
  14.  
  15.     /**
  16.      * We imitate an AJAX request for the data and grab it with ob_get_clean().
  17.      * Then we decode JSON data and voilà!
  18.      *
  19.      */
  20.     function __construct($tab = 1) {
  21.         $_GET['loadTasks'] = 1;
  22.         $_GET['list'] = $tab;           // which tab to display
  23.         $_GET['compl'] = 0;
  24.         $_GET['sort'] = 0;
  25.         $_GET['tz'] = 120;
  26.         $_GET['rnd'] = rand();
  27.         //debug($_GET);
  28.         ob_start();
  29.         require_once('todo/init.php');
  30.         $GLOBALS['lang'] = Lang::instance();
  31.         require_once('todo/ajax.php');
  32.         $json = ob_get_clean();
  33.         $this->tasks = json_decode($json, TRUE);
  34.         //debug($this->tasks);
  35.     }
  36.  
  37.     /**
  38.      * Modify this function in order to display data from $this->tasks['list'].
  39.      *
  40.      */
  41.     function render() {
  42.         require('template/head.phtml');
  43.         echo '<div class="headerMargin"><br>';
  44.         foreach ($this->tasks['list'] as $i => &$row) {
  45.             unset($row['id']);
  46.             unset($row['dateInline']);
  47.             unset($row['dateCompleted']);
  48.             unset($row['prio']);
  49.             unset($row['note']);
  50.             unset($row['noteText']);
  51.             unset($row['ow']);
  52.             unset($row['tags']);
  53.             unset($row['duedate']);
  54.             unset($row['dueClass']);
  55.             unset($row['dueStr']);
  56.             unset($row['dueInt']);
  57.             if ($row['compl']) {
  58.                 //unset($this->tasks['list'][$i]);
  59.                 break;
  60.             }
  61.             unset($row['compl']);
  62.         }
  63.         echo new slTable($this->tasks['list'], 'width="90%" style="margin: 0 auto;"');
  64.         echo '</div>';
  65.         require('template/footer.phtml');
  66.     }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement