/** * Access the entry/page data when its published * * @param array $publish_data * @return void */ public function control_panel__post_publish($publish_data) { // master switch for revisions if (!$this->core->isEnabled()) { return; } // The hook sends an array of info, we just need the data key $publish_data = $publish_data['data']; // Get content of existing file and of what is about to be saved $path = Path::tidy('/' . $publish_data['file']); $file_content = File::buildContent($publish_data['yaml'], $publish_data['content']); // Generate the commit message $msg_prefix = Config::get('_revisions_message_prefix', '') . ' '; $msg = ($msg = Request::post('revisions__commit_message')) ? $msg : __('published_on') . " " . Date::format(Config::getDateFormat()); $full_msg = trim($msg_prefix . $msg); // Strip off the content root $pattern = '/^\\/' . Config::getContentRoot() . '\\//'; $path = preg_replace($pattern, '', $path); $this->core->saveRevision($path, $file_content, $full_msg, null, $publish_data['new']); }
/** * Saves this member's profile data to file * * @todo some checks are needed to make sure things are allowed * @return void */ public function save() { // ensure UID $this->ensureUID(false); // set up variables $data = $this->data; $content = $this->get('biography_raw'); $file = Config::getConfigPath() . '/users/' . $this->username . '.yaml'; // biography is content, we don't need them in the data array if (isset($data['biography_raw'])) { unset($data['biography_raw']); } if (isset($data['biography'])) { unset($data['biography']); } // if username is set, we don't need that either if (isset($data['username'])) { unset($data['username']); } File::put($file, File::buildContent($data, $content)); }
|-------------------------------------------------------------------------- | | Set up an array of useful data for the hook and then run that sucker. | */ $publish_data = array('yaml' => $file_data, 'content' => $form_data['content'], 'file' => $file); $publish_data = Hook::run('control_panel', 'publish', 'replace', $publish_data, $publish_data); /* |-------------------------------------------------------------------------- | Build and write content |-------------------------------------------------------------------------- | | Let's create or update this file. | */ $file_content = File::buildContent($publish_data['yaml'], $publish_data['content']); File::put(Path::assemble(BASE_PATH, $file), $file_content); /* |-------------------------------------------------------------------------- | Rename/move file |-------------------------------------------------------------------------- | | If the slug changed we'll need to rename the file accordingly. | */ if (!isset($form_data['new'])) { $new_slug = $form_data['meta']['slug'] === '/' ? '/' : Slug::make($form_data['meta']['slug']); // Date Entry if ($form_data['type'] == 'date') { // With Timestamps if (Config::getEntryTimestamps()) {
private function completeEdit($submission, $config, $entry) { $content_set = ContentService::getContentByURL(Helper::decrypt($entry))->extract(); // Bail if the content doesn't exist. Someone tweaked it. Tsk tsk. if (!count($content_set)) { return; } // Get front-matter from existing submission $content = current($content_set); $yaml = YAML::parseFile($content['_file']); // MERGE!@#! $submission = array_merge($yaml, $submission); // Update the entry $file_content = File::buildContent($submission, ''); File::put($content['_file'], $file_content); // Shall we send? if (array_get($config, 'send_notification_email', false) === true) { $this->sendEmails($submission, $config, 'update'); } // Save data to flash for use in raven:submission $this->flash->set('submission', $submission); }
public function save() { $user_account = (array) $this->data; $content = $user_account['biography_raw']; unset($user_account['biography']); unset($user_account['biography_raw']); $file_path = "_config/users/{$this->name}.yaml"; File::put($file_path, File::buildContent($user_account, $content)); }
/** * build_file_content * Creates a file content from $data_array and $content * * @deprecated Use File::buildContent() instead * * @param array $data_array Data to load into the file's front-matter * @param string $content Content to append to the file * @return string */ public static function build_file_content($data_array, $content) { Log::warn("Use of Statamic_Helper::build_file_content() is deprecated. Use File::buildContent() instead.", "core", "Statamic_Helper"); return File::buildContent($data_array, $content); }
} } foreach ($form_data['yaml'] as $field => $value) { if (isset($field_settings[$field]['type']) && $field_settings[$field]['type'] != 'file') { $file_data[$field] = Fieldtype::process_field_data($field_settings[$field]['type'], $value, $field_settings[$field], $field); } else { $file_data[$field] = $value; } } unset($file_data['content']); unset($file_data['content_raw']); unset($file_data['last_modified']); if (isset($file_data['status'])) { unset($file_data['status']); } $file_content = File::buildContent($file_data, $form_data['content']); File::put($file, $file_content); // Do we need to rename the file? if (!isset($form_data['new'])) { $new_slug = $form_data['meta']['slug'] === '/' ? '/' : Slug::make($form_data['meta']['slug']); if ($form_data['type'] == 'date') { if (Config::getEntryTimestamps()) { $new_timestamp = $form_data['meta']['publish-time']; $new_datestamp = $form_data['meta']['publish-date']; $new_file = $content_root . "/" . dirname($path) . "/" . $status_prefix . $new_datestamp . "-" . $new_timestamp . "-" . $new_slug . "." . $content_type; } else { $new_datestamp = $form_data['meta']['publish-date']; $new_file = $content_root . "/" . dirname($path) . "/" . $status_prefix . $new_datestamp . "-" . $new_slug . "." . $content_type; } } elseif ($form_data['type'] == 'number') { $new_numeric = $form_data['meta']['publish-numeric'];