Example #1
0
 /**
  * Search for query in calendar events
  *
  * @param string $query
  * @return array list of \OCA\Calendar\Search\Event
  */
 function search($query)
 {
     $calendars = \OC_Calendar_Calendar::allCalendars(\OCP\USER::getUser(), true);
     // check if the calenar is enabled
     if (count($calendars) == 0 || !\OCP\App::isEnabled('calendar')) {
         return array();
     }
     $results = array();
     foreach ($calendars as $calendar) {
         $objects = \OC_Calendar_Object::all($calendar['id']);
         $date = strtotime($query);
         // search all calendar objects, one by one
         foreach ($objects as $object) {
             // skip non-events
             if ($object['objecttype'] != 'VEVENT') {
                 continue;
             }
             // check the event summary string
             if (stripos($object['summary'], $query) !== false) {
                 $results[] = new \OCA\Calendar\Search\Event($object);
                 continue;
             }
             // check if the event is happening on a queried date
             $range = $this->getDateRange($object);
             if ($date && $this->fallsWithin($date, $range)) {
                 $results[] = new \OCA\Calendar\Search\Event($object);
                 continue;
             }
         }
     }
     return $results;
 }
Example #2
0
 public static function getCalenderSources($parameters)
 {
     $base_url = \OCP\Util::linkTo('calendar', 'ajax/events.php') . '?calendar_id=';
     foreach (Addressbook::all(\OCP\USER::getUser()) as $addressbook) {
         $parameters['sources'][] = array('url' => $base_url . 'birthday_' . $addressbook['id'], 'backgroundColor' => '#cccccc', 'borderColor' => '#888', 'textColor' => 'black', 'cache' => true, 'editable' => false);
     }
 }
Example #3
0
 /**
  * Returns a list of ACE's for this node.
  *
  * Each ACE has the following properties:
  *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  *     currently the only supported privileges
  *   * 'principal', a url to the principal who owns the node
  *   * 'protected' (optional), indicating that this ACE is not allowed to
  *      be updated.
  *
  * @return array
  */
 public function getACL()
 {
     $readprincipal = $this->getOwner();
     $writeprincipal = $this->getOwner();
     $uid = CalendarCalendar::extractUserID($this->getOwner());
     $calendar = CalendarApp::getCalendar($this->calendarInfo['id'], false, false);
     if ($uid === \OCP\USER::getUser() && (bool) $calendar['issubscribe'] === true) {
         $readprincipal = 'principals/' . \OCP\USER::getUser();
         $writeprincipal = '';
     }
     if ($uid !== \OCP\USER::getUser()) {
         $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $this->calendarInfo['id']);
         if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_READ) {
             $readprincipal = 'principals/' . \OCP\USER::getUser();
             $writeprincipal = '';
         }
         if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE) {
             $readprincipal = 'principals/' . \OCP\USER::getUser();
             $writeprincipal = 'principals/' . \OCP\USER::getUser();
         }
     }
     $acl = array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-read', 'protected' => true), array('privilege' => '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}read-free-busy', 'principal' => '{DAV:}authenticated', 'protected' => true));
     if (empty($this->calendarInfo['{http://sabredav.org/ns}read-only'])) {
         $acl[] = ['privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true];
         $acl[] = ['privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true];
     }
     return $acl;
 }
Example #4
0
 /**
  * Returns a list of ACE's for this node.
  *
  * Each ACE has the following properties:
  *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  *     currently the only supported privileges
  *   * 'principal', a url to the principal who owns the node
  *   * 'protected' (optional), indicating that this ACE is not allowed to
  *      be updated.
  *
  * @return array
  */
 public function getACL()
 {
     $readprincipal = $this->getOwner();
     $writeprincipal = $this->getOwner();
     $createprincipal = $this->getOwner();
     $deleteprincipal = $this->getOwner();
     $uid = AddrBook::extractUserID($this->getOwner());
     //\OCP\Config::setUserValue($uid, 'contactsplus', 'syncaddrbook', $this->addressBookInfo['uri']);
     $readWriteACL = array(array('privilege' => '{DAV:}read', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true));
     if ($uid !== \OCP\USER::getUser()) {
         $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(ContactsApp::SHAREADDRESSBOOK, ContactsApp::SHAREADDRESSBOOKPREFIX . $this->addressBookInfo['id']);
         if ($sharedAddressbook) {
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
                 return $readWriteACL;
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE) {
                 $createprincipal = 'principals/' . \OCP\USER::getUser();
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) {
                 $readprincipal = 'principals/' . \OCP\USER::getUser();
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) {
                 $writeprincipal = 'principals/' . \OCP\USER::getUser();
             }
             if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
                 $deleteprincipal = 'principals/' . \OCP\USER::getUser();
             }
         }
     } else {
         return parent::getACL();
     }
     return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write-content', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}bind', 'principal' => $createprincipal, 'protected' => true), array('privilege' => '{DAV:}unbind', 'principal' => $deleteprincipal, 'protected' => true));
 }
