Пример #1
0
 function import()
 {
     switch ($this->appinfo->version) {
         default:
             // All versions of the app have had the same db structure, so all can use the same import function
             $query = $this->content->prepare('SELECT * FROM `contacts_addressbooks` WHERE `userid` LIKE ?');
             $results = $query->execute(array($this->olduid));
             $idmap = array();
             while ($row = $results->fetchRow()) {
                 // Import each addressbook
                 $addressbookquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_addressbooks` (`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)');
                 $addressbookquery->execute(array($this->uid, $row['displayname'], $row['uri'], $row['description'], $row['ctag']));
                 // Map the id
                 $idmap[$row['id']] = OCP\DB::insertid('*PREFIX*contacts_addressbooks');
                 // Make the addressbook active
                 OC_Contacts_Addressbook::setActive($idmap[$row['id']], true);
             }
             // Now tags
             foreach ($idmap as $oldid => $newid) {
                 $query = $this->content->prepare('SELECT * FROM `contacts_cards` WHERE `addressbookid` LIKE ?');
                 $results = $query->execute(array($oldid));
                 while ($row = $results->fetchRow()) {
                     // Import the contacts
                     $contactquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_cards` (`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)');
                     $contactquery->execute(array($newid, $row['fullname'], $row['carddata'], $row['uri'], $row['lastmodified']));
                 }
             }
             // All done!
             break;
     }
     return true;
 }
Пример #2
0
function getShortcode($url) {
	$shortcode = '';
	$query = OCP\DB::prepare('SELECT shortcode FROM *PREFIX*shorten WHERE url=?');
	$results = $query->execute(Array($url))->fetchAll();
	if ($results) {
		foreach($results as $result) {
			$shortcode = $result['shortcode'];	
		}
	}
	if ($shortcode == "") {
		$shortcode = rand_chars(6);
		$found = true;
		while ($found) {
			$query = OCP\DB::prepare('SELECT id FROM *PREFIX*shorten WHERE shortcode=?');
			$results = $query->execute(Array($shortcode))->fetchAll();
			if (!$results) {
				$found = false;
				$uid = \OCP\User::getUser();
				$query = OCP\DB::prepare('INSERT INTO *PREFIX*shorten (uid, shortcode, url) VALUES (?,?,?)');
				$query->execute(Array($uid,$shortcode,$url));
				$id = OCP\DB::insertid('*PREFIX*shorten');
			} else
				$shortcode = rand_chars(6);
		}
	}
	return $shortcode;
}
Пример #3
0
 function import()
 {
     switch ($this->appinfo->version) {
         default:
             // All versions of the app have had the same db structure, so all can use the same import function
             $query = $this->content->prepare("SELECT * FROM bookmarks WHERE user_id LIKE ?");
             $results = $query->execute(array($this->olduid));
             $idmap = array();
             while ($row = $results->fetchRow()) {
                 // Import each bookmark, saving its id into the map
                 $query = OCP\DB::prepare("INSERT INTO *PREFIX*bookmarks(url, title, user_id, public, added, lastmodified) VALUES (?, ?, ?, ?, ?, ?)");
                 $query->execute(array($row['url'], $row['title'], $this->uid, $row['public'], $row['added'], $row['lastmodified']));
                 // Map the id
                 $idmap[$row['id']] = OCP\DB::insertid();
             }
             // Now tags
             foreach ($idmap as $oldid => $newid) {
                 $query = $this->content->prepare("SELECT * FROM bookmarks_tags WHERE bookmark_id LIKE ?");
                 $results = $query->execute(array($oldid));
                 while ($row = $results->fetchRow()) {
                     // Import the tags for this bookmark, using the new bookmark id
                     $query = OCP\DB::prepare("INSERT INTO *PREFIX*bookmarks_tags(bookmark_id, tag) VALUES (?, ?)");
                     $query->execute(array($newid, $row['tag']));
                 }
             }
             // All done!
             break;
     }
     return true;
 }
