Loading ...
Sorry, an error occurred while loading the content.
 

php interface to todo.sh

Expand Messages
  • Joshua D. Curry
    I think that this script is helpful, but it would also be nice if I could maintain one global copy of my todo list that I can edit from anywhere. So, I created
    Message 1 of 4 , Aug 17, 2007
      I think that this script is helpful, but it would also be nice if I
      could maintain one global copy of my todo list that I can edit from
      anywhere. So, I created a php interface that will interact with a
      local todo.sh to accomplish this. You could run this on your home
      computer if you have a webserver running, or if you don't (like me),
      you just use an automated scp command to copy down the todo.txt files
      when they change.

      So far as the php code goes, I coded quickly, but it appears to work
      without problems. I put in only the essential features b/c I want to
      be able to access this page using my phone's browser, so I needed to
      keep the html size down. Still, code focus on the input line and does
      an automatic refresh when items are added or removed. It also pre
      formats the -h output so that it's easy to read.

      Please let me know what you think.

      <?php
      $output = null;
      $input = $_POST['input'];
      if ($input == '' ) { $input = 'list'; }
      ?>
      <html>
      <head>
      <?php if ( (strtolower($input) != 'list') && (strtolower($input) !=
      'ls') && (strtolower($input) != 'listall') && (strtolower($input) !=
      'lsa') && (strtolower($input) != 'listpri') && (strtolower($input) !=
      'lsp') && (strtolower($input) != '-h') ) { echo "<meta
      http-equiv=\"refresh\" content=\"3\">\n"; } ?>
      <title>USERNAME Todo List</title>
      </head>
      <body onload="document.todo.input.focus()">
      <br />
      <form name="todo" action="t.php" method="post">
      <input type="text" size=75 name="input">
      <input type="submit" value="Submit">
      </form>
      <hr />
      <?php

      function t_echo($value)
      {
      print "$value <br \/>";
      }

      exec('/home/USERNAME/bin/todo.sh -p -v -f -d /home/USERNAME/.todo
      '.escapeshellcmd($input), $output);

      if ($input == '-h') { echo "<pre>"; }
      array_walk($output, 't_echo');
      ?>
      </body></html>
    • nesman_64
      ... I know this is an old thread, but I ve updated Joshua s php script. The code is a lot larger, but I ve added several features. Now, you can print directly
      Message 2 of 4 , Jun 10, 2008
        --- In todotxt@yahoogroups.com, "Joshua D. Curry" <joshdcurry@...> wrote:
        >
        > I think that this script is helpful, but it would also be nice if I
        > could maintain one global copy of my todo list that I can edit from
        > anywhere. So, I created a php interface that will interact with a
        > local todo.sh to accomplish this. You could run this on your home
        > computer if you have a webserver running, or if you don't (like me),
        > you just use an automated scp command to copy down the todo.txt files
        > when they change.
        >
        > So far as the php code goes, I coded quickly, but it appears to work
        > without problems. I put in only the essential features b/c I want to
        > be able to access this page using my phone's browser, so I needed to
        > keep the html size down. Still, code focus on the input line and does
        > an automatic refresh when items are added or removed. It also pre
        > formats the -h output so that it's easy to read.
        >
        > Please let me know what you think.
        >
        > <?php
        > $output = null;
        > $input = $_POST['input'];
        > if ($input == '' ) { $input = 'list'; }
        > ?>
        > <html>
        > <head>
        > <?php if ( (strtolower($input) != 'list') && (strtolower($input) !=
        > 'ls') && (strtolower($input) != 'listall') && (strtolower($input) !=
        > 'lsa') && (strtolower($input) != 'listpri') && (strtolower($input) !=
        > 'lsp') && (strtolower($input) != '-h') ) { echo "<meta
        > http-equiv=\"refresh\" content=\"3\">\n"; } ?>
        > <title>USERNAME Todo List</title>
        > </head>
        > <body onload="document.todo.input.focus()">
        > <br />
        > <form name="todo" action="t.php" method="post">
        > <input type="text" size=75 name="input">
        > <input type="submit" value="Submit">
        > </form>
        > <hr />
        > <?php
        >
        > function t_echo($value)
        > {
        > print "$value <br \/>";
        > }
        >
        > exec('/home/USERNAME/bin/todo.sh -p -v -f -d /home/USERNAME/.todo
        > '.escapeshellcmd($input), $output);
        >
        > if ($input == '-h') { echo "<pre>"; }
        > array_walk($output, 't_echo');
        > ?>
        > </body></html>
        >

        I know this is an old thread, but I've updated Joshua's php script.
        The code is a lot larger, but I've added several features.
        Now, you can print directly from the server, assuming you have
        printing set up correctly. You can mark items "done" by clicking them.
        I also added a few canned searches. With this format, you should be
        able to easily edit this script to more closely fit your needs.

        Joshua, thanks for posting the original. I hope that my adjustments
        can be as useful to others as your script has been to me.

        The code can be viewed online here: http://nesman.net/files/todo.phps
        I did a short write-up of the process here:
        http://nesman.net/archives/2008/05/index.html

        Actual code follows:

        <?php
        /*
        *todo.php
        used to provide a web interface to todo.sh from todotxt.com
        Original code from
        http://tech.groups.yahoo.com/group/todotxt/message/1320
        posted by joshdcurry
        *
        */

        // Change your username here
        define("USERNAME", "nesman");


        $output = null;
        $input = $_POST['input'];
        $runonce = true;
        if ($input == '' ) { $input = 'list'; }
        if (isset($_GET['mode'])){
        //do stuff
        switch ($_GET['mode']) {
        case "buy":
        case "don":
        case "ria":
        $input = "list @".$_GET['mode'];
        break;
        case "do":
        $input = "do ".$_GET['num'];
        break;
        case "list":
        case "print":
        $input = $_GET['mode'];
        break;
        default:
        $input = 'list';
        }

        }
        ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        <html>
        <head>
        <?php if ( (strtolower($input) != 'list') && (strtolower($input) !=
        'ls') && (strtolower($input) != 'listall') && (strtolower($input) !=
        'lsa') && (strtolower($input) != 'listpri') && (strtolower($input) !=
        'lsp') && (strtolower($input) != '-h') ) {
        //echo "<meta http-equiv=\"refresh\" content=\"3\">\n";
        $runonce = false;
        } ?>
        <title><?php echo USERNAME ?> Todo List</title>
        <style type="text/css">
        #menu li {display:inline;padding:0.2em 1em;}
        </style>

        </head>
        <body onload="document.todo.input.focus()">
        <?php
        if ($input == 'print' ) {
        if ($_GET['really'] == 'yes'){
        print_groceries();
        }
        else {
        confirm_print();
        }
        $input='list @buy';
        }
        ?>
        <ul id="menu">
        <li><a href="todo.php?mode=buy">@buy</a>
        <li><a href="todo.php?mode=don">@don</a>
        <li><a href="todo.php?mode=ria">@ria</a>
        <li><a href="todo.php?mode=list">list items</a>
        <li><a href="todo.php?mode=print">print</a>
        <li><a href="todo.php?mode="></a>
        </ul>
        <br>
        <form name="todo" action="todo.php" method="post">
        <input type="text" size=75 name="input" value="add @buy ">
        <input type="submit" value="Submit">
        </form>
        <hr>
        <?php
        function t_echo($value)
        {
        $num = "";
        $firstspace = strpos($value, " ");
        $length = strlen($value);
        if ($firstspace === false){
        print "$value <br>\n";
        }
        else {
        for($i=0; $i<$firstspace; $i++){
        $num .= $value[$i];
        }
        if (is_numeric($num)){
        echo "<a href=\"todo.php?mode=do&num=$num\">Do $num</a>";
        }
        else {
        echo $num;
        }
        for($i; $i<$length; $i++){
        $line .= $value[$i];
        }

        print "$line <br>\n";
        }

        }
        function main_page($input)
        {
        exec('/home/'.USERNAME.'/bin/todo.sh -p -v -f -d
        /home/'.USERNAME.'/.todo '.escapeshellcmd($input), $output);
        if ($input == '-h') { echo "<pre>"; }
        array_walk($output, 't_echo');
        if ($input == '-h') { echo "</pre>"; }
        }
        function confirm_print()
        {
        echo "Really send grocery list to printer?<br />";
        echo '<a href="todo.php?mode=print&really=yes">Print</a>
        or <a href="todo.php">Cancel</a><br /><br />';
        echo "Or, print groceries with this command: <br> <code>todo
        list @buy | cut -f3- -d\ | lp</code><br><br>";
        }
        function print_groceries()
        {
        exec('/home/'.USERNAME.'/bin/todo.sh -p -v -f -d
        /home/'.USERNAME.'/.todo list @buy | cut -f3- -d\ | lp');

        echo "<meta http-equiv=\"refresh\" content=\"3;url=todo.php\">\n";
        echo "Groceries sent to printer...";
        //exit;
        }
        main_page($input);
        if ( $runonce == false ){
        $input = 'list';
        echo "<br><hr><br>";
        main_page($input);
        }

        ?>
        </body></html>
      • Dan DeLaiarro
        Sounds like a great idea. But, and excuse the newbie-ish type question, how do you get it up and running with minimal PHP experience?
        Message 3 of 4 , Jun 10, 2008
          Sounds like a great idea.

          But, and excuse the newbie-ish type question, how do you get it up and
          running with minimal PHP experience?

          --- In todotxt@yahoogroups.com, "Joshua D. Curry" <joshdcurry@...> wrote:
          >
          > I think that this script is helpful, but it would also be nice if I
          > could maintain one global copy of my todo list that I can edit from
          > anywhere. So, I created a php interface that will interact with a
          > local todo.sh to accomplish this. You could run this on your home
          > computer if you have a webserver running, or if you don't (like me),
          > you just use an automated scp command to copy down the todo.txt files
          > when they change.
          >
          > So far as the php code goes, I coded quickly, but it appears to work
          > without problems. I put in only the essential features b/c I want to
          > be able to access this page using my phone's browser, so I needed to
          > keep the html size down. Still, code focus on the input line and does
          > an automatic refresh when items are added or removed. It also pre
          > formats the -h output so that it's easy to read.
          >
          > Please let me know what you think.
          >
          > <?php
          > $output = null;
          > $input = $_POST['input'];
          > if ($input == '' ) { $input = 'list'; }
          > ?>
          > <html>
          > <head>
          > <?php if ( (strtolower($input) != 'list') && (strtolower($input) !=
          > 'ls') && (strtolower($input) != 'listall') && (strtolower($input) !=
          > 'lsa') && (strtolower($input) != 'listpri') && (strtolower($input) !=
          > 'lsp') && (strtolower($input) != '-h') ) { echo "<meta
          > http-equiv=\"refresh\" content=\"3\">\n"; } ?>
          > <title>USERNAME Todo List</title>
          > </head>
          > <body onload="document.todo.input.focus()">
          > <br />
          > <form name="todo" action="t.php" method="post">
          > <input type="text" size=75 name="input">
          > <input type="submit" value="Submit">
          > </form>
          > <hr />
          > <?php
          >
          > function t_echo($value)
          > {
          > print "$value <br \/>";
          > }
          >
          > exec('/home/USERNAME/bin/todo.sh -p -v -f -d /home/USERNAME/.todo
          > '.escapeshellcmd($input), $output);
          >
          > if ($input == '-h') { echo "<pre>"; }
          > array_walk($output, 't_echo');
          > ?>
          > </body></html>
          >
        • nesman_64
          ... and ... The easiest way to set up a php web server is xampp from http://www.apachefriends.org/ They make it so easy, it s hard to believe. Works in
          Message 4 of 4 , Jun 15, 2008
            --- In todotxt@yahoogroups.com, "Dan DeLaiarro" <dan.delaiarro@...>
            wrote:
            >
            > Sounds like a great idea.
            >
            > But, and excuse the newbie-ish type question, how do you get it up
            and
            > running with minimal PHP experience?
            >

            The easiest way to set up a php web server is xampp from
            http://www.apachefriends.org/
            They make it so easy, it's hard to believe. Works in Windows and
            Linux. I've used it in Linux when the standard Apache install was
            giving me fits. To get the server running, you basically unzip the
            download from their site and run the executable.

            For this script, it assumes you are running Linux, but if needed I
            can probably get it to work with Cygwin or whatever. The only part
            you should have to change to make it run is this line:

            define("USERNAME", "nesman");

            Change the username to match yours, as it is used in the path to
            your home directory. You can check the path with the pwd command.
            Then, have todo.sh installed in a directory named "bin" in your home
            directory.
            On my computer, todo.sh is here:
            /home/nesman/bin/todo.sh

            If you have any troubles after this, feel free to email me or post
            to the list and I'll see if I can sort it.
          Your message has been successfully submitted and would be delivered to recipients shortly.