Example #5
0
 /**
  * Returns a list of ACE's for this node.
  *
  * Each ACE has the following properties:
  *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  *     currently the only supported privileges
  *   * 'principal', a url to the principal who owns the node
  *   * 'protected' (optional), indicating that this ACE is not allowed to
  *      be updated.
  *
  * @return array
  */
 public function getACL()
 {
     $readprincipal = $this->getOwner();
     $writeprincipal = $this->getOwner();
     $calendarConnector = new CalendarConnector();
     $shareConnector = new ShareConnector();
     $uid = $calendarConnector->extractUserID($this->getOwner());
     $calendar = $calendarConnector->getCalendar($this->calendarInfo['id'], false, false);
     $user = \OCP\USER::getUser();
     if ($uid === $user && (bool) $calendar['issubscribe'] === true) {
         $readprincipal = 'principals/' . $user;
         $writeprincipal = '';
     }
     if ($uid !== $user) {
         $sharedCalendar = $shareConnector->getItemSharedWithBySourceCalendar($this->calendarInfo['id']);
         if ($sharedCalendar && $sharedCalendar['permissions'] & $shareConnector->getReadAccess()) {
             $readprincipal = 'principals/' . $user;
             $writeprincipal = '';
         }
         if ($sharedCalendar && $sharedCalendar['permissions'] & $shareConnector->getUpdateAccess()) {
             $readprincipal = 'principals/' . $user;
             $writeprincipal = 'principals/' . $user;
         }
     }
     $acl = array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-read', 'protected' => true), array('privilege' => '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}read-free-busy', 'principal' => '{DAV:}authenticated', 'protected' => true));
     if (empty($this->calendarInfo['{http://sabredav.org/ns}read-only'])) {
         $acl[] = ['privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true];
         $acl[] = ['privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true];
     }
     return $acl;
 }
Example #6
0
 public function __construct($userid = null)
 {
     if ($userid !== null) {
         $this->userid = $userid;
     } else {
         $this->userid = \OCP\USER::getUser();
     }
 }
Example #7
0
 public function setFileData($path, $width, $height)
 {
     $stmt = \OCP\DB::prepare('INSERT INTO `*PREFIX*pictures_images_cache` (`uid_owner`, `path`, `width`, `height`) VALUES (?, ?, ?, ?)');
     $stmt->execute(array(\OCP\USER::getUser(), $path, $width, $height));
     $ret = array('path' => $path, 'width' => $width, 'height' => $height);
     $dir = dirname($path);
     $this->cache[$dir][$path] = $ret;
     return $ret;
 }
 /**
  * init the versioning and create the versions folder.
  */
 public static function init()
 {
     if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') {
         // create versions folder
         $foldername = \OCP\Config::getSystemValue('datadirectory') . '/' . \OCP\USER::getUser() . '/' . \OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
         if (!is_dir($foldername)) {
             mkdir($foldername);
         }
     }
 }
Example #9
0
 /**
  * Delete thumb from filesystem if exists
  * @param string $thumbPath
  */
 private static function deleteThumb($thumbPath)
 {
     // Get full thumbnail path
     $fileInfo = pathinfo($thumbPath);
     $user = \OCP\USER::getUser();
     $previewDir = \OC_User::getHome($user) . '/oclife/previews/' . $user;
     $fullThumbPath = $previewDir . $fileInfo['dirname'] . '/' . $fileInfo['filename'] . '.png';
     // If thumbnail exists remove it
     if (file_exists($fullThumbPath)) {
         unlink($fullThumbPath);
     }
 }