Пример #4
0
 function import()
 {
     switch ($this->appinfo->version) {
         default:
             // All versions of the app have had the same db structure, so all can use the same import function
             $query = $this->content->prepare('SELECT * FROM `calendar_calendars` WHERE `userid` = ?');
             $results = $query->execute(array($this->olduid));
             $idmap = array();
             while ($row = $results->fetchRow()) {
                 // Import each calendar
                 $calendarquery = OCP\DB::prepare('INSERT INTO `*PREFIX*calendar_calendars` (`userid`,`displayname`,`uri`,`ctag`,`calendarorder`,`calendarcolor`,`timezone`,`components`) VALUES(?,?,?,?,?,?,?,?)');
                 $calendarquery->execute(array($this->uid, $row['displayname'], $row['uri'], $row['ctag'], $row['calendarorder'], $row['calendarcolor'], $row['timezone'], $row['components']));
                 // Map the id
                 $idmap[$row['id']] = OCP\DB::insertid('*PREFIX*calendar_calendars');
                 // Make the calendar active
                 OC_Calendar_Calendar::setCalendarActive($idmap[$row['id']], true);
             }
             // Now tags
             foreach ($idmap as $oldid => $newid) {
                 $query = $this->content->prepare('SELECT * FROM `calendar_objects` WHERE `calendarid` = ?');
                 $results = $query->execute(array($oldid));
                 while ($row = $results->fetchRow()) {
                     // Import the objects
                     $objectquery = OCP\DB::prepare('INSERT INTO `*PREFIX*calendar_objects` (`calendarid`,`objecttype`,`startdate`,`enddate`,`repeating`,`summary`,`calendardata`,`uri`,`lastmodified`) VALUES(?,?,?,?,?,?,?,?,?)');
                     $objectquery->execute(array($newid, $row['objecttype'], $row['startdate'], $row['enddate'], $row['repeating'], $row['summary'], $row['calendardata'], $row['uri'], $row['lastmodified']));
                 }
             }
             // All done!
             break;
     }
     return true;
 }
Пример #5
0
 function import()
 {
     switch ($this->appinfo->version) {
         default:
             // All versions of the app have had the same db structure, so all can use the same import function
             $query = $this->content->prepare("SELECT * FROM contacts_addressbooks WHERE userid LIKE ?");
             $results = $query->execute(array($this->olduid));
             $idmap = array();
             while ($row = $results->fetchRow()) {
                 // Import each bookmark, saving its id into the map
                 $query = OCP\DB::prepare("INSERT INTO *PREFIX*contacts_addressbooks (`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)");
                 $query->execute(array($this->uid, $row['displayname'], $row['uri'], $row['description'], $row['ctag']));
                 // Map the id
                 $idmap[$row['id']] = OCP\DB::insertid();
             }
             // Now tags
             foreach ($idmap as $oldid => $newid) {
                 $query = $this->content->prepare("SELECT * FROM contacts_cards WHERE addressbookid LIKE ?");
                 $results = $query->execute(array($oldid));
                 while ($row = $results->fetchRow()) {
                     // Import the tags for this bookmark, using the new bookmark id
                     $query = OCP\DB::prepare("INSERT INTO *PREFIX*contacts_cards (`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)");
                     $query->execute(array($newid, $row['fullname'], $row['carddata'], $row['uri'], $row['lastmodified']));
                 }
             }
             // All done!
             break;
     }
     return true;
 }
Пример #6
0
 function import()
 {
     $existingURIs = array();
     $existingNames = array();
     $query = $this->content->prepare('SELECT `displayname`, `uri` FROM *PREFIX*contacts_addressbooks WHERE userid = ?');
     $results = $query->execute(array($this->uid));
     while ($row = $results->fetchRow()) {
         \OCP\Util::writeLog('contacts', __METHOD__ . ', row: ' . print_r($row, true), \OCP\Util::DEBUG);
         $existingURIs[] = $row['uri'];
         $existingNames[] = $row['displayname'];
     }
     switch ($this->appinfo->version) {
         default:
             // All versions of the app have had the same db structure, so all can use the same import function
             $query = $this->content->prepare('SELECT * FROM contacts_addressbooks WHERE userid = ?');
             $results = $query->execute(array($this->olduid));
             $idmap = array();
             while ($row = $results->fetchRow()) {
                 // Import each addressbook
                 $addressbookquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_addressbooks` (`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)');
                 $uriSuffix = '';
                 $nameSuffix = '';
                 while (in_array($row['uri'] . $uriSuffix, $existingURIs)) {
                     $uriSuffix++;
                 }
                 while (in_array($row['displayname'] . $nameSuffix, $existingNames)) {
                     $nameSuffix++;
                 }
                 $addressbookquery->execute(array($this->uid, $row['displayname'] . $nameSuffix, $row['uri'] . $uriSuffix, $row['description'], $row['ctag']));
                 // Map the id
                 $idmap[$row['id']] = OCP\DB::insertid('*PREFIX*contacts_addressbooks');
                 // Make the addressbook active
                 OCA\Contacts\Addressbook::setActive($idmap[$row['id']], true);
             }
             // Now tags
             foreach ($idmap as $oldid => $newid) {
                 $query = $this->content->prepare('SELECT * FROM contacts_cards WHERE addressbookid = ?');
                 $results = $query->execute(array($oldid));
                 while ($row = $results->fetchRow()) {
                     // Import the contacts
                     $contactquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_cards` (`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)');
                     $contactquery->execute(array($newid, $row['fullname'], $row['carddata'], $row['uri'], $row['lastmodified']));
                 }
             }
             // All done!
             break;
     }
     return true;
 }
