public function testState() { $source = $this->makePattern(); $source->state = "completed"; $pattern = new Pattern($source); $this->assertEquals($source->state, $pattern->getState()); }
public static function create($a, $name, $inPattern = false) { if (is_string($a) && !$inPattern) { return new \Pattern($a); } elseif (is_string($a) && $inPattern) { return $a; } elseif (is_array($a)) { $pattern = new \Pattern(); if (array_key_exists('get', $a)) { $pattern->set_get_options($a['get']); } if (array_key_exists('pattern', $a)) { if (is_array($a['pattern'])) { foreach ($a['pattern'] as $p) { $pattern->add_pattern(\Pattern::create($p, $name, true)); } } elseif (is_string($a['pattern'])) { $pattern->add_pattern(\Pattern::create($a['pattern'], $name, true)); } } if (array_key_exists('couple', $a)) { $pattern->handler->set_default_loader(\Loaders\Module::create($a, $name, true)); } return $pattern; } }
public function create($name, $parameters) { $parameters += $this->defaults; $pattern = new Pattern($parameters['notation'], $parameters['conditions']); $instance = new Route($pattern, $name, $parameters['defaults']); $pattern->prepare(); return $instance; }
static function getPatternByProgram($program) { $pattern = new Pattern(); $db = new DataBase("SchedulerDatabase"); $getProgramPattern = "SELECT * FROM Patterns \n\t\t\t\t\t\t\t\t\tWHERE ProgramID = '{$program}'\n\t\t\t\t\t\t\t\t\tORDER BY YearRequired, TermRequired, SubjectID;"; $rows = $db->execute($getProgramPattern); while ($row = $rows->fetch_object()) { $newItem = new PatternItem($row->ProgramID, $row->CourseType, $row->YearRequired, $row->TermRequired, $row->SubjectID, $row->CourseNumber); $pattern->addItem($newItem); } return $pattern; }
/** * The {{ all_the_vars }} tag * * @return string */ public function index() { $remove_underscored = $this->fetchParam('remove_underscored', true, null, true); // Tidy up the context values $context = $this->context; foreach ($context as $key => $val) { // Remove objects. You can't use them in templates. if (is_object($val)) { unset($context[$key]); } // Remove underscored variables. if ($remove_underscored && Pattern::startsWith($key, '_')) { unset($context[$key]); } } // Get extra page data $this->page_data = Content::get(URL::getCurrent()); // CSS $output = $this->css->link('all_the_vars'); if (!$this->fetchParam('websafe_font', false, null, true)) { $output .= '<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Ubuntu+Mono" />'; } // Create table $output .= $this->createTable($context, false); // Display on the screen die($output); }
public function add_pattern($p) { if ($p instanceof \Pattern) { $this->patterns[] = $p; } else { $this->patterns[] = \Pattern::create($p, $this->module); } }
public function index($value, $parameters = array()) { $pi = pathinfo($value); if (Pattern::matches('resized$', $pi['dirname'])) { $dir = preg_replace('/resized$/', '', $pi['dirname']); $value = Path::assemble($dir, $pi['basename']); } return $value; }
/** * Get the path of the current file * * @return string Full path */ public function getPath() { // Get the query string and remove the ordering $url = Path::pretty(Request::get('path')); // Remove the 'page' if it's a page.md $url = Pattern::endsWith($url, 'page') ? URL::popLastSegment($url) : $url; // Get the content $content = Content::get($url); // Path is inside the content return ltrim($content['_local_path'], '/'); }
public function parse($str, $callback) { if (!$str) { return false; } $pattern = new Pattern(); call_user_func_array($callback, [$pattern]); preg_match_all($pattern->build(), $str, $m); $keys = $pattern->getKeys(); array_shift($m); $rows = []; foreach ($m as $param => $values) { $key = $keys[$param]; foreach ($values as $num => $value) { if (!isset($rows[$num])) { $rows[$num] = new \stdClass(); } $rows[$num]->{$key} = $value; } } return count($rows) === 1 ? reset($rows) : $rows; }
function __construct($y, $p, $t) { $this->counter = 0; $this->year = $y; $this->program = $p; $this->courses = new SectionList(); $this->term = $t; $this->cursched = new SectionList(); $this->Schedules = array(); //Array of SectionLists $this->pattern = Pattern::getPatternByProgram($this->program); $this->calculateCourses(); $this->calculateConflictFreeSchedules(); }
/** * Detects the current environment * * @return mixed */ public static function detect() { $uri = Request::getURL(); // get configured environments $environments = Config::get("_environments"); if (is_array($environments)) { foreach ($environments as $environment => $patterns) { foreach ($patterns as $pattern) { if (Pattern::matches($pattern, $uri)) { return $environment; } } } } return NULL; }
public function deleteFile() { if (!Config::get('allow_file_field_deletions')) { return $this->abortDeletion('file_deleting_not_permitted'); } if (!($path = Request::get('path'))) { return $this->abortDeletion('file_no_path'); } if (!($destination = Request::get('config'))) { return $this->abortDeletion('file_no_config'); } $destination = Path::addStartingSlash(Helper::decrypt(urldecode($destination))); if (!Pattern::startsWith($path, $destination) || strpos($path, '../')) { return $this->abortDeletion('error'); } $full_path = Path::assemble(BASE_PATH, $path); if (!File::exists($full_path)) { return $this->abortDeletion('file_doesnt_exist'); } File::delete($full_path); return array('success' => true, 'message' => Localization::fetch('file_deleted')); }
/** * Detects the current environment * * @param array $config Config to look through * @return mixed */ public static function detect($config) { // get current URL, this is probably called before the config is ready, // so we cannot simply use Request::getURL() $scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https://' : 'http://'; $port = (int) $_SERVER['SERVER_PORT']; $host = $_SERVER['HTTP_HOST']; $url = $scheme . $host; if ($scheme === 'https://' && $port !== 443 || $scheme === 'http://' && $port !== 80) { $url .= ':' . $port; } // get configured environments $environments = array_get($config, '_environments', null); if (is_array($environments)) { foreach ($environments as $environment => $patterns) { foreach ($patterns as $pattern) { if (Pattern::matches($pattern, $url)) { return $environment; } } } } return null; }
public function addPattern($value) { $p = new Pattern(); $p->setPattern($value); $this->setPattern($p); }
public static function getInstance($pattern) { return parent::getInstance($pattern, '\\bclass\\s+'); }
/** * Createa Pattern-Inatance and provide it with the given Pattern * * @param string $pattern The pattern to store * * @return Pattern */ public static function factory($pattern) { $p = new Pattern(); $p->setPattern($pattern); return $p; }
/** * Gets a tree of content information * * @param string $base_url URL for the base of the tree to load * @param int $depth Number of levels deep to return * @param boolean $folders_only Folders only * @param boolean $include_entries Should we include entries in our tree? * @param boolean $show_hidden Should we not include hidden content * @param boolean $include_content Should we include content from the found info? * @param mixed $exclude Array of URLs to exclude * @return array */ public static function getContentTree($base_url, $depth = 12, $folders_only = true, $include_entries = false, $show_hidden = false, $include_content = false, $exclude = false) { // load structure and set up variables self::loadStructure(); $output = array(); // exclude URLs $exclude = Helper::ensureArray($exclude); // no depth asked for if ($depth == 0) { return array(); } // make sure we can find the requested URL in the structure if (!isset(self::$structure[$base_url])) { Log::debug('Could not find URL in structure cache.', 'core', 'ContentService'); return array(); } // depth measurements $starting_depth = self::$structure[$base_url]['depth'] + 1; // start one deeper than the base URL's depth $current_depth = $starting_depth; // recursively grab the tree foreach (self::$structure as $url => $data) { // is this the right depth and not the 404 page? if ($data['depth'] !== $current_depth || $url == "/404") { continue; } // is this under the appropriate parent? if (!Pattern::startsWith(Path::tidy($data['parent'] . '/'), Path::tidy($base_url . '/'))) { continue; } // is this hidden? if ($data['is_draft'] || !$show_hidden && $data['is_hidden']) { continue; } // is this an entry when we don't want them? if (!$include_entries && $data['is_entry'] && !$data['is_page']) { continue; } // is this a non-folder when all we want is folders? if ($folders_only && $data['type'] != 'folder') { continue; } // is this in the excluded URLs list? if (in_array($url, $exclude)) { continue; } // get parent url $parent_url = substr($url, 0, strrpos($url, '/')); $parent_url = $parent_url == "" ? Config::getSiteRoot() : $parent_url; // look up parent data in cache if (!isset(self::$parent_cache[$parent_url])) { // doesn't exist, load it up $parent_data = Content::get($parent_url, $include_content, false); if ($include_content) { // give them everything $parent = $parent_data; } else { // just the bare necessities $parent = array('title' => isset($parent_data['title']) ? $parent_data['title'] : '', 'url' => isset($parent_data['url']) ? $parent_data['url'] : ''); } // now stick this in the cache for next time self::$parent_cache[$parent_url] = $parent; } // get information $content = Content::get($url, $include_content, false); // data to be returned to the tree $for_output = array('type' => $data['type'], 'title' => isset($content['title']) ? $content['title'] : '', 'slug' => $content['slug'], 'url' => $url, 'depth' => $current_depth, 'children' => self::getContentTree($url, $depth - 1, $folders_only, $include_entries, $show_hidden, $include_content, $exclude), 'is_current' => URL::getCurrent() == $url, 'is_parent' => URL::getCurrent() != $url && Pattern::startsWith(URL::getCurrent(), $url . '/'), 'is_entry' => $data['is_entry'], 'is_page' => $data['is_page'], 'is_folder' => $data['type'] == 'folder', 'order_key' => $data['order_key'], 'sub_order_key' => $data['sub_order_key'], 'parent' => array(self::$parent_cache[$parent_url])); // if we're including content, merge that in if ($include_content) { $for_output = $content + $for_output; } // add it to the list $output[] = $for_output; } // now we need to sort the nav items uasort($output, function ($a, $b) { // sort on order_key $result = Helper::compareValues($a['order_key'], $b['order_key']); // if those matched, sort on sub_order_key if ($result === 0) { $result = Helper::compareValues($a['sub_order_key'], $b['sub_order_key']); } // return 1 or 0 or -1, whatever we ended up with return $result; }); // re-key the array $output = array_values($output); // return what we know return $output; }
/** * Creates a URL-friendly path from webroot * * @param string $path Path to trim * @return string */ public static function toAsset($path, $as_variable = false) { $asset_path = Path::trimFilesystem($path); if (Pattern::startsWith($asset_path, '{{ _site_root }}')) { $asset_path = str_replace('{{ _site_root }}', '/', $asset_path); } if (!Pattern::startsWith($asset_path, Config::getSiteRoot())) { $asset_path = $as_variable ? '{{ _site_root }}' . $asset_path : Config::getSiteRoot() . '/' . $asset_path; } return rtrim(self::tidy($asset_path), '/'); }
<?php require_once '../config.php'; require_once 'classes/user.inc.php'; require_once 'classes/pattern.inc.php'; session_start(); $user = new User(); $pattern = new Pattern(); if (isset($_REQUEST['cmd'])) { $cmd = $_REQUEST['cmd']; } if (isset($_REQUEST['email'])) { $email = $_REQUEST['email']; } if (isset($_REQUEST['password'])) { $password = $_REQUEST['password']; } if (isset($_REQUEST['sequence'])) { $sequence = $_REQUEST['sequence']; } if (!isset($cmd)) { echo "No command specified."; return; } switch ($cmd) { case "login": if (isset($email) && isset($password)) { $login = $user->login($email, $password); $login['pattern'] = $pattern->get("user"); echo json_encode($login); } else {
// we posted . characters, but something converts them to _ (HTTP 1.1 standard) $r = array(); foreach ($_REQUEST as $i => $v) { $r[join('.', explode('_', $i))] = $v; //convert _ back to . } $regels = array(); for ($i0 = 0; isset($r['0.' . $i0]); $i0++) { $regels[$i0] = @$r['0.' . $i0 . '']; } $relaties = array(); for ($i0 = 0; isset($r['1.' . $i0]); $i0++) { $relaties[$i0] = @$r['1.' . $i0 . '']; } $Conceptueeldiagram = @$r['2']; $Pattern = new Pattern($ID, $regels, $relaties, $Conceptueeldiagram); if ($Pattern->save() !== false) { die('ok:' . serviceref($_REQUEST['content']) . '&Pattern=' . urlencode($Pattern->getId())); } else { die('Please fix errors!'); } exit; // do not show the interface } $buttons = ""; if (isset($_REQUEST['new'])) { $new = true; } else { $new = false; } if (isset($_REQUEST['edit']) || $new) {
/** * Checks for and parses front matter * * @param string $string Content to parse * @return array */ public static function frontMatter($string, $yamlize = true) { $data = array(); $content = $string; if (Pattern::startsWith($string, "---")) { list($yaml, $content) = preg_split("/\n---/", $string, 2, PREG_SPLIT_NO_EMPTY); if ($yamlize) { $data = self::yaml($yaml); } } return compact('data', 'content'); }
setcookie("courses", $filename, time() + 3600, "/"); if ($source == "html") { header("location:../pages/my_schedule.php"); } else { header("content-type: text/plain"); echo "success-onsched="; echo $filename; } exit; } exit; case "GetPattern": //returns pattern of program specified in XML format $program = $_POST['program']; header("content-type: text/xml"); $pat = new Pattern(); //Select all courses within the pattern table whose program is equal to the one specified by user $getProgramPattern = "SELECT * FROM Patterns \n\t\t\t\t\t\t\t\t\tWHERE ProgramID = '{$program}';"; $rows = $db->execute($getProgramPattern); while ($row = $rows->fetch_object()) { //Add all courses found in query to list $newItem = new PatternItem($row->ProgramID, $row->CourseType, $row->YearRequired, $row->TermRequired, $row->SubjectID, $row->CourseNumber); $pat->addItem($newItem); } //Return XML of pattern to client-side echo $pat->exportXML(); exit; case "GetPrograms": //Retrieves all academic programs in database and returns them to client-side as XML string $getPrograms = "SELECT * FROM AcademicPrograms;"; $rows = $db->execute($getPrograms);
$user = '******'; $sequence = $_SESSION['sequenceArr']; $hash = md5($user . $sequence + rand()); $shareUrl = APP_URL . "?p=" . $hash; $options = array("asset_data" => "@" . APP_PATH . $_SESSION['soundcloud_tmp_file'], "title" => $title, "description" => $description . "\n<a href='{$shareUrl}'>{$shareUrl}</a>", "sharing" => "public", "streamable" => "true", "downloadable" => $downloadable); //UPLOAD TRACK TO SOUNDCLOUD $result = $soundcloud->execute('tracks.json', 'track', 'POST', $options, 'multipart/form-data'); $permalink = $result->permalink_url; //ADD NEWLY UPLOADED TRACK INFO TO DB //$tracks = $soundcloud->execute('groups/20839/tracks?format=json', '', 'GET'); $battle = new Battle(); $battle->addTrack($result); //ASSOCIATE NEWLY UPLOADED TRACK WITH GROUP $soundcloud->execute('groups/20839/contributions/' . $result->id, '', 'PUT'); //SAVE PATTERN IN `shared_patterns` TABLE $patternAPI = new Pattern(); $patternAPI->share($user, $sequence, $hash); //DELETE TRACK FROM DISK AND CLEAR SESSION VARIABLES unlink($_SESSION['soundcloud_tmp_file']); $_SESSION['soundcloud_tmp_file'] = ""; $_SESSION['sequenceArr'] = ""; $success = true; } else { $error = true; } } ?> <body> <div id="divUploadWrapper"> <?php
$admin_app->flash('success', Localization::fetch('entry_deleted')); } $url = $admin_app->request()->getReferrer(); $admin_app->redirect($url); })->name('delete_entry')->via('GET', 'POST'); // GET: DELETE PAGE $admin_app->get('/delete/page', function () use($admin_app) { authenticateForRole('admin'); doStatamicVersionCheck($admin_app); $path = Path::assemble(BASE_PATH, Config::getContentRoot(), $admin_app->request()->get('path')); $type = $admin_app->request()->get('type'); if ($type == "folder" && Folder::exists($path)) { Folder::delete($path); $admin_app->flash('success', Localization::fetch('page_deleted')); } else { if (!Pattern::endsWith($path, Config::getContentType())) { $path .= Config::getContentType(); } if (File::exists($path)) { /* |-------------------------------------------------------------------------- | Delete Hook |-------------------------------------------------------------------------- | | Runs the delete hook, passing the file path | */ Hook::run('control_panel', 'delete', null, $path); File::delete($path); $admin_app->flash('success', Localization::fetch('page_deleted')); } else {
public static function getInstance($pattern) { return parent::getInstance($pattern, '\\bnamespace\\s+'); }
public function testNameWithState() { $pattern = new Pattern('one/two/three@completed', __FILE__); $this->assertEquals('three', $pattern->getName()); }
?> </ul> </div> <?php echo $_html; ?> </div> </div> <div id="footer"> <a href="http://statamic.com">Statamic</a> v<?php print STATAMIC_VERSION; ?> <span id="version-check"> <?php if (Pattern::isValidUUID($app->config['_license_key'])) { ?> <?php if (isset($app->config['latest_version']) && $app->config['latest_version'] != '' && STATAMIC_VERSION < $app->config['latest_version']) { ?> <a href="https://store.statamic.com/account"><?php echo Localization::fetch('update_available'); ?> : v<?php echo $app->config['latest_version']; ?> </a> <?php } else { ?>
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 function count() { // grab parameters $from = $this->fetchParam('from', URL::getCurrent()); $exclude = $this->fetchParam('exclude', false); $max_depth = $this->fetchParam('max_depth', 1, 'is_numeric'); $include_entries = $this->fetchParam('include_entries', false, false, true); $folders_only = $this->fetchParam('folders_only', true, false, true); $include_content = $this->fetchParam('include_content', false, false, true); $show_hidden = $this->fetchParam('show_hidden', false, null, true); // add in left-/ if not present if (substr($from, 0, 1) !== '/') { $from = '/' . $from; } // if this doesn't start with the site root, add the site root if (!Pattern::startsWith($from, Config::getSiteRoot())) { $from = Path::tidy(Config::getSiteRoot() . '/' . $from); } // standardize excludes if ($exclude && !is_array($exclude)) { $exclude = Helper::explodeOptions($exclude, array()); foreach ($exclude as $key => $value) { $exclude[$key] = Path::tidy(Config::getSiteRoot() . '/' . $value); } } // option hash $hash = Helper::makeHash($from, $exclude, $max_depth, $include_entries, $folders_only, $include_content, $show_hidden); // load the content tree from cache if ($this->blink->exists($hash)) { $tree = $this->blink->get($hash); } else { $tree = ContentService::getContentTree($from, $max_depth, $folders_only, $include_entries, $show_hidden, $include_content, $exclude); $this->blink->set($hash, $tree); } if ($this->content) { return Parse::template($this->content, array('count' => count($tree))); } elseif (count($tree)) { return count($tree); } return ''; }
public function replaceWithDollarBackReferences() { $quoter = Pattern::compile('([^=]+)=([^ >]+)([ >]*)'); $this->assertEquals('<a href="http://example.com" title="Link">...</a>', $quoter->replaceWith('$1="$2"$3', '<a href=http://example.com title=Link>...</a>')); }