Example #10
0
 /**
  * Returns the list of addressbooks for a specific user.
  *
  * @param string $principaluri
  * @return array
  */
 public function getAddressBooksForUser($principaluri)
 {
     $data = AddrBook::allWherePrincipalURIIs($principaluri);
     $addressbooks = array();
     foreach ($data as $i) {
         if ($i['userid'] !== \OCP\USER::getUser()) {
             $i['uri'] = $i['uri'] . '_shared_by_' . $i['userid'];
         }
         $addressbooks[] = array('id' => $i['id'], 'uri' => $i['uri'], 'principaluri' => 'principals/' . $i['userid'], '{DAV:}displayname' => $i['displayname'], '{' . \Sabre\CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => $i['description'], '{http://calendarserver.org/ns/}getctag' => $i['ctag'], '{http://sabredav.org/ns}sync-token' => $i['ctag'] ? $i['ctag'] : '0');
         //\OCP\Util::writeLog('kontakte','CARDDAV->:'.$i['displayname'], \OCP\Util::DEBUG);
     }
     return $addressbooks;
 }
Example #11
0
 /**
  * Returns a list of ACE's for this node.
  *
  * Each ACE has the following properties:
  *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  *     currently the only supported privileges
  *   * 'principal', a url to the principal who owns the node
  *   * 'protected' (optional), indicating that this ACE is not allowed to
  *      be updated.
  *
  * @return array
  */
 public function getACL()
 {
     $readprincipal = $this->getOwner();
     $writeprincipal = $this->getOwner();
     $uid = AddrBook::extractUserID($this->getOwner());
     if ($uid !== \OCP\USER::getUser()) {
         $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(ContactsApp::SHAREADDRESSBOOK, ContactsApp::SHAREADDRESSBOOKPREFIX . $this->addressBookInfo['id']);
         if ($sharedAddressbook && $sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) {
             $readprincipal = 'principals/' . \OCP\USER::getUser();
         }
         if ($sharedAddressbook && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) {
             $writeprincipal = 'principals/' . \OCP\USER::getUser();
         }
     }
     return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true));
 }
 /**
  * Search for query in tasks
  *
  * @param string $query
  * @return array list of \OCA\Tasks\Controller\Task
  */
 function search($query)
 {
     $calendars = \OC_Calendar_Calendar::allCalendars(\OCP\USER::getUser(), true);
     $user_timezone = \OC_Calendar_App::getTimezone();
     // check if the calenar is enabled
     if (count($calendars) == 0 || !\OCP\App::isEnabled('tasks')) {
         return array();
     }
     $results = array();
     foreach ($calendars as $calendar) {
         // $calendar_entries = \OC_Calendar_Object::all($calendar['id']);
         $objects = \OC_Calendar_Object::all($calendar['id']);
         // $date = strtotime($query);
         // 	// search all calendar objects, one by one
         foreach ($objects as $object) {
             // skip non-todos
             if ($object['objecttype'] != 'VTODO') {
                 continue;
             }
             $vtodo = Helper::parseVTODO($object['calendardata']);
             $id = $object['id'];
             $calendarId = $object['calendarid'];
             // check these properties
             $properties = array('SUMMARY', 'DESCRIPTION', 'LOCATION', 'CATEGORIES');
             foreach ($properties as $property) {
                 $string = $vtodo->getAsString($property);
                 if (stripos($string, $query) !== false) {
                     // $results[] = new \OCA\Tasks\Controller\Task($id,$calendarId,$vtodo,$property,$query,$user_timezone);
                     $results[] = Helper::arrayForJSON($id, $vtodo, $user_timezone, $calendarId);
                     continue 2;
                 }
             }
             $comments = $vtodo->COMMENT;
             if ($comments) {
                 foreach ($comments as $com) {
                     if (stripos($com->value, $query) !== false) {
                         // $results[] = new \OCA\Tasks\Controller\Task($id,$calendarId,$vtodo,'COMMENTS',$query,$user_timezone);
                         $results[] = Helper::arrayForJSON($id, $vtodo, $user_timezone, $calendarId);
                         continue 2;
                     }
                 }
             }
         }
     }
     usort($results, array($this, 'sort_completed'));
     return $results;
 }
