root/devel/mod/explodeping/lib.php

Revision 1539, 4.9 kB (checked in by renato, 10 months ago)

Setting prop svn:eol-style in LOTS of files.

  • Property svn:eol-style set to native
Line 
1 <?php
2
3     /*
4      * Explode pinger
5      * This periodically lets the Explode service know that this site exists,
6      * but will refuse to run if walled garden restrictions are enabled.
7      * You can delete this module with no ill effects, simply by removing
8      * the whole /mod/explodeping/ directory.
9      */
10     
11      function explodeping_pagesetup() {
12      }
13     
14      /*
15       * Checks to see if we've pinged Explode yet; if not, sends information
16       * about the URL and so on, and gets a service number and key back.
17       * If it has, sends another ping every two weeks with the most active
18       * user and the key, in order to instigate crawling.
19       * @uses $CFG;
20       */
21      function explodeping_init() {
22          global $CFG, $messages;
23
24          // FIXME: workaround to annoying warning when is enabled open_basedir
25          // restriction
26          if (@ini_get('open_basedir') || !ini_get_bool('allow_url_fopen')) { return;}
27
28          if (!$explodeservice = get_record('datalists', 'name', 'explodeservice')) {
29             
30              ini_set('default_socket_timeout', 20);
31             
32              $pingvars = "pingtype=registernew";
33              $pingvars .= "&url=" . urlencode($CFG->wwwroot);
34              $pingvars .= "&profileurl=" . urlencode($CFG->wwwroot . "%username%");
35              $pingvars .= "&name=" . urlencode($CFG->sitename);
36              $pingvars .= "&rssurl=" . urlencode($CFG->wwwroot . "%username%/rss");
37              $pingvars .= "&foafurl=" . urlencode($CFG->wwwroot . "%username%/foaf");
38              $pingresponse = file_get_contents("http://ex.plode.us/mod/searchping/elggping.php?{$pingvars}");
39             
40              if (user_flag_get("admin",$_SESSION['userid'])) {
41                  $messages[] = str_replace("&","<br />",$pingvars);
42                  $messages[] = $pingresponse;
43              }
44             
45              if (!empty($pingresponse)) {
46                  if ($uspingresponse = unserialize($pingresponse)) {
47                      $datalist = new stdClass;
48                      $datalist->name = 'explodeservice';
49                      $datalist->value = $pingresponse;
50                      insert_record('datalists',$datalist);
51                  }
52              }
53             
54          } else {
55             
56              $explodelastpinged = get_record('datalists', 'name', 'explodelastpinged');
57              $triggertime = time() - (86400* 7);
58              if (!$explodelastpinged || $explodelastpinged->value < $triggertime) {
59                 
60                  //reduce likelihood of concurrent pings on a stall
61                  delete_records('datalists','name','explodelastpinged');
62                  $datalist = new stdClass;
63                  $datalist->name = 'explodelastpinged';
64                  $datalist->value = $triggertime + 600;
65                  insert_record('datalists',$datalist);
66                  ini_set('default_socket_timeout', 20);
67                 
68                  //don't do anything if initial connect doesn't work
69                  $testresponse = file_get_contents("http://ex.plode.us/mod/searchping/elggping.php");
70                  if ($testresponse !== false) {
71                     
72                      $search_sql = "SELECT u.ident, u.username, COUNT(m.ident) AS members FROM `".$CFG->prefix."users` u JOIN ".$CFG->prefix."friends m ON m.owner = u.ident WHERE u.user_type = 'person' GROUP BY u.ident ORDER BY members DESC LIMIT 1";
73                      if ($users = get_records_sql($search_sql)) {
74                         
75                          foreach($users as $user) {
76                              $username = $user->username;
77                             
78                              $explodeservice = get_record_sql("select * from {$CFG->prefix}datalists where name = 'explodeservice'"); // ('datalists', 'name', 'explodeservice');
79                              $explodeservice = unserialize($explodeservice->value);
80                              $crypt_reping = sha1($explodeservice->ident . ":" . $username . ":" . $explodeservice->secretkey);
81                             
82                              $pingvars = "pingtype=reping";
83                              $pingvars .= "&service=" . urlencode($explodeservice->ident);
84                              $pingvars .= "&crypt=" . urlencode($crypt_reping);
85                              $pingvars .= "&username=" . urlencode($username);
86                             
87                              $response = file_get_contents("http://ex.plode.us/mod/searchping/elggping.php?{$pingvars}");
88                         }
89                         
90                      }
91                     
92                      delete_records('datalists','name','explodelastpinged');
93                      $datalist = new stdClass;
94                      $datalist->name = 'explodelastpinged';
95                      $datalist->value = time();
96                      insert_record('datalists',$datalist);
97                     
98                  }
99              }
100             
101          }
102      }
103
104 ?>
Note: See TracBrowser for help on using the browser.