public function getThemeSettings()
 {
     $path = $this->getThemeSettingsPath();
     $yaml = YAML::parseFile($path);
     return $yaml;
 }
Exemplo n.º 2
0
    // mark milestone for debug panel
    Debug::markMilestone('status determined');

    // find next/previous
    if ($add_prev_next && $visible) {
        $folder = substr(preg_replace(Pattern::ORDER_KEY, "", substr($path, 0, (-1*strlen($page))-1)), 1);

        $relative     = Statamic::find_relative($current_url, $folder);
        $data['prev'] = $relative['prev'];
        $data['next'] = $relative['next'];
    }

    // grab data for this folder
    $folder_data = Content::get(Path::tidy('/' . Config::getSiteRoot() . '/' . dirname($current_url)));

    $fields_data = YAML::parseFile(Path::tidy(BASE_PATH . "/" . Config::getContentRoot() . dirname($current_url) . '/fields.yaml'));

    // Check for fallback template
    if ($content_found && empty($data['_template'])) {
        // check fields.yaml first
        if (array_get($fields_data, '_default_folder_template')) {
            $data['_template'] = $fields_data['_default_folder_template'];
        // fall back to the folder's page.md file
        } elseif (array_get($folder_data, '_default_folder_template')) {
            $data['_template'] = $folder_data['_default_folder_template'];
        }
    }

    // set template and layout
    if (isset($data['_template'])) {
        $template_list[] = $data['_template'];
Exemplo n.º 3
0
 /**
  * Loads data from a given path from either the folder-data cache or from the filesystem
  * 
  * @param string  $path  File path to look up
  * @return array
  */
 protected function loadFolderData($path)
 {
     if (isset($this->folder_data[$path])) {
         return $this->folder_data[$path];
     } elseif (File::exists($path . '/folder.yaml')) {
         $folder = YAML::parseFile($path . '/folder.yaml');
         $this->folder_data[$path] = $folder;
         return $folder;
     } else {
         return array();
     }
 }
Exemplo n.º 4
0
 /**
  * Loads a given config file for this add-on
  * 
  * @param string  $path  Path to load relative to this add-on's config directory
  * @param boolean  $log_error  Write an error message on fail?
  * @param boolean  $throw_exception  Throw an exception on fail?
  * @return array
  * @throws Exception
  */
 public function loadConfigFile($path, $log_error=false, $throw_exception=false)
 {
     $path = trim($path);
     $path .= (preg_match('/\.y[a]?ml$/i', $path, $matches)) ? '' : '.yaml';
     
     $full_path = $this->getConfigPath() . $path;
     
     if (!File::exists($full_path)) {
         if ($log_error) {
             $this->log->debug("Could not load config `" . $path . "`, file does not exist.");
         }
         
         if ($throw_exception) {
             throw new Exception("Could not load config `" . $path . "`, file does not exist.");
         }
         
         return array();
     }
     
     return YAML::parseFile($full_path);
 }
Exemplo n.º 5
0
 /**
  * Loads the data file and merges all configs together
  *
  * @param string  $dataset  Dataset to attempt to load
  * @param array  $parameters  Parameters that were called on the plugin
  * @return array
  */
 public function loadDataset($dataset, $parameters = array())
 {
     // remove null values from parameters
     foreach ($parameters as $key => $value) {
         if (is_null($value)) {
             unset($parameters[$key]);
         }
     }
     // set some defaults if nothing is set
     $default_values = array('use_stemming' => false, 'use_alternates' => false, 'stop_words' => array('the', 'a', 'an'), 'query_cache_length' => 30, 'log_successful_searches' => true, 'log_failed_searches' => true, 'folders' => URL::getCurrent(), 'taxonomy' => false, 'show_hidden' => false, 'show_drafts' => false, 'show_future' => false, 'show_past' => true, 'type' => 'all', 'limit' => 10, 'offset' => 0, 'paginate' => true, 'query_variable' => 'query', 'include_content' => true, 'include_404' => false);
     // a complete list of all possible config variables
     $config = array('match_weights' => null, 'min_characters' => null, 'min_word_characters' => null, 'score_threshold' => null, 'property_weights' => null, 'query_mode' => null, 'use_stemming' => null, 'use_alternates' => null, 'include_full_query' => null, 'enable_too_many_results' => null, 'sort_by_score' => null, 'exclude_properties' => null, 'include_properties' => null, 'stop_words' => null, 'log_successful_searches' => null, 'log_failed_searches' => null, 'query_cache_length' => null, 'folders' => null, 'taxonomy' => null, 'show_hidden' => null, 'show_drafts' => null, 'since' => null, 'until' => null, 'show_future' => null, 'show_past' => null, 'type' => null, 'conditions' => null, 'limit' => null, 'page_limit' => null, 'offset' => null, 'paginate' => null, 'query_variable' => null, 'include_content' => null, 'include_404' => null, 'exclude' => null, 'query' => null);
     $loaded_config = array();
     if ($dataset) {
         $dataset_file = $file = Config::getConfigPath() . '/add-ons/' . $this->addon_name . '/datasets/' . $dataset . '.yaml';
         if (File::exists($dataset_file)) {
             $loaded_config = YAML::parseFile($dataset_file);
         } else {
             $this->log->error("Could not use dataset `" . $dataset . "`, YAML file does not exist.");
         }
     }
     // load global config
     $global_config = Helper::pick($this->getConfig(), array());
     // merge config variables in order
     $all_config = array_merge($config, $default_values, $global_config, $loaded_config, $parameters);
     // get query
     if (!isset($parameters['query']) && is_null($all_config['query']) && $all_config['query_variable']) {
         $new_query = filter_input(INPUT_GET, $all_config['query_variable']);
         $all_config['query'] = $new_query;
     }
     // always add content to exclude properties, don't worry, content_raw will take care of it
     if (is_array($all_config['exclude_properties'])) {
         $all_config['exclude_properties'] = array_unique(array_merge($all_config['exclude_properties'], array('content')));
     } else {
         $all_config['exclude_properties'] = array('content');
     }
     return $all_config;
 }
Exemplo n.º 6
0
 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);
 }
 /**
  * Merge all configs
  * @param string  $destination Paramter for destination YAML file to attempt to load.
  * @param string  $return_type Set the return type
  * @return array
  */
 public function merge_configs($destination = null, $respons_type = 'json')
 {
     // Set environment
     $this->env = $env = FILECLERK_ENV;
     // Error(s) holder
     $errors = false;
     // Check for a destination config
     $destination = is_null($destination) ? Request::get('destination') : $destination;
     // A complete list of all possible config variables
     $config = array('aws_access_key' => null, 'aws_secret_key' => null, 'custom_domain' => null, 'bucket' => null, 'directory' => null, 'permissions' => CannedAcl::PUBLIC_READ, 'content_types' => false);
     // Requried config values
     $required_config = array('aws_access_key', 'aws_secret_key');
     // Destination config values that even if null should override master config.
     $allow_override = array('custom_domain', 'directory', 'content_types');
     // Destination config array
     $destination_config = array();
     // Check that the destination config file exists
     if (!is_null($destination) || $destination !== 0 || $destination) {
         // Set the full path for the destination file
         $destination_file = FILECLERK_DESTINATION_PATH . ltrim($destination) . '.yaml';
         if (File::exists($destination_file)) {
             $destination_config = YAML::parseFile($destination_file);
             foreach ($destination_config as $key => $value) {
                 if (!in_array($key, $allow_override) && (empty($value) || is_null($value))) {
                     unset($destination_config[$key]);
                 }
             }
         } else {
             $this->log->error("Could not use destination `" . $destination . "`, YAML file does not exist.");
         }
     }
     // load global config
     $addon_config = Helper::pick($this->getConfig(), array());
     // merge config variables in order
     $config = array_merge($config, $addon_config, $destination_config);
     // Handle content types
     // If it's a string, need to cast to an array
     if (is_string($config['content_types'])) {
         switch ($config['content_types']) {
             // If empty string, set to false
             case '':
             case null:
                 $config['content_types'] = false;
                 break;
                 // If there is a value, push to an array
             // If there is a value, push to an array
             default:
                 $config['content_types'] = array($config['content_types']);
                 break;
         }
     }
     // Convert permissions to the corresponding Canned ACL constant.
     switch (strtolower(trim($config['permissions']))) {
         case 'private':
             $config['permissions'] = CannedAcl::PRIVATE_ACCESS;
             break;
         case 'public-read':
             $config['permissions'] = CannedAcl::PUBLIC_READ;
             break;
         case 'public-read-write':
             $config['permissions'] = CannedAcl::PUBLIC_READ_WRITE;
             break;
         case 'authenticated-read':
             $config['permissions'] = CannedAcl::AUTHENTICATED_READ;
             break;
         default:
             $config['permissions'] = CannedAcl::PUBLIC_READ;
             break;
     }
     // Check that required configs are set
     foreach ($required_config as $key) {
         if (!isset($config[$key]) || $config[$key] == '') {
             $errors[] = array('error' => "<pre>{$key}</pre> is a required File Clerk config value.");
         }
     }
     // If errors, set in config for checking later
     if ($errors) {
         $config['errors'] = $errors;
     }
     // Create our S3 client
     //self::load_s3();
     return $config;
 }
