Пример #1
0
function filterListsToAddTask($query)
{
    global $workflow;
    $responseItems = array();
    $listFilter = '';
    $task = '';
    $queryComponents = explode(':', $query, 2);
    $hasTask = false;
    # Parse the query
    if (count($queryComponents) == 2) {
        $listFilter = $queryComponents[0];
        $task = $queryComponents[1];
        $hasTask = true;
    } else {
        if (count($queryComponents) == 1) {
            $listFilter = $queryComponents[0];
        }
    }
    $listFilter = strtolower($listFilter);
    $allLists = getListInfo();
    $writableLists = array();
    $matchingLists = array();
    $canAutocomplete = !$hasTask;
    # Get list names from Wunderlist in the current locale
    $list_all = 'All';
    $list_assignedToMe = 'Assigned to Me';
    $list_completed = 'Completed';
    $list_week = 'Week';
    $list_inbox = 'Inbox';
    $list_today = 'Today';
    $list_starred = 'Starred';
    # These lists do not allow addition of new tasks
    $readonlyLists = array(strtolower($list_all), strtolower($list_assignedToMe), strtolower($list_completed), strtolower($list_week));
    foreach ($allLists as $listInfo) {
        $listName = strtolower($listInfo['listName']);
        if (!in_array($listName, $readonlyLists)) {
            # If nothing matches the filter we need to have a
            # record of all the lists that accept tasks
            array_push($writableLists, $listInfo);
            if ($listFilter !== '' && strpos($listName, $listFilter) !== false) {
                # The list is an exact match and the user has typed
                # (or autocompleted) the : following the list name,
                # look no further
                if ($hasTask && $listName == $listFilter) {
                    # Show only the matching list and add the task
                    # on return
                    $matchingLists = array($listInfo);
                    $canAutocomplete = false;
                    break;
                } else {
                    array_push($matchingLists, $listInfo);
                }
            }
        }
    }
    # There are no matching lists, so just let the user type a
    # task and select a list later using the arrow keys
    if (count($matchingLists) == 0) {
        $matchingLists = $writableLists;
        # If no text has been entered, allow autocompleting,
        # otherwise the user has begun to type a task. In
        # that case, actioning a list in Alfred should insert
        # the task into the list, not perform autocompletion.
        if ($listFilter !== '') {
            $canAutocomplete = false;
            # The task contained a colon which should not be
            # misinterpreted as filtering the list because
            # we know that no lists matched.
            if ($task !== '') {
                $task = $query;
            }
        }
        # Since autocomplete is disabled, set the first item to
        # the active list.
        $uid = null;
        $arg = $listIndex . '::' . $task;
        $title = 'Most recently used';
        $subtitle = 'Add a task to the most recently used list';
        $icon = 'icon.png';
        $valid = true;
        $autocompletion = null;
        $workflow->result($uid, $arg, $title, $subtitle, $icon, $valid, $autocompletion);
        # If the user did not type a colon the listFilter will
        # contain the text of the task. We know it doesn't match
        # any of the lists so now we can just reassign this.
        if ($task === '') {
            $task = $queryComponents[0];
        }
    }
    # Display all matching lists
    foreach ($matchingLists as $listInfo) {
        $listName = $listInfo['listName'];
        $taskCount = $listInfo['taskCount'];
        $listIndex = $listInfo['listIndex'];
        # Populate data for the result
        # Show 'a task' as a placeholder in 'Add [a task] to this list'
        $uid = null;
        $arg = $listIndex . '::' . $task;
        $title = $listName;
        $subtitle = 'Add ' . ($task ? $task : 'a task') . ' to this list';
        $icon = '/generic.png';
        $valid = true;
        $autocompletion = null;
        # If autocompletion is possible, set isValid to false
        # to enable autocomplete on tab
        if ($canAutocomplete) {
            $valid = true;
            $autocompletion = $listName . ':';
        }
        # Choose the proper icon for each list
        if ($listName == $list_inbox) {
            $icon = '/inbox.png';
        } else {
            if ($listName == $list_today) {
                $icon = '/today.png';
            } else {
                if ($listName == $list_starred) {
                    $icon = '/starred.png';
                }
            }
        }
        # Load the icon based on the configured theme
        $icon = 'lists/light/' . $icon;
        $workflow->result($uid, $arg, $title, $subtitle, $icon, $valid, $autocompletion);
    }
    return $workflow->toxml();
}
Пример #2
0
        echo json_encode($ret);
    } else {
        $ret = array("code" => 1, "data" => "更新错误" . $sqlhelper->sqlerror);
        echo json_encode($ret);
    }
} elseif ($type == "slist") {
    $beg = time();
    $isall = $_POST["isall"];
    $isnorun = $_POST["isnorun"];
    $ruserid = $_POST["ruserid"];
    $users = getUserOnline($userid);
    $recs = null;
    $lists = null;
    dojump($userid);
    // 更新最近发送请求的时间
    $lists = getListInfo($userid, $ruserid);
    // 用户列表,其他用户发送的信息数
    if ($ruserid != -1) {
        $recs = getUserChatLog($userid, $ruserid, $isall);
        // 具体用户信息
    }
    $ret = array("code" => 0, "lists" => $lists, "recs" => $recs, "users" => $users);
    echo json_encode($ret);
    // ." sasdfas";
} elseif ($type = "delFriend") {
    $suserid = $_POST["ruserid"];
    $sql = "delete from usership where userid={$userid} and _userid ={$suserid} ";
    if ($sqlhelper->update($sql)) {
        $ret = array("code" => 0, "data" => "ok");
        echo json_encode($ret);
    } else {
Пример #3
0
function updatePendingRole()
{
    //Update the pending user's role id. Invitations are handled in one database table, so one function can handle both.
    global $debug, $message, $success, $Dbc, $returnThis;
    $output = '';
    try {
        if (empty($_POST['invitationId'])) {
            throw new Adrlist_CustomException('', '$_POST[\'invitationId\'] is empty.');
        } elseif (empty($_POST['type'])) {
            throw new Adrlist_CustomException('', '$_POST[\'type\'] is empty.');
        } elseif (empty($_POST['typeId'])) {
            throw new Adrlist_CustomException('', '$_POST[\'typeId\'] is empty.');
        } elseif (!isset($_POST['newRoleId'])) {
            //The newRoleId may be zero, so check that the value isset rather than empty.
            throw new Adrlist_CustomException('', '$_POST[\'newRoleId\'] is not set.');
        }
        if ($_POST['type'] == 'list') {
            $type = 'list';
            $listInfo = getListInfo($_SESSION['userId'], $_POST['typeId']);
            $role = $listInfo['listRoleId'];
        } else {
            $type = 'folder';
            $folderInfo = getFolderInfo($_SESSION['userId'], $_POST['typeId']);
            $role = $folderInfo['folderRoleId'];
        }
        //Verify the user has a sufficient role to delete invitations.
        if (empty($role) || $role < 3) {
            throw new Adrlist_CustomException('Your role does not allow you to edit this ' . $_POST['type'] . '.', '');
        }
        //Update the roleId.
        $stmt = $Dbc->prepare("UPDATE\n\tinvitations\nSET\n\t{$type}RoleId = ?\nWHERE\n\tinvitationId = ?\nLIMIT 1");
        $params = array($_POST['newRoleId'], $_POST['invitationId']);
        $stmt->execute($params);
        $rowCount = $stmt->rowCount();
        if (empty($rowCount)) {
            pdoError(__LINE__, $stmt, $params, true);
        }
        //Get the id of the folder or list to pass to the buildUser functions.
        $getIdQuery = $Dbc->prepare("SELECT\n\t{$type}Id AS '{$type}Id'\nFROM\n\tinvitations\nWHERE\n\tinvitationId = ?");
        $getIdQuery->execute(array($_POST['invitationId']));
        $row = $getIdQuery->fetch(PDO::FETCH_ASSOC);
        if ($type == 'folder') {
            $_POST['folderId'] = $row['folderId'];
            //We will not update user's role id for all of the folder's lists. That occurs when the pending user creates an account.
            $returnThis['buildUsers'] = buildFolderUsers();
        } else {
            $_POST['listId'] = $row['listId'];
            $returnThis['buildUsers'] = buildListUsers();
        }
        if (MODE == 'updatePendingRole') {
            $success = true;
            $message .= 'Updated';
        }
    } catch (Adrlist_CustomException $e) {
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
    if (MODE == 'updatePendingRole') {
        returnData();
    }
}