function diff_page($ctl) { $file = $_REQUEST['file']; $from_rev = $_REQUEST['from_rev']; $to_rev = $_REQUEST['to_rev']; if (preg_match('@^/|(^|/)\\.\\.?($|/)|[\\"\'\\`\\(\\)\\[\\]\\&\\|\\>\\<]@', $file, $m) || preg_match('/[^\\d\\.]+/', $from_rev, $m) || !preg_match('/^([\\d\\.]+|local)$/', $to_rev, $m)) { return trigger_error("Please don't hack...", E_USER_ERROR); } ### Get the partial diff $to_rev_clause = $to_rev == 'local' ? "" : "-r {$to_rev}"; if (PROJECT_PROJECT_TIMERS) { START_TIMER('REPO_CMD'); } $revision_arg = $to_rev == 'local' ? "-r{$from_rev}" : "-r{$from_rev}:{$to_rev}"; $cmd_prefix = $ctl->stage->config('repo_cmd_prefix'); $cmd_name = $ctl->stage->repo()->command_name; $cdiff = `{$cmd_prefix}{$cmd_name} diff {$revision_arg} "{$file}" 2>&1 | cat`; if (PROJECT_PROJECT_TIMERS) { END_TIMER('REPO_CMD'); } return array('cdiff' => $cdiff, 'from_rev' => $from_rev, 'to_rev' => $to_rev, 'file' => $file, 'command_name' => $ctl->stage->repo()->command_name); }
/** * dbh_do_bind() - Execute a (possibly write access) SQL query with bound parameters * * @param string $sql The SQL query to run * @param mixed $params this can either be called passing an array of bind params, or just by passing the bind params as args after the SQL arg * @return PDOStatement */ function dbh_do_bind($sql) { $use_dbh = $this->dbh(); if (ORM_SQL_PROFILE) { START_TIMER('dbh_do_bind'); } $bind_params = array_slice(func_get_args(), 1); ### Allow params passed in an array or as args if (is_a($bind_params[count($bind_params) - 1], 'PDO') || is_a($bind_params[count($bind_params) - 1], 'PhoneyPDO')) { $use_dbh = array_pop($bind_params); } if (count($bind_params) == 1 && is_array(array_shift(array_values($bind_params)))) { $bind_params = array_shift(array_values($bind_params)); } $this->reverse_t_bools($bind_params); if (ORM_SQL_DEBUG || ORM_SQL_WRITE_DEBUG) { bug($sql, $bind_params); } $GLOBALS['ORM_SQL_LOG'][] = array(microtime(true), $sql, $bind_params); try { $sth = $use_dbh->prepare($sql); $rv = $sth->execute($bind_params); } catch (PDOException $e) { trace_dump(); $err_msg = 'There was an error running a SQL statement, [' . $sql . '] with (' . join(',', $bind_params) . '): ' . $e->getMessage() . ' in ' . trace_blame_line(); if (strlen($err_msg) > 1024) { bug($err_msg, $sql, $bind_params, $e->getMessage()); $sql = substr($sql, 0, 1020 + strlen($sql) - strlen($err_msg)) . '...'; } trigger_error('There was an error running a SQL statement, [' . $sql . '] with (' . join(',', $bind_params) . '): ' . $e->getMessage() . ' in ' . trace_blame_line(), E_USER_ERROR); return false; } if (ORM_SQL_PROFILE) { END_TIMER('dbh_do_bind'); } return $rv; }
public function handler() { // Load Main Libraries if (!empty($this->STARK_PROFILING)) { START_TIMER('STARK-controller-lib_load'); } require_once $this->lib_path . '/Stark/View.class.php'; require_once $this->lib_path . '/Stark/Controller/Base.class.php'; if (isset($this->CONTROLLER_PRELOAD_LIBS)) { foreach ($this->CONTROLLER_PRELOAD_LIBS as $lib) { require_once $lib; } } if (!empty($this->STARK_PROFILING)) { END_TIMER('STARK-controller-lib_load'); } // Main Controller Sequence if (!empty($this->STARK_PROFILING)) { START_TIMER('STARK-controller-handlers'); } $this->view = new Stark__View($_SERVER['SCRIPT_NAME']); $this->view->controller = $this; /// Reguster AJAX mode if (!empty($_SERVER['__STARK_AJAX_MODE__'])) { $this->ajax_mode = true; } /// Catch the Previous Step # TODO /// Page Handler list($page_ctl, $page_page) = $this->load_controller_by_path($this->path); $this->run_directory_handlers($this->path, $page_ctl); if (!empty($page_ctl)) { // If the controller is defined... $method = $page_page . (!empty($_SERVER['__STARK_AJAX_MODE__']) ? '_ajax' : '_page'); /// Call the handler if it is defined $exists = method_exists($page_ctl, 'real_method_exists') ? $page_ctl->real_method_exists($method) : method_exists($page_ctl, $method); if ($exists) { $scope = $page_ctl->{$method}($this); /// AJAX returnin if (!empty($_SERVER['__STARK_AJAX_MODE__'])) { header('Content-type: application/json'); print !empty($_REQUEST['callback']) ? 'function ' . $_REQUEST['callback'] . '(){return ' . json_encode($scope) . '}' : "{}&&\n" . json_encode($scope); exit; # if we let it proceed it might print report_timers(), which isn't waht we want! } else { if (!empty($scope) && is_array($scope)) { foreach (array_keys($scope) as $var) { if (isset($scope[$var])) { $this->view->{$var} = $scope[$var]; } } } } } } if (!empty($this->STARK_PROFILING)) { END_TIMER('STARK-controller-handlers'); } }
public function import_scope($dont_import = array()) { if (STARK_EXTEND_PROFILE) { START_TIMER('Stark__Extend->import_scope'); } if (is_array($dont_import)) { $this->__dont_import = $dont_import; } /// This is the file to be included $return = $this->dirname_file . '/Extend/import_scope.inc.php'; if (STARK_EXTEND_PROFILE) { PAUSE_TIMER('Stark__Extend->import_scope'); } if (STARK_EXTEND_PROFILE) { START_TIMER('Stark__Extend->include overhead'); } return $return; }
function dax_scrub_tag($tagname, $tag, $scrub_config) { START_TIMER('DAX_SCRUB_tag'); global $dax_neverNested, $dax_freeElementAttrs; if (isset($scrub_config['allowed_tags'][$tagname])) { if (!is_array($scrub_config['allowed_tags'][$tagname])) { $scrub_config['allowed_tags'][$tagname] = isset($dax_freeElementAttrs[$tagname]) ? $dax_freeElementAttrs[$tagname] : array(); } if (!isset($scrub_config['allowed_tags'][$tagname]['allowed_attrs'])) { $scrub_config['allowed_tags'][$tagname]['allowed_attrs'] = array(); } if (!isset($scrub_config['allowed_tags'][$tagname]['allowed_styles'])) { $scrub_config['allowed_tags'][$tagname]['allowed_styles'] = array(); } if (!isset($scrub_config['allowed_tags'][$tagname]['disallowed_attrs'])) { $scrub_config['allowed_tags'][$tagname]['disallowed_attrs'] = array(); } if (!isset($scrub_config['allowed_tags'][$tagname]['disallowed_styles'])) { $scrub_config['allowed_tags'][$tagname]['disallowed_styles'] = array(); } ### Implied Style attr allowed unless globally disabled if (!isset($scrub_config['options']['disable_style_attr']) && empty($scrub_config['allowed_tags'][$tagname]['allowed_attrs']['style'])) { $scrub_config['allowed_tags'][$tagname]['allowed_attrs']['style'] = true; } ### Scrub the tag's attributes... $keepAttrs = array(); $close_tag = substr($tag, strlen($tag) - 2, 1) == '/' || isset($dax_neverNested[$tagname]) ? '/>' : '>'; $open_tag = (substr($tag, 1, 1) == '/' ? '</' : '<') . $tagname; if (preg_match_all('/(\\w+)\\=(\\"[^\\"]*\\"|\'[^\']*\'|[^\\"\\s]+)/', substr($tag, strlen($open_tag), strlen($tag) - strlen($open_tag) - strlen($close_tag)), $m) == 0) { END_TIMER('DAX_SCRUB_tag'); return array(true, $open_tag . $close_tag, true); } $attrs = $m[0]; $styleAttrRules = array(); ### Loop thru the attributes for ($i = 0; $i < count($attrs); $i++) { $n_v = null; # Keep the line count the same if (!preg_match('/^([\\w-]+)=\\"?([^\\"]+)\\"?$/', $attrs[$i], $n_v) && !preg_match('/^([\\w-]+)=\'?([^\']+)\'?$/', $attrs[$i], $mm)) { continue; } $attr = strtolower($n_v[1]); ### Attribute Rules : Simple Allow / Disallow if (!isset($scrub_config['allowed_attrs'][$attr]) && !isset($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]) || isset($scrub_config['allowed_tags'][$tagname]['disallowed_attrs'][$attr])) { continue; } ### Attribute Rules : Tag Inspecific Attr Value regexp if (isset($scrub_config['allowed_attrs'][$attr]) && is_array($scrub_config['allowed_attrs'][$attr]) && (isset($scrub_config['allowed_attrs'][$attr]['regexp']) && !preg_match($scrub_config['allowed_attrs'][$attr]['regexp'], $n_v[2], $m) || isset($scrub_config['allowed_attrs'][$attr]['neg_regexp']) && preg_match($scrub_config['allowed_attrs'][$attr]['neg_regexp'], $n_v[2], $m))) { continue; } ### Attribute Rules : Tag Specific Attr Value regexp if (isset($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]) && is_array($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]) && (isset($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]['regexp']) && !preg_match($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]['regexp'], $n_v[2], $m) || isset($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]['neg_regexp']) && preg_match($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]['neg_regexp'], $n_v[2], $m))) { continue; } ### Parse CSS Styles for Style Rules if ($attr == 'style') { $rules = preg_split('/\\s*;\\s*/', $n_v[2]); ### Loop thru STYLE rules for ($ii = 0; $ii < count($rules); $ii++) { $style_n_v = null; # Keep the line count the same; if (!preg_match('/^([\\w-]+)\\s*:\\s*(.+)?$/s', $rules[$ii], $style_n_v)) { continue; } $style = strtolower($style_n_v[1]); ### Style Rules : Simple Allow / Disallow if (!isset($scrub_config['allowed_styles'][$style]) && !isset($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]) || $scrub_config['allowed_tags'][$tagname]['disallowed_styles'][$style]) { continue; } ### Style Rules : Tag Inspecific Style Value regexp if (isset($scrub_config['allowed_styles'][$style]) && is_array($scrub_config['allowed_styles'][$style]) && (isset($scrub_config['allowed_styles'][$style]['regexp']) && !preg_match($scrub_config['allowed_styles'][$style]['regexp'], $style_n_v[2], $m) || isset($scrub_config['allowed_styles'][$style]['neg_regexp']) && preg_match($scrub_config['allowed_styles'][$style]['neg_regexp'], $style_n_v[2], $m))) { continue; } ### Style Rules : Tag Specific Style Value regexp if (isset($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]) && is_array($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]) && (isset($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]['regexp']) && !preg_match($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]['regexp'], $style_n_v[2], $m) || isset($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]['neg_regexp']) && preg_match($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]['neg_regexp'], $style_n_v[2], $m))) { continue; } array_push($styleAttrRules, $rules[$ii]); } } else { array_push($keepAttrs, $attrs[$i]); } } if (count($styleAttrRules) > 0) { array_push($keepAttrs, 'style="' . join($styleAttrRules, '; ') . '"'); } if (count($keepAttrs) > 0) { END_TIMER('DAX_SCRUB_tag'); return array(true, $open_tag . ' ' . join($keepAttrs, ' ') . $close_tag, false); } END_TIMER('DAX_SCRUB_tag'); return array(true, $open_tag . $close_tag, true); } else { END_TIMER('DAX_SCRUB_tag'); return array(false, '', true); } }
public function updateEntireRepoAction($tag, $user) { set_time_limit(0); $cmd = ''; $command_output = ''; ### Prepare for a MASS HEAD update if updating to HEAD $doing_indiv_dir_update = array(); if ($tag == 'HEAD') { $head_update_cmd = "svn update"; START_TIMER('REPO_CMD', PROJECT_PROJECT_TIMERS); $this->log_repo_action($head_update_cmd, 'entire_repo', $user); $command_output .= shell_exec($this->stage->config('repo_cmd_prefix') . "{$head_update_cmd} 2>&1 | cat -"); END_TIMER('REPO_CMD', PROJECT_PROJECT_TIMERS); $cmd .= "\n" . (strlen($cmd) ? ' ; ' : '') . $head_update_cmd; } else { ############################# ### Step 1 : First find any files that we have tags for but don't exist ### Start out by updating all rows in the tag table as mass_edit=1 ### as we delete and update, the ones that have tags will be set back to 0 $rv = dbh_do_bind("UPDATE file_tag SET mass_edit=1 AND tag=?", $tag); $command_output = ''; $status = $this->get_dir_status(); foreach (preg_split('/\\n/', $status) as $line) { if (preg_match('/^\\s*[A-Z]?\\s*\\d+\\s+(\\d+)\\s+\\S+\\s+(\\S.*)$/', $line, $m)) { $cur_rev = $m[1]; $file = rtrim($m[2], "\n\r"); /// Override this with the SLOW, but accurate alternate. This turns a 2 min update into a 2+ hour update list($cur_rev) = $this->get_current_rev($file); ### Skip dirs in SVN (for now)... if (is_dir($this->stage->env()->repo_base . '/' . $file)) { continue; } ### We could be cache-ing the tags here, but in some repos with long file paths and hundreds of thousands of files, we would run out of memory # ### See what the tag is... # $sth = dbh_query_bind("SELECT revision FROM file_tag WHERE file = ? AND tag = ?", $file, $tag); # $old_rev = $sth->fetch(PDO::FETCH_NUM); # $sth->closeCursor(); ### ALL we are doing for the files that exist for this loop is marking mass_edit as off $rv = dbh_do_bind("UPDATE file_tag SET mass_edit=0 WHERE file = ? AND tag = ?", $file, $tag); } } ############################# ### Step 2 : Update the files that didn't exist... ### The rows the mass_edit still need to be Un-tagged... ### See what the tag was before... $sth = dbh_query_bind("SELECT file,revision FROM file_tag WHERE mass_edit=1 AND tag=?", $tag); while (list($file, $rev) = $sth->fetch(PDO::FETCH_NUM)) { /// Each loop, do a $individual_file_rev_updates instead of globally $individual_file_rev_updates = array(); $dir_test = $file; ### Before we do Inidividual Tag updates on files the containing dirs must exist $dirs_to_update = array(); while (!empty($dir_test) && !is_dir(dirname($this->stage->env()->repo_base . "/{$dir_test}")) && $this->stage->env()->repo_base != dirname($this->stage->env()->repo_base . "/{$dir_test}") && !array_key_exists(dirname($dir_test), $doing_indiv_dir_update)) { $dir = dirname($dir_test); $dirs_to_update[] = $dir; $doing_indiv_dir_update[$dir] = true; $dir_test = $dir; // iterate backwards } /// Need to add in parent-first order /// NOTE: we only need to do the parent one, because the in-between ones will be included if (count($dirs_to_update)) { $individual_file_rev_updates[] = array(array_pop($dirs_to_update), $rev); } $individual_file_rev_updates[] = array($file, $rev); foreach ($individual_file_rev_updates as $update) { list($up_file, $up_rev) = $update; $indiv_update_cmd = "svn update -r{$up_rev} " . escapeshellcmd($up_file); START_TIMER('REPO_CMD', PROJECT_PROJECT_TIMERS); $this->log_repo_action($indiv_update_cmd, 'entire_repo', $user); $command_output .= shell_exec($this->stage->config('repo_cmd_prefix') . "{$indiv_update_cmd} 2>&1 | cat -"); END_TIMER('REPO_CMD', PROJECT_PROJECT_TIMERS); $cmd .= "\n" . (strlen($cmd) ? ' ; ' : '') . $indiv_update_cmd; } } $sth->closeCursor(); $rv = dbh_do_bind("UPDATE file_tag SET mass_edit=0 WHERE tag=?", $tag); ############################# ### Step 3 : NOW, get a new Status output, and go through again, now that all files are present and set everything to the right tags ### Reset Cache on dir status unset($this->repo_cache['dir_status']['*ROOTDIR*']); $status = $this->get_dir_status(); foreach (preg_split('/\\n/', $status) as $line) { if (preg_match('/^\\s*[A-Z]?\\s*\\d+\\s+(\\d+)\\s+\\S+\\s+(\\S.*)$/', $line, $m)) { $cur_rev = $m[1]; $file = rtrim($m[2], "\n\r"); if (is_dir($this->stage->env()->repo_base . "/{$file}")) { continue; } /// Each loop, do a $individual_file_rev_updates instead of globally $individual_file_rev_updates = array(); ### Get the tag rev for this file... $sth = dbh_query_bind("SELECT revision FROM file_tag WHERE file = ? AND tag = ?", $file, $tag); $rev = $sth->fetch(PDO::FETCH_NUM); $sth->closeCursor(); if (!empty($rev)) { $dir_test = $file; ### Before we do Inidividual Tag updates on files the containing dirs must exist $dirs_to_update = array(); while (!empty($dir_test) && !is_dir(dirname($this->stage->env()->repo_base . "/{$dir_test}")) && $this->stage->env()->repo_base != dirname($this->stage->env()->repo_base . "/{$dir_test}") && !array_key_exists(dirname($dir_test), $doing_indiv_dir_update)) { $dir = dirname($dir_test); $dirs_to_update[] = $dir; $doing_indiv_dir_update[$dir] = true; $dir_test = $dir; // iterate backwards } /// Need to add in parent-first order /// NOTE: we only need to do the parent one, because the in-between ones will be included if (count($dirs_to_update)) { # bug("Parent Dir update", $file); $individual_file_rev_updates[] = array(array_pop($dirs_to_update), $rev[0]); } else { if ($cur_rev != $rev[0]) { # bug("Regular update", $file); $individual_file_rev_updates[] = array($file, $rev[0]); } } } else { list($first_rev, $error) = $this->get_first_rev($file); # bug("NO TAG, intent-to-rm update", $file, $first_rev); if (empty($error)) { $rev_before_first = $first_rev - 1; $individual_file_rev_updates[] = array($file, $rev_before_first); } } /// Do updates... foreach ($individual_file_rev_updates as $update) { list($up_file, $up_rev) = $update; $indiv_update_cmd = "svn update -r{$up_rev} " . escapeshellcmd($up_file); START_TIMER('REPO_CMD', PROJECT_PROJECT_TIMERS); $this->log_repo_action($indiv_update_cmd, 'entire_repo', $user); $command_output .= shell_exec($this->stage->config('repo_cmd_prefix') . "{$indiv_update_cmd} 2>&1 | cat -"); END_TIMER('REPO_CMD', PROJECT_PROJECT_TIMERS); $cmd .= "\n" . (strlen($cmd) ? ' ; ' : '') . $indiv_update_cmd; } } } } if (empty($command_output)) { $command_output = '</xmp><i>No output</i>'; } return array($cmd, $command_output); }
public function cache_statuses($files) { global $REPO_CMD_PREFIX, $MAX_BATCH_SIZE, $MAX_BATCH_STRING_SIZE; $cache_key = 'status'; ### Batch and run the command while (count($files) > 0) { $round = array(); $round_str = ''; while ($files && $round < $MAX_BATCH_SIZE && strlen($round_str) < $MAX_BATCH_STRING_SIZE) { $file = array_shift($files); ### Skip ones whos parent dir ! exists $parent_dir = dirname($file); if (!is_dir($_SERVER['PROJECT_REPO_BASE'] . "/{$parent_dir}")) { continue; } array_push($round, $file); $round_str .= " \"{$file}\""; } $round_checkoff = array_flip($round); if (PROJECT_PROJECT_TIMERS) { START_TIMER('REPO_CMD'); } $all_entries = `{$REPO_CMD_PREFIX}cvs status {$round_str} 2>&1 | cat`; # bug substr($all_entries, -200); if (PROJECT_PROJECT_TIMERS) { END_TIMER('REPO_CMD'); } foreach (preg_split('@===================================================================+\\n@', $all_entries) as $entry) { if (preg_match('/^\\s*$/s', $entry, $m)) { continue; } ### Get the filename if (preg_match('@Repository revision:\\s*[\\d\\.]+\\s*/sandbox/cvsroot/(?:project/)?(.+?),v\\n@', $entry, $m)) { $file = $m[1]; array_shift($round); } else { if (preg_match('@^File: (?:no file )?(.+?)\\s+Status@', $entry, $m)) { $file = $m[1]; if (preg_match('@/\\Q$file\\E$@', $round[0], $m)) { $file = array_shift($round); } else { # bug [$entry, $file]; } } else { # bug [$entry]; # silently skip continue; } } ### Cache if (!array_key_exists($round_checkoff[$file])) { continue; # BUG [$entry, $round, $file,$round_checkoff]; # return trigger_error("file not in round", E_USER_ERROR); } unset($round_checkoff[$file]); $this->repo_cache[$cache_key][$file] = $entry; } } }
/** * reset_timers() - Reset benchmarking values, counts and data */ function reset_timers() { global $BUG_ON, $BUG_TIME_I, $BUG_TIMERS, $BUG_TIMESEQ, $BUG_TIMEX; if (!$BUG_ON) { return true; } $BUG_TIMERS = array(); $BUG_TIMESEQ = array(); $BUG_TIMEX = array(); START_TIMER('all_global'); }