Example #1
0
 /**
  * Set variables for blog display
  *
  */
 public static function Init()
 {
     global $addonPathData;
     if (isset(self::$data)) {
         return;
     }
     self::$data_dir = $addonPathData;
     self::$index_file = self::$data_dir . '/index.php';
     self::$root_url = 'Special_Blog';
     if (is_callable(array('common', 'SpecialHref'))) {
         self::$root_url = common::SpecialHref('Special_Blog');
     }
     self::GetBlogData();
     self::AddCSS();
     //regenerate if there are pending posts that need to be published
     if (!is_null(SimpleBlogCommon::$data['next_regen']) && SimpleBlogCommon::$data['next_regen'] < time()) {
         if (@gpFiles::WriteLock()) {
             self::GenStaticContent();
             SimpleBlogCommon::NextGenTime();
             SimpleBlogCommon::SaveIndex();
             gpFiles::Unlock('write', gp_random);
         }
     }
 }
Example #2
0
 /**
  * Save the post
  *
  */
 public static function SavePost($post_id, $post)
 {
     global $langmessage;
     $_POST += array('title' => '', 'content' => '', 'subtitle' => '', 'isDraft' => '', 'category' => array());
     $title = htmlspecialchars($_POST['title']);
     $title = trim($title);
     if (empty($title)) {
         message($langmessage['TITLE_REQUIRED']);
         return false;
     }
     self::GetPostedTime();
     //different time
     //organize posts based on publish time
     SimpleBlogCommon::AStrSet('post_times', $post_id, $_POST['time']);
     $post_times = SimpleBlogCommon::AStrToArray('post_times');
     arsort($post_times);
     $str_index = array_keys($post_times);
     SimpleBlogCommon::$data['str_index'] = SimpleBlogCommon::AStrFromArray($str_index);
     //get next static gen time
     SimpleBlogCommon::NextGenTime();
     //create post array
     $post['title'] = $title;
     $post['content'] = $_POST['content'];
     $post['subtitle'] = htmlspecialchars($_POST['subtitle']);
     $post['categories'] = $_POST['category'];
     $post['time'] = $_POST['time'];
     unset($post['isDraft']);
     //save to data file
     if (!parent::SavePost($post_id, $post)) {
         return false;
     }
     //draft
     if ($_POST['isDraft'] === 'on') {
         SimpleBlogCommon::AStrSet('drafts', $post_id, 1);
     } else {
         SimpleBlogCommon::AStrRm('drafts', $post_id);
     }
     SimpleBlogCommon::AStrSet('titles', $post_id, $title);
     self::UpdatePostCategories($post_id);
     //find and update the edited post in categories and archives
     if (!SimpleBlogCommon::SaveIndex()) {
         message($langmessage['OOPS'] . ' (Index not saved)');
         return false;
     }
     SimpleBlogCommon::GenStaticContent();
     message($langmessage['SAVED']);
     return true;
 }