Example #1
0
 public function testNextPrev()
 {
     $params = array('title' => 'this is my test next prev post', 'content_type' => 'post', 'is_active' => 1);
     //saving
     $save_post1 = save_content($params);
     $save_post2 = save_content($params);
     $save_post3 = save_content($params);
     //getting
     $next = next_content($save_post1);
     $prev = prev_content($save_post2);
     $this->assertEquals($save_post2, $next['id']);
     $this->assertEquals($save_post1, $prev['id']);
     $next = next_content($save_post2);
     $prev = prev_content($save_post3);
     $this->assertEquals($save_post3, $next['id']);
     $this->assertEquals($save_post2, $prev['id']);
     $del1 = delete_content($save_post1);
     $del2 = delete_content($save_post2);
     $del3 = delete_content($save_post3);
     //PHPUnit
     $this->assertEquals(true, is_array($del1));
     $this->assertEquals(true, is_array($del2));
     $this->assertEquals(true, is_array($del3));
     $this->assertEquals(true, is_array($next));
 }
/**
 * Delete post completely from the system
 * @param int $post_id pass the post id as an integer
 * @return bool true on success, false on fail
 */
function delete_post($post_id)
{
    $output = false;
    $i = 0;
    if (post_exist((int) $post_id)) {
        $posts_list = get_json_content(CONTENTPATH . 'content.json');
        $posts =& $posts_list['posts'];
        while ($i < count($posts)) {
            if ($posts[$i]['id'] === (int) $post_id) {
                if (delete_content($posts[$i]['content'])) {
                    unset($posts[$i]);
                    $posts = array_values($posts);
                    if (write_to_json(CONTENTPATH . 'content.json', $posts_list)) {
                        $output = true;
                    }
                }
                break;
            }
            $i++;
        }
    }
    return $output;
}
    $content = isset($_POST['content']) ? $_POST['content'] : NULL;
    $keyword = isset($_POST['keyword']) ? $_POST['keyword'] : NULL;
    $deskripsi = isset($_POST['deskripsi']) ? $_POST['deskripsi'] : NULL;
    $status = isset($_POST['status']) ? $_POST['status'] : NULL;
    if ($status == "lama") {
        $response = update_content($kode_content, $judul_content, $kode_kategori, $penulis, $content, $keyword, $deskripsi);
        if ($response == 1) {
            header('location:index.php?page=content&message=2');
        } else {
            header('location:index.php?page=content&message=0');
        }
    } else {
        $response = insert_content($judul_content, $kode_kategori, $penulis, $content, $keyword, $deskripsi);
        if ($response == 1) {
            header('location:index.php?page=content&message=1');
        } else {
            header('location:index.php?page=content&message=0');
        }
    }
} else {
    if (isset($_GET['action'])) {
        if ($_GET['action'] == "delete") {
            $response = delete_content($_GET['kode']);
            if ($response == 1) {
                header('location:index.php?page=content&message=3');
            } else {
                header('location:index.php?page=content&message=0');
            }
        }
    }
}
Example #4
0
             page_fail(BAD_REQUEST);
         }
     }
 } else {
     if (array_key_exists('delete', $_POST) && array_key_exists('type', $_POST)) {
         // delete content (single entity)
         if ($_POST['type'] != 'file' && $_POST['type'] != 'comment') {
             page_fail(BAD_REQUEST);
         }
         // verify that the user can access the entity
         $kind = $_POST['type'] == 'file' ? 'file_upload' : 'user_comment';
         if (!abet_is_admin_authenticated() && !check_general_content_item_access($_SESSION['id'], $_POST['delete'], $kind, $found)) {
             page_fail($found ? UNAUTHORIZED : NOT_FOUND);
         }
         // delete the specified entity
         echo delete_content($_POST['delete'], $kind);
     } else {
         if (array_key_exists('id', $_POST)) {
             // update content (single entity)
             if (array_key_exists('file_comment', $_POST)) {
                 $kind = 'file_upload';
             } else {
                 if (array_key_exists('content', $_POST)) {
                     $kind = 'user_comment';
                 } else {
                     page_fail(BAD_REQUEST);
                 }
             }
             // verify that the user can access the entity
             if (!abet_is_admin_authenticated() && !check_general_content_item_access($_SESSION['id'], $_POST['id'], $kind, $found)) {
                 page_fail($found ? UNAUTHORIZED : NOT_FOUND);