Пример #7
0
 /**
  * @brief Create a new comment for the post with the given contents
  * @param Content to be presented within the comment
  * @param Member who wrote (created) the comment
  * @param Post ID
  * @return int|boolean (Comment ID|false)
  */
 public static function createComment($content, $member, $post_id)
 {
     try {
         $query = \OCP\DB::prepare('INSERT INTO `*PREFIX*collaboration_comment`(`content`, `creator`, `post_id`, `time`) VALUES(?, ?, ?, CURRENT_TIMESTAMP)');
         $result = $query->execute(array($content, $member, $post_id));
         return OCP\DB::insertid('*PREFIX*collaboration_comment');
     } catch (\Exception $e) {
         OC_Log::write('collaboration', __METHOD__ . ', Exception: ' . $e->getMessage(), OCP\Util::DEBUG);
         return false;
     }
 }
Пример #8
0
 /**
  * @brief Adds a card
  * @param $aid integer Addressbook id
  * @param $card OC_VObject  vCard file
  * @param $uri string the uri of the card, default based on the UID
  * @param $isChecked boolean If the vCard should be checked for validity and version.
  * @return insertid on success or false.
  */
 public static function add($aid, OC_VObject $card, $uri = null, $isChecked = false)
 {
     if (is_null($card)) {
         OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::add. No vCard supplied', OCP\Util::ERROR);
         return null;
     }
     $addressbook = OC_Contacts_Addressbook::find($aid);
     if ($addressbook['userid'] != OCP\User::getUser()) {
         $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $aid);
         if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_CREATE)) {
             throw new Exception(OC_Contacts_App::$l10n->t('You do not have the permissions to add contacts to this addressbook.'));
         }
     }
     if (!$isChecked) {
         OC_Contacts_App::loadCategoriesFromVCard($card);
         self::updateValuesFromAdd($aid, $card);
     }
     $card->setString('VERSION', '3.0');
     // Add product ID is missing.
     $prodid = trim($card->getAsString('PRODID'));
     if (!$prodid) {
         $appinfo = OCP\App::getAppInfo('contacts');
         $appversion = OCP\App::getAppVersion('contacts');
         $prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion . '//EN';
         $card->setString('PRODID', $prodid);
     }
     $fn = $card->getAsString('FN');
     if (empty($fn)) {
         $fn = '';
     }
     if (!$uri) {
         $uid = $card->getAsString('UID');
         $uri = $uid . '.vcf';
     }
     $data = $card->serialize();
     $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_cards` (`addressbookid`,`fullname`,`carddata`,`uri`,`lastmodified`) VALUES(?,?,?,?,?)');
     try {
         $result = $stmt->execute(array($aid, $fn, $data, $uri, time()));
     } catch (Exception $e) {
         OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::ERROR);
         OCP\Util::writeLog('contacts', __METHOD__ . ', aid: ' . $aid . ' uri' . $uri, OCP\Util::DEBUG);
         return false;
     }
     $newid = OCP\DB::insertid('*PREFIX*contacts_cards');
     OC_Contacts_Addressbook::touch($aid);
     OC_Hook::emit('OC_Contacts_VCard', 'post_createVCard', $newid);
     return $newid;
 }
Пример #9
0
 /**
  * @brief Creates a new address book from the data sabredav provides
  * @param string $principaluri
  * @param string $uri
  * @param string $name
  * @param string $description
  * @return insertid or false
  */
 public static function addFromDAVData($principaluri, $uri, $name, $description)
 {
     $uid = self::extractUserID($principaluri);
     try {
         $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_addressbooks` (`userid`,`displayname`,`uri`,`description`,`ctag`) VALUES(?,?,?,?,?)');
         $result = $stmt->execute(array($uid, $name, $uri, $description, 1));
     } catch (Exception $e) {
         OCP\Util::writeLog('contacts', __CLASS__ . '::' . __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::ERROR);
         OCP\Util::writeLog('contacts', __CLASS__ . '::' . __METHOD__ . ', uid: ' . $uid, OCP\Util::DEBUG);
         OCP\Util::writeLog('contacts', __CLASS__ . '::' . __METHOD__ . ', uri: ' . $uri, OCP\Util::DEBUG);
         return false;
     }
     return OCP\DB::insertid('*PREFIX*contacts_addressbooks');
 }
