/**
  * Adds a new task into the curent taskpaper.
  *
  * This is used when adding new tasks from the input box.
  *
  * @param string $new_task      The new task as text, as typed by the user, can include notes, and a project identifier ('/2')
  * @param int    $project_index The project index (not number!) into which to insert
  * @return boolean  True on success
  */
 function add($new_task, $project_index = 0)
 {
     $max = self::$_content->project_count - 1;
     $project_index = $project_index > $max ? $max : $project_index;
     $at_top = \tpp\ini('insert_pos') == 'top';
     // edge case: insert at end of list only 1 project exists
     if ($max == 0 && !$at_top) {
         $raw = $this->raw() . "\n" . $new_task;
         self::update(UPDATE_RAW, $raw);
         return true;
         // edge case: at top of orphan project (0)
     } elseif ($project_index == 0 && $at_top) {
         $this->replace('010', $new_task);
         return true;
         // or insert into a specific Project
     } elseif ($project_index >= 0 && $project_index < $max) {
         $offset = $at_top ? 0 : 1;
         $key = array_search($project_index + $offset, self::$_content->project_index);
         $this->replace($key, $new_task);
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
define('RES_NO_SPACE', 2);
define('RES_NO_SUCH_KEY', 3);
// Regex patterns, terms and symbols used globally in app
require_once APP_PATH . 'conf/term.php';
// Basic app functions: config() lang(), ini(), + general functions
require_once APP_PATH . 'inc/common.php';
// Confirm that necessary data folders exist
define('DATA_DIR', getdir_or(ini('taskpaper_folder'), config('data_dir')));
define('DELETED_DIR', getdir_or(config('deleted_dir')));
define('CACHE_DIR', getdir_or(config('cache_dir')));
// Load global language array from existing config file names
$langs = glob('./conf/lang_*');
foreach ($langs as $lang) {
    $config['lang_list'][] = substr($lang, 12, -4);
}
$cur_lang = \tpp\ini('language');
$lang_path = 'conf/lang_' . $cur_lang . '.php';
$lang_en_path = 'conf/lang_en.php';
// default english lang strings (in case of missing items or language)
$lang = array();
require_once APP_PATH . $lang_en_path;
if (file_exists($lang_path)) {
    require_once APP_PATH . $lang_path;
}
// this ensures that dates will be localised also
// locale names must match PHP standards: see conf/locale_names.txt
$location = setlocale(LC_ALL, $cur_lang);
DEFINE('LOCATION', $location);
// used in TaskItem
define('MAX_ACTION', count(\tpp\lang('state_order')) - 2);
// set correct locale settings (timezone must be set first)