function _remap($pluginname = '', $params = array()) { if (empty($pluginname) or !is_dir($this->plugin_folder . 'src/' . $pluginname)) { show_error("Plugin not found"); } else { # cek file controller if (!is_file($this->plugin_folder . 'src/' . $pluginname . '/func_controller.php')) { show_error('File func_controller.php not exist.'); } include $this->plugin_folder . 'src/' . $pluginname . '/func_controller.php'; # jika kosong ambil index if (empty($params[0])) { $params[0] = 'index'; } # check function exist if (!function_exists($params[0])) { show_404(); } # cek jika ada function construct, selalu panggil fungsi itu duluan # biasanya untuk keperluan cek session pengguna plugin if (function_exists('construct')) { construct(); } $copy_param = $params; unset($copy_param[0]); # redinex $copy_param = array_values($copy_param); call_user_func_array($params[0], $copy_param); } }
/** * Создаёт заказ по данным из mysql * * @param array $data данные из mysql * * @return &array объект заказа */ function &unserializeFromMysql(array $data) { $Order =& construct(); setId($Order, $data['id']); setPrice($Order, $data['price']); setText($Order, $data['text']); return $Order; }
function libProject($lib, $args = null) { $lib = strtolower(Inflector::uncamelize($lib)); $script = str_replace('_', DS, $lib) . '.php'; if (fnmatch('*_*', $lib)) { $class = 'Thin\\' . str_replace('_', '\\', $lib); $tab = explode('\\', $class); $first = $tab[1]; $class = str_replace('Thin\\' . $first, 'Thin\\' . ucfirst($first) . 'Project', $class); if (count($tab) > 2) { for ($i = 2; $i < count($tab); $i++) { $seg = trim($tab[$i]); $class = str_replace('\\' . $seg, '\\' . ucfirst($seg), $class); } } } else { $class = 'Thin\\' . ucfirst($lib) . 'Project'; } $file = path('module') . DS . 'classes' . DS . $script; if (file_exists($file)) { require_once $file; if (empty($args)) { return new $class(); } else { if (!is_array($args)) { if (is_string($args)) { if (fnmatch('*,*', $args)) { $args = explode(',', str_replace(', ', ',', $args)); } else { $args = [$args]; } } else { $args = [$args]; } } $methods = get_class_methods($class); if (in_array('instance', $methods)) { $check = new \ReflectionMethod($class, 'instance'); if ($check->isStatic()) { return call_user_func_array([$class, 'instance'], $args); } } else { return construct($class, $args); } } } if (class_exists('Thin\\' . $lib)) { $c = 'Thin\\' . $lib; return new $c(); } if (class_exists($lib)) { return new $lib(); } throw new Exception("The Project {$class} does not exist."); }
/** * Construct single Sweet, transform from Twitter API * @param array $tweet * @param boolean $position (left: FALSE, right: TRUE) * @return array */ function construct($tweet, $position = FALSE) { // Display time $current = strtotime($tweet['created_at']); $date_format = date('z', $current) === date('z', time()) ? 'G:i' : 'j M'; if (date('Y', $current) !== date('Y', time())) { $date_format .= ' y'; } // Basic Structure $output = array('position' => $position ? 'right' : 'left', 'id' => $tweet['id_str'], 'rel_time' => date($date_format, $current), 'abs_time' => date('G:i - j M y', $current), 'text' => $tweet['text'], 'source' => $tweet['source'], 'user' => array('screen_name' => $tweet['user']['screen_name'], 'name' => $tweet['user']['name'], 'avatar' => $tweet['user']['profile_image_url']), 'retweeted' => NULL, 'geo' => $tweet['geo'], 'photo' => NULL); // Detect Twitter photos if (!empty($tweet['entities']['media'])) { foreach ($tweet['entities']['media'] as $m) { $output['photo'] = $m['media_url']; $output['text'] = str_replace($m['url'], NULL, $output['text']); } } // Replace links and detect Instagram photos if (!empty($tweet['entities']['urls'])) { $u_search = array(); $u_replace = array(); foreach ($tweet['entities']['urls'] as $u) { $u_search[] = $u['url']; $u_replace[] = '<a href="' . $u['expanded_url'] . '">' . $u['display_url'] . '</a>'; if (preg_match_all('#instagr\\.am\\/p\\/([_-\\d\\w]+)#i', $u['expanded_url'], $matches, PREG_PATTERN_ORDER) > 0) { foreach ($matches[1] as $match) { $output['photo'] = sprintf('http://instagr.am/p/%s/media/?size=l', $match); } } } $output['text'] = trim(str_replace($u_search, $u_replace, $output['text'])); } // Construct retweeted status if (isset($tweet['retweeted_status'])) { $output['retweeted'] = construct($tweet['retweeted_status'], TRUE); } return $output; }
//--- check if lable already exists in $labelsDir if ($orderId > 0 && file_exists($labelsDir . "/ups_label_{$orderId}.gif")) { // load existing image $gifName = $labelsDir . "/ups_label_{$orderId}.gif"; $resultImage = file_get_contents($gifName); // header("Content-type: " . image_type_to_mime_type(IMAGETYPE_GIF)); // echo $resultImage; header("Content-type: " . image_type_to_mime_type(IMAGETYPE_PNG)); $img = imagecreatefromstring($resultImage); $img = imagerotate($img, -90, 0); imagegif($img); exit; } //--- init // $ch = curl_init(); construct($tempDir4Cookies); // //--- make start page for cookies $response = request("http://ups.com/content/us/en/index.jsx", null, "get"); //--- login $post = array("sret" => "http://ups.com/content/us/en/index.jsx", "uret" => "http://ups.com/content/us/en/index.jsx", "ctxcc" => "en_US", "userid" => $userId, "password" => $userPassword); foreach ($post as $pk => $pv) { $postItems[] = "{$pk}=" . urlencode($pv); } $response = request("https://wwwapps.ups.com/cclamp/login", implode("&", $postItems), "post", $ref = 'http://ups.com/content/us/en/index.jsx'); if (strpos($response, "Welcome,") === false) { $logText .= "Login page: CAN'T LOGIN:<br>"; $occuredError = true; } else { $logText .= "Login page: LOGGED IN OK.\n<br>\n"; }
function keyMap($combiner, $in, $keys = null) { if (!empty($in)) { if (!isset($keys)) { $keys = array_keys($in); $in = array_values($in); } return construct(fa($combiner, array(first($keys), first($in))), keyMap($combiner, rest($in), rest($keys))); } else { return array(); } //takes a combiner function }
/** * Создаёт исполнителя по данным из mysql * * @param array $data данные из mysql * * @return &array объект исполнителя */ function &unserializeFromMysql(array $data) { $Executor =& construct(); setId($Executor, $data['id']); setFio($Executor, $data['fio']); setSalary($Executor, $data['salary']); setLogin($Executor, $data['login']); return $Executor; }
include_once 'config.php'; include_once 'libs/twitter.php'; include_once 'common.php'; $max_id = isset($_GET['max_id']) ? minus_one($_GET['max_id']) : NULL; $content = array(); $connection = new TwitterOAuth($config['consumer_key'], $config['consumer_secret'], $config['access_token'], $config['access_token_secret']); $post_data = array('screen_name' => $config['user_a'], 'count' => $config['count'], 'since_id' => $config['since_id'], 'include_rts' => true, 'include_entities' => true, 'exclude_replies' => true); if (!is_null($max_id)) { $post_data['max_id'] = $max_id; } $timeline = $connection->get('statuses/user_timeline', $post_data); if (isset($timeline['error'])) { response(array('error' => $timeline['error']), 404); } if (!empty($timeline)) { foreach ($timeline as $tweet) { $content[$tweet['id_str']] = construct($tweet); } } $post_data['screen_name'] = $config['user_b']; $timeline = $connection->get('statuses/user_timeline', $post_data); if (isset($timeline['error'])) { response(array('error' => $timeline['error']), 404); } if (!empty($timeline)) { foreach ($timeline as $tweet) { $content[$tweet['id_str']] = construct($tweet, TRUE); } } krsort($content); response(array_values($content));
function execute() { global $path; construct($path); }
function write_ctp($in, $out_file, $options = array()) { if (!isset($options["offset"])) { $options["offset"] = "0"; } $offset = $options["offset"] + 0; $force = $options["force"]; // データベーススキーマを収集する。 $schema = array(); while (($line = fgets($in)) !== false) { // "# ワークシート名"はワークシートの先頭行を示す。 if (substr($line, 0, 1) != "#") { continue; } $table = trim(substr($line, 1)); $records = array(); $row = 0; while (($record = fgetcsv($in, 65536, ",", '"')) !== FALSE) { // 空行はワークシートの最終行を示す。 if ($record == array('')) { break; } $tag = array_shift($record); $record = array_slice($record, $offset); $num_cols = count($record); switch ($tag) { case "fields": $fields = $record; break; case "types": $types = $record; break; case "params": $params = $record; break; case "titles": $titles = $record; break; case "record": $records[] = $record; break; default: $contents = implode(",", $record); fputs(STDERR, "Warning: unkown tag[{$tag}]. {$contents}\n"); return; } $row += 1; } // 決め打ち。改良が必要。 for ($col = 5; $col < count($records[0]); $col++) { $field = $records[3][$col]; for ($row = 2; $row < count($records); $row++) { $key = $records[$row][0]; $value = $records[$row][$col]; $schema[$table][$field][$key] = $value; } } } // テンプレートのあるディレクトリと出力ディレクトリを決める。 $template_dirs = array(); $template_dirs[] = "./ctp_templates/"; $template_dirs[] = dirname(__FILE__) . "/ctp_templates/"; $instance_dirs = array(); $instance_dirs[] = "./schema/"; $template_dir = ""; foreach ($template_dirs as $dir) { if (file_exists($dir)) { $template_dir = $dir; break; } } if ($template_dir == "") { fputs(STDERR, "Error: Template directory does not exist.\n"); return; } $instance_dir = ""; foreach ($instance_dirs as $dir) { if (file_exists($dir)) { $instance_dir = $dir; break; } } if ($instance_dir == "") { if (mkdir("./schema/", 0700)) { $instance_dir = "./schema/"; } else { fputs(STDERR, "Error: Output directory does not exist.\n"); return; } } // コードを生成する。 foreach ($schema as $table => $detail) { $in_dir = $template_dir; $out_dir = "{$instance_dir}/" . Inflector::camelize($table); if (!file_exists($out_dir)) { mkdir($out_dir); } $in_ext = "ctp"; $out_ext = "ctp"; $templates = preg_grep("/^\\w+\\.{$in_ext}\$/", scandir($template_dir)); foreach ($templates as $template) { $filename = pathinfo($template, PATHINFO_FILENAME); $in_file = "{$in_dir}/{$filename}.{$in_ext}"; $out_file = "{$out_dir}/{$filename}.{$out_ext}"; $s = construct(file_get_contents($in_file), $schema, $table); if (file_exists($out_file) && !$force) { fputs(STDERR, "Error: Already [{$out_file}] exists. Use -f option to overwrite it.\n"); return; } file_put_contents($out_file, $s); } } return; }