public static function isValidURL($url, $maxlen = 255) { if (Common::startsWith($url, '/')) { return true; } return preg_match("/^[a-zA-Z]+[:\\/\\/]+[A-Za-z0-9\\-_]+\\.+[A-Za-z0-9\\.\\/%&=\\?\\-_]+\$/iD", $url) === 1; }
private function onTag(Slay_Song $song) { $form = $this->formTag($song); if (false !== ($error = $form->validateCSRF_WeakS())) { return $error; } $tags = array(); $errors = array(); foreach ($_POST as $k => $v) { if (Common::startsWith($k, 'tag_')) { $k = substr($k, 4); if (Slay_Tag::getByName($k) === false) { $errors[] = $this->module->lang('err_tag_uk'); } else { $tags[] = $k; } } } if (count($errors) > 0) { return GWF_HTML::error('Slaytags', $errors); } $user = GWF_Session::getUser(); if (false === Slay_TagVote::clearVotes($song, $user)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === Slay_TagVote::addVotes($song, $user, $tags)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === $song->computeTags()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return $this->module->message('msg_tagged'); }
/** * * @todo poll only new revisions and append to changelogfile (extend GDO or modulevar?) * if GDO: repository url dynamically * @todo add to WC Cronjob * @todo rename * @author spaceone */ public static function main() { $svn = new GWF_SvnInfo(); $svn->setRepository('https://svn.gwf3.gizmore.org/GWF3'); $startrev = 422; //292; $logs = $svn->getLog($startrev, $svn->getCurrentRevision()); # Known users and their WeChall profiles $users = array('spaceone' => 'space', 'gizmore' => 'Gizmore'); $back = ''; foreach ($logs as $log) { $comment = $log['comment']; $thx = ''; if (Common::startsWith($comment, 'WC') || false !== strpos(strtolower($comment), 'wechall')) { # TODO: GWF_Date::toString if (0 < preg_match_all('/\\(\\s*?thx +([^\\)]+)\\)/', $comment, $matches)) { foreach ($matches[1] as $match) { foreach (preg_split('/[\\s,;]+/', $match) as $username) { $username = htmlspecialchars(trim($username)); $username = isset($users[$username]) ? $users[$username] : $username; $thx .= sprintf('<a title="%s" href="%sprofile/%s">%s</a>' . PHP_EOL, $username, GWF_WEB_ROOT, $username); } } } # TODO: HTML formatting $creator = isset($users[$log['creator-displayname']]) ? $users[$log['creator-displayname']] : $log['creator-displayname']; $pattern = 'Revision: %s; by <a href="%s/profile/%s">%s</a>; on %s;' . PHP_EOL . ' %s' . PHP_EOL . '%s' . PHP_EOL; $back .= sprintf($pattern, $log['version-name'], GWF_WEB_ROOT, $creator, $creator, $log['date'], str_replace("\n", "\n ", $comment), $thx); } } if (false === file_put_contents(GWF_WWW_PATH . self::$outfile, $back)) { # TODO } }
private function getReplyTitle() { $title = $this->replyThread === true ? $this->thread->getVar('thread_title') : $this->post->getVar('post_title'); if (!Common::startsWith($title, 'RE: ')) { $title = 'RE: ' . $title; } return $title; #return GWF_HTML::display($title); }
private function sanitize() { $this->ipp = $this->module->getHistmsgPerPage(); $channel = Common::getGet('channel', ''); if (Common::startsWith($channel, 'G-')) { $channel = 'G#' . substr($channel, 2); } $this->channel = $this->module->getWhitelistedChannel($channel); $this->nItems = $this->module->countHistoryMessages($this->channel); $this->nPages = GWF_PageMenu::getPagecount($this->ipp, $this->nItems); $this->page = Common::clamp((int) Common::getGet('page', $this->nPages), 1, $this->nPages); }
private function getLanguageFilesR($iso, $path, array &$files) { if (false === ($dir = dir($path))) { return; } while (false !== ($entry = $dir->read())) { $fullpath = $path . '/' . $entry; if (Common::startsWith($entry, '.')) { } elseif (is_dir($fullpath)) { $this->getLanguageFilesR($iso, $fullpath, $files); } elseif (preg_match("/.+_{$iso}.php\$/D", $entry)) { $files[] = $fullpath; } } $dir->close(); }
public static function populateRec($basedir, $path) { if (false === ($dir = dir($path))) { return false; } while (false !== ($entry = $dir->read())) { if (Common::startsWith($entry, '.')) { continue; } $fullpath = $path . '/' . $entry; if (is_dir($fullpath)) { self::populateRec($basedir, $fullpath); } else { self::populateFile($basedir, $fullpath); } } }
public static function install(Module_Admin $module, $dropTables) { // if ($module->cfgRobotUsers() === false) { // return ''; // } $users = GDO::table('GWF_User'); $users->deleteWhere("user_name LIKE '[%]'"); printf('Deleted %d bots.<br/>', $users->affectedRows()); GDO::table('GWF_Webspider')->createTable(true); $filename = GWF_CORE_PATH . 'module/Admin/' . self::SPIDER_FILE; if (false === ($fh = fopen($filename, 'r'))) { return GWF_HTML::err('ERR_FILE_NOT_FOUND', $filename); } $ips = array(); $botname = ''; while (true) { if (false === ($line = fgets($fh))) { break; } $line = trim($line); if ($line === '' || Common::startsWith($line, '#')) { continue; } if (Common::startsWith($line, '[')) { if ($botname !== '') { self::install_spider($botname, $ips); } $line = trim($line, '[]'); $botname = $line; $ips = array(); echo "SWITCHING TO NEXT BOT: {$line}<br/>"; } else { $ips[] = $line; } } if ($botname !== '') { self::install_spider($botname, $ips); $ips = array(); } fclose($fh); return ''; }
private static function parseSudoshRow(Module_Audit $module, $row, $fh2) { // echo $row; if (false === ($row2 = Common::substrFrom($row, '-sudosh: ', false))) { return self::error('Invalid line: ' . $row); } elseif (Common::startsWith($row2, 'created')) { return self::parseSudoCreated($module, $row2); } elseif (Common::startsWith($row2, 'destroyed')) { return self::parseSudoDestroyed($module, $row2); } elseif (Common::startsWith($row2, 'st')) { return true; # skip } elseif (false === ($id = Common::substrUntil($row2, ':', false))) { return self::error('Invalid line: ' . $row); } elseif (false === ($row2 = Common::substrFrom($row2, ':', false))) { return self::error('Invalid line: ' . $row); } else { return self::appendToLog($module, $id, $row2); } }
private function gatherFilesRec($path) { if (false === ($dir = dir($path))) { echo GWF_HTML::err('ERR_FILE_NOT_FOUND', array($path)); return false; } while (false !== ($entry = $dir->read())) { if (Common::startsWith($entry, '.')) { continue; } $fullpath = $path . '/' . $entry; if (is_dir($fullpath)) { $this->gatherFilesRec($fullpath); } elseif (1 === preg_match('/_([a-z]{2})\\.php$/D', $entry, $matches)) { $iso = $matches[1]; $this->files[] = array($fullpath, $this->isBranched($fullpath), GWF_LangFile::getByPath($fullpath), $iso, $entry); } else { // echo "SKIP ".$fullpath; } } return true; }
/** * Removes all cookies in a directory * @param int $time one week * @param string $path * @author spaceone **/ public static function cleanupCookies($time = 604800, $path = self::COOKIE_PATH) { if (false === ($files = scandir($path))) { return false; } $ret = true; foreach ($files as $file) { if (true === Common::startsWith($dir, self::COOKIE_PREFIX) && false === is_dir($path . $file) && filemtime($path . $file) <= time() - $time) { if (false === unlink($path . $file)) { $ret = false; } } } return $ret; }
private function getFormTitle() { if ($this->pm === false) { return ''; } else { $re = $this->module->cfgRE(); $old = $this->pm->getVar('pm_title'); return Common::startsWith($old, $re) ? $old : $re . $old; } }
private function isLockingCommand($command) { $c = strtolower($command); if (Common::startsWith($c, '#')) { return true; } if (Common::startsWith($c, 'attack')) { return true; } if (Common::startsWith($c, 'idle')) { return true; } if (Common::startsWith($c, 'fl')) { return true; } // if (Common::startsWith($c, 'flee')) // { // return true; // } return false; }
private function getDescription($url) { # Get page content # TODO: Only download .txt and .html content! GWF_HTTP::setTimeout(10); GWF_HTTP::setConnectTimeout(3); $content = GWF_HTTP::getFromURL($url, true); GWF_HTTP::setTimeout(); GWF_HTTP::setConnectTimeout(); if ($content === false) { Dog_Log::error('Mod_Link::getDescription(): getFromURL() failed. URL: ' . $url); return false; } list($head, $content) = preg_split("/[\r\n]{4}/", $content, 2); $type = Common::regex('/Content-Type: *(.*)/Di', $head); echo $type . PHP_EOL; if (Common::startsWith($type, 'image')) { return array('image', $content); } # Get Title from html if (0 === preg_match('#< *title *>([^<]+)< */ *title *>#i', $content, $matches)) { return false; } $title = $this->decode($matches[1]); $descr = ''; if (1 === preg_match('#(< *meta.*description[^>]*>)#i', $content, $matchesB)) { $tag = $matchesB[1]; if (1 === preg_match('#content=["\']([^"\']+)["\']#', $tag, $matchesB)) { $descr = ' - ' . $this->decode($matchesB[1]); } } return array('html', $title . ' - ' . $descr); }
public function getProfileURL($onsitename) { $profile_part = $this->replaceURL($this->getVar('site_url_profile'), urlencode($onsitename)); if (Common::startsWith($profile_part, 'http')) { return $profile_part; } return $this->getVar('site_url') . '/' . $profile_part; }
/** * Get the config vars from ####conf string. * @see Dog_Vars * @return array */ public function getConfigVars() { static $MAGIC = '####conf '; $row = false; if (false !== ($fh = fopen($this->path, 'r'))) { while (false !== ($row = fgets($fh))) { if (Common::startsWith($row, $MAGIC)) { break; } } fclose($fh); } return $row === false ? array() : Dog_Var::parseConfigVars(trim(substr($row, strlen($MAGIC))), NULL, $this->name); }
private function onCheckRecursive($path) { if (false === ($dir = dir($path))) { return; } while (false !== ($entry = $dir->read())) { if (Common::startsWith($entry, '.')) { continue; } $fullpath = $path . '/' . $entry; $fullisopath = $path . '/' . substr($entry, 0, -7) . sprintf('_%s.php', $this->lang->getISO()); if (is_dir($fullpath)) { if ($entry === 'lang') { $this->locateBaseFile($fullpath); } if (in_array(GWF_Debug::shortpath(realpath($fullpath)), $this->dirsToSkip)) { continue; } $this->onCheckRecursive($fullpath); } elseif (Common::endsWith($entry, '_en.php')) { $this->onCheckFile($fullisopath); } } }
public function loadTriggers() { // $this->triggers = array(); $s = array('UP', 'DOWN', 'ADD', 'REMOVE'); $r = array('++', '--', '+', '-'); foreach (get_class_methods(get_class($this)) as $method) { if (Common::startsWith($method, 'on_')) { $trigger = substr($method, 3); // Cut off 'on_' $trigger = Common::substrUntil($trigger, '_', $trigger, true); // Cut off privabcdef $trigger = str_replace($s, $r, $trigger); // replace special chars $this->triggers[$trigger] = $method; } } }
public function displayText($class = '') { $href = $this->getVar('link_href'); if (Common::startsWith($href, '/')) { $href = GWF_WEB_ROOT . substr($href, 1); } $class = $class === '' ? '' : ' class="' . $class . '"'; return sprintf('<a%s href="%s" onclick="%s">%s</a>', $class, GWF_HTML::display($href), $this->getOnClick(), $this->display('link_descr')); }
public function targetExists($target) { if ($target === '') { return true; } if (Common::startsWith($target, self::$GUEST_PREFIX)) { return $this->isNameTaken($target); } return GWF_User::getByName($target) !== false; }
public function onMessage(IWebSocketConnection $user, IWebSocketMessage $msg) { $this->say("[DEMO] {$user->getId()} says '{$msg->getData()}'"); $message = $msg->getData(); if (Common::startsWith($message, 'XLIN')) { $this->onLogin($user, $message); } elseif (false !== ($dog_user = $this->isLoggedIn($user))) { $this->addToQueue($user, $dog_user, $message); } else { $this->say("XLIN4"); } }
} 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! :('); } } }
/** * Check if mimetype is image * @param unknown_type $mime * @return unknown_type */ public static function isImageMime($mime) { return Common::startsWith($mime, 'image/'); }
public function onZipC() { # Create ZIP $archive = new GWF_ZipArchive(); chdir(GWF_PATH); $archivename = $this->getArchiveName(); if (false === $archive->open($archivename, ZipArchive::CREATE | ZipArchive::CM_REDUCE_4)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # ZIP STUFF # Core if (false === $this->zipDir($archive, 'core/inc')) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # ZIP Module(Groups) foreach ($_POST as $group => $checked) { if (!Common::startsWith($group, 'mod_')) { continue; } # zip dir recursive, do not ignore style if (false === $this->zipDir($archive, 'core/module/' . substr($group, 4), true, false)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } } # 3rd Party Core // if (false === ($this->zipDir($archive, 'inc3p'))) { // return $this->module->error('err_zip', array(__FILE__, __LINE__)); // } # Smarty // if (false === ($this->zipDir($archive, 'smarty_lib'))) { // return $this->module->error('err_zip', array(__FILE__, __LINE__)); // } # JS if (false === $this->zipDir($archive, 'www/js')) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Installer if (false === $this->zipDir($archive, 'www/install')) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Base Lang if (false === $this->zipDir($archive, 'core/lang')) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Images if (false === $this->zipDir($archive, 'www/img', false)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } // if (false === ($this->zipDir($archive, 'img/default/country', false))) { // return $this->module->error('err_zip', array(__FILE__, __LINE__)); // } // if (false === ($this->zipDir($archive, 'img/default/smile', false))) { // return $this->module->error('err_zip', array(__FILE__, __LINE__)); // } # Temp if (false === $this->addEmptyDirs($archive, self::$tempdirs)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Fonts if (false === $this->zipDir($archive, 'extra/font')) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Templates if (false === $this->zipDir($archive, 'www/tpl', true, false)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Root Files if (false === $this->addFiles($archive, self::$rootfiles)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Protected Dirs // if (false === $this->zipDirs($archive, self::$protected_dirs)) { // return $this->module->error('err_zip', array(__FILE__, __LINE__)); // } # Protected Files if (false === $this->addFiles($archive, self::$protected_files)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Module Extra Files and Dirs if (false === $this->zipDirs($archive, $this->getModuleExtraDirs())) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } if (false === $this->addFiles($archive, $this->getModuleExtraFiles())) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } // chdir(GWF_WWW_PATH); $total_files = $archive->getTotalFilesCounter(); if (false === $archive->close()) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } $this->has_error = false; return $this->module->message('msg_zipped', array($archivename, GWF_Upload::humanFilesize(filesize($archivename)), $total_files)); }
private function setupFeed(Dog_NewsFeed $feed, $content) { if (!Common::startsWith($content, '<?xml')) { Dog_Log::error('Feed does not start with <?xml'); return false; } if (false === ($xml = simplexml_load_string($content))) { Dog_Log::error('Feed is not valid XML!'); return false; } $a = $xml->attributes(); $version = (string) $a['version']; switch ($version) { case '2.0': $rss_version = Dog_NewsFeed::RSS_20; break; default: Dog_Log::error(sprintf('RSS Version %s is not supported!', $version)); return false; } if (!isset($xml->channel->title) || (string) $xml->channel->title === '') { Dog_Log::error('Feed channel has no title!'); return false; } $feed->setVar('lnf_name', (string) $xml->channel->title); $feed->setOption($rss_version, true); return true; }