Пример #10
0
 /**
  * @brief Adds an object with the data provided by sabredav
  * @param integer $id Calendar id
  * @param string $uri   the uri the card will have
  * @param string $data  object
  * @return insertid
  */
 public static function addFromDAVData($id, $uri, $data)
 {
     $object = OC_VObject::parse($data);
     list($type, $startdate, $enddate, $summary, $repeating, $uid) = self::extractData($object);
     $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*calendar_objects (calendarid,objecttype,startdate,enddate,repeating,summary,calendardata,uri,lastmodified) VALUES(?,?,?,?,?,?,?,?,?)');
     $stmt->execute(array($id, $type, $startdate, $enddate, $repeating, $summary, $data, $uri, time()));
     $object_id = OCP\DB::insertid('*PREFIX*calendar_objects');
     OC_Calendar_Calendar::touchCalendar($id);
     return $object_id;
 }
Пример #11
0
 /**
  * @brief Creates a new project
  * @param Project title
  * @param Description of the project
  * @param Member who created the project
  * @param Deadline of the project
  * @param List of members working in the project and their roles
  * @return int|boolean (Post ID of the post specifying the project creation|false)
  */
 public static function createProject($title, $desc, $creator, $deadline, $details = NULL)
 {
     $post_id = NULL;
     try {
         \OCP\DB::beginTransaction();
         $calendar_id = OC_Calendar_Calendar::addCalendar(\OC_User::getUser(), $title, 'VEVENT,VTODO,VJOURNAL', null, 0, '#3a87ad');
         $query = \OCP\DB::prepare('INSERT INTO `*PREFIX*collaboration_project`(`title`, `description`, `starting_date`, `ending_date`, `last_updated`, `calendar_id`) VALUES(?, ?, CURRENT_TIMESTAMP, ?, CURRENT_TIMESTAMP, ?)');
         $query->execute(array($title, $desc, OC_Collaboration_Time::convertUITimeToDBTime($deadline . ' 23:59:59'), $calendar_id));
         $pid = OCP\DB::insertid('*PREFIX*collaboration_project');
         $add_member = \OCP\DB::prepare('INSERT INTO `*PREFIX*collaboration_works_on`(`pid`, `member`, `role`) VALUES(?, ?, ?)');
         $add_member->execute(array($pid, $creator, 'Creator'));
         $cnt = count($details);
         if ($cnt != 0 && isset($details[0]['member'])) {
             foreach ($details as $detail) {
                 $member = strtolower($detail['member']);
                 if (!OC_User::userExists($member)) {
                     OC_User::createUser($member, $member);
                 }
                 $add_member->execute(array($pid, $member, $detail['role']));
                 OC_Preferences::setValue($member, 'settings', 'email', $detail['email']);
                 OC_Preferences::setValue($member, 'collaboration', 'mobile', $detail['mobile']);
             }
         }
         $post_id = OC_Collaboration_Post::createPost('Project Created', 'Project \'' . $title . '\' has been created with deadline ' . OC_Collaboration_Time::convertToFullDate($deadline) . '.', $creator, $pid, 'Project Creation', array(), true);
         \OCP\DB::commit();
     } catch (\Exception $e) {
         OC_Log::write('collaboration', __METHOD__ . ', Exception: ' . $e->getMessage(), OCP\Util::DEBUG);
         return false;
     }
     return $post_id;
 }
Пример #12
0
 /**
  * Add a bookmark
  * @param string $url
  * @param string $title Name of the bookmark
  * @param array $tags Simple array of tags to qualify the bookmark (different tags are taken from values)
  * @param string $description A longer description about the bookmark
  * @param boolean $is_public True if the bookmark is publishable to not registered users
  * @return int The id of the bookmark created
  */
 public static function addBookmark($url, $title, $tags = array(), $description = '', $is_public = false)
 {
     $is_public = $is_public ? 1 : 0;
     $enc_url = htmlspecialchars_decode($url);
     $_ut = self::getNowValue();
     // Change lastmodified date if the record if already exists
     $sql = "SELECT * from  `*PREFIX*bookmarks` WHERE `url` = ? AND `user_id` = ?";
     $query = OCP\DB::prepare($sql, 1);
     $result = $query->execute(array($enc_url, OCP\USER::getUser()));
     if ($row = $result->fetchRow()) {
         $params = array();
         $title_str = '';
         if (trim($title) != '') {
             // Do we replace the old title
             $title_str = ' , title = ?';
             $params[] = $title;
         }
         $desc_str = '';
         if (trim($title) != '') {
             // Do we replace the old description
             $desc_str = ' , description = ?';
             $params[] = $description;
         }
         $sql = "UPDATE `*PREFIX*bookmarks` SET `lastmodified` = {$_ut} {$title_str} {$desc_str} WHERE `url` = ? and `user_id` = ?";
         $params[] = $enc_url;
         $params[] = OCP\USER::getUser();
         $query = OCP\DB::prepare($sql);
         $query->execute($params);
         return $row['id'];
     }
     $query = OCP\DB::prepare("\n\t\t\tINSERT INTO `*PREFIX*bookmarks`\n\t\t\t(`url`, `title`, `user_id`, `public`, `added`, `lastmodified`, `description`)\n\t\t\tVALUES (?, ?, ?, ?, {$_ut}, {$_ut}, ?)\n\t\t\t");
     $params = array($enc_url, htmlspecialchars_decode($title), OCP\USER::getUser(), $is_public, $description);
     $query->execute($params);
     $b_id = OCP\DB::insertid('*PREFIX*bookmarks');
     if ($b_id !== false) {
         self::addTags($b_id, $tags);
         return $b_id;
     }
 }