Example #13
0
 /**
  * Returns a list of ACE's for this node.
  *
  * Each ACE has the following properties:
  *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  *     currently the only supported privileges
  *   * 'principal', a url to the principal who owns the node
  *   * 'protected' (optional), indicating that this ACE is not allowed to
  *      be updated.
  *
  * @return array
  */
 public function getACL()
 {
     $readprincipal = $this->getOwner();
     $writeprincipal = $this->getOwner();
     $uid = $this->carddavBackend->userIDByPrincipal($this->getOwner());
     if ($uid != \OCP\USER::getUser()) {
         list(, $id) = explode('::', $this->addressBookInfo['id']);
         $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id);
         if ($sharedAddressbook && $sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) {
             $readprincipal = 'principals/' . \OCP\USER::getUser();
         }
         if ($sharedAddressbook && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) {
             $writeprincipal = 'principals/' . \OCP\USER::getUser();
         }
     }
     return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true));
 }
Example #14
0
 public function __construct($imagePath, $user = null, $square = false)
 {
     if (!Filesystem::isValidPath($imagePath)) {
         return;
     }
     if (is_null($user)) {
         $this->view = Filesystem::getView();
         $this->user = \OCP\USER::getUser();
     } else {
         $this->view = new View('/' . $user . '/files');
         $this->user = $user;
     }
     $galleryDir = \OC_User::getHome($this->user) . '/gallery/' . $this->user . '/';
     $this->path = $galleryDir . $imagePath . '.png';
     if (!file_exists($this->path)) {
         self::create($imagePath, $square);
     }
 }
Example #15
0
function explore($current_dir, $sub_dirs, $num_of_results)
{
    $return = array();
    // Search for pdfs in sub directories.
    foreach ($sub_dirs as $dir) {
        $pdfs = \OC_FileCache::searchByMime('application', 'pdf', '/' . \OCP\USER::getUser() . '/files' . $current_dir . $dir . '/');
        sort($pdfs);
        $max_count = min(count($pdfs), $num_of_results);
        $thumbs = array();
        for ($i = $max_count - 1; $i >= 0; $i--) {
            if (!in_array($pdfs[$i], $thumbs)) {
                $thumbs[] = $pdfs[$i];
            }
        }
        $return[] = array($dir, $thumbs);
    }
    return $return;
}
 public function getFileData($path)
 {
     $gallery_path = \OCP\Config::getSystemValue('datadirectory') . '/' . \OC_User::getUser() . '/gallery';
     $path = $gallery_path . $path;
     $stmt = \OCP\DB::prepare('SELECT * FROM *PREFIX*pictures_images_cache WHERE uid_owner LIKE ? AND path = ?');
     $result = $stmt->execute(array(\OCP\USER::getUser(), $path));
     if (($row = $result->fetchRow()) != false) {
         return $row;
     }
     $image = new \OC_Image();
     if (!$image->loadFromFile($path)) {
         return false;
     }
     $stmt = \OCP\DB::prepare('INSERT INTO *PREFIX*pictures_images_cache (uid_owner, path, width, height) VALUES (?, ?, ?, ?)');
     $stmt->execute(array(\OCP\USER::getUser(), $path, $image->width(), $image->height()));
     $ret = array('path' => $path, 'width' => $image->width(), 'height' => $image->height());
     unset($image);
     return $ret;
 }
Example #17
0
 /**
  * Returns the list of addressbooks for a specific user.
  *
  * @param string $principaluri
  * @return array
  */
 public function getAddressBooksForUser($principaluri)
 {
     $app = new Contacts\App();
     $userAddressBooks = array();
     foreach ($this->backends as $backendName) {
         $backend = $app->getBackend($backendName);
         $addressBooks = $backend->getAddressBooksForUser();
         if (is_array($addressBooks)) {
             foreach ($addressBooks as $addressBook) {
                 if ($addressBook['owner'] != \OCP\USER::getUser()) {
                     $addressBook['uri'] = $addressBook['uri'] . '_shared_by_' . $addressBook['owner'];
                     $addressBook['displayname'] = $addressBook['displayname'];
                 }
                 $userAddressBooks[] = array('id' => $backend->name . '::' . $addressBook['id'], 'uri' => $addressBook['uri'], 'principaluri' => 'principals/' . $addressBook['owner'], '{DAV:}displayname' => $addressBook['displayname'], '{' . \Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => $addressBook['description'], '{http://calendarserver.org/ns/}getctag' => $addressBook['lastmodified'], '{' . \Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new \Sabre_CardDAV_Property_SupportedAddressData());
             }
         }
     }
     return $userAddressBooks;
 }
