/** * @PublicPage * @NoCSRFRequired * * @return TemplateResponse */ public function show() { try { $user = $this->activityManager->getCurrentUserId(); $userLang = $this->config->getUserValue($user, 'core', 'lang'); // Overwrite user and language in the helper $l = Util::getL10N('activity', $userLang); $l->forceLanguage($userLang); $this->helper->setL10n($l); $this->helper->setUser($user); $description = (string) $l->t('Personal activity feed for %s', $user); $activities = $this->data->read($this->helper, $this->settings, 0, self::DEFAULT_PAGE_SIZE, 'all', $user); } catch (\UnexpectedValueException $e) { $l = Util::getL10N('activity'); $description = (string) $l->t('Your feed URL is invalid'); $activities = [['activity_id' => -1, 'timestamp' => time(), 'subject' => true, 'subjectformatted' => ['full' => $description]]]; } $response = new TemplateResponse('activity', 'rss', ['rssLang' => $l->getLanguageCode(), 'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'), 'rssPubDate' => date('r'), 'description' => $description, 'activities' => $activities], ''); if ($this->request->getHeader('accept') !== null && stristr($this->request->getHeader('accept'), 'application/rss+xml')) { $response->addHeader('Content-Type', 'application/rss+xml'); } else { $response->addHeader('Content-Type', 'text/xml; charset=UTF-8'); } return $response; }
public static function sendMail($path) { if (!\OCP\User::isLoggedIn()) { return; } $config = \OC::$server->getConfig(); $user = \OC::$server->getUserSession()->getUser(); $email = $user->getEMailAddress(); $displayName = $user->getDisplayName(); if (strval($displayName) === '') { $displayName = $user->getUID(); } \OCP\Util::writeLog('files_antivirus', 'Email: ' . $email, \OCP\Util::DEBUG); if (!empty($email)) { try { $tmpl = new \OCP\Template('files_antivirus', 'notification'); $tmpl->assign('file', $path); $tmpl->assign('host', \OC::$server->getRequest()->getServerHost()); $tmpl->assign('user', $displayName); $msg = $tmpl->fetchPage(); $from = \OCP\Util::getDefaultEmailAddress('security-noreply'); $mailer = \OC::$server->getMailer(); $message = $mailer->createMessage(); $message->setSubject(\OCP\Util::getL10N('files_antivirus')->t('Malware detected')); $message->setFrom([$from => 'ownCloud Notifier']); $message->setTo([$email => $displayName]); $message->setPlainBody($msg); $message->setHtmlBody($msg); $mailer->send($message); } catch (\Exception $e) { \OC::$server->getLogger()->error(__METHOD__ . ', exception: ' . $e->getMessage(), ['app' => 'files_antivirus']); } } }
/** * @dataProvider getTemplateData */ public function testHooksDeleteUser($constructorActive, $forceActive) { $l = \OCP\Util::getL10N('activity'); $navigation = new Navigation($l, \OC::$server->getActivityManager(), \OC::$server->getURLGenerator(), $constructorActive); $output = $navigation->getTemplate($forceActive)->fetchPage(); // Get only the template part with the navigation links $navigationLinks = substr($output, strpos($output, '<li>') + 4); $navigationLinks = substr($navigationLinks, 0, strrpos($navigationLinks, '</li>')); // Remove tabs and new lines $navigationLinks = str_replace(array("\t", "\n"), '', $navigationLinks); // Turn the list of links into an array $navigationEntries = explode('</li><li>', $navigationLinks); $links = $navigation->getLinkList(); // Check whether all top links are available foreach ($links['top'] as $link) { $found = false; foreach ($navigationEntries as $navigationEntry) { if (strpos($navigationEntry, 'data-navigation="' . $link['id'] . '"') !== false) { $found = true; $this->assertContains('href="' . $link['url'] . '">' . $link['name'] . '</a>', $navigationEntry); if ($forceActive == $link['id']) { $this->assertContains('class="active"', $navigationEntry); } else { if ($forceActive == null && $constructorActive == $link['id']) { $this->assertContains('class="active"', $navigationEntry); } } } } $this->assertTrue($found, 'Could not find navigation entry "' . $link['name'] . '"'); } // Check size of app links $this->assertSame(1, sizeof($links['apps'])); $this->assertNotContains('data-navigation="files"', $navigationLinks, 'Files app should not be included when there are no other apps.'); }
/** * @dataProvider getData */ public function testGet($user, $start, $count, $expected) { $_GET['start'] = $start; $_GET['count'] = $count; \OC_User::setUserId($user); $sessionUser = \OC::$server->getUserSession()->getUser(); $this->assertInstanceOf('OCP\\IUser', $sessionUser); $this->assertEquals($user, $sessionUser->getUID()); $activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $activityManager->registerExtension(function () { return new Extension(\OCP\Util::getL10N('activity', 'en'), $this->getMock('\\OCP\\IURLGenerator')); }); $this->overwriteService('ActivityManager', $activityManager); $result = \OCA\Activity\Api::get(array('_route' => 'get_cloud_activity')); $this->restoreService('ActivityManager'); $this->assertEquals(100, $result->getStatusCode()); $data = $result->getData(); $this->assertEquals(sizeof($expected), sizeof($data)); while (!empty($expected)) { $assertExpected = array_shift($expected); $assertData = array_shift($data); foreach ($assertExpected as $key => $value) { $this->assertArrayHasKey($key, $assertData); if ($value !== null) { $this->assertEquals($value, $assertData[$key]); } } } }
/** * @dataProvider getTypeIconData */ public function testGetTypeIcon($type, $expected) { $manager = $this->getMock('\\OCP\\Activity\\IManager'); $manager->expects($this->any())->method('getTypeIcon')->willReturn(''); $dataHelper = new DataHelper($manager, new ParameterHelper($manager, new View(''), $this->getMockBuilder('OCP\\IConfig')->disableOriginalConstructor()->getMock(), Util::getL10N('activity')), Util::getL10N('activity')); $this->assertEquals($expected, $dataHelper->getTypeIcon($type)); }
/** * @dataProvider translationData */ public function testTranslation($text, $params, $stripPath, $highlightParams, $expected) { $config = $this->getMockBuilder('OCP\\IConfig')->disableOriginalConstructor()->getMock(); $config->expects($this->any())->method('getSystemValue')->with('enable_avatars', true)->willReturn(true); $dataHelper = new \OCA\Activity\DataHelper($this->getMock('\\OCP\\Activity\\IManager'), new \OCA\Activity\ParameterHelper(new \OC\Files\View(''), $config, \OCP\Util::getL10N('activity')), \OCP\Util::getL10N('activity')); $this->assertEquals($expected, (string) $dataHelper->translation('files', $text, $params, $stripPath, $highlightParams)); }
/** * @brief Translate an event string with the translations from the app where it was send from * @param string $app The app where this event comes from * @param string $text The text including placeholders * @param array $params The parameter for the placeholder * @return string translated */ public static function translation($app, $text, $params) { $l = \OCP\Util::getL10N($app); $result = $l->t($text, $params); unset($l); return $result; }
public function setUp() { parent::setUp(); $this->originalWEBROOT =\OC::$WEBROOT; \OC::$WEBROOT = ''; $l = \OCP\Util::getL10N('activity'); $this->view = new \OC\Files\View(''); $this->parameterHelper = new \OCA\Activity\ParameterHelper($this->view, $l); }
public function testSetL10n() { /** @var GroupHelper $helper */ /** @var \PHPUnit_Framework_MockObject_MockObject $dataHelperMock */ list($helper, $dataHelperMock) = $this->setUpHelpers(); $l = \OCP\Util::getL10N('activity', 'de'); $dataHelperMock->expects($this->once())->method('setL10n')->with($l); $helper->setL10n($l); }
protected function setUp() { parent::setUp(); $this->activityLanguage = $activityLanguage = \OCP\Util::getL10N('activity', 'en'); $activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $activityManager->registerExtension(function () use($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\\OCP\\IURLGenerator')); }); $this->data = new Data($activityManager); }
protected function setUp() { parent::setUp(); $this->activityLanguage = $activityLanguage = \OCP\Util::getL10N('activity', 'en'); $this->activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $this->session = $this->getMockBuilder('OCP\\IUserSession')->disableOriginalConstructor()->getMock(); $this->activityManager->registerExtension(function () use($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\\OCP\\IURLGenerator')); }); $this->data = new Data($this->activityManager, \OC::$server->getDatabaseConnection(), $this->session); }
/** * Registers the preLogin hook to catch wether or not the user accepted the * disclaimer */ public function register() { $callback = function ($user, $password) { $appId = Application::APP_ID; if (!isset($_POST[$appId . 'Checkbox'])) { $message = \OCP\Util::getL10N($appId)->t('Please read and ' . 'agree the disclaimer before proceeding'); throw new LoginException($message); } }; $this->userManager->listen('\\OC\\User', 'preLogin', $callback); }
protected function setUp() { parent::setUp(); $this->originalWEBROOT = \OC::$WEBROOT; \OC::$WEBROOT = ''; $l = \OCP\Util::getL10N('activity'); $this->view = new \OC\Files\View(''); $manager = $this->getMock('\\OCP\\Activity\\IManager'); $manager->expects($this->any())->method('getSpecialParameterList')->will($this->returnValue(false)); $this->parameterHelper = new \OCA\Activity\ParameterHelper($manager, $this->view, $l); }
/** * @dataProvider getTemplateData */ public function testHooksDeleteUser($constructorActive, $forceActive, $matchTags, $notMatchTags) { $l = \OCP\Util::getL10N('activity'); $navigation = new Navigation($l, $constructorActive); $output = $navigation->getTemplate($forceActive)->fetchPage(); foreach ($matchTags as $matcher) { $this->assertTag($matcher, $output); } foreach ($notMatchTags as $matcher) { $this->assertNotTag($matcher, $output); } }
/** * Get a list with enabled notification types for a user * * @param string $user Name of the user * @param string $method Should be one of 'stream' or 'email' * @return array */ public function getNotificationTypes($user, $method) { $l = Util::getL10N('activity'); $types = $this->data->getNotificationTypes($l); $notificationTypes = array(); foreach ($types as $type => $desc) { if ($this->getUserSetting($user, $method, $type)) { $notificationTypes[] = $type; } } return $notificationTypes; }
protected function setUp() { parent::setUp(); $this->data = $this->getMockBuilder('OCA\\Activity\\Data')->disableOriginalConstructor()->getMock(); $this->userSettings = $this->getMockBuilder('OCA\\Activity\\UserSettings')->disableOriginalConstructor()->getMock(); $this->config = $this->getMock('OCP\\IConfig'); $this->request = $this->getMock('OCP\\IRequest'); $this->urlGenerator = $this->getMock('OCP\\IURLGenerator'); $this->random = $this->getMock('OCP\\Security\\ISecureRandom'); $this->l10n = \OCP\Util::getL10N('activity', 'en'); $this->controller = new Settings('activity', $this->request, $this->config, $this->random, $this->urlGenerator, $this->data, $this->userSettings, $this->l10n, 'test'); }
/** * @param AbstractBackend $backend The storage backend * @param array $addressBookInfo * @throws \Exception */ public function __construct(Backend\AbstractBackend $backend, array $addressBookInfo) { self::$l10n = \OCP\Util::getL10N('contacts'); $this->backend = $backend; $this->addressBookInfo = $addressBookInfo; if (is_null($this->getId())) { $id = $this->backend->createAddressBook($addressBookInfo); if ($id === false) { throw new \Exception('Error creating address book.', Http::STATUS_INTERNAL_SERVER_ERROR); } $this->addressBookInfo = $this->backend->getAddressBook($id); } //\OCP\Util::writeLog('contacts', __METHOD__.' backend: ' . print_r($this->backend, true), \OCP\Util::DEBUG); }
/** * @brief Translate an event string with the translations from the app where it was send from * @param string $app The app where this event comes from * @param string $text The text including placeholders * @param array $params The parameter for the placeholder * @param bool $stripPath Shall we strip the path from file names? * @param bool $highlightParams Shall we highlight the parameters in the string? * They will be highlighted with `<strong>`, all data will be passed through * \OCP\Util::sanitizeHTML() before, so no XSS is possible. * @return string translated */ public function translation($app, $text, $params, $stripPath = false, $highlightParams = false) { if (!$text) { return ''; } $preparedParams = $this->parameterHelper->prepareParameters($params, $this->parameterHelper->getSpecialParameterList($app, $text), $stripPath, $highlightParams); // Allow apps to correctly translate their activities $translation = $this->activityManager->translate($app, $text, $preparedParams, $stripPath, $highlightParams, $this->l->getLanguageCode()); if ($translation !== false) { return $translation; } $l = Util::getL10N($app, $this->l->getLanguageCode()); return $l->t($text, $preparedParams); }
public static function get($param) { $l = \OCP\Util::getL10N('activity'); $data = new \OCA\Activity\Data(\OC::$server->getActivityManager()); $groupHelper = new \OCA\Activity\GroupHelper(\OC::$server->getActivityManager(), new \OCA\Activity\DataHelper(\OC::$server->getActivityManager(), new \OCA\Activity\ParameterHelper(new \OC\Files\View(''), \OC::$server->getConfig(), $l), $l), false); $start = isset($_GET['start']) ? $_GET['start'] : 0; $count = isset($_GET['count']) ? $_GET['count'] : self::DEFAULT_LIMIT; $activities = $data->read($groupHelper, $start, $count, 'all'); $data = array(); foreach ($activities as $entry) { $data[] = array('id' => $entry['activity_id'], 'subject' => (string) $entry['subjectformatted']['full'], 'message' => (string) $entry['messageformatted']['full'], 'file' => $entry['file'], 'link' => $entry['link'], 'date' => date('c', $entry['timestamp'])); } return new \OC_OCS_Result($data); }
public static function init() { self::$l10n = \OCP\Util::getL10N(self::APP_ID); \OC::$CLASSPATH['OCA\\Updater\\Backup'] = self::APP_ID . '/lib/backup.php'; \OC::$CLASSPATH['OCA\\Updater\\Downloader'] = self::APP_ID . '/lib/downloader.php'; \OC::$CLASSPATH['OCA\\Updater\\Updater'] = self::APP_ID . '/lib/updater.php'; \OC::$CLASSPATH['OCA\\Updater\\Helper'] = self::APP_ID . '/lib/helper.php'; \OC::$CLASSPATH['OCA\\Updater\\Location'] = self::APP_ID . '/lib/location.php'; \OC::$CLASSPATH['OCA\\Updater\\Location_3rdparty'] = self::APP_ID . '/lib/location/3rdparty.php'; \OC::$CLASSPATH['OCA\\Updater\\Location_Apps'] = self::APP_ID . '/lib/location/apps.php'; \OC::$CLASSPATH['OCA\\Updater\\Location_Core'] = self::APP_ID . '/lib/location/core.php'; //Allow config page \OCP\App::registerAdmin(self::APP_ID, 'admin'); }
/** * @dataProvider getTemplateData */ public function testGetTemplate($constructorActive, $forceActive = null, $rssToken = '') { $activityLanguage = \OCP\Util::getL10N('activity', 'en'); $activityManager = new ActivityManager($this->getMock('OCP\\IRequest'), $this->getMock('OCP\\IUserSession'), $this->getMock('OCP\\IConfig')); $activityManager->registerExtension(function () use($activityLanguage) { return new Extension($activityLanguage, $this->getMock('\\OCP\\IURLGenerator')); }); $userSettings = $this->getMockBuilder('OCA\\Activity\\UserSettings')->disableOriginalConstructor()->getMock(); $userSettings->expects($this->exactly(2))->method('getUserSetting')->with('test', 'setting', 'self')->willReturn(true); $navigation = new Navigation($activityLanguage, $activityManager, \OC::$server->getURLGenerator(), $userSettings, 'test', $rssToken, $constructorActive); $output = $navigation->getTemplate($forceActive)->fetchPage(); // Get only the template part with the navigation links $navigationLinks = substr($output, strpos($output, '<ul>') + 4); $navigationLinks = substr($navigationLinks, 0, strrpos($navigationLinks, '</li>')); // Remove tabs and new lines $navigationLinks = str_replace(array("\t", "\n"), '', $navigationLinks); // Turn the list of links into an array $navigationEntries = explode('</li>', $navigationLinks); $links = $navigation->getLinkList(); // Check whether all top links are available foreach ($links['top'] as $link) { $found = false; foreach ($navigationEntries as $navigationEntry) { if (strpos($navigationEntry, 'data-navigation="' . $link['id'] . '"') !== false) { $found = true; $this->assertContains('href="' . $link['url'] . '">' . $link['name'] . '</a>', $navigationEntry); if ($forceActive == $link['id'] || $forceActive == null && $constructorActive == $link['id']) { $this->assertStringStartsWith('<li class="active">', $navigationEntry); } else { $this->assertStringStartsWith('<li>', $navigationEntry); } } } $this->assertTrue($found, 'Could not find navigation entry "' . $link['name'] . '"'); } // Check size of app links $this->assertSame(1, sizeof($links['apps'])); $this->assertNotContains('data-navigation="files"', $navigationLinks, 'Files app should not be included when there are no other apps.'); if ($rssToken) { $rssInputField = strpos($output, 'input id="rssurl"'); $this->assertGreaterThan(0, $rssInputField); $endOfInputField = strpos($output, ' />', $rssInputField); $this->assertNotSame(false, strpos(substr($output, $rssInputField, $endOfInputField - $rssInputField), $rssToken)); } }
public static function sendMail($path) { if (!\OCP\User::isLoggedIn()) { return; } $email = \OCP\Config::getUserValue(\OCP\User::getUser(), 'settings', 'email', ''); \OCP\Util::writeLog('files_antivirus', 'Email: ' . $email, \OCP\Util::DEBUG); if (!empty($email)) { $defaults = new \OCP\Defaults(); $tmpl = new \OCP\Template('files_antivirus', 'notification'); $tmpl->assign('file', $path); $tmpl->assign('host', \OCP\Util::getServerHost()); $tmpl->assign('user', \OCP\User::getDisplayName()); $msg = $tmpl->fetchPage(); $from = \OCP\Util::getDefaultEmailAddress('security-noreply'); \OCP\Util::sendMail($email, \OCP\User::getUser(), \OCP\Util::getL10N('files_antivirus')->t('Malware detected'), $msg, $from, $defaults->getName(), true); } }
/** * @dataProvider groupHelperData */ public function testGroupHelper($allowGrouping, $activities, $expected) { $activityManager = $this->getMock('\\OCP\\Activity\\IManager'); $activityManager->expects($this->any())->method('getGroupParameter')->with($this->anything())->will($this->returnValue(false)); $activityLanguage = \OCP\Util::getL10N('activity'); $helper = new GroupHelper($activityManager, new DataHelper($activityManager, new ParameterHelper($activityManager, new \OC\Files\View(''), $this->getMockBuilder('OCP\\IConfig')->disableOriginalConstructor()->getMock(), $activityLanguage), $activityLanguage), $allowGrouping); foreach ($activities as $activity) { $helper->addActivity($activity); } $result = $helper->getActivities(); $clearedResult = array(); foreach ($result as $activity) { unset($activity['subjectformatted']); unset($activity['messageformatted']); unset($activity['timestamp']); $clearedResult[] = $activity; } $this->assertEquals($expected, $clearedResult); }
public static function av_scan($path) { $path = $path[\OC\Files\Filesystem::signal_param_path]; if ($path != '') { if (isset($_POST['dirToken'])) { //Public upload case $filesView = \OC\Files\Filesystem::getView(); } else { $filesView = \OCP\Files::getStorage("files"); } if (!is_object($filesView)) { \OCP\Util::writeLog('files_antivirus', 'Can\'t init filesystem view', \OCP\Util::WARN); return; } // check if path is a directory if ($filesView->is_dir($path)) { return; } // we should have a file to work with, and the file shouldn't // be empty $fileExists = $filesView->file_exists($path); if ($fileExists && $filesView->filesize($path) > 0) { $fileStatus = self::scanFile($filesView, $path); $result = $fileStatus->getNumericStatus(); switch ($result) { case Status::SCANRESULT_UNCHECKED: //TODO: Show warning to the user: The file can not be checked break; case Status::SCANRESULT_INFECTED: //remove file $filesView->unlink($path); Notification::sendMail($path); $message = \OCP\Util::getL10N('files_antivirus')->t("Virus detected! Can't upload the file %s", array(basename($path))); \OCP\JSON::error(array("data" => array("message" => $message))); exit; break; case Status::SCANRESULT_CLEAN: //do nothing break; } } } }
/** * @brief Translate an event string with the translations from the app where it was send from * @param string $app The app where this event comes from * @param string $text The text including placeholders * @param array $params The parameter for the placeholder * @return string translated */ public static function translation($app, $text, $params) { // Replace the user id with the display name of the users if ($app === 'files') { switch ($text) { case '%s created by %s': case '%s changed by %s': case '%s deleted by %s': case 'You shared %s with %s': $params[1] = \OCP\User::getDisplayName($params[1]); break; case '%s shared %s with you': $params[0] = \OCP\User::getDisplayName($params[0]); break; } } $l = \OCP\Util::getL10N($app); $result = $l->t($text, $params); unset($l); return $result; }
/** * @dataProvider translationData */ public function testTranslation($text, $params, $stripPath, $highlightParams, $expected) { $dataHelper = new \OCA\Activity\DataHelper($this->getMock('\\OCP\\Activity\\IManager'), new \OCA\Activity\ParameterHelper(new \OC\Files\View(''), \OCP\Util::getL10N('activity')), \OCP\Util::getL10N('activity')); $this->assertEquals($expected, (string) $dataHelper->translation('files', $text, $params, $stripPath, $highlightParams)); }
/** * @dataProvider showData * * @param string $acceptHeader * @param string $expectedHeader */ public function testShowNoToken($acceptHeader, $expectedHeader) { $this->manager->expects($this->any())->method('getCurrentUserId')->willThrowException(new \UnexpectedValueException()); if ($acceptHeader !== null) { $this->request->expects($this->any())->method('getHeader')->willReturn($acceptHeader); } $templateResponse = $this->controller->show(); $this->assertTrue($templateResponse instanceof TemplateResponse, 'Asserting type of return is \\OCP\\AppFramework\\Http\\TemplateResponse'); $headers = $templateResponse->getHeaders(); $this->assertArrayHasKey('Content-Type', $headers); $this->assertEquals($expectedHeader, $headers['Content-Type']); $renderedResponse = $templateResponse->render(); $this->assertNotEmpty($renderedResponse); $l = Util::getL10N('activity'); $description = (string) $l->t('Your feed URL is invalid'); $this->assertContains($description, $renderedResponse); }
if (sizeof($users) !== 1) { // User not found header('HTTP/1.0 404 Not Found'); exit; } // Token found login as that user \OC_User::setUserId(array_shift($users)); $forceUserLogout = true; } // check if the user has the right permissions. \OCP\User::checkLoggedIn(); // rss is of content type text/xml if (isset($_SERVER['HTTP_ACCEPT']) && stristr($_SERVER['HTTP_ACCEPT'], 'application/rss+xml')) { header('Content-Type: application/rss+xml'); } else { header('Content-Type: text/xml; charset=UTF-8'); } // generate and show the rss feed $l = \OCP\Util::getL10N('activity'); $data = new \OCA\Activity\Data(\OC::$server->getActivityManager()); $groupHelper = new \OCA\Activity\GroupHelper(\OC::$server->getActivityManager(), new \OCA\Activity\DataHelper(\OC::$server->getActivityManager(), new \OCA\Activity\ParameterHelper(new \OC\Files\View(''), $l), $l), false); $tmpl = new \OCP\Template('activity', 'rss'); $tmpl->assign('rssLang', \OC_Preferences::getValue(\OCP\User::getUser(), 'core', 'lang')); $tmpl->assign('rssLink', \OCP\Util::linkToAbsolute('activity', 'rss.php')); $tmpl->assign('rssPubDate', date('r')); $tmpl->assign('user', \OCP\User::getUser()); $tmpl->assign('activities', $data->read($groupHelper, 0, 30, 'all')); $tmpl->printPage(); if ($forceUserLogout) { \OC_User::logout(); }
/** * @brief Translate an event string with the translations from the app where it was send from * @param string $app The app where this event comes from * @param string $text The text including placeholders * @param array $params The parameter for the placeholder * @param bool $stripPath Shall we strip the path from file names? * @param bool $highlightParams Shall we highlight the parameters in the string? * They will be highlighted with `<strong>`, all data will be passed through * \OCP\Util::sanitizeHTML() before, so no XSS is possible. * @return string translated */ public function translation($app, $text, $params, $stripPath = false, $highlightParams = false) { if (!$text) { return ''; } $preparedParams = $this->parameterHelper->prepareParameters($params, $this->parameterHelper->getSpecialParameterList($app, $text), $stripPath, $highlightParams); if ($app === 'files') { switch ($text) { case 'created_self': return $this->l->t('You created %1$s', $preparedParams); case 'created_by': return $this->l->t('%2$s created %1$s', $preparedParams); case 'created_public': return $this->l->t('%1$s was created in a public folder', $preparedParams); case 'changed_self': return $this->l->t('You changed %1$s', $preparedParams); case 'changed_by': return $this->l->t('%2$s changed %1$s', $preparedParams); case 'deleted_self': return $this->l->t('You deleted %1$s', $preparedParams); case 'deleted_by': return $this->l->t('%2$s deleted %1$s', $preparedParams); case 'restored_self': return $this->l->t('You restored %1$s', $preparedParams); case 'restored_by': return $this->l->t('%2$s restored %1$s', $preparedParams); case 'shared_user_self': return $this->l->t('You shared %1$s with %2$s', $preparedParams); case 'shared_group_self': return $this->l->t('You shared %1$s with group %2$s', $preparedParams); case 'shared_with_by': return $this->l->t('%2$s shared %1$s with you', $preparedParams); case 'shared_link_self': return $this->l->t('You shared %1$s via link', $preparedParams); } } // Allow other apps to correctly translate their activities $translation = $this->activityManager->translate($app, $text, $preparedParams, $stripPath, $highlightParams, $this->l->getLanguageCode()); if ($translation !== false) { return $translation; } $l = Util::getL10N($app); return $l->t($text, $preparedParams); }
public static function init() { self::$l10n = \OCP\Util::getL10N(self::APP_ID); //Allow config page \OCP\App::registerAdmin(self::APP_ID, 'admin'); }