Пример #13
0
 /**
  * @brief Adds an object with the data provided by sabredav
  * @param integer $id Calendar id
  * @param string $uri   the uri the card will have
  * @param string $data  object
  * @return insertid
  */
 public static function addFromDAVData($id, $uri, $data)
 {
     $shared = false;
     $calendar = OC_Calendar_Calendar::find($id);
     if ($calendar['userid'] != OCP\User::getUser()) {
         $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id);
         if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_CREATE)) {
             throw new \Sabre\DAV\Exception\Forbidden(OC_Calendar_App::$l10n->t('You do not have the permissions to add events to this calendar.'));
         }
         $shared = true;
     }
     $object = \Sabre\VObject\Reader::read($data);
     $vevent = self::getElement($object);
     if ($shared && isset($vevent->CLASS) && (string) $vevent->CLASS !== 'PUBLIC') {
         throw new \Sabre\DAV\Exception\PreconditionFailed(OC_Calendar_App::$l10n->t('You cannot add non-public events to a shared calendar.'));
     }
     list($type, $startdate, $enddate, $summary, $repeating, $uid) = self::extractData($object);
     $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*clndr_objects` (`calendarid`,`objecttype`,`startdate`,`enddate`,`repeating`,`summary`,`calendardata`,`uri`,`lastmodified`) VALUES(?,?,?,?,?,?,?,?,?)');
     $stmt->execute(array($id, $type, $startdate, $enddate, $repeating, $summary, $data, $uri, time()));
     $object_id = OCP\DB::insertid('*PREFIX*clndr_objects');
     self::addAlarmsDBFromData($object, $object_id);
     OC_Calendar_Calendar::touchCalendar($id);
     OCP\Util::emitHook('OC_Calendar', 'addEvent', $object_id);
     return $object_id;
 }
Пример #14
0
 /**
  * Add an song to the database
  * @param string name
  * @param string path
  * @param integer artist
  * @param integer album
  * @return integer the song_id of the added artist
  */
 public static function addSong($name, $path, $artist, $album, $length, $track, $size)
 {
     $name = trim($name);
     $path = trim($path);
     if ($name == '' or $path == '') {
         return 0;
     }
     $uid = OCP\USER::getUser();
     //check if the song is already in the database
     $songId = self::getSongId($name, $artist, $album);
     if ($songId != 0) {
         $songInfo = self::getSong($songId);
         self::moveSong($songInfo['song_path'], $path);
         return $songId;
     } else {
         if (!isset(self::$queries['addsong'])) {
             $query = OCP\DB::prepare("INSERT INTO  `*PREFIX*media_songs` (`song_name` ,`song_artist` ,`song_album` ,`song_path` ,`song_user`,`song_length`,`song_track`,`song_size`,`song_playcount`,`song_lastplayed`)\n\t\t\t\tVALUES (?, ?, ?, ?,?,?,?,?,0,0)");
             self::$queries['addsong'] = $query;
         } else {
             $query = self::$queries['addsong'];
         }
         $query->execute(array($name, $artist, $album, $path, $uid, $length, $track, $size));
         $songId = OCP\DB::insertid('*PREFIX*media_songs_song');
         // 			self::setLastUpdated();
         return self::getSongId($name, $artist, $album);
     }
 }
Пример #15
0
 /**
  * @brief Creates a new address book from the data sabredav provides
  * @param string $principaluri
  * @param string $uri
  * @param string $name
  * @param string $description
  * @return insertid
  */
 public static function addFromDAVData($principaluri, $uri, $name, $description)
 {
     $userid = self::extractUserID($principaluri);
     $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)');
     $result = $stmt->execute(array($userid, $name, $uri, $description, 1));
     return OCP\DB::insertid('*PREFIX*contacts_addressbooks');
 }
Пример #16
0
function addBookmark($url, $title, $tags = '')
{
    $CONFIG_DBTYPE = OCP\Config::getSystemValue("dbtype", "sqlite");
    if ($CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3') {
        $_ut = "strftime('%s','now')";
    } elseif ($CONFIG_DBTYPE == 'pgsql') {
        $_ut = 'date_part(\'epoch\',now())::integer';
    } else {
        $_ut = "UNIX_TIMESTAMP()";
    }
    //FIXME: Detect when user adds a known URL
    $query = OCP\DB::prepare("\n\t\tINSERT INTO `*PREFIX*bookmarks`\n\t\t(`url`, `title`, `user_id`, `public`, `added`, `lastmodified`)\n\t\tVALUES (?, ?, ?, 0, {$_ut}, {$_ut})\n\t\t");
    if (empty($title)) {
        $metadata = getURLMetadata($url);
        if (isset($metadata['title'])) {
            // Check for problems fetching the title
            $title = $metadata['title'];
        }
    }
    if (empty($title)) {
        $l = OC_L10N::get('bookmarks');
        $title = $l->t('unnamed');
    }
    $params = array(htmlspecialchars_decode($url), htmlspecialchars_decode($title), OCP\USER::getUser());
    $query->execute($params);
    $b_id = OCP\DB::insertid('*PREFIX*bookmarks');
    if ($b_id !== false) {
        $query = OCP\DB::prepare("\n\t\t\tINSERT INTO `*PREFIX*bookmarks_tags`\n\t\t\t(`bookmark_id`, `tag`)\n\t\t\tVALUES (?, ?)\n\t\t\t");
        $tags = explode(' ', urldecode($tags));
        foreach ($tags as $tag) {
            if (empty($tag)) {
                //avoid saving blankspaces
                continue;
            }
            $params = array($b_id, trim($tag));
            $query->execute($params);
        }
        return $b_id;
    }
}
Пример #17
0
 /**
  * @brief Add a new category.
  * @param $name A string with a name of the category
  * @returns int the id of the added category or false if it already exists.
  */
 public function add($name)
 {
     OCP\Util::writeLog('core', __METHOD__ . ', name: ' . $name, OCP\Util::DEBUG);
     if ($this->hasCategory($name)) {
         OCP\Util::writeLog('core', __METHOD__ . ', name: ' . $name . ' exists already', OCP\Util::DEBUG);
         return false;
     }
     OCP\DB::insertIfNotExist(self::CATEGORY_TABLE, array('uid' => $this->user, 'type' => $this->type, 'category' => $name));
     $id = OCP\DB::insertid(self::CATEGORY_TABLE);
     OCP\Util::writeLog('core', __METHOD__ . ', id: ' . $id, OCP\Util::DEBUG);
     $this->categories[$id] = $name;
     return $id;
 }
Пример #18
0
 /**
  * @brief Adds an object with the data provided by sabredav
  * @param integer $id Calendar id
  * @param string $uri   the uri the card will have
  * @param string $data  object
  * @return insertid
  */
 public static function addFromDAVData($id, $uri, $data)
 {
     $calendar = OC_Calendar_Calendar::find($id);
     if ($calendar['userid'] != OCP\User::getUser()) {
         $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id);
         if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_CREATE)) {
             throw new Sabre_DAV_Exception_Forbidden(OC_Calendar_App::$l10n->t('You do not have the permissions to add events to this calendar.'));
         }
     }
     $object = OC_VObject::parse($data);
     list($type, $startdate, $enddate, $summary, $repeating, $uid) = self::extractData($object);
     $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*clndr_objects` (`calendarid`,`objecttype`,`startdate`,`enddate`,`repeating`,`summary`,`calendardata`,`uri`,`lastmodified`) VALUES(?,?,?,?,?,?,?,?,?)');
     $stmt->execute(array($id, $type, $startdate, $enddate, $repeating, $summary, $data, $uri, time()));
     $object_id = OCP\DB::insertid('*PREFIX*clndr_objects');
     OC_Calendar_Calendar::touchCalendar($id);
     OCP\Util::emitHook('OC_Calendar', 'addEvent', $object_id);
     return $object_id;
 }