Example #18
0
 /**
  * Returns a list of ACE's for this node.
  *
  * Each ACE has the following properties:
  *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  *     currently the only supported privileges
  *   * 'principal', a url to the principal who owns the node
  *   * 'protected' (optional), indicating that this ACE is not allowed to
  *      be updated.
  *
  * @return array
  */
 public function getACL()
 {
     $readprincipal = $this->getOwner();
     $writeprincipal = $this->getOwner();
     $uid = CalendarCalendar::extractUserID($this->getOwner());
     if ($uid != \OCP\USER::getUser()) {
         $object = VObject::parse($this->objectData['calendardata']);
         $sharedCalendar = \OCP\Share::getItemSharedWithBySource(CalendarApp::SHARECALENDAR, CalendarApp::SHARECALENDARPREFIX . $this->calendarInfo['id']);
         $sharedAccessClassPermissions = Object::getAccessClassPermissions($object);
         if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_READ && $sharedAccessClassPermissions & \OCP\PERMISSION_READ) {
             $readprincipal = 'principals/' . \OCP\USER::getUser();
         }
         if ($sharedCalendar && $sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE && $sharedAccessClassPermissions & \OCP\PERMISSION_UPDATE) {
             $writeprincipal = 'principals/' . \OCP\USER::getUser();
         } else {
             $writeprincipal = '';
         }
     }
     return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-read', 'protected' => true));
 }
Example #19
0
 function search($query)
 {
     $addressbooks = Addressbook::all(\OCP\USER::getUser(), 1);
     if (count($addressbooks) == 0 || !\OCP\App::isEnabled('contacts')) {
         return array();
     }
     $results = array();
     $l = new \OC_l10n('contacts');
     foreach ($addressbooks as $addressbook) {
         $vcards = VCard::all($addressbook['id']);
         foreach ($vcards as $vcard) {
             if (substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) {
                 //$link = \OCP\Util::linkTo('contacts', 'index.php').'?id='.urlencode($vcard['id']);
                 $link = 'javascript:openContact(' . $vcard['id'] . ')';
                 $results[] = new \OC_Search_Result($vcard['fullname'], '', $link, (string) $l->t('Contact'));
                 //$name,$text,$link,$type
             }
         }
     }
     return $results;
 }
Example #20
0
function explore($current_dir, $sub_dirs)
{
    $return = array();
    // Search for pdfs in sub directories.
    foreach ($sub_dirs as $dir) {
        $pdfs = \OC_FileCache::searchByMime('application', 'pdf', '/' . \OCP\USER::getUser() . '/files' . $current_dir . $dir . '/');
        sort($pdfs);
        $thumbs = array();
        $count = 1;
        foreach ($pdfs as $pdf) {
            // We need only 3 pdf pages to create thumbnails for folders.
            if ($count <= 3) {
                // Store the urls in an array.
                $thumbs[] = $pdf;
                $count++;
            }
        }
        // Return the directory and contained pdfs(any 3).
        $return[] = array($dir, $thumbs);
    }
    return $return;
}
Example #21
0
 /**
  * Returns a list of ACE's for this node.
  *
  * Each ACE has the following properties:
  *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  *     currently the only supported privileges
  *   * 'principal', a url to the principal who owns the node
  *   * 'protected' (optional), indicating that this ACE is not allowed to
  *      be updated.
  *
  * @return array
  */
 public function getACL()
 {
     $readprincipal = $this->getOwner();
     $writeprincipal = $this->getOwner();
     $user = \OCP\USER::getUser();
     $calendarConnector = new CalendarConnector();
     $shareConnector = new ShareConnector();
     $objectParser = new ObjectParser($user);
     $uid = $calendarConnector->extractUserID($this->getOwner());
     if ($uid != $user) {
         $object = $objectParser->parse($this->objectData['calendardata']);
         $sharedCalendar = $shareConnector->getItemSharedWithBySourceCalendar($this->calendarInfo['id']);
         $sharedAccessClassPermissions = $objectParser->getAccessClassPermissions($object);
         if ($sharedCalendar && $sharedCalendar['permissions'] & $shareConnector->getReadAccess() && $sharedAccessClassPermissions & $shareConnector->getReadAccess()) {
             $readprincipal = 'principals/' . $user;
         }
         if ($sharedCalendar && $sharedCalendar['permissions'] & $shareConnector->getUpdateAccess() && $sharedAccessClassPermissions & $shareConnector->getUpdateAccess()) {
             $writeprincipal = 'principals/' . $user;
         } else {
             $writeprincipal = '';
         }
     }
     return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal . '/calendar-proxy-write', 'protected' => true), array('privilege' => '{DAV:}read', 'principal' => $readprincipal . '/calendar-proxy-read', 'protected' => true));
 }
