/** * Returns a given user's profile * * @param string $username Username's profile to return * @return array */ public static function getUserProfile($username) { if (!UserAuth::isUser($username)) { return null; } $content = substr(File::get(Config::getConfigPath() . "/users/" . $username . ".yaml"), 3); $divide = strpos($content, "\n---"); $front_matter = trim(substr($content, 0, $divide)); $content_raw = trim(substr($content, $divide + 4)); $profile = YAML::parse($front_matter); $profile['biography_raw'] = $content_raw; $profile['biography'] = Content::transform($content_raw); $profile['username'] = $username; return $profile; }
/** * Returns a Member object for one member * * @param string $username Username of member to get * @return Member */ public static function getMember($username) { self::loadMembers(); if (!self::isMember($username)) { return array(); } // get data $data = self::$members[$username]; // load bio $file = File::get(sprintf(self::$path, $username)); if ($file) { $content = substr(File::get($file), 3); $divide = strpos($content, "\n---"); $data['biography_raw'] = trim(substr($content, $divide + 4)); $data['biography'] = Content::transform($data['biography_raw']); } return new Member($data); }
/** * Loads a Member's profile * * @param string $username username to load data for * @return array * @throws Exception */ private static function loadMemberData($username) { // pull profile data from filesystem $file = Config::getConfigPath() . '/users/' . $username . '.yaml'; $raw_profile = substr(File::get($file), 3); // no profile found, throw an exception if (!$raw_profile) { throw new Exception('Member `' . $username . '` not found.'); } // split out the profile into parts $divide = strpos($raw_profile, "\n---"); $front_matter = trim(substr($raw_profile, 0, $divide)); $content_raw = trim(substr($raw_profile, $divide + 4)); // create data array for populating into the Member object $data = YAML::parse($front_matter); $data['biography_raw'] = $content_raw; $data['biography'] = Content::transform($content_raw); $data['username'] = $username; // return the Member data return $data; }
public static function yamlize_content($meta_raw, $content_key = 'content') { if (File::exists($meta_raw)) { $meta_raw = File::get($meta_raw); } if (Pattern::endsWith($meta_raw, "---")) { $meta_raw .= "\n"; # prevent parse failure } // Parse YAML Front Matter if (strpos($meta_raw, "---") === false) { $meta = YAML::parse($meta_raw); $meta['content'] = ""; } else { list($yaml, $content) = preg_split("/---/", $meta_raw, 2, PREG_SPLIT_NO_EMPTY); $meta = YAML::parse($yaml); $meta[$content_key . '_raw'] = trim($content); $meta[$content_key] = Content::transform($content); return $meta; } }
public static function transform_content($content, $content_type = NULL) { Log::warn("Use of Statamic::transform_content() is deprecated. Use Content::render() instead.", "core", "Statamic"); return Content::transform($content, $content_type); }
public static function load($username) { $meta_raw = ""; if (File::exists("_config/users/{$username}.yaml")) { $meta_raw = file_get_contents("_config/users/{$username}.yaml"); } else { return NULL; } if (Pattern::endsWith($meta_raw, "---")) { $meta_raw .= "\n"; # prevent parse failure } # Parse YAML Front Matter if (stripos($meta_raw, "---") === FALSE) { $meta = YAML::Parse($meta_raw); $meta['content'] = ""; } else { list($yaml, $content) = preg_split("/---/", $meta_raw, 2, PREG_SPLIT_NO_EMPTY); $meta = YAML::Parse($yaml); $meta['biography_raw'] = trim($content); $meta['biography'] = Content::transform($content); $u = new Statamic_User($meta); $u->set_name($username); return $u; } }