public function getWhen($instance, $method) { $ref = new ReflectionClass($instance); $refMethod = $ref->getMethod($method); $comment = $refMethod->getDocComment(); $when = Utils::cut('@when=', "\n", $comment); return $when ?: '* * * * *'; }
private function getPartials($code) { $tab = explode('@@partial', $code); array_shift($tab); $partials = array(); if (count($tab)) { foreach ($tab as $partial) { $partial = Utils::cut('(', ')', $partial); array_push($partials, $partial); } } return $partials; }
public function img($q) { $data = lib('geo')->dwnCache("https://www.pinterest.com/search/pins/?q=" . urlencode($q)); $tab = explode('}, "orig": {"url": ', $data); array_shift($tab); $collection = []; foreach ($tab as $row) { $src = str_replace(["\\"], [""], Utils::cut('"', '"', $row)); $width = Utils::cut('"width": ', ',', $row); $height = Utils::cut('"height": ', '}', $row); $collection[] = ['src' => $src, 'width' => $width, 'height' => $height]; } return $collection; }
function typeSql($string) { $length = 'NA'; $type = (string) $string; if (strstr($string, '(')) { $length = (int) Utils::cut('(', ')', $string); list($type, $dummy) = explode('(', $string, 2); $type = (string) $type; } return array('fieldType' => $type, 'length' => $length); }
public function serializeClosure(callable $closure) { $ref = new \ReflectionFunction($closure); $file = $ref->getFileName(); $start = $ref->getStartLine(); $end = $ref->getEndline(); $content = file($file); $code = []; for ($i = $start - 1; $i < $end; $i++) { $code[] = trim($content[$i]); } $code = implode('', $code) . 'end'; $function = 'function (' . Utils::cut('function (', '});end', $code) . '}'; return $function; }
/** * [fromSql description] * * @method fromSql * * @param [type] $sql [description] * * @return [type] [description] */ public static function fromSql($sql) { $select = Utils::cut('SELECT ', ' FROM', $sql); $from = Utils::cut(' FROM ', ' ', $sql); $wheres = ''; if (fnmatch('* WHERE *', $sql)) { $wheres = Arrays::last(explode(' WHERE ', $sql)); } $joins = []; if (fnmatch('* JOIN *', $sql)) { $segs = explode(' JOIN ', $sql); array_shift($segs); foreach ($segs as $seg) { $fk = Arrays::first(explode(' ', $seg)); if (!in_array($joins, $joins)) { $joins[] = $fk; } } } if (fnmatch('*.*', $from)) { list($db, $table) = explode('.', Inflector::lower($from), 2); } else { $db = SITE_NAME; $table = Inflector::lower($from); } $instance = self::instance($db, $table); if (!empty($select) && $select != '*') { $selects = explode(',', str_replace(' ', '', Inflector::lower($select))); foreach ($selects as $field) { $instance->select($field); } } if (fnmatch('* ORDER BY *', $wheres)) { list($wheres, $orders) = explode(' ORDER BY ', $wheres, 2); } $whs = [$wheres]; $or = false; if (fnmatch('* && *', $wheres)) { $whs = explode(' && ', $wheres); } if (fnmatch('* || *', $wheres)) { $whs = explode(' || ', $wheres); $or = true; } foreach ($whs as $wh) { list($f, $o, $v) = explode(' ', $wh, 3); if ($v[0] == "'") { $v = substr($v, 1); } if ($v[strlen($v) - 1] == "'") { $v = substr($v, 0, -1); } if (is_numeric($v)) { if ($v == intval($v)) { $v = (int) $v; } } if (!$or) { $instance = $instance->where([$f, $o, $v]); } else { $instance = $instance->where([$f, $o, $v], 'OR'); } } if (isset($orders)) { if (fnmatch('*,*', $orders)) { $orders = explode(',', str_replace(', ', ',', $orders)); } else { $orders = [$orders]; } foreach ($orders as $order) { if (fnmatch('* *', $order)) { list($f, $d) = explode(' ', $order, 2); } else { $f = $order; $d = 'ASC'; } $instance = $instance->order($f, $d); } } return $instance; }
/** * @return string The release year of the movie or $sNotFound. */ public function getReleaseYear() { if (true === $this->isReady) { return (int) Utils::cut('(<a href="/year/', '/', $this->sSource); } return $this->sNotFound; }
public static function lng($content) { $tab = array_merge(explode('<t ', $content), explode('<t>', $content)); if (count($tab)) { array_shift($tab); foreach ($tab as $row) { $id = Utils::cut('id="', '"', trim($row)); $args = Utils::cut('args=[', ']', trim($row)); $default = Utils::cut('">', '</t>', trim($row)); $default = !strlen($default) ? Utils::cut(']>', '</t>', trim($row)) : $default; if (!strlen($default)) { if (!strstr($row, '</t>')) { continue; } else { list($default, $dummy) = explode('</t>', $row, 2); } } if (strlen($args)) { if (strlen($id)) { $content = repl('<t id="' . $id . '" args=[' . $args . ']>' . $default . '</t>', '<?php echo trad("' . repl('"', '\\"', $id) . '", "' . repl('"', '\\"', $default) . '", "' . repl('"', '\\"', $args) . '"); ?>', $content); } else { $id = Inflector::urlize($default); $content = repl('<t args=[' . $args . ']>' . $default . '</t>', '<?php echo trad("' . $id . '", "' . repl('"', '\\"', $default) . '", "' . repl('"', '\\"', $args) . '"); ?>', $content); } } else { if (strlen($id)) { $content = repl('<t id="' . $id . '">' . $default . '</t>', '<?php echo trad("' . repl('"', '\\"', $id) . '", "' . repl('"', '\\"', $default) . '"); ?>', $content); } else { $id = Inflector::urlize($default); $content = repl('<t>' . $default . '</t>', '<?php echo trad("' . $id . '", "' . repl('"', '\\"', $default) . '"); ?>', $content); } } } } return $content; }
public function getGraphs($id) { if (is_object($id)) { $id = (string) $id; } $content = $this->native($id)['content']; $content = str_replace('<span data-graph-place="true">', '', $content); $content = str_replace('<span data-graph-object="true">', '', $content); $content = str_replace('<span data-graph-people="true">', '', $content); $content = str_replace('</span></span>', '</span>', $content); if (strstr($content, '</span></span>')) { $content = str_replace('</span></span>', '</span>', $content); $tab = explode('="true"><span', $content); foreach ($tab as $row) { $subtab = explode('<span data-', $row); array_pop($subtab); $content = str_replace($row, implode('<span data-', $subtab), $content); } } $content = str_replace('<span="true">', '', $content); $content = str_replace('">="true">', '">', $content); $content = str_replace('"></span>', '">', $content); $content = str_replace(' ="true"><span', '<span', $content); $content = str_replace('="true"></span>', '="true">', $content); $content = str_replace(' </span>', '</span> ', $content); $content = str_replace(' </span>', '</span> ', $content); $content = str_replace(' ', ' ', $content); if (strstr($content, '<span="true"')) { $tab = explode('<span="true"', $content); array_shift($tab); foreach ($tab as $row) { $color = Utils::cut('style="color: ', ';', $row); if ($color == 'orange') { $type = "place"; } elseif ($color == 'green') { $type = "people"; } elseif ($color == 'navy') { $type = "object"; } $content = str_replace('<span="true" style="color: ' . $color, '<span data-graph-' . $type . '="true" style="color: ' . $color, $content); } } $links = Model::GraphLink()->where(['article_id', '=', $id])->where(['article_id', '=', new \MongoId($id)], 'OR')->models(); foreach ($links as $link) { $tab = $link->toArray(); $type = $tab['type']; $search = $tab['search']; switch ($type) { case 'people': $color = 'green'; break; case 'place': $color = 'orange'; break; default: $color = 'navy'; break; } $type = !in_array($type, ['people', 'place', 'object']) ? 'object' : $type; $chunks = explode("data-graph-{$type}", $content); array_shift($chunks); foreach ($chunks as $chunk) { $segment = Utils::cut('>', '</', $chunk); if (!strlen($segment)) { continue; } $data = $link->data(); $pl = Inflector::urlize(isAke($data, 'completename', isAke($data, 'name', ''))); $data_id = $data['id']; if (Inflector::urlize($segment) == Inflector::urlize($search)) { $what = "<span data-graph-{$type}=\"true\" style=\"color: {$color}; font-weight: bold; text-decoration: underline;\">{$segment}</span>"; $by = "<a class=\"graph_{$type}\" href=\"/graph/{$link->id}/{$pl}\">{$segment}</a>"; $content = str_replace($what, $by, $content); $what = "<span data-graph-{$type}=\"true\" style=\"color: {$color}; text-decoration: underline; font-weight: bold;\">{$segment}</span>"; $content = str_replace($what, $by, $content); $what = "<span data-graph-{$type}=\"true\" style=\"text-decoration:underline; color:{$color}; font-weight: bold;\">{$segment}</span>"; $content = str_replace($what, $by, $content); $what = "<em data-graph-{$type}=\"true\" style=\"color: {$color}; font-weight: bold; text-decoration: underline;\">{$segment}</em>"; // $by = "<a class=\"graph_$type\" href=\"/graph/{$link->id}/$pl\">$segment</a>"; $content = str_replace($what, $by, $content); $what = "<em data-graph-{$type}=\"true\" style=\"color: {$color}; text-decoration: underline; font-weight: bold;\">{$segment}</em>"; $content = str_replace($what, $by, $content); $what = "<em data-graph-{$type}=\"true\" style=\"text-decoration:underline; color:{$color}; font-weight: bold;\">{$segment}</em>"; $content = str_replace($what, $by, $content); } else { } } } // while (strstr($content, '<span data-graph-')) { // $cleans = explode('<span data-graph-', $content); // array_shift($cleans); // foreach ($cleans as $tmp) { // $seg = Utils::cut('>', '</span>', $tmp); // list($f, $dummy) = explode('>', $tmp, 2); // $what = '<span data-graph-' . $f . '>' . $seg . '</span>'; // $content = str_replace($what, $seg, $content); // } // } // while (strstr($content, '<em data-graph-')) { // $cleans = explode('<em data-graph-', $content); // array_shift($cleans); // foreach ($cleans as $tmp) { // $seg = Utils::cut('>', '</em>', $tmp); // list($f, $dummy) = explode('>', $tmp, 2); // $what = '<em data-graph-' . $f . '>' . $seg . '</em>'; // $content = str_replace($what, $seg, $content); // } // } $content = str_replace('style="color: navy; font-weight: bold; text-decoration: underline;"', '', $content); $content = str_replace('style="color: orange; font-weight: bold; text-decoration: underline;"', '', $content); $content = str_replace('style="color: green; font-weight: bold; text-decoration: underline;"', '', $content); return $content; }
public static function makeQueryDisplay($queryJs, $type) { $fields = static::getModel($type); $queryJs = substr($queryJs, 9, -2); $query = repl('##', ' AND ', $queryJs); $query = repl('%%', ' ', $query); $query = repl('NOT LIKE', 'ne contient pas', $query); $query = repl('LIKESTART', 'commence par', $query); $query = repl('LIKEEND', 'finit par', $query); $query = repl('LIKE', 'contient', $query); $query = repl('%', '', $query); foreach ($fields as $field => $fieldInfos) { if (strstr($query, $field)) { if (strlen($fieldInfos['content'])) { $seg = Utils::cut($field, " '", $query); $segs = explode(" '", $query); for ($i = 0; $i < count($segs); $i++) { $seg = trim($segs[$i]); if (strstr($seg, $field)) { $goodSeg = trim($segs[$i + 1]); list($oldValue, $dummy) = explode("'", $goodSeg, 2); $content = repl(array('##self##', '##type##', '##field##'), array($oldValue, $type, $field), $fieldInfos['content']); $value = Html\Helper::display(static::internalFunction($content)); $newSeg = repl("{$oldValue}'", "{$value}'", $goodSeg); $query = repl($goodSeg, $newSeg, $query); } } } $query = repl($field, Inflector::lower($fieldInfos['label']), $query); } } $query = repl('=', 'vaut', $query); $query = repl('<', 'plus petit que', $query); $query = repl('>', 'plus grand que', $query); $query = repl('>=', 'plus grand ou vaut', $query); $query = repl('<=', 'plus petit ou vaut', $query); $query = repl(' AND ', ' et ', $query); $query = repl(" '", ' <span style="color: #ffdd00;">', $query); $query = repl("'", '</span>', $query); return $query; }
private function closureParse($closure) { $ref = new \ReflectionFunction($closure); $file = $ref->getFileName(); $start = $ref->getStartLine(); $end = $ref->getEndLine(); $code = File::readLines($file, $start, $end); $infos = Utils::cut('function(', '});', $code); $code = 'function(' . str_replace(["\n", "\r", "\t"], '', $infos) . '}'; return $code; }