Example #22
0
 /**
  * @brief remember the file which should be deleted and it's owner
  * @param array $params
  * @return boolean
  */
 public static function preDelete($params)
 {
     $path = $params[\OC\Files\Filesystem::signal_param_path];
     // skip this method if the trash bin is enabled or if we delete a file
     // outside of /data/user/files
     if (\OCP\App::isEnabled('files_trashbin')) {
         return true;
     }
     $util = new Util(new \OC_FilesystemView('/'), \OCP\USER::getUser());
     list($owner, $ownerPath) = $util->getUidAndFilename($path);
     self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]] = array('uid' => $owner, 'path' => $ownerPath);
 }
 /**
  * @NoAdminRequired
  */
 public function deleteCalendar()
 {
     $calId = (int) $this->params('calendarid');
     $del = CalendarCalendar::deleteCalendar($calId);
     if ($del === true) {
         $calendars = CalendarCalendar::allCalendars($this->userId, false, false, false);
         $bNewId = null;
         //\OCP\Util::writeLog($this->appName, 'DEL COUNT-> '.count($calendars).$calendars[0]['id'], \OCP\Util::DEBUG);
         if (\OCP\USER::isLoggedIn() && count($calendars) === 0) {
             $bNewId = CalendarCalendar::addDefaultCalendars($this->userId);
         }
         $params = ['status' => 'success', 'newid' => $bNewId];
     } else {
         $params = ['status' => 'error'];
     }
     $response = new JSONResponse($params);
     return $response;
 }
Example #24
0
 /**
  * @brief deletes a card with the data provided by sabredav
  * @param integer $aid Addressbook id
  * @param string $uri the uri of the card
  * @return boolean
  */
 public static function deleteFromDAVData($aid, $uri)
 {
     $contact = self::findWhereDAVDataIs($aid, $uri);
     if (!$contact) {
         \OCP\Util::writeLog(App::$appname, __METHOD__ . ', contact not found: ' . $uri, \OCP\Util::DEBUG);
         throw new \Sabre_DAV_Exception_NotFound(App::$l10n->t('Contact not found.'));
     }
     $id = $contact['id'];
     try {
         //Libasys
         $iosSupport = \OCP\Config::getUserValue(\OCP\USER::getUser(), App::$appname, 'iossupport');
         if ($contact['component'] == 'GROUP' && $iosSupport) {
             $stmt = \OCP\DB::prepare('DELETE FROM `*PREFIX*vcategory` WHERE `category` = ? AND `uid` = ?');
             $stmt->execute(array($contact['fullname'], \OCP\User::getUser()));
         }
         return self::delete($id);
     } catch (\Exception $e) {
         switch ($e->getCode()) {
             case 403:
                 \OCP\Util::writeLog(App::$appname, __METHOD__ . ', forbidden: ' . $uri, \OCP\Util::DEBUG);
                 throw new \Sabre_DAV_Exception_Forbidden(App::$l10n->t($e->getMessage()));
                 break;
             case 404:
                 \OCP\Util::writeLog(App::$appname, __METHOD__ . ', contact not found: ' . $uri, \OCP\Util::DEBUG);
                 throw new \Sabre_DAV_Exception_NotFound(App::$l10n->t($e->getMessage()));
                 break;
             default:
                 throw $e;
                 break;
         }
     }
     return true;
 }
