Beispiel #1
0
 function update_page($page, $prevpage)
 {
     $file_content = "";
     // we don't want to save parent data
     $parent = $page['parent'];
     unset($page['parent']);
     // set content
     foreach ($page as $key => $value) {
         if ($value) {
             $value = replace_pusaka_brackets($value);
             if ($key == 'slug') {
                 $file_content .= "{: " . $key . " :} " . strtolower(url_title($value)) . "\n";
             } else {
                 $file_content .= "{: " . $key . " :} " . $value . "\n";
             }
         }
     }
     // move page
     $this->pusaka->move_page($prevpage['slug'], $page['slug'], $prevpage['parent'], $parent);
     if (!file_exists(PAGE_FOLDER . $parent . '/' . $page['slug'] . '.md')) {
         $page['slug'] .= '/index';
     }
     // update page content
     if (write_file(PAGE_FOLDER . $parent . '/' . $page['slug'] . '.md', $file_content, 'w+')) {
         $this->pusaka->sync_page();
         return true;
     } else {
         return false;
     }
 }
Beispiel #2
0
 function edit()
 {
     $prevname = $this->uri->segment(4);
     if (!isset($prevname)) {
         show_404();
     }
     $prevpost = $this->pusaka->get_post($prevname, false, false, true);
     $prevpost['labels'] = !empty($prevpost['labels']) ? implode(",", $prevpost['labels']) : '';
     $prevpost['slug'] = isset($prevpost['slug']) ? $prevpost['slug'] : $prevname;
     $this->form_validation->set_rules($this->post_fields);
     if ($this->form_validation->run()) {
         $post = $this->input->post();
         $file_content = "{: author :} ";
         $file_content .= isset($prevpost['author']) ? $prevpost['author'] : $this->session->userdata('username');
         $file_content .= "\n";
         // set content
         foreach ($post as $key => $value) {
             if ($value) {
                 $value = replace_pusaka_brackets($value);
                 if ($key == 'slug') {
                     $file_content .= "{: " . $key . " :} " . strtolower(url_title($value)) . "\n";
                 } else {
                     $file_content .= "{: " . $key . " :} " . $value . "\n";
                 }
             }
         }
         $date = date("Y-m-d-H-i", strtotime($prevpost['date'])) . '-';
         $redir_date = date("Y/m/d/", strtotime($prevpost['date']));
         // rename post first
         if ($prevpost['slug'] != $post['slug']) {
             rename(POST_FOLDER . $date . $prevpost['slug'] . '.md', POST_FOLDER . $date . $post['slug'] . '.md');
         }
         if (write_file(POST_FOLDER . $date . $post['slug'] . '.md', $file_content)) {
             $this->session->set_flashdata('success', 'Post updated.');
             // call event after_update
             $post['filename'] = $date . $post['slug'] . '.md';
             $postmeta = $this->pusaka->create_post_attributes($post['filename']);
             $post = array_merge($post, $postmeta);
             $this->call_event('Posts', 'after_update', $date . $prevpost['slug'] . '.md', $post);
             // update post index
             $this->sync(false);
             if ($this->input->post('btnSaveExit')) {
                 redirect('panel/posts');
             } else {
                 redirect('panel/posts/edit/' . $date . $post['slug'] . '.md');
             }
         } else {
             $this->template->set('error', 'Post failed to update. Make sure the folder ' . POST_FOLDER . ' is writable.');
         }
     }
     $this->template->enable_parser_body(false)->set('type', 'edit')->set('filename', $prevname)->set('post', $prevpost)->set('layouts', $this->pusaka->get_layouts($this->config->item('theme')))->view('post_form');
 }