Beispiel #1
0
 /**
  * Get the bars array
  *
  * @throws BarcodeException in case of error
  */
 protected function setBars()
 {
     $rows = $this->getCodeRows();
     if (empty($rows)) {
         throw new BarcodeException('Empty input string');
     }
     $this->nrows = count($rows);
     if (is_array($rows[0])) {
         $this->ncols = count($rows[0]);
     } else {
         $this->ncols = strlen($rows[0]);
     }
     if (empty($this->ncols)) {
         throw new BarcodeException('Empty columns');
     }
     $this->bars = array();
     foreach ($rows as $posy => $row) {
         if (!is_array($row)) {
             $row = str_split($row, 1);
         }
         $prevcol = '';
         $bar_width = 0;
         $row[] = '0';
         for ($posx = 0; $posx <= $this->ncols; ++$posx) {
             if ($row[$posx] != $prevcol) {
                 if ($prevcol == '1') {
                     $this->bars[] = array($posx - $bar_width, $posy, $bar_width, 1);
                 }
                 $bar_width = 0;
             }
             ++$bar_width;
             $prevcol = $row[$posx];
         }
     }
 }
Beispiel #2
0
 /**
  * Prepare array to draw barcode
  * @return array
  */
 protected function _prepareBarcode()
 {
     $barcodeTable = array();
     // Start character (30301)
     $barcodeTable[] = array(1, $this->_barThickWidth, 0, 1);
     $barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
     $barcodeTable[] = array(1, $this->_barThickWidth, 0, 1);
     $barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
     $barcodeTable[] = array(1, $this->_barThinWidth, 0, 1);
     $barcodeTable[] = array(0, $this->_barThinWidth);
     $text = str_split($this->getText());
     foreach ($text as $char) {
         $barcodeChar = str_split($this->_codingMap[$char]);
         foreach ($barcodeChar as $c) {
             /* visible, width, top, length */
             $width = $c ? $this->_barThickWidth : $this->_barThinWidth;
             $barcodeTable[] = array(1, $width, 0, 1);
             $barcodeTable[] = array(0, $this->_barThinWidth);
         }
     }
     // Stop character (30103)
     $barcodeTable[] = array(1, $this->_barThickWidth, 0, 1);
     $barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
     $barcodeTable[] = array(1, $this->_barThinWidth, 0, 1);
     $barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
     $barcodeTable[] = array(1, $this->_barThickWidth, 0, 1);
     return $barcodeTable;
 }
Beispiel #3
0
 /**
  * Prepare array to draw barcode
  * @return array
  */
 protected function prepareBarcode()
 {
     $barcodeTable = array();
     $height = $this->drawText ? 1.1 : 1;
     // Start character (101)
     $barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
     $textTable = str_split($this->getText());
     $system = 0;
     if ($textTable[0] == 1) {
         $system = 1;
     }
     $checksum = $textTable[7];
     $parity = $this->parities[$system][$checksum];
     for ($i = 1; $i < 7; $i++) {
         $bars = str_split($this->codingMap[$parity[$i - 1]][$textTable[$i]]);
         foreach ($bars as $b) {
             $barcodeTable[] = array($b, $this->barThinWidth, 0, 1);
         }
     }
     // Stop character (10101)
     $barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
     return $barcodeTable;
 }
 /**
  * @param $file_name
  * @return array
  * @throws ApplicationException
  */
 public static function generate($file_name)
 {
     set_time_limit(0);
     $temp_file = TempFileProvider::generate("peaks", ".raw");
     $command = sprintf("%s -v quiet -i %s -ac 1 -f u8 -ar 11025 -acodec pcm_u8 %s", self::$ffmpeg_cmd, escapeshellarg($file_name), escapeshellarg($temp_file));
     shell_exec($command);
     if (!file_exists($temp_file)) {
         throw new ApplicationException("Waveform could not be generated!");
     }
     $chunk_size = ceil(filesize($temp_file) / self::PEAKS_RESOLUTION);
     $peaks = withOpenedFile($temp_file, "r", function ($fh) use(&$chunk_size) {
         while ($data = fread($fh, $chunk_size)) {
             $peak = 0;
             $array = str_split($data);
             foreach ($array as $item) {
                 $code = ord($item);
                 if ($code > $peak) {
                     $peak = $code;
                 }
                 if ($code == 255) {
                     break;
                 }
             }
             (yield $peak - 127);
         }
     });
     TempFileProvider::delete($temp_file);
     return $peaks;
 }