Exemplo n.º 8
0
Arquivo: addon.php Projeto: nob/joi
 /**
  * Retrieves the config file for this Add-on
  *
  * @return mixed
  */
 public function getConfig()
 {
     if (File::exists($file = Config::getConfigPath() . '/add-ons/' . $this->addon_name . '/' . $this->addon_name . '.yaml')) {
         return YAML::parseFile($file);
     } elseif (File::exists($file = Config::getConfigPath() . '/add-ons/' . $this->addon_name . '.yaml')) {
         return YAML::parseFile($file);
     }
     return null;
 }
 public function createPhotoCollection()
 {
     $yaml_path = $_SERVER['DOCUMENT_ROOT'] . '/_content/photos/';
     $files = glob($yaml_path . '*.{md,collection}', GLOB_BRACE);
     $arr_files = [];
     //put each file into an array
     foreach ($files as $file) {
         if (basename($file) != "page.md") {
             $temp = array('date' => substr(basename($file), 0, 10), 'time' => substr(basename($file), 11, 4), 'hour' => substr(basename($file), 11, 2), 'file' => basename($file));
             $arr_files[] = $temp;
         }
     }
     //now split these into more arrays, grouped by date.
     //this is where we're loosing a file
     $last_date = $arr_files[0]['date'];
     $arr_groups = [];
     $i = 0;
     foreach ($arr_files as $file) {
         if ($last_date != $file['date']) {
             $i++;
         }
         $arr_groups[$i][] = $file;
         $last_date = $file['date'];
     }
     reset($arr_groups);
     //now further split this into similar times (+ or - 2 hours of eachother)
     $last_time = $arr_groups[0][0]['hour'];
     foreach ($arr_groups as $group) {
         if (count($group) > 1) {
             $last_time = $group[0]['hour'];
             foreach ($group as $item) {
                 $max = $last_time + 2;
                 $min = $last_time - 2;
                 if ($min < $item['hour'] && $item['hour'] > $max) {
                     $i++;
                 }
                 $time_groups[$i][] = $item;
                 $last_time = $item['hour'];
             }
             $i++;
         }
     }
     //now write out these groups into new YAML files.
     foreach ($time_groups as $times) {
         $YAML_arr = [];
         $images_arr = [];
         $i = 0;
         if (count($times) > 1) {
             foreach ($times as $item) {
                 //convert this array into the -images part of the YAML
                 $images_arr[] = YAML::parseFile($yaml_path . $item['file']);
                 $i++;
             }
             $YAML_arr['title'] = $images_arr[0]['title'];
             $YAML_arr['cover'] = $images_arr[0]['image'];
             $YAML_arr['first_time'] = $times[0]['time'];
             $YAML_arr['last_time'] = $times[$i - 1]['time'];
             $YAML_arr['images'] = $images_arr;
             $slug = Slug::make($images_arr[0]['flickr_id']);
             $file = $times[0]['date'] . "-" . $times[0]['time'] . "-" . $slug . ".md";
             if (!File::exists($yaml_path . "collections/" . $file)) {
                 File::put($yaml_path . "collections/" . $file, YAML::dump($YAML_arr) . '---' . "\n");
                 foreach ($times as $item) {
                     $arhive_file = $archive_file = preg_replace('"\\.md$"', '.collection', $item['file']);
                     if (File::exists($yaml_path . $item['file'])) {
                         rename($yaml_path . $item['file'], $yaml_path . $archive_file);
                     }
                 }
             }
         }
     }
     return true;
 }