Пример #19
0
 /**
  * @brief Creates a new calendar from the data sabredav provides
  * @param string $principaluri
  * @param string $uri
  * @param string $name
  * @param string $components
  * @param string $timezone
  * @param integer $order
  * @param string $color format: '#RRGGBB(AA)'
  * @return int
  */
 public static function addCalendarFromDAVData($principaluri, $uri, $name, $components, $timezone, $order, $color)
 {
     $userid = self::extractUserID($principaluri);
     $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*clndr_calendars` (`userid`,`displayname`,`uri`,`ctag`,`calendarorder`,`calendarcolor`,`timezone`,`components`) VALUES(?,?,?,?,?,?,?,?)');
     $result = $stmt->execute(array($userid, $name, $uri, 1, $order, $color, $timezone, $components));
     $insertid = OCP\DB::insertid('*PREFIX*clndr_calendars');
     OCP\Util::emitHook('OC_Calendar', 'addCalendar', $insertid);
     return $insertid;
 }
Пример #20
0
 /**
  * @brief send a new notification to the given user
  * @param $appid app which sends the notification
  * @param $class id relating to a template in the app's info.xml
  * @param $uid receiving user
  * @param $params keys and values for placeholders in the template and href/img
  * @return id of the inserted notification, null if unsuccessful
  */
 public static function sendUserNotification($appid, $class, $uid, $params = array())
 {
     try {
         $classId = self::getClassId($appid, $class);
         if ($classId === false) {
             throw new Exception("Notification template {$appid}/{$class} not found");
         }
         if (self::isBlacklisted($uid, $classId)) {
             return null;
         }
         OCP\DB::beginTransaction();
         if (!isset(self::$notifyStmt)) {
             self::$notifyStmt = OCP\DB::prepare("INSERT INTO *PREFIX*notifications (class, uid, moment) VALUES (?, ?, NOW())");
         }
         OC_Hook::emit("notify", "pre_sendUserNotification", array("classId" => $classId, "uid" => $uid, "params" => $params));
         self::$notifyStmt->execute(array($classId, $uid));
         $id = OCP\DB::insertid("*PREFIX*notifications");
         if (count($params)) {
             if (!isset(self::$paramStmt)) {
                 self::$paramStmt = OCP\DB::prepare("INSERT INTO *PREFIX*notification_params (nid, key, value) VALUES ({$id}, ?, ?)");
             }
             foreach ($params as $key => $value) {
                 self::$paramStmt->execute(array($key, $value));
                 OCP\DB::insertid("*PREFIX*notification_params");
             }
         }
         OCP\DB::commit();
         OC_Hook::emit("notify", "post_sendUserNotification", array("id" => $id, "classId" => $classId, "uid" => $uid, "params" => $params));
         return (int) $id;
     } catch (Exception $e) {
         OCP\Util::writeLog("notify", "Could not send notification: " . $e->getMessage(), OCP\Util::ERROR);
         throw $e;
         /* TODO: good exception handling and throwing, e.g.:
          * - throw exception when there are errors
          * - return false (or null?) when the app/class is blacklisted
          */
     }
 }
Пример #21
0
 /**
  * @brief Creates a new calendar from the data sabredav provides
  * @param string $principaluri
  * @param string $uri
  * @param string $name
  * @param string $components
  * @param string $timezone
  * @param integer $order
  * @param string $color format: '#RRGGBB(AA)'
  * @return insertid
  */
 public static function addCalendarFromDAVData($principaluri, $uri, $name, $components, $timezone, $order, $color)
 {
     $userid = self::extractUserID($principaluri);
     $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*calendar_calendars (userid,displayname,uri,ctag,calendarorder,calendarcolor,timezone,components) VALUES(?,?,?,?,?,?,?,?)');
     $result = $stmt->execute(array($userid, $name, $uri, 1, $order, $color, $timezone, $components));
     return OCP\DB::insertid('*PREFIX*calendar_calendars');
 }
Пример #22
0
 /**
  * @brief Creates a new post with the given title and contents
  * @param Title of the post
  * @param Post content
  * @param Member who created the post
  * @param Project to which the post corresponds
  * @param Post type
  * @param List of members having read access to the post
  * @param Whether the calling method has already initiated the (database) transaction
  * @param Task ID, if the post is related to a task
  * @return int|boolean (Post ID|false)
  */
 public static function createPost($title, $content, $creator, $pid, $type, $viewers = array(), $inTransaction = false, $tid = NULL)
 {
     try {
         $cnt = count($viewers);
         if (!isset($viewers) || $cnt == 0) {
             $post_to_all = true;
         } else {
             $post_to_all = false;
         }
         if (!$inTransaction && !$post_to_all) {
             \OCP\DB::beginTransaction();
         }
         $query = \OCP\DB::prepare('INSERT INTO `*PREFIX*collaboration_post`(`title`, `content`, `creator`, `pid`, `type`, `time`, `post_to_all`, `tid`) VALUES(?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?, ?)');
         $query->execute(array($title, $content, $creator, $pid, $type, $post_to_all, $tid));
         $post_id = OCP\DB::insertid('*PREFIX*collaboration_post');
         if (!$post_to_all) {
             $query = \OCP\DB::prepare('INSERT INTO `*PREFIX*collaboration_notification`(`post_id`, `visible_to`) VALUES(?, ?)');
             for ($i = 0; $i < $cnt; $i++) {
                 $query->execute(array($post_id, $viewers[$i]));
             }
             if (!$inTransaction) {
                 \OCP\DB::commit();
             }
         }
         return $post_id;
     } catch (\Exception $e) {
         OC_Log::write('collaboration', __METHOD__ . ', Exception: ' . $e->getMessage(), OCP\Util::DEBUG);
         return false;
     }
 }
Пример #23
0
 /**
  * @brief Adds a card
  * @param integer $aid Addressbook id
  * @param OC_VObject $card  vCard file
  * @param string $uri the uri of the card, default based on the UID
  * @return insertid on success or null if no card.
  */
 public static function add($aid, OC_VObject $card, $uri = null, $isnew = false)
 {
     if (is_null($card)) {
         OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::add. No vCard supplied', OCP\Util::ERROR);
         return null;
     }
     if (!$isnew) {
         OC_Contacts_App::loadCategoriesFromVCard($card);
         self::updateValuesFromAdd($aid, $card);
     }
     $card->setString('VERSION', '3.0');
     // Add product ID is missing.
     $prodid = trim($card->getAsString('PRODID'));
     if (!$prodid) {
         $appinfo = OCP\App::getAppInfo('contacts');
         $appversion = OCP\App::getAppVersion('contacts');
         $prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion . '//EN';
         $card->setString('PRODID', $prodid);
     }
     $fn = $card->getAsString('FN');
     if (empty($fn)) {
         $fn = '';
     }
     if (!$uri) {
         $uid = $card->getAsString('UID');
         $uri = $uid . '.vcf';
     }
     $data = $card->serialize();
     $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)');
     $result = $stmt->execute(array($aid, $fn, $data, $uri, time()));
     $newid = OCP\DB::insertid('*PREFIX*contacts_cards');
     OC_Contacts_Addressbook::touch($aid);
     return $newid;
 }
Пример #24
0
 /**
  * @brief Creates a new task with the given title and contents
  * @param Title of the task
  * @param Description of the task
  * @param Member who created the task
  * @param Project to which the task corresponds
  * @param Priority of the task
  * @param Task deadline
  * @param Task initial status
  * @param Member to whom the task is assigned
  * @return int|boolean (Task ID|false)
  */
 public static function createTask($title, $desc, $creator, $pid, $priority, $end_time, $status, $member = NULL)
 {
     $tid = NULL;
     $deadline = explode(' ', $end_time);
     try {
         \OCP\DB::beginTransaction();
         $end_date = OC_Collaboration_Time::convertUITimeToDBTime($end_time . ':00');
         $query = OCP\DB::prepare('INSERT INTO `*PREFIX*collaboration_task`(`title`, `description`, `creator`, `pid`, `priority`, `starting_time`, `ending_time`) VALUES(?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?)');
         $result = $query->execute(array($title, $desc, $creator, $pid, $priority, $end_date));
         $tid = OCP\DB::insertid('*PREFIX*collaboration_task');
         $query = OCP\DB::prepare('INSERT INTO `*PREFIX*collaboration_task_status`(`tid`, `status`, `last_updated_time`, `member`) VALUES(?, ?, CURRENT_TIMESTAMP, ?)');
         $result = $query->execute(array($tid, $status, $member));
         if (is_null($member)) {
             OC_Collaboration_Post::createPost('Task Unassigned', 'The task \'' . $title . '\' has been created with deadline ' . OC_Collaboration_Time::convertToFullDate($deadline[0]) . ' and is not yet assigned to any member.', $creator, $pid, 'Task Unassigned', array($creator), true, $tid);
         } else {
             OC_Collaboration_Post::createPost('Task Assigned', 'The task \'' . $title . '\' has been assigned with deadline ' . OC_Collaboration_Time::convertToFullDate($deadline[0]) . '.', $creator, $pid, 'Task Assigned', array($member), true, $tid);
         }
         \OCP\DB::commit();
     } catch (\Exception $e) {
         OC_Log::write('collaboration', __METHOD__ . ', Exception: ' . $e->getMessage(), OCP\Util::DEBUG);
         return false;
     }
     return $tid;
 }