#!/usr/bin/env php */ if (file_exists(__DIR__ . '/../../mnemo/lib/Application.php')) { $baseDir = __DIR__ . '/../'; } else { require_once 'PEAR/Config.php'; $baseDir = PEAR_Config::singleton() ->get('horde_dir', null, 'pear.horde.org') . '/mnemo/'; } require_once $baseDir . 'lib/Application.php'; Horde_Registry::appInit('mnemo', array('cli' => true)); // Read command line parameters. if (count($argv) != 4) { $cli->message('Too many or too few parameters.', 'cli.error'); usage(); } $notepad = $argv[1]; $user = $argv[2]; $file = $argv[3]; // Read standard input. if (!file_exists($file)) { $cli>message("$file does not exist", 'cli.error'); usage(); } $data = file_get_contents($file); if (empty($data)) { $cli->message('No import data provided.', 'cli.error'); usage(); } $data = pathinfo($file, PATHINFO_FILENAME) . "\n\n" . $data; // Set user. $registry->setAuth($user, array()); // Import data. try { $result = $registry->notes->import($data, 'text/plain', $notepad); $cli->message('Imported successfully ' . count($result) . ' notes', 'cli.success'); } catch (Mnemo_Exception $e) { $cli->fatal($e->getMessage()); } function usage() { $GLOBALS['cli']->writeln('Usage: mnemo-import-text-note notepad user file'); exit; }