function fetchFunctionDescription($func, $language = 'en') { global $message, $redirects; $notfoundtext = 'Nothing matches your query, try search:'; Dog_Log::debug('phpmanual: fetching ' . $func . ' info'); $res = GWF_HTTP::getFromUrl('http://' . ($language != 'en' ? $language . '.' : '') . 'php.net/' . $func, false, 'LAST_LANG=' . $language); if ($res === false) { return 'Timeout on contacting ' . ($language != 'en' ? $language . '.' : '') . 'php.net'; } if (preg_match('/<span class=\\"refname\\">(.*?)<\\/span> — <span class=\\"dc\\-title\\">(.*?)<\\/span>/si', $res, $match)) { $match[2] = str_replace(array("\n", "\r"), ' ', strip_tags($match[2])); preg_match('/<div class=\\"methodsynopsis dc\\-description\\">(.*?)<\\/div>/si', $res, $descmatch); $decl = isset($descmatch[1]) ? strip_tags($descmatch[1]) : $match[1]; $decl = html_entity_decode(str_replace(array("\n", "\r"), ' ', $decl)); $decl = str_replace($func, "" . $func . "", $decl); $output = $decl . ' - ' . html_entity_decode($match[2]) . ' ( http://' . ($language != 'en' ? $language . '.' : '') . 'php.net/' . $func . ' )'; } else { // if several possibilities $output = ''; if (preg_match_all('/<a href=\\"\\/manual\\/[a-z]+\\/(?:.*?)\\.php\\">(?:<b>)?(.*?)(?:<\\/b>)?<\\/a><br/i', $res, $matches, PREG_SET_ORDER)) { if ($redirects++ < 2) { return fetchFunctionDescription($matches[0][1]); } else { return $notfoundtext . ' http://' . ($language != 'en' ? $language . '.' : '') . 'php.net/search.php?show=wholesite&pattern=' . $message; } } else { $output = $notfoundtext . ' http://' . ($language != 'en' ? $language . '.' : '') . 'php.net/search.php?show=wholesite&pattern=' . $func; } } return $output; }
function getWikiText($term, $wikiurl, $notfound) { $term = str_replace(" ", "_", $term); $term[0] = strtoupper($term[0]); $content = GWF_HTTP::getFromUrl($wikiurl . str_replace("%23", "#", urlencode($term))); if ($content === false || stristr($content, $notfound)) { return false; } $pos = strpos($content, '<div id="contentSub">'); $content = substr($content, $pos); $content = preg_replace("#<tr.*?</tr>#", '', $content); $content = str_replace("</li>", ",</li>", $content); preg_match_all("#<(p|li)>(.*?)</(p|li)>#", $content, $arr); $content = ""; foreach ($arr[2] as $row) { $row = trim(strip_tags($row)); if (!empty($row)) { $content .= $row . " "; } } $content = html_entity_decode($content); $content = str_replace(chr(160), " ", $content); $output['text'] = $content; $output['link'] = $wikiurl . urlencode($term); return $output; }
function getRandomRadio($term) { $term = str_replace(" ", "+", $term); $url = 'http://hagbard.host-ed.me/intranet/radio.php?out=inline&shuffle=true&limit=1&search=' . urlencode($term); $content = GWF_HTTP::getFromUrl($url . str_replace("%23", "#", urlencode($term)) . '*'); if ($content === false || strlen($content) == 0) { return false; } echo $content . PHP_EOL; $temp = explode('|', $content, 2); return array(Common::substrFrom($temp[1], ') ', $temp[1]), $temp[0]); }
function fetchDefinitionE(Dog_Plugin $plugin, $term) { $output = array(); $res = GWF_HTTP::getFromUrl('http://www.urbandictionary.com/define.php?term=' . $term); if ($res === false) { return Dog::lang('err_timeout'); } if (strstr($res, "isn't defined <a href")) { return $plugin->lang('none_yet', array($term, urlencode($term))); } preg_match('#<div class=\'meaning\'>(.+?)</div>.*?<div class=\'example\'>(.*?)</div>#s', $res, $arr); $definition = trim(html_entity_decode(strip_tags(preg_replace('#<\\s*?br\\s*?/?\\s*?>#', "\n", $arr[1])))); $definition = strtr($definition, array("\r" => ' ', "\n" => ' ')); while (false !== strstr($definition, ' ')) { $definition = str_replace(' ', ' ', $definition); } if (strlen($definition) > 800) { $definition = substr($definition, 0, 800) . '...'; } $output['definition'] = $definition; if (!empty($arr[2])) { $example = trim(html_entity_decode(strip_tags(preg_replace('#<\\s*?br\\s*?/?\\s*?>#', "\n", $arr[2])))); $example = strtr($example, array("\r" => ' | ', "\n" => ' | ')); while (false !== strstr($example, ' | | ')) { $example = str_replace(' | | ', ' | ', $example); } while (false !== strstr($example, ' ')) { $example = str_replace(' ', ' ', $example); } if (strlen($example) > 800) { $example = substr($example, 0, 800) . '...'; } $output['example'] = $example; } return $output; }