Example #25
0
 /**
  * @brief checks if access is public/anonymous user
  * @return bool
  */
 public static function isPublicAccess()
 {
     if (\OCP\USER::getUser() === false || isset($_GET['service']) && $_GET['service'] == 'files' && isset($_GET['t'])) {
         return true;
     } else {
         return false;
     }
 }
Example #26
0
 public static function addingDummyContacts($iNum)
 {
     $active_addressbooks = array();
     $active_addressbooks = Addressbook::active(\OCP\USER::getUser());
     $contacts_addressbook = array();
     $ids = array();
     foreach ($active_addressbooks as $addressbook) {
         $ids[] = $addressbook['id'];
     }
     for ($i = 0; $i < $iNum; $i++) {
         //$dummyName=self::generateFnDummy();
         $dummySure = self::generateFnDummy(10);
         $dummyLast = self::generateFnDummy(10);
         $uid = substr(md5(rand() . time()), 0, 10);
         $aid = $ids[0];
         $vcard = new VObject\Component\VCard(array('N' => array($dummySure, $dummyLast, '', '', ''), 'UID' => $uid));
         $vcard->FN = $dummySure . ' ' . $dummyLast;
         $vcard->CATEGORIES = 'familie';
         $vcard->add('TEL', '+1 555 34567 456', array('type' => 'fax'));
         $vcard->add('TEL', '+1 555 34567 457', array('type' => 'voice', 'pref' => 1));
         $vcard->add('EMAIL', '*****@*****.**', array('type' => 'work'));
         $vcard->add('EMAIL', '*****@*****.**', array('type' => 'private', 'pref' => 1));
         $id = VCard::add($aid, $vcard, null, true);
     }
 }
Example #27
0
    public function checkAlarm()
    {
        $getStartdate = strtotime($this->getStartofTheWeek());
        $getEnddate = strtotime($this->getEndofTheWeek());
        $start = $this->getStartDayDB($getStartdate);
        $end = $this->getEndDayDB($getEnddate);
        $addWhereSql = '';
        $ids = array();
        //\OCP\Util::writeLog('calendarplus','COUNT ALARM:'.count($ids) ,\OCP\Util::DEBUG);
        $aExec = array('1', 'VJOURNAL');
        foreach ($this->aCalendars as $calInfo) {
            $ids[] = $calInfo['id'];
            array_push($aExec, $calInfo['id']);
        }
        $id_sql = '';
        if (count($ids) > 0) {
            $id_sql = join(',', array_fill(0, count($ids), '?'));
            array_push($aExec, $start, $end, $start, $end, $start, $start);
            $repeatDB = new RepeatDAO(\OC::$server->getDb(), \OCP\USER::getUser());
            $stmt = \OCP\DB::prepare('SELECT * FROM `' . App::CldObjectTable . '` WHERE `isalarm` = ? AND `objecttype`!= ?  AND `calendarid` IN (' . $id_sql . ') ' . ' AND ((`startdate` >= ? AND `enddate` <= ? AND `repeating` = 0)' . ' OR (`enddate` >= ? AND `startdate` <= ? AND `repeating` = 0)' . ' OR (`startdate` <= ? AND `repeating` = 1) ' . ' OR (`startdate` >= ? AND `repeating` = 1)
			)');
            $result = $stmt->execute($aExec);
            $calendarobjects = array();
            while ($row = $result->fetchRow()) {
                if ($row['repeating']) {
                    $cachedinperiod = $repeatDB->getEventInperiod($row['id'], $start, $end, true);
                    //\OCP\Util::writeLog('calendarplus','REPEAT ALARM:'.$row['id'] ,\OCP\Util::DEBUG);
                    $rowRepeat = array();
                    if (is_array($cachedinperiod)) {
                        foreach ($cachedinperiod as $cachedevent) {
                            $rowRepeat['startdate'] = $cachedevent['startdate'];
                            $rowRepeat['enddate'] = $cachedevent['enddate'];
                            $rowRepeat['calendardata'] = $row['calendardata'];
                            $rowRepeat['id'] = $row['id'];
                            $rowRepeat['summary'] = $row['summary'];
                            $calendarobjects[] = $rowRepeat;
                        }
                    }
                }
                $calendarobjects[] = $row;
            }
        }
        if (count($calendarobjects) > 0) {
            $this->parseAlarm($calendarobjects);
        } else {
            return false;
        }
    }
