/** * Append the new uploaded file to the content. * @param string $name * @param string $path * @return string html content */ private static function fileToContent($name, $path, $bbcode) { $image_ext = array('.png', '.jpg', '.jpeg', '.bmp', '.tiff', '.gif'); foreach ($image_ext as $ext) { if (Common::endsWith($name, $ext)) { return self::fileToIMG($name, $path, $bbcode); } } return self::fileToAnchor($name, $path, $bbcode); }
public static function installModule(Dog_Module $module, $flush_tables) { $path = $module->getTablePath(); if (Common::isDir($path)) { foreach (scandir($path) as $filename) { if (Common::endsWith($filename, '.php')) { GDO::table(substr($filename, 0, -4))->createTable($flush_tables); } } } $module->onInstall($flush_tables); }
public function onUpload(WC_Challenge $chall) { $module = Module_WeChall::instance(); $form = $this->getForm($chall); if (false === ($file = $form->getVar('image'))) { return GWF_HTML::error('Smile', array($chall->lang('err_no_image'))); } if (!GWF_Upload::isImageFile($file)) { return GWF_HTML::error('Smile', array($chall->lang('err_no_image'))); } if (false === GWF_Upload::resizeImage($file, 64, 64, 16, 16)) { return GWF_HTML::error('Smile', array($chall->lang('err_no_image'))); } $whitelist = array('.jpg', '.jpeg', '.gif', '.png'); $filename = $file['name']; $allowed = false; foreach ($whitelist as $allow) { if (Common::endsWith($filename, $allow)) { $allowed = true; break; } } if (strpos($filename, '.php') !== false) { $allowed = false; } if (!preg_match('/^[\\x00-\\x7f]+$/D', $filename)) { return GWF_HTML::error('Smile Path', array($chall->lang('err_ascii'))); } if (!$allowed) { return GWF_HTML::error('Smile', array($chall->lang('err_no_image'))); } $fullpath = "challenge/livinskull/smile/smiles/{$filename}"; $efp = htmlspecialchars($fullpath); if (false === ($file = GWF_Upload::moveTo($file, $fullpath))) { return GWF_HTML::err('ERR_WRITE_FILE', array($efp)); } $efp = htmlspecialchars($fullpath); $rule = htmlspecialchars("<img src=\"/{$efp}\" />"); return GWF_HTML::message('Smile', $chall->lang('msg_uploaded', array($rule))); }
private function isFileWanted($entry) { if (Common::endsWith($entry, '.zip')) { return false; } if (Common::endsWith($entry, '.jar')) { return false; } return true; }
} elseif (!$plug->isEnabled($serv, $chan)) { Dog::rply('err_disabled'); } else { $plug->execute(); } } elseif (false !== ($mod = Dog_Module::getByTrigger($trigger))) { if (!$mod->hasScopeFor($trigger, $serv, $chan)) { Dog::scopeError($mod->getScope($trigger)); } if (!$mod->hasPermissionFor($trigger, $serv, $chan, $user)) { Dog::permissionError($mod->getPriv($trigger)); } elseif (!$mod->isTriggerEnabled($serv, $chan, $trigger)) { Dog::rply('err_disabled'); } else { $mod->execute($trigger); } } else { // Dog::rply('err_command'); } } } elseif (Common::startsWith($msg, "") && Common::endsWith($msg, "")) { require 'CTCP.php'; } else { $msg = preg_replace('[^a-z]', '', $msg); if ($msg === 'wechallnetISUP') { Dog::reply('Yay \\o/'); } elseif ($msg === 'wechallnetISUP') { Dog::reply('NO! :('); } } }
public function getDefDis($trigger) { return Common::endsWith($this->getFunc($trigger), 'x') ? '1' : '0'; }
public static function getAllMethods(GWF_Module $module) { $back = array(); $name = $module->getName(); $path = GWF_CORE_PATH . "module/{$name}/method"; if (!Common::isDir($path)) { return array(); } if (false === ($dir = scandir($path))) { GWF3::logDie('Cannot access ' . $path . ' in ' . __METHOD__ . ' line ' . __LINE__); } foreach ($dir as $file) { # starts with . if ($file[0] === '.' || false === Common::endsWith($file, '.php')) { continue; } $path2 = $path . '/' . $file; if (Common::isFile($path2)) { if (false === ($method = $module->getMethod(substr($file, 0, -4)))) { GWF3::logDie('NO METHOD for ' . $file); } $back[] = $method; } } return $back; }
private static function validateMissingVars($context, GWF_Form $form, $validator) { $errors = array(); $check_sent = $form->getMethod() === GWF_Form::METHOD_POST ? $_POST : $_GET; $check_need = array(); // var_dump($_POST); foreach ($form->getFormData() as $key => $data) { if (in_array($data[0], self::$SKIPPERS, true)) { unset($check_sent[$key]); continue; } switch ($data[0]) { case GWF_Form::VALIDATOR: break; case GWF_Form::SELECT_A: unset($check_sent[$key]); break; case GWF_Form::TIME: $check_need[] = $key . 'h'; $check_need[] = $key . 'i'; break; case GWF_Form::DATE: case GWF_Form::DATE_FUTURE: switch ($data[4]) { case 14: $check_need[] = $key . 's'; case 12: $check_need[] = $key . 'i'; case 10: $check_need[] = $key . 'h'; case 8: $check_need[] = $key . 'd'; case 6: $check_need[] = $key . 'm'; case 4: $check_need[] = $key . 'y'; break; default: die('Date field is invalid in form!'); } break; case GWF_Form::SUBMITS: case GWF_Form::SUBMIT_IMGS: foreach (array_keys($data[1]) as $key) { // if (false !== ($i = array_search($key, $check_sent, true))) { // unset ($check_sent[$i]); // } unset($check_sent[$key]); } break; case GWF_Form::FILE: if (false === GWF_Upload::getFile($key)) { $check_need[] = $key; } break; case GWF_Form::INT: case GWF_Form::STRING: if (Common::endsWith($key, ']')) { $key = Common::substrUntil($key, '['); if (!in_array($key, $check_need)) { $check_need[] = $key; } break; } default: $check_need[] = $key; break; } } // var_dump($check_need); foreach ($check_need as $key) { if (!isset($check_sent[$key])) { $errors[] = GWF_HTML::lang('ERR_MISSING_VAR', array(htmlspecialchars($key))); } else { unset($check_sent[$key]); } } foreach ($check_sent as $key => $value) { $errors[] = GWF_HTML::lang('ERR_POST_VAR', array(htmlspecialchars($key))); } return count($errors) === 0 ? false : $errors; }
private function locateBaseFile($path) { $dir = dir($path); while (false !== ($entry = $dir->read())) { if (Common::endsWith($entry, '_en.php')) { return; } } $this->MissingFile['en'][] = $path; $this->missing['en']++; }
<?php $lang = array('en' => array('help' => 'Usage: %CMD% <number>. Check if input is a fibonnaci number.')); $plugin = Dog::getPlugin(); $argv = $plugin->argv(); if (count($argv) !== 1) { return $plugin->showHelp(); } $arg = $argv[0]; if (Common::endsWith($arg, '0')) { Dog::reply('Yes!'); } else { Dog::reply('No!'); }