コード例 #1
0
 public function bootstrap($wwwroot, $pubkey, $appname = 'moodle', $institution = null)
 {
     $wwwroot = dropslash($wwwroot);
     if (!$this->findByWwwroot($wwwroot)) {
         $hostname = get_hostname_from_uri($wwwroot);
         // Get the IP address for that host - if this fails, it will
         // return the hostname string
         $ipaddress = gethostbyname($hostname);
         // Couldn't find the IP address?
         if ($ipaddress === $hostname && !preg_match('/^\\d+\\.\\d+\\.\\d+.\\d+$/', $hostname)) {
             throw new ParamOutOfRangeException('Could not find IP address for host: ' . addslashes($hostname));
             return false;
         }
         // Default the name to the wwwroot
         $this->name = $wwwroot;
         // Get a page from the remote host, and check its title.
         $homepage = file_get_contents($wwwroot);
         if (!empty($homepage) && ($count = preg_match("@<title>(.*)</title>@siU", $homepage, $matches))) {
             $this->name = $matches[1];
         }
         $exists = get_record('application', 'name', $appname);
         if (empty($exists)) {
             throw new ParamOutOfRangeException('Application ' . addslashes($appname) . ' does not exist.');
         }
         $this->appname = $appname;
         $this->application = Application::findByName($this->appname);
         $this->wwwroot = $wwwroot;
         $this->ipaddress = $ipaddress;
         require_once get_config('libroot') . 'institution.php';
         if (null == $institution) {
             $institution = new Institution();
             $institution->name = preg_replace('/[^a-zA-Z]/', '', $this->name);
             // Check that the institution name has not already been taken.
             // If it has, we change it until we find a name that works
             $existinginstitutionnames = get_column('institution', 'name');
             if (in_array($institution->name, $existinginstitutionnames)) {
                 $success = false;
                 foreach (range('a', 'z') as $character) {
                     $testname = $institution->name . $character;
                     if (!in_array($testname, $existinginstitutionnames)) {
                         $success = true;
                         $institution->name = $testname;
                         break;
                     }
                 }
                 if (!$success) {
                     // We couldn't find a unique name. Noes!
                     throw new RemoteServerException('Could not create a unique institution name');
                 }
             }
             $institution->displayname = $this->name;
             $institution->commit();
             $this->institution = $institution->name;
         } else {
             $this->institution = $institution;
         }
         if (empty($pubkey)) {
             try {
                 $somekey = get_public_key($this->wwwroot, $this->appname);
                 $this->publickey = new PublicKey($somekey, $this->wwwroot);
             } catch (XmlrpcClientException $e) {
                 $errcode = $e->getCode();
                 if ($errcode == 404) {
                     throw new RemoteServerException('404: Incorrect WWWRoot or Application: file not found.');
                 } elseif ($errcode == 704) {
                     throw new RemoteServerException('Networking is disabled on the host at ' . $this->wwwroot . '.');
                 } else {
                     throw new RemoteServerException('Error retrieving public key, failed with error code ' . $errcode . ': ' . $e->getMessage());
                 }
             } catch (Exception $e) {
                 throw new RemoteServerException('Error retrieving public key: ' . $e->getMessage());
             }
         } else {
             $this->publickey = new PublicKey($pubkey, $this->wwwroot);
         }
         $this->lastconnecttime = 0;
         $this->initialized = self::INITIALIZED;
         $this->changed = true;
         if (false == $this->publickey->expires) {
             $this->publickey == null;
             return false;
         }
     }
     return true;
 }
コード例 #2
0
ファイル: recaptcha.php プロジェクト: mrclay/elgg_recaptcha
<?php

namespace Beck24\ReCaptcha;

/**
 * input/recaptcha
 *
 * render a recaptcha challenge
 *
 * @uses $vars['theme'] Optional the theme to render: light | dark
 * @uses $vars['size']	Optional size of the captcha: compact | normal
 * @uses $vars['type']  Optional the type of recaptcha: image | audio
 * @uses $vars['form']  Optional the jquery selector for a form
 */
elgg_require_js('elgg_recaptcha/render');
$key = get_public_key();
$options = array('class' => 'g-recaptcha', 'data-sitekey' => $key, 'data-theme' => get_recaptcha_theme(), 'data-size' => get_recaptcha_size(), 'data-type' => get_recaptcha_type());
if ($vars['theme']) {
    $options['data-theme'] = $vars['theme'];
}
if ($vars['size']) {
    $options['data-size'] = $vars['size'];
}
if ($vars['type']) {
    $options['data-type'] = $vars['type'];
}
if ($vars['form']) {
    $options['data-form'] = $vars['form'];
}
$attributes = elgg_format_attributes($options);
$nojs = <<<NOJS