code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function beforeSave(&$model) {
// Define the new tag model
$Tag =& new Tag;
if ($model->hasField($this->settings[$model->name]['table_label'])
&& $Tag->hasField($this->settings[$model->name]['tag_label'])) {
// Parse out all of the
$tag_list = $this->_parseTag($model->data[$model->name][$this->settings[$model->name]['table_label']], $this->settings[$model->name]);
$tag_info = array(); // New tag array to store tag id and names from db
foreach($tag_list as $t) {
if ($res = $Tag->find($this->settings[$model->name]['tag_label'] . " LIKE '" . $t . "'")) {
$tag_info[] = $res['Tag']['id'];
} else {
$Tag->save(array('id'=>'',$this->settings[$model->name]['tag_label']=>$t));
$tag_info[] = sprintf($Tag->getLastInsertID());
}
unset($res);
}
// This prepares the linking table data...
$model->data['Tag']['Tag'] = $tag_info;
// This formats the tags field before save...
$model->data[$model->name][$this->settings[$model->name]['table_label']] = implode(', ', $tag_list);
}
//return true;
}
|
Run before a model is saved, used to set up tag for model.
@param object $model Model about to be saved.
@access public
@since 1.0
|
beforeSave
|
php
|
Datawalke/Coordino
|
app/models/behaviors/tag.php
|
https://github.com/Datawalke/Coordino/blob/master/app/models/behaviors/tag.php
|
MIT
|
public function _getSpamFlags($content) {
$flags = 0;
// Get links in the content
$links = preg_match_all("#(^|[\n ])(?:(?:http|ftp|irc)s?:\/\/|www.)(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,4}(?:[-a-zA-Z0-9._\/&=+%?;\#]+)#is", $content, $matches);
$links = $matches[0];
$totalLinks = count($links);
$length = strlen($content);
// How many links are in the body
// +2 if less than 2, -1 per link if over 2
if ($totalLinks > 2) {
$flags = $flags + $totalLinks;
} else {
$flags = $flags - 1;
}
// Keyword search
// -1 per blacklisted keyword
$blacklistKeywords = array('levitra', 'viagra', 'casino', 'sex', 'loan', 'lol', 'nigs', 'nig', 'finance', 'slots', 'debt', 'free', 'nigger','nigga','jews', 'fucker',
'ass', 'bitch','fucker','fuck','penis','vagina','erection','die', 'http://', '.com');
foreach ($blacklistKeywords as $keyword) {
if (stripos($content, $keyword) !== false) {
$flags = $flags + 5;
}
}
// Random character match
// -1 point per 5 consecutive consonants
$consonants = preg_match_all('/[^aAeEiIoOuU\s]{5,}+/i', $content, $matches);
$totalConsonants = count($matches[0]);
if ($totalConsonants > 0) {
$flags = $flags + ($totalConsonants * 2);
}
return $flags;
}
|
Checks Spam in Tags
Returns a severity number.
@param string $content
@return $flags A severity count of how many times an item was flagged.
|
_getSpamFlags
|
php
|
Datawalke/Coordino
|
app/models/behaviors/tag.php
|
https://github.com/Datawalke/Coordino/blob/master/app/models/behaviors/tag.php
|
MIT
|
function _parseTag($string, $settings) {
$string = strtolower($string);
$string = preg_replace('/[^a-z0-9-' . $settings['separator'] . ' ]/i', '', $string);
$string = preg_replace('/' . $settings['separator'] . '[' . $settings['separator'] . ']*/', $settings['separator'], $string);
$string_array = preg_split('/' . $settings['separator'] . '/', $string);
$return_array = array();
foreach($string_array as $t) {
$tFlags = $this->_getSpamFlags($t);
$t = str_replace(' ', '-', $t);
$t = strtolower(trim($t));
if (strlen($t)>0 && $tFlags < 2) {
$return_array[] = $t;
}
}
return $return_array;
}
|
Parse the tag string and return a properly formatted array
@param string $string String.
@param array $settings Settings to use (looks for 'separator' and 'length')
@return string Tag for given string.
@access private
|
_parseTag
|
php
|
Datawalke/Coordino
|
app/models/behaviors/tag.php
|
https://github.com/Datawalke/Coordino/blob/master/app/models/behaviors/tag.php
|
MIT
|
public function parse($html, HtmlParserHandler $handler) {
$this->input = $html;
$this->pos = 0;
$this->len = strlen($html);
$this->handler = $handler;
$text = '';
while ($this->pos < $this->len) {
$char = $this->look();
if ($char === '<') {
if ($this->lookMatches('<!')) {
// Handle HTML comment
$this->commentBlock();
} else {
// Process tag
$this->fireText($text);
$text = '';
$this->tag();
}
} else {
$text .= $this->char();
}
}
if ($text !== '') {
$this->fireText($text);
}
}
|
Parse HTML snippet
@param $html string HTML snippet
@param $handler HtmlParserHandler Callback handler
|
parse
|
php
|
Datawalke/Coordino
|
app/vendors/htmlfilter/htmlfilter.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/htmlfilter/htmlfilter.php
|
MIT
|
private function char() {
if ($this->look() === '&') {
return $this->entity();
} else {
return htmlspecialchars($this->matchAny());
}
}
|
Match character, handling special characters and character entities
|
char
|
php
|
Datawalke/Coordino
|
app/vendors/htmlfilter/htmlfilter.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/htmlfilter/htmlfilter.php
|
MIT
|
private function entityNumber() {
$entity = $this->matches('&#');
$entity .= $this->matchNumber();
$len = strlen($entity);
if ($len <= 2 || $len > 6) {
// Invalid entity, escape &
return htmlspecialchars($entity);
}
if ($this->look() === ';') {
$entity .= $this->match(';');
} else {
$entity .= ';';
}
return $entity;
}
|
Parse HTML entity in number format. Eg. ©
|
entityNumber
|
php
|
Datawalke/Coordino
|
app/vendors/htmlfilter/htmlfilter.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/htmlfilter/htmlfilter.php
|
MIT
|
private function entityHex() {
$entity = $this->matches('&#x', true);
$entity .= $this->matchHexNumber();
$len = strlen($entity);
if ($len <= 3 || $len > 7) {
// Invalid entity, escape &
return htmlspecialchars($entity);
}
if ($this->look() === ';') {
$entity .= $this->match(';');
} else {
$entity .= ';';
}
return $entity;
}
|
Parse HTML entity in hex format. Eg. j
|
entityHex
|
php
|
Datawalke/Coordino
|
app/vendors/htmlfilter/htmlfilter.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/htmlfilter/htmlfilter.php
|
MIT
|
function Markdownify($linksAfterEachParagraph = MDFY_LINKS_EACH_PARAGRAPH, $bodyWidth = MDFY_BODYWIDTH, $keepHTML = MDFY_KEEPHTML) {
$this->linksAfterEachParagraph = $linksAfterEachParagraph;
$this->keepHTML = $keepHTML;
if ($bodyWidth > $this->minBodyWidth) {
$this->bodyWidth = intval($bodyWidth);
} else {
$this->bodyWidth = false;
}
$this->parser = new parseHTML;
$this->parser->noTagsInCode = true;
# we don't have to do this every time
$search = array();
$replace = array();
foreach ($this->escapeInText as $s => $r) {
array_push($search, '#(?<!\\\)'.$s.'#U');
array_push($replace, $r);
}
$this->escapeInText = array(
'search' => $search,
'replace' => $replace
);
}
|
constructor, set options, setup parser
@param bool $linksAfterEachParagraph wether or not to flush stacked links after each paragraph
defaults to false
@param int $bodyWidth wether or not to wrap the output to the given width
defaults to false
@param bool $keepHTML wether to keep non markdownable HTML or to discard it
defaults to true (HTML will be kept)
@return void
|
Markdownify
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function parseString($html) {
$this->parser->html = $html;
$this->parse();
return $this->output;
}
|
parse a HTML string
@param string $html
@return string markdown formatted
|
parseString
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function parse() {
$this->output = '';
# drop tags
$this->parser->html = preg_replace('#<('.implode('|', $this->drop).')[^>]*>.*</\\1>#sU', '', $this->parser->html);
while ($this->parser->nextNode()) {
switch ($this->parser->nodeType) {
case 'doctype':
break;
case 'pi':
case 'comment':
if ($this->keepHTML) {
$this->flushLinebreaks();
$this->out($this->parser->node);
$this->setLineBreaks(2);
}
# else drop
break;
case 'text':
$this->handleText();
break;
case 'tag':
if (in_array($this->parser->tagName, $this->ignore)) {
break;
}
if ($this->parser->isStartTag) {
$this->flushLinebreaks();
}
if ($this->skipConversion) {
$this->isMarkdownable(); # update notConverted
$this->handleTagToText();
continue;
}
if (!$this->parser->keepWhitespace && $this->parser->isBlockElement && $this->parser->isStartTag) {
$this->parser->html = ltrim($this->parser->html);
}
if ($this->isMarkdownable()) {
if ($this->parser->isBlockElement && $this->parser->isStartTag && !$this->lastWasBlockTag && !empty($this->output)) {
if (!empty($this->buffer)) {
$str =& $this->buffer[count($this->buffer) -1];
} else {
$str =& $this->output;
}
if (substr($str, -strlen($this->indent)-1) != "\n".$this->indent) {
$str .= "\n".$this->indent;
}
}
$func = 'handleTag_'.$this->parser->tagName;
$this->$func();
if ($this->linksAfterEachParagraph && $this->parser->isBlockElement && !$this->parser->isStartTag && empty($this->parser->openTags)) {
$this->flushStacked();
}
if (!$this->parser->isStartTag) {
$this->lastClosedTag = $this->parser->tagName;
}
} else {
$this->handleTagToText();
$this->lastClosedTag = '';
}
break;
default:
trigger_error('invalid node type', E_USER_ERROR);
break;
}
$this->lastWasBlockTag = $this->parser->nodeType == 'tag' && $this->parser->isStartTag && $this->parser->isBlockElement;
}
if (!empty($this->buffer)) {
trigger_error('buffer was not flushed, this is a bug. please report!', E_USER_WARNING);
while (!empty($this->buffer)) {
$this->out($this->unbuffer());
}
}
### cleanup
$this->output = rtrim(str_replace('&', '&', str_replace('<', '<', str_replace('>', '>', $this->output))));
# end parsing, flush stacked tags
$this->flushStacked();
$this->stack = array();
}
|
iterate through the nodes and decide what we
shall do with the current node
@param void
@return void
|
parse
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function isMarkdownable() {
if (!isset($this->isMarkdownable[$this->parser->tagName])) {
# simply not markdownable
return false;
}
if ($this->parser->isStartTag) {
$return = true;
if ($this->keepHTML) {
$diff = array_diff(array_keys($this->parser->tagAttributes), array_keys($this->isMarkdownable[$this->parser->tagName]));
if (!empty($diff)) {
# non markdownable attributes given
$return = false;
}
}
if ($return) {
foreach ($this->isMarkdownable[$this->parser->tagName] as $attr => $type) {
if ($type == 'required' && !isset($this->parser->tagAttributes[$attr])) {
# required markdown attribute not given
$return = false;
break;
}
}
}
if (!$return) {
array_push($this->notConverted, $this->parser->tagName.'::'.implode('/', $this->parser->openTags));
}
return $return;
} else {
if (!empty($this->notConverted) && end($this->notConverted) === $this->parser->tagName.'::'.implode('/', $this->parser->openTags)) {
array_pop($this->notConverted);
return false;
}
return true;
}
}
|
check if current tag can be converted to Markdown
@param void
@return bool
|
isMarkdownable
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function flushStacked() {
# links
foreach ($this->stack as $tag => $a) {
if (!empty($a)) {
call_user_func(array(&$this, 'flushStacked_'.$tag));
}
}
}
|
output all stacked tags
@param void
@return void
|
flushStacked
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function flushStacked_a() {
$out = false;
foreach ($this->stack['a'] as $k => $tag) {
if (!isset($tag['unstacked'])) {
if (!$out) {
$out = true;
$this->out("\n\n", true);
} else {
$this->out("\n", true);
}
$this->out(' ['.$tag['linkID'].']: '.$tag['href'].(isset($tag['title']) ? ' "'.$tag['title'].'"' : ''), true);
$tag['unstacked'] = true;
$this->stack['a'][$k] = $tag;
}
}
}
|
output link references (e.g. [1]: http://example.com "title");
@param void
@return void
|
flushStacked_a
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function flushLinebreaks() {
if ($this->lineBreaks && !empty($this->output)) {
$this->out(str_repeat("\n".$this->indent, $this->lineBreaks), true);
}
$this->lineBreaks = 0;
}
|
flush enqued linebreaks
@param void
@return void
|
flushLinebreaks
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTagToText() {
if (!$this->keepHTML) {
if (!$this->parser->isStartTag && $this->parser->isBlockElement) {
$this->setLineBreaks(2);
}
} else {
# dont convert to markdown inside this tag
/** TODO: markdown extra **/
if (!$this->parser->isEmptyTag) {
if ($this->parser->isStartTag) {
if (!$this->skipConversion) {
$this->skipConversion = $this->parser->tagName.'::'.implode('/', $this->parser->openTags);
}
} else {
if ($this->skipConversion == $this->parser->tagName.'::'.implode('/', $this->parser->openTags)) {
$this->skipConversion = false;
}
}
}
if ($this->parser->isBlockElement) {
if ($this->parser->isStartTag) {
if (in_array($this->parent(), array('ins', 'del'))) {
# looks like ins or del are block elements now
$this->out("\n", true);
$this->indent(' ');
}
if ($this->parser->tagName != 'pre') {
$this->out($this->parser->node."\n".$this->indent);
if (!$this->parser->isEmptyTag) {
$this->indent(' ');
} else {
$this->setLineBreaks(1);
}
$this->parser->html = ltrim($this->parser->html);
} else {
# don't indent inside <pre> tags
$this->out($this->parser->node);
static $indent;
$indent = $this->indent;
$this->indent = '';
}
} else {
if (!$this->parser->keepWhitespace) {
$this->output = rtrim($this->output);
}
if ($this->parser->tagName != 'pre') {
$this->indent(' ');
$this->out("\n".$this->indent.$this->parser->node);
} else {
# reset indentation
$this->out($this->parser->node);
static $indent;
$this->indent = $indent;
}
if (in_array($this->parent(), array('ins', 'del'))) {
# ins or del was block element
$this->out("\n");
$this->indent(' ');
}
if ($this->parser->tagName == 'li') {
$this->setLineBreaks(1);
} else {
$this->setLineBreaks(2);
}
}
} else {
$this->out($this->parser->node);
}
if (in_array($this->parser->tagName, array('code', 'pre'))) {
if ($this->parser->isStartTag) {
$this->buffer();
} else {
# add stuff so cleanup just reverses this
$this->out(str_replace('<', '&lt;', str_replace('>', '&gt;', $this->unbuffer())));
}
}
}
}
|
handle non Markdownable tags
@param void
@return void
|
handleTagToText
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleText() {
if ($this->hasParent('pre') && strpos($this->parser->node, "\n") !== false) {
$this->parser->node = str_replace("\n", "\n".$this->indent, $this->parser->node);
}
if (!$this->hasParent('code') && !$this->hasParent('pre')) {
# entity decode
$this->parser->node = $this->decode($this->parser->node);
if (!$this->skipConversion) {
# escape some chars in normal Text
$this->parser->node = preg_replace($this->escapeInText['search'], $this->escapeInText['replace'], $this->parser->node);
}
} else {
$this->parser->node = str_replace(array('"', '&apos'), array('"', '\''), $this->parser->node);
}
$this->out($this->parser->node);
$this->lastClosedTag = '';
}
|
handle plain text
@param void
@return void
|
handleText
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_em() {
$this->out('*', true);
}
|
handle <em> and <i> tags
@param void
@return void
|
handleTag_em
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_strong() {
$this->out('**', true);
}
|
handle <strong> and <b> tags
@param void
@return void
|
handleTag_strong
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleHeader($level) {
if ($this->parser->isStartTag) {
$this->out(str_repeat('#', $level).' ', true);
} else {
$this->setLineBreaks(2);
}
}
|
handle header tags (<h1> - <h6>)
@param int $level 1-6
@return void
|
handleHeader
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_p() {
if (!$this->parser->isStartTag) {
$this->setLineBreaks(2);
}
}
|
handle <p> tags
@param void
@return void
|
handleTag_p
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_a() {
if ($this->parser->isStartTag) {
$this->buffer();
if (isset($this->parser->tagAttributes['title'])) {
$this->parser->tagAttributes['title'] = $this->decode($this->parser->tagAttributes['title']);
} else {
$this->parser->tagAttributes['title'] = null;
}
$this->parser->tagAttributes['href'] = $this->decode(trim($this->parser->tagAttributes['href']));
$this->stack();
} else {
$tag = $this->unstack();
$buffer = $this->unbuffer();
if (empty($tag['href']) && empty($tag['title'])) {
# empty links... testcase mania, who would possibly do anything like that?!
$this->out('['.$buffer.']()', true);
return;
}
if ($buffer == $tag['href'] && empty($tag['title'])) {
# <http://example.com>
$this->out('<'.$buffer.'>', true);
return;
}
$bufferDecoded = $this->decode(trim($buffer));
if (substr($tag['href'], 0, 7) == 'mailto:' && 'mailto:'.$bufferDecoded == $tag['href']) {
if (is_null($tag['title'])) {
# <[email protected]>
$this->out('<'.$bufferDecoded.'>', true);
return;
}
# [[email protected]][1]
# ...
# [1]: mailto:[email protected] Title
$tag['href'] = 'mailto:'.$bufferDecoded;
}
# [This link][id]
foreach ($this->stack['a'] as $tag2) {
if ($tag2['href'] == $tag['href'] && $tag2['title'] === $tag['title']) {
$tag['linkID'] = $tag2['linkID'];
break;
}
}
if (!isset($tag['linkID'])) {
$tag['linkID'] = count($this->stack['a']) + 1;
array_push($this->stack['a'], $tag);
}
$this->out('['.$buffer.']['.$tag['linkID'].']', true);
}
}
|
handle <a> tags
@param void
@return void
|
handleTag_a
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_img() {
if (!$this->parser->isStartTag) {
return; # just to be sure this is really an empty tag...
}
if (isset($this->parser->tagAttributes['title'])) {
$this->parser->tagAttributes['title'] = $this->decode($this->parser->tagAttributes['title']);
} else {
$this->parser->tagAttributes['title'] = null;
}
if (isset($this->parser->tagAttributes['alt'])) {
$this->parser->tagAttributes['alt'] = $this->decode($this->parser->tagAttributes['alt']);
} else {
$this->parser->tagAttributes['alt'] = null;
}
if (empty($this->parser->tagAttributes['src'])) {
# support for "empty" images... dunno if this is really needed
# but there are some testcases which do that...
if (!empty($this->parser->tagAttributes['title'])) {
$this->parser->tagAttributes['title'] = ' '.$this->parser->tagAttributes['title'].' ';
}
$this->out('!['.$this->parser->tagAttributes['alt'].']('.$this->parser->tagAttributes['title'].')', true);
return;
} else {
$this->parser->tagAttributes['src'] = $this->decode($this->parser->tagAttributes['src']);
}
# [This link][id]
$link_id = false;
if (!empty($this->stack['a'])) {
foreach ($this->stack['a'] as $tag) {
if ($tag['href'] == $this->parser->tagAttributes['src']
&& $tag['title'] === $this->parser->tagAttributes['title']) {
$link_id = $tag['linkID'];
break;
}
}
} else {
$this->stack['a'] = array();
}
if (!$link_id) {
$link_id = count($this->stack['a']) + 1;
$tag = array(
'href' => $this->parser->tagAttributes['src'],
'linkID' => $link_id,
'title' => $this->parser->tagAttributes['title']
);
array_push($this->stack['a'], $tag);
}
$this->out('!['.$this->parser->tagAttributes['alt'].']['.$link_id.']', true);
}
|
handle <img /> tags
@param void
@return void
|
handleTag_img
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_code() {
if ($this->hasParent('pre')) {
# ignore code blocks inside <pre>
return;
}
if ($this->parser->isStartTag) {
$this->buffer();
} else {
$buffer = $this->unbuffer();
# use as many backticks as needed
preg_match_all('#`+#', $buffer, $matches);
if (!empty($matches[0])) {
rsort($matches[0]);
$ticks = '`';
while (true) {
if (!in_array($ticks, $matches[0])) {
break;
}
$ticks .= '`';
}
} else {
$ticks = '`';
}
if ($buffer[0] == '`' || substr($buffer, -1) == '`') {
$buffer = ' '.$buffer.' ';
}
$this->out($ticks.$buffer.$ticks, true);
}
}
|
handle <code> tags
@param void
@return void
|
handleTag_code
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_pre() {
if ($this->keepHTML && $this->parser->isStartTag) {
# check if a simple <code> follows
if (!preg_match('#^\s*<code\s*>#Us', $this->parser->html)) {
# this is no standard markdown code block
$this->handleTagToText();
return;
}
}
$this->indent(' ');
if (!$this->parser->isStartTag) {
$this->setLineBreaks(2);
} else {
$this->parser->html = ltrim($this->parser->html);
}
}
|
handle <pre> tags
@param void
@return void
|
handleTag_pre
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_blockquote() {
$this->indent('> ');
}
|
handle <blockquote> tags
@param void
@return void
|
handleTag_blockquote
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_ul() {
if ($this->parser->isStartTag) {
$this->stack();
if (!$this->keepHTML && $this->lastClosedTag == $this->parser->tagName) {
$this->out("\n".$this->indent.'<!-- -->'."\n".$this->indent."\n".$this->indent);
}
} else {
$this->unstack();
if ($this->parent() != 'li' || preg_match('#^\s*(</li\s*>\s*<li\s*>\s*)?<(p|blockquote)\s*>#sU', $this->parser->html)) {
# dont make Markdown add unneeded paragraphs
$this->setLineBreaks(2);
}
}
}
|
handle <ul> tags
@param void
@return void
|
handleTag_ul
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_ol() {
# same as above
$this->parser->tagAttributes['num'] = 0;
$this->handleTag_ul();
}
|
handle <ul> tags
@param void
@return void
|
handleTag_ol
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_li() {
if ($this->parent() == 'ol') {
$parent =& $this->getStacked('ol');
if ($this->parser->isStartTag) {
$parent['num']++;
$this->out($parent['num'].'.'.str_repeat(' ', 3 - strlen($parent['num'])), true);
}
$this->indent(' ', false);
} else {
if ($this->parser->isStartTag) {
$this->out('* ', true);
}
$this->indent(' ', false);
}
if (!$this->parser->isStartTag) {
$this->setLineBreaks(1);
}
}
|
handle <li> tags
@param void
@return void
|
handleTag_li
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_hr() {
if (!$this->parser->isStartTag) {
return; # just to be sure this really is an empty tag
}
$this->out('* * *', true);
$this->setLineBreaks(2);
}
|
handle <hr /> tags
@param void
@return void
|
handleTag_hr
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function handleTag_br() {
$this->out(" \n".$this->indent, true);
$this->parser->html = ltrim($this->parser->html);
}
|
handle <br /> tags
@param void
@return void
|
handleTag_br
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function stack() {
if (!isset($this->stack[$this->parser->tagName])) {
$this->stack[$this->parser->tagName] = array();
}
array_push($this->stack[$this->parser->tagName], $this->parser->tagAttributes);
}
|
add current node to the stack
this only stores the attributes
@param void
@return void
|
stack
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function unstack() {
if (!isset($this->stack[$this->parser->tagName]) || !is_array($this->stack[$this->parser->tagName])) {
trigger_error('Trying to unstack from empty stack. This must not happen.', E_USER_ERROR);
}
return array_pop($this->stack[$this->parser->tagName]);
}
|
remove current tag from stack
@param void
@return array
|
unstack
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function & getStacked($tagName) {
// no end() so it can be referenced
return $this->stack[$tagName][count($this->stack[$tagName])-1];
}
|
get last stacked element of type $tagName
@param string $tagName
@return array
|
getStacked
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function setLineBreaks($number) {
if ($this->lineBreaks < $number) {
$this->lineBreaks = $number;
}
}
|
set number of line breaks before next start tag
@param int $number
@return void
|
setLineBreaks
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function buffer() {
array_push($this->buffer, '');
}
|
buffer next parser output until unbuffer() is called
@param void
@return void
|
buffer
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function unbuffer() {
return array_pop($this->buffer);
}
|
end current buffer and return buffered output
@param void
@return string
|
unbuffer
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function out($put, $nowrap = false) {
if (empty($put)) {
return;
}
if (!empty($this->buffer)) {
$this->buffer[count($this->buffer) - 1] .= $put;
} else {
if ($this->bodyWidth && !$this->parser->keepWhitespace) { # wrap lines
// get last line
$pos = strrpos($this->output, "\n");
if ($pos === false) {
$line = $this->output;
} else {
$line = substr($this->output, $pos);
}
if ($nowrap) {
if ($put[0] != "\n" && $this->strlen($line) + $this->strlen($put) > $this->bodyWidth) {
$this->output .= "\n".$this->indent.$put;
} else {
$this->output .= $put;
}
return;
} else {
$put .= "\n"; # make sure we get all lines in the while below
$lineLen = $this->strlen($line);
while ($pos = strpos($put, "\n")) {
$putLine = substr($put, 0, $pos+1);
$put = substr($put, $pos+1);
$putLen = $this->strlen($putLine);
if ($lineLen + $putLen < $this->bodyWidth) {
$this->output .= $putLine;
$lineLen = $putLen;
} else {
$split = preg_split('#^(.{0,'.($this->bodyWidth - $lineLen).'})\b#', $putLine, 2, PREG_SPLIT_OFFSET_CAPTURE | PREG_SPLIT_DELIM_CAPTURE);
$this->output .= rtrim($split[1][0])."\n".$this->indent.$this->wordwrap(ltrim($split[2][0]), $this->bodyWidth, "\n".$this->indent, false);
}
}
$this->output = substr($this->output, 0, -1);
return;
}
} else {
$this->output .= $put;
}
}
}
|
append string to the correct var, either
directly to $this->output or to the current
buffers
@param string $put
@return void
|
out
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function indent($str, $output = true) {
if ($this->parser->isStartTag) {
$this->indent .= $str;
if ($output) {
$this->out($str, true);
}
} else {
$this->indent = substr($this->indent, 0, -strlen($str));
}
}
|
indent next output (start tag) or unindent (end tag)
@param string $str indentation
@param bool $output add indendation to output
@return void
|
indent
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function decode($text, $quote_style = ENT_QUOTES) {
if (version_compare(PHP_VERSION, '5', '>=')) {
# UTF-8 is only supported in PHP 5.x.x and above
$text = html_entity_decode($text, $quote_style, 'UTF-8');
} else {
if (function_exists('html_entity_decode')) {
$text = html_entity_decode($text, $quote_style, 'ISO-8859-1');
} else {
static $trans_tbl;
if (!isset($trans_tbl)) {
$trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES, $quote_style));
}
$text = strtr($text, $trans_tbl);
}
$text = preg_replace_callback('~&#x([0-9a-f]+);~i', array(&$this, '_decode_hex'), $text);
$text = preg_replace_callback('~&#(\d{2,5});~', array(&$this, '_decode_numeric'), $text);
}
return $text;
}
|
decode email addresses
@author [email protected] <http://www.php.net/manual/en/function.html-entity-decode.php#68536>
@author Milian Wolff <http://milianw.de>
|
decode
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function _decode_hex($matches) {
return $this->unichr(hexdec($matches[1]));
}
|
callback for decode() which converts a hexadecimal entity to UTF-8
@param array $matches
@return string UTF-8 encoded
|
_decode_hex
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function _decode_numeric($matches) {
return $this->unichr($matches[1]);
}
|
callback for decode() which converts a numerical entity to UTF-8
@param array $matches
@return string UTF-8 encoded
|
_decode_numeric
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function unichr($dec) {
if ($dec < 128) {
$utf = chr($dec);
} else if ($dec < 2048) {
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
} else {
$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
}
return $utf;
}
|
UTF-8 chr() which supports numeric entities
@author grey - greywyvern - com <http://www.php.net/manual/en/function.chr.php#55978>
@param array $matches
@return string UTF-8 encoded
|
unichr
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function strlen($str) {
if (function_exists('mb_strlen')) {
return mb_strlen($str, 'UTF-8');
} else {
return preg_match_all('/[\x00-\x7F\xC0-\xFD]/', $str, $var_empty);
}
}
|
UTF-8 strlen()
@param string $str
@return int
@author dtorop 932 at hotmail dot com <http://www.php.net/manual/en/function.strlen.php#37975>
@author Milian Wolff <http://milianw.de>
|
strlen
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function wordwrap($str, $width, $break, $cut = false){
if (!$cut) {
$regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){1,'.$width.'}\b#';
} else {
$regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.'}#';
}
$return = '';
while (preg_match($regexp, $str, $matches)) {
$string = $matches[0];
$str = ltrim(substr($str, strlen($string)));
if (!$cut && isset($str[0]) && in_array($str[0], array('.', '!', ';', ':', '?', ','))) {
$string .= $str[0];
$str = ltrim(substr($str, 1));
}
$return .= $string.$break;
}
return $return.ltrim($str);
}
|
wordwrap for utf8 encoded strings
@param string $str
@param integer $len
@param string $what
@return string
|
wordwrap
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function hasParent($tagName) {
return in_array($tagName, $this->parser->openTags);
}
|
check if current node has a $tagName as parent (somewhere, not only the direct parent)
@param string $tagName
@return bool
|
hasParent
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function parent() {
return end($this->parser->openTags);
}
|
get tagName of direct parent tag
@param void
@return string $tagName
|
parent
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify.php
|
MIT
|
function Markdownify_Extra($linksAfterEachParagraph = MDFY_LINKS_EACH_PARAGRAPH, $bodyWidth = MDFY_BODYWIDTH, $keepHTML = MDFY_KEEPHTML) {
parent::Markdownify($linksAfterEachParagraph, $bodyWidth, $keepHTML);
### new markdownable tags & attributes
# header ids: # foo {bar}
$this->isMarkdownable['h1']['id'] = 'optional';
$this->isMarkdownable['h2']['id'] = 'optional';
$this->isMarkdownable['h3']['id'] = 'optional';
$this->isMarkdownable['h4']['id'] = 'optional';
$this->isMarkdownable['h5']['id'] = 'optional';
$this->isMarkdownable['h6']['id'] = 'optional';
# tables
$this->isMarkdownable['table'] = array();
$this->isMarkdownable['th'] = array(
'align' => 'optional',
);
$this->isMarkdownable['td'] = array(
'align' => 'optional',
);
$this->isMarkdownable['tr'] = array();
array_push($this->ignore, 'thead');
array_push($this->ignore, 'tbody');
array_push($this->ignore, 'tfoot');
# definition lists
$this->isMarkdownable['dl'] = array();
$this->isMarkdownable['dd'] = array();
$this->isMarkdownable['dt'] = array();
# footnotes
$this->isMarkdownable['fnref'] = array(
'target' => 'required',
);
$this->isMarkdownable['footnotes'] = array();
$this->isMarkdownable['fn'] = array(
'name' => 'required',
);
$this->parser->blockElements['fnref'] = false;
$this->parser->blockElements['fn'] = true;
$this->parser->blockElements['footnotes'] = true;
# abbr
$this->isMarkdownable['abbr'] = array(
'title' => 'required',
);
# build RegEx lookahead to decide wether table can pe parsed or not
$inlineTags = array_keys($this->parser->blockElements, false);
$colContents = '(?:[^<]|<(?:'.implode('|', $inlineTags).'|[^a-z]))+';
$this->tableLookaheadHeader = '{
^\s*(?:<thead\s*>)?\s* # open optional thead
<tr\s*>\s*(?: # start required row with headers
<th(?:\s+align=("|\')(?:left|center|right)\1)?\s*> # header with optional align
\s*'.$colContents.'\s* # contents
</th>\s* # close header
)+</tr> # close row with headers
\s*(?:</thead>)? # close optional thead
}sxi';
$this->tdSubstitute = '\s*'.$colContents.'\s* # contents
</td>\s*';
$this->tableLookaheadBody = '{
\s*(?:<tbody\s*>)?\s* # open optional tbody
(?:<tr\s*>\s* # start row
%s # cols to be substituted
</tr>)+ # close row
\s*(?:</tbody>)? # close optional tbody
\s*</table> # close table
}sxi';
}
|
constructor, see Markdownify::Markdownify() for more information
|
Markdownify_Extra
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function handleHeader($level) {
static $id = null;
if ($this->parser->isStartTag) {
if (isset($this->parser->tagAttributes['id'])) {
$id = $this->parser->tagAttributes['id'];
}
} else {
if (!is_null($id)) {
$this->out(' {#'.$id.'}');
$id = null;
}
}
parent::handleHeader($level);
}
|
handle header tags (<h1> - <h6>)
@param int $level 1-6
@return void
|
handleHeader
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function handleTag_abbr() {
if ($this->parser->isStartTag) {
$this->stack();
$this->buffer();
} else {
$tag = $this->unstack();
$tag['text'] = $this->unbuffer();
$add = true;
foreach ($this->stack['abbr'] as $stacked) {
if ($stacked['text'] == $tag['text']) {
/** TODO: differing abbr definitions, i.e. different titles for same text **/
$add = false;
break;
}
}
$this->out($tag['text']);
if ($add) {
array_push($this->stack['abbr'], $tag);
}
}
}
|
handle <abbr> tags
@param void
@return void
|
handleTag_abbr
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function flushStacked_abbr() {
$out = array();
foreach ($this->stack['abbr'] as $k => $tag) {
if (!isset($tag['unstacked'])) {
array_push($out, ' *['.$tag['text'].']: '.$tag['title']);
$tag['unstacked'] = true;
$this->stack['abbr'][$k] = $tag;
}
}
if (!empty($out)) {
$this->out("\n\n".implode("\n", $out));
}
}
|
flush stacked abbr tags
@param void
@return void
|
flushStacked_abbr
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function handleTag_table() {
if ($this->parser->isStartTag) {
# check if upcoming table can be converted
if ($this->keepHTML) {
if (preg_match($this->tableLookaheadHeader, $this->parser->html, $matches)) {
# header seems good, now check body
# get align & number of cols
preg_match_all('#<th(?:\s+align=("|\')(left|right|center)\1)?\s*>#si', $matches[0], $cols);
$regEx = '';
$i = 1;
$aligns = array();
foreach ($cols[2] as $align) {
$align = strtolower($align);
array_push($aligns, $align);
if (empty($align)) {
$align = 'left'; # default value
}
$td = '\s+align=("|\')'.$align.'\\'.$i;
$i++;
if ($align == 'left') {
# look for empty align or left
$td = '(?:'.$td.')?';
}
$td = '<td'.$td.'\s*>';
$regEx .= $td.$this->tdSubstitute;
}
$regEx = sprintf($this->tableLookaheadBody, $regEx);
if (preg_match($regEx, $this->parser->html, $matches, null, strlen($matches[0]))) {
# this is a markdownable table tag!
$this->table = array(
'rows' => array(),
'col_widths' => array(),
'aligns' => $aligns,
);
$this->row = 0;
} else {
# non markdownable table
$this->handleTagToText();
}
} else {
# non markdownable table
$this->handleTagToText();
}
} else {
$this->table = array(
'rows' => array(),
'col_widths' => array(),
'aligns' => array(),
);
$this->row = 0;
}
} else {
# finally build the table in Markdown Extra syntax
$separator = array();
# seperator with correct align identifikators
foreach($this->table['aligns'] as $col => $align) {
if (!$this->keepHTML && !isset($this->table['col_widths'][$col])) {
break;
}
$left = ' ';
$right = ' ';
switch ($align) {
case 'left':
$left = ':';
break;
case 'center':
$right = ':';
$left = ':';
case 'right':
$right = ':';
break;
}
array_push($separator, $left.str_repeat('-', $this->table['col_widths'][$col]).$right);
}
$separator = '|'.implode('|', $separator).'|';
$rows = array();
# add padding
array_walk_recursive($this->table['rows'], array(&$this, 'alignTdContent'));
$header = array_shift($this->table['rows']);
array_push($rows, '| '.implode(' | ', $header).' |');
array_push($rows, $separator);
foreach ($this->table['rows'] as $row) {
array_push($rows, '| '.implode(' | ', $row).' |');
}
$this->out(implode("\n".$this->indent, $rows));
$this->table = array();
$this->setLineBreaks(2);
}
}
|
handle <table> tags
@param void
@return void
|
handleTag_table
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function alignTdContent(&$content, $col) {
switch ($this->table['aligns'][$col]) {
default:
case 'left':
$content .= str_repeat(' ', $this->table['col_widths'][$col] - $this->strlen($content));
break;
case 'right':
$content = str_repeat(' ', $this->table['col_widths'][$col] - $this->strlen($content)).$content;
break;
case 'center':
$paddingNeeded = $this->table['col_widths'][$col] - $this->strlen($content);
$left = floor($paddingNeeded / 2);
$right = $paddingNeeded - $left;
$content = str_repeat(' ', $left).$content.str_repeat(' ', $right);
break;
}
}
|
properly pad content so it is aligned as whished
should be used with array_walk_recursive on $this->table['rows']
@param string &$content
@param int $col
@return void
|
alignTdContent
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function handleTag_tr() {
if ($this->parser->isStartTag) {
$this->col = -1;
} else {
$this->row++;
}
}
|
handle <tr> tags
@param void
@return void
|
handleTag_tr
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function handleTag_td() {
if ($this->parser->isStartTag) {
$this->col++;
if (!isset($this->table['col_widths'][$this->col])) {
$this->table['col_widths'][$this->col] = 0;
}
$this->buffer();
} else {
$buffer = trim($this->unbuffer());
$this->table['col_widths'][$this->col] = max($this->table['col_widths'][$this->col], $this->strlen($buffer));
$this->table['rows'][$this->row][$this->col] = $buffer;
}
}
|
handle <td> tags
@param void
@return void
|
handleTag_td
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function handleTag_th() {
if (!$this->keepHTML && !isset($this->table['rows'][1]) && !isset($this->table['aligns'][$this->col+1])) {
if (isset($this->parser->tagAttributes['align'])) {
$this->table['aligns'][$this->col+1] = $this->parser->tagAttributes['align'];
} else {
$this->table['aligns'][$this->col+1] = '';
}
}
$this->handleTag_td();
}
|
handle <th> tags
@param void
@return void
|
handleTag_th
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function handleTag_dl() {
if (!$this->parser->isStartTag) {
$this->setLineBreaks(2);
}
}
|
handle <dl> tags
@param void
@return void
|
handleTag_dl
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function handleTag_dt() {
if (!$this->parser->isStartTag) {
$this->setLineBreaks(1);
}
}
|
handle <dt> tags
@param void
@return void
|
handleTag_dt
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function handleTag_dd() {
if ($this->parser->isStartTag) {
if (substr(ltrim($this->parser->html), 0, 3) == '<p>') {
# next comes a paragraph, so we'll need an extra line
$this->out("\n".$this->indent);
} elseif (substr($this->output, -2) == "\n\n") {
$this->output = substr($this->output, 0, -1);
}
$this->out(': ');
$this->indent(' ', false);
} else {
# lookahead for next dt
if (substr(ltrim($this->parser->html), 0, 4) == '<dt>') {
$this->setLineBreaks(2);
} else {
$this->setLineBreaks(1);
}
$this->indent(' ');
}
}
|
handle <dd> tags
@param void
@return void
|
handleTag_dd
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function handleTag_fn() {
if ($this->parser->isStartTag) {
$this->out('[^'.$this->parser->tagAttributes['name'].']:');
$this->setLineBreaks(1);
} else {
$this->setLineBreaks(2);
}
$this->indent(' ');
}
|
handle <fn> tags (custom footnotes, see markdownify_extra::parseString()
and markdownify_extra::_makeFootnotes())
@param void
@return void
|
handleTag_fn
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function handleTag_footnotes() {
if (!$this->parser->isStartTag) {
$this->setLineBreaks(2);
}
}
|
handle <footnotes> tag (custom footnotes, see markdownify_extra::parseString()
and markdownify_extra::_makeFootnotes())
@param void
@return void
|
handleTag_footnotes
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function parseString($html) {
/** TODO: custom markdown-extra options, e.g. titles & classes **/
# <sup id="fnref:..."><a href"#fn..." rel="footnote">...</a></sup>
# => <fnref target="..." />
$html = preg_replace('@<sup id="fnref:([^"]+)">\s*<a href="#fn:\1" rel="footnote">\s*\d+\s*</a>\s*</sup>@Us', '<fnref target="$1" />', $html);
# <div class="footnotes">
# <hr />
# <ol>
#
# <li id="fn:...">...</li>
# ...
#
# </ol>
# </div>
# =>
# <footnotes>
# <fn name="...">...</fn>
# ...
# </footnotes>
$html = preg_replace_callback('#<div class="footnotes">\s*<hr />\s*<ol>\s*(.+)\s*</ol>\s*</div>#Us', array(&$this, '_makeFootnotes'), $html);
return parent::parseString($html);
}
|
parse a HTML string, clean up footnotes prior
@param string $HTML input
@return string Markdown formatted output
|
parseString
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function _makeFootnotes($matches) {
# <li id="fn:1">
# ...
# <a href="#fnref:block" rev="footnote">↩</a></p>
# </li>
# => <fn name="1">...</fn>
# remove footnote link
$fns = preg_replace('@\s*( \s*)?<a href="#fnref:[^"]+" rev="footnote"[^>]*>↩</a>\s*@s', '', $matches[1]);
# remove empty paragraph
$fns = preg_replace('@<p>\s*</p>@s', '', $fns);
# <li id="fn:1">...</li> -> <footnote nr="1">...</footnote>
$fns = str_replace('<li id="fn:', '<fn name="', $fns);
$fns = '<footnotes>'.$fns.'</footnotes>';
return preg_replace('#</li>\s*(?=(?:<fn|</footnotes>))#s', '</fn>$1', $fns);
}
|
replace HTML representation of footnotes with something more easily parsable
@note this is a callback to be used in parseString()
@param array $matches
@return string
|
_makeFootnotes
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/markdownify_extra.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/markdownify_extra.php
|
MIT
|
function nextNode() {
if (empty($this->html)) {
# we are done with parsing the html string
return false;
}
static $skipWhitespace = true;
if ($this->isStartTag && !$this->isEmptyTag) {
array_push($this->openTags, $this->tagName);
if (in_array($this->tagName, $this->preformattedTags)) {
# dont truncate whitespaces for <code> or <pre> contents
$this->keepWhitespace++;
}
}
if ($this->html[0] == '<') {
$token = substr($this->html, 0, 9);
if (substr($token, 0, 2) == '<?') {
# xml prolog or other pi's
/** TODO **/
#trigger_error('this might need some work', E_USER_NOTICE);
$pos = strpos($this->html, '>');
$this->setNode('pi', $pos + 1);
return true;
}
if (substr($token, 0, 4) == '<!--') {
# comment
$pos = strpos($this->html, '-->');
if ($pos === false) {
# could not find a closing -->, use next gt instead
# this is firefox' behaviour
$pos = strpos($this->html, '>') + 1;
} else {
$pos += 3;
}
$this->setNode('comment', $pos);
$skipWhitespace = true;
return true;
}
if ($token == '<!DOCTYPE') {
# doctype
$this->setNode('doctype', strpos($this->html, '>')+1);
$skipWhitespace = true;
return true;
}
if ($token == '<![CDATA[') {
# cdata, use text node
# remove leading <![CDATA[
$this->html = substr($this->html, 9);
$this->setNode('text', strpos($this->html, ']]>')+3);
# remove trailing ]]> and trim
$this->node = substr($this->node, 0, -3);
$this->handleWhitespaces();
$skipWhitespace = true;
return true;
}
if ($this->parseTag()) {
# seems to be a tag
# handle whitespaces
if ($this->isBlockElement) {
$skipWhitespace = true;
} else {
$skipWhitespace = false;
}
return true;
}
}
if ($this->keepWhitespace) {
$skipWhitespace = false;
}
# when we get here it seems to be a text node
$pos = strpos($this->html, '<');
if ($pos === false) {
$pos = strlen($this->html);
}
$this->setNode('text', $pos);
$this->handleWhitespaces();
if ($skipWhitespace && $this->node == ' ') {
return $this->nextNode();
}
$skipWhitespace = false;
return true;
}
|
get next node, set $this->html prior!
@param void
@return bool
|
nextNode
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/parsehtml/parsehtml.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/parsehtml/parsehtml.php
|
MIT
|
function parseTag() {
static $a_ord, $z_ord, $special_ords;
if (!isset($a_ord)) {
$a_ord = ord('a');
$z_ord = ord('z');
$special_ords = array(
ord(':'), // for xml:lang
ord('-'), // for http-equiv
);
}
$tagName = '';
$pos = 1;
$isStartTag = $this->html[$pos] != '/';
if (!$isStartTag) {
$pos++;
}
# get tagName
while (isset($this->html[$pos])) {
$pos_ord = ord(strtolower($this->html[$pos]));
if (($pos_ord >= $a_ord && $pos_ord <= $z_ord) || (!empty($tagName) && is_numeric($this->html[$pos]))) {
$tagName .= $this->html[$pos];
$pos++;
} else {
$pos--;
break;
}
}
$tagName = strtolower($tagName);
if (empty($tagName) || !isset($this->blockElements[$tagName])) {
# something went wrong => invalid tag
$this->invalidTag();
return false;
}
if ($this->noTagsInCode && end($this->openTags) == 'code' && !($tagName == 'code' && !$isStartTag)) {
# we supress all HTML tags inside code tags
$this->invalidTag();
return false;
}
# get tag attributes
/** TODO: in html 4 attributes do not need to be quoted **/
$isEmptyTag = false;
$attributes = array();
$currAttrib = '';
while (isset($this->html[$pos+1])) {
$pos++;
# close tag
if ($this->html[$pos] == '>' || $this->html[$pos].$this->html[$pos+1] == '/>') {
if ($this->html[$pos] == '/') {
$isEmptyTag = true;
$pos++;
}
break;
}
$pos_ord = ord(strtolower($this->html[$pos]));
if ( ($pos_ord >= $a_ord && $pos_ord <= $z_ord) || in_array($pos_ord, $special_ords)) {
# attribute name
$currAttrib .= $this->html[$pos];
} elseif (in_array($this->html[$pos], array(' ', "\t", "\n"))) {
# drop whitespace
} elseif (in_array($this->html[$pos].$this->html[$pos+1], array('="', "='"))) {
# get attribute value
$pos++;
$await = $this->html[$pos]; # single or double quote
$pos++;
$value = '';
while (isset($this->html[$pos]) && $this->html[$pos] != $await) {
$value .= $this->html[$pos];
$pos++;
}
$attributes[$currAttrib] = $value;
$currAttrib = '';
} else {
$this->invalidTag();
return false;
}
}
if ($this->html[$pos] != '>') {
$this->invalidTag();
return false;
}
if (!empty($currAttrib)) {
# html 4 allows something like <option selected> instead of <option selected="selected">
$attributes[$currAttrib] = $currAttrib;
}
if (!$isStartTag) {
if (!empty($attributes) || $tagName != end($this->openTags)) {
# end tags must not contain any attributes
# or maybe we did not expect a different tag to be closed
$this->invalidTag();
return false;
}
array_pop($this->openTags);
if (in_array($tagName, $this->preformattedTags)) {
$this->keepWhitespace--;
}
}
$pos++;
$this->node = substr($this->html, 0, $pos);
$this->html = substr($this->html, $pos);
$this->tagName = $tagName;
$this->tagAttributes = $attributes;
$this->isStartTag = $isStartTag;
$this->isEmptyTag = $isEmptyTag || in_array($tagName, $this->emptyTags);
if ($this->isEmptyTag) {
# might be not well formed
$this->node = preg_replace('# */? *>$#', ' />', $this->node);
}
$this->nodeType = 'tag';
$this->isBlockElement = $this->blockElements[$tagName];
return true;
}
|
parse tag, set tag name and attributes, see if it's a closing tag and so forth...
@param void
@return bool
|
parseTag
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/parsehtml/parsehtml.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/parsehtml/parsehtml.php
|
MIT
|
function invalidTag() {
$this->html = substr_replace($this->html, '<', 0, 1);
}
|
handle invalid tags
@param void
@return void
|
invalidTag
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/parsehtml/parsehtml.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/parsehtml/parsehtml.php
|
MIT
|
function setNode($type, $pos) {
if ($this->nodeType == 'tag') {
# set tag specific vars to null
# $type == tag should not be called here
# see this::parseTag() for more
$this->tagName = null;
$this->tagAttributes = null;
$this->isStartTag = null;
$this->isEmptyTag = null;
$this->isBlockElement = null;
}
$this->nodeType = $type;
$this->node = substr($this->html, 0, $pos);
$this->html = substr($this->html, $pos);
}
|
update all vars and make $this->html shorter
@param string $type see description for $this->nodeType
@param int $pos to which position shall we cut?
@return void
|
setNode
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/parsehtml/parsehtml.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/parsehtml/parsehtml.php
|
MIT
|
function match($str) {
return substr($this->html, 0, strlen($str)) == $str;
}
|
check if $this->html begins with $str
@param string $str
@return bool
|
match
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/parsehtml/parsehtml.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/parsehtml/parsehtml.php
|
MIT
|
function handleWhitespaces() {
if ($this->keepWhitespace) {
# <pre> or <code> before...
return;
}
# truncate multiple whitespaces to a single one
$this->node = preg_replace('#\s+#s', ' ', $this->node);
}
|
truncate whitespaces
@param void
@return void
|
handleWhitespaces
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/parsehtml/parsehtml.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/parsehtml/parsehtml.php
|
MIT
|
function normalizeNode() {
$this->node = '<';
if (!$this->isStartTag) {
$this->node .= '/'.$this->tagName.'>';
return;
}
$this->node .= $this->tagName;
foreach ($this->tagAttributes as $name => $value) {
$this->node .= ' '.$name.'="'.str_replace('"', '"', $value).'"';
}
if ($this->isEmptyTag) {
$this->node .= ' /';
}
$this->node .= '>';
}
|
normalize self::node
@param void
@return void
|
normalizeNode
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/parsehtml/parsehtml.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/parsehtml/parsehtml.php
|
MIT
|
function indentHTML($html, $indent = " ", $noTagsInCode = false) {
$parser = new parseHTML;
$parser->noTagsInCode = $noTagsInCode;
$parser->html = $html;
$html = '';
$last = true; # last tag was block elem
$indent_a = array();
while($parser->nextNode()) {
if ($parser->nodeType == 'tag') {
$parser->normalizeNode();
}
if ($parser->nodeType == 'tag' && $parser->isBlockElement) {
$isPreOrCode = in_array($parser->tagName, array('code', 'pre'));
if (!$parser->keepWhitespace && !$last && !$isPreOrCode) {
$html = rtrim($html)."\n";
}
if ($parser->isStartTag) {
$html .= implode($indent_a);
if (!$parser->isEmptyTag) {
array_push($indent_a, $indent);
}
} else {
array_pop($indent_a);
if (!$isPreOrCode) {
$html .= implode($indent_a);
}
}
$html .= $parser->node;
if (!$parser->keepWhitespace && !($isPreOrCode && $parser->isStartTag)) {
$html .= "\n";
}
$last = true;
} else {
if ($parser->nodeType == 'tag' && $parser->tagName == 'br') {
$html .= $parser->node."\n";
$last = true;
continue;
} elseif ($last && !$parser->keepWhitespace) {
$html .= implode($indent_a);
$parser->node = ltrim($parser->node);
}
$html .= $parser->node;
if (in_array($parser->nodeType, array('comment', 'pi', 'doctype'))) {
$html .= "\n";
} else {
$last = false;
}
}
}
return $html;
}
|
indent a HTML string properly
@param string $html
@param string $indent optional
@return string
|
indentHTML
|
php
|
Datawalke/Coordino
|
app/vendors/markdownify/parsehtml/parsehtml.php
|
https://github.com/Datawalke/Coordino/blob/master/app/vendors/markdownify/parsehtml/parsehtml.php
|
MIT
|
function __form($pubkey, $error = null, $use_ssl = false){
if ($pubkey == null || $pubkey == '') {
die ("To use reCAPTCHA you must get an API key from <a href='http://recaptcha.net/api/getkey'>http://recaptcha.net/api/getkey</a>");
}
if ($use_ssl) {
$server = Configure::read('Recaptcha.apiSecureServer');
} else {
$server = Configure::read('Recaptcha.apiServer');
}
$errorpart = "";
if ($error) {
$errorpart = "&error=" . $error;
}
return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
<noscript>
<iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>';
}
|
Gets the challenge HTML (javascript and non-javascript version).
This is called from the browser, and the resulting reCAPTCHA HTML widget
is embedded within the HTML form it was called from.
@param string $pubkey A public key for reCAPTCHA
@param string $error The error given by reCAPTCHA (optional, default is null)
@param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
@return string - The HTML to be embedded in the user's form.
|
__form
|
php
|
Datawalke/Coordino
|
app/views/helpers/recaptcha.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/recaptcha.php
|
MIT
|
function _recaptcha_mailhide_email_parts ($email) {
$arr = preg_split("/@/", $email );
if (strlen ($arr[0]) <= 4) {
$arr[0] = substr ($arr[0], 0, 1);
} else if (strlen ($arr[0]) <= 6) {
$arr[0] = substr ($arr[0], 0, 3);
} else {
$arr[0] = substr ($arr[0], 0, 4);
}
return $arr;
}
|
gets the parts of the email to expose to the user.
eg, given johndoe@example,com return ["john", "example.com"].
the email is then displayed as [email protected]
|
_recaptcha_mailhide_email_parts
|
php
|
Datawalke/Coordino
|
app/views/helpers/recaptcha.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/recaptcha.php
|
MIT
|
function recaptcha_mailhide_html($pubkey, $privkey, $email) {
$emailparts = $this->_recaptcha_mailhide_email_parts ($email);
$url = $this->recaptcha_mailhide_url ($pubkey, $privkey, $email);
return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
"' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
}
|
Gets html to display an email address given a public an private key.
to get a key, go to:
http://mailhide.recaptcha.net/apikey
|
recaptcha_mailhide_html
|
php
|
Datawalke/Coordino
|
app/views/helpers/recaptcha.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/recaptcha.php
|
MIT
|
public function show(array $options = array(),array $tag_options = array()) {
echo $this->get($options, $tag_options);
}
|
Print image tag for thumbnail. If the thumbnail doesn't exist, it will be created.
@param array $options
@param array $tag_options
|
show
|
php
|
Datawalke/Coordino
|
app/views/helpers/thumbnail.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/thumbnail.php
|
MIT
|
public function get(array $options = array(), array $tag_options = array()) {
$this->init($options, $tag_options);
if(!$this->image_is_cached()) {
$this->create_thumb();
}
return $this->get_image_tag();
}
|
Return image tag for thumbnail. If the thumbnail doesn't exist, il will be created
@param array $options
@param array $tag_options
|
get
|
php
|
Datawalke/Coordino
|
app/views/helpers/thumbnail.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/thumbnail.php
|
MIT
|
private function get_image_tag() {
if($this->error != '') {
$src = $this->options['error_image_path'];
//$this->tag_options['alt'] = $this->error;
} else {
$src = $this->options['display_path'] . '/' . substr($this->cache_filename, strrpos($this->cache_filename, DS) + 1, strlen($this->cache_filename));
}
$img_tag = '<img src="' . $src . '"';
if(isset($this->options['w'])) {
$img_tag .= ' width="' . $this->options['w'] . '"';
}
if(isset($this->options['h'])) {
$img_tag .= ' height="' . $this->options['h'] . '"';
}
if(isset($this->options['alt'])) {
$img_tag .= ' alt="' . $this->options['alt'] . '"';
}
foreach($this->tag_options as $key => $value) {
$img_tag .= ' ' . $key . '="' . $value . '"';
}
$img_tag .= ' />';
return $img_tag;
}
|
Create image tag based on the current conf.
|
get_image_tag
|
php
|
Datawalke/Coordino
|
app/views/helpers/thumbnail.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/thumbnail.php
|
MIT
|
function draw($type = null, $params = array()) {
if($type != null) {
switch($type) {
case 'picker':
$this->__picker($params);
break;
case 'pickerWithName':
$this->__pickerWithName($params);
break;
}
} else {
switch($this->defaultType) {
case 'picker':
$this->__picker($params);
break;
case 'pickerWithName':
$this->__pickerWithName($params);
break;
}
}
}
|
This method can be called using from a view to print a Tricky Element to the
page. This method accepts a custom type, that must be included in the $this->types
array. If the element is not found, an error will be displayed.
@param $type the type of tricky element to print
@param $params the options array that affects the element's attributes
|
draw
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __picker($params = array()) {
if(!$this->__startup('picker', $params)) {
return;
}
if($this->options['form'] != false) { ?>
<?php $this->__htmlForm(); ?>
<?php $this->__htmlDiv(); ?>
<?php $this->__htmlInput(); ?>
<?php $this->__htmlImage(); ?>
<?php $this->__htmlEndTag('div'); ?>
<?php $this->__htmlEndTag('form'); ?>
<?php } else { ?>
<?php $this->__htmlDiv(); ?>
<?php $this->__htmlInput(); ?>
<?php $this->__htmlImage(); ?>
<?php $this->__htmlEndTag('div'); ?>
<?php }
}
|
Called from the draw() function based on the $type parameter to draw
a file picking button without any other elements.
|
__picker
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __pickerWithName($params = array()) {
if(!$this->__startup('pickerWithName', $params)) {
return;
}
if($this->options['form'] != false) {
$this->__htmlForm();
$this->__htmlDiv();
$this->__htmlInput();
$this->__htmlImage();
$this->__htmlEndTag('div');
$this->__htmlName();
$this->__htmlEndTag('form');
} else {
$this->__htmlDiv();
$this->__htmlInput();
$this->__htmlImage();
$this->__htmlEndTag('div');
}
$this->__javascriptNameChange();
}
|
Called from the draw() function based on the $type parameter to draw
a file picking button with a disabled text field to show the name of the file.
|
__pickerWithName
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __displayAutosubmit() { ?>
<form
enctype="multipart/form-data"
action="<?=$this->options['form']['action']?>"
id="<?=$this->options['form']['id']?>"
name="<?=$this->options['form']['name']?>"
method="<?=$this->options['form']['method']?>"
>
<div class="<?=$this->errorStyles['div']?>">
<input
type="file"
id="<?=$this->options['input']['id']?>"
name="<?=$this->options['input']['name']?>"
class="<?=$this->errorStyles['input']?>"
onchange="document.<?=$this->options['form']['name']?>.submit();"
/>
</div>
</form>
<?php }
|
Displays a regular file element if the program fails with errors and is requested.
|
__displayAutosubmit
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __displayRegular() { ?>
<div class="<?=$this->errorStyles['div']?>">
<input
type="file"
id="<?=$this->options['input']['id']?>"
name="<?=$this->options['input']['name']?>"
class="<?=$this->errorStyles['input']?>"
onchange="<?=$this->options['input']['submitOnChange']?>"
/>
</div>
<?php }
|
Displays a regular file element if the program fails with errors and is requested.
|
__displayRegular
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __incrementDefaultOptionIds() {
if($this->options['form']['name'] == $this->defaultOptions['form']['name']) {
$this->options['form']['name'] = $this->defaultOptions['form']['name'] . '_' . $this->runs;
} if($this->options['form']['id'] == $this->defaultOptions['form']['id']) {
$this->options['form']['id'] = $this->defaultOptions['form']['id'] . '_' . $this->runs;
}
if($this->options['input']['name'] == $this->defaultOptions['input']['name']) {
$this->options['input']['name'] = $this->defaultOptions['input']['name'] . '_' . $this->runs;
} if($this->options['input']['id'] == $this->defaultOptions['input']['id']) {
$this->options['input']['id'] = $this->defaultOptions['input']['id'] . '_' . $this->runs;
}
if($this->options['name']['name'] == $this->defaultOptions['name']['name']) {
$this->options['name']['name'] = $this->defaultOptions['name']['name'] . '_' . $this->runs;
} if($this->options['name']['id'] == $this->defaultOptions['name']['id']) {
$this->options['name']['id'] = $this->defaultOptions['name']['id'] . '_' . $this->runs;
}
}
|
Increments the default values to prevent overwriting
|
__incrementDefaultOptionIds
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __startup($type, $params) {
$this->__resetElementOptions();
$this->__getErrors($type, $params);
if(!empty($this->errors)) {
if($this->debug == 'yes') {
$this->__printErrors();
}
if($this->displayOnFail == 'regular') {
$this->__displayRegular();
} else if($this->displayOnFail == 'autosubmit') {
$this->__displayAutosubmit();
}
return false;
}
$this->runs++;
$this->__setOptions($params);
$this->__incrementDefaultOptionIds();
return true;
}
|
Called from the drawing functions to initiate the components.
|
__startup
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __resetElementOptions() {
$this->options = $this->defaultOptions;
}
|
This method resets the options for the next field to be drawn.
|
__resetElementOptions
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __getErrors($type, $params) {
if((!isset($params['form']) || $params['form'] == false) && (isset($params['input']['submitOnChange']) && $params['input']['submitOnChange'])) {
$this->errors[] = '<b>Squawk!</b> You cannot autosubmit this element if form is turned off.';
}
if(isset($params['form']['method']) && !($params['form']['method'] == 'post' || $params['form']['method'] == 'get')) {
$this->errors[] = '<b>Sqwawk!</b> Invalid method type (optional: get or post)!';
}
if($type == 'pickerWithName' && isset($params['input']['submitOnChange']) && $params['input']['submitOnChange']) {
$this->errors[] = '<b>Squawk!</b> You cannot autosubmit an element with a name input field';
}
if($type == 'pickerWithName' && $params['form'] !== false) {
$this->errors[] = '<b>Squawk!</b> You cannot create a pickerWithName with a form wrapper! You have to create your own submit.';
}
}
|
This method finds any errors, and set the errors array with them.
|
__getErrors
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __setOptions($params) {
if(!isset($params) && empty($params)) {
return;
}
/* set form elements */
if(isset($params['form']) && $params['form'] !== false) {
if(isset($params['form']['id'])) { $this->options['form']['id'] = $params['form']['id']; }
if(isset($params['form']['name'])) { $this->options['form']['name'] = $params['form']['name']; }
if(isset($params['form']['method'])) { $this->options['form']['method'] = $params['form']['method']; }
if(isset($params['form']['action'])) { $this->options['form']['action'] = $params['form']['action']; }
} else {
$this->options['form'] = false;
}
/* set input elements */
if(isset($params['input'])) {
if(isset($params['input']['id'])) { $this->options['input']['id'] = $params['input']['id']; }
if(isset($params['input']['name'])) { $this->options['input']['name'] = $params['input']['name']; }
if(isset($params['input']['submitOnChange']) && $params['input']['submitOnChange']) {
$this->options['input']['submitOnChange'] = 'document.' . $this->options['form']['name'] . '.submit();';
}
}
/* set name elements */
if(isset($params['name'])) {
if(isset($params['name']['id'])) { $this->options['name']['id'] = $params['name']['id']; }
if(isset($params['name']['name'])) { $this->options['name']['name'] = $params['name']['name']; }
}
/* set styles elements */
if(isset($params['styles'])) {
if(isset($params['styles']['div'])) { $this->styles['div'] = $params['styles']['div']; }
if(isset($params['styles']['input'])) { $this->styles['input'] = $params['styles']['input']; }
if(isset($params['styles']['image'])) { $this->styles['image'] = $params['styles']['image']; }
if(isset($params['styles']['name'])) { $this->styles['name'] = $params['styles']['name']; }
}
/* set the image */
if(isset($params['image'])) { $this->options['image'] = $params['image']; }
}
|
This method accepts the parameters passed into this helper,
in preparation for printing the element.
|
__setOptions
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __htmlEndTag($tagName = null) {
echo '</' . $tagName . '>';
}
|
Creates an HTML ending tag based on a tagName
|
__htmlEndTag
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __htmlDiv() { ?>
<div class="<?=$this->styles['div']?>">
<?php }
|
Creates a tricky input html div wrapper
|
__htmlDiv
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __htmlInput() { ?>
<input
type="file"
id="<?=$this->options['input']['id']?>"
name="<?=$this->options['input']['name']?>"
class="<?=$this->styles['input']?>"
onchange="<?=$this->options['input']['submitOnChange']?>"
/>
<?php }
|
Creates a tricky input html file input field
|
__htmlInput
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __htmlInputForName() { ?>
<input
type="file"
id="<?=$this->options['input']['id']?>"
name="<?=$this->options['input']['name']?>"
class="<?=$this->styles['input']?>"
onchange="<?=$this->options['input']['submitOnChange']?>"
/>
<?php }
|
Creates a tricky input html file input field
|
__htmlInputForName
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function __htmlName() { ?>
<span
id="<?=$this->options['name']['id']?>"
class="<?=$this->styles['name']?>"
></span>
<?php }
|
Creates a tricky input html name text field
|
__htmlName
|
php
|
Datawalke/Coordino
|
app/views/helpers/tricky_file_input.php
|
https://github.com/Datawalke/Coordino/blob/master/app/views/helpers/tricky_file_input.php
|
MIT
|
function make_clean_css($path, $name) {
App::import('Vendor', 'csspp' . DS . 'csspp');
$data = file_get_contents($path);
$csspp = new csspp();
$output = $csspp->compress($data);
$ratio = 100 - (round(strlen($output) / strlen($data), 3) * 100);
$output = " /* file: $name, ratio: $ratio% */ " . $output;
return $output;
}
|
Enter description here...
@param unknown_type $path
@param unknown_type $name
@return unknown
|
make_clean_css
|
php
|
Datawalke/Coordino
|
app/webroot/css.php
|
https://github.com/Datawalke/Coordino/blob/master/app/webroot/css.php
|
MIT
|
function write_css_cache($path, $content) {
if (!is_dir(dirname($path))) {
mkdir(dirname($path));
}
$cache = new File($path);
return $cache->write($content);
}
|
Enter description here...
@param unknown_type $path
@param unknown_type $content
@return unknown
|
write_css_cache
|
php
|
Datawalke/Coordino
|
app/webroot/css.php
|
https://github.com/Datawalke/Coordino/blob/master/app/webroot/css.php
|
MIT
|
function config() {
$args = func_get_args();
foreach ($args as $arg) {
if ($arg === 'database' && file_exists(CONFIGS . 'database.php')) {
include_once(CONFIGS . $arg . '.php');
} elseif (file_exists(CONFIGS . $arg . '.php')) {
include_once(CONFIGS . $arg . '.php');
if (count($args) == 1) {
return true;
}
} else {
if (count($args) == 1) {
return false;
}
}
}
return true;
}
|
Loads configuration files. Receives a set of configuration files
to load.
Example:
`config('config1', 'config2');`
@return boolean Success
@link http://book.cakephp.org/view/1125/config
|
config
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function uses() {
$args = func_get_args();
foreach ($args as $file) {
require_once(LIBS . strtolower($file) . '.php');
}
}
|
Loads component/components from LIBS. Takes optional number of parameters.
Example:
`uses('flay', 'time');`
@param string $name Filename without the .php part
@deprecated Will be removed in 2.0
@link http://book.cakephp.org/view/1140/uses
|
uses
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function debug($var = false, $showHtml = false, $showFrom = true) {
if (Configure::read() > 0) {
if ($showFrom) {
$calledFrom = debug_backtrace();
echo '<strong>' . substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) . '</strong>';
echo ' (line <strong>' . $calledFrom[0]['line'] . '</strong>)';
}
echo "\n<pre class=\"cake-debug\">\n";
$var = print_r($var, true);
if ($showHtml) {
$var = str_replace('<', '<', str_replace('>', '>', $var));
}
echo $var . "\n</pre>\n";
}
}
|
Prints out debug information about given variable.
Only runs if debug level is greater than zero.
@param boolean $var Variable to show debug information for.
@param boolean $showHtml If set to true, the method prints the debug data in a screen-friendly way.
@param boolean $showFrom If set to true, the method prints from where the function was called.
@link http://book.cakephp.org/view/1190/Basic-Debugging
@link http://book.cakephp.org/view/1128/debug
|
debug
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function getMicrotime() {
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
|
Returns microtime for execution time checking
@return float Microtime
|
getMicrotime
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
if (!is_array($array)) {
return null;
}
foreach ($array as $key => $val) {
$sa[$key] = $val[$sortby];
}
if ($order == 'asc') {
asort($sa, $type);
} else {
arsort($sa, $type);
}
foreach ($sa as $key => $val) {
$out[] = $array[$key];
}
return $out;
}
|
Sorts given $array by key $sortby.
@param array $array Array to sort
@param string $sortby Sort by this key
@param string $order Sort order asc/desc (ascending or descending).
@param integer $type Type of sorting to perform
@return mixed Sorted array
|
sortByKey
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function array_combine($a1, $a2) {
$a1 = array_values($a1);
$a2 = array_values($a2);
$c1 = count($a1);
$c2 = count($a2);
if ($c1 != $c2) {
return false;
}
if ($c1 <= 0) {
return false;
}
$output = array();
for ($i = 0; $i < $c1; $i++) {
$output[$a1[$i]] = $a2[$i];
}
return $output;
}
|
Combines given identical arrays by using the first array's values as keys,
and the second one's values as values. (Implemented for backwards compatibility with PHP4)
@param array $a1 Array to use for keys
@param array $a2 Array to use for values
@return mixed Outputs either combined array or false.
@deprecated Will be removed in 2.0
|
array_combine
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function h($text, $charset = null) {
if (is_array($text)) {
return array_map('h', $text);
}
static $defaultCharset = false;
if ($defaultCharset === false) {
$defaultCharset = Configure::read('App.encoding');
if ($defaultCharset === null) {
$defaultCharset = 'UTF-8';
}
}
if ($charset) {
return htmlspecialchars($text, ENT_QUOTES, $charset);
} else {
return htmlspecialchars($text, ENT_QUOTES, $defaultCharset);
}
}
|
Convenience method for htmlspecialchars.
@param string $text Text to wrap through htmlspecialchars
@param string $charset Character set to use when escaping. Defaults to config value in 'App.encoding' or 'UTF-8'
@return string Wrapped text
@link http://book.cakephp.org/view/1132/h
|
h
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.