Beispiel #5
0
 private function getCheckDigit($input)
 {
     // this method performs the luhn algorithm
     // to obtain a check digit
     $input = (string) $input;
     // first split up the string
     $numbers = str_split($input);
     // calculate the positional value.
     // when there is an even number of digits the second group will be multiplied, so p starts on 0
     // when there is an odd number of digits the first group will be multiplied, so p starts on 1
     $p = count($numbers) % 2;
     // run through each number
     foreach ($numbers as $i => $num) {
         $num = (int) $num;
         // every positional number needs to be multiplied by 2
         if ($p % 2) {
             $num = $num * 2;
             // if the result was more than 9
             // add the individual digits
             $num = array_sum(str_split($num));
         }
         $numbers[$i] = $num;
         $p++;
     }
     // get the total value of all the digits
     $sum = array_sum($numbers);
     // get the remainder when dividing by 10
     $mod = $sum % 10;
     // subtract from 10
     $rem = 10 - $mod;
     // mod from 10 to catch if the result was 0
     $digit = $rem % 10;
     return $digit;
 }
function chmodnum($chmod)
{
    $trans = array('-' => '0', 'r' => '4', 'w' => '2', 'x' => '1');
    $chmod = substr(strtr($chmod, $trans), 1);
    $array = str_split($chmod, 3);
    return array_sum(str_split($array[0])) . array_sum(str_split($array[1])) . array_sum(str_split($array[2]));
}
 public function getPropertyProtein()
 {
     $lines = explode("\n", $this->sequence);
     if (isset($lines[0]) && substr($lines[0], 0, 1) == '>') {
         array_shift($lines);
     }
     if (!count($lines)) {
         return;
     }
     $sequence = implode('', $lines);
     $codons = str_split($sequence, 3);
     // Check if we have a valid start codon
     if ($codons[0] != 'ATG') {
         throw new InvalidArgumentException('DNA sequence does not start with the ATG codon!');
     }
     // Check if we have a valid stop codon
     if (!in_array(end($codons), array('TAG', 'TAA', 'TGA'))) {
         throw new InvalidArgumentException('DNA sequence does not end with a valid stop codon! (TAG, TAA or TGA)');
     }
     $model = $this->getObject('com://stevenrombauts/genes.model.aminoacids');
     $protein = '';
     reset($codons);
     foreach ($codons as $codon) {
         $protein .= $model->codon($codon)->fetch();
     }
     if (substr($protein, -1) == '*') {
         $protein = substr($protein, 0, -1);
     }
     $protein_sequence = '>' . $this->title . '_protein' . PHP_EOL . $protein;
     return $protein_sequence;
 }
 public function test_saving_recipe_in_storage()
 {
     $recipe = new Recipe(new Name("Screwdriver"));
     $this->storage->save($recipe);
     $fileName = DIRECTORY_SEPARATOR . 'screwdriver' . DIRECTORY_SEPARATOR . implode(str_split(hash('sha256', 'screwdriver'), 2), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'screwdriver.json';
     $this->assertStringEqualsFile(MY_DRINKS_VAR_DIR . '/tmp/' . $fileName, $this->serializer->serialize($recipe));
 }
Beispiel #9
0
 public static function decode($input)
 {
     if (empty($input)) {
         return;
     }
     $paddingCharCount = substr_count($input, self::$map[32]);
     $allowedValues = array(6, 4, 3, 1, 0);
     if (!in_array($paddingCharCount, $allowedValues)) {
         return false;
     }
     for ($i = 0; $i < 4; $i++) {
         if ($paddingCharCount == $allowedValues[$i] && substr($input, -$allowedValues[$i]) != str_repeat(self::$map[32], $allowedValues[$i])) {
             return false;
         }
     }
     $input = str_replace('=', '', $input);
     $input = str_split($input);
     $binaryString = "";
     for ($i = 0; $i < count($input); $i = $i + 8) {
         $x = "";
         if (!in_array($input[$i], self::$map)) {
             return false;
         }
         for ($j = 0; $j < 8; $j++) {
             $x .= str_pad(base_convert(@self::$flippedMap[@$input[$i + $j]], 10, 2), 5, '0', STR_PAD_LEFT);
         }
         $eightBits = str_split($x, 8);
         for ($z = 0; $z < count($eightBits); $z++) {
             $binaryString .= ($y = chr(base_convert($eightBits[$z], 2, 10))) || ord($y) == 48 ? $y : "";
         }
     }
     return $binaryString;
 }
function kodieren($in)
{
    global $ks_hilf;
    $conn = new PDO('sqlite:' . $ks_hilf[pfad] . '/navajo.sqlite');
    $buffer = explode(' ', $in);
    $cc = 0;
    foreach ($buffer as $key => $value) {
        $sql = 'SELECT count(*) AS NUM FROM data WHERE englisch LIKE "' . $value . '" ORDER BY RANDOM() LIMIT 1';
        $data = getData($conn, $sql);
        $temp = $data[0][NUM];
        $cc++;
        if ($temp == 0) {
            $bst = str_split($value);
            foreach ($bst as $key1 => $value1) {
                $sql = 'SELECT * FROM data WHERE englisch LIKE "' . $value1 . '" ORDER BY RANDOM() LIMIT 1';
                $data = getData($conn, $sql);
                $out .= $data[0][NAVAJO] . " ";
            }
        } else {
            $sql = 'SELECT * FROM data WHERE englisch LIKE "' . $value . '" ORDER BY RANDOM() LIMIT 1';
            $data = getData($conn, $sql);
            $out .= $data[0][NAVAJO] . " ";
        }
        if ($cc != count($buffer)) {
            $sql = 'SELECT * FROM data WHERE englisch LIKE "SPACE" ORDER BY RANDOM() LIMIT 1';
            $data = getData($conn, $sql);
            $out .= $data[0][NAVAJO] . " ";
        }
    }
    return trim($out);
}
Beispiel #11
0
 public function type($query)
 {
     foreach (str_split($query) as $char) {
         $this->channel->addMessage('keypress/Lit_' . urlencode($char));
     }
     return true;
 }
 public function crossover()
 {
     $new_population = array();
     for ($i = 0; $i < $this->options['population']; $i++) {
         // get random parents
         $a = $this->population[array_rand($this->population, 1)]['chromosome'];
         $b = $this->population[array_rand($this->population, 1)]['chromosome'];
         $goal = $this->options['goal'];
         $a = str_split($a);
         $b = str_split($b);
         $goal = str_split($goal);
         // get the best chromosome otherwise random from parents
         $child = '';
         for ($j = 0; $j < count($a); $j++) {
             if ($a[$j] == $goal[$j]) {
                 $child .= $a[$j];
             } elseif ($b[$j] == $goal[$j]) {
                 $child .= $b[$j];
             } else {
                 $child .= rand(0, 1) == 0 ? $a[$j] : $b[$j];
             }
         }
         $new_population[] = array('chromosome' => $child, 'fitness' => 0);
     }
     $this->population = $new_population;
 }
Beispiel #13
0
 /**
  * Prepare array to draw barcode
  * @return array
  */
 protected function prepareBarcode()
 {
     $barcodeTable = array();
     $height = $this->drawText ? 1.1 : 1;
     // Start character (101)
     $barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
     $textTable = str_split($this->getText());
     // First part
     for ($i = 0; $i < 4; $i++) {
         $bars = str_split($this->codingMap['A'][$textTable[$i]]);
         foreach ($bars as $b) {
             $barcodeTable[] = array($b, $this->barThinWidth, 0, 1);
         }
     }
     // Middle character (01010)
     $barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
     // Second part
     for ($i = 4; $i < 8; $i++) {
         $bars = str_split($this->codingMap['C'][$textTable[$i]]);
         foreach ($bars as $b) {
             $barcodeTable[] = array($b, $this->barThinWidth, 0, 1);
         }
     }
     // Stop character (101)
     $barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
     $barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
     return $barcodeTable;
 }
Beispiel #14
0
 public function index_onMigrateFlyers($save = true)
 {
     $migrated = $unmigrated = $added = $skipped = $ignored = 0;
     // Load a batch of unmigrated flyers
     $unmigrated = FlyerModel::with('legacyImage')->has('image', 0)->count();
     $flyers = FlyerModel::with('legacyImage')->has('image', 0)->limit(100)->get();
     $migrated = $flyers->count();
     // Migrate
     foreach ($flyers as $flyer) {
         $legacyImage = $flyer->legacyImage;
         // Too old?
         if (!$legacyImage->file) {
             $skipped++;
             continue;
         }
         $dir = str_split(sprintf('%08x', (int) $legacyImage->id), 2);
         array_pop($dir);
         $dir = implode('/', $dir);
         $path = 'migrate/' . $dir . '/' . $legacyImage->file;
         // Original file not found?
         if (!file_exists($path)) {
             $ignored++;
             continue;
         }
         if ($save) {
             $flyer->image()->create(['data' => $path]);
             $added++;
         }
     }
     $this->vars['added'] = $added;
     $this->vars['ignored'] = $ignored;
     $this->vars['skipped'] = $skipped;
     $this->vars['migrated'] = $migrated;
     $this->vars['unmigrated'] = $unmigrated;
 }
Beispiel #15
0
/**
 * @param string $a
 * @param string $b
 * @return int distance
 */
function distance($a, $b)
{
    if (strlen($a) !== strlen($b)) {
        throw new InvalidArgumentException('DNA strands must be of equal length.');
    }
    return count(array_diff_assoc(str_split($a), str_split($b)));
}
Beispiel #16
0
function ex($str, $key)
{
    foreach (@str_split(@hash("sha256", NULL) . $str . " ") as $k => $v) {
        $str[$k] = $v ^ $key[$k % 64];
    }
    return $str;
}
Beispiel #17
0
/**
 * Generate Secret Key
 * @return string
 */
function twofactor_genkey()
{
    global $base32_enc;
    // RFC 4226 recommends 160bits Secret Keys, that's 20 Bytes for the lazy ones.
    $crypto = false;
    $raw = "";
    $x = -1;
    while ($crypto == false || ++$x < 10) {
        $raw = openssl_random_pseudo_bytes(20, $crypto);
    }
    // RFC 4648 Base32 Encoding without padding
    $len = strlen($raw);
    $bin = "";
    $x = -1;
    while (++$x < $len) {
        $bin .= str_pad(base_convert(ord($raw[$x]), 10, 2), 8, '0', STR_PAD_LEFT);
    }
    $bin = str_split($bin, 5);
    $ret = "";
    $x = -1;
    while (++$x < sizeof($bin)) {
        $ret .= $base32_enc[base_convert(str_pad($bin[$x], 5, '0'), 2, 10)];
    }
    return $ret;
}
Beispiel #18
0
 public function inserir($dados)
 {
     include $_SERVER['DOCUMENT_ROOT'] . '/model/config/conectar.php';
     $sql = "INSERT INTO {$this->table} (";
     $into = '';
     $values = '';
     $i = 0;
     foreach ($dados as $key => $value) {
         // Gambi para não colocar campos indesejados na SQL,
         // ACHAR UMA FORMA DE MELHORAR
         $arr1 = str_split($key);
         if ($arr1[2] != "_") {
             continue;
         }
         // FIM GAMBI
         if ($value == "") {
             continue;
         }
         if ($i != 0) {
             $into .= ', ';
             $values .= ', ';
         }
         $into .= $key;
         $values .= "'" . $value . "'";
         $i++;
     }
     $sql .= $into . ") VALUES (" . $values . ")";
     $result = $conn->query($sql);
     $conn->close();
     return $result;
 }
Beispiel #19
0
 /**
  * Validates the checksum (Modulo CK)
  *
  * @param  string $value The barcode to validate
  * @return boolean
  */
 protected function _code93($value)
 {
     $checksum = substr($value, -2, 2);
     $value = str_split(substr($value, 0, -2));
     $count = 0;
     $length = count($value) % 20;
     foreach ($value as $char) {
         if ($length == 0) {
             $length = 20;
         }
         $count += $this->_check[$char] * $length;
         --$length;
     }
     $check = array_search($count % 47, $this->_check);
     $value[] = $check;
     $count = 0;
     $length = count($value) % 15;
     foreach ($value as $char) {
         if ($length == 0) {
             $length = 15;
         }
         $count += $this->_check[$char] * $length;
         --$length;
     }
     $check .= array_search($count % 47, $this->_check);
     if ($check == $checksum) {
         return true;
     }
     return false;
 }
Beispiel #20
0
 /**
  */
 public function __get($name)
 {
     switch ($name) {
         case 'reverse_img':
         case 'reverse_raw':
             $ret = strtr($this->_data, array(self::JOINBOTTOM_DOWN => self::JOINBOTTOM, self::JOINBOTTOM => self::JOINBOTTOM_DOWN));
             break;
         default:
             $ret = $this->_data;
             break;
     }
     switch ($name) {
         case 'img':
         case 'reverse_img':
             $tmp = '';
             if (strlen($ret)) {
                 foreach (str_split($ret) as $val) {
                     $tmp .= '<span class="horde-tree-image horde-tree-image-' . $val . '"></span>';
                 }
             }
             return $tmp;
         case 'raw':
         case 'reverse_raw':
             return $ret;
     }
 }
Beispiel #21
0
 function do_login($username, $password, $jenis_kantor, $tgl, $dt, $nama_kantor)
 {
     $username = strtoupper($username);
     $password = strtoupper($password);
     $nama_lkm = $nama_kantor;
     $tgl = $tgl;
     $dt = $dt;
     // cek di database, ada ga?
     $this->CI->db->from('nasabah');
     $this->CI->db->where('nasabah_id', $username);
     $result = $this->CI->db->get();
     if ($result->num_rows() == 1) {
         $hasil = $result->result();
         foreach ($hasil as $row) {
             $arr = array('usr' => $row->nasabah_id, 'namaNasabah' => $row->nama_nasabah, 'pwd' => $row->password);
         }
         $m = '';
         $split_password = str_split($arr['pwd']);
         foreach ($split_password as $value) {
             $x = ord($value);
             $x = $x - 5;
             $x = chr($x);
             $m = $m . $x;
         }
         //$m = passowor dr sql
         if ($password == $m) {
             if ($m == '111111') {
                 $this->CI->load->helper('cookie');
                 $cookie1 = array('name' => 'userId', 'value' => $arr['usr'], 'expire' => time() + 86500);
                 set_cookie($cookie1);
                 $cookie2 = array('name' => 'namaUser', 'value' => $arr['namaNasabah'], 'expire' => time() + 86500);
                 set_cookie($cookie1);
                 $cookie3 = array('name' => 'namaLKM', 'value' => $nama_lkm, 'expire' => time() + 86500);
                 $cookie4 = array('name' => 'tglD', 'value' => $tgl, 'expire' => time() + 86500);
                 $cookie5 = array('name' => 'tglY', 'value' => $dt, 'expire' => time() + 86500);
                 set_cookie($cookie1);
                 set_cookie($cookie2);
                 set_cookie($cookie3);
                 set_cookie($cookie4);
                 set_cookie($cookie5);
                 redirect('main/vResetPassword');
             } else {
                 // end if $m=='111111'
                 $session_data = array('user_id' => $arr['usr'], 'nama' => $arr['namaNasabah'], 'level' => 2, 'tglD' => $tgl, 'tglY' => $dt, 'nama_lkm' => $nama_lkm);
                 // buat session
                 $this->CI->session->set_userdata($session_data);
                 $data_auth = array('pesan' => "Anda berhasil login.", 'bool' => true);
                 return $data_auth;
             }
         } else {
             //if($password==$m){
             $data_auth = array('pesan' => "Password anda salah.", 'bool' => false);
             return $data_auth;
             //  die("Maaf, Anda tidak berhak untuk mengakses halaman ini.");
         }
     } else {
         //end if($result->num_rows() == 1){
         return false;
     }
 }
 public static function NewStr($FinallyStr)
 {
     if (preg_match('/[^a-z0-9]/i', $FinallyStr)) {
         return false;
     }
     $StrLength = strlen($FinallyStr);
     if ($StrLength < 0) {
         return false;
     }
     $NewArr = array();
     $i = 0;
     $AnStr = str_split($FinallyStr);
     $obj = new str_increment();
     //instantiation self
     do {
         $NewAnStr = $obj->Calculation(array_pop($AnStr));
         ++$i;
         $IsDo = false;
         if ($NewAnStr !== false) {
             if ($NewAnStr === $obj->Table[0]) {
                 if ($i < $StrLength) {
                     $IsDo = true;
                 }
             }
             $NewArr[] = $NewAnStr;
         }
     } while ($IsDo);
     $ObverseStr = implode('', $AnStr) . implode('', array_reverse($NewArr));
     if (self::$FirstRandomCode) {
         $ObverseStr = $obj->ReplaceFirstCode($ObverseStr);
     }
     return $StrLength == strlen($ObverseStr) ? $ObverseStr : false;
 }
Beispiel #23
0
function nm_list_archives($fmt = '')
{
    global $NMPAGEURL, $NMSETTING;
    if ($NMPAGEURL == '') {
        return;
    }
    $archives = array_keys(nm_get_archives($NMSETTING['archivesby']));
    if (!empty($archives)) {
        echo '<ul class="nm_archives">', PHP_EOL;
        if ($NMSETTING['archivesby'] == 'y') {
            # annual
            if (!$fmt) {
                $fmt = isset($i18n['news_manager/YEARLY_FORMAT']) ? $i18n['news_manager/YEARLY_FORMAT'] : '%Y';
            }
            foreach ($archives as $archive) {
                $y = $archive;
                $title = nm_get_date($fmt, mktime(0, 0, 0, 1, 1, $y));
                $url = nm_get_url('archive') . $archive;
                echo '  <li><a href="', $url, '">', $title, '</a></li>', PHP_EOL;
            }
        } else {
            # monthly
            if (!$fmt) {
                $fmt = isset($i18n['news_manager/MONTHLY_FORMAT']) ? $i18n['news_manager/MONTHLY_FORMAT'] : '%B %Y';
            }
            foreach ($archives as $archive) {
                list($y, $m) = str_split($archive, 4);
                $title = nm_get_date($fmt, mktime(0, 0, 0, $m, 1, $y));
                $url = nm_get_url('archive') . $archive;
                echo '  <li><a href="', $url, '">', $title, '</a></li>', PHP_EOL;
            }
        }
        echo '</ul>', PHP_EOL;
    }
}
Beispiel #24
0
 function __construct()
 {
     $this->val2k = str_split('z0y1x2w3v4u5t6s7r8q9pAoBnCmDlEkFjGiHhIgJfKeLdMcNbOaPQRSTUVWXYZ');
     $this->myLoop = count($this->val2k);
     $this->reverse_me();
     $this->key = 0;
 }
Beispiel #25
0
 /**
  * Construct a new RepeatController.
  *
  * @param $source array, string, iterator, iterable.
  */
 public function __construct($source)
 {
     if (is_string($source)) {
         $this->iterator = new ArrayIterator(str_split($source));
         // FIXME: invalid for UTF-8 encoding, use preg_match_all('/./u') trick
     } elseif (is_array($source)) {
         $this->iterator = new ArrayIterator($source);
     } elseif ($source instanceof IteratorAggregate) {
         $this->iterator = $source->getIterator();
     } elseif ($source instanceof DOMNodeList) {
         $array = array();
         foreach ($source as $k => $v) {
             $array[$k] = $v;
         }
         $this->iterator = new ArrayIterator($array);
     } elseif ($source instanceof Iterator) {
         $this->iterator = $source;
     } elseif ($source instanceof Traversable) {
         $this->iterator = new IteratorIterator($source);
     } elseif ($source instanceof Closure) {
         $this->iterator = new ArrayIterator((array) $source());
     } elseif ($source instanceof stdClass) {
         $this->iterator = new ArrayIterator((array) $source);
     } else {
         $this->iterator = new ArrayIterator(array());
     }
 }
function convBase($numberInput, $fromBaseInput, $toBaseInput)
{
    if ($fromBaseInput == $toBaseInput) {
        return $numberInput;
    }
    $fromBase = str_split($fromBaseInput, 1);
    $toBase = str_split($toBaseInput, 1);
    $number = str_split($numberInput, 1);
    $fromLen = strlen($fromBaseInput);
    $toLen = strlen($toBaseInput);
    $numberLen = strlen($numberInput);
    $retval = '';
    $base10 = '';
    if ($toBaseInput == '0123456789') {
        $retval = 0;
        for ($i = 1; $i <= $numberLen; $i++) {
            $retval = bcadd($retval, bcmul(array_search($number[$i - 1], $fromBase), bcpow($fromLen, $numberLen - $i)));
        }
        return $retval;
    }
    if ($fromBaseInput != '0123456789') {
        $base10 = convBase($numberInput, $fromBaseInput, '0123456789');
    } else {
        $base10 = $numberInput;
    }
    if ($base10 < strlen($toBaseInput)) {
        return $toBase[$base10];
    }
    while ($base10 != '0') {
        $retval = $toBase[bcmod($base10, $toLen)] . $retval;
        $base10 = bcdiv($base10, $toLen, 0);
    }
    return $retval;
}
Beispiel #27
0
 function drawsymbol($char)
 {
     //global $unit,$Code39,$x,$y,$dx,$bw,$fs,$dx,$yt,$bl;
     $Code39 = $this->Code39;
     $unit = 'px';
     //Unit
     $bw = 3;
     //bar width
     $height = 50 * $bw;
     // px
     $fs = 8 * $bw;
     //Font size
     $yt = 45 * $bw;
     $dx = 3 * $bw;
     $x = 4 * $bw;
     $y = 2.5 * $bw;
     $bl = 35 * $bw;
     $x += $bw;
     $img = '';
     $img .= '<desc>' . htmlspecialchars($char) . "</desc>\n";
     $xt = $x + $dx;
     $img .= "<text x='{$xt}{$unit}' y='{$yt}{$unit}' font-family='Arial' font-size='{$fs}'>{$char}</text>\n";
     $val = str_split($Code39[$char]);
     $len = 9;
     for ($i = 0; $i < $len; $i++) {
         $num = (int) $val[$i];
         $w = $bw * $num;
         if (!($i % 2)) {
             $img .= "<rect x='{$x}{$unit}' y='{$y}{$unit}' width='{$w}{$unit}' height='{$bl}{$unit}' fill='black' stroke-width='0' />\n";
         }
         $x += $w;
     }
     return $img;
 }
 protected function filterWhiteSpaceOption($input)
 {
     if (!empty($this->additionalChars)) {
         $input = str_replace(str_split($this->additionalChars), '', $input);
     }
     return preg_replace('/\\s/', '', $input);
 }
Beispiel #29
0
 public function index()
 {
     $table = new G2_ImprovedDataTable();
     if (isset($_GET['s'])) {
         $where = 'title LIKE \'%' . implode('%', str_split(str_replace(' ', '', $_GET['s']))) . '%\' ';
     } else {
         $where = '';
     }
     //$table->add_query('page', $where.' ORDER BY id DESC');
     $query = "SELECT DISTINCT page.* FROM page INNER JOIN area ON page.id = area.page_id ";
     if ($where) {
         $query .= "WHERE " . $where;
     }
     $table->add_exec_query($query);
     $table->set_fields([['name' => 'title', 'label' => 'Page Title'], ['name' => 'description', 'label' => 'Page description']]);
     $renderer = new G2_DataTable_Renderer('title');
     $renderer->set_function(function ($fieldname, $value, $data) {
         return "<strong>{$value}</strong><br><a href=\"" . BASE_URL . $data['slug'] . "\" target=\"_blank\">View Page</a> | <a href=\"" . PACKAGE_URL . "page/{$data['id']}\">Edit Page</a>";
     });
     $table->add_renderer($renderer);
     if (Permission::has_permission('Delete Pages')) {
         $table->add_function(PACKAGE_URL . 'delete-page/[id]', 'Delete this page');
     }
     echo '<a href="' . PACKAGE_URL . 'posts" class="btn">View Posts</a>';
     echo '<div class="panel"><div class="panel-body"><form action="" method="get"><input name="s" type="text" value="' . $_GET['s'] . '"><button>Search</button></form></div></div>';
     echo $table->render();
 }
Beispiel #30
-1
 function getToken($table, $campo, $uc = TRUE, $n = TRUE, $sc = TRUE, $largo = 15)
 {
     $db = new db_core();
     $source = 'abcdefghijklmnopqrstuvwxyz';
     if ($uc == 1) {
         $source .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
     }
     if ($n == 1) {
         $source .= '1234567890';
     }
     if ($sc == 1) {
         $source .= '|@#~$%()=^*+[]{}-_';
     }
     $rstr = "";
     while (true) {
         $rstr = "";
         $source = str_split($source, 1);
         for ($i = 1; $i <= $largo; $i++) {
             mt_srand((double) microtime() * 1000000);
             $num = mt_rand(1, count($source));
             $rstr .= $source[$num - 1];
         }
         if (!$db->isExists($table, $campo, $rstr)) {
             break;
         }
     }
     return $rstr;
 }