code
stringlengths
15
9.96M
docstring
stringlengths
1
10.1k
func_name
stringlengths
1
124
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
6
186
url
stringlengths
50
236
license
stringclasses
4 values
protected function newTag($name, array $attrs, $content = null) { foreach ($attrs as $key => $attr) { if ($attr !== null) { $attrs[$key] = $this->assertFlatText($attr); } } return phutil_tag($name, $attrs, $content); }
Safely generate a tag. In Remarkup contexts, it's not safe to use arbitrary text in tag attributes: even though it will be escaped, it may contain replacement tokens which are then replaced with markup. This method acts as @{function:phutil_tag}, but checks attributes before using them. @param string $name Tag name. @param dict<string, wild> $attrs Tag attributes. @param wild $content (optional) Tag content. @return PhutilSafeHTML Tag object.
newTag
php
phorgeit/phorge
src/infrastructure/markup/markuprule/PhutilRemarkupRule.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/markuprule/PhutilRemarkupRule.php
Apache-2.0
protected function assertFlatText($text) { $text = (string)hsprintf('%s', phutil_safe_html($text)); $rich = (strpos($text, PhutilRemarkupBlockStorage::MAGIC_BYTE) !== false); if ($rich) { throw new Exception( pht( 'Remarkup rule precedence is dangerous: rendering text with tokens '. 'as flat text!')); } return $text; }
Assert that a text token is flat (it contains no replacement tokens). Because tokens can be replaced with markup, it is dangerous to use arbitrary input text in tag attributes. Normally, rule precedence should prevent this. Asserting that text is flat before using it as an attribute provides an extra layer of security. Normally, you can call @{method:newTag} rather than calling this method directly. @{method:newTag} will check attributes for you. @param wild $text Ostensibly flat text. @return string Flat text.
assertFlatText
php
phorgeit/phorge
src/infrastructure/markup/markuprule/PhutilRemarkupRule.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/markuprule/PhutilRemarkupRule.php
Apache-2.0
protected function isFlatText($text) { $text = (string)hsprintf('%s', phutil_safe_html($text)); return (strpos($text, PhutilRemarkupBlockStorage::MAGIC_BYTE) === false); }
Check whether text is flat (contains no replacement tokens) or not. @param wild $text Ostensibly flat text. @return bool True if the text is flat.
isFlatText
php
phorgeit/phorge
src/infrastructure/markup/markuprule/PhutilRemarkupRule.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/markuprule/PhutilRemarkupRule.php
Apache-2.0
protected function getRemarkupLinkClass($is_internal) { // Allow developers to style esternal links differently $classes = array('remarkup-link'); if (!$is_internal) { $classes[] = 'remarkup-link-ext'; } return implode(' ', $classes); }
Get the CSS class="" attribute for a Remarkup link. It's just "remarkup-link" for all cases, plus the possibility for designers to style external links differently. @param boolean $is_internal Whenever the link was internal or not. @return string
getRemarkupLinkClass
php
phorgeit/phorge
src/infrastructure/markup/markuprule/PhutilRemarkupRule.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/markuprule/PhutilRemarkupRule.php
Apache-2.0
public function getPriority() { return 300; }
This rule executes at priority `300`, so it can preempt the list block rule and claim blocks which begin `---`.
getPriority
php
phorgeit/phorge
src/infrastructure/markup/blockrule/PhutilRemarkupHorizontalRuleBlockRule.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/blockrule/PhutilRemarkupHorizontalRuleBlockRule.php
Apache-2.0
private static function isKnownLanguageCode($lang) { $languages = self::knownLanguageCodes(); return isset($languages[$lang]); }
Check if a language code can be used in a generic flavored markdown. @param string $lang Language code @return bool
isKnownLanguageCode
php
phorgeit/phorge
src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php
Apache-2.0
private static function knownLanguageCodes() { // This is a friendly subset from https://pygments.org/languages/ static $map = array( 'arduino' => 1, 'assembly' => 1, 'awk' => 1, 'bash' => 1, 'bat' => 1, 'c' => 1, 'cmake' => 1, 'cobol' => 1, 'cpp' => 1, 'css' => 1, 'csharp' => 1, 'dart' => 1, 'delphi' => 1, 'fortran' => 1, 'go' => 1, 'groovy' => 1, 'haskell' => 1, 'java' => 1, 'javascript' => 1, 'kotlin' => 1, 'lisp' => 1, 'lua' => 1, 'matlab' => 1, 'make' => 1, 'perl' => 1, 'php' => 1, 'powershell' => 1, 'python' => 1, 'r' => 1, 'ruby' => 1, 'rust' => 1, 'scala' => 1, 'sh' => 1, 'sql' => 1, 'typescript' => 1, 'vba' => 1, ); return $map; }
Get the available languages for a generic flavored markdown. @return array Languages as array keys. Ignore the value.
knownLanguageCodes
php
phorgeit/phorge
src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php
Apache-2.0
private function guessFilenameExtension($name) { $name = basename($name); $pos = strrpos($name, '.'); if ($pos !== false) { return substr($name, $pos + 1); } return null; }
Get the extension from a filename. @param string $name "/path/to/something.name" @return null|string ".name"
guessFilenameExtension
php
phorgeit/phorge
src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php
Apache-2.0
public function getPriority() { return 500; }
Determine the order in which blocks execute. Blocks with smaller priority numbers execute sooner than blocks with larger priority numbers. The default priority for blocks is `500`. Priorities are used to disambiguate syntax which can match multiple patterns. For example, ` - Lorem ipsum...` may be a code block or a list. @return int Priority at which this block should execute.
getPriority
php
phorgeit/phorge
src/infrastructure/markup/blockrule/PhutilRemarkupBlockRule.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/blockrule/PhutilRemarkupBlockRule.php
Apache-2.0
public function getPriority() { return 400; }
This rule must apply before the Code block rule because it needs to win blocks which begin ` - Lorem ipsum`.
getPriority
php
phorgeit/phorge
src/infrastructure/markup/blockrule/PhutilRemarkupListBlockRule.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/blockrule/PhutilRemarkupListBlockRule.php
Apache-2.0
private function buildTree(array $items, $l, $r, $cur_level) { if ($l == $r) { return array(); } if ($cur_level > self::MAXIMUM_LIST_NESTING_DEPTH) { // This algorithm is recursive and we don't need you blowing the stack // with your oh-so-clever 50,000-item-deep list. Cap indentation levels // at a reasonable number and just shove everything deeper up to this // level. $nodes = array(); for ($ii = $l; $ii < $r; $ii++) { $nodes[] = array( 'level' => $cur_level, 'items' => array(), ) + $items[$ii]; } return $nodes; } $min = $l; for ($ii = $r - 1; $ii >= $l; $ii--) { if ($items[$ii]['depth'] <= $items[$min]['depth']) { $min = $ii; } } $min_depth = $items[$min]['depth']; $nodes = array(); if ($min != $l) { $nodes[] = array( 'text' => null, 'level' => $cur_level, 'style' => null, 'mark' => null, 'items' => $this->buildTree($items, $l, $min, $cur_level + 1), ); } $last = $min; for ($ii = $last + 1; $ii < $r; $ii++) { if ($items[$ii]['depth'] == $min_depth) { $nodes[] = array( 'level' => $cur_level, 'items' => $this->buildTree($items, $last + 1, $ii, $cur_level + 1), ) + $items[$last]; $last = $ii; } } $nodes[] = array( 'level' => $cur_level, 'items' => $this->buildTree($items, $last + 1, $r, $cur_level + 1), ) + $items[$last]; return $nodes; }
See additional notes in @{method:markupText}.
buildTree
php
phorgeit/phorge
src/infrastructure/markup/blockrule/PhutilRemarkupListBlockRule.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/blockrule/PhutilRemarkupListBlockRule.php
Apache-2.0
private function adjustTreeStyleInformation(array &$tree) { // The effect here is just to walk backward through the nodes at this level // and apply the first style in the list to any empty nodes we inserted // before it. As we go, also recurse down the tree. $style = '-'; for ($ii = count($tree) - 1; $ii >= 0; $ii--) { if ($tree[$ii]['style'] !== null) { // This is the earliest node we've seen with style, so set the // style to its style. $style = $tree[$ii]['style']; } else { // This node has no style, so apply the current style. $tree[$ii]['style'] = $style; } if ($tree[$ii]['items']) { $this->adjustTreeStyleInformation($tree[$ii]['items']); } } }
See additional notes in @{method:markupText}.
adjustTreeStyleInformation
php
phorgeit/phorge
src/infrastructure/markup/blockrule/PhutilRemarkupListBlockRule.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/markup/blockrule/PhutilRemarkupListBlockRule.php
Apache-2.0
public function __construct($uri) { // Keep the original string for basic checks. $this->uriStr = phutil_string_cast($uri); // A PhutilURI may be useful. If available, import that as-is. // Note that the constructor PhutilURI(string) is a bit expensive. if ($uri instanceof PhutilURI) { $this->phutilUri = $uri; } }
@param string|PhutilURI $uri
__construct
php
phorgeit/phorge
src/infrastructure/parser/PhutilURIHelper.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/parser/PhutilURIHelper.php
Apache-2.0
public function isSelf() { // The backend prefers a PhutilURI object, if available. $uri = $this->phutilUri ? $this->phutilUri : $this->uriStr; return PhabricatorEnv::isSelfURI($uri); }
Check if the URI points to Phorge itself. @return bool
isSelf
php
phorgeit/phorge
src/infrastructure/parser/PhutilURIHelper.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/parser/PhutilURIHelper.php
Apache-2.0
public function isAnchor() { return $this->isStartingWithChar('#'); }
Check whenever an URI is just a simple fragment without path and protocol. @return bool
isAnchor
php
phorgeit/phorge
src/infrastructure/parser/PhutilURIHelper.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/parser/PhutilURIHelper.php
Apache-2.0
public function isStartingWithSlash() { return $this->isStartingWithChar('/'); }
Check whenever an URI starts with a slash (no protocol, etc.) @return bool
isStartingWithSlash
php
phorgeit/phorge
src/infrastructure/parser/PhutilURIHelper.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/parser/PhutilURIHelper.php
Apache-2.0
public function __toString() { return $this->uriStr; }
A sane default.
__toString
php
phorgeit/phorge
src/infrastructure/parser/PhutilURIHelper.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/parser/PhutilURIHelper.php
Apache-2.0
private function isStartingWithChar($char) { return strncmp($this->uriStr, $char, 1) === 0; }
Check whenever the URI starts with the provided character. @param string $char String that MUST have length of 1. @return bool
isStartingWithChar
php
phorgeit/phorge
src/infrastructure/parser/PhutilURIHelper.php
https://github.com/phorgeit/phorge/blob/master/src/infrastructure/parser/PhutilURIHelper.php
Apache-2.0
function xhprof_error($message) { error_log($message); }
Copyright (c) 2009 Facebook Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. This file contains various XHProf library (utility) functions. Do not add any display specific code here.
xhprof_error
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_parse_parent_child($parent_child) { $ret = explode("==>", $parent_child); // Return if both parent and child are set if (isset($ret[1])) { return $ret; } return array(null, $ret[0]); }
Takes a parent/child function name encoded as "a==>b" and returns array("a", "b"). @author Kannan
xhprof_parse_parent_child
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_build_parent_child_key($parent, $child) { if ($parent) { return $parent . "==>" . $child; } else { return $child; } }
Given parent & child function name, composes the key in the format present in the raw data. @author Kannan
xhprof_build_parent_child_key
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_valid_run($run_id, $raw_data) { $main_info = $raw_data["main()"]; if (empty($main_info)) { xhprof_error("XHProf: main() missing in raw data for Run ID: $run_id"); return false; } // raw data should contain either wall time or samples information... if (isset($main_info["wt"])) { $metric = "wt"; } else if (isset($main_info["samples"])) { $metric = "samples"; } else { xhprof_error("XHProf: Wall Time information missing from Run ID: $run_id"); return false; } foreach ($raw_data as $info) { $val = $info[$metric]; // basic sanity checks... if ($val < 0) { xhprof_error("XHProf: $metric should not be negative: Run ID $run_id" . serialize($info)); return false; } if ($val > (86400000000)) { xhprof_error("XHProf: $metric > 1 day found in Run ID: $run_id " . serialize($info)); return false; } } return true; }
Checks if XHProf raw data appears to be valid and not corrupted. @param int $run_id Run id of run to be pruned. [Used only for reporting errors.] @param array $raw_data XHProf raw data to be pruned & validated. @return bool true on success, false on failure @author Kannan
xhprof_valid_run
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_normalize_metrics($raw_data, $num_runs) { if (empty($raw_data) || ($num_runs == 0)) { return $raw_data; } $raw_data_total = array(); if (isset($raw_data["==>main()"]) && isset($raw_data["main()"])) { xhprof_error("XHProf Error: both ==>main() and main() set in raw data..."); } foreach ($raw_data as $parent_child => $info) { foreach ($info as $metric => $value) { $raw_data_total[$parent_child][$metric] = ($value / $num_runs); } } return $raw_data_total; }
Takes raw XHProf data that was aggregated over "$num_runs" number of runs averages/nomalizes the data. Essentially the various metrics collected are divided by $num_runs. @author Kannan
xhprof_normalize_metrics
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_compute_diff($xhprof_data1, $xhprof_data2) { global $display_calls; // use the second run to decide what metrics we will do the diff on $metrics = xhprof_get_metrics($xhprof_data2); $xhprof_delta = $xhprof_data2; foreach ($xhprof_data1 as $parent_child => $info) { if (!isset($xhprof_delta[$parent_child])) { // this pc combination was not present in run1; // initialize all values to zero. if ($display_calls) { $xhprof_delta[$parent_child] = array("ct" => 0); } else { $xhprof_delta[$parent_child] = array(); } foreach ($metrics as $metric) { $xhprof_delta[$parent_child][$metric] = 0; } } if ($display_calls) { $xhprof_delta[$parent_child]["ct"] -= $info["ct"]; } foreach ($metrics as $metric) { $xhprof_delta[$parent_child][$metric] -= $info[$metric]; } } return $xhprof_delta; }
Hierarchical diff: Compute and return difference of two call graphs: Run2 - Run1. @author Kannan
xhprof_compute_diff
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_array_set($arr, $k, $v) { $arr[$k] = $v; return $arr; }
Set one key in an array and return the array @author Kannan
xhprof_array_set
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_array_unset($arr, $k) { unset($arr[$k]); return $arr; }
Removes/unsets one key in an array and return the array @author Kannan
xhprof_array_unset
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_get_param_helper($param) { $val = null; if (isset($_GET[$param])) $val = $_GET[$param]; else if (isset($_POST[$param])) { $val = $_POST[$param]; } return $val; }
Internal helper function used by various xhprof_get_param* flavors for various types of parameters. @param string name of the URL query string param @author Kannan
xhprof_get_param_helper
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_get_string_param($param, $default = '') { $val = xhprof_get_param_helper($param); if ($val === null) return $default; return $val; }
Extracts value for string param $param from query string. If param is not specified, return the $default value. @author Kannan
xhprof_get_string_param
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_get_uint_param($param, $default = 0) { $val = xhprof_get_param_helper($param); if ($val === null) $val = $default; // trim leading/trailing whitespace $val = trim($val); // if it only contains digits, then ok.. if (ctype_digit($val)) { return $val; } xhprof_error("$param is $val. It must be an unsigned integer."); return null; }
Extracts value for unsigned integer param $param from query string. If param is not specified, return the $default value. If value is not a valid unsigned integer, logs error and returns null. @author Kannan
xhprof_get_uint_param
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_get_float_param($param, $default = 0) { $val = xhprof_get_param_helper($param); if ($val === null) $val = $default; // trim leading/trailing whitespace $val = trim($val); // TBD: confirm the value is indeed a float. if (true) // for now.. return (float)$val; xhprof_error("$param is $val. It must be a float."); return null; }
Extracts value for a float param $param from query string. If param is not specified, return the $default value. If value is not a valid unsigned integer, logs error and returns null. @author Kannan
xhprof_get_float_param
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_get_bool_param($param, $default = false) { $val = xhprof_get_param_helper($param); if ($val === null) $val = $default; // trim leading/trailing whitespace $val = trim($val); switch (strtolower($val)) { case '0': case '1': $val = (bool)$val; break; case 'true': case 'on': case 'yes': $val = true; break; case 'false': case 'off': case 'no': $val = false; break; default: xhprof_error("$param is $val. It must be a valid boolean string."); return null; } return $val; }
Extracts value for a boolean param $param from query string. If param is not specified, return the $default value. If value is not a valid unsigned integer, logs error and returns null. @author Kannan
xhprof_get_bool_param
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
function xhprof_param_init($params) { /* Create variables specified in $params keys, init defaults */ foreach ($params as $k => $v) { switch ($v[0]) { case XHPROF_STRING_PARAM: $p = xhprof_get_string_param($k, $v[1]); break; case XHPROF_UINT_PARAM: $p = xhprof_get_uint_param($k, $v[1]); break; case XHPROF_FLOAT_PARAM: $p = xhprof_get_float_param($k, $v[1]); break; case XHPROF_BOOL_PARAM: $p = xhprof_get_bool_param($k, $v[1]); break; default: xhprof_error("Invalid param type passed to xhprof_param_init: " . $v[0]); exit(); } // create a global variable using the parameter name. $GLOBALS[$k] = $p; } }
Initialize params from URL query string. The function creates globals variables for each of the params and if the URL query string doesn't specify a particular param initializes them with the corresponding default value specified in the input. @params array $params An array whose keys are the names of URL params who value needs to be retrieved from the URL query string. PHP globals are created with these names. The value is itself an array with 2-elems (the param type, and its default value). If a param is not specified in the query string the default value is used. @author Kannan
xhprof_param_init
php
phorgeit/phorge
externals/xhprof/xhprof_lib.php
https://github.com/phorgeit/phorge/blob/master/externals/xhprof/xhprof_lib.php
Apache-2.0
public static function Stem($word) { if (strlen($word) <= 2) { return $word; } $word = self::step1ab($word); $word = self::step1c($word); $word = self::step2($word); $word = self::step3($word); $word = self::step4($word); $word = self::step5($word); return $word; }
Stems a word. Simple huh? @param string $word Word to stem @return string Stemmed word
Stem
php
phorgeit/phorge
externals/porter-stemmer/src/Porter.php
https://github.com/phorgeit/phorge/blob/master/externals/porter-stemmer/src/Porter.php
Apache-2.0
private static function step1ab($word) { // Part a if (substr($word, -1) == 's') { self::replace($word, 'sses', 'ss') OR self::replace($word, 'ies', 'i') OR self::replace($word, 'ss', 'ss') OR self::replace($word, 's', ''); } // Part b if (substr($word, -2, 1) != 'e' OR !self::replace($word, 'eed', 'ee', 0)) { // First rule $v = self::$regex_vowel; // ing and ed if ( preg_match("#$v+#", substr($word, 0, -3)) && self::replace($word, 'ing', '') OR preg_match("#$v+#", substr($word, 0, -2)) && self::replace($word, 'ed', '')) { // Note use of && and OR, for precedence reasons // If one of above two test successful if ( !self::replace($word, 'at', 'ate') AND !self::replace($word, 'bl', 'ble') AND !self::replace($word, 'iz', 'ize')) { // Double consonant ending if ( self::doubleConsonant($word) AND substr($word, -2) != 'll' AND substr($word, -2) != 'ss' AND substr($word, -2) != 'zz') { $word = substr($word, 0, -1); } elseif (self::m($word) == 1 AND self::cvc($word)) { $word .= 'e'; } } } } return $word; }
Step 1
step1ab
php
phorgeit/phorge
externals/porter-stemmer/src/Porter.php
https://github.com/phorgeit/phorge/blob/master/externals/porter-stemmer/src/Porter.php
Apache-2.0
private static function step1c($word) { $v = self::$regex_vowel; if (substr($word, -1) == 'y' && preg_match("#$v+#", substr($word, 0, -1))) { self::replace($word, 'y', 'i'); } return $word; }
Step 1c @param string $word Word to stem
step1c
php
phorgeit/phorge
externals/porter-stemmer/src/Porter.php
https://github.com/phorgeit/phorge/blob/master/externals/porter-stemmer/src/Porter.php
Apache-2.0
private static function step2($word) { switch (substr($word, -2, 1)) { case 'a': self::replace($word, 'ational', 'ate', 0) OR self::replace($word, 'tional', 'tion', 0); break; case 'c': self::replace($word, 'enci', 'ence', 0) OR self::replace($word, 'anci', 'ance', 0); break; case 'e': self::replace($word, 'izer', 'ize', 0); break; case 'g': self::replace($word, 'logi', 'log', 0); break; case 'l': self::replace($word, 'entli', 'ent', 0) OR self::replace($word, 'ousli', 'ous', 0) OR self::replace($word, 'alli', 'al', 0) OR self::replace($word, 'bli', 'ble', 0) OR self::replace($word, 'eli', 'e', 0); break; case 'o': self::replace($word, 'ization', 'ize', 0) OR self::replace($word, 'ation', 'ate', 0) OR self::replace($word, 'ator', 'ate', 0); break; case 's': self::replace($word, 'iveness', 'ive', 0) OR self::replace($word, 'fulness', 'ful', 0) OR self::replace($word, 'ousness', 'ous', 0) OR self::replace($word, 'alism', 'al', 0); break; case 't': self::replace($word, 'biliti', 'ble', 0) OR self::replace($word, 'aliti', 'al', 0) OR self::replace($word, 'iviti', 'ive', 0); break; } return $word; }
Step 2 @param string $word Word to stem
step2
php
phorgeit/phorge
externals/porter-stemmer/src/Porter.php
https://github.com/phorgeit/phorge/blob/master/externals/porter-stemmer/src/Porter.php
Apache-2.0
private static function step3($word) { switch (substr($word, -2, 1)) { case 'a': self::replace($word, 'ical', 'ic', 0); break; case 's': self::replace($word, 'ness', '', 0); break; case 't': self::replace($word, 'icate', 'ic', 0) OR self::replace($word, 'iciti', 'ic', 0); break; case 'u': self::replace($word, 'ful', '', 0); break; case 'v': self::replace($word, 'ative', '', 0); break; case 'z': self::replace($word, 'alize', 'al', 0); break; } return $word; }
Step 3 @param string $word String to stem
step3
php
phorgeit/phorge
externals/porter-stemmer/src/Porter.php
https://github.com/phorgeit/phorge/blob/master/externals/porter-stemmer/src/Porter.php
Apache-2.0
private static function step4($word) { switch (substr($word, -2, 1)) { case 'a': self::replace($word, 'al', '', 1); break; case 'c': self::replace($word, 'ance', '', 1) OR self::replace($word, 'ence', '', 1); break; case 'e': self::replace($word, 'er', '', 1); break; case 'i': self::replace($word, 'ic', '', 1); break; case 'l': self::replace($word, 'able', '', 1) OR self::replace($word, 'ible', '', 1); break; case 'n': self::replace($word, 'ant', '', 1) OR self::replace($word, 'ement', '', 1) OR self::replace($word, 'ment', '', 1) OR self::replace($word, 'ent', '', 1); break; case 'o': if (substr($word, -4) == 'tion' OR substr($word, -4) == 'sion') { self::replace($word, 'ion', '', 1); } else { self::replace($word, 'ou', '', 1); } break; case 's': self::replace($word, 'ism', '', 1); break; case 't': self::replace($word, 'ate', '', 1) OR self::replace($word, 'iti', '', 1); break; case 'u': self::replace($word, 'ous', '', 1); break; case 'v': self::replace($word, 'ive', '', 1); break; case 'z': self::replace($word, 'ize', '', 1); break; } return $word; }
Step 4 @param string $word Word to stem
step4
php
phorgeit/phorge
externals/porter-stemmer/src/Porter.php
https://github.com/phorgeit/phorge/blob/master/externals/porter-stemmer/src/Porter.php
Apache-2.0
private static function step5($word) { // Part a if (substr($word, -1) == 'e') { if (self::m(substr($word, 0, -1)) > 1) { self::replace($word, 'e', ''); } elseif (self::m(substr($word, 0, -1)) == 1) { if (!self::cvc(substr($word, 0, -1))) { self::replace($word, 'e', ''); } } } // Part b if (self::m($word) > 1 AND self::doubleConsonant($word) AND substr($word, -1) == 'l') { $word = substr($word, 0, -1); } return $word; }
Step 5 @param string $word Word to stem
step5
php
phorgeit/phorge
externals/porter-stemmer/src/Porter.php
https://github.com/phorgeit/phorge/blob/master/externals/porter-stemmer/src/Porter.php
Apache-2.0
private static function replace(&$str, $check, $repl, $m = null) { $len = 0 - strlen($check); if (substr($str, $len) == $check) { $substr = substr($str, 0, $len); if (is_null($m) OR self::m($substr) > $m) { $str = $substr . $repl; } return true; } return false; }
Replaces the first string with the second, at the end of the string If third arg is given, then the preceding string must match that m count at least. @param string $str String to check @param string $check Ending to check for @param string $repl Replacement string @param int $m Optional minimum number of m() to meet @return bool Whether the $check string was at the end of the $str string. True does not necessarily mean that it was replaced.
replace
php
phorgeit/phorge
externals/porter-stemmer/src/Porter.php
https://github.com/phorgeit/phorge/blob/master/externals/porter-stemmer/src/Porter.php
Apache-2.0
private static function m($str) { $c = self::$regex_consonant; $v = self::$regex_vowel; $str = preg_replace("#^$c+#", '', $str); $str = preg_replace("#$v+$#", '', $str); preg_match_all("#($v+$c+)#", $str, $matches); return count($matches[1]); }
What, you mean it's not obvious from the name? m() measures the number of consonant sequences in $str. if c is a consonant sequence and v a vowel sequence, and <..> indicates arbitrary presence, <c><v> gives 0 <c>vc<v> gives 1 <c>vcvc<v> gives 2 <c>vcvcvc<v> gives 3 @param string $str The string to return the m count for @return int The m count
m
php
phorgeit/phorge
externals/porter-stemmer/src/Porter.php
https://github.com/phorgeit/phorge/blob/master/externals/porter-stemmer/src/Porter.php
Apache-2.0
private static function doubleConsonant($str) { $c = self::$regex_consonant; return preg_match("#$c{2}$#", $str, $matches) AND $matches[0][0] == $matches[0][1]; }
Returns true/false as to whether the given string contains two of the same consonant next to each other at the end of the string. @param string $str String to check @return bool Result
doubleConsonant
php
phorgeit/phorge
externals/porter-stemmer/src/Porter.php
https://github.com/phorgeit/phorge/blob/master/externals/porter-stemmer/src/Porter.php
Apache-2.0
private static function cvc($str) { $c = self::$regex_consonant; $v = self::$regex_vowel; return preg_match("#($c$v$c)$#", $str, $matches) AND strlen($matches[1]) == 3 AND $matches[1][2] != 'w' AND $matches[1][2] != 'x' AND $matches[1][2] != 'y'; }
Checks for ending CVC sequence where second C is not W, X or Y @param string $str String to check @return bool Result
cvc
php
phorgeit/phorge
externals/porter-stemmer/src/Porter.php
https://github.com/phorgeit/phorge/blob/master/externals/porter-stemmer/src/Porter.php
Apache-2.0
function loadFont($filename, $loadgerman = true) { $this->font = array(); if (!file_exists($filename)) { return self::raiseError('Figlet font file "' . $filename . '" cannot be found', 1); } $this->font_comment = ''; // If Gzip compressed font if (substr($filename, -3, 3) == '.gz') { $filename = 'compress.zlib://' . $filename; $compressed = true; if (!function_exists('gzcompress')) { return self::raiseError('Cannot load gzip compressed fonts since' . ' gzcompress() is not available.', 3); } } else { $compressed = false; } if (!($fp = fopen($filename, 'rb'))) { return self::raiseError('Cannot open figlet font file ' . $filename, 2); } if (!$compressed) { /* ZIPed font */ if (fread($fp, 2) == 'PK') { fclose($fp); $zip = new ZipArchive(); $zip_flags = 0; if(defined('ZipArchive::RDONLY')) { $zip_flags = ZipArchive::RDONLY; // Flag available since PHP 7.4, unnecessary before } $open_result = $zip->open($filename, $zip_flags); if ($open_result !== true) { return self::raiseError('Cannot open figlet font file ' . $filename . ', got error: ' . $open_result, 2); } $name = $zip->getNameIndex(0); $zip->close(); if (!($fp = fopen('zip://' . realpath($filename) . '#' . $name, 'rb'))) { return self::raiseError('Cannot open figlet font file ' . $filename, 2); } $compressed = true; } else { flock($fp, LOCK_SH); rewind($fp); } } // flf2a$ 6 5 20 15 3 0 143 229 // | | | | | | | | | | // / / | | | | | | | \ // Signature / / | | | | | \ Codetag_Count // Hardblank / / | | | \ Full_Layout // Height / | | \ Print_Direction // Baseline / \ Comment_Lines // Max_Length Old_Layout $header = explode(' ', fgets($fp, 2048)); if (substr($header[0], 0, 5) <> 'flf2a') { return self::raiseError('Unknown FIGlet font format.', 4); } @list ($this->hardblank, $this->height,,, $this->oldlayout, $cmt_count, $this->rtol) = $header; $this->hardblank = substr($this->hardblank, -1, 1); for ($i = 0; $i < $cmt_count; $i++) { $this->font_comment .= fgets($fp, 2048); } // ASCII charcters for ($i = 32; $i < 127; $i++) { $this->font[$i] = $this->_char($fp); } foreach (array(196, 214, 220, 228, 246, 252, 223) as $i) { if ($loadgerman) { $letter = $this->_char($fp); // Invalid character but main font is loaded and I can use it if ($letter === false) { fclose($fp); return true; } // Load if it is not blank only if (trim(implode('', $letter)) <> '') { $this->font[$i] = $letter; } } else { $this->_skip($fp); } } // Extented characters for ($n = 0; !feof($fp); $n++) { list ($i) = explode(' ', rtrim(fgets($fp, 1024)), 2); if ($i == '') { continue; } // If comment if (preg_match('/^\-0x/i', $i)) { $this->_skip($fp); } else { // If Unicode if (preg_match('/^0x/i', $i)) { $i = hexdec(substr($i, 2)); } else { // If octal if ($i[0] === '0' && $i !== '0' || substr($i, 0, 2) == '-0') { $i = octdec($i); } } $letter = $this->_char($fp); // Invalid character but main font is loaded and I can use it if ($letter === false) { fclose($fp); return true; } $this->font[$i] = $letter; } } fclose($fp); return true; }
Load user font. Must be invoked first. Automatically tries the Text_Figlet font data directory as long as no path separator is in the filename. @param string $filename font file name @param bool $loadgerman (optional) load German character set or not @access public @return mixed PEAR_Error or true for success
loadFont
php
phorgeit/phorge
externals/pear-figlet/Text/Figlet.php
https://github.com/phorgeit/phorge/blob/master/externals/pear-figlet/Text/Figlet.php
Apache-2.0
function _char(&$fp) { $out = array(); for ($i = 0; $i < $this->height; $i++) { if (feof($fp)) { return false; } $line = rtrim(fgets($fp, 2048), "\r\n"); if (preg_match('/(.){1,2}$/', $line, $r)) { $line = str_replace($r[1], '', $line); } $line .= "\x00"; $out[] = $line; } return $out; }
Function loads one character in the internal array from file @param resource &$fp handle of font file @return mixed lines of the character or false if foef occured @access private
_char
php
phorgeit/phorge
externals/pear-figlet/Text/Figlet.php
https://github.com/phorgeit/phorge/blob/master/externals/pear-figlet/Text/Figlet.php
Apache-2.0
function _skip(&$fp) { for ($i = 0; $i<$this->height && !feof($fp); $i++) { fgets($fp, 2048); } return true; }
Function for skipping one character in a font file @param resource &$fp handle of font file @return boolean always return true @access private
_skip
php
phorgeit/phorge
externals/pear-figlet/Text/Figlet.php
https://github.com/phorgeit/phorge/blob/master/externals/pear-figlet/Text/Figlet.php
Apache-2.0
public function __construct( $filename, $contentType, $stream, $contentDisposition = 'attachment', $contentId = '', $headers = [], $mimePartStr = '' ) { $this->filename = $filename; $this->contentType = $contentType; $this->stream = $stream; $this->content = null; $this->contentDisposition = $contentDisposition; $this->contentId = $contentId; $this->headers = $headers; $this->mimePartStr = $mimePartStr; }
Attachment constructor. @param string $filename @param string $contentType @param resource $stream @param string $contentDisposition @param string $contentId @param array $headers @param string $mimePartStr
__construct
php
phorgeit/phorge
externals/mimemailparser/Attachment.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Attachment.php
Apache-2.0
public function getFilename() { return $this->filename; }
retrieve the attachment filename @return string
getFilename
php
phorgeit/phorge
externals/mimemailparser/Attachment.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Attachment.php
Apache-2.0
public function getContentType() { return $this->contentType; }
Retrieve the Attachment Content-Type @return string
getContentType
php
phorgeit/phorge
externals/mimemailparser/Attachment.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Attachment.php
Apache-2.0
public function getContentDisposition() { return $this->contentDisposition; }
Retrieve the Attachment Content-Disposition @return string
getContentDisposition
php
phorgeit/phorge
externals/mimemailparser/Attachment.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Attachment.php
Apache-2.0
public function getContentID() { return $this->contentId; }
Retrieve the Attachment Content-ID @return string
getContentID
php
phorgeit/phorge
externals/mimemailparser/Attachment.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Attachment.php
Apache-2.0
public function getHeaders() { return $this->headers; }
Retrieve the Attachment Headers @return array
getHeaders
php
phorgeit/phorge
externals/mimemailparser/Attachment.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Attachment.php
Apache-2.0
public function getStream() { return $this->stream; }
Get a handle to the stream @return resource
getStream
php
phorgeit/phorge
externals/mimemailparser/Attachment.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Attachment.php
Apache-2.0
public function read($bytes = 2082) { return feof($this->stream) ? false : fread($this->stream, $bytes); }
Read the contents a few bytes at a time until completed Once read to completion, it always returns false @param int $bytes (default: 2082) @return string|bool
read
php
phorgeit/phorge
externals/mimemailparser/Attachment.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Attachment.php
Apache-2.0
public function getContent() { if ($this->content === null) { fseek($this->stream, 0); while (($buf = $this->read()) !== false) { $this->content .= $buf; } } return $this->content; }
Retrieve the file content in one go Once you retrieve the content you cannot use MimeMailParser_attachment::read() @return string
getContent
php
phorgeit/phorge
externals/mimemailparser/Attachment.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Attachment.php
Apache-2.0
public function getMimePartStr() { return $this->mimePartStr; }
Get mime part string for this attachment @return string
getMimePartStr
php
phorgeit/phorge
externals/mimemailparser/Attachment.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Attachment.php
Apache-2.0
public function save( $attach_dir, $filenameStrategy = Parser::ATTACHMENT_DUPLICATE_SUFFIX ) { $attach_dir = rtrim($attach_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; if (!is_dir($attach_dir)) { mkdir($attach_dir); } // Determine filename switch ($filenameStrategy) { case Parser::ATTACHMENT_RANDOM_FILENAME: $fileInfo = pathinfo($this->getFilename()); $extension = empty($fileInfo['extension']) ? '' : '.'.$fileInfo['extension']; $attachment_path = $attach_dir.uniqid().$extension; break; case Parser::ATTACHMENT_DUPLICATE_THROW: case Parser::ATTACHMENT_DUPLICATE_SUFFIX: $attachment_path = $attach_dir.$this->getFilename(); break; default: throw new Exception('Invalid filename strategy argument provided.'); } // Handle duplicate filename if (file_exists($attachment_path)) { switch ($filenameStrategy) { case Parser::ATTACHMENT_DUPLICATE_THROW: throw new Exception('Could not create file for attachment: duplicate filename.'); case Parser::ATTACHMENT_DUPLICATE_SUFFIX: $attachment_path = $this->suffixFileName($attachment_path); break; } } /** @var resource $fp */ if ($fp = fopen($attachment_path, 'w')) { while ($bytes = $this->read()) { fwrite($fp, $bytes); } fclose($fp); return realpath($attachment_path); } else { throw new Exception('Could not write attachments. Your directory may be unwritable by PHP.'); } }
Save the attachment individually @param string $attach_dir @param string $filenameStrategy @return string
save
php
phorgeit/phorge
externals/mimemailparser/Attachment.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Attachment.php
Apache-2.0
public function __construct(?MiddleWareContracts $middleware = null) { $this->middleware = $middleware; }
Construct the first middleware in this MiddlewareStack The next middleware is chained through $MiddlewareStack->add($Middleware) @param Middleware $middleware
__construct
php
phorgeit/phorge
externals/mimemailparser/MiddlewareStack.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/MiddlewareStack.php
Apache-2.0
public function add(MiddleWareContracts $middleware) { $stack = new static($middleware); $stack->next = $this; return $stack; }
Creates a chained middleware in MiddlewareStack @param Middleware $middleware @return MiddlewareStack Immutable MiddlewareStack
add
php
phorgeit/phorge
externals/mimemailparser/MiddlewareStack.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/MiddlewareStack.php
Apache-2.0
public function parse(MimePart $part) { if (!$this->middleware) { return $part; } $part = call_user_func(array($this->middleware, 'parse'), $part, $this->next); return $part; }
Parses the MimePart by passing it through the Middleware @param MimePart $part @return MimePart
parse
php
phorgeit/phorge
externals/mimemailparser/MiddlewareStack.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/MiddlewareStack.php
Apache-2.0
public function __invoke(MimePart $part) { return $this->parse($part); }
Allow calling MiddlewareStack instance directly to invoke parse() @param MimePart $part @return MimePart
__invoke
php
phorgeit/phorge
externals/mimemailparser/MiddlewareStack.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/MiddlewareStack.php
Apache-2.0
public function __construct(?CharsetManager $charset = null) { if ($charset == null) { $charset = new Charset(); } $this->charset = $charset; $this->middlewareStack = new MiddlewareStack(); }
Parser constructor. @param CharsetManager|null $charset
__construct
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function __destruct() { // clear the email file resource if (is_resource($this->stream)) { fclose($this->stream); } // clear the MailParse resource if (is_resource($this->resource)) { mailparse_msg_free($this->resource); } }
Free the held resources @return void
__destruct
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function setPath($path) { if (is_writable($path)) { $file = fopen($path, 'a+'); fseek($file, -1, SEEK_END); if (fread($file, 1) != "\n") { fwrite($file, PHP_EOL); } fclose($file); } // should parse message incrementally from file $this->resource = mailparse_msg_parse_file($path); $this->stream = fopen($path, 'r'); $this->parse(); return $this; }
Set the file path we use to get the email text @param string $path File path to the MIME mail @return Parser MimeMailParser Instance
setPath
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function setStream($stream) { // streams have to be cached to file first $meta = @stream_get_meta_data($stream); if (!$meta || !$meta['mode'] || !in_array($meta['mode'], self::$readableModes, true)) { throw new Exception( 'setStream() expects parameter stream to be readable stream resource.' ); } /** @var resource $tmp_fp */ $tmp_fp = tmpfile(); if ($tmp_fp) { while (!feof($stream)) { fwrite($tmp_fp, fread($stream, 2028)); } if (fread($tmp_fp, 1) != "\n") { fwrite($tmp_fp, PHP_EOL); } fseek($tmp_fp, 0); $this->stream = &$tmp_fp; } else { throw new Exception( 'Could not create temporary files for attachments. Your tmp directory may be unwritable by PHP.' ); } fclose($stream); $this->resource = mailparse_msg_create(); // parses the message incrementally (low memory usage but slower) while (!feof($this->stream)) { mailparse_msg_parse($this->resource, fread($this->stream, 2082)); } $this->parse(); return $this; }
Set the Stream resource we use to get the email text @param resource $stream @return Parser MimeMailParser Instance @throws Exception
setStream
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function setText($data) { if (empty($data)) { throw new Exception('You must not call MimeMailParser::setText with an empty string parameter'); } if (substr($data, -1) != "\n") { $data = $data.PHP_EOL; } $this->resource = mailparse_msg_create(); // does not parse incrementally, fast memory hog might explode mailparse_msg_parse($this->resource, $data); $this->data = $data; $this->parse(); return $this; }
Set the email text @param string $data @return Parser MimeMailParser Instance
setText
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function getRawHeader($name) { $name = strtolower($name); if (isset($this->parts[1])) { $headers = $this->getPart('headers', $this->parts[1]); return isset($headers[$name]) ? $headers[$name] : false; } else { throw new Exception( 'setPath() or setText() or setStream() must be called before retrieving email headers.' ); } }
Retrieve a specific Email Header, without charset conversion. @param string $name Header name (case-insensitive) @return string|bool @throws Exception
getRawHeader
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function getHeader($name) { $rawHeader = $this->getRawHeader($name); if ($rawHeader === false) { return false; } return $this->decodeHeader($rawHeader); }
Retrieve a specific Email Header @param string $name Header name (case-insensitive) @return string|false
getHeader
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function getHeadersRaw() { if (isset($this->parts[1])) { return $this->getPartHeader($this->parts[1]); } else { throw new Exception( 'setPath() or setText() or setStream() must be called before retrieving email headers.' ); } }
Retrieve the raw mail headers as a string @return string @throws Exception
getHeadersRaw
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
protected function getPartHeaderFromFile(&$part) { $start = $part['starting-pos']; $end = $part['starting-pos-body']; fseek($this->stream, $start, SEEK_SET); $header = fread($this->stream, $end - $start); return $header; }
Retrieve the Header from a MIME part from file @return String Mime Header Part @param $part Array
getPartHeaderFromFile
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
protected function getPartHeaderFromText(&$part) { $start = $part['starting-pos']; $end = $part['starting-pos-body']; $header = substr($this->data, $start, $end - $start); return $header; }
Retrieve the Header from a MIME part from text @return String Mime Header Part @param $part Array
getPartHeaderFromText
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
protected function partIdIsChildOfPart($partId, $parentPartId) { $parentPartId = $parentPartId.'.'; return substr($partId, 0, strlen($parentPartId)) == $parentPartId; }
Checks whether a given part ID is a child of another part eg. an RFC822 attachment may have one or more text parts @param string $partId @param string $parentPartId @return bool
partIdIsChildOfPart
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
protected function partIdIsChildOfAnAttachment($checkPartId) { foreach ($this->parts as $partId => $part) { if ($this->getPart('content-disposition', $part) == 'attachment') { if ($this->partIdIsChildOfPart($checkPartId, $partId)) { return true; } } } return false; }
Whether the given part ID is a child of any attachment part in the message. @param string $checkPartId @return bool
partIdIsChildOfAnAttachment
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function getMessageBody($type = 'text') { $mime_types = [ 'text' => 'text/plain', 'html' => 'text/html', 'htmlEmbedded' => 'text/html', ]; if (in_array($type, array_keys($mime_types))) { $part_type = $type === 'htmlEmbedded' ? 'html' : $type; $inline_parts = $this->getInlineParts($part_type); $body = empty($inline_parts) ? '' : $inline_parts[0]; } else { throw new Exception( 'Invalid type specified for getMessageBody(). Expected: text, html or htmlEmbeded.' ); } if ($type == 'htmlEmbedded') { $attachments = $this->getAttachments(); foreach ($attachments as $attachment) { if ($attachment->getContentID() != '') { $body = str_replace( '"cid:'.$attachment->getContentID().'"', '"'.$this->getEmbeddedData($attachment->getContentID()).'"', $body ); } } } return $body; }
Returns the email message body in the specified format @param string $type text, html or htmlEmbedded @return string Body @throws Exception
getMessageBody
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
protected function getEmbeddedData($contentId) { foreach ($this->parts as $part) { if ($this->getPart('content-id', $part) == $contentId) { $embeddedData = 'data:'; $embeddedData .= $this->getPart('content-type', $part); $embeddedData .= ';'.$this->getPart('transfer-encoding', $part); $embeddedData .= ','.$this->getPartBody($part); return $embeddedData; } } return ''; }
Returns the embedded data structure @param string $contentId Content-Id @return string
getEmbeddedData
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function getInlineParts($type = 'text') { $inline_parts = []; $mime_types = [ 'text' => 'text/plain', 'html' => 'text/html', ]; if (!in_array($type, array_keys($mime_types))) { throw new Exception('Invalid type specified for getInlineParts(). "type" can either be text or html.'); } foreach ($this->parts as $partId => $part) { if ($this->getPart('content-type', $part) == $mime_types[$type] && $this->getPart('content-disposition', $part) != 'attachment' && !$this->partIdIsChildOfAnAttachment($partId) ) { $headers = $this->getPart('headers', $part); $encodingType = array_key_exists('content-transfer-encoding', $headers) ? $headers['content-transfer-encoding'] : ''; $undecoded_body = $this->decodeContentTransfer($this->getPartBody($part), $encodingType); $inline_parts[] = $this->charset->decodeCharset($undecoded_body, $this->getPartCharset($part)); } } return $inline_parts; }
Returns the attachments contents in order of appearance @return Attachment[]
getInlineParts
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
protected function decodeHeader($input) { //Sometimes we have 2 label From so we take only the first if (is_array($input)) { return $this->decodeSingleHeader($input[0]); } return $this->decodeSingleHeader($input); }
$input can be a string or array @param string|array $input @return string
decodeHeader
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
protected function getPartCharset($part) { if (isset($part['charset'])) { return $this->charset->getCharsetAlias($part['charset']); } else { return 'us-ascii'; } }
Return the charset of the MIME part @param array $part @return string
getPartCharset
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
protected function getPart($type, $parts) { return (isset($parts[$type])) ? $parts[$type] : false; }
Retrieve a specified MIME part @param string $type @param array $parts @return string|array
getPart
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
protected function getPartBodyFromFile(&$part) { $start = $part['starting-pos-body']; $end = $part['ending-pos-body']; $body = ''; if ($end - $start > 0) { fseek($this->stream, $start, SEEK_SET); $body = fread($this->stream, $end - $start); } return $body; }
Retrieve the Body from a MIME part from file @param array $part @return string Mime Body Part
getPartBodyFromFile
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
protected function getPartBodyFromText(&$part) { $start = $part['starting-pos-body']; $end = $part['ending-pos-body']; return substr($this->data, $start, $end - $start); }
Retrieve the Body from a MIME part from text @param array $part @return string Mime Body Part
getPartBodyFromText
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
protected function getPartFromFile(&$part) { $start = $part['starting-pos']; $end = $part['ending-pos']; $body = ''; if ($end - $start > 0) { fseek($this->stream, $start, SEEK_SET); $body = fread($this->stream, $end - $start); } return $body; }
Retrieve the content from a MIME part from file @param array $part @return string Mime Content
getPartFromFile
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
protected function getPartFromText(&$part) { $start = $part['starting-pos']; $end = $part['ending-pos']; return substr($this->data, $start, $end - $start); }
Retrieve the content from a MIME part from text @param array $part @return string Mime Content
getPartFromText
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function getResource() { return $this->resource; }
Retrieve the resource @return resource resource
getResource
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function getStream() { return $this->stream; }
Retrieve the file pointer to email @return resource stream
getStream
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function getData() { return $this->data; }
Retrieve the text of an email @return string data
getData
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function getParts() { return $this->parts; }
Retrieve the parts of an email @return array parts
getParts
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function getCharset() { return $this->charset; }
Retrieve the charset manager object @return CharsetManager charset
getCharset
php
phorgeit/phorge
externals/mimemailparser/Parser.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Parser.php
Apache-2.0
public function __construct($id, array $part) { $this->part = $part; $this->id = $id; }
Create a mime part @param array $part @param string $id
__construct
php
phorgeit/phorge
externals/mimemailparser/MimePart.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/MimePart.php
Apache-2.0
public function getId() { return $this->id; }
Retrieve the part Id @return string
getId
php
phorgeit/phorge
externals/mimemailparser/MimePart.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/MimePart.php
Apache-2.0
public function getPart() { return $this->part; }
Retrieve the part data @return array
getPart
php
phorgeit/phorge
externals/mimemailparser/MimePart.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/MimePart.php
Apache-2.0
public function setPart(array $part) { $this->part = $part; }
Set the mime part data @param array $part @return void
setPart
php
phorgeit/phorge
externals/mimemailparser/MimePart.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/MimePart.php
Apache-2.0
public function offsetSet($offset, $value) { if (is_null($offset)) { $this->part[] = $value; return; } $this->part[$offset] = $value; }
[\ReturnTypeWillChange]
offsetSet
php
phorgeit/phorge
externals/mimemailparser/MimePart.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/MimePart.php
Apache-2.0
public function offsetExists($offset) { return isset($this->part[$offset]); }
[\ReturnTypeWillChange]
offsetExists
php
phorgeit/phorge
externals/mimemailparser/MimePart.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/MimePart.php
Apache-2.0
public function offsetUnset($offset) { unset($this->part[$offset]); }
[\ReturnTypeWillChange]
offsetUnset
php
phorgeit/phorge
externals/mimemailparser/MimePart.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/MimePart.php
Apache-2.0
public function offsetGet($offset) { return isset($this->part[$offset]) ? $this->part[$offset] : null; }
[\ReturnTypeWillChange]
offsetGet
php
phorgeit/phorge
externals/mimemailparser/MimePart.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/MimePart.php
Apache-2.0
public function __construct(callable $fn) { $this->parser = $fn; }
Create a middleware using a callable $fn @param callable $fn
__construct
php
phorgeit/phorge
externals/mimemailparser/Middleware.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Middleware.php
Apache-2.0
public function parse(MimePart $part, MiddlewareStack $next) { return call_user_func($this->parser, $part, $next); }
Process a mime part, optionally delegating parsing to the $next MiddlewareStack
parse
php
phorgeit/phorge
externals/mimemailparser/Middleware.php
https://github.com/phorgeit/phorge/blob/master/externals/mimemailparser/Middleware.php
Apache-2.0
function jsShrink($input) { return preg_replace_callback('( (?: (`(?:\\\\.|[^`\\\\])*`) # template literal |(^|[-+\([{}=,:;!%^&*|?~]|/(?![/*])|return|throw) # context before regexp (?:\s|//[^\n]*+\n|/\*(?:[^*]|\*(?!/))*+\*/)* # optional space (/(?![/*])(?: \\\\[^\n] |[^[\n/\\\\]++ |\[(?:\\\\[^\n]|[^]])++ )+/) # regexp |(^ |\'(?:\\\\.|[^\n\'\\\\])*\' |"(?:\\\\.|[^\n"\\\\])*" |([0-9A-Za-z_$]+) |([-+]+) |. ) )(?:\s|//[^\n]*+\n|/\*(?:[^*]|\*(?!/))*+\*/)* # optional space )sx', 'jsShrinkCallback', "$input\n"); }
Remove spaces and comments from JavaScript code @param string code with commands terminated by semicolon @return string shrinked code @link http://vrana.github.com/JsShrink/ @author Jakub Vrana, http://www.vrana.cz/ @copyright 2007 Jakub Vrana @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
jsShrink
php
phorgeit/phorge
externals/JsShrink/jsShrink.php
https://github.com/phorgeit/phorge/blob/master/externals/JsShrink/jsShrink.php
Apache-2.0
public static function binarize($frame) { $len = count($frame); foreach ($frame as &$frameLine) { for($i=0; $i<$len; $i++) { $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; } } return $frame; }
----------------------------------------------------------------------
binarize
php
phorgeit/phorge
externals/phpqrcode/phpqrcode.php
https://github.com/phorgeit/phorge/blob/master/externals/phpqrcode/phpqrcode.php
Apache-2.0