Ejemplo n.º 1
0
 function buildDataFile($files)
 {
     foreach ($files as $file) {
         $fileData = file_get_contents('../' . $file, true);
         $html = str_get_html($fileData);
         foreach ($html->find('.auto-rss-link') as $rssFeed) {
             $settingsData = new SettingsData();
             $this->data['rss'] = array('rss' => $settingsData->getHost() . "feed/", 'type' => 'rss');
             $rssFeed->href = "<?=get('{$this->dataFile}', 'rss')?>";
         }
         $fp = fopen('../' . $file, 'w');
         fwrite($fp, $html);
         fclose($fp);
     }
     if ($this->hasFeed()) {
         $this->copyFeed();
     }
 }
Ejemplo n.º 2
0
 public function updateBlogPost($post_id, $data, $publish = false)
 {
     $dataFile = $this->blogDataLocation . 'blog-' . $post_id . '.json';
     $changeLog = array();
     $isNew = false;
     $updateTime = time();
     $creationTime = time();
     if (file_exists($dataFile)) {
         $json = json_decode(file_get_contents($dataFile), true);
     } else {
         $isNew = true;
         $json = array('title' => null, 'keywords' => null, 'description' => null, 'author' => null, 'image' => null, 'image-alt-text' => null, 'short-blog' => null, 'full-blog' => null, 'link-text' => null, 'link-href' => null);
     }
     foreach ($data as $key => $datum) {
         if (DashboardUtils::endsWith($key, '-loaded') && trim($datum) != '') {
             $key = str_replace('-loaded', '', $key);
         }
         if ($key != 'save' && $key != 'publish') {
             $changeLog[] = array('key' => $key, 'change' => array('original' => $json[$key], 'new' => trim($datum)));
             $json[$key] = trim($datum);
         }
     }
     $json['published'] = $updateTime;
     $logsData = new LogsData();
     if (count($changeLog) > 0 && !$isNew) {
         $logsData->addToLog('has updated', $data['title'] . ' blog', $changeLog);
     } else {
         if (count($changeLog) > 0 && $isNew) {
             $logsData->addToLog('has created', $data['title'] . ' blog', $changeLog);
         }
     }
     $externalTitle = preg_replace('/[^a-z0-9-]/i', '', str_replace(' ', '-', strtolower(trim($json['title']))));
     if ($isNew || isset($this->data['posts'][$post_id]['external']) && $this->data['posts'][$post_id]['external'] != $externalTitle) {
         $externalTitleOriginal = $externalTitle;
         $count = 0;
         foreach ($this->data['posts'] as $key => $data) {
             while ($data['external'] == $externalTitle) {
                 $externalTitle = $externalTitleOriginal . '-' . $count++;
             }
         }
         if ($isNew) {
             $this->data['posts'][$post_id] = array('external' => $externalTitle, 'title' => $json['title'], 'creator' => $_SESSION["user"], 'created' => $creationTime);
         } else {
             $this->data['posts'][$post_id]['title'] = $json['title'];
             $this->data['posts'][$post_id]['external'] = $externalTitle;
             $this->data['posts'][$post_id]['last-updated'] = $updateTime;
         }
     } else {
         $this->data['posts'][$post_id]['last-updated'] = $updateTime;
     }
     if ($publish) {
         $this->data['posts'][$post_id]['published'] = $updateTime;
     }
     $settingsData = new SettingsData();
     $postPage = $this->data['post-page'];
     $json['link-href'] = $settingsData->getHost() . $postPage . '/' . $externalTitle . '/';
     $fp = fopen($dataFile, 'w');
     fwrite($fp, json_encode($json));
     fclose($fp);
     DashboardUtils::createXMLSitemap();
 }