public function getHost() { if (!DashboardUtils::endsWith($this->data['site-host']['text'], '/')) { $this->data['site-host']['text'] .= '/'; } return $this->data['site-host']['text']; }
public static function scanFiles($endsWith) { $files = scandir('../'); $arr = array(); foreach ($files as $file) { if (DashboardUtils::endsWith($file, $endsWith)) { $arr[] = $file; } } return $arr; }
public static function updatePage($file, $data) { $dataFile = 'data/page-' . $file . '.json'; $json = json_decode(file_get_contents($dataFile), true); $changeLog = array(); foreach ($data as $key => $datum) { if (DashboardUtils::endsWith($key, '-loaded') && trim($datum) != '') { $key = str_replace('-loaded', '', $key); } if ($key != 'key' && isset($json[$key]) && $json[$key][$json[$key]['type']] != trim($datum)) { $changeLog[] = array('key' => $key, 'change' => array('original' => $json[$key][$json[$key]['type']], 'new' => trim($datum))); $json[$key][$json[$key]['type']] = trim($datum); } else { list($repeatKey, $iteration, $itemKey) = explode("-", $key); if (isset($json[$repeatKey]['repeat'][$iteration][$itemKey]) && $json[$repeatKey]['repeat'][$iteration][$itemKey][$json[$repeatKey]['repeat'][$iteration][$itemKey]['type']] != trim($datum)) { $changeLog[] = array('key' => $key, 'change' => array('original' => $json[$repeatKey]['repeat'][$iteration][$itemKey][$json[$repeatKey]['repeat'][$iteration][$itemKey]['type']], 'new' => trim($datum))); $json[$repeatKey]['repeat'][$iteration][$itemKey][$json[$repeatKey]['repeat'][$iteration][$itemKey]['type']] = trim($datum); } } } if (count($changeLog) > 0) { $logsData = new LogsData(); $logsData->addToLog('has updated', $file . ' page', $changeLog); } $fp = fopen($dataFile, 'w'); fwrite($fp, json_encode($json)); fclose($fp); }
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(); }