Example #28
0
 /**
  * @brief Deletes all files and folders recursively within a directory
  * @param $directory The directory whose contents will be deleted
  * @param $empty Flag indicating whether directory will be emptied
  * @returns true/false
  *
  * @note By default the directory specified by $directory will be
  * deleted together with its contents. To avoid this set $empty to true
  */
 public function deleteAll($directory, $empty = false)
 {
     // strip leading slash
     if (substr($directory, 0, 1) == "/") {
         $directory = substr($directory, 1);
     }
     // strip trailing slash
     if (substr($directory, -1) == "/") {
         $directory = substr($directory, 0, -1);
     }
     if (!$this->file_exists(\OCP\USER::getUser() . '/' . $directory) || !$this->is_dir(\OCP\USER::getUser() . '/' . $directory)) {
         return false;
     } elseif (!$this->is_readable(\OCP\USER::getUser() . '/' . $directory)) {
         return false;
     } else {
         $directoryHandle = $this->opendir(\OCP\USER::getUser() . '/' . $directory);
         while ($contents = readdir($directoryHandle)) {
             if ($contents != '.' && $contents != '..') {
                 $path = $directory . "/" . $contents;
                 if ($this->is_dir($path)) {
                     deleteAll($path);
                 } else {
                     $this->unlink(\OCP\USER::getUser() . '/' . $path);
                     // TODO: make unlink use same system path as is_dir
                 }
             }
         }
         //$this->closedir( $directoryHandle ); // TODO: implement closedir in OC_FSV
         if ($empty == false) {
             if (!$this->rmdir($directory)) {
                 return false;
             }
         }
         return true;
     }
 }
Example #29
0
<?php

/**
 * Copyright (c) 2013, Sam Tuke <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 *
 * Script to handle admin settings for encrypted key recovery
 */
use OCA\Encryption;
\OCP\JSON::checkLoggedIn();
\OCP\JSON::checkAppEnabled('files_encryption');
\OCP\JSON::callCheck();
$l = \OC::$server->getL10N('files_encryption');
if (isset($_POST['userEnableRecovery']) && (0 == $_POST['userEnableRecovery'] || '1' === $_POST['userEnableRecovery'])) {
    $userId = \OCP\USER::getUser();
    $view = new \OC\Files\View('/');
    $util = new \OCA\Encryption\Util($view, $userId);
    // Save recovery preference to DB
    $return = $util->setRecoveryForUser($_POST['userEnableRecovery']);
    if ($_POST['userEnableRecovery'] === '1') {
        $util->addRecoveryKeys();
    } else {
        $util->removeRecoveryKeys();
    }
} else {
    $return = false;
}
// Return success or failure
if ($return) {
    \OCP\JSON::success(array('data' => array('message' => $l->t('File recovery settings updated'))));
Example #30
0
    OCA\Encryption\Helper::registerFilesystemHooks();
    // App manager related hooks
    OCA\Encryption\Helper::registerAppHooks();
    stream_wrapper_register('crypt', 'OCA\\Encryption\\Stream');
    // check if we are logged in
    if (OCP\User::isLoggedIn()) {
        // ensure filesystem is loaded
        if (!\OC\Files\Filesystem::$loaded) {
            \OC_Util::setupFS();
        }
        $view = new OC_FilesystemView('/');
        $sessionReady = OCA\Encryption\Helper::checkRequirements();
        if ($sessionReady) {
            $session = new \OCA\Encryption\Session($view);
        }
        $user = \OCP\USER::getUser();
        // check if user has a private key
        if ($sessionReady === false || !$view->file_exists('/' . $user . '/files_encryption/' . $user . '.private.key') && OCA\Encryption\Crypt::mode() === 'server') {
            // Force the user to log-in again if the encryption key isn't unlocked
            // (happens when a user is logged in before the encryption app is
            // enabled)
            OCP\User::logout();
            header("Location: " . OC::$WEBROOT . '/');
            exit;
        }
    }
} else {
    // logout user if we are in maintenance to force re-login
    OCP\User::logout();
}
// Register settings scripts