if (strlen(trim($post['entry_excerpt'])) == 0) {
        $data->entry_excerpt = substr(strip_tags($post['entry_text']), 0, 500) . "...";
    } else {
        $data->entry_excerpt = $post['entry_excerpt'];
    }
    $PAGE->set_title($post['title'] . " - " . $PAGE->course->fullname);
    $PAGE->set_heading($post['title'] . " - " . $PAGE->course->fullname);
    $data->header = $OUTPUT->header();
    $data->footer = $OUTPUT->footer();
    echo $OUTPUT->render_from_template('local_courseblog/post', $data);
} else {
    $PAGE->set_heading($data->blogtitle);
    if ($category == false) {
        $all_posts = local_courseblog_get_entires();
    } else {
        $all_posts = local_courseblog_get_entires(array($category));
    }
    if ($category != false) {
        $PAGE->navbar->add($categories[$category]['category'], new moodle_url('/local/courseblog/view.php', array('category' => $category)), global_navigation::TYPE_CUSTOM);
        $data->category = $category;
    }
    $post_output = array();
    $excerpts = optional_param('excerpts', 0, PARAM_INT);
    $i = 0;
    foreach ($all_posts as $post) {
        $post_output[$i]['id'] = $post['id'];
        $post_output[$i]['title'] = $post['title'];
        if ($excerpts == 1) {
            if (strlen(trim($post['entry_excerpt'])) == 0) {
                $post_output[$i]['content'] = substr(strip_tags($post['entry_text']), 0, 500) . "...";
            } else {
$PAGE->set_heading($SITE->fullname);
//page layout
$PAGE->set_pagelayout('admin');
//breadcrumbs
//actions list
$actionIndex = 'index';
$actionAdd = 'add';
$actionEdit = 'edit';
$actionDelete = 'delete';
$action = optional_param('action', 0, PARAM_TEXT);
$action = !empty($action) ? $action : 'index';
switch ($action) {
    case $actionIndex:
        $data = new stdClass();
        $data->url = new moodle_url($returnurl);
        $entries = local_courseblog_get_entires();
        $entries = array_values($entries);
        $categories = $DB->get_records_menu('local_courseblog_categories');
        if (count($entries) > 0) {
            foreach ($entries as $key => $elem) {
                foreach ($elem['categories'] as $k => $c) {
                    $entries[$key]['categories'][$k] = $categories[$c];
                }
                $entries[$key]['categories'] = implode(", ", $entries[$key]['categories']);
                $entries[$key]['date'] = date("m/d/Y", $elem['post_date']);
            }
            $data->hasentries = true;
        }
        $data->entries = $entries;
        $data->sesskey = sesskey();
        $data->wwwroot = $CFG->wwwroot;