/** * Get the template for a specific activity-event in the activities * * @param array $activity An array with all the activity data in it * @return string */ public function show($activity) { $tmpl = new Template('activity', 'stream.item'); $tmpl->assign('formattedDate', $this->dateTimeFormatter->formatDateTime($activity['timestamp'])); $tmpl->assign('formattedTimestamp', Template::relative_modified_date($activity['timestamp'])); $tmpl->assign('user', $activity['user']); $tmpl->assign('displayName', User::getDisplayName($activity['user'])); if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) { // We do not link the subject as we create links for the parameters instead $activity['link'] = ''; } $tmpl->assign('event', $activity); if ($activity['file']) { $this->view->chroot('/' . $activity['affecteduser'] . '/files'); $exist = $this->view->file_exists($activity['file']); $is_dir = $this->view->is_dir($activity['file']); $tmpl->assign('previewLink', $this->getPreviewLink($activity['file'], $is_dir)); // show a preview image if the file still exists $mimeType = \OC_Helper::getFileNameMimeType($activity['file']); if ($mimeType && !$is_dir && $this->preview->isMimeSupported($mimeType) && $exist) { $tmpl->assign('previewImageLink', $this->urlGenerator->linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150))); } else { $mimeTypeIcon = Template::mimetype_icon($is_dir ? 'dir' : $mimeType); $mimeTypeIcon = substr($mimeTypeIcon, -4) === '.png' ? substr($mimeTypeIcon, 0, -4) . '.svg' : $mimeTypeIcon; $tmpl->assign('previewImageLink', $mimeTypeIcon); $tmpl->assign('previewLinkIsDir', true); } } return $tmpl->fetchPage(); }
/** * @NoAdminRequired * lists the documents the user has access to (including shared files, once the code in core has been fixed) * also adds session and member info for these files */ public function listAll() { $found = Storage::getDocuments(); $fileIds = array(); $documents = array(); foreach ($found as $key => $document) { if (is_object($document)) { $documents[] = $document->getData(); } else { $documents[$key] = $document; } $documents[$key]['icon'] = preg_replace('/\\.png$/', '.svg', \OCP\Template::mimetype_icon($document['mimetype'])); $documents[$key]['hasPreview'] = \OC::$server->getPreviewManager()->isMimeSupported($document['mimetype']); $fileIds[] = $document['fileid']; } usort($documents, function ($a, $b) { return @$b['mtime'] - @$a['mtime']; }); $session = new Db\Session(); $sessions = $session->getCollectionBy('file_id', $fileIds); $members = array(); $member = new Db\Member(); foreach ($sessions as $session) { $members[$session['es_id']] = $member->getActiveCollection($session['es_id']); } return array('status' => 'success', 'documents' => $documents, 'sessions' => $sessions, 'members' => $members); }
/** * Adds the SVG media type if it's not already there * * If it's enabled, but doesn't work, an exception will be raised when trying to generate a * preview. If it's disabled, we support it via the browser's native support * * @param string[] $supportedMimes * @param bool $nativeSvgSupport * * @return string[] */ private function addSvgSupport($supportedMimes, $nativeSvgSupport) { if (!in_array('image/svg+xml', $supportedMimes) && $nativeSvgSupport) { $supportedMimes['image/svg+xml'] = Template::mimetype_icon('image/svg+xml'); } return $supportedMimes; }
/** Prepare document(s) structure */ private function prepareDocuments($rawDocuments) { $discovery_parsed = null; try { $discovery = $this->getDiscovery(); $loadEntities = libxml_disable_entity_loader(true); $discovery_parsed = simplexml_load_string($discovery); libxml_disable_entity_loader($loadEntities); if ($discovery_parsed === false) { $this->cache->remove('discovery.xml'); $wopiRemote = $this->appConfig->getAppValue('wopi_url'); return array('status' => 'error', 'message' => $this->l10n->t('Collabora Online: discovery.xml from "%s" is not a well-formed XML string.', array($wopiRemote)), 'hint' => $this->l10n->t('Please contact the "%s" administrator.', array($wopiRemote))); } } catch (ResponseException $e) { return array('status' => 'error', 'message' => $e->getMessage(), 'hint' => $e->getHint()); } $fileIds = array(); $documents = array(); $lolang = strtolower(str_replace('_', '-', $this->settings->getUserValue($this->uid, 'core', 'lang', 'en'))); foreach ($rawDocuments as $key => $document) { if (is_object($document)) { $documents[] = $document->getData(); } else { $documents[$key] = $document; } $documents[$key]['icon'] = preg_replace('/\\.png$/', '.svg', \OCP\Template::mimetype_icon($document['mimetype'])); $documents[$key]['hasPreview'] = \OC::$server->getPreviewManager()->isMimeSupported($document['mimetype']); $ret = $this->getWopiSrcUrl($discovery_parsed, $document['mimetype']); $documents[$key]['urlsrc'] = $ret['urlsrc']; $documents[$key]['action'] = $ret['action']; $documents[$key]['lolang'] = $lolang; $fileIds[] = $document['fileid']; } usort($documents, function ($a, $b) { return @$b['mtime'] - @$a['mtime']; }); $session = new Db\Session(); $sessions = $session->getCollectionBy('file_id', $fileIds); $members = array(); $member = new Db\Member(); foreach ($sessions as $session) { $members[$session['es_id']] = $member->getActiveCollection($session['es_id']); } return array('status' => 'success', 'documents' => $documents, 'sessions' => $sessions, 'members' => $members); }