function reload($user)
 {
     $lastfacts = DB::get()->val("SELECT value FROM options WHERE name='facts' and grouping = 'misc'");
     if ($lastfacts < mktime(0, 0, 0)) {
         DB::get()->query("SELECT * FROM drawers WHERE indexed = 'facts'");
         $users = DB::get()->col("SELECT id FROM users");
         $zip = new ZipArchive();
         if ($zip->open(dirname(__FILE__) . '/facts.zip') === TRUE) {
             $facts = explode("\n", $zip->getFromName('facts.txt'));
             $zip->close();
             $fact = '<div class="factoidtext">' . $facts[date('z')] . '</div>';
         } else {
             $content = file_get_contents('http://www.mentalfloss.com/amazingfactgenerator/?p=' . date('z'));
             $content = SimpleHTML::str_get_html($content);
             $fact = '<div class="factoidtext">FAIL:' . $content->find('.amazing_fact_body p', 0)->innertext . '</div>';
         }
         $msg = '<a href="#" class="close" onclick="return closedrawer({$drawer_id});">close this drawer</a>' . $fact;
         foreach ($users as $user_id) {
             DB::get()->query("INSERT INTO drawers (user_id, message, indexed, cssclass) VALUES (:user_id, :msg, 'facts', 'factoid');", array('user_id' => $user_id, 'msg' => $msg));
         }
         DB::get()->query("DELETE FROM options WHERE name = 'facts' AND grouping = 'misc'");
         DB::get()->query("INSERT INTO options (name, grouping, value) VALUES ('facts', 'misc', :value);", array('value' => mktime(0, 0, 0)));
     }
     return $user;
 }
Exemple #2
0
 function _twitter($params)
 {
     $user = $params['user'];
     $channel = $params['channel'];
     $query = $params['query'];
     $thtml = file_get_contents('http://twitter.com/' . $query);
     $content = SimpleHTML::str_get_html($thtml);
     $img = $content->find('#profile-image', 0);
     $li = $content->find('li[class=latest-status]', 0);
     $lia = $li->find('a');
     foreach ($lia as $a) {
         $a->href = 'http://twitter.com/' . $a->href;
     }
     $img->width = '48px';
     $img->height = '48px';
     $img->id = '';
     $img->class = "profile_image";
     $output = '<div class="slash">/twitter ' . htmlspecialchars($query) . '</div>';
     $output .= '<div class="twitterstatus">' . $img->outertext . '<a href="http://twitter.com/' . htmlspecialchars($query) . '">' . htmlspecialchars($query) . '</a>' . $li->innertext . '<hr></div>';
     DB::get()->query("INSERT INTO presence (data, user_id, channel, cssclass) VALUES (:msg, :user_id, :channel, 'twitter')", array('msg' => $output, 'user_id' => $user->id, 'channel' => $channel));
     return true;
 }
Exemple #3
0
 function _api($params)
 {
     $user = $params['user'];
     $name = $params['name'];
     $channel = $params['channel'];
     $output = Utils::cmdout($params);
     $searchurl = 'http://api.drupal.org/api/search/6/' . urlencode($name);
     $thtml = file_get_contents($searchurl);
     $content = SimpleHTML::str_get_html($thtml);
     $tbody = $content->find('table[class=sticky-enabled]', 0);
     if (!is_object($tbody)) {
         $code = $content->find('.active code', 0);
         $output .= '<code style="font-size: 1.5em;line-height: 2em"><a target="_blank" href="' . $searchurl . '">Reference</a>:' . $code->innertext . '</code>';
     } else {
         $trs = $tbody->find('tr');
         $modules = '';
         $count = 0;
         array_shift($trs);
         foreach ($trs as $tr) {
             $tds = $tr->find('td');
             $a = $tds[0]->find('a', 0);
             $modules .= '<li><a target="_blank" href="http://drupal.org/' . $a->href . '">' . $a->innertext . '</a>';
             //	$modules .= htmlspecialchars($tds[2]->innertext);
             $modules .= '</li>';
             if (++$count > 9) {
                 break;
             }
         }
         if ($modules != '') {
             $output .= '<ul style="margin-left:30px;">' . $modules . '</ul>';
         } else {
             $output .= '<p>No results.</p>';
         }
     }
     Status::create()->data($output)->user_id($user->id)->cssclass('drupal api')->channel($channel)->insert();
     return true;
 }
Exemple #4
0
 function urlinfo($url)
 {
     $cururl = $url;
     $rcount = 0;
     $location = false;
     do {
         $rcount++;
         $location = false;
         $purl = parse_url($cururl);
         $host = $purl['host'];
         $url = $purl['path'] . ($purl['query'] ? '?' . $purl['query'] : '');
         if ($url == '') {
             $url = '/';
         }
         $port = $purl['port'] ? $purl['port'] : 80;
         $fp = fsockopen($host, $port, $errno, $errstr, 30);
         $ctype = array('', '');
         $getwhole = false;
         if ($fp) {
             $out = "GET {$url} HTTP/1.1\r\n";
             $out .= "Host: {$host}\r\n";
             $out .= "Connection: Close\r\n\r\n";
             fwrite($fp, $out);
             $header = '';
             while (!feof($fp)) {
                 $header .= fgets($fp, 128);
                 if (!$getwhole && preg_match('%\\n\\n|\\r\\r|\\n\\r\\n|\\r\\n\\r%', $header)) {
                     preg_match('%Content-Type:\\s*([^/]+)/([^;\\n]+)%i', $header, $ctype);
                     switch ($ctype[1]) {
                         case 'text':
                             break;
                         case 'application':
                             if (strpos($ctype[2], 'xml') === false) {
                                 break 2;
                             }
                             break;
                         default:
                             break 2;
                     }
                     $getwhole = true;
                 }
             }
             fclose($fp);
             preg_match('%Content-Type:\\s*([^/]+)/([^;\\n]+)%i', $header, $ctype);
             if ($getwhole) {
                 list($header, $content) = preg_split('%\\n\\n|\\r\\r|\\n\\r\\n|\\r\\n\\r%', $header, 2);
                 $content = SimpleHTML::str_get_html($content);
             } else {
                 $content = SimpleHTML::str_get_html('');
             }
             $headers_temp = explode("\n", trim($header));
             $headers = array();
             foreach ($headers_temp as $h) {
                 if (strpos($h, ':') !== false) {
                     list($k, $v) = explode(':', trim($h), 2);
                 } else {
                     $k = 'status';
                     $v = $h;
                 }
                 $headers[strtolower($k)] = trim($v);
             }
             preg_match('%^HTTP/\\d.\\d (?P<code>\\d{3})%i', $headers['status'], $httpstatus);
             if ($httpstatus['code'][0] == '3') {
                 $cururl = $headers['location'];
                 $location = $headers['location'];
             }
         }
     } while ($location && $rcount < 5);
     $result = array('getwhole' => $getwhole, 'headers' => $headers, 'content' => $content, 'ctype' => $ctype, 'cururl' => $cururl, 'status' => $httpstatus['code']);
     $result = array_merge($result, $purl);
     return $result;
 }
 function run($string)
 {
     require_once TOOLKIT . "/class.simplehtml.php";
     $simplehtml = new SimpleHTML();
     return $simplehtml->process($string, NULL, false);
 }