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
public function testParseIconsFilter() { $this->assertEquals( '<span class="glyphicon glyphicon-heart"></span> foobar', $this->getIconExtension('glyphicon')->parseIconsFilter('.icon-heart foobar'), '->parseIconsFilter() returns the HTML code with the replaced icons.' ); $this->assertEquals( '<span class="fa fa-heart"></span> foobar', $this->getIconExtension('fa')->parseIconsFilter('.icon-heart foobar'), '->parseIconsFilter() uses the iconPrefix passed into the IconExtension constructor.' ); }
@covers Braincrafted\Bundle\BootstrapBundle\Twig\BootstrapIconExtension::parseIconsFilter
testParseIconsFilter
php
braincrafted/bootstrap-bundle
Tests/Twig/BootstrapIconExtensionTest.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Tests/Twig/BootstrapIconExtensionTest.php
MIT
public function testParseIconsFilterWithDifferntPrefix() { $this->assertEquals( '<span class="glyphicon glyphicon-heart"></span> foobar', $this->getIconExtension('default')->parseIconsFilter('.glyphicon-heart foobar'), '->parseIconsFilter() returns the HTML code with the replaced icons.' ); $this->assertEquals( '<span class="fa fa-heart"></span> foobar', $this->getIconExtension('default')->parseIconsFilter('.fa-heart foobar'), '->parseIconsFilter() uses the iconPrefix passed into the IconExtension constructor.' ); }
@covers Braincrafted\Bundle\BootstrapBundle\Twig\BootstrapIconExtension::parseIconsFilter
testParseIconsFilterWithDifferntPrefix
php
braincrafted/bootstrap-bundle
Tests/Twig/BootstrapIconExtensionTest.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Tests/Twig/BootstrapIconExtensionTest.php
MIT
public function testGetName() { $this->assertEquals('braincrafted_bootstrap_icon', $this->getIconExtension()->getName()); }
@covers Braincrafted\Bundle\BootstrapBundle\Twig\BootstrapIconExtension::getName()
testGetName
php
braincrafted/bootstrap-bundle
Tests/Twig/BootstrapIconExtensionTest.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Tests/Twig/BootstrapIconExtensionTest.php
MIT
public function testGetFunctions() { $this->assertCount(6, $this->extension->getFunctions()); }
@covers Braincrafted\Bundle\BootstrapBundle\Twig\BootstrapLabelExtension::getFunctions()
testGetFunctions
php
braincrafted/bootstrap-bundle
Tests/Twig/BootstrapLabelExtensionTest.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Tests/Twig/BootstrapLabelExtensionTest.php
MIT
public function testLabelFunction() { $this->assertEquals( '<span class="label label-default">Hello World</span>', $this->extension->labelFunction('Hello World'), '->labelFunction() returns the HTML code for the given label.' ); $this->assertEquals( '<span class="label label-success">Hello World</span>', $this->extension->labelFunction('Hello World', 'success'), '->labelFunction() returns the HTML code for the given success label.' ); }
@covers Braincrafted\Bundle\BootstrapBundle\Twig\BootstrapLabelExtension::labelFunction
testLabelFunction
php
braincrafted/bootstrap-bundle
Tests/Twig/BootstrapLabelExtensionTest.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Tests/Twig/BootstrapLabelExtensionTest.php
MIT
public function testLabelSuccessFunction() { $this->assertEquals( '<span class="label label-success">Foobar</span>', $this->extension->labelSuccessFunction('Foobar') ); }
@covers Braincrafted\Bundle\BootstrapBundle\Twig\BootstrapLabelExtension::labelSuccessFunction
testLabelSuccessFunction
php
braincrafted/bootstrap-bundle
Tests/Twig/BootstrapLabelExtensionTest.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Tests/Twig/BootstrapLabelExtensionTest.php
MIT
public function testLabelWarningFunction() { $this->assertEquals( '<span class="label label-warning">Foobar</span>', $this->extension->labelWarningFunction('Foobar') ); }
@covers Braincrafted\Bundle\BootstrapBundle\Twig\BootstrapLabelExtension::labelWarningFunction
testLabelWarningFunction
php
braincrafted/bootstrap-bundle
Tests/Twig/BootstrapLabelExtensionTest.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Tests/Twig/BootstrapLabelExtensionTest.php
MIT
public function testLabelDangerFunction() { $this->assertEquals( '<span class="label label-danger">Foobar</span>', $this->extension->labelDangerFunction('Foobar') ); }
@covers Braincrafted\Bundle\BootstrapBundle\Twig\BootstrapLabelExtension::labelDangerFunction
testLabelDangerFunction
php
braincrafted/bootstrap-bundle
Tests/Twig/BootstrapLabelExtensionTest.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Tests/Twig/BootstrapLabelExtensionTest.php
MIT
public function testLabelInfoFunction() { $this->assertEquals( '<span class="label label-info">Foobar</span>', $this->extension->labelInfoFunction('Foobar') ); }
@covers Braincrafted\Bundle\BootstrapBundle\Twig\BootstrapLabelExtension::labelInfoFunction
testLabelInfoFunction
php
braincrafted/bootstrap-bundle
Tests/Twig/BootstrapLabelExtensionTest.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Tests/Twig/BootstrapLabelExtensionTest.php
MIT
public function testLabelPrimaryFunction() { $this->assertEquals( '<span class="label label-primary">Foobar</span>', $this->extension->labelPrimaryFunction('Foobar') ); }
@covers Braincrafted\Bundle\BootstrapBundle\Twig\BootstrapLabelExtension::labelPrimaryFunction
testLabelPrimaryFunction
php
braincrafted/bootstrap-bundle
Tests/Twig/BootstrapLabelExtensionTest.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Tests/Twig/BootstrapLabelExtensionTest.php
MIT
public function testGetName() { $this->assertEquals('braincrafted_bootstrap_label', $this->extension->getName()); }
@covers Braincrafted\Bundle\BootstrapBundle\Twig\BootstrapLabelExtension::getName()
testGetName
php
braincrafted/bootstrap-bundle
Tests/Twig/BootstrapLabelExtensionTest.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Tests/Twig/BootstrapLabelExtensionTest.php
MIT
public function testGetRelativePath($expected, $from, $to) { $this->assertEquals($expected, $this->util->getRelativePath($from, $to)); }
@param $expected string @param $from string @param $to string @covers Braincrafted\Bundle\BootstrapBundle\Util\PathUtil::getRelativePath() @dataProvider relativePathProvider
testGetRelativePath
php
braincrafted/bootstrap-bundle
Tests/Util/PathUtilTest.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Tests/Util/PathUtilTest.php
MIT
public function badgeFunction($text) { return sprintf('<span class="badge">%s</span>', $text); }
Returns the HTML code for a badge. @param string $text The text of the badge @return string The HTML code of the badge
badgeFunction
php
braincrafted/bootstrap-bundle
Twig/BootstrapBadgeExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapBadgeExtension.php
MIT
public function setStyle($style) { $this->style = $style; }
Sets the style. @param string $style Name of the style
setStyle
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function getStyle() { return $this->style; }
Returns the style. @return string Name of the style
getStyle
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function setColSize($colSize) { $this->colSize = $colSize; }
Sets the column size. @param string $colSize Column size (xs, sm, md or lg)
setColSize
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function getColSize() { return $this->colSize; }
Returns the column size. @return string Column size (xs, sm, md or lg)
getColSize
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function setWidgetCol($widgetCol) { $this->widgetCol = $widgetCol; }
Sets the number of columns of widgets. @param integer $widgetCol Number of columns.
setWidgetCol
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function getWidgetCol() { return $this->widgetCol; }
Returns the number of columns of widgets. @return integer Number of columns.Class
getWidgetCol
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function setLabelCol($labelCol) { $this->labelCol = $labelCol; }
Sets the number of columns of labels. @param integer $labelCol Number of columns.
setLabelCol
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function getLabelCol() { return $this->labelCol; }
Returns the number of columns of labels. @return integer Number of columns.
getLabelCol
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function setSimpleCol($simpleCol) { $this->simpleCol = $simpleCol; }
Sets the number of columns of simple widgets. @param integer $simpleCol Number of columns.
setSimpleCol
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function getSimpleCol() { return $this->simpleCol; }
Returns the number of columns of simple widgets. @return integer Number of columns.
getSimpleCol
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function backupFormSettings() { $settings = array( 'style' => $this->style, 'colSize' => $this->colSize, 'widgetCol' => $this->widgetCol, 'labelCol' => $this->labelCol, 'simpleCol' => $this->simpleCol, ); array_push($this->settingsStack, $settings); }
Backup the form settings to the stack. @internal Should only be used at the beginning of form_start. This allows a nested subform to change its settings without affecting its parent form.
backupFormSettings
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function restoreFormSettings() { if (count($this->settingsStack) < 1) { return; } $settings = array_pop($this->settingsStack); $this->style = $settings['style']; $this->colSize = $settings['colSize']; $this->widgetCol = $settings['widgetCol']; $this->labelCol = $settings['labelCol']; $this->simpleCol = $settings['simpleCol']; }
Restore the form settings from the stack. @internal Should only be used at the end of form_end. @see backupFormSettings
restoreFormSettings
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function formControlStaticFunction($label, $value) { return sprintf( '<div class="form-group"><label class="col-sm-%s control-label">%s</label><div class="col-sm-%s"><p class="form-control-static">%s</p></div></div>', $this->getLabelCol(), $label, $this->getWidgetCol(), $value ); }
@param string $label @param string $value @return string
formControlStaticFunction
php
braincrafted/bootstrap-bundle
Twig/BootstrapFormExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapFormExtension.php
MIT
public function __construct($iconPrefix, $iconTag = 'span') { $this->iconPrefix = $iconPrefix; $this->iconTag = $iconTag; }
@param string $iconPrefix @param string $iconTag
__construct
php
braincrafted/bootstrap-bundle
Twig/BootstrapIconExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapIconExtension.php
MIT
public function parseIconsFilter($text) { $that = $this; return preg_replace_callback( '/\.([a-z]+)-([a-z0-9+-]+)/', function ($matches) use ($that) { return $that->iconFunction($matches[2], $matches[1]); }, $text ); }
Parses the given string and replaces all occurrences of .icon-[name] with the corresponding icon. @param string $text The text to parse @return string The HTML code with the icons
parseIconsFilter
php
braincrafted/bootstrap-bundle
Twig/BootstrapIconExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapIconExtension.php
MIT
public function iconFunction($icon, $iconSet = 'icon') { if ($iconSet == 'icon') $iconSet = $this->iconPrefix; $icon = str_replace('+', ' '.$iconSet.'-', $icon); return sprintf('<%1$s class="%2$s %2$s-%3$s"></%1$s>', $this->iconTag, $iconSet, $icon); }
Returns the HTML code for the given icon. @param string $icon The name of the icon @param string $iconSet The icon-set name @return string The HTML code for the icon
iconFunction
php
braincrafted/bootstrap-bundle
Twig/BootstrapIconExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapIconExtension.php
MIT
public function labelFunction($text, $type = 'default') { return sprintf('<span class="label%s">%s</span>', ($type ? ' label-' . $type : ''), $text); }
Returns the HTML code for a label. @param string $text The text of the label @param string $type The type of label @return string The HTML code of the label
labelFunction
php
braincrafted/bootstrap-bundle
Twig/BootstrapLabelExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapLabelExtension.php
MIT
public function labelSuccessFunction($text) { return $this->labelFunction($text, 'success'); }
Returns the HTML code for a success label. @param string $text The text of the label @return string The HTML code of the label
labelSuccessFunction
php
braincrafted/bootstrap-bundle
Twig/BootstrapLabelExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapLabelExtension.php
MIT
public function labelWarningFunction($text) { return $this->labelFunction($text, 'warning'); }
Returns the HTML code for a warning label. @param string $text The text of the label @return string The HTML code of the label
labelWarningFunction
php
braincrafted/bootstrap-bundle
Twig/BootstrapLabelExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapLabelExtension.php
MIT
public function labelDangerFunction($text) { return $this->labelFunction($text, 'danger'); }
Returns the HTML code for a important label. @param string $text The text of the label @return string The HTML code of the label
labelDangerFunction
php
braincrafted/bootstrap-bundle
Twig/BootstrapLabelExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapLabelExtension.php
MIT
public function labelInfoFunction($text) { return $this->labelFunction($text, 'info'); }
Returns the HTML code for a info label. @param string $text The text of the label @return string The HTML code of the label
labelInfoFunction
php
braincrafted/bootstrap-bundle
Twig/BootstrapLabelExtension.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Twig/BootstrapLabelExtension.php
MIT
public function getRelativePath($from, $to) { // some compatibility fixes for Windows paths $from = is_dir($from) ? rtrim($from, '\/') . '/' : $from; $to = is_dir($to) ? rtrim($to, '\/') . '/' : $to; $from = str_replace('\\', '/', $from); $to = str_replace('\\', '/', $to); $from = explode('/', $from); $to = explode('/', $to); $relPath = $to; foreach ($from as $depth => $dir) { // find first non-matching dir if ($dir === $to[$depth]) { // ignore this directory array_shift($relPath); } else { // get number of remaining dirs to $from $remaining = count($from) - $depth; if ($remaining > 1) { // add traversals up to first matching dir $padLength = (count($relPath) + $remaining - 1) * -1; $relPath = array_pad($relPath, $padLength, '..'); break; } else { $relPath[0] = './' . $relPath[0]; } } } return implode('/', $relPath); }
Returns the relative path $from to $to. @param string $from @param string $to @return string @link http://stackoverflow.com/a/2638272/776654
getRelativePath
php
braincrafted/bootstrap-bundle
Util/PathUtil.php
https://github.com/braincrafted/bootstrap-bundle/blob/master/Util/PathUtil.php
MIT
public function underScrutiny() { foreach ($this->examinators as $gaze) { if (getenv($gaze)) { return true; } } return false; }
Where the magic occurs. @return bool
underScrutiny
php
hugues-m/phpunit-vw
src/HMLB/VW/SecretSoftware.php
https://github.com/hugues-m/phpunit-vw/blob/master/src/HMLB/VW/SecretSoftware.php
MIT
public function force(PHPUnit_Framework_TestCase $test) { if (!$test->hasFailed()) { return; } $testReflection = new ReflectionClass('PHPUnit_Framework_TestCase'); $resultReflection = new ReflectionClass('PHPUnit_Framework_TestResult'); $result = $this->getPropertyValue($testReflection, 'result', $test); $this ->forcePropertyValue($resultReflection, 'errors', array(), $result) ->forcePropertyValue($resultReflection, 'failures', array(), $result) ->forcePropertyValue($resultReflection, 'risky', array(), $result) ->forcePropertyValue($testReflection, 'status', PHPUnit_Runner_BaseTestRunner::STATUS_PASSED, $test) ->forcePropertyValue($testReflection, 'statusMessage', '', $test); }
Failing test cases are not a problem anymore. @param PHPUnit_Framework_TestCase $test
force
php
hugues-m/phpunit-vw
src/HMLB/VW/SecretSoftware.php
https://github.com/hugues-m/phpunit-vw/blob/master/src/HMLB/VW/SecretSoftware.php
MIT
private function forcePropertyValue(ReflectionClass $reflection, $property, $value, $object) { $propertyReflection = $this->accessProperty($reflection, $property); $propertyReflection->setValue($object, $value); $propertyReflection->setAccessible(false); return $this; }
@param ReflectionClass $reflection @param string $property @param mixed $value @param mixed $object @return self
forcePropertyValue
php
hugues-m/phpunit-vw
src/HMLB/VW/SecretSoftware.php
https://github.com/hugues-m/phpunit-vw/blob/master/src/HMLB/VW/SecretSoftware.php
MIT
private function getPropertyValue(ReflectionClass $reflection, $property, $object) { $propertyReflection = $this->accessProperty($reflection, $property); $value = $propertyReflection->getValue($object); $propertyReflection->setAccessible(false); return $value; }
@param ReflectionClass $reflection @param string $property @param mixed $object @return mixed
getPropertyValue
php
hugues-m/phpunit-vw
src/HMLB/VW/SecretSoftware.php
https://github.com/hugues-m/phpunit-vw/blob/master/src/HMLB/VW/SecretSoftware.php
MIT
private function accessProperty(ReflectionClass $reflection, $property) { $propertyReflection = $reflection->getProperty($property); $propertyReflection->setAccessible(true); return $propertyReflection; }
@param ReflectionClass $reflection @param string $property @return ReflectionProperty
accessProperty
php
hugues-m/phpunit-vw
src/HMLB/VW/SecretSoftware.php
https://github.com/hugues-m/phpunit-vw/blob/master/src/HMLB/VW/SecretSoftware.php
MIT
public static function putAlignmentMarker(array &$frame, $ox, $oy) { $finder = array( "\xa1\xa1\xa1\xa1\xa1", "\xa1\xa0\xa0\xa0\xa1", "\xa1\xa0\xa1\xa0\xa1", "\xa1\xa0\xa0\xa0\xa1", "\xa1\xa1\xa1\xa1\xa1" ); $yStart = $oy-2; $xStart = $ox-2; for($y=0; $y<5; $y++) { QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]); } }
-------------------------------------------------------------------- Put an alignment marker. @param frame @param width @param ox,oy center coordinate of the pattern
putAlignmentMarker
php
wizwizdev/wizwizxui-timebot
phpqrcode/phpqrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/phpqrcode.php
MIT
public static function putFinderPattern(&$frame, $ox, $oy) { $finder = array( "\xc1\xc1\xc1\xc1\xc1\xc1\xc1", "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" ); for($y=0; $y<7; $y++) { QRstr::set($frame, $ox, $oy+$y, $finder[$y]); } }
-------------------------------------------------------------------- Put a finder pattern. @param frame @param width @param ox,oy upper-left coordinate of the pattern
putFinderPattern
php
wizwizdev/wizwizxui-timebot
phpqrcode/phpqrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/phpqrcode.php
MIT
public static function putAlignmentMarker(array &$frame, $ox, $oy) { $finder = array( "\xa1\xa1\xa1\xa1\xa1", "\xa1\xa0\xa0\xa0\xa1", "\xa1\xa0\xa1\xa0\xa1", "\xa1\xa0\xa0\xa0\xa1", "\xa1\xa1\xa1\xa1\xa1" ); $yStart = $oy-2; $xStart = $ox-2; for($y=0; $y<5; $y++) { QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]); } }
-------------------------------------------------------------------- Put an alignment marker. @param frame @param width @param ox,oy center coordinate of the pattern
putAlignmentMarker
php
wizwizdev/wizwizxui-timebot
phpqrcode/qrspec.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/qrspec.php
MIT
public static function putFinderPattern(&$frame, $ox, $oy) { $finder = array( "\xc1\xc1\xc1\xc1\xc1\xc1\xc1", "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" ); for($y=0; $y<7; $y++) { QRstr::set($frame, $ox, $oy+$y, $finder[$y]); } }
-------------------------------------------------------------------- Put a finder pattern. @param frame @param width @param ox,oy upper-left coordinate of the pattern
putFinderPattern
php
wizwizdev/wizwizxui-timebot
phpqrcode/qrspec.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/qrspec.php
MIT
function str_split($string, $split_length=1) { if ((strlen($string) > $split_length) OR (!$split_length)) { do { $c = strlen($string); $parts[] = substr($string, 0, $split_length); $string = substr($string, $split_length); } while ($string !== false); } else { $parts = array($string); } return $parts; }
Convert a string to an array (needed for PHP4 compatibility) @param string $string The input string. @param int $split_length Maximum length of the chunk. @return If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element.
str_split
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
public function __construct($code, $eclevel = 'L') { $barcode_array = array(); if ((is_null($code)) OR ($code == '\0') OR ($code == '')) { return false; } // set error correction level $this->level = array_search($eclevel, array('L', 'M', 'Q', 'H')); if ($this->level === false) { $this->level = QR_ECLEVEL_L; } if (($this->hint != QR_MODE_8B) AND ($this->hint != QR_MODE_KJ)) { return false; } if (($this->version < 0) OR ($this->version > QRSPEC_VERSION_MAX)) { return false; } $this->items = array(); $this->encodeString($code); $qrTab = $this->binarize($this->data); $size = count($qrTab); $barcode_array['num_rows'] = $size; $barcode_array['num_cols'] = $size; $barcode_array['bcode'] = array(); foreach ($qrTab as $line) { $arrAdd = array(); foreach (str_split($line) as $char) { $arrAdd[] = ($char=='1')?1:0; } $barcode_array['bcode'][] = $arrAdd; } $this->barcode_array = $barcode_array; }
This is the class constructor. Creates a QRcode object @param string $code code to represent using QRcode @param string $eclevel error level: <ul><li>L : About 7% or less errors can be corrected.</li><li>M : About 15% or less errors can be corrected.</li><li>Q : About 25% or less errors can be corrected.</li><li>H : About 30% or less errors can be corrected.</li></ul> @access public @since 1.0.000
__construct
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
public function getBarcodeArray() { return $this->barcode_array; }
Returns a barcode array which is readable by TCPDF @return array barcode array readable by TCPDF; @access public
getBarcodeArray
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function binarize($frame) { $len = count($frame); // the frame is square (width = height) foreach ($frame as &$frameLine) { for ($i=0; $i<$len; $i++) { $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; } } return $frame; }
Convert the frame in binary form @param array $frame array to binarize @return array frame in binary form
binarize
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function encodeString($string) { $this->dataStr = $string; if (!$this->casesensitive) { $this->toUpper(); } $ret = $this->splitString(); if ($ret < 0) { return NULL; } $this->encodeMask(-1); }
Encode the input string to QR code @param string $string input string to encode
encodeString
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function encodeMask($mask) { $spec = array(0, 0, 0, 0, 0); $this->datacode = $this->getByteStream($this->items); if (is_null($this->datacode)) { return NULL; } $spec = $this->getEccSpec($this->version, $this->level, $spec); $this->b1 = $this->rsBlockNum1($spec); $this->dataLength = $this->rsDataLength($spec); $this->eccLength = $this->rsEccLength($spec); $this->ecccode = array_fill(0, $this->eccLength, 0); $this->blocks = $this->rsBlockNum($spec); $ret = $this->init($spec); if ($ret < 0) { return NULL; } $this->count = 0; $this->width = $this->getWidth($this->version); $this->frame = $this->newFrame($this->version); $this->x = $this->width - 1; $this->y = $this->width - 1; $this->dir = -1; $this->bit = -1; // inteleaved data and ecc codes for ($i=0; $i < ($this->dataLength + $this->eccLength); $i++) { $code = $this->getCode(); $bit = 0x80; for ($j=0; $j<8; $j++) { $addr = $this->getNextPosition(); $this->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); $bit = $bit >> 1; } } // remainder bits $j = $this->getRemainder($this->version); for ($i=0; $i<$j; $i++) { $addr = $this->getNextPosition(); $this->setFrameAt($addr, 0x02); } // masking $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); if ($mask < 0) { if (QR_FIND_BEST_MASK) { $masked = $this->mask($this->width, $this->frame, $this->level); } else { $masked = $this->makeMask($this->width, $this->frame, (intval(QR_DEFAULT_MASK) % 8), $this->level); } } else { $masked = $this->makeMask($this->width, $this->frame, $mask, $this->level); } if ($masked == NULL) { return NULL; } $this->data = $masked; }
Encode mask @param int $mask masking mode
encodeMask
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function setFrameAt($at, $val) { $this->frame[$at['y']][$at['x']] = chr($val); }
Set frame value at specified position @param array $at x,y position @param int $val value of the character to set
setFrameAt
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function getFrameAt($at) { return ord($this->frame[$at['y']][$at['x']]); }
Get frame value at specified position @param array $at x,y position @return value at specified position
getFrameAt
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function getNextPosition() { do { if ($this->bit == -1) { $this->bit = 0; return array('x'=>$this->x, 'y'=>$this->y); } $x = $this->x; $y = $this->y; $w = $this->width; if ($this->bit == 0) { $x--; $this->bit++; } else { $x++; $y += $this->dir; $this->bit--; } if ($this->dir < 0) { if ($y < 0) { $y = 0; $x -= 2; $this->dir = 1; if ($x == 6) { $x--; $y = 9; } } } else { if ($y == $w) { $y = $w - 1; $x -= 2; $this->dir = -1; if ($x == 6) { $x--; $y -= 8; } } } if (($x < 0) OR ($y < 0)) { return NULL; } $this->x = $x; $this->y = $y; } while(ord($this->frame[$y][$x]) & 0x80); return array('x'=>$x, 'y'=>$y); }
Return the next frame position @return array of x,y coordinates
getNextPosition
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function init($spec) { $dl = $this->rsDataCodes1($spec); $el = $this->rsEccCodes1($spec); $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); $blockNo = 0; $dataPos = 0; $eccPos = 0; $endfor = $this->rsBlockNum1($spec); for ($i=0; $i < $endfor; ++$i) { $ecc = array_slice($this->ecccode, $eccPos); $this->rsblocks[$blockNo] = array(); $this->rsblocks[$blockNo]['dataLength'] = $dl; $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos); $this->rsblocks[$blockNo]['eccLength'] = $el; $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc); $this->rsblocks[$blockNo]['ecc'] = $ecc; $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); $dataPos += $dl; $eccPos += $el; $blockNo++; } if ($this->rsBlockNum2($spec) == 0) { return 0; } $dl = $this->rsDataCodes2($spec); $el = $this->rsEccCodes2($spec); $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); if ($rs == NULL) { return -1; } $endfor = $this->rsBlockNum2($spec); for ($i=0; $i < $endfor; ++$i) { $ecc = array_slice($this->ecccode, $eccPos); $this->rsblocks[$blockNo] = array(); $this->rsblocks[$blockNo]['dataLength'] = $dl; $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos); $this->rsblocks[$blockNo]['eccLength'] = $el; $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc); $this->rsblocks[$blockNo]['ecc'] = $ecc; $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); $dataPos += $dl; $eccPos += $el; $blockNo++; } return 0; }
Initialize code. @param array $spec array of ECC specification @return 0 in case of success, -1 in case of error
init
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function getCode() { if ($this->count < $this->dataLength) { $row = $this->count % $this->blocks; $col = $this->count / $this->blocks; if ($col >= $this->rsblocks[0]['dataLength']) { $row += $this->b1; } $ret = $this->rsblocks[$row]['data'][$col]; } elseif ($this->count < $this->dataLength + $this->eccLength) { $row = ($this->count - $this->dataLength) % $this->blocks; $col = ($this->count - $this->dataLength) / $this->blocks; $ret = $this->rsblocks[$row]['ecc'][$col]; } else { return 0; } $this->count++; return $ret; }
Return Reed-Solomon block code. @return array rsblocks
getCode
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function writeFormatInformation($width, &$frame, $mask, $level) { $blacks = 0; $format = $this->getFormatInfo($mask, $level); for ($i=0; $i<8; ++$i) { if ($format & 1) { $blacks += 2; $v = 0x85; } else { $v = 0x84; } $frame[8][$width - 1 - $i] = chr($v); if ($i < 6) { $frame[$i][8] = chr($v); } else { $frame[$i + 1][8] = chr($v); } $format = $format >> 1; } for ($i=0; $i<7; ++$i) { if ($format & 1) { $blacks += 2; $v = 0x85; } else { $v = 0x84; } $frame[$width - 7 + $i][8] = chr($v); if ($i == 0) { $frame[8][7] = chr($v); } else { $frame[8][6 - $i] = chr($v); } $format = $format >> 1; } return $blacks; }
Write Format Information on frame and returns the number of black bits @param int $width frame width @param array $frame frame @param array $mask masking mode @param int $level error correction level @return int blacks
writeFormatInformation
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function mask0($x, $y) { return ($x + $y) & 1; }
mask0 @param int $x X position @param int $y Y position @return int mask
mask0
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function mask1($x, $y) { return ($y & 1); }
mask1 @param int $x X position @param int $y Y position @return int mask
mask1
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function mask2($x, $y) { return ($x % 3); }
mask2 @param int $x X position @param int $y Y position @return int mask
mask2
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function mask3($x, $y) { return ($x + $y) % 3; }
mask3 @param int $x X position @param int $y Y position @return int mask
mask3
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function mask4($x, $y) { return (((int)($y / 2)) + ((int)($x / 3))) & 1; }
mask4 @param int $x X position @param int $y Y position @return int mask
mask4
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function mask5($x, $y) { return (($x * $y) & 1) + ($x * $y) % 3; }
mask5 @param int $x X position @param int $y Y position @return int mask
mask5
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function mask6($x, $y) { return ((($x * $y) & 1) + ($x * $y) % 3) & 1; }
mask6 @param int $x X position @param int $y Y position @return int mask
mask6
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function mask7($x, $y) { return ((($x * $y) % 3) + (($x + $y) & 1)) & 1; }
mask7 @param int $x X position @param int $y Y position @return int mask
mask7
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function generateMaskNo($maskNo, $width, $frame) { $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); for ($y=0; $y<$width; ++$y) { for ($x=0; $x<$width; ++$x) { if (ord($frame[$y][$x]) & 0x80) { $bitMask[$y][$x] = 0; } else { $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); $bitMask[$y][$x] = ($maskFunc == 0)?1:0; } } } return $bitMask; }
Return bitmask @param int $maskNo mask number @param int $width width @param array $frame frame @return array bitmask
generateMaskNo
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false) { $b = 0; $bitMask = array(); $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); if ($maskGenOnly) { return; } $d = $s; for ($y=0; $y<$width; ++$y) { for ($x=0; $x<$width; ++$x) { if ($bitMask[$y][$x] == 1) { $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); } $b += (int)(ord($d[$y][$x]) & 1); } } return $b; }
makeMaskNo @param int $maskNo @param int $width @param int $s @param int $d @param boolean $maskGenOnly @return int b
makeMaskNo
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function makeMask($width, $frame, $maskNo, $level) { $masked = array_fill(0, $width, str_repeat("\0", $width)); $this->makeMaskNo($maskNo, $width, $frame, $masked); $this->writeFormatInformation($width, $masked, $maskNo, $level); return $masked; }
makeMask @param int $width @param array $frame @param int $maskNo @param int $level @return array mask
makeMask
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function calcN1N3($length) { $demerit = 0; for ($i=0; $i<$length; ++$i) { if ($this->runLength[$i] >= 5) { $demerit += (N1 + ($this->runLength[$i] - 5)); } if ($i & 1) { if (($i >= 3) AND ($i < ($length-2)) AND ($this->runLength[$i] % 3 == 0)) { $fact = (int)($this->runLength[$i] / 3); if (($this->runLength[$i-2] == $fact) AND ($this->runLength[$i-1] == $fact) AND ($this->runLength[$i+1] == $fact) AND ($this->runLength[$i+2] == $fact)) { if (($this->runLength[$i-3] < 0) OR ($this->runLength[$i-3] >= (4 * $fact))) { $demerit += N3; } elseif ((($i+3) >= $length) OR ($this->runLength[$i+3] >= (4 * $fact))) { $demerit += N3; } } } } } return $demerit; }
calcN1N3 @param int $length @return int demerit
calcN1N3
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function evaluateSymbol($width, $frame) { $head = 0; $demerit = 0; for ($y=0; $y<$width; ++$y) { $head = 0; $this->runLength[0] = 1; $frameY = $frame[$y]; if ($y > 0) { $frameYM = $frame[$y-1]; } for ($x=0; $x<$width; ++$x) { if (($x > 0) AND ($y > 0)) { $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); if (($b22 | ($w22 ^ 1)) & 1) { $demerit += N2; } } if (($x == 0) AND (ord($frameY[$x]) & 1)) { $this->runLength[0] = -1; $head = 1; $this->runLength[$head] = 1; } elseif ($x > 0) { if ((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { $head++; $this->runLength[$head] = 1; } else { $this->runLength[$head]++; } } } $demerit += $this->calcN1N3($head+1); } for ($x=0; $x<$width; ++$x) { $head = 0; $this->runLength[0] = 1; for ($y=0; $y<$width; ++$y) { if (($y == 0) AND (ord($frame[$y][$x]) & 1)) { $this->runLength[0] = -1; $head = 1; $this->runLength[$head] = 1; } elseif ($y > 0) { if ((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { $head++; $this->runLength[$head] = 1; } else { $this->runLength[$head]++; } } } $demerit += $this->calcN1N3($head+1); } return $demerit; }
evaluateSymbol @param int $width @param array $frame @return int demerit
evaluateSymbol
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function mask($width, $frame, $level) { $minDemerit = PHP_INT_MAX; $bestMaskNum = 0; $bestMask = array(); $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7); if (QR_FIND_FROM_RANDOM !== false) { $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9); for ($i = 0; $i < $howManuOut; ++$i) { $remPos = rand (0, count($checked_masks)-1); unset($checked_masks[$remPos]); $checked_masks = array_values($checked_masks); } } $bestMask = $frame; foreach ($checked_masks as $i) { $mask = array_fill(0, $width, str_repeat("\0", $width)); $demerit = 0; $blacks = 0; $blacks = $this->makeMaskNo($i, $width, $frame, $mask); $blacks += $this->writeFormatInformation($width, $mask, $i, $level); $blacks = (int)(100 * $blacks / ($width * $width)); $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); $demerit += $this->evaluateSymbol($width, $mask); if ($demerit < $minDemerit) { $minDemerit = $demerit; $bestMask = $mask; $bestMaskNum = $i; } } return $bestMask; }
mask @param int $width @param array $frame @param int $level @return array best mask
mask
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function isdigitat($str, $pos) { if ($pos >= strlen($str)) { return false; } return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); }
Return true if the character at specified position is a number @param string $str string @param int $pos characted position @return boolean true of false
isdigitat
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function isalnumat($str, $pos) { if ($pos >= strlen($str)) { return false; } return ($this->lookAnTable(ord($str[$pos])) >= 0); }
Return true if the character at specified position is an alphanumeric character @param string $str string @param int $pos characted position @return boolean true of false
isalnumat
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function identifyMode($pos) { if ($pos >= strlen($this->dataStr)) { return QR_MODE_NL; } $c = $this->dataStr[$pos]; if ($this->isdigitat($this->dataStr, $pos)) { return QR_MODE_NM; } elseif ($this->isalnumat($this->dataStr, $pos)) { return QR_MODE_AN; } elseif ($this->hint == QR_MODE_KJ) { if ($pos+1 < strlen($this->dataStr)) { $d = $this->dataStr[$pos+1]; $word = (ord($c) << 8) | ord($d); if (($word >= 0x8140 && $word <= 0x9ffc) OR ($word >= 0xe040 && $word <= 0xebbf)) { return QR_MODE_KJ; } } } return QR_MODE_8B; }
identifyMode @param int $pos @return int mode
identifyMode
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function newInputItem($mode, $size, $data, $bstream=null) { $setData = array_slice($data, 0, $size); if (count($setData) < $size) { $setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0)); } if (!$this->check($mode, $size, $setData)) { return NULL; } $inputitem = array(); $inputitem['mode'] = $mode; $inputitem['size'] = $size; $inputitem['data'] = $setData; $inputitem['bstream'] = $bstream; return $inputitem; }
newInputItem @param int $mode @param int $size @param array $data @param array $bstream @return array input item
newInputItem
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function encodeModeNum($inputitem, $version) { $words = (int)($inputitem['size'] / 3); $inputitem['bstream'] = array(); $val = 0x1; $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_NM, $version), $inputitem['size']); for ($i=0; $i < $words; ++$i) { $val = (ord($inputitem['data'][$i*3 ]) - ord('0')) * 100; $val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10; $val += (ord($inputitem['data'][$i*3+2]) - ord('0')); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val); } if ($inputitem['size'] - $words * 3 == 1) { $val = ord($inputitem['data'][$words*3]) - ord('0'); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val); } elseif (($inputitem['size'] - ($words * 3)) == 2) { $val = (ord($inputitem['data'][$words*3 ]) - ord('0')) * 10; $val += (ord($inputitem['data'][$words*3+1]) - ord('0')); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val); } return $inputitem; }
encodeModeNum @param array $inputitem @param int $version @return array input item
encodeModeNum
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function encodeModeAn($inputitem, $version) { $words = (int)($inputitem['size'] / 2); $inputitem['bstream'] = array(); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02); $inputitem['bstream'] = $this->appendNum(v, $this->lengthIndicator(QR_MODE_AN, $version), $inputitem['size']); for ($i=0; $i < $words; ++$i) { $val = (int)$this->lookAnTable(ord($inputitem['data'][$i*2 ])) * 45; $val += (int)$this->lookAnTable(ord($inputitem['data'][$i*2+1])); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val); } if ($inputitem['size'] & 1) { $val = $this->lookAnTable(ord($inputitem['data'][($words * 2)])); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val); } return $inputitem; }
encodeModeAn @param array $inputitem @param int $version @return array input item
encodeModeAn
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function encodeMode8($inputitem, $version) { $inputitem['bstream'] = array(); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_8B, $version), $inputitem['size']); for ($i=0; $i < $inputitem['size']; ++$i) { $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$i])); } return $inputitem; }
encodeMode8 @param array $inputitem @param int $version @return array input item
encodeMode8
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function encodeModeKanji($inputitem, $version) { $inputitem['bstream'] = array(); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int)($inputitem['size'] / 2)); for ($i=0; $i<$inputitem['size']; $i+=2) { $val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i+1]); if ($val <= 0x9ffc) { $val -= 0x8140; } else { $val -= 0xc140; } $h = ($val >> 8) * 0xc0; $val = ($val & 0xff) + $h; $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 13, $val); } return $inputitem; }
encodeModeKanji @param array $inputitem @param int $version @return array input item
encodeModeKanji
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function encodeModeStructure($inputitem) { $inputitem['bstream'] = array(); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x03); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][1]) - 1); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][0]) - 1); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][2])); return $inputitem; }
encodeModeStructure @param array $inputitem @return array input item
encodeModeStructure
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function encodeBitStream($inputitem, $version) { $inputitem['bstream'] = array(); $words = $this->maximumWords($inputitem['mode'], $version); if ($inputitem['size'] > $words) { $st1 = $this->newInputItem($inputitem['mode'], $words, $inputitem['data']); $st2 = $this->newInputItem($inputitem['mode'], $inputitem['size'] - $words, array_slice($inputitem['data'], $words)); $st1 = $this->encodeBitStream($st1, $version); $st2 = $this->encodeBitStream($st2, $version); $inputitem['bstream'] = array(); $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']); $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']); } else { switch($inputitem['mode']) { case QR_MODE_NM: { $inputitem = $this->encodeModeNum($inputitem, $version); break; } case QR_MODE_AN: { $inputitem = $this->encodeModeAn($inputitem, $version); break; } case QR_MODE_8B: { $inputitem = $this->encodeMode8($inputitem, $version); break; } case QR_MODE_KJ: { $inputitem = $this->encodeModeKanji($inputitem, $version); break; } case QR_MODE_ST: { $inputitem = $this->encodeModeStructure($inputitem); break; } default: { break; } } } return $inputitem; }
encodeBitStream @param array $inputitem @param int $version @return array input item
encodeBitStream
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function appendNewInputItem($items, $mode, $size, $data) { $items[] = $this->newInputItem($mode, $size, $data); return $items; }
Append data to an input object. The data is copied and appended to the input object. @param array items input items @param int $mode encoding mode. @param int $size size of data (byte). @param array $data array of input data. @return items
appendNewInputItem
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function insertStructuredAppendHeader($items, $size, $index, $parity) { if ($size > MAX_STRUCTURED_SYMBOLS) { return -1; } if (($index <= 0) OR ($index > MAX_STRUCTURED_SYMBOLS)) { return -1; } $buf = array($size, $index, $parity); $entry = $this->newInputItem(QR_MODE_ST, 3, buf); array_unshift($items, $entry); return $items; }
insertStructuredAppendHeader @param array $items @param int $size @param int $index @param int $parity @return array items
insertStructuredAppendHeader
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function calcParity($items) { $parity = 0; foreach ($items as $item) { if ($item['mode'] != QR_MODE_ST) { for ($i=$item['size']-1; $i>=0; --$i) { $parity ^= $item['data'][$i]; } } } return $parity; }
calcParity @param array $items @return int parity
calcParity
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function checkModeNum($size, $data) { for ($i=0; $i<$size; ++$i) { if ((ord($data[$i]) < ord('0')) OR (ord($data[$i]) > ord('9'))){ return false; } } return true; }
checkModeNum @param int $size @param array $data @return boolean true or false
checkModeNum
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function estimateBitsModeNum($size) { $w = (int)$size / 3; $bits = $w * 10; switch($size - $w * 3) { case 1: { $bits += 4; break; } case 2: { $bits += 7; break; } default: { break; } } return $bits; }
estimateBitsModeNum @param int $size @return int number of bits
estimateBitsModeNum
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function lookAnTable($c) { return (($c > 127)?-1:$this->anTable[$c]); }
Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19). @param int $c character value @return value
lookAnTable
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function checkModeAn($size, $data) { for ($i=0; $i<$size; ++$i) { if ($this->lookAnTable(ord($data[$i])) == -1) { return false; } } return true; }
checkModeAn @param int $size @param array $data @return boolean true or false
checkModeAn
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function estimateBitsModeAn($size) { $w = (int)($size / 2); $bits = $w * 11; if ($size & 1) { $bits += 6; } return $bits; }
estimateBitsModeAn @param int $size @return int number of bits
estimateBitsModeAn
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function estimateBitsMode8($size) { return $size * 8; }
estimateBitsMode8 @param int $size @return int number of bits
estimateBitsMode8
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function estimateBitsModeKanji($size) { return (int)(($size / 2) * 13); }
estimateBitsModeKanji @param int $size @return int number of bits
estimateBitsModeKanji
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function checkModeKanji($size, $data) { if ($size & 1) { return false; } for ($i=0; $i<$size; $i+=2) { $val = (ord($data[$i]) << 8) | ord($data[$i+1]); if (($val < 0x8140) OR (($val > 0x9ffc) AND ($val < 0xe040)) OR ($val > 0xebbf)) { return false; } } return true; }
checkModeKanji @param int $size @param array $data @return boolean true or false
checkModeKanji
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function check($mode, $size, $data) { if ($size <= 0) { return false; } switch($mode) { case QR_MODE_NM: { return $this->checkModeNum($size, $data); } case QR_MODE_AN: { return $this->checkModeAn($size, $data); } case QR_MODE_KJ: { return $this->checkModeKanji($size, $data); } case QR_MODE_8B: { return true; } case QR_MODE_ST: { return true; } default: { break; } } return false; }
Validate the input data. @param int $mode encoding mode. @param int $size size of data (byte). @param array data data to validate @return boolean true in case of valid data, false otherwise
check
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function estimateBitStreamSize($items, $version) { $bits = 0; if ($version == 0) { $version = 1; } foreach ($items as $item) { switch($item['mode']) { case QR_MODE_NM: { $bits = $this->estimateBitsModeNum($item['size']); break; } case QR_MODE_AN: { $bits = $this->estimateBitsModeAn($item['size']); break; } case QR_MODE_8B: { $bits = $this->estimateBitsMode8($item['size']); break; } case QR_MODE_KJ: { $bits = $this->estimateBitsModeKanji($item['size']); break; } case QR_MODE_ST: { return STRUCTURE_HEADER_BITS; } default: { return 0; } } $l = $this->lengthIndicator($item['mode'], $version); $m = 1 << $l; $num = (int)(($item['size'] + $m - 1) / $m); $bits += $num * (4 + $l); } return $bits; }
estimateBitStreamSize @param array $items @param int $version @return int bits
estimateBitStreamSize
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function estimateVersion($items) { $version = 0; $prev = 0; do { $prev = $version; $bits = $this->estimateBitStreamSize($items, $prev); $version = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level); if ($version < 0) { return -1; } } while ($version > $prev); return $version; }
estimateVersion @param array $items @return int version
estimateVersion
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function lengthOfCode($mode, $version, $bits) { $payload = $bits - 4 - $this->lengthIndicator($mode, $version); switch($mode) { case QR_MODE_NM: { $chunks = (int)($payload / 10); $remain = $payload - $chunks * 10; $size = $chunks * 3; if ($remain >= 7) { $size += 2; } elseif ($remain >= 4) { $size += 1; } break; } case QR_MODE_AN: { $chunks = (int)($payload / 11); $remain = $payload - $chunks * 11; $size = $chunks * 2; if ($remain >= 6) { ++$size; } break; } case QR_MODE_8B: { $size = (int)($payload / 8); break; } case QR_MODE_KJ: { $size = (int)(($payload / 13) * 2); break; } case QR_MODE_ST: { $size = (int)($payload / 8); break; } default: { $size = 0; break; } } $maxsize = $this->maximumWords($mode, $version); if ($size < 0) { $size = 0; } if ($size > $maxsize) { $size = $maxsize; } return $size; }
lengthOfCode @param int $mode @param int $version @param int $bits @return int size
lengthOfCode
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function createBitStream($items) { $total = 0; foreach ($items as $key => $item) { $items[$key] = $this->encodeBitStream($item, $this->version); $bits = count($items[$key]['bstream']); $total += $bits; } return array($items, $total); }
createBitStream @param array $items @return array of items and total bits
createBitStream
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function convertData($items) { $ver = $this->estimateVersion($items); if ($ver > $this->version) { $this->version = $ver; } for (;;) { $cbs = $this->createBitStream($items); $items = $cbs[0]; $bits = $cbs[1]; if ($bits < 0) { return -1; } $ver = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level); if ($ver < 0) { return -1; } elseif ($ver > $this->version) { $this->version = $ver; } else { break; } } return $items; }
convertData @param array $items @return array items
convertData
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function appendPaddingBit($bstream) { $bits = count($bstream); $maxwords = $this->getDataLength($this->version, $this->level); $maxbits = $maxwords * 8; if ($maxbits == $bits) { return 0; } if ($maxbits - $bits < 5) { return $this->appendNum($bstream, $maxbits - $bits, 0); } $bits += 4; $words = (int)(($bits + 7) / 8); $padding = array(); $padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0); $padlen = $maxwords - $words; if ($padlen > 0) { $padbuf = array(); for ($i=0; $i<$padlen; ++$i) { $padbuf[$i] = ($i&1)?0x11:0xec; } $padding = $this->appendBytes($padding, $padlen, $padbuf); } return $this->appendBitstream($bstream, $padding); }
Append Padding Bit to bitstream @param array $bstream @return array bitstream
appendPaddingBit
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function mergeBitStream($items) { $items = $this->convertData($items); $bstream = array(); foreach ($items as $item) { $bstream = $this->appendBitstream($bstream, $item['bstream']); } return $bstream; }
mergeBitStream @param array $bstream @return array bitstream
mergeBitStream
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT
protected function getBitStream($items) { $bstream = $this->mergeBitStream($items); return $this->appendPaddingBit($bstream); }
Returns a stream of bits. @param int $items @return array padded merged byte stream
getBitStream
php
wizwizdev/wizwizxui-timebot
phpqrcode/bindings/tcpdf/qrcode.php
https://github.com/wizwizdev/wizwizxui-timebot/blob/master/phpqrcode/bindings/tcpdf/qrcode.php
MIT