Exemplo n.º 1
0
 private function alertAdminsOfXMLErrors($plugin)
 {
     $errors = [];
     if ($plugin->xml_state == 'bad_xml_url') {
         $errors[] = ['reason' => 'url', 'url' => $plugin->xml_url];
     } elseif ($plugin->xml_state == 'xml_error') {
         // Reevaluating Errors with previous plain-text xml,
         // using the collectMode of ValidableXMLPluginDescription
         $xml = new ValidableXMLPluginDescription($this->currentXml, true);
         $xml->validate();
         foreach ($xml->errors as $_error) {
             $error = [];
             $error['reason'] = $_error->getInfo('reason');
             switch ($error['reason']) {
                 case 'parse':
                     $error['line'] = $_error->getInfo('line');
                     $error['errstring'] = $_error->getInfo('errstring');
                 case 'field':
                     $error['field'] = $_error->getInfo('field');
                     $error['errstring'] = $_error->getInfo('errstring');
             }
             $errors[] = $error;
         }
     } else {
         return;
     }
     $permissions = $plugin->permissions;
     foreach ($permissions as $user) {
         if ($user->pivot->admin || $user->pivot->allowed_notifications) {
             $mailer = new Mailer();
             $mailer->sendMail('xml_error.html', [$user->email], '"' . $plugin->key . '"' . ' Plugin\'s XML has turned invalid', ['errors' => $errors, 'plugin' => $plugin, 'user' => $user]);
         }
     }
 }
Exemplo n.º 2
0
 if (!$resp->isSuccess()) {
     throw new InvalidRecaptcha();
 }
 if (!isset($body->plugin_url) || gettype($body->plugin_url) != 'string') {
     throw new InvalidField('plugin_url');
 }
 // Quickly validating
 if (Plugin::where('xml_url', '=', $body->plugin_url)->count() > 0) {
     throw new UnavailableName('XML_URL', $body->plugin_url);
 }
 $xml = @file_get_contents($body->plugin_url);
 if (!$xml) {
     throw new InvalidXML('url', $body->plugin_url);
 }
 $xml = new ValidableXMLPluginDescription($xml);
 $xml->validate();
 $xml = $xml->contents;
 if (Plugin::where('key', '=', $xml->key)->count() > 0) {
     throw new UnavailableName('Plugin', $xml->key);
 }
 $plugin = new Plugin();
 $plugin->xml_url = $body->plugin_url;
 $plugin->date_added = DB::raw('NOW()');
 $plugin->active = false;
 $plugin->download_count = 0;
 $plugin->save();
 $plugin->permissions()->attach($user);
 $user = $plugin->permissions()->where('user_id', '=', $user->id)->first();
 $user->pivot['admin'] = true;
 $user->pivot->save();
 $mailer = new Mailer();