Exemplo n.º 10
0
 /**
  * Get Globals & Theme Variables
  *
  * Create global variables from v1 globals and theme variables
  *
  * @return array
  */
 private function createGlobals()
 {
     $globals = array('settings' => array(), 'global' => array(), 'theme' => array());
     // Get a list of variables added to _config/settings.yaml
     // Anything not also in the defaults will be considered a global added manually.
     $defaults = array_keys(YAML::parseFile(Config::getAppConfigPath() . '/default.settings.yaml'));
     $settings = array_keys(YAML::parseFile(Config::getConfigPath() . '/settings.yaml'));
     $settings_globals = array_diff($settings, $defaults);
     foreach ($settings_globals as $setting) {
         $setting = ltrim($setting, '_');
         $globals['settings'][$setting] = Config::get($setting);
     }
     // Get a list of variables in _config/global.yaml
     $site_globals = Config::getConfigPath() . '/global.yaml';
     if (File::exists($site_globals)) {
         $globals['global'] = YAML::parse($site_globals);
     }
     // Get a list of variables in the theme.yaml
     $theme_globals = Config::getCurrentThemePath() . 'theme.yaml';
     if (File::exists($theme_globals)) {
         $globals['theme'] = YAML::parse($theme_globals);
     }
     $this->migration['globals'] = $globals;
 }