Exemplo n.º 1
0
 /**
  * @brief parse the info.xml of the given app and save its notification templates to database
  * @param $app application id
  * @param $class optional name of the class to get its ID
  * @return class id if a name is given and the class exists, array of class IDs if only the app is given
  */
 public static function parseAppNotifications($app, $class = null)
 {
     if (!isset(self::$classInsertStmt)) {
         self::$classInsertStmt = OCP\DB::prepare("INSERT INTO *PREFIX*notification_classes (appid, name, summary, content) VALUES (?, ?, ?, ?)");
     }
     $appInfo = @file_get_contents(OC_App::getAppPath($app) . '/appinfo/info.xml');
     if ($appInfo) {
         $xml = new SimpleXMLElement($appInfo);
     } else {
         return false;
     }
     $templates = $xml->xpath('notifications/template');
     $return = array();
     foreach ($templates as $template) {
         $attr = $template->attributes();
         $name = $attr->id;
         $summary = substr(strip_tags(trim($attr->summary)), 0, 64);
         $content = strip_tags((string) $template, "<a><b><i><strong><em><span>");
         if (empty($name) or empty($content)) {
             //FIXME also require summary??
             continue;
         }
         try {
             self::$classInsertStmt->execute(array($app, $name, $summary, $content));
             $id = OCP\DB::insertid("*PREFIX*notification_classes");
             if ($class == null) {
                 $return[] = (int) $id;
             } else {
                 if ($class == $name) {
                     $return = (int) $id;
                 }
             }
         } catch (Exception $e) {
             //most likely a database conflict
         }
     }
     if ($class == null or is_int($return)) {
         return $return;
     } else {
         return false;
     }
 }