s around
+ # "paragraphs" that are wrapped in non-block-level tags, such as anchors,
+ # phrase emphasis, and spans. The list of tags we're looking for is
+ # hard-coded:
+ #
+ # * List "a" is made of tags which can be both inline or block-level.
+ # These will be treated block-level when the start tag is alone on
+ # its line, otherwise they're not matched here and will be taken as
+ # inline later.
+ # * List "b" is made of tags which are always block-level;
+ #
+ $block_tags_a_re = 'ins|del';
+ $block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|'.
+ 'script|noscript|form|fieldset|iframe|math|svg|'.
+ 'article|section|nav|aside|hgroup|header|footer|'.
+ 'figure';
+
+ # Regular expression for the content of a block tag.
+ $nested_tags_level = 4;
+ $attr = '
+ (?> # optional tag attributes
+ \s # starts with whitespace
+ (?>
+ [^>"/]+ # text outside quotes
+ |
+ /+(?!>) # slash not followed by ">"
+ |
+ "[^"]*" # text inside double quotes (tolerate ">")
+ |
+ \'[^\']*\' # text inside single quotes (tolerate ">")
+ )*
+ )?
+ ';
+ $content =
+ str_repeat('
+ (?>
+ [^<]+ # content without tag
+ |
+ <\2 # nested opening tag
+ '.$attr.' # attributes
+ (?>
+ />
+ |
+ >', $nested_tags_level). # end of opening tag
+ '.*?'. # last level nested tag content
+ str_repeat('
+ \2\s*> # closing nested tag
+ )
+ |
+ <(?!/\2\s*> # other tags with a different name
+ )
+ )*',
+ $nested_tags_level);
+ $content2 = str_replace('\2', '\3', $content);
+
+ # First, look for nested blocks, e.g.:
+ #
).
+ "doAutoLinks" => 30,
+ "encodeAmpsAndAngles" => 40,
+
+ "doItalicsAndBold" => 50,
+ "doHardBreaks" => 60,
+ );
+
+ protected function runSpanGamut($text) {
+ #
+ # Run span gamut tranformations.
+ #
+ foreach ($this->span_gamut as $method => $priority) {
+ $text = $this->$method($text);
+ }
+
+ return $text;
+ }
+
+
+ protected function doHardBreaks($text) {
+ # Do hard breaks:
+ return preg_replace_callback('/ {2,}\n/',
+ array(&$this, '_doHardBreaks_callback'), $text);
+ }
+ protected function _doHardBreaks_callback($matches) {
+ return $this->hashPart("
empty_element_suffix\n");
+ }
+
+
+ protected function doAnchors($text) {
+ #
+ # Turn Markdown link shortcuts into XHTML tags.
+ #
+ if ($this->in_anchor) return $text;
+ $this->in_anchor = true;
+
+ #
+ # First, handle reference-style links: [link text] [id]
+ #
+ $text = preg_replace_callback('{
+ ( # wrap whole match in $1
+ \[
+ ('.$this->nested_brackets_re.') # link text = $2
+ \]
+
+ [ ]? # one optional space
+ (?:\n[ ]*)? # one optional newline followed by spaces
+
+ \[
+ (.*?) # id = $3
+ \]
+ )
+ }xs',
+ array(&$this, '_doAnchors_reference_callback'), $text);
+
+ #
+ # Next, inline-style links: [link text](url "optional title")
+ #
+ $text = preg_replace_callback('{
+ ( # wrap whole match in $1
+ \[
+ ('.$this->nested_brackets_re.') # link text = $2
+ \]
+ \( # literal paren
+ [ \n]*
+ (?:
+ <(.+?)> # href = $3
+ |
+ ('.$this->nested_url_parenthesis_re.') # href = $4
+ )
+ [ \n]*
+ ( # $5
+ ([\'"]) # quote char = $6
+ (.*?) # Title = $7
+ \6 # matching quote
+ [ \n]* # ignore any spaces/tabs between closing quote and )
+ )? # title is optional
+ \)
+ )
+ }xs',
+ array(&$this, '_doAnchors_inline_callback'), $text);
+
+ #
+ # Last, handle reference-style shortcuts: [link text]
+ # These must come last in case you've also got [link text][1]
+ # or [link text](/foo)
+ #
+ $text = preg_replace_callback('{
+ ( # wrap whole match in $1
+ \[
+ ([^\[\]]+) # link text = $2; can\'t contain [ or ]
+ \]
+ )
+ }xs',
+ array(&$this, '_doAnchors_reference_callback'), $text);
+
+ $this->in_anchor = false;
+ return $text;
+ }
+ protected function _doAnchors_reference_callback($matches) {
+ $whole_match = $matches[1];
+ $link_text = $matches[2];
+ $link_id =& $matches[3];
+
+ if ($link_id == "") {
+ # for shortcut links like [this][] or [this].
+ $link_id = $link_text;
+ }
+
+ # lower-case and turn embedded newlines into spaces
+ $link_id = strtolower($link_id);
+ $link_id = preg_replace('{[ ]?\n}', ' ', $link_id);
+
+ if (isset($this->urls[$link_id])) {
+ $url = $this->urls[$link_id];
+ $url = $this->encodeAttribute($url);
+
+ $result = "titles[$link_id] ) ) {
+ $title = $this->titles[$link_id];
+ $title = $this->encodeAttribute($title);
+ $result .= " title=\"$title\"";
+ }
+
+ $link_text = $this->runSpanGamut($link_text);
+ $result .= ">$link_text";
+ $result = $this->hashPart($result);
+ }
+ else {
+ $result = $whole_match;
+ }
+ return $result;
+ }
+ protected function _doAnchors_inline_callback($matches) {
+ $whole_match = $matches[1];
+ $link_text = $this->runSpanGamut($matches[2]);
+ $url = $matches[3] == '' ? $matches[4] : $matches[3];
+ $title =& $matches[7];
+
+ $url = $this->encodeAttribute($url);
+
+ $result = "encodeAttribute($title);
+ $result .= " title=\"$title\"";
+ }
+
+ $link_text = $this->runSpanGamut($link_text);
+ $result .= ">$link_text";
+
+ return $this->hashPart($result);
+ }
+
+
+ protected function doImages($text) {
+ #
+ # Turn Markdown image shortcuts into tags.
+ #
+ #
+ # First, handle reference-style labeled images: ![alt text][id]
+ #
+ $text = preg_replace_callback('{
+ ( # wrap whole match in $1
+ !\[
+ ('.$this->nested_brackets_re.') # alt text = $2
+ \]
+
+ [ ]? # one optional space
+ (?:\n[ ]*)? # one optional newline followed by spaces
+
+ \[
+ (.*?) # id = $3
+ \]
+
+ )
+ }xs',
+ array(&$this, '_doImages_reference_callback'), $text);
+
+ #
+ # Next, handle inline images: ![alt text](url "optional title")
+ # Don't forget: encode * and _
+ #
+ $text = preg_replace_callback('{
+ ( # wrap whole match in $1
+ !\[
+ ('.$this->nested_brackets_re.') # alt text = $2
+ \]
+ \s? # One optional whitespace character
+ \( # literal paren
+ [ \n]*
+ (?:
+ <(\S*)> # src url = $3
+ |
+ ('.$this->nested_url_parenthesis_re.') # src url = $4
+ )
+ [ \n]*
+ ( # $5
+ ([\'"]) # quote char = $6
+ (.*?) # title = $7
+ \6 # matching quote
+ [ \n]*
+ )? # title is optional
+ \)
+ )
+ }xs',
+ array(&$this, '_doImages_inline_callback'), $text);
+
+ return $text;
+ }
+ protected function _doImages_reference_callback($matches) {
+ $whole_match = $matches[1];
+ $alt_text = $matches[2];
+ $link_id = strtolower($matches[3]);
+
+ if ($link_id == "") {
+ $link_id = strtolower($alt_text); # for shortcut links like ![this][].
+ }
+
+ $alt_text = $this->encodeAttribute($alt_text);
+ if (isset($this->urls[$link_id])) {
+ $url = $this->encodeAttribute($this->urls[$link_id]);
+ $result = "titles[$link_id])) {
+ $title = $this->titles[$link_id];
+ $title = $this->encodeAttribute($title);
+ $result .= " title=\"$title\"";
+ }
+ $result .= $this->empty_element_suffix;
+ $result = $this->hashPart($result);
+ }
+ else {
+ # If there's no such link ID, leave intact:
+ $result = $whole_match;
+ }
+
+ return $result;
+ }
+ protected function _doImages_inline_callback($matches) {
+ $whole_match = $matches[1];
+ $alt_text = $matches[2];
+ $url = $matches[3] == '' ? $matches[4] : $matches[3];
+ $title =& $matches[7];
+
+ $alt_text = $this->encodeAttribute($alt_text);
+ $url = $this->encodeAttribute($url);
+ $result = "encodeAttribute($title);
+ $result .= " title=\"$title\""; # $title already quoted
+ }
+ $result .= $this->empty_element_suffix;
+
+ return $this->hashPart($result);
+ }
+
+
+ protected function doHeaders($text) {
+ # Setext-style headers:
+ # Header 1
+ # ========
+ #
+ # Header 2
+ # --------
+ #
+ $text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx',
+ array(&$this, '_doHeaders_callback_setext'), $text);
+
+ # atx-style headers:
+ # # Header 1
+ # ## Header 2
+ # ## Header 2 with closing hashes ##
+ # ...
+ # ###### Header 6
+ #
+ $text = preg_replace_callback('{
+ ^(\#{1,6}) # $1 = string of #\'s
+ [ ]*
+ (.+?) # $2 = Header text
+ [ ]*
+ \#* # optional closing #\'s (not counted)
+ \n+
+ }xm',
+ array(&$this, '_doHeaders_callback_atx'), $text);
+
+ return $text;
+ }
+ protected function _doHeaders_callback_setext($matches) {
+ # Terrible hack to check we haven't found an empty list item.
+ if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1]))
+ return $matches[0];
+
+ $level = $matches[2]{0} == '=' ? 1 : 2;
+ $block = "".$this->runSpanGamut($matches[1])."";
+ return "\n" . $this->hashBlock($block) . "\n\n";
+ }
+ protected function _doHeaders_callback_atx($matches) {
+ $level = strlen($matches[1]);
+ $block = "".$this->runSpanGamut($matches[2])."";
+ return "\n" . $this->hashBlock($block) . "\n\n";
+ }
+
+
+ protected function doLists($text) {
+ #
+ # Form HTML ordered (numbered) and unordered (bulleted) lists.
+ #
+ $less_than_tab = $this->tab_width - 1;
+
+ # Re-usable patterns to match list item bullets and number markers:
+ $marker_ul_re = '[*+-]';
+ $marker_ol_re = '\d+[\.]';
+ $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)";
+
+ $markers_relist = array(
+ $marker_ul_re => $marker_ol_re,
+ $marker_ol_re => $marker_ul_re,
+ );
+
+ foreach ($markers_relist as $marker_re => $other_marker_re) {
+ # Re-usable pattern to match any entirel ul or ol list:
+ $whole_list_re = '
+ ( # $1 = whole list
+ ( # $2
+ ([ ]{0,'.$less_than_tab.'}) # $3 = number of spaces
+ ('.$marker_re.') # $4 = first list item marker
+ [ ]+
+ )
+ (?s:.+?)
+ ( # $5
+ \z
+ |
+ \n{2,}
+ (?=\S)
+ (?! # Negative lookahead for another list item marker
+ [ ]*
+ '.$marker_re.'[ ]+
+ )
+ |
+ (?= # Lookahead for another kind of list
+ \n
+ \3 # Must have the same indentation
+ '.$other_marker_re.'[ ]+
+ )
+ )
+ )
+ '; // mx
+
+ # We use a different prefix before nested lists than top-level lists.
+ # See extended comment in _ProcessListItems().
+
+ if ($this->list_level) {
+ $text = preg_replace_callback('{
+ ^
+ '.$whole_list_re.'
+ }mx',
+ array(&$this, '_doLists_callback'), $text);
+ }
+ else {
+ $text = preg_replace_callback('{
+ (?:(?<=\n)\n|\A\n?) # Must eat the newline
+ '.$whole_list_re.'
+ }mx',
+ array(&$this, '_doLists_callback'), $text);
+ }
+ }
+
+ return $text;
+ }
+ protected function _doLists_callback($matches) {
+ # Re-usable patterns to match list item bullets and number markers:
+ $marker_ul_re = '[*+-]';
+ $marker_ol_re = '\d+[\.]';
+ $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)";
+
+ $list = $matches[1];
+ $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol";
+
+ $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re );
+
+ $list .= "\n";
+ $result = $this->processListItems($list, $marker_any_re);
+
+ $result = $this->hashBlock("<$list_type>\n" . $result . "$list_type>");
+ return "\n". $result ."\n\n";
+ }
+
+ protected $list_level = 0;
+
+ protected function processListItems($list_str, $marker_any_re) {
+ #
+ # Process the contents of a single ordered or unordered list, splitting it
+ # into individual list items.
+ #
+ # The $this->list_level global keeps track of when we're inside a list.
+ # Each time we enter a list, we increment it; when we leave a list,
+ # we decrement. If it's zero, we're not in a list anymore.
+ #
+ # We do this because when we're not inside a list, we want to treat
+ # something like this:
+ #
+ # I recommend upgrading to version
+ # 8. Oops, now this line is treated
+ # as a sub-list.
+ #
+ # As a single paragraph, despite the fact that the second line starts
+ # with a digit-period-space sequence.
+ #
+ # Whereas when we're inside a list (or sub-list), that line will be
+ # treated as the start of a sub-list. What a kludge, huh? This is
+ # an aspect of Markdown's syntax that's hard to parse perfectly
+ # without resorting to mind-reading. Perhaps the solution is to
+ # change the syntax rules such that sub-lists must start with a
+ # starting cardinal number; e.g. "1." or "a.".
+
+ $this->list_level++;
+
+ # trim trailing blank lines:
+ $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str);
+
+ $list_str = preg_replace_callback('{
+ (\n)? # leading line = $1
+ (^[ ]*) # leading whitespace = $2
+ ('.$marker_any_re.' # list marker and space = $3
+ (?:[ ]+|(?=\n)) # space only required if item is not empty
+ )
+ ((?s:.*?)) # list item text = $4
+ (?:(\n+(?=\n))|\n) # tailing blank line = $5
+ (?= \n* (\z | \2 ('.$marker_any_re.') (?:[ ]+|(?=\n))))
+ }xm',
+ array(&$this, '_processListItems_callback'), $list_str);
+
+ $this->list_level--;
+ return $list_str;
+ }
+ protected function _processListItems_callback($matches) {
+ $item = $matches[4];
+ $leading_line =& $matches[1];
+ $leading_space =& $matches[2];
+ $marker_space = $matches[3];
+ $tailing_blank_line =& $matches[5];
+
+ if ($leading_line || $tailing_blank_line ||
+ preg_match('/\n{2,}/', $item))
+ {
+ # Replace marker with the appropriate whitespace indentation
+ $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item;
+ $item = $this->runBlockGamut($this->outdent($item)."\n");
+ }
+ else {
+ # Recursion for sub-lists:
+ $item = $this->doLists($this->outdent($item));
+ $item = preg_replace('/\n+$/', '', $item);
+ $item = $this->runSpanGamut($item);
+ }
+
+ return "" . $item . "\n";
+ }
+
+
+ protected function doCodeBlocks($text) {
+ #
+ # Process Markdown `` blocks.
+ #
+ $text = preg_replace_callback('{
+ (?:\n\n|\A\n?)
+ ( # $1 = the code block -- one or more lines, starting with a space/tab
+ (?>
+ [ ]{'.$this->tab_width.'} # Lines must start with a tab or a tab-width of spaces
+ .*\n+
+ )+
+ )
+ ((?=^[ ]{0,'.$this->tab_width.'}\S)|\Z) # Lookahead for non-space at line-start, or end of doc
+ }xm',
+ array(&$this, '_doCodeBlocks_callback'), $text);
+
+ return $text;
+ }
+ protected function _doCodeBlocks_callback($matches) {
+ $codeblock = $matches[1];
+
+ $codeblock = $this->outdent($codeblock);
+ $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
+
+ # trim leading newlines and trailing newlines
+ $codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock);
+
+ $codeblock = "$codeblock\n
";
+ return "\n\n".$this->hashBlock($codeblock)."\n\n";
+ }
+
+
+ protected function makeCodeSpan($code) {
+ #
+ # Create a code span markup for $code. Called from handleSpanToken.
+ #
+ $code = htmlspecialchars(trim($code), ENT_NOQUOTES);
+ return $this->hashPart("$code
");
+ }
+
+
+ protected $em_relist = array(
+ '' => '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(?em_relist as $em => $em_re) {
+ foreach ($this->strong_relist as $strong => $strong_re) {
+ # Construct list of allowed token expressions.
+ $token_relist = array();
+ if (isset($this->em_strong_relist["$em$strong"])) {
+ $token_relist[] = $this->em_strong_relist["$em$strong"];
+ }
+ $token_relist[] = $em_re;
+ $token_relist[] = $strong_re;
+
+ # Construct master expression from list.
+ $token_re = '{('. implode('|', $token_relist) .')}';
+ $this->em_strong_prepared_relist["$em$strong"] = $token_re;
+ }
+ }
+ }
+
+ protected function doItalicsAndBold($text) {
+ $token_stack = array('');
+ $text_stack = array('');
+ $em = '';
+ $strong = '';
+ $tree_char_em = false;
+
+ while (1) {
+ #
+ # Get prepared regular expression for seraching emphasis tokens
+ # in current context.
+ #
+ $token_re = $this->em_strong_prepared_relist["$em$strong"];
+
+ #
+ # Each loop iteration search for the next emphasis token.
+ # Each token is then passed to handleSpanToken.
+ #
+ $parts = preg_split($token_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE);
+ $text_stack[0] .= $parts[0];
+ $token =& $parts[1];
+ $text =& $parts[2];
+
+ if (empty($token)) {
+ # Reached end of text span: empty stack without emitting.
+ # any more emphasis.
+ while ($token_stack[0]) {
+ $text_stack[1] .= array_shift($token_stack);
+ $text_stack[0] .= array_shift($text_stack);
+ }
+ break;
+ }
+
+ $token_len = strlen($token);
+ if ($tree_char_em) {
+ # Reached closing marker while inside a three-char emphasis.
+ if ($token_len == 3) {
+ # Three-char closing marker, close em and strong.
+ array_shift($token_stack);
+ $span = array_shift($text_stack);
+ $span = $this->runSpanGamut($span);
+ $span = "$span";
+ $text_stack[0] .= $this->hashPart($span);
+ $em = '';
+ $strong = '';
+ } else {
+ # Other closing marker: close one em or strong and
+ # change current token state to match the other
+ $token_stack[0] = str_repeat($token{0}, 3-$token_len);
+ $tag = $token_len == 2 ? "strong" : "em";
+ $span = $text_stack[0];
+ $span = $this->runSpanGamut($span);
+ $span = "<$tag>$span$tag>";
+ $text_stack[0] = $this->hashPart($span);
+ $$tag = ''; # $$tag stands for $em or $strong
+ }
+ $tree_char_em = false;
+ } else if ($token_len == 3) {
+ if ($em) {
+ # Reached closing marker for both em and strong.
+ # Closing strong marker:
+ for ($i = 0; $i < 2; ++$i) {
+ $shifted_token = array_shift($token_stack);
+ $tag = strlen($shifted_token) == 2 ? "strong" : "em";
+ $span = array_shift($text_stack);
+ $span = $this->runSpanGamut($span);
+ $span = "<$tag>$span$tag>";
+ $text_stack[0] .= $this->hashPart($span);
+ $$tag = ''; # $$tag stands for $em or $strong
+ }
+ } else {
+ # Reached opening three-char emphasis marker. Push on token
+ # stack; will be handled by the special condition above.
+ $em = $token{0};
+ $strong = "$em$em";
+ array_unshift($token_stack, $token);
+ array_unshift($text_stack, '');
+ $tree_char_em = true;
+ }
+ } else if ($token_len == 2) {
+ if ($strong) {
+ # Unwind any dangling emphasis marker:
+ if (strlen($token_stack[0]) == 1) {
+ $text_stack[1] .= array_shift($token_stack);
+ $text_stack[0] .= array_shift($text_stack);
+ }
+ # Closing strong marker:
+ array_shift($token_stack);
+ $span = array_shift($text_stack);
+ $span = $this->runSpanGamut($span);
+ $span = "$span";
+ $text_stack[0] .= $this->hashPart($span);
+ $strong = '';
+ } else {
+ array_unshift($token_stack, $token);
+ array_unshift($text_stack, '');
+ $strong = $token;
+ }
+ } else {
+ # Here $token_len == 1
+ if ($em) {
+ if (strlen($token_stack[0]) == 1) {
+ # Closing emphasis marker:
+ array_shift($token_stack);
+ $span = array_shift($text_stack);
+ $span = $this->runSpanGamut($span);
+ $span = "$span";
+ $text_stack[0] .= $this->hashPart($span);
+ $em = '';
+ } else {
+ $text_stack[0] .= $token;
+ }
+ } else {
+ array_unshift($token_stack, $token);
+ array_unshift($text_stack, '');
+ $em = $token;
+ }
+ }
+ }
+ return $text_stack[0];
+ }
+
+
+ protected function doBlockQuotes($text) {
+ $text = preg_replace_callback('/
+ ( # Wrap whole match in $1
+ (?>
+ ^[ ]*>[ ]? # ">" at the start of a line
+ .+\n # rest of the first line
+ (.+\n)* # subsequent consecutive lines
+ \n* # blanks
+ )+
+ )
+ /xm',
+ array(&$this, '_doBlockQuotes_callback'), $text);
+
+ return $text;
+ }
+ protected function _doBlockQuotes_callback($matches) {
+ $bq = $matches[1];
+ # trim one level of quoting - trim whitespace-only lines
+ $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq);
+ $bq = $this->runBlockGamut($bq); # recurse
+
+ $bq = preg_replace('/^/m', " ", $bq);
+ # These leading spaces cause problem with content,
+ # so we need to fix that:
+ $bq = preg_replace_callback('{(\s*.+?
)}sx',
+ array(&$this, '_doBlockQuotes_callback2'), $bq);
+
+ return "\n". $this->hashBlock("\n$bq\n
")."\n\n";
+ }
+ protected function _doBlockQuotes_callback2($matches) {
+ $pre = $matches[1];
+ $pre = preg_replace('/^ /m', '', $pre);
+ return $pre;
+ }
+
+
+ protected function formParagraphs($text) {
+ #
+ # Params:
+ # $text - string to process with html tags
+ #
+ # Strip leading and trailing lines:
+ $text = preg_replace('/\A\n+|\n+\z/', '', $text);
+
+ $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY);
+
+ #
+ # Wrap
tags and unhashify HTML blocks
+ #
+ foreach ($grafs as $key => $value) {
+ if (!preg_match('/^B\x1A[0-9]+B$/', $value)) {
+ # Is a paragraph.
+ $value = $this->runSpanGamut($value);
+ $value = preg_replace('/^([ ]*)/', "
", $value);
+ $value .= "
";
+ $grafs[$key] = $this->unhash($value);
+ }
+ else {
+ # Is a block.
+ # Modify elements of @grafs in-place...
+ $graf = $value;
+ $block = $this->html_hashes[$graf];
+ $graf = $block;
+// if (preg_match('{
+// \A
+// ( # $1 = tag
+//
]*
+// \b
+// markdown\s*=\s* ([\'"]) # $2 = attr quote char
+// 1
+// \2
+// [^>]*
+// >
+// )
+// ( # $3 = contents
+// .*
+// )
+// (
) # $4 = closing tag
+// \z
+// }xs', $block, $matches))
+// {
+// list(, $div_open, , $div_content, $div_close) = $matches;
+//
+// # We can't call Markdown(), because that resets the hash;
+// # that initialization code should be pulled into its own sub, though.
+// $div_content = $this->hashHTMLBlocks($div_content);
+//
+// # Run document gamut methods on the content.
+// foreach ($this->document_gamut as $method => $priority) {
+// $div_content = $this->$method($div_content);
+// }
+//
+// $div_open = preg_replace(
+// '{\smarkdown\s*=\s*([\'"]).+?\1}', '', $div_open);
+//
+// $graf = $div_open . "\n" . $div_content . "\n" . $div_close;
+// }
+ $grafs[$key] = $graf;
+ }
+ }
+
+ return implode("\n\n", $grafs);
+ }
+
+
+ protected function encodeAttribute($text) {
+ #
+ # Encode text for a double-quoted HTML attribute. This function
+ # is *not* suitable for attributes enclosed in single quotes.
+ #
+ $text = $this->encodeAmpsAndAngles($text);
+ $text = str_replace('"', '"', $text);
+ return $text;
+ }
+
+
+ protected function encodeAmpsAndAngles($text) {
+ #
+ # Smart processing for ampersands and angle brackets that need to
+ # be encoded. Valid character entities are left alone unless the
+ # no-entities mode is set.
+ #
+ if ($this->no_entities) {
+ $text = str_replace('&', '&', $text);
+ } else {
+ # Ampersand-encoding based entirely on Nat Irons's Amputator
+ # MT plugin:
+ $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/',
+ '&', $text);
+ }
+ # Encode remaining <'s
+ $text = str_replace('<', '<', $text);
+
+ return $text;
+ }
+
+
+ protected function doAutoLinks($text) {
+ $text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i',
+ array(&$this, '_doAutoLinks_url_callback'), $text);
+
+ # Email addresses:
+ $text = preg_replace_callback('{
+ <
+ (?:mailto:)?
+ (
+ (?:
+ [-!#$%&\'*+/=?^_`.{|}~\w\x80-\xFF]+
+ |
+ ".*?"
+ )
+ \@
+ (?:
+ [-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+
+ |
+ \[[\d.a-fA-F:]+\] # IPv4 & IPv6
+ )
+ )
+ >
+ }xi',
+ array(&$this, '_doAutoLinks_email_callback'), $text);
+ $text = preg_replace_callback('{<(tel:([^\'">\s]+))>}i',array(&$this, '_doAutoLinks_tel_callback'), $text);
+
+ return $text;
+ }
+ protected function _doAutoLinks_tel_callback($matches) {
+ $url = $this->encodeAttribute($matches[1]);
+ $tel = $this->encodeAttribute($matches[2]);
+ $link = "$tel";
+ return $this->hashPart($link);
+ }
+ protected function _doAutoLinks_url_callback($matches) {
+ $url = $this->encodeAttribute($matches[1]);
+ $link = "$url";
+ return $this->hashPart($link);
+ }
+ protected function _doAutoLinks_email_callback($matches) {
+ $address = $matches[1];
+ $link = $this->encodeEmailAddress($address);
+ return $this->hashPart($link);
+ }
+
+
+ protected function encodeEmailAddress($addr) {
+ #
+ # Input: an email address, e.g. "foo@example.com"
+ #
+ # Output: the email address as a mailto link, with each character
+ # of the address encoded as either a decimal or hex entity, in
+ # the hopes of foiling most address harvesting spam bots. E.g.:
+ #
+ # foo@exampl
+ # e.com
+ #
+ # Based by a filter by Matthew Wickline, posted to BBEdit-Talk.
+ # With some optimizations by Milian Wolff.
+ #
+ $addr = "mailto:" . $addr;
+ $chars = preg_split('/(? $char) {
+ $ord = ord($char);
+ # Ignore non-ascii chars.
+ if ($ord < 128) {
+ $r = ($seed * (1 + $key)) % 100; # Pseudo-random function.
+ # roughly 10% raw, 45% hex, 45% dec
+ # '@' *must* be encoded. I insist.
+ if ($r > 90 && $char != '@') /* do nothing */;
+ else if ($r < 45) $chars[$key] = ''.dechex($ord).';';
+ else $chars[$key] = ''.$ord.';';
+ }
+ }
+
+ $addr = implode('', $chars);
+ $text = implode('', array_slice($chars, 7)); # text without `mailto:`
+ $addr = "$text";
+
+ return $addr;
+ }
+
+
+ protected function parseSpan($str) {
+ #
+ # Take the string $str and parse it into tokens, hashing embeded HTML,
+ # escaped characters and handling code spans.
+ #
+ $output = '';
+
+ $span_re = '{
+ (
+ \\\\'.$this->escape_chars_re.'
+ |
+ (?no_markup ? '' : '
+ |
+ # comment
+ |
+ <\?.*?\?> | <%.*?%> # processing instruction
+ |
+ <[!$]?[-a-zA-Z0-9:_]+ # regular tags
+ (?>
+ \s
+ (?>[^"\'>]+|"[^"]*"|\'[^\']*\')*
+ )?
+ >
+ |
+ <[-a-zA-Z0-9:_]+\s*/> # xml-style empty tag
+ |
+ [-a-zA-Z0-9:_]+\s*> # closing tag
+ ').'
+ )
+ }xs';
+
+ while (1) {
+ #
+ # Each loop iteration seach for either the next tag, the next
+ # openning code span marker, or the next escaped character.
+ # Each token is then passed to handleSpanToken.
+ #
+ $parts = preg_split($span_re, $str, 2, PREG_SPLIT_DELIM_CAPTURE);
+
+ # Create token from text preceding tag.
+ if ($parts[0] != "") {
+ $output .= $parts[0];
+ }
+
+ # Check if we reach the end.
+ if (isset($parts[1])) {
+ $output .= $this->handleSpanToken($parts[1], $parts[2]);
+ $str = $parts[2];
+ }
+ else {
+ break;
+ }
+ }
+
+ return $output;
+ }
+
+
+ protected function handleSpanToken($token, &$str) {
+ #
+ # Handle $token provided by parseSpan by determining its nature and
+ # returning the corresponding value that should replace it.
+ #
+ switch ($token{0}) {
+ case "\\":
+ return $this->hashPart("". ord($token{1}). ";");
+ case "`":
+ # Search for end marker in remaining text.
+ if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm',
+ $str, $matches))
+ {
+ $str = $matches[2];
+ $codespan = $this->makeCodeSpan($matches[1]);
+ return $this->hashPart($codespan);
+ }
+ return $token; // return as text since no ending marker found.
+ default:
+ return $this->hashPart($token);
+ }
+ }
+
+
+ protected function outdent($text) {
+ #
+ # Remove one level of line-leading tabs or spaces
+ #
+ return preg_replace('/^(\t|[ ]{1,'.$this->tab_width.'})/m', '', $text);
+ }
+
+
+ # String length function for detab. `_initDetab` will create a function to
+ # hanlde UTF-8 if the default function does not exist.
+ protected $utf8_strlen = 'mb_strlen';
+
+ protected function detab($text) {
+ #
+ # Replace tabs with the appropriate amount of space.
+ #
+ # For each line we separate the line in blocks delemited by
+ # tab characters. Then we reconstruct every line by adding the
+ # appropriate number of space between each blocks.
+
+ $text = preg_replace_callback('/^.*\t.*$/m',
+ array(&$this, '_detab_callback'), $text);
+
+ return $text;
+ }
+ protected function _detab_callback($matches) {
+ $line = $matches[0];
+ $strlen = $this->utf8_strlen; # strlen function for UTF-8.
+
+ # Split in blocks.
+ $blocks = explode("\t", $line);
+ # Add each blocks to the line.
+ $line = $blocks[0];
+ unset($blocks[0]); # Do not add first block twice.
+ foreach ($blocks as $block) {
+ # Calculate amount of space, insert spaces, insert block.
+ $amount = $this->tab_width -
+ $strlen($line, 'UTF-8') % $this->tab_width;
+ $line .= str_repeat(" ", $amount) . $block;
+ }
+ return $line;
+ }
+ protected function _initDetab() {
+ #
+ # Check for the availability of the function in the `utf8_strlen` property
+ # (initially `mb_strlen`). If the function is not available, create a
+ # function that will loosely count the number of UTF-8 characters with a
+ # regular expression.
+ #
+ if (function_exists($this->utf8_strlen)) return;
+ $this->utf8_strlen = create_function('$text', 'return preg_match_all(
+ "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/",
+ $text, $m);');
+ }
+
+
+ protected function unhash($text) {
+ #
+ # Swap back in all the tags hashed by _HashHTMLBlocks.
+ #
+ return preg_replace_callback('/(.)\x1A[0-9]+\1/',
+ array(&$this, '_unhash_callback'), $text);
+ }
+ protected function _unhash_callback($matches) {
+ return $this->html_hashes[$matches[0]];
+ }
+
+}
+
+
+#
+# Temporary Markdown Extra Parser Implementation Class
+#
+# NOTE: DON'T USE THIS CLASS
+# Currently the implementation of of Extra resides here in this temporary class.
+# This makes it easier to propagate the changes between the three different
+# packaging styles of PHP Markdown. When this issue is resolved, this
+# MarkdownExtra_TmpImpl class here will disappear and \Michelf\MarkdownExtra
+# will contain the code. So please use \Michelf\MarkdownExtra and ignore this
+# one.
+#
+
+abstract class _MarkdownExtra_TmpImpl extends \Michelf\Markdown {
+
+ ### Configuration Variables ###
+
+ # Prefix for footnote ids.
+ public $fn_id_prefix = "";
+
+ # Optional title attribute for footnote links and backlinks.
+ public $fn_link_title = "";
+ public $fn_backlink_title = "";
+
+ # Optional class attribute for footnote links and backlinks.
+ public $fn_link_class = "footnote-ref";
+ public $fn_backlink_class = "footnote-backref";
+
+ # Class name for table cell alignment (%% replaced left/center/right)
+ # For instance: 'go-%%' becomes 'go-left' or 'go-right' or 'go-center'
+ # If empty, the align attribute is used instead of a class name.
+ public $table_align_class_tmpl = '';
+
+ # Optional class prefix for fenced code block.
+ public $code_class_prefix = "";
+ # Class attribute for code blocks goes on the `code` tag;
+ # setting this to true will put attributes on the `pre` tag instead.
+ public $code_attr_on_pre = false;
+
+ # Predefined abbreviations.
+ public $predef_abbr = array();
+
+
+ ### Parser Implementation ###
+
+ public function __construct() {
+ #
+ # Constructor function. Initialize the parser object.
+ #
+ # Add extra escapable characters before parent constructor
+ # initialize the table.
+ $this->escape_chars .= ':|';
+
+ # Insert extra document, block, and span transformations.
+ # Parent constructor will do the sorting.
+ $this->document_gamut += array(
+ "doFencedCodeBlocks" => 5,
+ "stripFootnotes" => 15,
+ "stripAbbreviations" => 25,
+ "appendFootnotes" => 50,
+ );
+ $this->block_gamut += array(
+ "doFencedCodeBlocks" => 5,
+ "doTables" => 15,
+ "doDefLists" => 45,
+ );
+ $this->span_gamut += array(
+ "doFootnotes" => 5,
+ "doAbbreviations" => 70,
+ );
+
+ parent::__construct();
+ }
+
+
+ # Extra variables used during extra transformations.
+ protected $footnotes = array();
+ protected $footnotes_ordered = array();
+ protected $footnotes_ref_count = array();
+ protected $footnotes_numbers = array();
+ protected $abbr_desciptions = array();
+ protected $abbr_word_re = '';
+
+ # Give the current footnote number.
+ protected $footnote_counter = 1;
+
+
+ protected function setup() {
+ #
+ # Setting up Extra-specific variables.
+ #
+ parent::setup();
+
+ $this->footnotes = array();
+ $this->footnotes_ordered = array();
+ $this->footnotes_ref_count = array();
+ $this->footnotes_numbers = array();
+ $this->abbr_desciptions = array();
+ $this->abbr_word_re = '';
+ $this->footnote_counter = 1;
+
+ foreach ($this->predef_abbr as $abbr_word => $abbr_desc) {
+ if ($this->abbr_word_re)
+ $this->abbr_word_re .= '|';
+ $this->abbr_word_re .= preg_quote($abbr_word);
+ $this->abbr_desciptions[$abbr_word] = trim($abbr_desc);
+ }
+ }
+
+ protected function teardown() {
+ #
+ # Clearing Extra-specific variables.
+ #
+ $this->footnotes = array();
+ $this->footnotes_ordered = array();
+ $this->footnotes_ref_count = array();
+ $this->footnotes_numbers = array();
+ $this->abbr_desciptions = array();
+ $this->abbr_word_re = '';
+
+ parent::teardown();
+ }
+
+
+ ### Extra Attribute Parser ###
+
+ # Expression to use to catch attributes (includes the braces)
+ protected $id_class_attr_catch_re = '\{((?:[ ]*[#.][-_:a-zA-Z0-9]+){1,})[ ]*\}';
+ # Expression to use when parsing in a context when no capture is desired
+ protected $id_class_attr_nocatch_re = '\{(?:[ ]*[#.][-_:a-zA-Z0-9]+){1,}[ ]*\}';
+
+ protected function doExtraAttributes($tag_name, $attr) {
+ #
+ # Parse attributes caught by the $this->id_class_attr_catch_re expression
+ # and return the HTML-formatted list of attributes.
+ #
+ # Currently supported attributes are .class and #id.
+ #
+ if (empty($attr)) return "";
+
+ # Split on components
+ preg_match_all('/[#.][-_:a-zA-Z0-9]+/', $attr, $matches);
+ $elements = $matches[0];
+
+ # handle classes and ids (only first id taken into account)
+ $classes = array();
+ $id = false;
+ foreach ($elements as $element) {
+ if ($element{0} == '.') {
+ $classes[] = substr($element, 1);
+ } else if ($element{0} == '#') {
+ if ($id === false) $id = substr($element, 1);
+ }
+ }
+
+ # compose attributes as string
+ $attr_str = "";
+ if (!empty($id)) {
+ $attr_str .= ' id="'.$id.'"';
+ }
+ if (!empty($classes)) {
+ $attr_str .= ' class="'.implode(" ", $classes).'"';
+ }
+ return $attr_str;
+ }
+
+
+ protected function stripLinkDefinitions($text) {
+ #
+ # Strips link definitions from text, stores the URLs and titles in
+ # hash references.
+ #
+ $less_than_tab = $this->tab_width - 1;
+
+ # Link defs are in the form: ^[id]: url "optional title"
+ $text = preg_replace_callback('{
+ ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1
+ [ ]*
+ \n? # maybe *one* newline
+ [ ]*
+ (?:
+ <(.+?)> # url = $2
+ |
+ (\S+?) # url = $3
+ )
+ [ ]*
+ \n? # maybe one newline
+ [ ]*
+ (?:
+ (?<=\s) # lookbehind for whitespace
+ ["(]
+ (.*?) # title = $4
+ [")]
+ [ ]*
+ )? # title is optional
+ (?:[ ]* '.$this->id_class_attr_catch_re.' )? # $5 = extra id & class attr
+ (?:\n+|\Z)
+ }xm',
+ array(&$this, '_stripLinkDefinitions_callback'),
+ $text);
+ return $text;
+ }
+ protected function _stripLinkDefinitions_callback($matches) {
+ $link_id = strtolower($matches[1]);
+ $url = $matches[2] == '' ? $matches[3] : $matches[2];
+ $this->urls[$link_id] = $url;
+ $this->titles[$link_id] =& $matches[4];
+ $this->ref_attr[$link_id] = $this->doExtraAttributes("", $dummy =& $matches[5]);
+ return ''; # String that will replace the block
+ }
+
+
+ ### HTML Block Parser ###
+
+ # Tags that are always treated as block tags:
+ protected $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption';
+
+ # Tags treated as block tags only if the opening tag is alone on its line:
+ protected $context_block_tags_re = 'script|noscript|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video';
+
+ # Tags where markdown="1" default to span mode:
+ protected $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address';
+
+ # Tags which must not have their contents modified, no matter where
+ # they appear:
+ protected $clean_tags_re = 'script|math|svg';
+
+ # Tags that do not need to be closed.
+ protected $auto_close_tags_re = 'hr|img|param|source|track';
+
+
+ protected function hashHTMLBlocks($text) {
+ #
+ # Hashify HTML Blocks and "clean tags".
+ #
+ # We only want to do this for block-level HTML tags, such as headers,
+ # lists, and tables. That's because we still want to wrap s around
+ # "paragraphs" that are wrapped in non-block-level tags, such as anchors,
+ # phrase emphasis, and spans. The list of tags we're looking for is
+ # hard-coded.
+ #
+ # This works by calling _HashHTMLBlocks_InMarkdown, which then calls
+ # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1"
+ # attribute is found within a tag, _HashHTMLBlocks_InHTML calls back
+ # _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag.
+ # These two functions are calling each other. It's recursive!
+ #
+ if ($this->no_markup) return $text;
+
+ #
+ # Call the HTML-in-Markdown hasher.
+ #
+ list($text, ) = $this->_hashHTMLBlocks_inMarkdown($text);
+
+ return $text;
+ }
+ protected function _hashHTMLBlocks_inMarkdown($text, $indent = 0,
+ $enclosing_tag_re = '', $span = false)
+ {
+ #
+ # Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags.
+ #
+ # * $indent is the number of space to be ignored when checking for code
+ # blocks. This is important because if we don't take the indent into
+ # account, something like this (which looks right) won't work as expected:
+ #
+ #
+ #
+ # Hello World. <-- Is this a Markdown code block or text?
+ #
<-- Is this a Markdown code block or a real tag?
+ #
+ #
+ # If you don't like this, just don't indent the tag on which
+ # you apply the markdown="1" attribute.
+ #
+ # * If $enclosing_tag_re is not empty, stops at the first unmatched closing
+ # tag with that name. Nested tags supported.
+ #
+ # * If $span is true, text inside must treated as span. So any double
+ # newline will be replaced by a single newline so that it does not create
+ # paragraphs.
+ #
+ # Returns an array of that form: ( processed text , remaining text )
+ #
+ if ($text === '') return array('', '');
+
+ # Regex to check for the presense of newlines around a block tag.
+ $newline_before_re = '/(?:^\n?|\n\n)*$/';
+ $newline_after_re =
+ '{
+ ^ # Start of text following the tag.
+ (?>[ ]*)? # Optional comment.
+ [ ]*\n # Must be followed by newline.
+ }xs';
+
+ # Regex to match any tag.
+ $block_tag_re =
+ '{
+ ( # $2: Capture whole tag.
+ ? # Any opening or closing tag.
+ (?> # Tag name.
+ '.$this->block_tags_re.' |
+ '.$this->context_block_tags_re.' |
+ '.$this->clean_tags_re.' |
+ (?!\s)'.$enclosing_tag_re.'
+ )
+ (?:
+ (?=[\s"\'/a-zA-Z0-9]) # Allowed characters after tag name.
+ (?>
+ ".*?" | # Double quotes (can contain `>`)
+ \'.*?\' | # Single quotes (can contain `>`)
+ .+? # Anything but quotes and `>`.
+ )*?
+ )?
+ > # End of tag.
+ |
+ # HTML Comment
+ |
+ <\?.*?\?> | <%.*?%> # Processing instruction
+ |
+ # CData Block
+ '. ( !$span ? ' # If not in span.
+ |
+ # Indented code block
+ (?: ^[ ]*\n | ^ | \n[ ]*\n )
+ [ ]{'.($indent+4).'}[^\n]* \n
+ (?>
+ (?: [ ]{'.($indent+4).'}[^\n]* | [ ]* ) \n
+ )*
+ |
+ # Fenced code block marker
+ (?<= ^ | \n )
+ [ ]{0,'.($indent+3).'}(?:~{3,}|`{3,})
+ [ ]*
+ (?:
+ \.?[-_:a-zA-Z0-9]+ # standalone class name
+ |
+ '.$this->id_class_attr_nocatch_re.' # extra attributes
+ )?
+ [ ]*
+ (?= \n )
+ ' : '' ). ' # End (if not is span).
+ |
+ # Code span marker
+ # Note, this regex needs to go after backtick fenced
+ # code blocks but it should also be kept outside of the
+ # "if not in span" condition adding backticks to the parser
+ `+
+ )
+ }xs';
+
+
+ $depth = 0; # Current depth inside the tag tree.
+ $parsed = ""; # Parsed text that will be returned.
+
+ #
+ # Loop through every tag until we find the closing tag of the parent
+ # or loop until reaching the end of text if no parent tag specified.
+ #
+ do {
+ #
+ # Split the text using the first $tag_match pattern found.
+ # Text before pattern will be first in the array, text after
+ # pattern will be at the end, and between will be any catches made
+ # by the pattern.
+ #
+ $parts = preg_split($block_tag_re, $text, 2,
+ PREG_SPLIT_DELIM_CAPTURE);
+
+ # If in Markdown span mode, add a empty-string span-level hash
+ # after each newline to prevent triggering any block element.
+ if ($span) {
+ $void = $this->hashPart("", ':');
+ $newline = "$void\n";
+ $parts[0] = $void . str_replace("\n", $newline, $parts[0]) . $void;
+ }
+
+ $parsed .= $parts[0]; # Text before current tag.
+
+ # If end of $text has been reached. Stop loop.
+ if (count($parts) < 3) {
+ $text = "";
+ break;
+ }
+
+ $tag = $parts[1]; # Tag to handle.
+ $text = $parts[2]; # Remaining text after current tag.
+ $tag_re = preg_quote($tag); # For use in a regular expression.
+
+ #
+ # Check for: Fenced code block marker.
+ # Note: need to recheck the whole tag to disambiguate backtick
+ # fences from code spans
+ #
+ if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~{3,}|`{3,})[ ]*(?:\.?[-_:a-zA-Z0-9]+|'.$this->id_class_attr_nocatch_re.')?[ ]*\n?$}', $tag, $capture)) {
+ # Fenced code block marker: find matching end marker.
+ $fence_indent = strlen($capture[1]); # use captured indent in re
+ $fence_re = $capture[2]; # use captured fence in re
+ if (preg_match('{^(?>.*\n)*?[ ]{'.($fence_indent).'}'.$fence_re.'[ ]*(?:\n|$)}', $text,
+ $matches))
+ {
+ # End marker found: pass text unchanged until marker.
+ $parsed .= $tag . $matches[0];
+ $text = substr($text, strlen($matches[0]));
+ }
+ else {
+ # No end marker: just skip it.
+ $parsed .= $tag;
+ }
+ }
+ #
+ # Check for: Indented code block.
+ #
+ else if ($tag{0} == "\n" || $tag{0} == " ") {
+ # Indented code block: pass it unchanged, will be handled
+ # later.
+ $parsed .= $tag;
+ }
+ #
+ # Check for: Code span marker
+ # Note: need to check this after backtick fenced code blocks
+ #
+ else if ($tag{0} == "`") {
+ # Find corresponding end marker.
+ $tag_re = preg_quote($tag);
+ if (preg_match('{^(?>.+?|\n(?!\n))*?(?block_tags_re.')\b}', $tag) ||
+ ( preg_match('{^<(?:'.$this->context_block_tags_re.')\b}', $tag) &&
+ preg_match($newline_before_re, $parsed) &&
+ preg_match($newline_after_re, $text) )
+ )
+ {
+ # Need to parse tag and following text using the HTML parser.
+ list($block_text, $text) =
+ $this->_hashHTMLBlocks_inHTML($tag . $text, "hashBlock", true);
+
+ # Make sure it stays outside of any paragraph by adding newlines.
+ $parsed .= "\n\n$block_text\n\n";
+ }
+ #
+ # Check for: Clean tag (like script, math)
+ # HTML Comments, processing instructions.
+ #
+ else if (preg_match('{^<(?:'.$this->clean_tags_re.')\b}', $tag) ||
+ $tag{1} == '!' || $tag{1} == '?')
+ {
+ # Need to parse tag and following text using the HTML parser.
+ # (don't check for markdown attribute)
+ list($block_text, $text) =
+ $this->_hashHTMLBlocks_inHTML($tag . $text, "hashClean", false);
+
+ $parsed .= $block_text;
+ }
+ #
+ # Check for: Tag with same name as enclosing tag.
+ #
+ else if ($enclosing_tag_re !== '' &&
+ # Same name as enclosing tag.
+ preg_match('{^?(?:'.$enclosing_tag_re.')\b}', $tag))
+ {
+ #
+ # Increase/decrease nested tag count.
+ #
+ if ($tag{1} == '/') $depth--;
+ else if ($tag{strlen($tag)-2} != '/') $depth++;
+
+ if ($depth < 0) {
+ #
+ # Going out of parent element. Clean up and break so we
+ # return to the calling function.
+ #
+ $text = $tag . $text;
+ break;
+ }
+
+ $parsed .= $tag;
+ }
+ else {
+ $parsed .= $tag;
+ }
+ } while ($depth >= 0);
+
+ return array($parsed, $text);
+ }
+ protected function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) {
+ #
+ # Parse HTML, calling _HashHTMLBlocks_InMarkdown for block tags.
+ #
+ # * Calls $hash_method to convert any blocks.
+ # * Stops when the first opening tag closes.
+ # * $md_attr indicate if the use of the `markdown="1"` attribute is allowed.
+ # (it is not inside clean tags)
+ #
+ # Returns an array of that form: ( processed text , remaining text )
+ #
+ if ($text === '') return array('', '');
+
+ # Regex to match `markdown` attribute inside of a tag.
+ $markdown_attr_re = '
+ {
+ \s* # Eat whitespace before the `markdown` attribute
+ markdown
+ \s*=\s*
+ (?>
+ (["\']) # $1: quote delimiter
+ (.*?) # $2: attribute value
+ \1 # matching delimiter
+ |
+ ([^\s>]*) # $3: unquoted attribute value
+ )
+ () # $4: make $3 always defined (avoid warnings)
+ }xs';
+
+ # Regex to match any tag.
+ $tag_re = '{
+ ( # $2: Capture whole tag.
+ ? # Any opening or closing tag.
+ [\w:$]+ # Tag name.
+ (?:
+ (?=[\s"\'/a-zA-Z0-9]) # Allowed characters after tag name.
+ (?>
+ ".*?" | # Double quotes (can contain `>`)
+ \'.*?\' | # Single quotes (can contain `>`)
+ .+? # Anything but quotes and `>`.
+ )*?
+ )?
+ > # End of tag.
+ |
+ # HTML Comment
+ |
+ <\?.*?\?> | <%.*?%> # Processing instruction
+ |
+ # CData Block
+ )
+ }xs';
+
+ $original_text = $text; # Save original text in case of faliure.
+
+ $depth = 0; # Current depth inside the tag tree.
+ $block_text = ""; # Temporary text holder for current text.
+ $parsed = ""; # Parsed text that will be returned.
+
+ #
+ # Get the name of the starting tag.
+ # (This pattern makes $base_tag_name_re safe without quoting.)
+ #
+ if (preg_match('/^<([\w:$]*)\b/', $text, $matches))
+ $base_tag_name_re = $matches[1];
+
+ #
+ # Loop through every tag until we find the corresponding closing tag.
+ #
+ do {
+ #
+ # Split the text using the first $tag_match pattern found.
+ # Text before pattern will be first in the array, text after
+ # pattern will be at the end, and between will be any catches made
+ # by the pattern.
+ #
+ $parts = preg_split($tag_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE);
+
+ if (count($parts) < 3) {
+ #
+ # End of $text reached with unbalenced tag(s).
+ # In that case, we return original text unchanged and pass the
+ # first character as filtered to prevent an infinite loop in the
+ # parent function.
+ #
+ return array($original_text{0}, substr($original_text, 1));
+ }
+
+ $block_text .= $parts[0]; # Text before current tag.
+ $tag = $parts[1]; # Tag to handle.
+ $text = $parts[2]; # Remaining text after current tag.
+
+ #
+ # Check for: Auto-close tag (like
)
+ # Comments and Processing Instructions.
+ #
+ if (preg_match('{^?(?:'.$this->auto_close_tags_re.')\b}', $tag) ||
+ $tag{1} == '!' || $tag{1} == '?')
+ {
+ # Just add the tag to the block as if it was text.
+ $block_text .= $tag;
+ }
+ else {
+ #
+ # Increase/decrease nested tag count. Only do so if
+ # the tag's name match base tag's.
+ #
+ if (preg_match('{^?'.$base_tag_name_re.'\b}', $tag)) {
+ if ($tag{1} == '/') $depth--;
+ else if ($tag{strlen($tag)-2} != '/') $depth++;
+ }
+
+ #
+ # Check for `markdown="1"` attribute and handle it.
+ #
+ if ($md_attr &&
+ preg_match($markdown_attr_re, $tag, $attr_m) &&
+ preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3]))
+ {
+ # Remove `markdown` attribute from opening tag.
+ $tag = preg_replace($markdown_attr_re, '', $tag);
+
+ # Check if text inside this tag must be parsed in span mode.
+ $this->mode = $attr_m[2] . $attr_m[3];
+ $span_mode = $this->mode == 'span' || $this->mode != 'block' &&
+ preg_match('{^<(?:'.$this->contain_span_tags_re.')\b}', $tag);
+
+ # Calculate indent before tag.
+ if (preg_match('/(?:^|\n)( *?)(?! ).*?$/', $block_text, $matches)) {
+ $strlen = $this->utf8_strlen;
+ $indent = $strlen($matches[1], 'UTF-8');
+ } else {
+ $indent = 0;
+ }
+
+ # End preceding block with this tag.
+ $block_text .= $tag;
+ $parsed .= $this->$hash_method($block_text);
+
+ # Get enclosing tag name for the ParseMarkdown function.
+ # (This pattern makes $tag_name_re safe without quoting.)
+ preg_match('/^<([\w:$]*)\b/', $tag, $matches);
+ $tag_name_re = $matches[1];
+
+ # Parse the content using the HTML-in-Markdown parser.
+ list ($block_text, $text)
+ = $this->_hashHTMLBlocks_inMarkdown($text, $indent,
+ $tag_name_re, $span_mode);
+
+ # Outdent markdown text.
+ if ($indent > 0) {
+ $block_text = preg_replace("/^[ ]{1,$indent}/m", "",
+ $block_text);
+ }
+
+ # Append tag content to parsed text.
+ if (!$span_mode) $parsed .= "\n\n$block_text\n\n";
+ else $parsed .= "$block_text";
+
+ # Start over with a new block.
+ $block_text = "";
+ }
+ else $block_text .= $tag;
+ }
+
+ } while ($depth > 0);
+
+ #
+ # Hash last block text that wasn't processed inside the loop.
+ #
+ $parsed .= $this->$hash_method($block_text);
+
+ return array($parsed, $text);
+ }
+
+
+ protected function hashClean($text) {
+ #
+ # Called whenever a tag must be hashed when a function inserts a "clean" tag
+ # in $text, it passes through this function and is automaticaly escaped,
+ # blocking invalid nested overlap.
+ #
+ return $this->hashPart($text, 'C');
+ }
+
+
+ protected function doAnchors($text) {
+ #
+ # Turn Markdown link shortcuts into XHTML
tags.
+ #
+ if ($this->in_anchor) return $text;
+ $this->in_anchor = true;
+
+ #
+ # First, handle reference-style links: [link text] [id]
+ #
+ $text = preg_replace_callback('{
+ ( # wrap whole match in $1
+ \[
+ ('.$this->nested_brackets_re.') # link text = $2
+ \]
+
+ [ ]? # one optional space
+ (?:\n[ ]*)? # one optional newline followed by spaces
+
+ \[
+ (.*?) # id = $3
+ \]
+ )
+ }xs',
+ array(&$this, '_doAnchors_reference_callback'), $text);
+
+ #
+ # Next, inline-style links: [link text](url "optional title")
+ #
+ $text = preg_replace_callback('{
+ ( # wrap whole match in $1
+ \[
+ ('.$this->nested_brackets_re.') # link text = $2
+ \]
+ \( # literal paren
+ [ \n]*
+ (?:
+ <(.+?)> # href = $3
+ |
+ ('.$this->nested_url_parenthesis_re.') # href = $4
+ )
+ [ \n]*
+ ( # $5
+ ([\'"]) # quote char = $6
+ (.*?) # Title = $7
+ \6 # matching quote
+ [ \n]* # ignore any spaces/tabs between closing quote and )
+ )? # title is optional
+ \)
+ (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes
+ )
+ }xs',
+ array(&$this, '_doAnchors_inline_callback'), $text);
+
+ #
+ # Last, handle reference-style shortcuts: [link text]
+ # These must come last in case you've also got [link text][1]
+ # or [link text](/foo)
+ #
+ $text = preg_replace_callback('{
+ ( # wrap whole match in $1
+ \[
+ ([^\[\]]+) # link text = $2; can\'t contain [ or ]
+ \]
+ )
+ }xs',
+ array(&$this, '_doAnchors_reference_callback'), $text);
+
+ $this->in_anchor = false;
+ return $text;
+ }
+ protected function _doAnchors_reference_callback($matches) {
+ $whole_match = $matches[1];
+ $link_text = $matches[2];
+ $link_id =& $matches[3];
+
+ if ($link_id == "") {
+ # for shortcut links like [this][] or [this].
+ $link_id = $link_text;
+ }
+
+ # lower-case and turn embedded newlines into spaces
+ $link_id = strtolower($link_id);
+ $link_id = preg_replace('{[ ]?\n}', ' ', $link_id);
+
+ if (isset($this->urls[$link_id])) {
+ $url = $this->urls[$link_id];
+ $url = $this->encodeAttribute($url);
+
+ $result = "titles[$link_id] ) ) {
+ $title = $this->titles[$link_id];
+ $title = $this->encodeAttribute($title);
+ $result .= " title=\"$title\"";
+ }
+ if (isset($this->ref_attr[$link_id]))
+ $result .= $this->ref_attr[$link_id];
+
+ $link_text = $this->runSpanGamut($link_text);
+ $result .= ">$link_text";
+ $result = $this->hashPart($result);
+ }
+ else {
+ $result = $whole_match;
+ }
+ return $result;
+ }
+ protected function _doAnchors_inline_callback($matches) {
+ $whole_match = $matches[1];
+ $link_text = $this->runSpanGamut($matches[2]);
+ $url = $matches[3] == '' ? $matches[4] : $matches[3];
+ $title =& $matches[7];
+ $attr = $this->doExtraAttributes("a", $dummy =& $matches[8]);
+
+
+ $url = $this->encodeAttribute($url);
+
+ $result = "
encodeAttribute($title);
+ $result .= " title=\"$title\"";
+ }
+ $result .= $attr;
+
+ $link_text = $this->runSpanGamut($link_text);
+ $result .= ">$link_text";
+
+ return $this->hashPart($result);
+ }
+
+
+ protected function doImages($text) {
+ #
+ # Turn Markdown image shortcuts into
tags.
+ #
+ #
+ # First, handle reference-style labeled images: ![alt text][id]
+ #
+ $text = preg_replace_callback('{
+ ( # wrap whole match in $1
+ !\[
+ ('.$this->nested_brackets_re.') # alt text = $2
+ \]
+
+ [ ]? # one optional space
+ (?:\n[ ]*)? # one optional newline followed by spaces
+
+ \[
+ (.*?) # id = $3
+ \]
+
+ )
+ }xs',
+ array(&$this, '_doImages_reference_callback'), $text);
+
+ #
+ # Next, handle inline images: ![alt text](url "optional title")
+ # Don't forget: encode * and _
+ #
+ $text = preg_replace_callback('{
+ ( # wrap whole match in $1
+ !\[
+ ('.$this->nested_brackets_re.') # alt text = $2
+ \]
+ \s? # One optional whitespace character
+ \( # literal paren
+ [ \n]*
+ (?:
+ <(\S*)> # src url = $3
+ |
+ ('.$this->nested_url_parenthesis_re.') # src url = $4
+ )
+ [ \n]*
+ ( # $5
+ ([\'"]) # quote char = $6
+ (.*?) # title = $7
+ \6 # matching quote
+ [ \n]*
+ )? # title is optional
+ \)
+ (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes
+ )
+ }xs',
+ array(&$this, '_doImages_inline_callback'), $text);
+
+ return $text;
+ }
+ protected function _doImages_reference_callback($matches) {
+ $whole_match = $matches[1];
+ $alt_text = $matches[2];
+ $link_id = strtolower($matches[3]);
+
+ if ($link_id == "") {
+ $link_id = strtolower($alt_text); # for shortcut links like ![this][].
+ }
+
+ $alt_text = $this->encodeAttribute($alt_text);
+ if (isset($this->urls[$link_id])) {
+ $url = $this->encodeAttribute($this->urls[$link_id]);
+ $result = "
titles[$link_id])) {
+ $title = $this->titles[$link_id];
+ $title = $this->encodeAttribute($title);
+ $result .= " title=\"$title\"";
+ }
+ if (isset($this->ref_attr[$link_id]))
+ $result .= $this->ref_attr[$link_id];
+ $result .= $this->empty_element_suffix;
+ $result = $this->hashPart($result);
+ }
+ else {
+ # If there's no such link ID, leave intact:
+ $result = $whole_match;
+ }
+
+ return $result;
+ }
+ protected function _doImages_inline_callback($matches) {
+ $whole_match = $matches[1];
+ $alt_text = $matches[2];
+ $url = $matches[3] == '' ? $matches[4] : $matches[3];
+ $title =& $matches[7];
+ $attr = $this->doExtraAttributes("img", $dummy =& $matches[8]);
+
+ $alt_text = $this->encodeAttribute($alt_text);
+ $url = $this->encodeAttribute($url);
+ $result = "
encodeAttribute($title);
+ $result .= " title=\"$title\""; # $title already quoted
+ }
+ $result .= $attr;
+ $result .= $this->empty_element_suffix;
+
+ return $this->hashPart($result);
+ }
+
+
+ protected function doHeaders($text) {
+ #
+ # Redefined to add id and class attribute support.
+ #
+ # Setext-style headers:
+ # Header 1 {#header1}
+ # ========
+ #
+ # Header 2 {#header2 .class1 .class2}
+ # --------
+ #
+ $text = preg_replace_callback(
+ '{
+ (^.+?) # $1: Header text
+ (?:[ ]+ '.$this->id_class_attr_catch_re.' )? # $3 = id/class attributes
+ [ ]*\n(=+|-+)[ ]*\n+ # $3: Header footer
+ }mx',
+ array(&$this, '_doHeaders_callback_setext'), $text);
+
+ # atx-style headers:
+ # # Header 1 {#header1}
+ # ## Header 2 {#header2}
+ # ## Header 2 with closing hashes ## {#header3.class1.class2}
+ # ...
+ # ###### Header 6 {.class2}
+ #
+ $text = preg_replace_callback('{
+ ^(\#{1,6}) # $1 = string of #\'s
+ [ ]*
+ (.+?) # $2 = Header text
+ [ ]*
+ \#* # optional closing #\'s (not counted)
+ (?:[ ]+ '.$this->id_class_attr_catch_re.' )? # $3 = id/class attributes
+ [ ]*
+ \n+
+ }xm',
+ array(&$this, '_doHeaders_callback_atx'), $text);
+
+ return $text;
+ }
+ protected function _doHeaders_callback_setext($matches) {
+ if ($matches[3] == '-' && preg_match('{^- }', $matches[1]))
+ return $matches[0];
+ $level = $matches[3]{0} == '=' ? 1 : 2;
+ $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2]);
+ $block = "
".$this->runSpanGamut($matches[1])."";
+ return "\n" . $this->hashBlock($block) . "\n\n";
+ }
+ protected function _doHeaders_callback_atx($matches) {
+ $level = strlen($matches[1]);
+ $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3]);
+ $block = "
".$this->runSpanGamut($matches[2])."";
+ return "\n" . $this->hashBlock($block) . "\n\n";
+ }
+
+
+ protected function doTables($text) {
+ #
+ # Form HTML tables.
+ #
+ $less_than_tab = $this->tab_width - 1;
+ #
+ # Find tables with leading pipe.
+ #
+ # | Header 1 | Header 2
+ # | -------- | --------
+ # | Cell 1 | Cell 2
+ # | Cell 3 | Cell 4
+ #
+ $text = preg_replace_callback('
+ {
+ ^ # Start of a line
+ [ ]{0,'.$less_than_tab.'} # Allowed whitespace.
+ [|] # Optional leading pipe (present)
+ (.+) \n # $1: Header row (at least one pipe)
+
+ [ ]{0,'.$less_than_tab.'} # Allowed whitespace.
+ [|] ([ ]*[-:]+[-| :]*) \n # $2: Header underline
+
+ ( # $3: Cells
+ (?>
+ [ ]* # Allowed whitespace.
+ [|] .* \n # Row content.
+ )*
+ )
+ (?=\n|\Z) # Stop at final double newline.
+ }xm',
+ array(&$this, '_doTable_leadingPipe_callback'), $text);
+
+ #
+ # Find tables without leading pipe.
+ #
+ # Header 1 | Header 2
+ # -------- | --------
+ # Cell 1 | Cell 2
+ # Cell 3 | Cell 4
+ #
+ $text = preg_replace_callback('
+ {
+ ^ # Start of a line
+ [ ]{0,'.$less_than_tab.'} # Allowed whitespace.
+ (\S.*[|].*) \n # $1: Header row (at least one pipe)
+
+ [ ]{0,'.$less_than_tab.'} # Allowed whitespace.
+ ([-:]+[ ]*[|][-| :]*) \n # $2: Header underline
+
+ ( # $3: Cells
+ (?>
+ .* [|] .* \n # Row content
+ )*
+ )
+ (?=\n|\Z) # Stop at final double newline.
+ }xm',
+ array(&$this, '_DoTable_callback'), $text);
+
+ return $text;
+ }
+ protected function _doTable_leadingPipe_callback($matches) {
+ $head = $matches[1];
+ $underline = $matches[2];
+ $content = $matches[3];
+
+ # Remove leading pipe for each row.
+ $content = preg_replace('/^ *[|]/m', '', $content);
+
+ return $this->_doTable_callback(array($matches[0], $head, $underline, $content));
+ }
+ protected function _doTable_makeAlignAttr($alignname)
+ {
+ if (empty($this->table_align_class_tmpl))
+ return " align=\"$alignname\"";
+
+ $classname = str_replace('%%', $alignname, $this->table_align_class_tmpl);
+ return " class=\"$classname\"";
+ }
+ protected function _doTable_callback($matches) {
+ $head = $matches[1];
+ $underline = $matches[2];
+ $content = $matches[3];
+
+ # Remove any tailing pipes for each line.
+ $head = preg_replace('/[|] *$/m', '', $head);
+ $underline = preg_replace('/[|] *$/m', '', $underline);
+ $content = preg_replace('/[|] *$/m', '', $content);
+
+ # Reading alignement from header underline.
+ $separators = preg_split('/ *[|] */', $underline);
+ foreach ($separators as $n => $s) {
+ if (preg_match('/^ *-+: *$/', $s))
+ $attr[$n] = $this->_doTable_makeAlignAttr('right');
+ else if (preg_match('/^ *:-+: *$/', $s))
+ $attr[$n] = $this->_doTable_makeAlignAttr('center');
+ else if (preg_match('/^ *:-+ *$/', $s))
+ $attr[$n] = $this->_doTable_makeAlignAttr('left');
+ else
+ $attr[$n] = '';
+ }
+
+ # Parsing span elements, including code spans, character escapes,
+ # and inline HTML tags, so that pipes inside those gets ignored.
+ $head = $this->parseSpan($head);
+ $headers = preg_split('/ *[|] */', $head);
+ $col_count = count($headers);
+ $attr = array_pad($attr, $col_count, '');
+
+ # Write column headers.
+ $text = "
\n";
+ $text .= "\n";
+ $text .= "\n";
+ foreach ($headers as $n => $header)
+ $text .= " ".$this->runSpanGamut(trim($header))." | \n";
+ $text .= "
\n";
+ $text .= "\n";
+
+ # Split content by row.
+ $rows = explode("\n", trim($content, "\n"));
+
+ $text .= "\n";
+ foreach ($rows as $row) {
+ # Parsing span elements, including code spans, character escapes,
+ # and inline HTML tags, so that pipes inside those gets ignored.
+ $row = $this->parseSpan($row);
+
+ # Split row by cell.
+ $row_cells = preg_split('/ *[|] */', $row, $col_count);
+ $row_cells = array_pad($row_cells, $col_count, '');
+
+ $text .= "\n";
+ foreach ($row_cells as $n => $cell)
+ $text .= " ".$this->runSpanGamut(trim($cell))." | \n";
+ $text .= "
\n";
+ }
+ $text .= "\n";
+ $text .= "
";
+
+ return $this->hashBlock($text) . "\n";
+ }
+
+
+ protected function doDefLists($text) {
+ #
+ # Form HTML definition lists.
+ #
+ $less_than_tab = $this->tab_width - 1;
+
+ # Re-usable pattern to match any entire dl list:
+ $whole_list_re = '(?>
+ ( # $1 = whole list
+ ( # $2
+ [ ]{0,'.$less_than_tab.'}
+ ((?>.*\S.*\n)+) # $3 = defined term
+ \n?
+ [ ]{0,'.$less_than_tab.'}:[ ]+ # colon starting definition
+ )
+ (?s:.+?)
+ ( # $4
+ \z
+ |
+ \n{2,}
+ (?=\S)
+ (?! # Negative lookahead for another term
+ [ ]{0,'.$less_than_tab.'}
+ (?: \S.*\n )+? # defined term
+ \n?
+ [ ]{0,'.$less_than_tab.'}:[ ]+ # colon starting definition
+ )
+ (?! # Negative lookahead for another definition
+ [ ]{0,'.$less_than_tab.'}:[ ]+ # colon starting definition
+ )
+ )
+ )
+ )'; // mx
+
+ $text = preg_replace_callback('{
+ (?>\A\n?|(?<=\n\n))
+ '.$whole_list_re.'
+ }mx',
+ array(&$this, '_doDefLists_callback'), $text);
+
+ return $text;
+ }
+ protected function _doDefLists_callback($matches) {
+ # Re-usable patterns to match list item bullets and number markers:
+ $list = $matches[1];
+
+ # Turn double returns into triple returns, so that we can make a
+ # paragraph for the last item in a list, if necessary:
+ $result = trim($this->processDefListItems($list));
+ $result = "
\n" . $result . "\n
";
+ return $this->hashBlock($result) . "\n\n";
+ }
+
+
+ protected function processDefListItems($list_str) {
+ #
+ # Process the contents of a single definition list, splitting it
+ # into individual term and definition list items.
+ #
+ $less_than_tab = $this->tab_width - 1;
+
+ # trim trailing blank lines:
+ $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str);
+
+ # Process definition terms.
+ $list_str = preg_replace_callback('{
+ (?>\A\n?|\n\n+) # leading line
+ ( # definition terms = $1
+ [ ]{0,'.$less_than_tab.'} # leading whitespace
+ (?!\:[ ]|[ ]) # negative lookahead for a definition
+ # mark (colon) or more whitespace.
+ (?> \S.* \n)+? # actual term (not whitespace).
+ )
+ (?=\n?[ ]{0,3}:[ ]) # lookahead for following line feed
+ # with a definition mark.
+ }xm',
+ array(&$this, '_processDefListItems_callback_dt'), $list_str);
+
+ # Process actual definitions.
+ $list_str = preg_replace_callback('{
+ \n(\n+)? # leading line = $1
+ ( # marker space = $2
+ [ ]{0,'.$less_than_tab.'} # whitespace before colon
+ \:[ ]+ # definition mark (colon)
+ )
+ ((?s:.+?)) # definition text = $3
+ (?= \n+ # stop at next definition mark,
+ (?: # next term or end of text
+ [ ]{0,'.$less_than_tab.'} \:[ ] |
+
| \z
+ )
+ )
+ }xm',
+ array(&$this, '_processDefListItems_callback_dd'), $list_str);
+
+ return $list_str;
+ }
+ protected function _processDefListItems_callback_dt($matches) {
+ $terms = explode("\n", trim($matches[1]));
+ $text = '';
+ foreach ($terms as $term) {
+ $term = $this->runSpanGamut(trim($term));
+ $text .= "\n" . $term . "";
+ }
+ return $text . "\n";
+ }
+ protected function _processDefListItems_callback_dd($matches) {
+ $leading_line = $matches[1];
+ $marker_space = $matches[2];
+ $def = $matches[3];
+
+ if ($leading_line || preg_match('/\n{2,}/', $def)) {
+ # Replace marker with the appropriate whitespace indentation
+ $def = str_repeat(' ', strlen($marker_space)) . $def;
+ $def = $this->runBlockGamut($this->outdent($def . "\n\n"));
+ $def = "\n". $def ."\n";
+ }
+ else {
+ $def = rtrim($def);
+ $def = $this->runSpanGamut($this->outdent($def));
+ }
+
+ return "\n" . $def . "\n";
+ }
+
+
+ protected function doFencedCodeBlocks($text) {
+ #
+ # Adding the fenced code block syntax to regular Markdown:
+ #
+ # ~~~
+ # Code block
+ # ~~~
+ #
+ $less_than_tab = $this->tab_width;
+
+ $text = preg_replace_callback('{
+ (?:\n|\A)
+ # 1: Opening marker
+ (
+ (?:~{3,}|`{3,}) # 3 or more tildes/backticks.
+ )
+ [ ]*
+ (?:
+ \.?([-_:a-zA-Z0-9]+) # 2: standalone class name
+ |
+ '.$this->id_class_attr_catch_re.' # 3: Extra attributes
+ )?
+ [ ]* \n # Whitespace and newline following marker.
+
+ # 4: Content
+ (
+ (?>
+ (?!\1 [ ]* \n) # Not a closing marker.
+ .*\n+
+ )+
+ )
+
+ # Closing marker.
+ \1 [ ]* (?= \n )
+ }xm',
+ array(&$this, '_doFencedCodeBlocks_callback'), $text);
+
+ return $text;
+ }
+ protected function _doFencedCodeBlocks_callback($matches) {
+ $classname =& $matches[2];
+ $attrs =& $matches[3];
+ $codeblock = $matches[4];
+ $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
+ $codeblock = preg_replace_callback('/^\n+/',
+ array(&$this, '_doFencedCodeBlocks_newlines'), $codeblock);
+
+ if ($classname != "") {
+ if ($classname{0} == '.')
+ $classname = substr($classname, 1);
+ $attr_str = ' class="'.$this->code_class_prefix.$classname.'"';
+ } else {
+ $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs);
+ }
+ $pre_attr_str = $this->code_attr_on_pre ? $attr_str : '';
+ $code_attr_str = $this->code_attr_on_pre ? '' : $attr_str;
+ $codeblock = "
$codeblock
";
+
+ return "\n\n".$this->hashBlock($codeblock)."\n\n";
+ }
+ protected function _doFencedCodeBlocks_newlines($matches) {
+ return str_repeat("
empty_element_suffix",
+ strlen($matches[0]));
+ }
+
+
+ #
+ # Redefining emphasis markers so that emphasis by underscore does not
+ # work in the middle of a word.
+ #
+ protected $em_relist = array(
+ '' => '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? tags
+ #
+ # Strip leading and trailing lines:
+ $text = preg_replace('/\A\n+|\n+\z/', '', $text);
+
+ $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY);
+
+ #
+ # Wrap
tags and unhashify HTML blocks
+ #
+ foreach ($grafs as $key => $value) {
+ $value = trim($this->runSpanGamut($value));
+
+ # Check if this should be enclosed in a paragraph.
+ # Clean tag hashes & block tag hashes are left alone.
+ $is_p = !preg_match('/^B\x1A[0-9]+B|^C\x1A[0-9]+C$/', $value);
+
+ if ($is_p) {
+ $value = "
$value
";
+ }
+ $grafs[$key] = $value;
+ }
+
+ # Join grafs in one text, then unhash HTML tags.
+ $text = implode("\n\n", $grafs);
+
+ # Finish by removing any tag hashes still present in $text.
+ $text = $this->unhash($text);
+
+ return $text;
+ }
+
+
+ ### Footnotes
+
+ protected function stripFootnotes($text) {
+ #
+ # Strips link definitions from text, stores the URLs and titles in
+ # hash references.
+ #
+ $less_than_tab = $this->tab_width - 1;
+
+ # Link defs are in the form: [^id]: url "optional title"
+ $text = preg_replace_callback('{
+ ^[ ]{0,'.$less_than_tab.'}\[\^(.+?)\][ ]?: # note_id = $1
+ [ ]*
+ \n? # maybe *one* newline
+ ( # text = $2 (no blank lines allowed)
+ (?:
+ .+ # actual text
+ |
+ \n # newlines but
+ (?!\[\^.+?\]:\s)# negative lookahead for footnote marker.
+ (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed
+ # by non-indented content
+ )*
+ )
+ }xm',
+ array(&$this, '_stripFootnotes_callback'),
+ $text);
+ return $text;
+ }
+ protected function _stripFootnotes_callback($matches) {
+ $note_id = $this->fn_id_prefix . $matches[1];
+ $this->footnotes[$note_id] = $this->outdent($matches[2]);
+ return ''; # String that will replace the block
+ }
+
+
+ protected function doFootnotes($text) {
+ #
+ # Replace footnote references in $text [^id] with a special text-token
+ # which will be replaced by the actual footnote marker in appendFootnotes.
+ #
+ if (!$this->in_anchor) {
+ $text = preg_replace('{\[\^(.+?)\]}', "F\x1Afn:\\1\x1A:", $text);
+ }
+ return $text;
+ }
+
+
+ protected function appendFootnotes($text) {
+ #
+ # Append footnote list to text.
+ #
+ $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}',
+ array(&$this, '_appendFootnotes_callback'), $text);
+
+ if (!empty($this->footnotes_ordered)) {
+ $text .= "\n\n";
+ $text .= "";
+ }
+ return $text;
+ }
+ protected function _appendFootnotes_callback($matches) {
+ $node_id = $this->fn_id_prefix . $matches[1];
+
+ # Create footnote marker only if it has a corresponding footnote *and*
+ # the footnote hasn't been used by another marker.
+ if (isset($this->footnotes[$node_id])) {
+ $num =& $this->footnotes_numbers[$node_id];
+ if (!isset($num)) {
+ # Transfer footnote content to the ordered list and give it its
+ # number
+ $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id];
+ $this->footnotes_ref_count[$node_id] = 1;
+ $num = $this->footnote_counter++;
+ $ref_count_mark = '';
+ } else {
+ $ref_count_mark = $this->footnotes_ref_count[$node_id] += 1;
+ }
+
+ $attr = "";
+ if ($this->fn_link_class != "") {
+ $class = $this->fn_link_class;
+ $class = $this->encodeAttribute($class);
+ $attr .= " class=\"$class\"";
+ }
+ if ($this->fn_link_title != "") {
+ $title = $this->fn_link_title;
+ $title = $this->encodeAttribute($title);
+ $attr .= " title=\"$title\"";
+ }
+
+ $attr = str_replace("%%", $num, $attr);
+ $node_id = $this->encodeAttribute($node_id);
+
+ return
+ "
".
+ "$num".
+ "";
+ }
+
+ return "[^".$matches[1]."]";
+ }
+
+
+ ### Abbreviations ###
+
+ protected function stripAbbreviations($text) {
+ #
+ # Strips abbreviations from text, stores titles in hash references.
+ #
+ $less_than_tab = $this->tab_width - 1;
+
+ # Link defs are in the form: [id]*: url "optional title"
+ $text = preg_replace_callback('{
+ ^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?: # abbr_id = $1
+ (.*) # text = $2 (no blank lines allowed)
+ }xm',
+ array(&$this, '_stripAbbreviations_callback'),
+ $text);
+ return $text;
+ }
+ protected function _stripAbbreviations_callback($matches) {
+ $abbr_word = $matches[1];
+ $abbr_desc = $matches[2];
+ if ($this->abbr_word_re)
+ $this->abbr_word_re .= '|';
+ $this->abbr_word_re .= preg_quote($abbr_word);
+ $this->abbr_desciptions[$abbr_word] = trim($abbr_desc);
+ return ''; # String that will replace the block
+ }
+
+
+ protected function doAbbreviations($text) {
+ #
+ # Find defined abbreviations in text and wrap them in
elements.
+ #
+ if ($this->abbr_word_re) {
+ // cannot use the /x modifier because abbr_word_re may
+ // contain significant spaces:
+ $text = preg_replace_callback('{'.
+ '(?abbr_word_re.')'.
+ '(?![\w\x1A])'.
+ '}',
+ array(&$this, '_doAbbreviations_callback'), $text);
+ }
+ return $text;
+ }
+ protected function _doAbbreviations_callback($matches) {
+ $abbr = $matches[0];
+ if (isset($this->abbr_desciptions[$abbr])) {
+ $desc = $this->abbr_desciptions[$abbr];
+ if (empty($desc)) {
+ return $this->hashPart("$abbr");
+ } else {
+ $desc = $this->encodeAttribute($desc);
+ return $this->hashPart("$abbr");
+ }
+ } else {
+ return $matches[0];
+ }
+ }
+
+}
diff --git a/sources/vendor/Michelf/MarkdownExtra.inc.php b/sources/vendor/Michelf/MarkdownExtra.inc.php
new file mode 100644
index 0000000..e11b1ef
--- /dev/null
+++ b/sources/vendor/Michelf/MarkdownExtra.inc.php
@@ -0,0 +1,11 @@
+
+#
+# Original Markdown
+# Copyright (c) 2004-2006 John Gruber
+#
+#
+namespace Michelf;
+
+
+# Just force Michelf/Markdown.php to load. This is needed to load
+# the temporary implementation class. See below for details.
+\Michelf\Markdown::MARKDOWNLIB_VERSION;
+
+#
+# Markdown Extra Parser Class
+#
+# Note: Currently the implementation resides in the temporary class
+# \Michelf\MarkdownExtra_TmpImpl (in the same file as \Michelf\Markdown).
+# This makes it easier to propagate the changes between the three different
+# packaging styles of PHP Markdown. Once this issue is resolved, the
+# _MarkdownExtra_TmpImpl will disappear and this one will contain the code.
+#
+
+class MarkdownExtra extends \Michelf\_MarkdownExtra_TmpImpl {
+
+ ### Parser Implementation ###
+
+ # Temporarily, the implemenation is in the _MarkdownExtra_TmpImpl class.
+ # See note above.
+
+}
+
diff --git a/sources/vendor/Michelf/MarkdownInterface.inc.php b/sources/vendor/Michelf/MarkdownInterface.inc.php
new file mode 100644
index 0000000..a023ed4
--- /dev/null
+++ b/sources/vendor/Michelf/MarkdownInterface.inc.php
@@ -0,0 +1,9 @@
+
+#
+# Original Markdown
+# Copyright (c) 2004-2006 John Gruber
+#
+#
+namespace Michelf;
+
+
+#
+# Markdown Parser Interface
+#
+
+interface MarkdownInterface {
+
+ #
+ # Initialize the parser and return the result of its transform method.
+ # This will work fine for derived classes too.
+ #
+ public static function defaultTransform($text);
+
+ #
+ # Main function. Performs some preprocessing on the input text
+ # and pass it through the document gamut.
+ #
+ public function transform($text);
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/sources/vendor/OAuth/Common/AutoLoader.php b/sources/vendor/OAuth/Common/AutoLoader.php
new file mode 100644
index 0000000..9fe7951
--- /dev/null
+++ b/sources/vendor/OAuth/Common/AutoLoader.php
@@ -0,0 +1,81 @@
+
+ */
+class AutoLoader
+{
+ /**
+ * @var string The namespace prefix for this instance.
+ */
+ protected $namespace = '';
+
+ /**
+ * @var string The filesystem prefix to use for this instance
+ */
+ protected $path = '';
+
+ /**
+ * Build the instance of the autoloader
+ *
+ * @param string $namespace The prefixed namespace this instance will load
+ * @param string $path The filesystem path to the root of the namespace
+ */
+ public function __construct($namespace, $path)
+ {
+ $this->namespace = ltrim($namespace, '\\');
+ $this->path = rtrim($path, '/\\') . DIRECTORY_SEPARATOR;
+ }
+
+ /**
+ * Try to load a class
+ *
+ * @param string $class The class name to load
+ *
+ * @return boolean If the loading was successful
+ */
+ public function load($class)
+ {
+ $class = ltrim($class, '\\');
+
+ if (strpos($class, $this->namespace) === 0) {
+ $nsparts = explode('\\', $class);
+ $class = array_pop($nsparts);
+ $nsparts[] = '';
+ $path = $this->path . implode(DIRECTORY_SEPARATOR, $nsparts);
+ $path .= str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
+
+ if (file_exists($path)) {
+ require $path;
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Register the autoloader to PHP
+ *
+ * @return boolean The status of the registration
+ */
+ public function register()
+ {
+ return spl_autoload_register(array($this, 'load'));
+ }
+
+ /**
+ * Unregister the autoloader to PHP
+ *
+ * @return boolean The status of the unregistration
+ */
+ public function unregister()
+ {
+ return spl_autoload_unregister(array($this, 'load'));
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Consumer/Credentials.php b/sources/vendor/OAuth/Common/Consumer/Credentials.php
new file mode 100644
index 0000000..8e98e9f
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Consumer/Credentials.php
@@ -0,0 +1,60 @@
+consumerId = $consumerId;
+ $this->consumerSecret = $consumerSecret;
+ $this->callbackUrl = $callbackUrl;
+ }
+
+ /**
+ * @return string
+ */
+ public function getCallbackUrl()
+ {
+ return $this->callbackUrl;
+ }
+
+ /**
+ * @return string
+ */
+ public function getConsumerId()
+ {
+ return $this->consumerId;
+ }
+
+ /**
+ * @return string
+ */
+ public function getConsumerSecret()
+ {
+ return $this->consumerSecret;
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Consumer/CredentialsInterface.php b/sources/vendor/OAuth/Common/Consumer/CredentialsInterface.php
new file mode 100644
index 0000000..a33e54e
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Consumer/CredentialsInterface.php
@@ -0,0 +1,24 @@
+userAgent = $userAgent;
+ }
+
+ /**
+ * @param int $redirects Maximum redirects for client
+ *
+ * @return ClientInterface
+ */
+ public function setMaxRedirects($redirects)
+ {
+ $this->maxRedirects = $redirects;
+
+ return $this;
+ }
+
+ /**
+ * @param int $timeout Request timeout time for client in seconds
+ *
+ * @return ClientInterface
+ */
+ public function setTimeout($timeout)
+ {
+ $this->timeout = $timeout;
+
+ return $this;
+ }
+
+ /**
+ * @param array $headers
+ */
+ public function normalizeHeaders(&$headers)
+ {
+ // Normalize headers
+ array_walk(
+ $headers,
+ function (&$val, &$key) {
+ $key = ucfirst(strtolower($key));
+ $val = ucfirst(strtolower($key)) . ': ' . $val;
+ }
+ );
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Http/Client/ClientInterface.php b/sources/vendor/OAuth/Common/Http/Client/ClientInterface.php
new file mode 100644
index 0000000..f9c2022
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Http/Client/ClientInterface.php
@@ -0,0 +1,32 @@
+ value` pairs) to be passed to `curl_setopt`
+ *
+ * @var array
+ */
+ private $parameters = array();
+
+ /**
+ * Additional `curl_setopt` parameters
+ *
+ * @param array $parameters
+ */
+ public function setCurlParameters(array $parameters)
+ {
+ $this->parameters = $parameters;
+ }
+
+ /**
+ * @param bool $force
+ *
+ * @return CurlClient
+ */
+ public function setForceSSL3($force)
+ {
+ $this->forceSSL3 = $force;
+
+ return $this;
+ }
+
+ /**
+ * Any implementing HTTP providers should send a request to the provided endpoint with the parameters.
+ * They should return, in string form, the response body and throw an exception on error.
+ *
+ * @param UriInterface $endpoint
+ * @param mixed $requestBody
+ * @param array $extraHeaders
+ * @param string $method
+ *
+ * @return string
+ *
+ * @throws TokenResponseException
+ * @throws \InvalidArgumentException
+ */
+ public function retrieveResponse(
+ UriInterface $endpoint,
+ $requestBody,
+ array $extraHeaders = array(),
+ $method = 'POST'
+ ) {
+ // Normalize method name
+ $method = strtoupper($method);
+
+ $this->normalizeHeaders($extraHeaders);
+
+ if ($method === 'GET' && !empty($requestBody)) {
+ throw new \InvalidArgumentException('No body expected for "GET" request.');
+ }
+
+ if (!isset($extraHeaders['Content-Type']) && $method === 'POST' && is_array($requestBody)) {
+ $extraHeaders['Content-Type'] = 'Content-Type: application/x-www-form-urlencoded';
+ }
+
+ $extraHeaders['Host'] = 'Host: '.$endpoint->getHost();
+ $extraHeaders['Connection'] = 'Connection: close';
+
+ $ch = curl_init();
+
+ curl_setopt($ch, CURLOPT_URL, $endpoint->getAbsoluteUri());
+
+ if ($method === 'POST' || $method === 'PUT') {
+ if ($requestBody && is_array($requestBody)) {
+ $requestBody = http_build_query($requestBody, '', '&');
+ }
+
+ if ($method === 'PUT') {
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
+ } else {
+ curl_setopt($ch, CURLOPT_POST, true);
+ }
+
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
+ } else {
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
+ }
+
+ if ($this->maxRedirects > 0) {
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ curl_setopt($ch, CURLOPT_MAXREDIRS, $this->maxRedirects);
+ }
+
+ curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_HEADER, false);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $extraHeaders);
+ curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
+
+ foreach ($this->parameters as $key => $value) {
+ curl_setopt($ch, $key, $value);
+ }
+
+ if ($this->forceSSL3) {
+ curl_setopt($ch, CURLOPT_SSLVERSION, 3);
+ }
+
+ $response = curl_exec($ch);
+ $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+ if (false === $response) {
+ $errNo = curl_errno($ch);
+ $errStr = curl_error($ch);
+ curl_close($ch);
+ if (empty($errStr)) {
+ throw new TokenResponseException('Failed to request resource.', $responseCode);
+ }
+ throw new TokenResponseException('cURL Error # '.$errNo.': '.$errStr, $responseCode);
+ }
+
+ curl_close($ch);
+
+ return $response;
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Http/Client/StreamClient.php b/sources/vendor/OAuth/Common/Http/Client/StreamClient.php
new file mode 100644
index 0000000..7f3c524
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Http/Client/StreamClient.php
@@ -0,0 +1,92 @@
+normalizeHeaders($extraHeaders);
+
+ if ($method === 'GET' && !empty($requestBody)) {
+ throw new \InvalidArgumentException('No body expected for "GET" request.');
+ }
+
+ if (!isset($extraHeaders['Content-Type']) && $method === 'POST' && is_array($requestBody)) {
+ $extraHeaders['Content-Type'] = 'Content-Type: application/x-www-form-urlencoded';
+ }
+
+ $host = 'Host: '.$endpoint->getHost();
+ // Append port to Host if it has been specified
+ if ($endpoint->hasExplicitPortSpecified()) {
+ $host .= ':'.$endpoint->getPort();
+ }
+
+ $extraHeaders['Host'] = $host;
+ $extraHeaders['Connection'] = 'Connection: close';
+
+ if (is_array($requestBody)) {
+ $requestBody = http_build_query($requestBody, '', '&');
+ }
+ $extraHeaders['Content-length'] = 'Content-length: '.strlen($requestBody);
+
+ $context = $this->generateStreamContext($requestBody, $extraHeaders, $method);
+
+ $level = error_reporting(0);
+ $response = file_get_contents($endpoint->getAbsoluteUri(), false, $context);
+ error_reporting($level);
+ if (false === $response) {
+ $lastError = error_get_last();
+ if (is_null($lastError)) {
+ throw new TokenResponseException('Failed to request resource.');
+ }
+ throw new TokenResponseException($lastError['message']);
+ }
+
+ return $response;
+ }
+
+ private function generateStreamContext($body, $headers, $method)
+ {
+ return stream_context_create(
+ array(
+ 'http' => array(
+ 'method' => $method,
+ 'header' => implode("\r\n", array_values($headers)),
+ 'content' => $body,
+ 'protocol_version' => '1.1',
+ 'user_agent' => $this->userAgent,
+ 'max_redirects' => $this->maxRedirects,
+ 'timeout' => $this->timeout
+ ),
+ )
+ );
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Http/Exception/TokenResponseException.php b/sources/vendor/OAuth/Common/Http/Exception/TokenResponseException.php
new file mode 100644
index 0000000..c519a22
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Http/Exception/TokenResponseException.php
@@ -0,0 +1,12 @@
+parseUri($uri);
+ }
+ }
+
+ /**
+ * @param string $uri
+ *
+ * @throws \InvalidArgumentException
+ */
+ protected function parseUri($uri)
+ {
+ if (false === ($uriParts = parse_url($uri))) {
+ // congratulations if you've managed to get parse_url to fail,
+ // it seems to always return some semblance of a parsed url no matter what
+ throw new InvalidArgumentException("Invalid URI: $uri");
+ }
+
+ if (!isset($uriParts['scheme'])) {
+ throw new InvalidArgumentException('Invalid URI: http|https scheme required');
+ }
+
+ $this->scheme = $uriParts['scheme'];
+ $this->host = $uriParts['host'];
+
+ if (isset($uriParts['port'])) {
+ $this->port = $uriParts['port'];
+ $this->explicitPortSpecified = true;
+ } else {
+ $this->port = strcmp('https', $uriParts['scheme']) ? 80 : 443;
+ $this->explicitPortSpecified = false;
+ }
+
+ if (isset($uriParts['path'])) {
+ $this->path = $uriParts['path'];
+ if ('/' === $uriParts['path']) {
+ $this->explicitTrailingHostSlash = true;
+ }
+ } else {
+ $this->path = '/';
+ }
+
+ $this->query = isset($uriParts['query']) ? $uriParts['query'] : '';
+ $this->fragment = isset($uriParts['fragment']) ? $uriParts['fragment'] : '';
+
+ $userInfo = '';
+ if (!empty($uriParts['user'])) {
+ $userInfo .= $uriParts['user'];
+ }
+ if ($userInfo && !empty($uriParts['pass'])) {
+ $userInfo .= ':' . $uriParts['pass'];
+ }
+
+ $this->setUserInfo($userInfo);
+ }
+
+ /**
+ * @param string $rawUserInfo
+ *
+ * @return string
+ */
+ protected function protectUserInfo($rawUserInfo)
+ {
+ $colonPos = strpos($rawUserInfo, ':');
+
+ // rfc3986-3.2.1 | http://tools.ietf.org/html/rfc3986#section-3.2
+ // "Applications should not render as clear text any data
+ // after the first colon (":") character found within a userinfo
+ // subcomponent unless the data after the colon is the empty string
+ // (indicating no password)"
+ if ($colonPos !== false && strlen($rawUserInfo)-1 > $colonPos) {
+ return substr($rawUserInfo, 0, $colonPos) . ':********';
+ } else {
+ return $rawUserInfo;
+ }
+ }
+
+ /**
+ * @return string
+ */
+ public function getScheme()
+ {
+ return $this->scheme;
+ }
+
+ /**
+ * @return string
+ */
+ public function getUserInfo()
+ {
+ return $this->userInfo;
+ }
+
+ /**
+ * @return string
+ */
+ public function getRawUserInfo()
+ {
+ return $this->rawUserInfo;
+ }
+
+ /**
+ * @return string
+ */
+ public function getHost()
+ {
+ return $this->host;
+ }
+
+ /**
+ * @return int
+ */
+ public function getPort()
+ {
+ return $this->port;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPath()
+ {
+ return $this->path;
+ }
+
+ /**
+ * @return string
+ */
+ public function getQuery()
+ {
+ return $this->query;
+ }
+
+ /**
+ * @return string
+ */
+ public function getFragment()
+ {
+ return $this->fragment;
+ }
+
+ /**
+ * Uses protected user info by default as per rfc3986-3.2.1
+ * Uri::getRawAuthority() is available if plain-text password information is desirable.
+ *
+ * @return string
+ */
+ public function getAuthority()
+ {
+ $authority = $this->userInfo ? $this->userInfo.'@' : '';
+ $authority .= $this->host;
+
+ if ($this->explicitPortSpecified) {
+ $authority .= ":{$this->port}";
+ }
+
+ return $authority;
+ }
+
+ /**
+ * @return string
+ */
+ public function getRawAuthority()
+ {
+ $authority = $this->rawUserInfo ? $this->rawUserInfo.'@' : '';
+ $authority .= $this->host;
+
+ if ($this->explicitPortSpecified) {
+ $authority .= ":{$this->port}";
+ }
+
+ return $authority;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAbsoluteUri()
+ {
+ $uri = $this->scheme . '://' . $this->getRawAuthority();
+
+ if ('/' === $this->path) {
+ $uri .= $this->explicitTrailingHostSlash ? '/' : '';
+ } else {
+ $uri .= $this->path;
+ }
+
+ if (!empty($this->query)) {
+ $uri .= "?{$this->query}";
+ }
+
+ if (!empty($this->fragment)) {
+ $uri .= "#{$this->fragment}";
+ }
+
+ return $uri;
+ }
+
+ /**
+ * @return string
+ */
+ public function getRelativeUri()
+ {
+ $uri = '';
+
+ if ('/' === $this->path) {
+ $uri .= $this->explicitTrailingHostSlash ? '/' : '';
+ } else {
+ $uri .= $this->path;
+ }
+
+ return $uri;
+ }
+
+ /**
+ * Uses protected user info by default as per rfc3986-3.2.1
+ * Uri::getAbsoluteUri() is available if plain-text password information is desirable.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ $uri = $this->scheme . '://' . $this->getAuthority();
+
+ if ('/' === $this->path) {
+ $uri .= $this->explicitTrailingHostSlash ? '/' : '';
+ } else {
+ $uri .= $this->path;
+ }
+
+ if (!empty($this->query)) {
+ $uri .= "?{$this->query}";
+ }
+
+ if (!empty($this->fragment)) {
+ $uri .= "#{$this->fragment}";
+ }
+
+ return $uri;
+ }
+
+ /**
+ * @param $path
+ */
+ public function setPath($path)
+ {
+ if (empty($path)) {
+ $this->path = '/';
+ $this->explicitTrailingHostSlash = false;
+ } else {
+ $this->path = $path;
+ if ('/' === $this->path) {
+ $this->explicitTrailingHostSlash = true;
+ }
+ }
+ }
+
+ /**
+ * @param string $query
+ */
+ public function setQuery($query)
+ {
+ $this->query = $query;
+ }
+
+ /**
+ * @param string $var
+ * @param string $val
+ */
+ public function addToQuery($var, $val)
+ {
+ if (strlen($this->query) > 0) {
+ $this->query .= '&';
+ }
+ $this->query .= http_build_query(array($var => $val), '', '&');
+ }
+
+ /**
+ * @param string $fragment
+ */
+ public function setFragment($fragment)
+ {
+ $this->fragment = $fragment;
+ }
+
+ /**
+ * @param string $scheme
+ */
+ public function setScheme($scheme)
+ {
+ $this->scheme = $scheme;
+ }
+
+
+ /**
+ * @param string $userInfo
+ */
+ public function setUserInfo($userInfo)
+ {
+ $this->userInfo = $userInfo ? $this->protectUserInfo($userInfo) : '';
+ $this->rawUserInfo = $userInfo;
+ }
+
+
+ /**
+ * @param int $port
+ */
+ public function setPort($port)
+ {
+ $this->port = intval($port);
+
+ if (('https' === $this->scheme && $this->port === 443) || ('http' === $this->scheme && $this->port === 80)) {
+ $this->explicitPortSpecified = false;
+ } else {
+ $this->explicitPortSpecified = true;
+ }
+ }
+
+ /**
+ * @param string $host
+ */
+ public function setHost($host)
+ {
+ $this->host = $host;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasExplicitTrailingHostSlash()
+ {
+ return $this->explicitTrailingHostSlash;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasExplicitPortSpecified()
+ {
+ return $this->explicitPortSpecified;
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Http/Uri/UriFactory.php b/sources/vendor/OAuth/Common/Http/Uri/UriFactory.php
new file mode 100644
index 0000000..127aa20
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Http/Uri/UriFactory.php
@@ -0,0 +1,168 @@
+attemptProxyStyleParse($_server)) {
+ return $uri;
+ }
+
+ $scheme = $this->detectScheme($_server);
+ $host = $this->detectHost($_server);
+ $port = $this->detectPort($_server);
+ $path = $this->detectPath($_server);
+ $query = $this->detectQuery($_server);
+
+ return $this->createFromParts($scheme, '', $host, $port, $path, $query);
+ }
+
+ /**
+ * @param string $absoluteUri
+ *
+ * @return UriInterface
+ */
+ public function createFromAbsolute($absoluteUri)
+ {
+ return new Uri($absoluteUri);
+ }
+
+ /**
+ * Factory method to build a URI from parts
+ *
+ * @param string $scheme
+ * @param string $userInfo
+ * @param string $host
+ * @param string $port
+ * @param string $path
+ * @param string $query
+ * @param string $fragment
+ *
+ * @return UriInterface
+ */
+ public function createFromParts($scheme, $userInfo, $host, $port, $path = '', $query = '', $fragment = '')
+ {
+ $uri = new Uri();
+ $uri->setScheme($scheme);
+ $uri->setUserInfo($userInfo);
+ $uri->setHost($host);
+ $uri->setPort($port);
+ $uri->setPath($path);
+ $uri->setQuery($query);
+ $uri->setFragment($fragment);
+
+ return $uri;
+ }
+
+ /**
+ * @param array $_server
+ *
+ * @return UriInterface|null
+ */
+ private function attemptProxyStyleParse($_server)
+ {
+ // If the raw HTTP request message arrives with a proxy-style absolute URI in the
+ // initial request line, the absolute URI is stored in $_SERVER['REQUEST_URI'] and
+ // we only need to parse that.
+ if (isset($_server['REQUEST_URI']) && parse_url($_server['REQUEST_URI'], PHP_URL_SCHEME)) {
+ return new Uri($_server['REQUEST_URI']);
+ }
+
+ return null;
+ }
+
+ /**
+ * @param array $_server
+ *
+ * @return string
+ *
+ * @throws RuntimeException
+ */
+ private function detectPath($_server)
+ {
+ if (isset($_server['REQUEST_URI'])) {
+ $uri = $_server['REQUEST_URI'];
+ } elseif (isset($_server['REDIRECT_URL'])) {
+ $uri = $_server['REDIRECT_URL'];
+ } else {
+ throw new RuntimeException('Could not detect URI path from superglobal');
+ }
+
+ $queryStr = strpos($uri, '?');
+ if ($queryStr !== false) {
+ $uri = substr($uri, 0, $queryStr);
+ }
+
+ return $uri;
+ }
+
+ /**
+ * @param array $_server
+ *
+ * @return string
+ */
+ private function detectHost(array $_server)
+ {
+ $host = isset($_server['HTTP_HOST']) ? $_server['HTTP_HOST'] : '';
+
+ if (strstr($host, ':')) {
+ $host = parse_url($host, PHP_URL_HOST);
+ }
+
+ return $host;
+ }
+
+ /**
+ * @param array $_server
+ *
+ * @return string
+ */
+ private function detectPort(array $_server)
+ {
+ return isset($_server['SERVER_PORT']) ? $_server['SERVER_PORT'] : 80;
+ }
+
+ /**
+ * @param array $_server
+ *
+ * @return string
+ */
+ private function detectQuery(array $_server)
+ {
+ return isset($_server['QUERY_STRING']) ? $_server['QUERY_STRING'] : '';
+ }
+
+ /**
+ * Determine URI scheme component from superglobal array
+ *
+ * When using ISAPI with IIS, the value will be "off" if the request was
+ * not made through the HTTPS protocol. As a result, we filter the
+ * value to a bool.
+ *
+ * @param array $_server A super-global $_SERVER array
+ *
+ * @return string Returns http or https depending on the URI scheme
+ */
+ private function detectScheme(array $_server)
+ {
+ if (isset($_server['HTTPS']) && filter_var($_server['HTTPS'], FILTER_VALIDATE_BOOLEAN)) {
+ return 'https';
+ } else {
+ return 'http';
+ }
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Http/Uri/UriFactoryInterface.php b/sources/vendor/OAuth/Common/Http/Uri/UriFactoryInterface.php
new file mode 100644
index 0000000..2b157d8
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Http/Uri/UriFactoryInterface.php
@@ -0,0 +1,42 @@
+credentials = $credentials;
+ $this->httpClient = $httpClient;
+ $this->storage = $storage;
+ }
+
+ /**
+ * @param UriInterface|string $path
+ * @param UriInterface $baseApiUri
+ *
+ * @return UriInterface
+ *
+ * @throws Exception
+ */
+ protected function determineRequestUriFromPath($path, UriInterface $baseApiUri = null)
+ {
+ if ($path instanceof UriInterface) {
+ $uri = $path;
+ } elseif (stripos($path, 'http://') === 0 || stripos($path, 'https://') === 0) {
+ $uri = new Uri($path);
+ } else {
+ if (null === $baseApiUri) {
+ throw new Exception(
+ 'An absolute URI must be passed to ServiceInterface::request as no baseApiUri is set.'
+ );
+ }
+
+ $uri = clone $baseApiUri;
+ if (false !== strpos($path, '?')) {
+ $parts = explode('?', $path, 2);
+ $path = $parts[0];
+ $query = $parts[1];
+ $uri->setQuery($query);
+ }
+
+ if ($path[0] === '/') {
+ $path = substr($path, 1);
+ }
+
+ $uri->setPath($uri->getPath() . $path);
+ }
+
+ return $uri;
+ }
+
+ /**
+ * Accessor to the storage adapter to be able to retrieve tokens
+ *
+ * @return TokenStorageInterface
+ */
+ public function getStorage()
+ {
+ return $this->storage;
+ }
+
+ /**
+ * @return string
+ */
+ public function service()
+ {
+ // get class name without backslashes
+ $classname = get_class($this);
+
+ return preg_replace('/^.*\\\\/', '', $classname);
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Service/ServiceInterface.php b/sources/vendor/OAuth/Common/Service/ServiceInterface.php
new file mode 100644
index 0000000..5856a03
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Service/ServiceInterface.php
@@ -0,0 +1,49 @@
+tokens = array();
+ $this->states = array();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function retrieveAccessToken($service)
+ {
+ if ($this->hasAccessToken($service)) {
+ return $this->tokens[$service];
+ }
+
+ throw new TokenNotFoundException('Token not stored');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function storeAccessToken($service, TokenInterface $token)
+ {
+ $this->tokens[$service] = $token;
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function hasAccessToken($service)
+ {
+ return isset($this->tokens[$service]) && $this->tokens[$service] instanceof TokenInterface;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearToken($service)
+ {
+ if (array_key_exists($service, $this->tokens)) {
+ unset($this->tokens[$service]);
+ }
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearAllTokens()
+ {
+ $this->tokens = array();
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function retrieveAuthorizationState($service)
+ {
+ if ($this->hasAuthorizationState($service)) {
+ return $this->states[$service];
+ }
+
+ throw new AuthorizationStateNotFoundException('State not stored');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function storeAuthorizationState($service, $state)
+ {
+ $this->states[$service] = $state;
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function hasAuthorizationState($service)
+ {
+ return isset($this->states[$service]) && null !== $this->states[$service];
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearAuthorizationState($service)
+ {
+ if (array_key_exists($service, $this->states)) {
+ unset($this->states[$service]);
+ }
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearAllAuthorizationStates()
+ {
+ $this->states = array();
+
+ // allow chaining
+ return $this;
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Storage/Redis.php b/sources/vendor/OAuth/Common/Storage/Redis.php
new file mode 100644
index 0000000..77318bd
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Storage/Redis.php
@@ -0,0 +1,230 @@
+redis = $redis;
+ $this->key = $key;
+ $this->stateKey = $stateKey;
+ $this->cachedTokens = array();
+ $this->cachedStates = array();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function retrieveAccessToken($service)
+ {
+ if (!$this->hasAccessToken($service)) {
+ throw new TokenNotFoundException('Token not found in redis');
+ }
+
+ if (isset($this->cachedTokens[$service])) {
+ return $this->cachedTokens[$service];
+ }
+
+ $val = $this->redis->hget($this->key, $service);
+
+ return $this->cachedTokens[$service] = unserialize($val);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function storeAccessToken($service, TokenInterface $token)
+ {
+ // (over)write the token
+ $this->redis->hset($this->key, $service, serialize($token));
+ $this->cachedTokens[$service] = $token;
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function hasAccessToken($service)
+ {
+ if (isset($this->cachedTokens[$service])
+ && $this->cachedTokens[$service] instanceof TokenInterface
+ ) {
+ return true;
+ }
+
+ return $this->redis->hexists($this->key, $service);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearToken($service)
+ {
+ $this->redis->hdel($this->key, $service);
+ unset($this->cachedTokens[$service]);
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearAllTokens()
+ {
+ // memory
+ $this->cachedTokens = array();
+
+ // redis
+ $keys = $this->redis->hkeys($this->key);
+ $me = $this; // 5.3 compat
+
+ // pipeline for performance
+ $this->redis->pipeline(
+ function ($pipe) use ($keys, $me) {
+ foreach ($keys as $k) {
+ $pipe->hdel($me->getKey(), $k);
+ }
+ }
+ );
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function retrieveAuthorizationState($service)
+ {
+ if (!$this->hasAuthorizationState($service)) {
+ throw new AuthorizationStateNotFoundException('State not found in redis');
+ }
+
+ if (isset($this->cachedStates[$service])) {
+ return $this->cachedStates[$service];
+ }
+
+ $val = $this->redis->hget($this->stateKey, $service);
+
+ return $this->cachedStates[$service] = unserialize($val);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function storeAuthorizationState($service, $state)
+ {
+ // (over)write the token
+ $this->redis->hset($this->stateKey, $service, $state);
+ $this->cachedStates[$service] = $state;
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function hasAuthorizationState($service)
+ {
+ if (isset($this->cachedStates[$service])
+ && null !== $this->cachedStates[$service]
+ ) {
+ return true;
+ }
+
+ return $this->redis->hexists($this->stateKey, $service);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearAuthorizationState($service)
+ {
+ $this->redis->hdel($this->stateKey, $service);
+ unset($this->cachedStates[$service]);
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearAllAuthorizationStates()
+ {
+ // memory
+ $this->cachedStates = array();
+
+ // redis
+ $keys = $this->redis->hkeys($this->stateKey);
+ $me = $this; // 5.3 compat
+
+ // pipeline for performance
+ $this->redis->pipeline(
+ function ($pipe) use ($keys, $me) {
+ foreach ($keys as $k) {
+ $pipe->hdel($me->getKey(), $k);
+ }
+ }
+ );
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * @return Predis $redis
+ */
+ public function getRedis()
+ {
+ return $this->redis;
+ }
+
+ /**
+ * @return string $key
+ */
+ public function getKey()
+ {
+ return $this->key;
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Storage/Session.php b/sources/vendor/OAuth/Common/Storage/Session.php
new file mode 100644
index 0000000..e908a67
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Storage/Session.php
@@ -0,0 +1,188 @@
+startSession = $startSession;
+ $this->sessionVariableName = $sessionVariableName;
+ $this->stateVariableName = $stateVariableName;
+ if (!isset($_SESSION[$sessionVariableName])) {
+ $_SESSION[$sessionVariableName] = array();
+ }
+ if (!isset($_SESSION[$stateVariableName])) {
+ $_SESSION[$stateVariableName] = array();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function retrieveAccessToken($service)
+ {
+ if ($this->hasAccessToken($service)) {
+ return unserialize($_SESSION[$this->sessionVariableName][$service]);
+ }
+
+ throw new TokenNotFoundException('Token not found in session, are you sure you stored it?');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function storeAccessToken($service, TokenInterface $token)
+ {
+ $serializedToken = serialize($token);
+
+ if (isset($_SESSION[$this->sessionVariableName])
+ && is_array($_SESSION[$this->sessionVariableName])
+ ) {
+ $_SESSION[$this->sessionVariableName][$service] = $serializedToken;
+ } else {
+ $_SESSION[$this->sessionVariableName] = array(
+ $service => $serializedToken,
+ );
+ }
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function hasAccessToken($service)
+ {
+ return isset($_SESSION[$this->sessionVariableName], $_SESSION[$this->sessionVariableName][$service]);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearToken($service)
+ {
+ if (array_key_exists($service, $_SESSION[$this->sessionVariableName])) {
+ unset($_SESSION[$this->sessionVariableName][$service]);
+ }
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearAllTokens()
+ {
+ unset($_SESSION[$this->sessionVariableName]);
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function storeAuthorizationState($service, $state)
+ {
+ if (isset($_SESSION[$this->stateVariableName])
+ && is_array($_SESSION[$this->stateVariableName])
+ ) {
+ $_SESSION[$this->stateVariableName][$service] = $state;
+ } else {
+ $_SESSION[$this->stateVariableName] = array(
+ $service => $state,
+ );
+ }
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function hasAuthorizationState($service)
+ {
+ return isset($_SESSION[$this->stateVariableName], $_SESSION[$this->stateVariableName][$service]);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function retrieveAuthorizationState($service)
+ {
+ if ($this->hasAuthorizationState($service)) {
+ return $_SESSION[$this->stateVariableName][$service];
+ }
+
+ throw new AuthorizationStateNotFoundException('State not found in session, are you sure you stored it?');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearAuthorizationState($service)
+ {
+ if (array_key_exists($service, $_SESSION[$this->stateVariableName])) {
+ unset($_SESSION[$this->stateVariableName][$service]);
+ }
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearAllAuthorizationStates()
+ {
+ unset($_SESSION[$this->stateVariableName]);
+
+ // allow chaining
+ return $this;
+ }
+
+ public function __destruct()
+ {
+ if ($this->startSession) {
+ session_write_close();
+ }
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Storage/SymfonySession.php b/sources/vendor/OAuth/Common/Storage/SymfonySession.php
new file mode 100644
index 0000000..6c5fbf6
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Storage/SymfonySession.php
@@ -0,0 +1,200 @@
+session = $session;
+ $this->sessionVariableName = $sessionVariableName;
+ $this->stateVariableName = $stateVariableName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function retrieveAccessToken($service)
+ {
+ if ($this->hasAccessToken($service)) {
+ // get from session
+ $tokens = $this->session->get($this->sessionVariableName);
+
+ // one item
+ return $tokens[$service];
+ }
+
+ throw new TokenNotFoundException('Token not found in session, are you sure you stored it?');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function storeAccessToken($service, TokenInterface $token)
+ {
+ // get previously saved tokens
+ $tokens = $this->session->get($this->sessionVariableName);
+
+ if (!is_array($tokens)) {
+ $tokens = array();
+ }
+
+ $tokens[$service] = $token;
+
+ // save
+ $this->session->set($this->sessionVariableName, $tokens);
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function hasAccessToken($service)
+ {
+ // get from session
+ $tokens = $this->session->get($this->sessionVariableName);
+
+ return is_array($tokens)
+ && isset($tokens[$service])
+ && $tokens[$service] instanceof TokenInterface;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearToken($service)
+ {
+ // get previously saved tokens
+ $tokens = $this->session->get($this->sessionVariableName);
+
+ if (is_array($tokens) && array_key_exists($service, $tokens)) {
+ unset($tokens[$service]);
+
+ // Replace the stored tokens array
+ $this->session->set($this->sessionVariableName, $tokens);
+ }
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearAllTokens()
+ {
+ $this->session->remove($this->sessionVariableName);
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function retrieveAuthorizationState($service)
+ {
+ if ($this->hasAuthorizationState($service)) {
+ // get from session
+ $states = $this->session->get($this->stateVariableName);
+
+ // one item
+ return $states[$service];
+ }
+
+ throw new AuthorizationStateNotFoundException('State not found in session, are you sure you stored it?');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function storeAuthorizationState($service, $state)
+ {
+ // get previously saved tokens
+ $states = $this->session->get($this->stateVariableName);
+
+ if (!is_array($states)) {
+ $states = array();
+ }
+
+ $states[$service] = $state;
+
+ // save
+ $this->session->set($this->stateVariableName, $states);
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function hasAuthorizationState($service)
+ {
+ // get from session
+ $states = $this->session->get($this->stateVariableName);
+
+ return is_array($states)
+ && isset($states[$service])
+ && null !== $states[$service];
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearAuthorizationState($service)
+ {
+ // get previously saved tokens
+ $states = $this->session->get($this->stateVariableName);
+
+ if (is_array($states) && array_key_exists($service, $states)) {
+ unset($states[$service]);
+
+ // Replace the stored tokens array
+ $this->session->set($this->stateVariableName, $states);
+ }
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function clearAllAuthorizationStates()
+ {
+ $this->session->remove($this->stateVariableName);
+
+ // allow chaining
+ return $this;
+ }
+
+ /**
+ * @return Session
+ */
+ public function getSession()
+ {
+ return $this->session;
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Storage/TokenStorageInterface.php b/sources/vendor/OAuth/Common/Storage/TokenStorageInterface.php
new file mode 100644
index 0000000..46552ce
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Storage/TokenStorageInterface.php
@@ -0,0 +1,98 @@
+accessToken = $accessToken;
+ $this->refreshToken = $refreshToken;
+ $this->setLifetime($lifetime);
+ $this->extraParams = $extraParams;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAccessToken()
+ {
+ return $this->accessToken;
+ }
+
+ /**
+ * @return string
+ */
+ public function getRefreshToken()
+ {
+ return $this->refreshToken;
+ }
+
+ /**
+ * @return int
+ */
+ public function getEndOfLife()
+ {
+ return $this->endOfLife;
+ }
+
+ /**
+ * @param array $extraParams
+ */
+ public function setExtraParams(array $extraParams)
+ {
+ $this->extraParams = $extraParams;
+ }
+
+ /**
+ * @return array
+ */
+ public function getExtraParams()
+ {
+ return $this->extraParams;
+ }
+
+ /**
+ * @param string $accessToken
+ */
+ public function setAccessToken($accessToken)
+ {
+ $this->accessToken = $accessToken;
+ }
+
+ /**
+ * @param int $endOfLife
+ */
+ public function setEndOfLife($endOfLife)
+ {
+ $this->endOfLife = $endOfLife;
+ }
+
+ /**
+ * @param int $lifetime
+ */
+ public function setLifetime($lifetime)
+ {
+ if (0 === $lifetime || static::EOL_NEVER_EXPIRES === $lifetime) {
+ $this->endOfLife = static::EOL_NEVER_EXPIRES;
+ } elseif (null !== $lifetime) {
+ $this->endOfLife = intval($lifetime) + time();
+ } else {
+ $this->endOfLife = static::EOL_UNKNOWN;
+ }
+ }
+
+ /**
+ * @param string $refreshToken
+ */
+ public function setRefreshToken($refreshToken)
+ {
+ $this->refreshToken = $refreshToken;
+ }
+}
diff --git a/sources/vendor/OAuth/Common/Token/Exception/ExpiredTokenException.php b/sources/vendor/OAuth/Common/Token/Exception/ExpiredTokenException.php
new file mode 100644
index 0000000..26ad6cc
--- /dev/null
+++ b/sources/vendor/OAuth/Common/Token/Exception/ExpiredTokenException.php
@@ -0,0 +1,12 @@
+signature = $signature;
+ $this->baseApiUri = $baseApiUri;
+
+ $this->signature->setHashingAlgorithm($this->getSignatureMethod());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function requestRequestToken()
+ {
+ $authorizationHeader = array('Authorization' => $this->buildAuthorizationHeaderForTokenRequest());
+ $headers = array_merge($authorizationHeader, $this->getExtraOAuthHeaders());
+
+ $responseBody = $this->httpClient->retrieveResponse($this->getRequestTokenEndpoint(), array(), $headers);
+
+ $token = $this->parseRequestTokenResponse($responseBody);
+ $this->storage->storeAccessToken($this->service(), $token);
+
+ return $token;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationUri(array $additionalParameters = array())
+ {
+ // Build the url
+ $url = clone $this->getAuthorizationEndpoint();
+ foreach ($additionalParameters as $key => $val) {
+ $url->addToQuery($key, $val);
+ }
+
+ return $url;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function requestAccessToken($token, $verifier, $tokenSecret = null)
+ {
+ if (is_null($tokenSecret)) {
+ $storedRequestToken = $this->storage->retrieveAccessToken($this->service());
+ $tokenSecret = $storedRequestToken->getRequestTokenSecret();
+ }
+ $this->signature->setTokenSecret($tokenSecret);
+
+ $extraAuthenticationHeaders = array(
+ 'oauth_token' => $token,
+ );
+
+ $bodyParams = array(
+ 'oauth_verifier' => $verifier,
+ );
+
+ $authorizationHeader = array(
+ 'Authorization' => $this->buildAuthorizationHeaderForAPIRequest(
+ 'POST',
+ $this->getAccessTokenEndpoint(),
+ $this->storage->retrieveAccessToken($this->service()),
+ $bodyParams
+ )
+ );
+
+ $headers = array_merge($authorizationHeader, $this->getExtraOAuthHeaders());
+
+ $responseBody = $this->httpClient->retrieveResponse($this->getAccessTokenEndpoint(), $bodyParams, $headers);
+
+ $token = $this->parseAccessTokenResponse($responseBody);
+ $this->storage->storeAccessToken($this->service(), $token);
+
+ return $token;
+ }
+
+ /**
+ * Sends an authenticated API request to the path provided.
+ * If the path provided is not an absolute URI, the base API Uri (must be passed into constructor) will be used.
+ *
+ * @param string|UriInterface $path
+ * @param string $method HTTP method
+ * @param array $body Request body if applicable (key/value pairs)
+ * @param array $extraHeaders Extra headers if applicable.
+ * These will override service-specific any defaults.
+ *
+ * @return string
+ */
+ public function request($path, $method = 'GET', $body = null, array $extraHeaders = array())
+ {
+ $uri = $this->determineRequestUriFromPath($path, $this->baseApiUri);
+
+ /** @var $token StdOAuth1Token */
+ $token = $this->storage->retrieveAccessToken($this->service());
+ $extraHeaders = array_merge($this->getExtraApiHeaders(), $extraHeaders);
+ $authorizationHeader = array(
+ 'Authorization' => $this->buildAuthorizationHeaderForAPIRequest($method, $uri, $token, $body)
+ );
+ $headers = array_merge($authorizationHeader, $extraHeaders);
+
+ return $this->httpClient->retrieveResponse($uri, $body, $headers, $method);
+ }
+
+ /**
+ * Return any additional headers always needed for this service implementation's OAuth calls.
+ *
+ * @return array
+ */
+ protected function getExtraOAuthHeaders()
+ {
+ return array();
+ }
+
+ /**
+ * Return any additional headers always needed for this service implementation's API calls.
+ *
+ * @return array
+ */
+ protected function getExtraApiHeaders()
+ {
+ return array();
+ }
+
+ /**
+ * Builds the authorization header for getting an access or request token.
+ *
+ * @param array $extraParameters
+ *
+ * @return string
+ */
+ protected function buildAuthorizationHeaderForTokenRequest(array $extraParameters = array())
+ {
+ $parameters = $this->getBasicAuthorizationHeaderInfo();
+ $parameters = array_merge($parameters, $extraParameters);
+ $parameters['oauth_signature'] = $this->signature->getSignature(
+ $this->getRequestTokenEndpoint(),
+ $parameters,
+ 'POST'
+ );
+
+ $authorizationHeader = 'OAuth ';
+ $delimiter = '';
+ foreach ($parameters as $key => $value) {
+ $authorizationHeader .= $delimiter . rawurlencode($key) . '="' . rawurlencode($value) . '"';
+
+ $delimiter = ', ';
+ }
+
+ return $authorizationHeader;
+ }
+
+ /**
+ * Builds the authorization header for an authenticated API request
+ *
+ * @param string $method
+ * @param UriInterface $uri The uri the request is headed
+ * @param TokenInterface $token
+ * @param array $bodyParams Request body if applicable (key/value pairs)
+ *
+ * @return string
+ */
+ protected function buildAuthorizationHeaderForAPIRequest(
+ $method,
+ UriInterface $uri,
+ TokenInterface $token,
+ $bodyParams = null
+ ) {
+ $this->signature->setTokenSecret($token->getAccessTokenSecret());
+ $parameters = $this->getBasicAuthorizationHeaderInfo();
+ if (isset($parameters['oauth_callback'])) {
+ unset($parameters['oauth_callback']);
+ }
+
+ $parameters = array_merge($parameters, array('oauth_token' => $token->getAccessToken()));
+
+ $mergedParams = (is_array($bodyParams)) ? array_merge($parameters, $bodyParams) : $parameters;
+
+ $parameters['oauth_signature'] = $this->signature->getSignature($uri, $mergedParams, $method);
+
+ $authorizationHeader = 'OAuth ';
+ $delimiter = '';
+
+ foreach ($parameters as $key => $value) {
+ $authorizationHeader .= $delimiter . rawurlencode($key) . '="' . rawurlencode($value) . '"';
+ $delimiter = ', ';
+ }
+
+ return $authorizationHeader;
+ }
+
+ /**
+ * Builds the authorization header array.
+ *
+ * @return array
+ */
+ protected function getBasicAuthorizationHeaderInfo()
+ {
+ $dateTime = new \DateTime();
+ $headerParameters = array(
+ 'oauth_callback' => $this->credentials->getCallbackUrl(),
+ 'oauth_consumer_key' => $this->credentials->getConsumerId(),
+ 'oauth_nonce' => $this->generateNonce(),
+ 'oauth_signature_method' => $this->getSignatureMethod(),
+ 'oauth_timestamp' => $dateTime->format('U'),
+ 'oauth_version' => $this->getVersion(),
+ );
+
+ return $headerParameters;
+ }
+
+ /**
+ * Pseudo random string generator used to build a unique string to sign each request
+ *
+ * @param int $length
+ *
+ * @return string
+ */
+ protected function generateNonce($length = 32)
+ {
+ $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
+
+ $nonce = '';
+ $maxRand = strlen($characters)-1;
+ for ($i = 0; $i < $length; $i++) {
+ $nonce.= $characters[rand(0, $maxRand)];
+ }
+
+ return $nonce;
+ }
+
+ /**
+ * @return string
+ */
+ protected function getSignatureMethod()
+ {
+ return 'HMAC-SHA1';
+ }
+
+ /**
+ * This returns the version used in the authorization header of the requests
+ *
+ * @return string
+ */
+ protected function getVersion()
+ {
+ return '1.0';
+ }
+
+ /**
+ * Parses the request token response and returns a TokenInterface.
+ * This is only needed to verify the `oauth_callback_confirmed` parameter. The actual
+ * parsing logic is contained in the access token parser.
+ *
+ * @abstract
+ *
+ * @param string $responseBody
+ *
+ * @return TokenInterface
+ *
+ * @throws TokenResponseException
+ */
+ abstract protected function parseRequestTokenResponse($responseBody);
+
+ /**
+ * Parses the access token response and returns a TokenInterface.
+ *
+ * @abstract
+ *
+ * @param string $responseBody
+ *
+ * @return TokenInterface
+ *
+ * @throws TokenResponseException
+ */
+ abstract protected function parseAccessTokenResponse($responseBody);
+}
diff --git a/sources/vendor/OAuth/OAuth1/Service/BitBucket.php b/sources/vendor/OAuth/OAuth1/Service/BitBucket.php
new file mode 100644
index 0000000..f6d8edf
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth1/Service/BitBucket.php
@@ -0,0 +1,96 @@
+baseApiUri = new Uri('https://bitbucket.org/api/1.0/');
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getRequestTokenEndpoint()
+ {
+ return new Uri('https://bitbucket.org/!api/1.0/oauth/request_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://bitbucket.org/!api/1.0/oauth/authenticate');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://bitbucket.org/!api/1.0/oauth/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseRequestTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
+ throw new TokenResponseException('Error in retrieving token.');
+ }
+
+ return $this->parseAccessTokenResponse($responseBody);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth1Token();
+
+ $token->setRequestToken($data['oauth_token']);
+ $token->setRequestTokenSecret($data['oauth_token_secret']);
+ $token->setAccessToken($data['oauth_token']);
+ $token->setAccessTokenSecret($data['oauth_token_secret']);
+
+ $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
+ unset($data['oauth_token'], $data['oauth_token_secret']);
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth1/Service/Etsy.php b/sources/vendor/OAuth/OAuth1/Service/Etsy.php
new file mode 100644
index 0000000..884358e
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth1/Service/Etsy.php
@@ -0,0 +1,96 @@
+baseApiUri = new Uri('https://openapi.etsy.com/v2/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRequestTokenEndpoint()
+ {
+ return new Uri($this->baseApiUri . 'oauth/request_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri($this->baseApiUri);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri($this->baseApiUri . 'oauth/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseRequestTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
+ throw new TokenResponseException('Error in retrieving token.');
+ }
+
+ return $this->parseAccessTokenResponse($responseBody);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth1Token();
+
+ $token->setRequestToken($data['oauth_token']);
+ $token->setRequestTokenSecret($data['oauth_token_secret']);
+ $token->setAccessToken($data['oauth_token']);
+ $token->setAccessTokenSecret($data['oauth_token_secret']);
+
+ $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
+ unset($data['oauth_token'], $data['oauth_token_secret']);
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth1/Service/FitBit.php b/sources/vendor/OAuth/OAuth1/Service/FitBit.php
new file mode 100644
index 0000000..78032d7
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth1/Service/FitBit.php
@@ -0,0 +1,96 @@
+baseApiUri = new Uri('https://api.fitbit.com/1/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRequestTokenEndpoint()
+ {
+ return new Uri('https://api.fitbit.com/oauth/request_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://www.fitbit.com/oauth/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://api.fitbit.com/oauth/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseRequestTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
+ throw new TokenResponseException('Error in retrieving token.');
+ }
+
+ return $this->parseAccessTokenResponse($responseBody);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth1Token();
+
+ $token->setRequestToken($data['oauth_token']);
+ $token->setRequestTokenSecret($data['oauth_token_secret']);
+ $token->setAccessToken($data['oauth_token']);
+ $token->setAccessTokenSecret($data['oauth_token_secret']);
+
+ $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
+ unset($data['oauth_token'], $data['oauth_token_secret']);
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth1/Service/Flickr.php b/sources/vendor/OAuth/OAuth1/Service/Flickr.php
new file mode 100644
index 0000000..f06d282
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth1/Service/Flickr.php
@@ -0,0 +1,91 @@
+baseApiUri = new Uri('https://api.flickr.com/services/rest/');
+ }
+ }
+
+ public function getRequestTokenEndpoint()
+ {
+ return new Uri('https://www.flickr.com/services/oauth/request_token');
+ }
+
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://www.flickr.com/services/oauth/authorize');
+ }
+
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://www.flickr.com/services/oauth/access_token');
+ }
+
+ protected function parseRequestTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] != 'true') {
+ throw new TokenResponseException('Error in retrieving token.');
+ }
+ return $this->parseAccessTokenResponse($responseBody);
+ }
+
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+ if ($data === null || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth1Token();
+ $token->setRequestToken($data['oauth_token']);
+ $token->setRequestTokenSecret($data['oauth_token_secret']);
+ $token->setAccessToken($data['oauth_token']);
+ $token->setAccessTokenSecret($data['oauth_token_secret']);
+ $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
+ unset($data['oauth_token'], $data['oauth_token_secret']);
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+
+ public function request($path, $method = 'GET', $body = null, array $extraHeaders = array())
+ {
+ $uri = $this->determineRequestUriFromPath('/', $this->baseApiUri);
+ $uri->addToQuery('method', $path);
+
+ $token = $this->storage->retrieveAccessToken($this->service());
+ $extraHeaders = array_merge($this->getExtraApiHeaders(), $extraHeaders);
+ $authorizationHeader = array(
+ 'Authorization' => $this->buildAuthorizationHeaderForAPIRequest($method, $uri, $token, $body)
+ );
+ $headers = array_merge($authorizationHeader, $extraHeaders);
+
+ return $this->httpClient->retrieveResponse($uri, $body, $headers, $method);
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth1/Service/ScoopIt.php b/sources/vendor/OAuth/OAuth1/Service/ScoopIt.php
new file mode 100644
index 0000000..28bd250
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth1/Service/ScoopIt.php
@@ -0,0 +1,96 @@
+baseApiUri = new Uri('https://www.scoop.it/api/1/');
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getRequestTokenEndpoint()
+ {
+ return new Uri('https://www.scoop.it/oauth/request');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://www.scoop.it/oauth/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://www.scoop.it/oauth/access');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseRequestTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
+ throw new TokenResponseException('Error in retrieving token.');
+ }
+
+ return $this->parseAccessTokenResponse($responseBody);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth1Token();
+
+ $token->setRequestToken($data['oauth_token']);
+ $token->setRequestTokenSecret($data['oauth_token_secret']);
+ $token->setAccessToken($data['oauth_token']);
+ $token->setAccessTokenSecret($data['oauth_token_secret']);
+
+ $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
+ unset($data['oauth_token'], $data['oauth_token_secret']);
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth1/Service/ServiceInterface.php b/sources/vendor/OAuth/OAuth1/Service/ServiceInterface.php
new file mode 100644
index 0000000..3f91fbf
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth1/Service/ServiceInterface.php
@@ -0,0 +1,45 @@
+baseApiUri = new Uri('https://api.tumblr.com/v2/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRequestTokenEndpoint()
+ {
+ return new Uri('https://www.tumblr.com/oauth/request_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://www.tumblr.com/oauth/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://www.tumblr.com/oauth/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseRequestTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
+ throw new TokenResponseException('Error in retrieving token.');
+ }
+
+ return $this->parseAccessTokenResponse($responseBody);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth1Token();
+
+ $token->setRequestToken($data['oauth_token']);
+ $token->setRequestTokenSecret($data['oauth_token_secret']);
+ $token->setAccessToken($data['oauth_token']);
+ $token->setAccessTokenSecret($data['oauth_token_secret']);
+
+ $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
+ unset($data['oauth_token'], $data['oauth_token_secret']);
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth1/Service/Twitter.php b/sources/vendor/OAuth/OAuth1/Service/Twitter.php
new file mode 100644
index 0000000..f46c34e
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth1/Service/Twitter.php
@@ -0,0 +1,121 @@
+baseApiUri = new Uri('https://api.twitter.com/1.1/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRequestTokenEndpoint()
+ {
+ return new Uri('https://api.twitter.com/oauth/request_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ if ($this->authorizationEndpoint != self::ENDPOINT_AUTHENTICATE
+ && $this->authorizationEndpoint != self::ENDPOINT_AUTHORIZE) {
+ $this->authorizationEndpoint = self::ENDPOINT_AUTHENTICATE;
+ }
+ return new Uri($this->authorizationEndpoint);
+ }
+
+ /**
+ * @param string $authorizationEndpoint
+ *
+ * @throws Exception
+ */
+ public function setAuthorizationEndpoint($endpoint)
+ {
+ if ($endpoint != self::ENDPOINT_AUTHENTICATE && $endpoint != self::ENDPOINT_AUTHORIZE) {
+ throw new Exception(
+ sprintf("'%s' is not a correct Twitter authorization endpoint.", $endpoint)
+ );
+ }
+ $this->authorizationEndpoint = $endpoint;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://api.twitter.com/oauth/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseRequestTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
+ throw new TokenResponseException('Error in retrieving token.');
+ }
+
+ return $this->parseAccessTokenResponse($responseBody);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth1Token();
+
+ $token->setRequestToken($data['oauth_token']);
+ $token->setRequestTokenSecret($data['oauth_token_secret']);
+ $token->setAccessToken($data['oauth_token']);
+ $token->setAccessTokenSecret($data['oauth_token_secret']);
+
+ $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
+ unset($data['oauth_token'], $data['oauth_token_secret']);
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth1/Service/Xing.php b/sources/vendor/OAuth/OAuth1/Service/Xing.php
new file mode 100644
index 0000000..03e3357
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth1/Service/Xing.php
@@ -0,0 +1,96 @@
+baseApiUri = new Uri('https://api.xing.com/v1/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://api.xing.com/v1/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://api.xing.com/v1/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRequestTokenEndpoint()
+ {
+ return new Uri('https://api.xing.com/v1/request_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseRequestTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
+ throw new TokenResponseException('Error in retrieving token.');
+ }
+
+ return $this->parseAccessTokenResponse($responseBody);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth1Token();
+
+ $token->setRequestToken($data['oauth_token']);
+ $token->setRequestTokenSecret($data['oauth_token_secret']);
+ $token->setAccessToken($data['oauth_token']);
+ $token->setAccessTokenSecret($data['oauth_token_secret']);
+
+ $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
+ unset($data['oauth_token'], $data['oauth_token_secret']);
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth1/Service/Yahoo.php b/sources/vendor/OAuth/OAuth1/Service/Yahoo.php
new file mode 100644
index 0000000..cff291d
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth1/Service/Yahoo.php
@@ -0,0 +1,96 @@
+baseApiUri = new Uri('https://social.yahooapis.com/v1/');
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getRequestTokenEndpoint()
+ {
+ return new Uri('https://api.login.yahoo.com/oauth/v2/get_request_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://api.login.yahoo.com/oauth/v2/request_auth');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://api.login.yahoo.com/oauth/v2/get_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseRequestTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
+ throw new TokenResponseException('Error in retrieving token.');
+ }
+
+ return $this->parseAccessTokenResponse($responseBody);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth1Token();
+
+ $token->setRequestToken($data['oauth_token']);
+ $token->setRequestTokenSecret($data['oauth_token_secret']);
+ $token->setAccessToken($data['oauth_token']);
+ $token->setAccessTokenSecret($data['oauth_token_secret']);
+
+ $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
+ unset($data['oauth_token'], $data['oauth_token_secret']);
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth1/Signature/Exception/UnsupportedHashAlgorithmException.php b/sources/vendor/OAuth/OAuth1/Signature/Exception/UnsupportedHashAlgorithmException.php
new file mode 100644
index 0000000..44c36ce
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth1/Signature/Exception/UnsupportedHashAlgorithmException.php
@@ -0,0 +1,12 @@
+credentials = $credentials;
+ }
+
+ /**
+ * @param string $algorithm
+ */
+ public function setHashingAlgorithm($algorithm)
+ {
+ $this->algorithm = $algorithm;
+ }
+
+ /**
+ * @param string $token
+ */
+ public function setTokenSecret($token)
+ {
+ $this->tokenSecret = $token;
+ }
+
+ /**
+ * @param UriInterface $uri
+ * @param array $params
+ * @param string $method
+ *
+ * @return string
+ */
+ public function getSignature(UriInterface $uri, array $params, $method = 'POST')
+ {
+ parse_str($uri->getQuery(), $queryStringData);
+
+ foreach (array_merge($queryStringData, $params) as $key => $value) {
+ $signatureData[rawurlencode($key)] = rawurlencode($value);
+ }
+
+ ksort($signatureData);
+
+ // determine base uri
+ $baseUri = $uri->getScheme() . '://' . $uri->getRawAuthority();
+
+ if ('/' === $uri->getPath()) {
+ $baseUri .= $uri->hasExplicitTrailingHostSlash() ? '/' : '';
+ } else {
+ $baseUri .= $uri->getPath();
+ }
+
+ $baseString = strtoupper($method) . '&';
+ $baseString .= rawurlencode($baseUri) . '&';
+ $baseString .= rawurlencode($this->buildSignatureDataString($signatureData));
+
+ return base64_encode($this->hash($baseString));
+ }
+
+ /**
+ * @param array $signatureData
+ *
+ * @return string
+ */
+ protected function buildSignatureDataString(array $signatureData)
+ {
+ $signatureString = '';
+ $delimiter = '';
+ foreach ($signatureData as $key => $value) {
+ $signatureString .= $delimiter . $key . '=' . $value;
+
+ $delimiter = '&';
+ }
+
+ return $signatureString;
+ }
+
+ /**
+ * @return string
+ */
+ protected function getSigningKey()
+ {
+ $signingKey = rawurlencode($this->credentials->getConsumerSecret()) . '&';
+ if ($this->tokenSecret !== null) {
+ $signingKey .= rawurlencode($this->tokenSecret);
+ }
+
+ return $signingKey;
+ }
+
+ /**
+ * @param string $data
+ *
+ * @return string
+ *
+ * @throws UnsupportedHashAlgorithmException
+ */
+ protected function hash($data)
+ {
+ switch (strtoupper($this->algorithm)) {
+ case 'HMAC-SHA1':
+ return hash_hmac('sha1', $data, $this->getSigningKey(), true);
+ default:
+ throw new UnsupportedHashAlgorithmException(
+ 'Unsupported hashing algorithm (' . $this->algorithm . ') used.'
+ );
+ }
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth1/Signature/SignatureInterface.php b/sources/vendor/OAuth/OAuth1/Signature/SignatureInterface.php
new file mode 100644
index 0000000..da50ddb
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth1/Signature/SignatureInterface.php
@@ -0,0 +1,28 @@
+requestToken = $requestToken;
+ }
+
+ /**
+ * @return string
+ */
+ public function getRequestToken()
+ {
+ return $this->requestToken;
+ }
+
+ /**
+ * @param string $requestTokenSecret
+ */
+ public function setRequestTokenSecret($requestTokenSecret)
+ {
+ $this->requestTokenSecret = $requestTokenSecret;
+ }
+
+ /**
+ * @return string
+ */
+ public function getRequestTokenSecret()
+ {
+ return $this->requestTokenSecret;
+ }
+
+ /**
+ * @param string $accessTokenSecret
+ */
+ public function setAccessTokenSecret($accessTokenSecret)
+ {
+ $this->accessTokenSecret = $accessTokenSecret;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAccessTokenSecret()
+ {
+ return $this->accessTokenSecret;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth1/Token/TokenInterface.php b/sources/vendor/OAuth/OAuth1/Token/TokenInterface.php
new file mode 100644
index 0000000..0bc3f73
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth1/Token/TokenInterface.php
@@ -0,0 +1,41 @@
+stateParameterInAuthUrl = $stateParameterInAutUrl;
+
+ foreach ($scopes as $scope) {
+ if (!$this->isValidScope($scope)) {
+ throw new InvalidScopeException('Scope ' . $scope . ' is not valid for service ' . get_class($this));
+ }
+ }
+
+ $this->scopes = $scopes;
+
+ $this->baseApiUri = $baseApiUri;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationUri(array $additionalParameters = array())
+ {
+ $parameters = array_merge(
+ $additionalParameters,
+ array(
+ 'type' => 'web_server',
+ 'client_id' => $this->credentials->getConsumerId(),
+ 'redirect_uri' => $this->credentials->getCallbackUrl(),
+ 'response_type' => 'code',
+ )
+ );
+
+ $parameters['scope'] = implode(' ', $this->scopes);
+
+ if ($this->needsStateParameterInAuthUrl()) {
+ if (!isset($parameters['state'])) {
+ $parameters['state'] = $this->generateAuthorizationState();
+ }
+ $this->storeAuthorizationState($parameters['state']);
+ }
+
+ // Build the url
+ $url = clone $this->getAuthorizationEndpoint();
+ foreach ($parameters as $key => $val) {
+ $url->addToQuery($key, $val);
+ }
+
+ return $url;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function requestAccessToken($code, $state = null)
+ {
+ if (null !== $state) {
+ $this->validateAuthorizationState($state);
+ }
+
+ $bodyParams = array(
+ 'code' => $code,
+ 'client_id' => $this->credentials->getConsumerId(),
+ 'client_secret' => $this->credentials->getConsumerSecret(),
+ 'redirect_uri' => $this->credentials->getCallbackUrl(),
+ 'grant_type' => 'authorization_code',
+ );
+
+ $responseBody = $this->httpClient->retrieveResponse(
+ $this->getAccessTokenEndpoint(),
+ $bodyParams,
+ $this->getExtraOAuthHeaders()
+ );
+
+ $token = $this->parseAccessTokenResponse($responseBody);
+ $this->storage->storeAccessToken($this->service(), $token);
+
+ return $token;
+ }
+
+ /**
+ * Sends an authenticated API request to the path provided.
+ * If the path provided is not an absolute URI, the base API Uri (must be passed into constructor) will be used.
+ *
+ * @param string|UriInterface $path
+ * @param string $method HTTP method
+ * @param array $body Request body if applicable.
+ * @param array $extraHeaders Extra headers if applicable. These will override service-specific
+ * any defaults.
+ *
+ * @return string
+ *
+ * @throws ExpiredTokenException
+ * @throws Exception
+ */
+ public function request($path, $method = 'GET', $body = null, array $extraHeaders = array())
+ {
+ $uri = $this->determineRequestUriFromPath($path, $this->baseApiUri);
+ $token = $this->storage->retrieveAccessToken($this->service());
+
+ if ($token->getEndOfLife() !== TokenInterface::EOL_NEVER_EXPIRES
+ && $token->getEndOfLife() !== TokenInterface::EOL_UNKNOWN
+ && time() > $token->getEndOfLife()
+ ) {
+ throw new ExpiredTokenException(
+ sprintf(
+ 'Token expired on %s at %s',
+ date('m/d/Y', $token->getEndOfLife()),
+ date('h:i:s A', $token->getEndOfLife())
+ )
+ );
+ }
+
+ // add the token where it may be needed
+ if (static::AUTHORIZATION_METHOD_HEADER_OAUTH === $this->getAuthorizationMethod()) {
+ $extraHeaders = array_merge(array('Authorization' => 'OAuth ' . $token->getAccessToken()), $extraHeaders);
+ } elseif (static::AUTHORIZATION_METHOD_QUERY_STRING === $this->getAuthorizationMethod()) {
+ $uri->addToQuery('access_token', $token->getAccessToken());
+ } elseif (static::AUTHORIZATION_METHOD_QUERY_STRING_V2 === $this->getAuthorizationMethod()) {
+ $uri->addToQuery('oauth2_access_token', $token->getAccessToken());
+ } elseif (static::AUTHORIZATION_METHOD_QUERY_STRING_V3 === $this->getAuthorizationMethod()) {
+ $uri->addToQuery('apikey', $token->getAccessToken());
+ } elseif (static::AUTHORIZATION_METHOD_HEADER_BEARER === $this->getAuthorizationMethod()) {
+ $extraHeaders = array_merge(array('Authorization' => 'Bearer ' . $token->getAccessToken()), $extraHeaders);
+ }
+
+ $extraHeaders = array_merge($this->getExtraApiHeaders(), $extraHeaders);
+
+ return $this->httpClient->retrieveResponse($uri, $body, $extraHeaders, $method);
+ }
+
+ /**
+ * Accessor to the storage adapter to be able to retrieve tokens
+ *
+ * @return TokenStorageInterface
+ */
+ public function getStorage()
+ {
+ return $this->storage;
+ }
+
+ /**
+ * Refreshes an OAuth2 access token.
+ *
+ * @param TokenInterface $token
+ *
+ * @return TokenInterface $token
+ *
+ * @throws MissingRefreshTokenException
+ */
+ public function refreshAccessToken(TokenInterface $token)
+ {
+ $refreshToken = $token->getRefreshToken();
+
+ if (empty($refreshToken)) {
+ throw new MissingRefreshTokenException();
+ }
+
+ $parameters = array(
+ 'grant_type' => 'refresh_token',
+ 'type' => 'web_server',
+ 'client_id' => $this->credentials->getConsumerId(),
+ 'client_secret' => $this->credentials->getConsumerSecret(),
+ 'refresh_token' => $refreshToken,
+ );
+
+ $responseBody = $this->httpClient->retrieveResponse(
+ $this->getAccessTokenEndpoint(),
+ $parameters,
+ $this->getExtraOAuthHeaders()
+ );
+ $token = $this->parseAccessTokenResponse($responseBody);
+ $this->storage->storeAccessToken($this->service(), $token);
+
+ return $token;
+ }
+
+ /**
+ * Return whether or not the passed scope value is valid.
+ *
+ * @param string $scope
+ *
+ * @return bool
+ */
+ public function isValidScope($scope)
+ {
+ $reflectionClass = new \ReflectionClass(get_class($this));
+
+ return in_array($scope, $reflectionClass->getConstants(), true);
+ }
+
+ /**
+ * Check if the given service need to generate a unique state token to build the authorization url
+ *
+ * @return bool
+ */
+ public function needsStateParameterInAuthUrl()
+ {
+ return $this->stateParameterInAuthUrl;
+ }
+
+ /**
+ * Validates the authorization state against a given one
+ *
+ * @param string $state
+ * @throws InvalidAuthorizationStateException
+ */
+ protected function validateAuthorizationState($state)
+ {
+ if ($this->retrieveAuthorizationState() !== $state) {
+ throw new InvalidAuthorizationStateException();
+ }
+ }
+
+ /**
+ * Generates a random string to be used as state
+ *
+ * @return string
+ */
+ protected function generateAuthorizationState()
+ {
+ return md5(rand());
+ }
+
+ /**
+ * Retrieves the authorization state for the current service
+ *
+ * @return string
+ */
+ protected function retrieveAuthorizationState()
+ {
+ return $this->storage->retrieveAuthorizationState($this->service());
+ }
+
+ /**
+ * Stores a given authorization state into the storage
+ *
+ * @param string $state
+ */
+ protected function storeAuthorizationState($state)
+ {
+ $this->storage->storeAuthorizationState($this->service(), $state);
+ }
+
+ /**
+ * Return any additional headers always needed for this service implementation's OAuth calls.
+ *
+ * @return array
+ */
+ protected function getExtraOAuthHeaders()
+ {
+ return array();
+ }
+
+ /**
+ * Return any additional headers always needed for this service implementation's API calls.
+ *
+ * @return array
+ */
+ protected function getExtraApiHeaders()
+ {
+ return array();
+ }
+
+ /**
+ * Parses the access token response and returns a TokenInterface.
+ *
+ * @abstract
+ *
+ * @param string $responseBody
+ *
+ * @return TokenInterface
+ *
+ * @throws TokenResponseException
+ */
+ abstract protected function parseAccessTokenResponse($responseBody);
+
+ /**
+ * Returns a class constant from ServiceInterface defining the authorization method used for the API
+ * Header is the sane default.
+ *
+ * @return int
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_HEADER_OAUTH;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Amazon.php b/sources/vendor/OAuth/OAuth2/Service/Amazon.php
new file mode 100644
index 0000000..035d1a5
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Amazon.php
@@ -0,0 +1,97 @@
+
+ * @link https://images-na.ssl-images-amazon.com/images/G/01/lwa/dev/docs/website-developer-guide._TTH_.pdf
+ */
+class Amazon extends AbstractService
+{
+ /**
+ * Defined scopes
+ * @link https://images-na.ssl-images-amazon.com/images/G/01/lwa/dev/docs/website-developer-guide._TTH_.pdf
+ */
+ const SCOPE_PROFILE = 'profile';
+ const SCOPE_POSTAL_CODE = 'postal_code';
+
+ public function __construct(
+ CredentialsInterface $credentials,
+ ClientInterface $httpClient,
+ TokenStorageInterface $storage,
+ $scopes = array(),
+ UriInterface $baseApiUri = null
+ ) {
+ parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
+
+ if (null === $baseApiUri) {
+ $this->baseApiUri = new Uri('https://api.amazon.com/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://www.amazon.com/ap/oa');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://www.amazon.com/ap/oatoken');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_HEADER_BEARER;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error_description'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error_description'] . '"');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ $token->setLifeTime($data['expires_in']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+ unset($data['expires_in']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Bitly.php b/sources/vendor/OAuth/OAuth2/Service/Bitly.php
new file mode 100644
index 0000000..e01cbc4
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Bitly.php
@@ -0,0 +1,111 @@
+baseApiUri = new Uri('https://api-ssl.bitly.com/v3/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://bitly.com/oauth/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://api-ssl.bitly.com/oauth/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_QUERY_STRING;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ // I'm invincible!!!
+ $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
+ unset($data['access_token']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function requestAccessToken($code, $state = null)
+ {
+ if (null !== $state) {
+ $this->validateAuthorizationState($state);
+ }
+
+ $bodyParams = array(
+ 'code' => $code,
+ 'client_id' => $this->credentials->getConsumerId(),
+ 'client_secret' => $this->credentials->getConsumerSecret(),
+ 'redirect_uri' => $this->credentials->getCallbackUrl(),
+ 'grant_type' => 'authorization_code',
+ );
+
+ $responseBody = $this->httpClient->retrieveResponse(
+ $this->getAccessTokenEndpoint(),
+ $bodyParams,
+ $this->getExtraOAuthHeaders()
+ );
+
+ // we can scream what we want that we want bitly to return a json encoded string (format=json), but the
+ // WOAH WATCH YOUR LANGUAGE ;) service doesn't seem to like screaming, hence we need to manually
+ // parse the result
+ $parsedResult = array();
+ parse_str($responseBody, $parsedResult);
+
+ $token = $this->parseAccessTokenResponse(json_encode($parsedResult));
+ $this->storage->storeAccessToken($this->service(), $token);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Box.php b/sources/vendor/OAuth/OAuth2/Service/Box.php
new file mode 100644
index 0000000..14696c5
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Box.php
@@ -0,0 +1,88 @@
+
+ * @link https://developers.box.com/oauth/
+ */
+class Box extends AbstractService
+{
+ public function __construct(
+ CredentialsInterface $credentials,
+ ClientInterface $httpClient,
+ TokenStorageInterface $storage,
+ $scopes = array(),
+ UriInterface $baseApiUri = null
+ ) {
+ parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri, true);
+
+ if (null === $baseApiUri) {
+ $this->baseApiUri = new Uri('https://api.box.com/2.0/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://www.box.com/api/oauth2/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://www.box.com/api/oauth2/token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_HEADER_BEARER;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ $token->setLifeTime($data['expires_in']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+ unset($data['expires_in']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Dailymotion.php b/sources/vendor/OAuth/OAuth2/Service/Dailymotion.php
new file mode 100644
index 0000000..095a467
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Dailymotion.php
@@ -0,0 +1,129 @@
+
+ * @link http://www.dailymotion.com/doc/api/authentication.html
+ */
+class Dailymotion extends AbstractService
+{
+ /**
+ * Scopes
+ *
+ * @var string
+ */
+ const SCOPE_EMAIL = 'email',
+ SCOPE_PROFILE = 'userinfo',
+ SCOPE_VIDEOS = 'manage_videos',
+ SCOPE_COMMENTS = 'manage_comments',
+ SCOPE_PLAYLIST = 'manage_playlists',
+ SCOPE_TILES = 'manage_tiles',
+ SCOPE_SUBSCRIPTIONS = 'manage_subscriptions',
+ SCOPE_FRIENDS = 'manage_friends',
+ SCOPE_FAVORITES = 'manage_favorites',
+ SCOPE_GROUPS = 'manage_groups';
+
+ /**
+ * Dialog form factors
+ *
+ * @var string
+ */
+ const DISPLAY_PAGE = 'page',
+ DISPLAY_POPUP = 'popup',
+ DISPLAY_MOBILE = 'mobile';
+
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct(
+ CredentialsInterface $credentials,
+ ClientInterface $httpClient,
+ TokenStorageInterface $storage,
+ $scopes = array(),
+ UriInterface $baseApiUri = null
+ ) {
+ parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
+
+ if (null === $baseApiUri) {
+ $this->baseApiUri = new Uri('https://api.dailymotion.com/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://api.dailymotion.com/oauth/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://api.dailymotion.com/oauth/token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_HEADER_OAUTH;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error_description']) || isset($data['error'])) {
+ throw new TokenResponseException(
+ sprintf(
+ 'Error in retrieving token: "%s"',
+ isset($data['error_description']) ? $data['error_description'] : $data['error']
+ )
+ );
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ $token->setLifeTime($data['expires_in']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+ unset($data['expires_in']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getExtraOAuthHeaders()
+ {
+ return array('Accept' => 'application/json');
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Dropbox.php b/sources/vendor/OAuth/OAuth2/Service/Dropbox.php
new file mode 100644
index 0000000..43ec6c7
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Dropbox.php
@@ -0,0 +1,111 @@
+
+ * @link https://www.dropbox.com/developers/core/docs
+ */
+class Dropbox extends AbstractService
+{
+ public function __construct(
+ CredentialsInterface $credentials,
+ ClientInterface $httpClient,
+ TokenStorageInterface $storage,
+ $scopes = array(),
+ UriInterface $baseApiUri = null
+ ) {
+ parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
+
+ if (null === $baseApiUri) {
+ $this->baseApiUri = new Uri('https://api.dropbox.com/1/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationUri(array $additionalParameters = array())
+ {
+ $parameters = array_merge(
+ $additionalParameters,
+ array(
+ 'client_id' => $this->credentials->getConsumerId(),
+ 'redirect_uri' => $this->credentials->getCallbackUrl(),
+ 'response_type' => 'code',
+ )
+ );
+
+ $parameters['scope'] = implode(' ', $this->scopes);
+
+ // Build the url
+ $url = clone $this->getAuthorizationEndpoint();
+ foreach ($parameters as $key => $val) {
+ $url->addToQuery($key, $val);
+ }
+
+ return $url;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://www.dropbox.com/1/oauth2/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://api.dropbox.com/1/oauth2/token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_QUERY_STRING;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Exception/InvalidAccessTypeException.php b/sources/vendor/OAuth/OAuth2/Service/Exception/InvalidAccessTypeException.php
new file mode 100644
index 0000000..398df2f
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Exception/InvalidAccessTypeException.php
@@ -0,0 +1,12 @@
+
+ * Released under the MIT license.
+ */
+
+namespace OAuth\OAuth2\Service\Exception;
+
+use OAuth\Common\Exception\Exception;
+
+/**
+ * Exception thrown when a scope provided to a service is invalid.
+ */
+class InvalidScopeException extends Exception
+{
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Exception/MissingRefreshTokenException.php b/sources/vendor/OAuth/OAuth2/Service/Exception/MissingRefreshTokenException.php
new file mode 100644
index 0000000..21eece6
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Exception/MissingRefreshTokenException.php
@@ -0,0 +1,17 @@
+
+ * Released under the MIT license.
+ */
+
+namespace OAuth\OAuth2\Service\Exception;
+
+use OAuth\Common\Exception\Exception;
+
+/**
+ * Exception thrown when service is requested to refresh the access token but no refresh token can be found.
+ */
+class MissingRefreshTokenException extends Exception
+{
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Facebook.php b/sources/vendor/OAuth/OAuth2/Service/Facebook.php
new file mode 100644
index 0000000..80b25c0
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Facebook.php
@@ -0,0 +1,193 @@
+baseApiUri = new Uri('https://graph.facebook.com/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://www.facebook.com/dialog/oauth');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://graph.facebook.com/oauth/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ // Facebook gives us a query string ... Oh wait. JSON is too simple, understand ?
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+
+ if (isset($data['expires'])) {
+ $token->setLifeTime($data['expires']);
+ }
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+ unset($data['expires']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+
+ public function getDialogUri($dialogPath, array $parameters)
+ {
+ if (!isset($parameters['redirect_uri'])) {
+ throw new Exception("Redirect uri is mandatory for this request");
+ }
+ $parameters['app_id'] = $this->credentials->getConsumerId();
+ $baseUrl = self::WWW_URL . 'dialog/' . $dialogPath;
+ $query = http_build_query($parameters);
+ return new Uri($baseUrl . '?' . $query);
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Foursquare.php b/sources/vendor/OAuth/OAuth2/Service/Foursquare.php
new file mode 100644
index 0000000..fdbabf9
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Foursquare.php
@@ -0,0 +1,81 @@
+baseApiUri = new Uri('https://api.foursquare.com/v2/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://foursquare.com/oauth2/authenticate');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://foursquare.com/oauth2/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ // Foursquare tokens evidently never expire...
+ $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
+ unset($data['access_token']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function request($path, $method = 'GET', $body = null, array $extraHeaders = array())
+ {
+ $uri = new Uri($this->baseApiUri . $path);
+ $uri->addToQuery('v', $this->apiVersionDate);
+
+ return parent::request($uri, $method, $body, $extraHeaders);
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/GitHub.php b/sources/vendor/OAuth/OAuth2/Service/GitHub.php
new file mode 100644
index 0000000..3791a27
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/GitHub.php
@@ -0,0 +1,171 @@
+baseApiUri = new Uri('https://api.github.com/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://github.com/login/oauth/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://github.com/login/oauth/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_QUERY_STRING;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ // Github tokens evidently never expire...
+ $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
+ unset($data['access_token']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+
+ /**
+ * Used to configure response type -- we want JSON from github, default is query string format
+ *
+ * @return array
+ */
+ protected function getExtraOAuthHeaders()
+ {
+ return array('Accept' => 'application/json');
+ }
+
+ /**
+ * Required for GitHub API calls.
+ *
+ * @return array
+ */
+ protected function getExtraApiHeaders()
+ {
+ return array('Accept' => 'application/vnd.github.beta+json');
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Google.php b/sources/vendor/OAuth/OAuth2/Service/Google.php
new file mode 100644
index 0000000..fbfc1f2
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Google.php
@@ -0,0 +1,152 @@
+accessType = $accessType;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://accounts.google.com/o/oauth2/auth?access_type=' . $this->accessType);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://accounts.google.com/o/oauth2/token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ $token->setLifetime($data['expires_in']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+ unset($data['expires_in']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Harvest.php b/sources/vendor/OAuth/OAuth2/Service/Harvest.php
new file mode 100644
index 0000000..86e8993
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Harvest.php
@@ -0,0 +1,85 @@
+baseApiUri = new Uri('https://api.github.com/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://api.harvestapp.com/oauth2/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://api.harvestapp.com/oauth2/token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_QUERY_STRING;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || ! is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ $token->setEndOfLife($data['expires_in']);
+
+ unset($data['access_token']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+
+ /**
+ * @return array
+ */
+ protected function getExtraOAuthHeaders()
+ {
+ return array('Accept' => 'application/json');
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Heroku.php b/sources/vendor/OAuth/OAuth2/Service/Heroku.php
new file mode 100644
index 0000000..470cedc
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Heroku.php
@@ -0,0 +1,123 @@
+
+ * @link https://devcenter.heroku.com/articles/oauth
+ */
+class Heroku extends AbstractService
+{
+ /**
+ * Defined scopes
+ * @link https://devcenter.heroku.com/articles/oauth#scopes
+ */
+ const SCOPE_GLOBAL = 'global';
+ const SCOPE_IDENTITY = 'identity';
+ const SCOPE_READ = 'read';
+ const SCOPE_WRITE = 'write';
+ const SCOPE_READ_PROTECTED = 'read-protected';
+ const SCOPE_WRITE_PROTECTED = 'write-protected';
+
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct(
+ CredentialsInterface $credentials,
+ ClientInterface $httpClient,
+ TokenStorageInterface $storage,
+ $scopes = array(),
+ UriInterface $baseApiUri = null
+ ) {
+ parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
+
+ if (null === $baseApiUri) {
+ $this->baseApiUri = new Uri('https://api.heroku.com/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://id.heroku.com/oauth/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://id.heroku.com/oauth/token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_HEADER_BEARER;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error_description']) || isset($data['error'])) {
+ throw new TokenResponseException(
+ sprintf(
+ 'Error in retrieving token: "%s"',
+ isset($data['error_description']) ? $data['error_description'] : $data['error']
+ )
+ );
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ $token->setLifeTime($data['expires_in']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+ unset($data['expires_in']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getExtraOAuthHeaders()
+ {
+ return array('Accept' => 'application/vnd.heroku+json; version=3');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getExtraApiHeaders()
+ {
+ return array('Accept' => 'application/vnd.heroku+json; version=3', 'Content-Type' => 'application/json');
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Instagram.php b/sources/vendor/OAuth/OAuth2/Service/Instagram.php
new file mode 100644
index 0000000..49e9c8c
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Instagram.php
@@ -0,0 +1,85 @@
+baseApiUri = new Uri('https://api.instagram.com/v1/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://api.instagram.com/oauth/authorize/');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://api.instagram.com/oauth/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_QUERY_STRING;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ // Instagram tokens evidently never expire...
+ $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
+ unset($data['access_token']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Linkedin.php b/sources/vendor/OAuth/OAuth2/Service/Linkedin.php
new file mode 100644
index 0000000..bb801e6
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Linkedin.php
@@ -0,0 +1,102 @@
+
+ * @link http://developer.linkedin.com/documents/authentication
+ */
+class Linkedin extends AbstractService
+{
+ /**
+ * Defined scopes
+ * @link http://developer.linkedin.com/documents/authentication#granting
+ */
+ const SCOPE_R_BASICPROFILE = 'r_basicprofile';
+ const SCOPE_R_FULLPROFILE = 'r_fullprofile';
+ const SCOPE_R_EMAILADDRESS = 'r_emailaddress';
+ const SCOPE_R_NETWORK = 'r_network';
+ const SCOPE_R_CONTACTINFO = 'r_contactinfo';
+ const SCOPE_RW_NUS = 'rw_nus';
+ const SCOPE_RW_COMPANY_ADMIN = 'rw_company_admin';
+ const SCOPE_RW_GROUPS = 'rw_groups';
+ const SCOPE_W_MESSAGES = 'w_messages';
+
+ public function __construct(
+ CredentialsInterface $credentials,
+ ClientInterface $httpClient,
+ TokenStorageInterface $storage,
+ $scopes = array(),
+ UriInterface $baseApiUri = null
+ ) {
+ parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri, true);
+
+ if (null === $baseApiUri) {
+ $this->baseApiUri = new Uri('https://api.linkedin.com/v1/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://www.linkedin.com/uas/oauth2/authorization');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://www.linkedin.com/uas/oauth2/accessToken');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_QUERY_STRING_V2;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ $token->setLifeTime($data['expires_in']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+ unset($data['expires_in']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Mailchimp.php b/sources/vendor/OAuth/OAuth2/Service/Mailchimp.php
new file mode 100644
index 0000000..42abd3c
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Mailchimp.php
@@ -0,0 +1,115 @@
+baseApiUri) && $storage->hasAccessToken($this->service())) {
+ $this->setBaseApiUri($storage->retrieveAccessToken($this->service()));
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_QUERY_STRING_V3;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://login.mailchimp.com/oauth2/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://login.mailchimp.com/oauth2/token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ // Parse JSON
+ $data = json_decode($responseBody, true);
+
+ // Do validation.
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ // Create token object.
+ $token = new StdOAuth2Token($data['access_token']);
+
+ // Set the right API endpoint.
+ $this->setBaseApiUri($token);
+
+ // Mailchimp tokens evidently never expire...
+ $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
+
+ return $token;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function request($path, $method = 'GET', $body = null, array $extraHeaders = array())
+ {
+ if (is_null($this->baseApiUri)) {
+ $this->setBaseApiUri($this->storage->retrieveAccessToken($this->service()));
+ }
+
+ return parent::request($path, $method, $body, $extraHeaders);
+ }
+
+ /**
+ * Set the right base endpoint.
+ *
+ * @param StdOAuth2Token $token
+ */
+ protected function setBaseApiUri(StdOAuth2Token $token)
+ {
+ // Make request uri.
+ $endpoint = 'https://login.mailchimp.com/oauth2/metadata?oauth_token='. $token->getAccessToken();
+
+ // Grab meta data about the token.
+ $response = $this->httpClient->retrieveResponse(new Uri($endpoint), array(), array(), 'GET');
+
+ // Parse JSON.
+ $meta = json_decode($response, true);
+
+ // Set base api uri.
+ $this->baseApiUri = new Uri('https://'. $meta['dc'] .'.api.mailchimp.com/2.0/');
+
+ // Allow chaining.
+ return $this;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Microsoft.php b/sources/vendor/OAuth/OAuth2/Service/Microsoft.php
new file mode 100644
index 0000000..183ef45
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Microsoft.php
@@ -0,0 +1,119 @@
+baseApiUri = new Uri('https://apis.live.net/v5.0/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://login.live.com/oauth20_authorize.srf');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://login.live.com/oauth20_token.srf');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_QUERY_STRING;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ $token->setLifetime($data['expires_in']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+ unset($data['expires_in']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Paypal.php b/sources/vendor/OAuth/OAuth2/Service/Paypal.php
new file mode 100644
index 0000000..761c09d
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Paypal.php
@@ -0,0 +1,103 @@
+
+ * @link https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/detailed/
+ */
+class Paypal extends AbstractService
+{
+ /**
+ * Defined scopes
+ * @link https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/detailed/
+ * @see #attributes
+ */
+ const SCOPE_OPENID = 'openid';
+ const SCOPE_PROFILE = 'profile';
+ const SCOPE_PAYPALATTRIBUTES = 'https://uri.paypal.com/services/paypalattributes';
+ const SCOPE_EMAIL = 'email';
+ const SCOPE_ADDRESS = 'address';
+ const SCOPE_PHONE = 'phone';
+ const SCOPE_EXPRESSCHECKOUT = 'https://uri.paypal.com/services/expresscheckout';
+
+ public function __construct(
+ CredentialsInterface $credentials,
+ ClientInterface $httpClient,
+ TokenStorageInterface $storage,
+ $scopes = array(),
+ UriInterface $baseApiUri = null
+ ) {
+ parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
+
+ if (null === $baseApiUri) {
+ $this->baseApiUri = new Uri('https://api.paypal.com/v1/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://api.paypal.com/v1/identity/openidconnect/tokenservice');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_HEADER_BEARER;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['message'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['message'] . '"');
+ } elseif (isset($data['name'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['name'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ $token->setLifeTime($data['expires_in']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+ unset($data['expires_in']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Pocket.php b/sources/vendor/OAuth/OAuth2/Service/Pocket.php
new file mode 100644
index 0000000..8c95544
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Pocket.php
@@ -0,0 +1,125 @@
+baseApiUri = new Uri('https://getpocket.com/v3/');
+ }
+ }
+
+ public function getRequestTokenEndpoint()
+ {
+ return new Uri('https://getpocket.com/v3/oauth/request');
+ }
+
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://getpocket.com/auth/authorize');
+ }
+
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://getpocket.com/v3/oauth/authorize');
+ }
+
+ public function getAuthorizationUri(array $additionalParameters = array())
+ {
+ $parameters = array_merge(
+ $additionalParameters,
+ array(
+ 'redirect_uri' => $this->credentials->getCallbackUrl(),
+ )
+ );
+
+ // Build the url
+ $url = clone $this->getAuthorizationEndpoint();
+ foreach ($parameters as $key => $val) {
+ $url->addToQuery($key, $val);
+ }
+
+ return $url;
+ }
+
+ public function requestRequestToken()
+ {
+ $responseBody = $this->httpClient->retrieveResponse(
+ $this->getRequestTokenEndpoint(),
+ array(
+ 'consumer_key' => $this->credentials->getConsumerId(),
+ 'redirect_uri' => $this->credentials->getCallbackUrl(),
+ )
+ );
+
+ $code = $this->parseRequestTokenResponse($responseBody);
+
+ return $code;
+ }
+
+ protected function parseRequestTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (!isset($data['code'])) {
+ throw new TokenResponseException('Error in retrieving code.');
+ }
+ return $data['code'];
+ }
+
+ public function requestAccessToken($code)
+ {
+ $bodyParams = array(
+ 'consumer_key' => $this->credentials->getConsumerId(),
+ 'code' => $code,
+ );
+
+ $responseBody = $this->httpClient->retrieveResponse(
+ $this->getAccessTokenEndpoint(),
+ $bodyParams,
+ $this->getExtraOAuthHeaders()
+ );
+ $token = $this->parseAccessTokenResponse($responseBody);
+ $this->storage->storeAccessToken($this->service(), $token);
+
+ return $token;
+ }
+
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ parse_str($responseBody, $data);
+
+ if ($data === null || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ #$token->setRequestToken($data['access_token']);
+ $token->setAccessToken($data['access_token']);
+ $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
+ unset($data['access_token']);
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Reddit.php b/sources/vendor/OAuth/OAuth2/Service/Reddit.php
new file mode 100644
index 0000000..9e524d1
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Reddit.php
@@ -0,0 +1,114 @@
+baseApiUri = new Uri('https://oauth.reddit.com');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://ssl.reddit.com/api/v1/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://ssl.reddit.com/api/v1/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_HEADER_BEARER;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ $token->setLifeTime($data['expires_in']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+ unset($data['expires_in']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getExtraOAuthHeaders()
+ {
+ // Reddit uses a Basic OAuth header
+ return array('Authorization' => 'Basic ' .
+ base64_encode($this->credentials->getConsumerId() . ':' . $this->credentials->getConsumerSecret()));
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/RunKeeper.php b/sources/vendor/OAuth/OAuth2/Service/RunKeeper.php
new file mode 100644
index 0000000..7158407
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/RunKeeper.php
@@ -0,0 +1,105 @@
+baseApiUri = new Uri('https://api.runkeeper.com/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationUri(array $additionalParameters = array())
+ {
+ $parameters = array_merge(
+ $additionalParameters,
+ array(
+ 'client_id' => $this->credentials->getConsumerId(),
+ 'redirect_uri' => $this->credentials->getCallbackUrl(),
+ 'response_type' => 'code',
+ )
+ );
+
+ $parameters['scope'] = implode(' ', $this->scopes);
+
+ // Build the url
+ $url = clone $this->getAuthorizationEndpoint();
+ foreach ($parameters as $key => $val) {
+ $url->addToQuery($key, $val);
+ }
+
+ return $url;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://runkeeper.com/apps/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://runkeeper.com/apps/token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_HEADER_BEARER;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+
+ unset($data['access_token']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Salesforce.php b/sources/vendor/OAuth/OAuth2/Service/Salesforce.php
new file mode 100644
index 0000000..7d74db9
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Salesforce.php
@@ -0,0 +1,92 @@
+parseAccessTokenResponse($responseBody);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ // Salesforce tokens evidently never expire...
+ $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
+ unset($data['access_token']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getExtraOAuthHeaders()
+ {
+ return array('Accept' => 'application/json');
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/ServiceInterface.php b/sources/vendor/OAuth/OAuth2/Service/ServiceInterface.php
new file mode 100644
index 0000000..f3d1bda
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/ServiceInterface.php
@@ -0,0 +1,37 @@
+baseApiUri = new Uri('https://api.soundcloud.com/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://soundcloud.com/connect');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://api.soundcloud.com/oauth2/token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+
+ if (isset($data['expires_in'])) {
+ $token->setLifetime($data['expires_in']);
+ unset($data['expires_in']);
+ }
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Vkontakte.php b/sources/vendor/OAuth/OAuth2/Service/Vkontakte.php
new file mode 100644
index 0000000..ddf7a8e
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Vkontakte.php
@@ -0,0 +1,108 @@
+baseApiUri = new Uri('https://api.vk.com/method/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://oauth.vk.com/authorize');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://oauth.vk.com/access_token');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']);
+ $token->setLifeTime($data['expires_in']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+ unset($data['expires_in']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_QUERY_STRING;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Service/Yammer.php b/sources/vendor/OAuth/OAuth2/Service/Yammer.php
new file mode 100644
index 0000000..994a293
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Service/Yammer.php
@@ -0,0 +1,82 @@
+baseApiUri = new Uri('https://www.yammer.com/api/v1/');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationEndpoint()
+ {
+ return new Uri('https://www.yammer.com/dialog/oauth');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAccessTokenEndpoint()
+ {
+ return new Uri('https://www.yammer.com/oauth2/access_token.json');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAuthorizationMethod()
+ {
+ return static::AUTHORIZATION_METHOD_HEADER_BEARER;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function parseAccessTokenResponse($responseBody)
+ {
+ $data = json_decode($responseBody, true);
+
+ if (null === $data || !is_array($data)) {
+ throw new TokenResponseException('Unable to parse response.');
+ } elseif (isset($data['error'])) {
+ throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
+ }
+
+ $token = new StdOAuth2Token();
+ $token->setAccessToken($data['access_token']['token']);
+ $token->setLifetime($data['access_token']['expires_at']);
+
+ if (isset($data['refresh_token'])) {
+ $token->setRefreshToken($data['refresh_token']);
+ unset($data['refresh_token']);
+ }
+
+ unset($data['access_token']);
+ unset($data['expires_in']);
+
+ $token->setExtraParams($data);
+
+ return $token;
+ }
+}
diff --git a/sources/vendor/OAuth/OAuth2/Token/StdOAuth2Token.php b/sources/vendor/OAuth/OAuth2/Token/StdOAuth2Token.php
new file mode 100644
index 0000000..eaaacac
--- /dev/null
+++ b/sources/vendor/OAuth/OAuth2/Token/StdOAuth2Token.php
@@ -0,0 +1,13 @@
+
+ * @author Pieter Hordijk
+ * @copyright Copyright (c) 2013 The authors
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
+ */
+
+namespace OAuth;
+
+use OAuth\Common\Service\ServiceInterface;
+use OAuth\Common\Consumer\CredentialsInterface;
+use OAuth\Common\Storage\TokenStorageInterface;
+use OAuth\Common\Http\Client\ClientInterface;
+use OAuth\Common\Http\Client\StreamClient;
+use OAuth\Common\Http\Uri\UriInterface;
+use OAuth\Common\Exception\Exception;
+use OAuth\OAuth1\Signature\Signature;
+
+class ServiceFactory
+{
+ /**
+ *@var ClientInterface
+ */
+ protected $httpClient;
+
+ /**
+ * @var array
+ */
+ protected $serviceClassMap = array(
+ 'OAuth1' => array(),
+ 'OAuth2' => array()
+ );
+
+ /**
+ * @var array
+ */
+ protected $serviceBuilders = array(
+ 'OAuth2' => 'buildV2Service',
+ 'OAuth1' => 'buildV1Service',
+ );
+
+ /**
+ * @param ClientInterface $httpClient
+ *
+ * @return ServiceFactory
+ */
+ public function setHttpClient(ClientInterface $httpClient)
+ {
+ $this->httpClient = $httpClient;
+
+ return $this;
+ }
+
+ /**
+ * Register a custom service to classname mapping.
+ *
+ * @param string $serviceName Name of the service
+ * @param string $className Class to instantiate
+ *
+ * @return ServiceFactory
+ *
+ * @throws Exception If the class is nonexistent or does not implement a valid ServiceInterface
+ */
+ public function registerService($serviceName, $className)
+ {
+ if (!class_exists($className)) {
+ throw new Exception(sprintf('Service class %s does not exist.', $className));
+ }
+
+ $reflClass = new \ReflectionClass($className);
+
+ foreach (array('OAuth2', 'OAuth1') as $version) {
+ if ($reflClass->implementsInterface('OAuth\\' . $version . '\\Service\\ServiceInterface')) {
+ $this->serviceClassMap[$version][ucfirst($serviceName)] = $className;
+
+ return $this;
+ }
+ }
+
+ throw new Exception(sprintf('Service class %s must implement ServiceInterface.', $className));
+ }
+
+ /**
+ * Builds and returns oauth services
+ *
+ * It will first try to build an OAuth2 service and if none found it will try to build an OAuth1 service
+ *
+ * @param string $serviceName Name of service to create
+ * @param CredentialsInterface $credentials
+ * @param TokenStorageInterface $storage
+ * @param array|null $scopes If creating an oauth2 service, array of scopes
+ * @param UriInterface|null $baseApiUri
+ *
+ * @return ServiceInterface
+ */
+ public function createService(
+ $serviceName,
+ CredentialsInterface $credentials,
+ TokenStorageInterface $storage,
+ $scopes = array(),
+ UriInterface $baseApiUri = null
+ ) {
+ if (!$this->httpClient) {
+ // for backwards compatibility.
+ $this->httpClient = new StreamClient();
+ }
+
+ foreach ($this->serviceBuilders as $version => $buildMethod) {
+ $fullyQualifiedServiceName = $this->getFullyQualifiedServiceName($serviceName, $version);
+
+ if (class_exists($fullyQualifiedServiceName)) {
+ return $this->$buildMethod($fullyQualifiedServiceName, $credentials, $storage, $scopes, $baseApiUri);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Gets the fully qualified name of the service
+ *
+ * @param string $serviceName The name of the service of which to get the fully qualified name
+ * @param string $type The type of the service to get (either OAuth1 or OAuth2)
+ *
+ * @return string The fully qualified name of the service
+ */
+ private function getFullyQualifiedServiceName($serviceName, $type)
+ {
+ $serviceName = ucfirst($serviceName);
+
+ if (isset($this->serviceClassMap[$type][$serviceName])) {
+ return $this->serviceClassMap[$type][$serviceName];
+ }
+
+ return '\\OAuth\\' . $type . '\\Service\\' . $serviceName;
+ }
+
+ /**
+ * Builds v2 services
+ *
+ * @param string $serviceName The fully qualified service name
+ * @param CredentialsInterface $credentials
+ * @param TokenStorageInterface $storage
+ * @param array|null $scopes Array of scopes for the service
+ * @param UriInterface|null $baseApiUri
+ *
+ * @return ServiceInterface
+ *
+ * @throws Exception
+ */
+ private function buildV2Service(
+ $serviceName,
+ CredentialsInterface $credentials,
+ TokenStorageInterface $storage,
+ array $scopes,
+ UriInterface $baseApiUri = null
+ ) {
+ return new $serviceName(
+ $credentials,
+ $this->httpClient,
+ $storage,
+ $this->resolveScopes($serviceName, $scopes),
+ $baseApiUri
+ );
+ }
+
+ /**
+ * Resolves scopes for v2 services
+ *
+ * @param string $serviceName The fully qualified service name
+ * @param array $scopes List of scopes for the service
+ *
+ * @return array List of resolved scopes
+ */
+ private function resolveScopes($serviceName, array $scopes)
+ {
+ $reflClass = new \ReflectionClass($serviceName);
+ $constants = $reflClass->getConstants();
+
+ $resolvedScopes = array();
+ foreach ($scopes as $scope) {
+ $key = strtoupper('SCOPE_' . $scope);
+
+ if (array_key_exists($key, $constants)) {
+ $resolvedScopes[] = $constants[$key];
+ } else {
+ $resolvedScopes[] = $scope;
+ }
+ }
+
+ return $resolvedScopes;
+ }
+
+ /**
+ * Builds v1 services
+ *
+ * @param string $serviceName The fully qualified service name
+ * @param CredentialsInterface $credentials
+ * @param TokenStorageInterface $storage
+ * @param array $scopes
+ * @param UriInterface $baseApiUri
+ *
+ * @return ServiceInterface
+ *
+ * @throws Exception
+ */
+ private function buildV1Service(
+ $serviceName,
+ CredentialsInterface $credentials,
+ TokenStorageInterface $storage,
+ $scopes,
+ UriInterface $baseApiUri = null
+ ) {
+ if (!empty($scopes)) {
+ throw new Exception(
+ 'Scopes passed to ServiceFactory::createService but an OAuth1 service was requested.'
+ );
+ }
+
+ return new $serviceName($credentials, $this->httpClient, $storage, new Signature($credentials), $baseApiUri);
+ }
+}
diff --git a/sources/vendor/OAuth/bootstrap.php b/sources/vendor/OAuth/bootstrap.php
new file mode 100644
index 0000000..548678a
--- /dev/null
+++ b/sources/vendor/OAuth/bootstrap.php
@@ -0,0 +1,13 @@
+register();
diff --git a/sources/vendor/PicoDb/Database.php b/sources/vendor/PicoDb/Database.php
new file mode 100644
index 0000000..4d7b703
--- /dev/null
+++ b/sources/vendor/PicoDb/Database.php
@@ -0,0 +1,144 @@
+pdo = new Sqlite($settings);
+ break;
+
+ case 'mysql':
+ require_once __DIR__.'/Drivers/Mysql.php';
+ $this->pdo = new Mysql($settings);
+ break;
+
+ case 'postgres':
+ require_once __DIR__.'/Drivers/Postgres.php';
+ $this->pdo = new Postgres($settings);
+ break;
+
+ default:
+ throw new \LogicException('This database driver is not supported.');
+ }
+
+ $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
+ }
+
+
+ public static function bootstrap($name, \Closure $callback)
+ {
+ self::$instances[$name] = $callback;
+ }
+
+
+ public static function get($name)
+ {
+ if (! isset(self::$instances[$name])) {
+ throw new \LogicException('No database instance created with that name.');
+ }
+
+ if (is_callable(self::$instances[$name])) {
+ self::$instances[$name] = call_user_func(self::$instances[$name]);
+ }
+
+ return self::$instances[$name];
+ }
+
+
+ public function setLogMessage($message)
+ {
+ $this->logs[] = $message;
+ }
+
+
+ public function getLogMessages()
+ {
+ return $this->logs;
+ }
+
+
+ public function getConnection()
+ {
+ return $this->pdo;
+ }
+
+
+ public function escapeIdentifier($value)
+ {
+ return $this->pdo->escapeIdentifier($value);
+ }
+
+
+ public function execute($sql, array $values = array())
+ {
+ try {
+
+ $this->setLogMessage($sql);
+ $this->setLogMessage(implode(', ', $values));
+
+ $rq = $this->pdo->prepare($sql);
+ $rq->execute($values);
+
+ return $rq;
+ }
+ catch (\PDOException $e) {
+
+ if ($this->pdo->inTransaction()) $this->pdo->rollback();
+ $this->setLogMessage($e->getMessage());
+ return false;
+ }
+ }
+
+
+ public function startTransaction()
+ {
+ if (! $this->pdo->inTransaction()) {
+ $this->pdo->beginTransaction();
+ }
+ }
+
+
+ public function closeTransaction()
+ {
+ if ($this->pdo->inTransaction()) {
+ $this->pdo->commit();
+ }
+ }
+
+
+ public function cancelTransaction()
+ {
+ if ($this->pdo->inTransaction()) {
+ $this->pdo->rollback();
+ }
+ }
+
+
+ public function table($table_name)
+ {
+ require_once __DIR__.'/Table.php';
+ return new Table($this, $table_name);
+ }
+
+
+ public function schema()
+ {
+ require_once __DIR__.'/Schema.php';
+ return new Schema($this);
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/PicoDb/Drivers/Mysql.php b/sources/vendor/PicoDb/Drivers/Mysql.php
new file mode 100644
index 0000000..22277a0
--- /dev/null
+++ b/sources/vendor/PicoDb/Drivers/Mysql.php
@@ -0,0 +1,76 @@
+ 'SET NAMES '.$settings['charset']
+ );
+
+ parent::__construct($dsn, $settings['username'], $settings['password'], $options);
+
+ if (isset($settings['schema_table'])) {
+ $this->schema_table = $settings['schema_table'];
+ }
+ }
+
+
+ public function getSchemaVersion()
+ {
+ $this->exec("CREATE TABLE IF NOT EXISTS `".$this->schema_table."` (`version` INT DEFAULT '0')");
+
+ $rq = $this->prepare('SELECT `version` FROM `'.$this->schema_table.'`');
+ $rq->execute();
+ $result = $rq->fetch(\PDO::FETCH_ASSOC);
+
+ if (isset($result['version'])) {
+ return (int) $result['version'];
+ }
+ else {
+ $this->exec('INSERT INTO `'.$this->schema_table.'` VALUES(0)');
+ }
+
+ return 0;
+ }
+
+
+ public function setSchemaVersion($version)
+ {
+ $rq = $this->prepare('UPDATE `'.$this->schema_table.'` SET `version`=?');
+ $rq->execute(array($version));
+ }
+
+
+ public function getLastId()
+ {
+ return $this->lastInsertId();
+ }
+
+
+ public function escapeIdentifier($value)
+ {
+ if (strpos($value, '.') !== false) return $value;
+ return '`'.$value.'`';
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/PicoDb/Drivers/Postgres.php b/sources/vendor/PicoDb/Drivers/Postgres.php
new file mode 100644
index 0000000..641727f
--- /dev/null
+++ b/sources/vendor/PicoDb/Drivers/Postgres.php
@@ -0,0 +1,73 @@
+schema_table = $settings['schema_table'];
+ }
+ }
+
+
+ public function getSchemaVersion()
+ {
+ $this->exec("CREATE TABLE IF NOT EXISTS ".$this->schema_table." (version SMALLINT DEFAULT 0)");
+
+ $rq = $this->prepare('SELECT version FROM '.$this->schema_table.'');
+ $rq->execute();
+ $result = $rq->fetch(\PDO::FETCH_ASSOC);
+
+ if (isset($result['version'])) {
+ return (int) $result['version'];
+ }
+ else {
+ $this->exec('INSERT INTO '.$this->schema_table.' VALUES(0)');
+ }
+
+ return 0;
+ }
+
+
+ public function setSchemaVersion($version)
+ {
+ $rq = $this->prepare('UPDATE '.$this->schema_table.' SET version=?');
+ $rq->execute(array($version));
+ }
+
+
+ public function getLastId()
+ {
+ $rq = $this->prepare('SELECT LASTVAL()');
+ $rq->execute();
+ return $rq->fetchColumn();
+ }
+
+
+ public function escapeIdentifier($value)
+ {
+ return $value;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/PicoDb/Drivers/Sqlite.php b/sources/vendor/PicoDb/Drivers/Sqlite.php
new file mode 100644
index 0000000..83b61c4
--- /dev/null
+++ b/sources/vendor/PicoDb/Drivers/Sqlite.php
@@ -0,0 +1,57 @@
+exec('PRAGMA foreign_keys = ON');
+ }
+
+
+ public function getSchemaVersion()
+ {
+ $rq = $this->prepare('PRAGMA user_version');
+ $rq->execute();
+ $result = $rq->fetch(\PDO::FETCH_ASSOC);
+
+ if (isset($result['user_version'])) {
+ return (int) $result['user_version'];
+ }
+
+ return 0;
+ }
+
+
+ public function setSchemaVersion($version)
+ {
+ $this->exec('PRAGMA user_version='.$version);
+ }
+
+
+ public function getLastId()
+ {
+ return $this->lastInsertId();
+ }
+
+
+ public function escapeIdentifier($value)
+ {
+ if (strpos($value, '.') !== false) return $value;
+ return '"'.$value.'"';
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/PicoDb/Schema.php b/sources/vendor/PicoDb/Schema.php
new file mode 100644
index 0000000..b75366e
--- /dev/null
+++ b/sources/vendor/PicoDb/Schema.php
@@ -0,0 +1,59 @@
+db = $db;
+ }
+
+
+ public function check($last_version = 1)
+ {
+ $current_version = $this->db->getConnection()->getSchemaVersion();
+
+ if ($current_version < $last_version) {
+ return $this->migrateTo($current_version, $last_version);
+ }
+
+ return true;
+ }
+
+
+ public function migrateTo($current_version, $next_version)
+ {
+ try {
+
+ $this->db->startTransaction();
+
+ for ($i = $current_version + 1; $i <= $next_version; $i++) {
+
+ $function_name = '\Schema\version_'.$i;
+
+ if (function_exists($function_name)) {
+
+ call_user_func($function_name, $this->db->getConnection());
+ $this->db->getConnection()->setSchemaVersion($i);
+ }
+ else {
+
+ throw new \LogicException('To execute a database migration, you need to create this function: "'.$function_name.'".');
+ }
+ }
+
+ $this->db->closeTransaction();
+ }
+ catch (\PDOException $e) {
+
+ $this->db->cancelTransaction();
+ return false;
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/PicoDb/Table.php b/sources/vendor/PicoDb/Table.php
new file mode 100644
index 0000000..8a0ce64
--- /dev/null
+++ b/sources/vendor/PicoDb/Table.php
@@ -0,0 +1,432 @@
+db = $db;
+ $this->table_name = $table_name;
+
+ return $this;
+ }
+
+
+ public function save(array $data)
+ {
+ if (! empty($this->conditions)) {
+
+ return $this->update($data);
+ }
+ else {
+
+ return $this->insert($data);
+ }
+ }
+
+
+ public function update(array $data)
+ {
+ $columns = array();
+ $values = array();
+
+ foreach ($data as $column => $value) {
+
+ $columns[] = $this->db->escapeIdentifier($column).'=?';
+ $values[] = $value;
+ }
+
+ foreach ($this->values as $value) {
+
+ $values[] = $value;
+ }
+
+ $sql = sprintf(
+ 'UPDATE %s SET %s %s',
+ $this->db->escapeIdentifier($this->table_name),
+ implode(', ', $columns),
+ $this->conditions()
+ );
+
+ $result = $this->db->execute($sql, $values);
+
+ if ($result !== false/* && $result->rowCount() > 0*/) {
+ return true;
+ }
+
+ return false;
+ }
+
+
+ public function insert(array $data)
+ {
+ $columns = array();
+
+ foreach ($data as $column => $value) {
+
+ $columns[] = $this->db->escapeIdentifier($column);
+ }
+
+ $sql = sprintf(
+ 'INSERT INTO %s (%s) VALUES (%s)',
+ $this->db->escapeIdentifier($this->table_name),
+ implode(', ', $columns),
+ implode(', ', array_fill(0, count($data), '?'))
+ );
+
+ return false !== $this->db->execute($sql, array_values($data));
+ }
+
+
+ public function remove()
+ {
+ $sql = sprintf(
+ 'DELETE FROM %s %s',
+ $this->db->escapeIdentifier($this->table_name),
+ $this->conditions()
+ );
+
+ return false !== $this->db->execute($sql, $this->values);
+ }
+
+
+ public function listing($key, $value)
+ {
+ $this->columns($key, $value);
+
+ $listing = array();
+ $results = $this->findAll();
+
+ if ($results) {
+
+ foreach ($results as $result) {
+
+ $listing[$result[$key]] = $result[$value];
+ }
+ }
+
+ return $listing;
+ }
+
+
+ public function findAll()
+ {
+ $rq = $this->db->execute($this->buildSelectQuery(), $this->values);
+ if (false === $rq) return false;
+
+ return $rq->fetchAll(\PDO::FETCH_ASSOC);
+ }
+
+
+ public function findAllByColumn($column)
+ {
+ $this->columns = array($column);
+ $rq = $this->db->execute($this->buildSelectQuery(), $this->values);
+ if (false === $rq) return false;
+
+ return $rq->fetchAll(\PDO::FETCH_COLUMN, 0);
+ }
+
+
+ public function findOne()
+ {
+ $this->limit(1);
+ $result = $this->findAll();
+
+ return isset($result[0]) ? $result[0] : null;
+ }
+
+
+ public function findOneColumn($column)
+ {
+ $this->limit(1);
+ $this->columns = array($column);
+
+ $rq = $this->db->execute($this->buildSelectQuery(), $this->values);
+ if (false === $rq) return false;
+
+ return $rq->fetchColumn();
+ }
+
+
+ public function buildSelectQuery()
+ {
+ return sprintf(
+ 'SELECT %s %s FROM %s %s %s %s %s %s %s',
+ $this->distinct ? 'DISTINCT' : '',
+ empty($this->columns) ? '*' : implode(', ', $this->columns),
+ $this->db->escapeIdentifier($this->table_name),
+ implode(' ', $this->joins),
+ $this->conditions(),
+ empty($this->group_by) ? '' : 'GROUP BY '.implode(', ', $this->group_by),
+ $this->sql_order,
+ $this->sql_limit,
+ $this->sql_offset
+ );
+ }
+
+
+ public function count()
+ {
+ $sql = sprintf(
+ 'SELECT COUNT(*) FROM %s'.$this->conditions().$this->sql_order.$this->sql_limit.$this->sql_offset,
+ $this->db->escapeIdentifier($this->table_name)
+ );
+
+ $rq = $this->db->execute($sql, $this->values);
+ if (false === $rq) return false;
+
+ $result = $rq->fetchColumn();
+ return $result ? (int) $result : 0;
+ }
+
+
+ public function join($table, $foreign_column, $local_column)
+ {
+ $this->joins[] = sprintf(
+ 'LEFT JOIN %s ON %s=%s',
+ $this->db->escapeIdentifier($table),
+ $this->db->escapeIdentifier($table).'.'.$this->db->escapeIdentifier($foreign_column),
+ $this->db->escapeIdentifier($this->table_name).'.'.$this->db->escapeIdentifier($local_column)
+ );
+
+ return $this;
+ }
+
+
+ public function conditions()
+ {
+ if (! empty($this->conditions)) {
+
+ return ' WHERE '.implode(' AND ', $this->conditions);
+ }
+ else {
+
+ return '';
+ }
+ }
+
+
+ public function addCondition($sql)
+ {
+ if ($this->is_or_condition) {
+
+ $this->or_conditions[] = $sql;
+ }
+ else {
+
+ $this->conditions[] = $sql;
+ }
+ }
+
+
+ public function beginOr()
+ {
+ $this->is_or_condition = true;
+ $this->or_conditions = array();
+
+ return $this;
+ }
+
+
+ public function closeOr()
+ {
+ $this->is_or_condition = false;
+
+ if (! empty($this->or_conditions)) {
+
+ $this->conditions[] = '('.implode(' OR ', $this->or_conditions).')';
+ }
+
+ return $this;
+ }
+
+
+ public function orderBy($column, $order = self::SORT_ASC)
+ {
+ $order = strtoupper($order);
+ $order = $order === self::SORT_ASC || $order === self::SORT_DESC ? $order : self::SORT_ASC;
+
+ if ($this->sql_order === '') {
+ $this->sql_order = ' ORDER BY '.$this->db->escapeIdentifier($column).' '.$order;
+ }
+ else {
+ $this->sql_order .= ', '.$this->db->escapeIdentifier($column).' '.$order;
+ }
+
+ return $this;
+ }
+
+
+ public function asc($column)
+ {
+ if ($this->sql_order === '') {
+ $this->sql_order = ' ORDER BY '.$this->db->escapeIdentifier($column).' '.self::SORT_ASC;
+ }
+ else {
+ $this->sql_order .= ', '.$this->db->escapeIdentifier($column).' '.self::SORT_ASC;
+ }
+
+ return $this;
+ }
+
+
+ public function desc($column)
+ {
+ if ($this->sql_order === '') {
+ $this->sql_order = ' ORDER BY '.$this->db->escapeIdentifier($column).' '.self::SORT_DESC;
+ }
+ else {
+ $this->sql_order .= ', '.$this->db->escapeIdentifier($column).' '.self::SORT_DESC;
+ }
+
+ return $this;
+ }
+
+
+ public function limit($value)
+ {
+ if (! is_null($value)) $this->sql_limit = ' LIMIT '.(int) $value;
+ return $this;
+ }
+
+
+ public function offset($value)
+ {
+ if (! is_null($value)) $this->sql_offset = ' OFFSET '.(int) $value;
+ return $this;
+ }
+
+
+ public function groupBy()
+ {
+ $this->group_by = \func_get_args();
+ return $this;
+ }
+
+
+ public function columns()
+ {
+ $this->columns = \func_get_args();
+ return $this;
+ }
+
+
+ public function distinct()
+ {
+ $this->columns = \func_get_args();
+ $this->distinct = true;
+ return $this;
+ }
+
+
+ public function __call($name, array $arguments)
+ {
+ $column = $arguments[0];
+ $sql = '';
+
+ switch (strtolower($name)) {
+
+ case 'in':
+ if (isset($arguments[1]) && is_array($arguments[1])) {
+
+ $sql = sprintf(
+ '%s IN (%s)',
+ $this->db->escapeIdentifier($column),
+ implode(', ', array_fill(0, count($arguments[1]), '?'))
+ );
+ }
+ break;
+
+ case 'notin':
+ if (isset($arguments[1]) && is_array($arguments[1])) {
+
+ $sql = sprintf(
+ '%s NOT IN (%s)',
+ $this->db->escapeIdentifier($column),
+ implode(', ', array_fill(0, count($arguments[1]), '?'))
+ );
+ }
+ break;
+
+ case 'like':
+ $sql = sprintf('%s LIKE ?', $this->db->escapeIdentifier($column));
+ break;
+
+ case 'eq':
+ case 'equal':
+ case 'equals':
+ $sql = sprintf('%s = ?', $this->db->escapeIdentifier($column));
+ break;
+
+ case 'gt':
+ case 'greaterthan':
+ $sql = sprintf('%s > ?', $this->db->escapeIdentifier($column));
+ break;
+
+ case 'lt':
+ case 'lowerthan':
+ $sql = sprintf('%s < ?', $this->db->escapeIdentifier($column));
+ break;
+
+ case 'gte':
+ case 'greaterthanorequals':
+ $sql = sprintf('%s >= ?', $this->db->escapeIdentifier($column));
+ break;
+
+ case 'lte':
+ case 'lowerthanorequals':
+ $sql = sprintf('%s <= ?', $this->db->escapeIdentifier($column));
+ break;
+
+ case 'isnull':
+ $sql = sprintf('%s IS NULL', $this->db->escapeIdentifier($column));
+ break;
+
+ case 'notnull':
+ $sql = sprintf('%s IS NOT NULL', $this->db->escapeIdentifier($column));
+ break;
+ }
+
+ if ($sql !== '') {
+
+ $this->addCondition($sql);
+
+ if (isset($arguments[1])) {
+
+ if (is_array($arguments[1])) {
+
+ foreach ($arguments[1] as $value) {
+ $this->values[] = $value;
+ }
+ }
+ else {
+
+ $this->values[] = $arguments[1];
+ }
+ }
+ }
+
+ return $this;
+ }
+}
diff --git a/sources/vendor/SimpleValidator/Base.php b/sources/vendor/SimpleValidator/Base.php
new file mode 100644
index 0000000..45c01a6
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Base.php
@@ -0,0 +1,44 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator;
+
+/**
+ * @author Frédéric Guillot
+ */
+abstract class Base
+{
+ protected $field = '';
+ protected $error_message = '';
+ protected $data = array();
+
+
+ abstract public function execute(array $data);
+
+
+ public function __construct($field, $error_message)
+ {
+ $this->field = $field;
+ $this->error_message = $error_message;
+ }
+
+
+ public function getErrorMessage()
+ {
+ return $this->error_message;
+ }
+
+
+ public function getField()
+ {
+ return $this->field;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validator.php b/sources/vendor/SimpleValidator/Validator.php
new file mode 100644
index 0000000..8bb4d62
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validator.php
@@ -0,0 +1,67 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator;
+
+/**
+ * @author Frédéric Guillot
+ */
+class Validator
+{
+ private $data = array();
+ private $errors = array();
+ private $validators = array();
+
+
+ public function __construct(array $data, array $validators)
+ {
+ $this->data = $data;
+ $this->validators = $validators;
+ }
+
+
+ public function execute()
+ {
+ $result = true;
+
+ foreach ($this->validators as $validator) {
+
+ if (! $validator->execute($this->data)) {
+
+ $this->addError(
+ $validator->getField(),
+ $validator->getErrorMessage()
+ );
+
+ $result = false;
+ }
+ }
+
+ return $result;
+ }
+
+
+ public function addError($field, $message)
+ {
+ if (! isset($this->errors[$field])) {
+
+ $this->errors[$field] = array();
+ }
+
+ $this->errors[$field][] = $message;
+ }
+
+
+ public function getErrors()
+ {
+ return $this->errors;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/Alpha.php b/sources/vendor/SimpleValidator/Validators/Alpha.php
new file mode 100644
index 0000000..b00b819
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/Alpha.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class Alpha extends Base
+{
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ if (! ctype_alpha($data[$this->field])) {
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/AlphaNumeric.php b/sources/vendor/SimpleValidator/Validators/AlphaNumeric.php
new file mode 100644
index 0000000..e1762d6
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/AlphaNumeric.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class AlphaNumeric extends Base
+{
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ if (! ctype_alnum($data[$this->field])) {
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/Date.php b/sources/vendor/SimpleValidator/Validators/Date.php
new file mode 100644
index 0000000..54c949b
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/Date.php
@@ -0,0 +1,48 @@
+formats = $formats;
+ }
+
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ foreach ($this->formats as $format) {
+ if ($this->isValidDate($data[$this->field], $format) === true) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ return true;
+ }
+
+ public function isValidDate($value, $format)
+ {
+ $date = DateTime::createFromFormat($format, $value);
+
+ if ($date !== false) {
+ $errors = DateTime::getLastErrors();
+ if ($errors['error_count'] === 0 && $errors['warning_count'] === 0) {
+ $timestamp = $date->getTimestamp();
+ return $timestamp > 0 ? true : false;
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/sources/vendor/SimpleValidator/Validators/Email.php b/sources/vendor/SimpleValidator/Validators/Email.php
new file mode 100644
index 0000000..e4e3d5d
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/Email.php
@@ -0,0 +1,81 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class Email extends Base
+{
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ // I use the same validation method as Firefox
+ // http://hg.mozilla.org/mozilla-central/file/cf5da681d577/content/html/content/src/nsHTMLInputElement.cpp#l3967
+
+ $value = $data[$this->field];
+ $length = strlen($value);
+
+ // If the email address begins with a '@' or ends with a '.',
+ // we know it's invalid.
+ if ($value[0] === '@' || $value[$length - 1] === '.') {
+
+ return false;
+ }
+
+ // Check the username
+ for ($i = 0; $i < $length && $value[$i] !== '@'; ++$i) {
+
+ $c = $value[$i];
+
+ if (! (ctype_alnum($c) || $c === '.' || $c === '!' || $c === '#' || $c === '$' ||
+ $c === '%' || $c === '&' || $c === '\'' || $c === '*' || $c === '+' ||
+ $c === '-' || $c === '/' || $c === '=' || $c === '?' || $c === '^' ||
+ $c === '_' || $c === '`' || $c === '{' || $c === '|' || $c === '}' ||
+ $c === '~')) {
+
+ return false;
+ }
+ }
+
+ // There is no domain name (or it's one-character long),
+ // that's not a valid email address.
+ if (++$i >= $length) return false;
+ if (($i + 1) === $length) return false;
+
+ // The domain name can't begin with a dot.
+ if ($value[$i] === '.') return false;
+
+ // Parsing the domain name.
+ for (; $i < $length; ++$i) {
+
+ $c = $value[$i];
+
+ if ($c === '.') {
+
+ // A dot can't follow a dot.
+ if ($value[$i - 1] === '.') return false;
+ }
+ elseif (! (ctype_alnum($c) || $c === '-')) {
+
+ // The domain characters have to be in this list to be valid.
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/Equals.php b/sources/vendor/SimpleValidator/Validators/Equals.php
new file mode 100644
index 0000000..91f34e4
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/Equals.php
@@ -0,0 +1,43 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class Equals extends Base
+{
+ private $field2;
+
+
+ public function __construct($field1, $field2, $error_message)
+ {
+ parent::__construct($field1, $error_message);
+
+ $this->field2 = $field2;
+ }
+
+
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ if (! isset($data[$this->field2])) return false;
+
+ return $data[$this->field] === $data[$this->field2];
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/GreaterThan.php b/sources/vendor/SimpleValidator/Validators/GreaterThan.php
new file mode 100644
index 0000000..e038cb6
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/GreaterThan.php
@@ -0,0 +1,36 @@
+min = $min;
+ }
+
+
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+ return $data[$this->field] > $this->min;
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/Integer.php b/sources/vendor/SimpleValidator/Validators/Integer.php
new file mode 100644
index 0000000..150558a
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/Integer.php
@@ -0,0 +1,42 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class Integer extends Base
+{
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ if (is_string($data[$this->field])) {
+
+ if ($data[$this->field][0] === '-') {
+
+ return ctype_digit(substr($data[$this->field], 1));
+ }
+
+ return ctype_digit($data[$this->field]);
+ }
+ else {
+
+ return is_int($data[$this->field]);
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/Ip.php b/sources/vendor/SimpleValidator/Validators/Ip.php
new file mode 100644
index 0000000..48afe56
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/Ip.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class Ip extends Base
+{
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ if (! filter_var($data[$this->field], FILTER_VALIDATE_IP)) {
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/Length.php b/sources/vendor/SimpleValidator/Validators/Length.php
new file mode 100644
index 0000000..36e50b3
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/Length.php
@@ -0,0 +1,48 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class Length extends Base
+{
+ private $min;
+ private $max;
+
+
+ public function __construct($field, $error_message, $min, $max)
+ {
+ parent::__construct($field, $error_message);
+
+ $this->min = $min;
+ $this->max = $max;
+ }
+
+
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ $length = mb_strlen($data[$this->field], 'UTF-8');
+
+ if ($length < $this->min || $length > $this->max) {
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/MacAddress.php b/sources/vendor/SimpleValidator/Validators/MacAddress.php
new file mode 100644
index 0000000..d934841
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/MacAddress.php
@@ -0,0 +1,37 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class MacAddress extends Base
+{
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ $groups = explode(':', $data[$this->field]);
+
+ if (count($groups) !== 6) return false;
+
+ foreach ($groups as $group) {
+
+ if (! ctype_xdigit($group)) return false;
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/MaxLength.php b/sources/vendor/SimpleValidator/Validators/MaxLength.php
new file mode 100644
index 0000000..d8e032b
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/MaxLength.php
@@ -0,0 +1,46 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class MaxLength extends Base
+{
+ private $max;
+
+
+ public function __construct($field, $error_message, $max)
+ {
+ parent::__construct($field, $error_message);
+
+ $this->max = $max;
+ }
+
+
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ $length = mb_strlen($data[$this->field], 'UTF-8');
+
+ if ($length > $this->max) {
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/MinLength.php b/sources/vendor/SimpleValidator/Validators/MinLength.php
new file mode 100644
index 0000000..4b7f7d2
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/MinLength.php
@@ -0,0 +1,46 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class MinLength extends Base
+{
+ private $min;
+
+
+ public function __construct($field, $error_message, $min)
+ {
+ parent::__construct($field, $error_message);
+
+ $this->min = $min;
+ }
+
+
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ $length = mb_strlen($data[$this->field], 'UTF-8');
+
+ if ($length < $this->min) {
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/Numeric.php b/sources/vendor/SimpleValidator/Validators/Numeric.php
new file mode 100644
index 0000000..a958df1
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/Numeric.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class Numeric extends Base
+{
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ if (! is_numeric($data[$this->field])) {
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/Range.php b/sources/vendor/SimpleValidator/Validators/Range.php
new file mode 100644
index 0000000..1d71b92
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/Range.php
@@ -0,0 +1,51 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class Range extends Base
+{
+ private $min;
+ private $max;
+
+
+ public function __construct($field, $error_message, $min, $max)
+ {
+ parent::__construct($field, $error_message);
+
+ $this->min = $min;
+ $this->max = $max;
+ }
+
+
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ if (! is_numeric($data[$this->field])) {
+
+ return false;
+ }
+
+ if ($data[$this->field] < $this->min || $data[$this->field] > $this->max) {
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/Required.php b/sources/vendor/SimpleValidator/Validators/Required.php
new file mode 100644
index 0000000..e7ef271
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/Required.php
@@ -0,0 +1,30 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class Required extends Base
+{
+ public function execute(array $data)
+ {
+ if (! isset($data[$this->field]) || $data[$this->field] === '') {
+
+ return false;
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/Unique.php b/sources/vendor/SimpleValidator/Validators/Unique.php
new file mode 100644
index 0000000..c20dbe1
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/Unique.php
@@ -0,0 +1,78 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ */
+class Unique extends Base
+{
+ private $pdo;
+ private $primary_key;
+ private $table;
+
+
+ public function __construct($field, $error_message, \PDO $pdo, $table, $primary_key = 'id')
+ {
+ parent::__construct($field, $error_message);
+
+ $this->pdo = $pdo;
+ $this->primary_key = $primary_key;
+ $this->table = $table;
+ }
+
+
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ if (! isset($data[$this->primary_key])) {
+
+ $rq = $this->pdo->prepare('SELECT COUNT(*) FROM '.$this->table.' WHERE '.$this->field.'=?');
+
+ $rq->execute(array(
+ $data[$this->field]
+ ));
+
+ $result = $rq->fetch(\PDO::FETCH_NUM);
+
+ if (isset($result[0]) && $result[0] === '1') {
+
+ return false;
+ }
+ }
+ else {
+
+ $rq = $this->pdo->prepare(
+ 'SELECT COUNT(*) FROM '.$this->table.'
+ WHERE '.$this->field.'=? AND '.$this->primary_key.' != ?'
+ );
+
+ $rq->execute(array(
+ $data[$this->field],
+ $data[$this->primary_key]
+ ));
+
+ $result = $rq->fetch(\PDO::FETCH_NUM);
+
+ if (isset($result[0]) && $result[0] === '1') {
+
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/SimpleValidator/Validators/Version.php b/sources/vendor/SimpleValidator/Validators/Version.php
new file mode 100644
index 0000000..273a28a
--- /dev/null
+++ b/sources/vendor/SimpleValidator/Validators/Version.php
@@ -0,0 +1,32 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+/**
+ * @author Frédéric Guillot
+ * @link http://semver.org/
+ */
+class Version extends Base
+{
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ $pattern = '/^[0-9]+\.[0-9]+\.[0-9]+([+-][^+-][0-9A-Za-z-.]*)?$/';
+ return (bool) preg_match($pattern, $data[$this->field]);
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sources/vendor/password.php b/sources/vendor/password.php
new file mode 100644
index 0000000..c6e84cb
--- /dev/null
+++ b/sources/vendor/password.php
@@ -0,0 +1,227 @@
+
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
+ * @copyright 2012 The Authors
+ */
+
+if (!defined('PASSWORD_BCRYPT')) {
+
+ define('PASSWORD_BCRYPT', 1);
+ define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);
+
+ if (version_compare(PHP_VERSION, '5.3.7', '<')) {
+
+ define('PASSWORD_PREFIX', '$2a$');
+ }
+ else {
+
+ define('PASSWORD_PREFIX', '$2y$');
+ }
+
+ /**
+ * Hash the password using the specified algorithm
+ *
+ * @param string $password The password to hash
+ * @param int $algo The algorithm to use (Defined by PASSWORD_* constants)
+ * @param array $options The options for the algorithm to use
+ *
+ * @return string|false The hashed password, or false on error.
+ */
+ function password_hash($password, $algo, array $options = array()) {
+ if (!function_exists('crypt')) {
+ trigger_error("Crypt must be loaded for password_hash to function", E_USER_WARNING);
+ return null;
+ }
+ if (!is_string($password)) {
+ trigger_error("password_hash(): Password must be a string", E_USER_WARNING);
+ return null;
+ }
+ if (!is_int($algo)) {
+ trigger_error("password_hash() expects parameter 2 to be long, " . gettype($algo) . " given", E_USER_WARNING);
+ return null;
+ }
+ switch ($algo) {
+ case PASSWORD_BCRYPT:
+ // Note that this is a C constant, but not exposed to PHP, so we don't define it here.
+ $cost = 10;
+ if (isset($options['cost'])) {
+ $cost = $options['cost'];
+ if ($cost < 4 || $cost > 31) {
+ trigger_error(sprintf("password_hash(): Invalid bcrypt cost parameter specified: %d", $cost), E_USER_WARNING);
+ return null;
+ }
+ }
+ $required_salt_len = 22;
+ $hash_format = sprintf("%s%02d$", PASSWORD_PREFIX, $cost);
+ break;
+ default:
+ trigger_error(sprintf("password_hash(): Unknown password hashing algorithm: %s", $algo), E_USER_WARNING);
+ return null;
+ }
+ if (isset($options['salt'])) {
+ switch (gettype($options['salt'])) {
+ case 'NULL':
+ case 'boolean':
+ case 'integer':
+ case 'double':
+ case 'string':
+ $salt = (string) $options['salt'];
+ break;
+ case 'object':
+ if (method_exists($options['salt'], '__tostring')) {
+ $salt = (string) $options['salt'];
+ break;
+ }
+ case 'array':
+ case 'resource':
+ default:
+ trigger_error('password_hash(): Non-string salt parameter supplied', E_USER_WARNING);
+ return null;
+ }
+ if (strlen($salt) < $required_salt_len) {
+ trigger_error(sprintf("password_hash(): Provided salt is too short: %d expecting %d", strlen($salt), $required_salt_len), E_USER_WARNING);
+ return null;
+ } elseif (0 == preg_match('#^[a-zA-Z0-9./]+$#D', $salt)) {
+ $salt = str_replace('+', '.', base64_encode($salt));
+ }
+ } else {
+ $buffer = '';
+ $raw_length = (int) ($required_salt_len * 3 / 4 + 1);
+ $buffer_valid = false;
+ if (function_exists('mcrypt_create_iv') && !defined('PHALANGER')) {
+ $buffer = mcrypt_create_iv($raw_length, MCRYPT_DEV_URANDOM);
+ if ($buffer) {
+ $buffer_valid = true;
+ }
+ }
+ if (!$buffer_valid && function_exists('openssl_random_pseudo_bytes')) {
+ $buffer = openssl_random_pseudo_bytes($raw_length);
+ if ($buffer) {
+ $buffer_valid = true;
+ }
+ }
+ if (!$buffer_valid && is_readable('/dev/urandom')) {
+ $f = fopen('/dev/urandom', 'r');
+ $read = strlen($buffer);
+ while ($read < $raw_length) {
+ $buffer .= fread($f, $raw_length - $read);
+ $read = strlen($buffer);
+ }
+ fclose($f);
+ if ($read >= $raw_length) {
+ $buffer_valid = true;
+ }
+ }
+ if (!$buffer_valid || strlen($buffer) < $raw_length) {
+ $bl = strlen($buffer);
+ for ($i = 0; $i < $raw_length; $i++) {
+ if ($i < $bl) {
+ $buffer[$i] = $buffer[$i] ^ chr(mt_rand(0, 255));
+ } else {
+ $buffer .= chr(mt_rand(0, 255));
+ }
+ }
+ }
+ $salt = str_replace('+', '.', base64_encode($buffer));
+
+ }
+ $salt = substr($salt, 0, $required_salt_len);
+
+ $hash = $hash_format . $salt;
+
+ $ret = crypt($password, $hash);
+
+ if (!is_string($ret) || strlen($ret) <= 13) {
+ return false;
+ }
+
+ return $ret;
+ }
+
+ /**
+ * Get information about the password hash. Returns an array of the information
+ * that was used to generate the password hash.
+ *
+ * array(
+ * 'algo' => 1,
+ * 'algoName' => 'bcrypt',
+ * 'options' => array(
+ * 'cost' => 10,
+ * ),
+ * )
+ *
+ * @param string $hash The password hash to extract info from
+ *
+ * @return array The array of information about the hash.
+ */
+ function password_get_info($hash) {
+ $return = array(
+ 'algo' => 0,
+ 'algoName' => 'unknown',
+ 'options' => array(),
+ );
+ if (substr($hash, 0, 4) == PASSWORD_PREFIX && strlen($hash) == 60) {
+ $return['algo'] = PASSWORD_BCRYPT;
+ $return['algoName'] = 'bcrypt';
+ list($cost) = sscanf($hash, PASSWORD_PREFIX."%d$");
+ $return['options']['cost'] = $cost;
+ }
+ return $return;
+ }
+
+ /**
+ * Determine if the password hash needs to be rehashed according to the options provided
+ *
+ * If the answer is true, after validating the password using password_verify, rehash it.
+ *
+ * @param string $hash The hash to test
+ * @param int $algo The algorithm used for new password hashes
+ * @param array $options The options array passed to password_hash
+ *
+ * @return boolean True if the password needs to be rehashed.
+ */
+ function password_needs_rehash($hash, $algo, array $options = array()) {
+ $info = password_get_info($hash);
+ if ($info['algo'] != $algo) {
+ return true;
+ }
+ switch ($algo) {
+ case PASSWORD_BCRYPT:
+ $cost = isset($options['cost']) ? $options['cost'] : 10;
+ if ($cost != $info['options']['cost']) {
+ return true;
+ }
+ break;
+ }
+ return false;
+ }
+
+ /**
+ * Verify a password against a hash using a timing attack resistant approach
+ *
+ * @param string $password The password to verify
+ * @param string $hash The hash to verify against
+ *
+ * @return boolean If the password matches the hash
+ */
+ function password_verify($password, $hash) {
+ if (!function_exists('crypt')) {
+ trigger_error("Crypt must be loaded for password_verify to function", E_USER_WARNING);
+ return false;
+ }
+ $ret = crypt($password, $hash);
+ if (!is_string($ret) || strlen($ret) != strlen($hash) || strlen($ret) <= 13) {
+ return false;
+ }
+
+ $status = 0;
+ for ($i = 0; $i < strlen($ret); $i++) {
+ $status |= (ord($ret[$i]) ^ ord($hash[$i]));
+ }
+
+ return $status === 0;
+ }
+}