function action_create_from_url($input) { Services_Exception_Disabled::check('page_content_fetch'); Services_Exception_Denied::checkGlobal('edit_article'); $id = null; $title = null; $url = $input->url->url(); if ($_SERVER['REQUEST_METHOD'] == 'POST' && $url) { $lib = TikiLib::lib('pagecontent'); $data = $lib->grabContent($url); if (!$data) { throw new Services_Exception_FieldError($input->errorfield->text() ?: 'url', tr('Content could not be loaded.')); } $data['content'] = trim($data['content']) == '' ? $data['content'] : '~np~' . $data['content'] . '~/np~'; $data['description'] = ''; $data['author'] = ''; $topicId = $input->topicId->int(); $articleType = $input->type->text(); $title = $data['title']; $hash = md5($data['title'] . $data['description'] . $data['content']); $id = TikiDb::get()->table('tiki_articles')->fetchOne('articleId', array('linkto' => $url)) ?: 0; if (!$id) { $tikilib = TikiLib::lib('tiki'); $publication = $tikilib->now; $expire = $publication + 3600 * 24 * 365; $rating = 10; $artlib = TikiLib::lib('art'); $id = $artlib->replace_article($title, $data['author'], $topicId, 'n', '', 0, '', '', $data['description'], $data['content'], $publication, $expire, $GLOBALS['user'], $id, 0, 0, $articleType, '', '', $url, '', '', $rating, 'n', '', '', '', '', 'y', true); } } $db = TikiDb::get(); $topics = $db->table('tiki_topics')->fetchMap('topicId', 'name', array(), -1, -1, 'name_asc'); $types = $db->table('tiki_article_types')->fetchColumn('type', array()); return ['title' => tr('Create article from URL'), 'url' => $url, 'id' => $id, 'articleTitle' => $title, 'topics' => $topics, 'types' => $types]; }
function action_regenerate_slugs($input) { global $prefs; Services_Exception_Denied::checkGlobal('admin'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $pages = TikiDb::get()->table('tiki_pages'); $initial = TikiLib::lib('slugmanager'); $tracker = new Tiki\Wiki\SlugManager\InMemoryTracker(); $manager = clone $initial; $manager->setValidationCallback($tracker); $list = $pages->fetchColumn('pageName', []); $pages->updateMultiple(['pageSlug' => null], []); foreach ($list as $page) { $slug = $manager->generate($prefs['wiki_url_scheme'], $page, $prefs['url_only_ascii'] === 'y'); $count = 1; while ($pages->fetchCount(['pageSlug' => $slug]) && $count < 100) { $count++; $slug = $manager->generate($prefs['wiki_url_scheme'], $page . ' ' . $count, $prefs['url_only_ascii'] === 'y'); } $tracker->add($page); $pages->update(['pageSlug' => $slug], ['pageName' => $page]); } TikiLib::lib('access')->redirect('tiki-admin.php?page=wiki'); } return array('title' => tr('Regenerate Wiki URLs')); }
function action_process_queue($input) { Services_Exception_Denied::checkGlobal('admin'); $batch = $input->batch->int() ?: 50; $unifiedsearchlib = TikiLib::lib('unifiedsearch'); $stat = null; if ($_SERVER['REQUEST_METHOD'] == 'POST') { @ini_set('max_execution_time', 0); @ini_set('memory_limit', -1); $stat = $unifiedsearchlib->processUpdateQueue($batch); } return ['title' => tr('Process Update Queue'), 'stat' => $stat, 'queue_count' => $unifiedsearchlib->getQueueCount(), 'batch' => $batch]; }
function setUp() { Services_Exception_Disabled::check('feature_search'); Services_Exception_Denied::checkGlobal('tiki_p_admin'); }
function action_email_wikipage($input) { Services_Exception_Disabled::check('feature_wiki'); Services_Exception_Denied::checkGlobal('admin_users'); $check = Services_Exception_BadRequest::checkAccess(); //first pass - show confirm popup if (!empty($check['ticket'])) { $users = $input->asArray('checked'); if (count($users) > 0) { //provide redirect if js is not enabled $referer = Services_Utilities_Controller::noJsPath(); return ['title' => tra('Send wiki page content by email to selected users'), 'confirmAction' => $input->action->word(), 'confirmController' => 'user', 'customMsg' => tra('For these selected users:'), 'items' => $users, 'extra' => ['referer' => $referer], 'ticket' => $check['ticket'], 'modal' => '1', 'confirm' => 'y']; } else { throw new Services_Exception(tra('No users were selected. Please select one or more users.'), 409); } //after confirm submit - perform action and return success feedback } elseif ($check === true && $_SERVER['REQUEST_METHOD'] === 'POST') { $wikiTpl = $input['wikiTpl']; $tikilib = TikiLib::lib('tiki'); $pageinfo = $tikilib->get_page_info($wikiTpl); if (!$pageinfo) { throw new Services_Exception_NotFound(tra('Page not found')); } if (empty($pageinfo['description'])) { throw new Services_Exception(tra('The page does not have a description, which is mandatory to perform this action.')); } $bcc = $input['bcc']; include_once 'lib/webmail/tikimaillib.php'; $mail = new TikiMail(); if (!empty($bcc)) { if (!validate_email($bcc)) { throw new Services_Exception(tra('Invalid bcc email address.')); } $mail->setBcc($bcc); $bccmsg = tr('and blind copied to %0', $bcc); } $foo = parse_url($_SERVER['REQUEST_URI']); $machine = $tikilib->httpPrefix(true) . dirname($foo['path']); $machine = preg_replace('!/$!', '', $machine); // just in case global $smarty, $user; $smarty->assign_by_ref('mail_machine', $machine); $users = json_decode($input['items'], true); $logslib = TikiLib::lib('logs'); foreach ($users as $mail_user) { $smarty->assign_by_ref('user', $mail_user); $mail->setUser($mail_user); $mail->setSubject($pageinfo['description']); $text = $smarty->fetch('wiki:' . $wikiTpl); if (empty($text)) { throw new Services_Exception(tra('The template page has no text or it cannot be extracted.')); } $mail->setHtml($text); if (!$mail->send($this->lib->get_user_email($mail_user))) { $errormsg = tra('Unable to send mail'); if (Perms::get()->admin) { $mailerrors = print_r($mail->errors, true); $errormsg .= $mailerrors; } throw new Services_Exception($errormsg); } else { if (!empty($bcc)) { $logmsg = sprintf(tra('Mail sent to user %s'), $mail_user); } $logmsg = !empty($bccmsg) ? $logmsg . ' ' . $bccmsg : $logmsg; if (!empty($msg)) { $logslib->add_log('adminusers', $logmsg, $user); } } $smarty->assign_by_ref('user', $user); } //return to page //if javascript is not enabled $extra = json_decode($input['extra'], true); if (!empty($extra['referer'])) { $this->access->redirect($extra['referer'], tra('Page sent'), null, 'feedback'); } $msg = count($users) === 1 ? tr('The page %0 has been emailed to the following user:'******'The page %0 has been emailed to the following users:', $wikiTpl); $toMsg = !empty($bcc) ? tr('And blind copied to %0.', $bcc) : ''; return ['extra' => 'post', 'feedback' => ['ajaxtype' => 'feedback', 'ajaxheading' => tra('Success'), 'ajaxitems' => $users, 'ajaxmsg' => $msg, 'ajaxtoMsg' => $toMsg, 'modal' => '1']]; } }
function setUp() { Services_Exception_Denied::checkGlobal('admin'); }
function action_invite_tempuser($input) { Services_Exception_Denied::checkGlobal('admin_users'); $emails = $input->tempuser_emails->string(); $groups = $input->tempuser_groups->string(); $expiry = $input->tempuser_expiry->int(); $prefix = $input->tempuser_prefix->string(); $path = $input->tempuser_path->string(); if (empty($prefix)) { $prefix = '_token'; } if (empty($path)) { $path = 'tiki-index.php'; } $groups = explode(',', $groups); $emails = explode(',', $emails); $groups = array_map('trim', $groups); $emails = array_map('trim', $emails); if ($expiry > 0) { $expiry = $expiry * 3600; } else { if ($expiry != -1) { throw new Services_Exception(tra('Please specify validity period')); } } foreach ($groups as $grp) { if (!TikiLib::lib('user')->group_exists($grp)) { throw new Services_Exception(tra('The group %0 does not exist', $grp)); } } TikiLib::lib('user')->invite_tempuser($emails, $groups, $expiry, $prefix, $path); return array('modal' => '1', 'FORWARD' => array('controller' => 'utilities', 'action' => 'modal_alert', 'ajaxtype' => 'feedback', 'ajaxheading' => tra('Success'), 'ajaxmsg' => 'Your invite has been sent.', 'ajaxdismissible' => 'n')); }
function action_export_search_csv($input) { $lib = TikiLib::lib('tabular'); $trackerId = $input->trackerId->int(); $tabularId = $input->tabularId->int(); $conditions = array_filter(['trackerId' => $trackerId, 'tabularId' => $tabularId]); $formats = $lib->getList($conditions); if ($tabularId) { $info = $lib->getInfo($tabularId); $schema = $this->getSchema($info); $schema->validate(); $trackerId = $info['trackerId']; Services_Exception_Denied::checkObject('tiki_p_tabular_export', 'tabular', $tabularId); $search = TikiLib::lib('unifiedsearch'); $query = $search->buildQuery($input->filter->none() ?: []); // Force filters $query->filterType('trackeritem'); $query->filterContent($trackerId, 'tracker_id'); $source = new \Tracker\Tabular\Source\QuerySource($schema, $query); $writer = new \Tracker\Tabular\Writer\CsvWriter('php://output'); $name = TikiLib::lib('tiki')->remove_non_word_characters_and_accents($info['name']); $writer->sendHeaders($name . '_export_search.csv'); TikiLib::lib('tiki')->allocate_extra('tracker_export_items', function () use($writer, $source) { $writer->write($source); }); exit; } elseif (count($formats) === 0) { throw new Services_Exception(tr('No formats available.')); } else { if ($trackerId) { Services_Exception_Denied::checkObject('tiki_p_view_trackers', 'tracker', $trackerId); } else { Services_Exception_Denied::checkGlobal('tiki_p_tabular_admin'); } return ['title' => tr('Select Format'), 'formats' => $formats, 'filters' => $input->filter->none()]; } }