Example #1
0
} elseif ($route->match('api-modules-installed', null)) {
    // Prepare and sanitize post input
    $api->setInputs($_POST);
    $module = $model->moduleFind(array('id' => $api->getInputVal('id')));
    if (!$module) {
        $response->status = 404;
        $response->message = 'Not found';
        $response->json($response);
    }
    $input = array('installed' => (int) $module->installed + 1);
    $model->moduleUpdate($input, array('id' => $api->getInputVal('id')));
    $response->json($response);
} elseif ($route->match('api-comments-create', null)) {
    // Prepare and sanitize post input
    $api->setInputs($_POST);
    if (!$model->commentCreate($api->getInputs())) {
        $response->status = 500;
        $response->message = 'Unable to add a comment';
        $response->json($response);
    }
    if ($api->getInputVal('type') != 1 && ($module = $model->moduleFindJoin(array('m.id' => $api->getInputVal('module_id'))))) {
        $email = array('from' => '*****@*****.**', 'from_name' => $api->getInputVal('name'), 'to' => $module->mail, 'subject' => $module->title . ' - new comment', 'body' => $api->getInputVal('content'));
        $api->sendEmail($email);
    }
    $input['id'] = $db->inserId();
    $response->data = $input;
    $response->json($response);
} elseif ($route->match('api-comments', 1)) {
    // Prepare and sanitize post input
    $api->setInputs(array('module_id' => $route->getParam(0)));
    $response->data = $model->commentsAll($api->getInputs());