Example #1
0
 public function configuration_action()
 {
     $template_factory = new Flexi_TemplateFactory(__DIR__ . '/templates');
     $template = $template_factory->open('edit');
     $template->links = Navigation::getItem('/start');
     $template->config = WidgetHelper::getWidgetUserConfig($GLOBALS['user']->id, 'QUICK_SELECTION');
     $template->plugin = $this;
     header('X-Title: ' . _('Schnellzugriff konfigurieren'));
     echo studip_utf8encode($template->render());
 }
Example #2
0
 /**
  * this action is the main action of the schedule-controller, setting the environment for the timetable,
  * accepting a comma-separated list of days.
  *
  * @param  string  a list of an arbitrary mix of the numbers 0-6, separated with a comma (e.g. 1,2,3,4,5 (for Monday to Friday, the default))
  */
 function index_action($days = false)
 {
     if ($GLOBALS['perm']->have_perm('admin')) {
         $inst_mode = true;
     }
     $my_schedule_settings = $GLOBALS['user']->cfg->SCHEDULE_SETTINGS;
     // set the days to be displayed
     if ($days === false) {
         if (Request::getArray('days')) {
             $this->days = array_keys(Request::getArray('days'));
         } else {
             $this->days = array(0, 1, 2, 3, 4, 5, 6);
         }
     } else {
         $this->days = explode(',', $days);
     }
     // try to find the correct institute-id
     $institute_id = Request::option('institute_id', $SessSemName[1] ? $SessSemName[1] : Request::option('cid', false));
     if (!$institute_id) {
         $institute_id = $GLOBALS['user']->cfg->MY_INSTITUTES_DEFAULT;
     }
     if (!$institute_id || in_array(get_object_type($institute_id), words('inst fak')) === false) {
         throw new Exception(sprintf(_('Kann Einrichtungskalendar nicht anzeigen!' . 'Es wurde eine ungültige Instituts-Id übergeben (%s)!', $institute_id)));
     }
     // load semester-data and current semester
     $semdata = new SemesterData();
     $this->semesters = $semdata->getAllSemesterData();
     if (Request::option('semester_id')) {
         $this->current_semester = $semdata->getSemesterData(Request::option('semester_id'));
     } else {
         $this->current_semester = $semdata->getCurrentSemesterData();
     }
     $this->entries = (array) CalendarInstscheduleModel::getInstituteEntries($GLOBALS['user']->id, $this->current_semester, 8, 20, $institute_id, $this->days);
     Navigation::activateItem('/course/main/schedule');
     PageLayout::setHelpKeyword('Basis.TerminkalenderStundenplan');
     PageLayout::setTitle($GLOBALS['SessSemName']['header_line'] . ' - ' . _('Veranstaltungs-Stundenplan'));
     $zoom = Request::int('zoom', 0);
     $this->controller = $this;
     $this->calendar_view = new CalendarWeekView($this->entries, 'instschedule');
     $this->calendar_view->setHeight(40 + 20 * $zoom);
     $this->calendar_view->setRange($my_schedule_settings['glb_start_time'], $my_schedule_settings['glb_end_time']);
     $this->calendar_view->groupEntries();
     // if enabled, group entries with same start- and end-date
     URLHelper::addLinkParam('zoom', $zoom);
     URLHelper::addLinkParam('semester_id', $this->current_semester['semester_id']);
     $style_parameters = array('whole_height' => $this->calendar_view->getOverallHeight(), 'entry_height' => $this->calendar_view->getHeight());
     $factory = new Flexi_TemplateFactory($this->dispatcher->trails_root . '/views');
     PageLayout::addStyle($factory->render('calendar/stylesheet', $style_parameters));
     if (Request::option('printview')) {
         PageLayout::addStylesheet('print.css');
     } else {
         PageLayout::addStylesheet('print.css', array('media' => 'print'));
     }
 }
 public function getHomepageTemplate($user_id)
 {
     $this->addStylesheet('assets/pluginmarket.less');
     $templatefactory = new Flexi_TemplateFactory(__DIR__ . "/views");
     $template = $templatefactory->open("presenting/users_plugins.php");
     $plugins = MarketPlugin::findBySQL("user_id = ? AND publiclyvisible = 1 AND approved = 1 ORDER BY mkdate DESC", array($user_id));
     $template->set_attribute("plugin", $this);
     $template->set_attribute("plugins", $plugins);
     $template->set_attribute("title", _("Meine Plugins"));
     return count($plugins) ? $template : null;
 }
Example #4
0
 /**
  * Returns the Flexi template for entering the necessary values
  * for this step.
  *
  * @param Array $values Pre-set values
  * @param int $stepnumber which number has the current step in the wizard?
  * @param String $temp_id temporary ID for wizard workflow
  * @return String a Flexi template for getting needed data.
  */
 public function getStepTemplate($values, $stepnumber, $temp_id)
 {
     // We only need our own stored values here.
     $values = $values[__CLASS__];
     // Load template from step template directory.
     $factory = new Flexi_TemplateFactory($GLOBALS['STUDIP_BASE_PATH'] . '/app/views/course/wizard/steps');
     $tpl = $factory->open('studyareas/index');
     if ($values['studyareas']) {
         $tree = $this->buildPartialSemTree(StudipStudyArea::backwards(StudipStudyArea::findMany($values['studyareas'])), false);
         $tpl->set_attribute('assigned', $tree);
     } else {
         $tpl->set_attribute('assigned', array());
     }
     $tpl->set_attribute('values', $values);
     // First tree level is always shown.
     $tree = StudipStudyArea::findByParent(StudipStudyArea::ROOT);
     if (count($tree) == 0) {
         PageLayout::postError(formatReady(_('Das Anlegen einer ' . 'Veranstaltung ist nicht möglich, da keine Studienbereiche ' . 'existieren. Bitte wenden Sie sich an [die ' . 'Stud.IP-Administration]' . URLHelper::getLink('dispatch.php/siteinfo/show') . ' .')));
         return false;
     }
     /*
      * Someone works without JS activated, load all ancestors and
      * children of open node.
      */
     if ($values['open_node']) {
         $tpl->set_attribute('open_nodes', $this->buildPartialSemTree(StudipStudyArea::backwards(StudipStudyArea::findByParent($values['open_node'])), false, true));
     }
     /*
      * Someone works without JS and has entered a search term:
      * build the partial tree with search results.
      */
     if ($values['searchterm']) {
         $search = $this->searchSemTree($values['searchterm'], false, true);
         if ($search) {
             $tpl->set_attribute('open_nodes', $search);
             $tpl->set_attribute('search_result', $search);
             unset($values['open_node']);
         } else {
             PageLayout::postMessage(MessageBox::info(_('Es wurde kein Suchergebnis gefunden.')));
             unset($values['searchterm']);
         }
     }
     $tpl->set_attribute('tree', $tree);
     $tpl->set_attribute('ajax_url', $values['ajax_url'] ?: URLHelper::getLink('dispatch.php/course/wizard/ajax'));
     $tpl->set_attribute('no_js_url', $values['no_js_url'] ?: 'dispatch.php/course/wizard/forward/' . $stepnumber . '/' . $temp_id);
     $tpl->set_attribute('stepnumber', $stepnumber);
     $tpl->set_attribute('temp_id', $temp_id);
     return $tpl->render();
 }
Example #5
0
 public function getResultTemplate($only_user_ids = null)
 {
     $answers = $this->answers;
     if ($only_user_ids !== null) {
         foreach ($answers as $key => $answer) {
             if (!in_array($answer['user_id'], $only_user_ids)) {
                 unset($answers[$key]);
             }
         }
     }
     $tf = new Flexi_TemplateFactory(realpath(__DIR__ . "/../../app/views"));
     $template = $tf->open("questionnaire/question_types/vote/vote_evaluation.php");
     $template->set_attribute('vote', $this);
     $template->set_attribute('answers', $answers);
     return $template;
 }
 /**
  * This method behaves as usual but prefers files from the "patch"
  * location over the "core" files of Stud.IP.
  *
  * @param  string     a template string
  *
  * @return string     an absolute filename
  *
  * @throws Flexi_TemplateNotFoundException  if the template could not be found
  */
 function get_template_file($template0)
 {
     try {
         return parent::get_template_file($template0);
     } catch (\Flexi_TemplateNotFoundException $e) {
         return $this->core_factory->get_template_file($template0);
     }
 }
Example #7
0
 /**
  * Extends this controller with neccessary infobox
  *
  * @param String $view Currently viewed group
  */
 private function setSidebar($view)
 {
     $sidebar = Sidebar::Get();
     $sidebar->setImage('sidebar/smiley-sidebar.png');
     $sidebar->setTitle(PageLayout::getTitle() ?: _('Smileys'));
     // Render items
     $factory = new Flexi_TemplateFactory($this->dispatcher->trails_root . '/views/admin/smileys/');
     $actions = new ActionsWidget();
     $actions->addLink(_('Neues Smiley hochladen'), $this->url_for('admin/smileys/upload', $view), Icon::create('add', 'clickable'))->asDialog('size=auto');
     $actions->addLink(_('Smileys zählen'), $this->url_for('admin/smileys/count', $view), Icon::create('code', 'clickable'));
     $actions->addLink(_('Tabelle aktualisieren'), $this->url_for('admin/smileys/refresh', $view), Icon::create('refresh', 'clickable'));
     $actions->addLink(_('Smiley-Übersicht öffnen'), URLHelper::getLink('dispatch.php/smileys'), Icon::create('smiley', 'clickable'))->asDialog();
     $sidebar->addWidget($actions);
     $widget = new SidebarWidget();
     $filter = $factory->render('selector', array('characters' => Smiley::getUsedCharacters(), 'controller' => $this, 'view' => $view));
     $widget->setTitle(_('Filter'));
     $widget->addElement(new WidgetElement($filter));
     $sidebar->addWidget($widget);
     $widget = new SidebarWidget();
     $statistics = $factory->render('statistics', Smiley::getStatistics());
     $widget->setTitle(_('Statistiken'));
     $widget->addElement(new WidgetElement($statistics));
     $sidebar->addWidget($widget);
 }
Example #8
0
 /**
  * Renders a template using an optional layout template.
  *
  * @param mixed  a flexi template
  * @param mixes  a flexi template which is used as layout
  *
  * @return void
  */
 function render_template($template_name, $layout = NULL)
 {
     # open template
     $factory = new Flexi_TemplateFactory($this->dispatcher->trails_root . '/views/');
     $template = $factory->open($template_name);
     # template requires setup ?
     switch (get_class($template)) {
         case 'Flexi_JsTemplate':
             $this->set_content_type('text/javascript');
             break;
     }
     $template->set_attributes($this->get_assigned_variables());
     if (isset($layout)) {
         $template->set_layout($layout);
     }
     $this->render_text($template->render());
 }
Example #9
0
 /**
  * Constructor of Plugin : adds Navigation and collects information for javascript-update.
  */
 public function __construct()
 {
     parent::__construct();
     if (UpdateInformation::isCollecting()) {
         $data = Request::getArray("page_info");
         if (stripos(Request::get("page"), "plugins.php/blubber") !== false && isset($data['Blubber'])) {
             $output = array();
             switch ($data['Blubber']['stream']) {
                 case "global":
                     $stream = BlubberStream::getGlobalStream();
                     break;
                 case "course":
                     $stream = BlubberStream::getCourseStream($data['Blubber']['context_id']);
                     break;
                 case "profile":
                     $stream = BlubberStream::getProfileStream($data['Blubber']['context_id']);
                     break;
                 case "thread":
                     $stream = BlubberStream::getThreadStream($data['Blubber']['context_id']);
                     break;
                 case "custom":
                     $stream = new BlubberStream($data['Blubber']['context_id']);
                     break;
             }
             $last_check = $data['Blubber']['last_check'] ? $data['Blubber']['last_check'] : time() - 5 * 60;
             $new_postings = $stream->fetchNewPostings($last_check);
             $factory = new Flexi_TemplateFactory($this->getPluginPath() . "/views");
             foreach ($new_postings as $new_posting) {
                 if ($new_posting['root_id'] === $new_posting['topic_id']) {
                     $thread = $new_posting;
                     $template = $factory->open("streams/thread.php");
                     $template->set_attribute('thread', $new_posting);
                 } else {
                     $thread = new BlubberPosting($new_posting['root_id']);
                     $template = $factory->open("streams/comment.php");
                     $template->set_attribute('posting', $new_posting);
                 }
                 BlubberPosting::$course_hashes = $thread['user_id'] !== $thread['Seminar_id'] ? $thread['Seminar_id'] : false;
                 $template->set_attribute("course_id", $data['Blubber']['seminar_id']);
                 $output['postings'][] = array('posting_id' => $new_posting['topic_id'], 'discussion_time' => $new_posting['discussion_time'], 'mkdate' => $new_posting['mkdate'], 'root_id' => $new_posting['root_id'], 'content' => $template->render());
             }
             UpdateInformation::setInformation("Blubber.getNewPosts", $output);
             //Events-Queue:
             $db = DBManager::get();
             $events = $db->query("SELECT event_type, item_id " . "FROM blubber_events_queue " . "WHERE mkdate >= " . $db->quote($last_check) . " " . "ORDER BY mkdate ASC " . "")->fetchAll(PDO::FETCH_ASSOC);
             UpdateInformation::setInformation("Blubber.blubberEvents", $events);
             $db->exec("DELETE FROM blubber_events_queue " . "WHERE mkdate < UNIX_TIMESTAMP() - 60 * 60 * 6 " . "");
         }
     }
     if (Navigation::hasItem("/community")) {
         $nav = new Navigation($this->getDisplayTitle(), PluginEngine::getURL($this, array(), "streams/global"));
         $nav->addSubNavigation("global", new AutoNavigation(_("Globaler Stream"), PluginEngine::getURL($this, array(), "streams/global")));
         foreach (BlubberStream::findMine() as $stream) {
             $url = PluginEngine::getURL($this, array(), "streams/custom/" . $stream->getId());
             $nav->addSubNavigation($stream->getId(), new AutoNavigation($stream['name'], $url));
             if ($stream['defaultstream']) {
                 $nav->setURL($url);
             }
         }
         $nav->addSubNavigation("add", new AutoNavigation(_("Neuen Stream erstellen"), PluginEngine::getURL($this, array(), "streams/edit")));
         Navigation::insertItem("/community/blubber", $nav, "online");
         Navigation::getItem("/community")->setURL($nav->getURL());
     }
     if (Navigation::hasItem("/profile") && $this->isActivated(get_userid(Request::username('username', $GLOBALS['auth']->auth['uname'])), 'user')) {
         $nav = new AutoNavigation(_("Blubber"), PluginEngine::getURL($this, array('user_id' => get_userid(Request::get("username"))), "streams/profile"));
         Navigation::addItem("/profile/blubber", $nav);
     }
 }
Example #10
0
 /**
  * outputs the CalendarView with all (grouped) dates in columns.
  *
  * @param  array  $params  you can pass some additional variables to the templates
  *
  * @return string
  */
 public function render($params = array())
 {
     $style_parameters = array('whole_height' => $this->getOverallHeight(), 'entry_height' => $this->getHeight());
     $factory = new Flexi_TemplateFactory(dirname(__FILE__) . '/../../app/views');
     PageLayout::addStyle($factory->render('calendar/stylesheet', $style_parameters));
     $template = $GLOBALS['template_factory']->open("calendar/calendar_view.php");
     $template->set_attribute("calendar_view", $this);
     $template->set_attribute("view_id", $this->view_id);
     return $template->render($params);
 }
 public function getHomepageTemplate($user_id)
 {
     $materialien = LernmarktplatzMaterial::findMine($user_id);
     if (count($materialien)) {
         $template_factory = new Flexi_TemplateFactory(__DIR__ . "/views");
         $template = $template_factory->open("mymaterial/_material_list");
         $template->set_attribute("plugin", $this);
         $template->set_attribute("materialien", $materialien);
         $template->set_attribute("title", _("Lernmaterialien"));
         $template->set_attribute("icon_url", Icon::create("service", "clickable")->asImagePath());
         return $template;
     } else {
         return null;
     }
 }
 function index_action()
 {
     if (!$GLOBALS['perm']->have_perm("admin")) {
         throw new AccessDeniedException(_("Sie sind nicht berechtigt, dieses Plugin zu benutzen."));
     }
     $db = DBManager::get();
     if (Request::submitted('do_search_source')) {
         $result = search_range(Request::quoted('search_source'));
         if (is_array($result)) {
             $result = array_filter($result, function ($r) {
                 return $r["type"] == "sem";
             });
             if (count($result)) {
                 PageLayout::postMessage(MessageBox::success(sprintf(_("Ihre Sucher ergab %s Treffer."), count($result))));
                 $show_source_result = true;
             }
         } else {
             PageLayout::postMessage(MessageBox::info(_("Ihre Suche ergab keine Treffer.")));
         }
     }
     if (Request::submitted('do_choose_source')) {
         $source_id = Request::option('search_source_result');
         $copy_count = 5;
         Request::set('to_copy', null);
     } else {
         if (Request::submitted('source_id')) {
             $source_id = Request::option('source_id');
             $copy_count = Request::int('copy_count');
             if ($copy_count < 1) {
                 $copy_count = 1;
             }
         }
     }
     if ($source_id) {
         $source = Seminar::getInstance($source_id);
         $source_name = $source->getName() . ' (' . $source->getStartSemesterName() . ')';
         $copy_type = Request::int('copy_type', $source->status);
         if (SeminarCategories::getByTypeId($copy_type)->course_creation_forbidden) {
             $copy_type = 0;
         }
         if (SeminarCategories::getByTypeId($source->status)->only_inst_user) {
             $search_template = "user_inst";
         } else {
             $search_template = "user";
         }
         $bet_inst = $db->query("SELECT institut_id FROM seminar_inst WHERE seminar_id=" . $db->quote($source_id))->fetchAll(PDO::FETCH_COLUMN);
         $source_dozenten = array_keys($source->getMembers('dozent'));
         if ($copy_count) {
             $r = Request::getArray('to_copy');
             $delete_lecturer = Request::getArray('delete_lecturer');
             $add_lecturer = count(Request::getArray('add_lecturer')) ? (int) key(Request::getArray('add_lecturer')) : null;
             for ($i = 0; $i < $copy_count; $i++) {
                 $to_copy['nr'][$i] = isset($r['nr'][$i]) ? $r['nr'][$i] : $source->getNumber();
                 $to_copy['name'][$i] = isset($r['name'][$i]) ? $r['name'][$i] : $source->getName();
                 $to_copy['participants'][$i] = isset($r['participants'][$i]) ? 1 : 0;
                 $to_copy['lecturers'][$i] = $r['lecturers'][$i];
                 if (empty($to_copy['lecturers'][$i])) {
                     $to_copy['lecturers'][$i] = $source_dozenten;
                 } else {
                     if (isset($delete_lecturer[$i]) && count($to_copy['lecturers'][$i]) > 1) {
                         $to_delete = array_search(key($delete_lecturer[$i]), $to_copy['lecturers'][$i]);
                         if ($to_delete !== false) {
                             unset($to_copy['lecturers'][$i][$to_delete]);
                         }
                     }
                 }
                 if ($add_lecturer === $i && Request::option('add_doz_' . $add_lecturer)) {
                     $to_copy['lecturers'][$i][] = Request::option('add_doz_' . $add_lecturer);
                 }
                 $to_copy['search_lecturer'][$i] = new PermissionSearch($search_template, sprintf(_("%s auswählen"), get_title_for_status('dozent', 1, $source->status)), "user_id", array('permission' => 'dozent', 'exclude_user' => $to_copy['lecturers'][$i], 'institute' => $bet_inst));
             }
         }
         if (Request::submitted('do_copy') && count($to_copy)) {
             $copied = array();
             $lecturer_insert = $db->prepare("INSERT INTO seminar_user (seminar_id,user_id,status,position,gruppe,comment,visible,mkdate) VALUES (?,?,'dozent',?,?,'','yes',UNIX_TIMESTAMP())");
             $copy_seminar_inst = $db->prepare("INSERT INTO seminar_inst (seminar_id,institut_id) SELECT ?,institut_id FROM seminar_inst WHERE seminar_id=?");
             $copy_seminar_sem_tree = $db->prepare("INSERT INTO seminar_sem_tree (seminar_id,sem_tree_id) SELECT ?,sem_tree_id FROM seminar_sem_tree WHERE seminar_id=?");
             $copy_seminar_user = $db->prepare("INSERT IGNORE INTO seminar_user (seminar_id,user_id,status,gruppe, mkdate,comment,position) SELECT ?,user_id,status,gruppe,UNIX_TIMESTAMP(),'',0 FROM seminar_user WHERE status IN ('user','autor','tutor') AND seminar_id=?");
             $copy_seminar_userdomains = $db->prepare("INSERT INTO seminar_userdomains (seminar_id,userdomain_id) SELECT ?,userdomain_id FROM seminar_userdomains WHERE seminar_id=?");
             $copy_statusgruppen = $db->prepare("INSERT INTO statusgruppen (statusgruppe_id,name,range_id,position,size,selfassign,mkdate) SELECT MD5(CONCAT(statusgruppe_id, ?)),name,?,position,size,selfassign,UNIX_TIMESTAMP() FROM statusgruppen WHERE range_id=?");
             $copy_statusgruppe_user = $db->prepare("INSERT INTO statusgruppe_user (statusgruppe_id,user_id,position) SELECT MD5(CONCAT(statusgruppe_user.statusgruppe_id, ?)),user_id,statusgruppe_user.position FROM statusgruppen INNER JOIN statusgruppe_user USING(statusgruppe_id) WHERE range_id=?");
             for ($i = 0; $i < $copy_count; $i++) {
                 $new_sem = Course::build($source->toArray());
                 $new_sem->setId($new_sem->getNewId());
                 $new_sem_id = $new_sem->id;
                 $new_sem->status = Request::int('copy_type', 1);
                 $new_sem->name = $to_copy['name'][$i];
                 $new_sem->veranstaltungsnummer = $to_copy['nr'][$i];
                 $new_sem->store();
                 if (!$new_sem->isNew()) {
                     log_event("SEM_CREATE", $new_sem_id);
                     $gruppe = (int) select_group($new_sem->start_time);
                     $position = 1;
                     foreach ($to_copy['lecturers'][$i] as $lecturer) {
                         $lecturer_insert->execute(array($new_sem_id, $lecturer, $position, $gruppe));
                     }
                     $copy_seminar_inst->execute(array($new_sem_id, $source_id));
                     $copy_seminar_sem_tree->execute(array($new_sem_id, $source_id));
                     $copy_seminar_userdomains->execute(array($new_sem_id, $source_id));
                     if ($to_copy['participants'][$i]) {
                         $copy_seminar_user->execute(array($new_sem_id, $source_id));
                         $copy_statusgruppen->execute(array($new_sem_id, $new_sem_id, $source_id));
                         $copy_statusgruppe_user->execute(array($new_sem_id, $source_id));
                     }
                     $copied[] = $new_sem;
                 }
             }
             PageLayout::postMessage(MessageBox::success(sprintf(_("Es wurden %s Kopien erstellt."), count($copied))));
             $source_id = null;
         }
     }
     PageLayout::setTitle(_("Veranstaltungs-Vervielfältiger"));
     $template_factory = new Flexi_TemplateFactory(dirname(__FILE__) . "/templates");
     $template = $template_factory->open('index.php');
     $template->set_layout($GLOBALS['template_factory']->open('layouts/base.php'));
     echo $template->render(compact('source_id', 'source_name', 'show_source_result', 'result', 'copy_count', 'copy_type', 'to_copy', 'copied'));
 }
Example #13
0
 /**
  * delete one room request
  */
 public function delete_action()
 {
     $request = RoomRequest::find(Request::option('request_id'));
     if (!$request) {
         throw new Trails_Exception(403);
     }
     if (Request::isGet()) {
         $factory = new Flexi_TemplateFactory($this->dispatcher->trails_root . '/views/');
         $template = $factory->open('course/room_requests/_del.php');
         $template->action = $this->link_for('delete/' . $this->course_id, array('request_id' => $request->getid()));
         $template->question = sprintf(_('Möchten Sie die Raumanfrage "%s" löschen?'), $request->getTypeExplained());
         $this->flash['message'] = $template->render();
     } else {
         CSRFProtection::verifyUnsafeRequest();
         if (Request::submitted('kill')) {
             if ($request->delete()) {
                 $this->flash['message'] = MessageBox::success("Die Raumanfrage wurde gelöscht.");
             }
         }
     }
     $this->redirect('course/room_requests/index/' . $this->course_id);
 }
Example #14
0
 public function comment_action()
 {
     $context = Request::option("context");
     $thread = new ForumPosting(Request::option("thread"));
     if ($thread['context_type'] === "course") {
         $seminar = new Seminar($context);
         if ($seminar->write_level > 0 && !$GLOBALS['perm']->have_studip_perm("autor", $context)) {
             throw new AccessDeniedException("Kein Zugriff");
         }
     }
     ForumPosting::$course_hashes = $thread['context_type'] === "course" ? $thread['Seminar_id'] : false;
     if (Request::option("thread") && $thread['Seminar_id'] === $context) {
         $output = array();
         $posting = new ForumPosting();
         ForumPosting::$mention_thread_id = $thread->getId();
         StudipTransformFormat::addStudipMarkup("mention1", '@\\"[^\\n\\"]*\\"', "", "ForumPosting::mention");
         StudipTransformFormat::addStudipMarkup("mention2", '@[^\\s]*[\\d\\w_]+', "", "ForumPosting::mention");
         $content = transformBeforeSave(studip_utf8decode(Request::get("content")));
         //mentions einbauen:
         $content = preg_replace("/(@\"[^\n\"]*\")/e", "ForumPosting::mention('\\1', '" . $thread->getId() . "')", $content);
         $content = preg_replace("/(@[^\\s]+)/e", "ForumPosting::mention('\\1', '" . $thread->getId() . "')", $content);
         $posting['description'] = $content;
         $posting['context_type'] = $thread['context_type'];
         $posting['seminar_id'] = $thread['Seminar_id'];
         $posting['root_id'] = $posting['parent_id'] = Request::option("thread");
         $posting['name'] = "Re: " . $thread['name'];
         if ($GLOBALS['user']->id !== "nobody") {
             $posting['user_id'] = $GLOBALS['user']->id;
             $posting['author'] = get_fullname();
         } else {
             if (Request::get("anonymous_security") === $_SESSION['blubber_anonymous_security']) {
                 $contact_user = BlubberExternalContact::findByEmail(Request::get("anonymous_email"));
                 $_SESSION['anonymous_email'] = Request::get("anonymous_email");
                 $_SESSION['anonymous_name'] = $contact_user['name'] = Request::get("anonymous_name");
                 $contact_user->store();
                 $posting['user_id'] = $contact_user->getId();
                 $posting['external_contact'] = 1;
                 $posting['author'] = Request::get("anonymous_name");
             } else {
                 throw new AccessDeniedException("No permission to write posting.");
             }
         }
         $posting['author_host'] = $_SERVER['REMOTE_ADDR'];
         if ($posting->store()) {
             $factory = new Flexi_TemplateFactory($this->plugin->getPluginPath() . "/views/forum");
             $template = $factory->open("comment.php");
             $template->set_attribute('posting', $posting);
             $template->set_attribute('course_id', $thread['Seminar_id']);
             $output['content'] = studip_utf8encode($template->render($template->render()));
             $output['mkdate'] = time();
             $output['posting_id'] = $posting->getId();
             //Notifications:
             if (class_exists("PersonalNotifications")) {
                 $user_ids = array();
                 if ($thread['user_id'] && $thread['user_id'] !== $GLOBALS['user']->id) {
                     $user_ids[] = $thread['user_id'];
                 }
                 foreach ((array) $thread->getChildren() as $comment) {
                     if ($comment['user_id'] && $comment['user_id'] !== $GLOBALS['user']->id && !$comment['external_contact']) {
                         $user_ids[] = $comment['user_id'];
                     }
                 }
                 $user_ids = array_unique($user_ids);
                 PersonalNotifications::add($user_ids, PluginEngine::getURL($this->plugin, array('cid' => $thread['context_type'] === "course" ? $thread['Seminar_id'] : null), "forum/thread/" . $thread->getId()), get_fullname() . " hat einen Kommentar geschrieben", "posting_" . $posting->getId(), Avatar::getAvatar($GLOBALS['user']->id)->getURL(Avatar::MEDIUM));
             }
         }
         $this->render_json($output);
     } else {
         $this->render_json(array('error' => "Konnte thread nicht zuordnen."));
     }
 }
Example #15
0
<?php

error_reporting(E_ALL ^ E_NOTICE);
// load flexi lib
require_once dirname(__FILE__) . '/../../lib/flexi.php';
// where are the templates
$path_to_the_templates = dirname(__FILE__) . '/templates';
// we need a template factory
$factory = new Flexi_TemplateFactory($path_to_the_templates);
// load haml plugin
require_once dirname(__FILE__) . '/../../lib/mustache_template.php';
$factory->add_handler('mustache', 'Flexi_MustacheTemplate');
// open template
$template = $factory->open('mustache');
$template->set_attributes(array("name" => "Chris", "value" => 10000, "taxed_value" => 10000 - 10000 * 0.4, "in_ca" => true));
// test mix of different template engines
$template->set_layout("layout");
// render template
echo $template->render();
 function index_action($step = 'manifest')
 {
     $step = Request::option('step', $step);
     $this->previous = $this->next = $last = false;
     foreach ($this->actions as $action) {
         if ($last == $step) {
             $this->next = $action;
         }
         if ($action == $step) {
             $this->previous = $last;
         }
         $last = $action;
     }
     // if (Request::isPost()) {    # since Stud.IP 2.1
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $this->plugin = array_merge($this->plugin, $this->extract($step, $errors));
         $_SESSION['plugin-generator']['passed'][$step] = empty($errors);
     }
     if (!empty($errors)) {
         PageLayout::postMessage(Messagebox::error(_('Es sind Fehler aufgetreten:'), $errors));
     } elseif (Request::submitted('action')) {
         $action = Request::option('action');
         if (!in_array($action, array('display download install'))) {
             $generator = new Generator($this->dispatcher->plugin->getPluginPath(), '/templates', '/environments');
         }
         $generator->populate($this->plugin);
         $generator->{$action}();
         if ($action === 'install') {
             $this->redirect(URLHelper::getURL('dispatch.php/admin/plugin'));
             return;
         }
         #            PageLayout::postMessage(Messagebox::success('Jipp.'));
     } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
         if (Request::submitted('back')) {
             $step = Request::option('back', $this->previous);
         } else {
             if (Request::submitted('forward')) {
                 $step = Request::option('forward', $this->next);
             }
         }
         $this->redirect('generator/' . $step);
         return;
     }
     $this->step = $step;
     switch ($step) {
         case 'manifest':
             $this->interfaces = array('HomepagePlugin' => _('Homepage eines Nutzers'), 'PortalPlugin' => _('Startseite (Portalseite)'), 'StandardPlugin' => _('Veranstaltungen und Einrichtungen'), 'StudienmodulManagementPlugin' => _('Studienmodulsuche'), 'SystemPlugin' => _('Systemweite Erweiterungen'));
             $this->versions = words('2.0 2.1 2.2 2.3 2.4');
             break;
         case 'assets':
             $this->environments = array('default' => _('Standard'), 'trails' => _('Trails'));
             break;
         case 'polyfill':
             $this->polyfills = Polyfill::getVersions();
             break;
     }
     $variables = array('step' => $step, 'controller' => $this);
     $factory = new Flexi_TemplateFactory($this->dispatcher->plugin->getPluginPath() . '/app/views/');
     $progress = $factory->render('infobox-route', $variables);
     $this->setInfoboxImage($this->dispatcher->plugin->getPluginURL() . '/assets/images/puzzle.jpg')->addToInfobox(_('Fortschritt'), $progress)->addToInfobox(_('Aktionen'), sprintf('<a href="%s">Reset</a>', $this->url_for('generator/' . $step . '?reset=1')), Assets::image_path('icons/16/black/refresh.png'));
 }
Example #17
0
 /**
  * send out the notification messages for the passed topic. The contents
  * and a link directly to the topic are added to the messages.
  * 
  * @param string $topic_id
  */
 static function notify($topic_id)
 {
     // send message to all abo-users
     $db = DBManager::get();
     $messaging = new ForumBulkMail();
     // $messaging = new Messaging();
     // get all parent topic-ids, to find out which users to notify
     $path = ForumEntry::getPathToPosting($topic_id);
     // fetch all users to notify, exlcude current user
     $stmt = $db->prepare("SELECT DISTINCT user_id\n            FROM forum_abo_users\n            WHERE topic_id IN (:topic_ids)\n                AND user_id != :user_id");
     $stmt->bindParam(':topic_ids', array_keys($path), StudipPDO::PARAM_ARRAY);
     $stmt->bindParam(':user_id', $GLOBALS['user']->id);
     $stmt->execute();
     // get details for topic
     $topic = ForumEntry::getConstraints($topic_id);
     $template_factory = new Flexi_TemplateFactory(dirname(__FILE__) . '/../views');
     $template = $template_factory->open('index/_mail_notification');
     // notify users
     while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $user_id = $data['user_id'];
         // create subject and content
         setTempLanguage(get_userid($user_id));
         // check if user wants an email for all or selected messages only
         $force_email = false;
         if ($messaging->user_wants_email($user_id)) {
             $force_email = true;
         }
         $parent_id = ForumEntry::getParentTopicId($topic['topic_id']);
         setTempLanguage($data['user_id']);
         $notification = sprintf(_("%s hat einen Beitrag geschrieben"), $topic['anonymous'] ? _('Anonym') : $topic['author']);
         restoreLanguage();
         PersonalNotifications::add($user_id, UrlHelper::getUrl('plugins.php/coreforum/index/index/' . $topic['topic_id'] . '#' . $topic['topic_id'], array('cid' => $topic['seminar_id']), true), $notification, "forumposting_" . $topic['topic_id'], Icon::create('forum', 'clickable')->asImagePath(40));
         if ($force_email) {
             $title = implode(' >> ', ForumEntry::getFlatPathToPosting($topic_id));
             $subject = addslashes(_('[Forum]') . ' ' . ($title ?: _('Neuer Beitrag')));
             $htmlMessage = $template->render(compact('user_id', 'topic', 'path'));
             $textMessage = trim(kill_format($htmlMessage));
             $userWantsHtml = UserConfig::get($user_id)->getValue('MAIL_AS_HTML');
             StudipMail::sendMessage(User::find($user_id)->email, $subject, addslashes($textMessage), $userWantsHtml ? $htmlMessage : null);
         }
         restoreLanguage();
     }
     $messaging->bulkSend();
 }
Example #18
0
 /**
  * Writes a comment on a thread and outputs the metadata of new comment as json.
  * @throws AccessDeniedException
  */
 public function comment_action()
 {
     if (!Request::isPost()) {
         throw new Exception("GET not supported");
     }
     $context = Request::option("context");
     $thread = new BlubberPosting(Request::option("thread"));
     if ($thread['context_type'] === "course" && $GLOBALS['SessSemName']['class'] === "sem") {
         $seminar = new Seminar($context);
         if ($seminar->write_level > 0 && !$GLOBALS['perm']->have_studip_perm("autor", $context)) {
             throw new AccessDeniedException();
         }
     }
     BlubberPosting::$course_hashes = $thread['context_type'] === "course" ? $thread['Seminar_id'] : false;
     if (!$thread->isNew() && $thread['Seminar_id'] === $context) {
         $output = array();
         $posting = new BlubberPosting();
         $posting['context_type'] = $thread['context_type'];
         $posting['seminar_id'] = $thread['Seminar_id'];
         $posting['root_id'] = $posting['parent_id'] = $thread->getId();
         $posting['name'] = "Re: " . $thread['name'];
         if ($GLOBALS['user']->id !== "nobody") {
             $posting['user_id'] = $GLOBALS['user']->id;
         } else {
             if (Request::get("anonymous_security") === $_SESSION['blubber_anonymous_security']) {
                 $contact_user = BlubberExternalContact::findByEmail(Request::get("anonymous_email"));
                 $_SESSION['anonymous_email'] = Request::get("anonymous_email");
                 $_SESSION['anonymous_name'] = $contact_user['name'] = Request::get("anonymous_name");
                 $contact_user->store();
                 $posting['user_id'] = $contact_user->getId();
                 $posting['external_contact'] = 1;
             } else {
                 throw new AccessDeniedException("No permission to write posting.");
             }
         }
         $posting['author_host'] = $_SERVER['REMOTE_ADDR'];
         $posting['description'] = studip_utf8decode(Request::get("content"));
         $posting->store();
         BlubberPosting::$mention_posting_id = $posting->getId();
         StudipTransformFormat::addStudipMarkup("mention1", '@\\"[^\\n\\"]*\\"', null, "BlubberPosting::mention");
         StudipTransformFormat::addStudipMarkup("mention2", '@[^\\s]*[\\d\\w_]+', null, "BlubberPosting::mention");
         $content = transformBeforeSave(studip_utf8decode(Request::get("content")));
         $posting['description'] = $content;
         $posting->store();
         $factory = new Flexi_TemplateFactory($this->plugin->getPluginPath() . "/views/streams");
         $template = $factory->open("comment.php");
         $template->set_attribute('posting', $posting);
         $template->set_attribute('course_id', $thread['Seminar_id']);
         $output['content'] = $template->render($template->render());
         $output['mkdate'] = time();
         $output['posting_id'] = $posting->getId();
         //Notifications:
         $user_ids = array();
         if ($thread['user_id'] && $thread['user_id'] !== $GLOBALS['user']->id) {
             $user_ids[] = $thread['user_id'];
         }
         foreach ((array) $thread->getChildren() as $comment) {
             if ($comment['user_id'] && $comment['user_id'] !== $GLOBALS['user']->id && !$comment['external_contact']) {
                 $user_ids[] = $comment['user_id'];
             }
         }
         $user_ids = array_unique($user_ids);
         foreach ($user_ids as $user_id) {
             setTempLanguage($user_id);
             $avatar = Visibility::verify('picture', $GLOBALS['user']->id, $user_id) ? Avatar::getAvatar($GLOBALS['user']->id) : Avatar::getNobody();
             PersonalNotifications::add($user_id, PluginEngine::getURL($this->plugin, array('cid' => $thread['context_type'] === "course" ? $thread['Seminar_id'] : null), "streams/thread/" . $thread->getId()), sprintf(_("%s hat einen Kommentar geschrieben"), get_fullname()), "posting_" . $posting->getId(), $avatar->getURL(Avatar::MEDIUM));
             restoreLanguage();
         }
         $this->render_json($output);
     } else {
         $this->render_json(array('error' => "Konnte thread nicht zuordnen."));
     }
 }
Example #19
0
 /**
  * this action is the main action of the schedule-controller, setting the environment
  * for the timetable, accepting a comma-separated list of days.
  *
  * @param  string  $days  a list of an arbitrary mix of the numbers 0-6, separated
  *                        with a comma (e.g. 1,2,3,4,5 (for Monday to Friday, the default))
  * @return void
  */
 function index_action($days = false)
 {
     global $user;
     $schedule_settings = CalendarScheduleModel::getScheduleSettings();
     if ($GLOBALS['perm']->have_perm('admin')) {
         $inst_mode = true;
     }
     if ($inst_mode) {
         // try to find the correct institute-id
         $institute_id = Request::option('institute_id', $SessSemName[1] ? $SessSemName[1] : Request::option('cid', false));
         if (!$institute_id) {
             $institute_id = UserConfig::get($user->id)->MY_INSTITUTES_DEFAULT;
         }
         if (!$institute_id || !in_array(get_object_type($institute_id), words('fak inst'))) {
             throw new Exception('Cannot display institute-calender. No valid ID given!');
         }
         Navigation::activateItem('/browse/my_courses/schedule');
     } else {
         Navigation::activateItem('/calendar/schedule');
     }
     // check, if the hidden seminar-entries shall be shown
     $show_hidden = Request::int('show_hidden', 0);
     // load semester-data and current semester
     $semdata = new SemesterData();
     $this->semesters = array_reverse($semdata->getAllSemesterData());
     if (Request::option('semester_id')) {
         $this->current_semester = $semdata->getSemesterData(Request::option('semester_id'));
     } else {
         $this->current_semester = $semdata->getCurrentSemesterData();
     }
     // check type-safe if days is false otherwise sunday (0) cannot be chosen
     if ($days === false) {
         if (Request::getArray('days')) {
             $this->days = array_keys(Request::getArray('days'));
         } else {
             $this->days = $schedule_settings['glb_days'];
             foreach ($this->days as $key => $day_number) {
                 $this->days[$key] = ($day_number + 6) % 7;
             }
         }
     } else {
         $this->days = explode(',', $days);
     }
     $this->controller = $this;
     $this->calendar_view = $inst_mode ? CalendarScheduleModel::getInstCalendarView($institute_id, $show_hidden, $this->current_semester, $this->days) : CalendarScheduleModel::getUserCalendarView($GLOBALS['user']->id, $show_hidden, $this->current_semester, $this->days);
     // have we chosen an entry to display?
     if ($this->flash['entry']) {
         if ($inst_mode) {
             $this->show_entry = $this->flash['entry'];
         } else {
             if ($this->flash['entry']['id'] == null) {
                 $this->show_entry = $this->flash['entry'];
             } else {
                 foreach ($this->calendar_view->getColumns() as $entry_days) {
                     foreach ($entry_days->getEntries() as $entry) {
                         if ($this->flash['entry']['cycle_id']) {
                             if ($this->flash['entry']['id'] . '-' . $this->flash['entry']['cycle_id'] == $entry['id']) {
                                 $this->show_entry = $entry;
                                 $this->show_entry['id'] = reset(explode('-', $this->show_entry['id']));
                             }
                         } else {
                             if ($entry['id'] == $this->flash['entry']['id']) {
                                 $this->show_entry = $entry;
                             }
                         }
                     }
                 }
             }
         }
     }
     $style_parameters = array('whole_height' => $this->calendar_view->getOverallHeight(), 'entry_height' => $this->calendar_view->getHeight());
     $factory = new Flexi_TemplateFactory($this->dispatcher->trails_root . '/views');
     PageLayout::addStyle($factory->render('calendar/stylesheet', $style_parameters), 'screen, print');
     if (Request::option('printview')) {
         $this->calendar_view->setReadOnly();
         PageLayout::addStylesheet('print.css');
     } else {
         PageLayout::addStylesheet('print.css', array('media' => 'print'));
     }
     $this->show_hidden = $show_hidden;
     $inst = get_object_name($institute_id, 'inst');
     $this->inst_mode = $inst_mode;
     $this->institute_name = $inst['name'];
     $this->institute_id = $institute_id;
     if (Request::get('show_settings')) {
         $this->show_settings = true;
     }
 }
Example #20
0
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# load flexi lib
require_once dirname(__FILE__) . '/../../lib/flexi.php';
# where are the templates
$path_to_the_templates = dirname(__FILE__) . '/templates';
# we need a template factory
$factory = new Flexi_TemplateFactory($path_to_the_templates);
# open template
$template = $factory->open('quotes');
# set quotes
$quotes = array(array('author' => 'August Strindberg', 'quote' => 'Der Mensch ist ein wunderliches Tier.'), array('author' => 'Pierre Reverdy', 'quote' => 'Der Mensch ist ein Tier, das sich selbst gezähmt hat.'), array('author' => 'Thomas Niederreuther', 'quote' => 'Der Mensch ist das einzige Tier, das sich für einen Menschen hält.'), array('author' => 'Durs Grünbein', 'quote' => 'Der Mensch ist das Tier, das Kaugummi kaut.'), array('author' => 'Mark Twain', 'quote' => 'Der Mensch ist das einzige Tier, das erröten kann - oder sollte.'));
# select one randomly
shuffle($quotes);
$quote_of_the_day = array_shift($quotes);
$template->set_attributes(array('quotes' => $quotes, 'quote_of_the_day' => $quote_of_the_day));
# set current time
$time = time();
$template->set_attribute('time', $time);
# render template
echo $template->render();
Example #21
0
 public function __construct()
 {
     global $perm;
     parent::__construct();
     if (UpdateInformation::isCollecting()) {
         $data = Request::getArray("page_info");
         if (stripos(Request::get("page"), "plugins.php/blubber") !== false) {
             $output = array();
             $context_id = $data['Blubber']['context_id'];
             $stream = $data['Blubber']['stream'];
             $last_check = $data['Blubber']['last_check'] ? $data['Blubber']['last_check'] : time() - 5 * 60;
             $parameter = array('since' => $last_check);
             if ($stream === "thread") {
                 $parameter['thread'] = $context_id;
             }
             if ($stream === "course") {
                 $parameter['seminar_id'] = $context_id;
             }
             if ($stream === "profile") {
                 $parameter['user_id'] = $context_id;
             }
             if ($data['Blubber']['search']) {
                 $parameter['search'] = $data['Blubber']['search'];
             }
             $new_postings = ForumPosting::getPostings($parameter);
             $factory = new Flexi_TemplateFactory($this->getPluginPath() . "/views");
             foreach ($new_postings as $new_posting) {
                 if ($new_posting['root_id'] === $new_posting['topic_id']) {
                     $thread = $new_posting;
                     $template = $factory->open("forum/thread.php");
                     $template->set_attribute('thread', $new_posting);
                 } else {
                     $thread = new ForumPosting($new_posting['root_id']);
                     $template = $factory->open("forum/comment.php");
                     $template->set_attribute('posting', $new_posting);
                 }
                 ForumPosting::$course_hashes = $thread['user_id'] !== $thread['Seminar_id'] ? $thread['Seminar_id'] : false;
                 $template->set_attribute("course_id", $data['Blubber']['seminar_id']);
                 $output['postings'][] = array('posting_id' => $new_posting['topic_id'], 'mkdate' => $new_posting['mkdate'], 'root_id' => $new_posting['root_id'], 'content' => $template->render());
             }
             UpdateInformation::setInformation("Blubber.getNewPosts", $output);
             //Events-Queue:
             $db = DBManager::get();
             $events = $db->query("SELECT event_type, item_id " . "FROM blubber_events_queue " . "WHERE mkdate >= " . $db->quote($last_check) . " " . "ORDER BY mkdate ASC " . "")->fetchAll(PDO::FETCH_ASSOC);
             UpdateInformation::setInformation("Blubber.blubberEvents", $events);
             $db->exec("DELETE FROM blubber_events_queue " . "WHERE mkdate < UNIX_TIMESTAMP() - 60 * 60 * 6 " . "");
         }
     }
     if (Navigation::hasItem("/course") && $this->isActivated() && version_compare($GLOBALS['SOFTWARE_VERSION'], "2.4") <= 0) {
         $tab = new AutoNavigation($this->getDisplayTitle(), PluginEngine::getLink($this, array(), "forum/forum"));
         $tab->setImage($this->getPluginURL() . "/assets/images/blubber_white.png");
         Navigation::addItem("/course/blubberforum", $tab);
     }
     if (Navigation::hasItem("/community")) {
         $nav = new AutoNavigation($this->getDisplayTitle(), PluginEngine::getURL($this, array(), "forum/globalstream"));
         Navigation::insertItem("/community/blubber", $nav, "online");
         Navigation::getItem("/community")->setURL(PluginEngine::getURL($this, array(), "forum/globalstream"));
     }
     if (Navigation::hasItem("/profile")) {
         $nav = new AutoNavigation(_("Blubber"), PluginEngine::getURL($this, array('user_id' => get_userid(Request::get("username"))), "forum/profile"));
         Navigation::addItem("/profile/blubber", $nav);
     }
 }
Example #22
0
 /**
  *
  **/
 public function perform($unconsumed)
 {
     $format = reset(self::$format_guesses);
     if (isset($_SERVER['CONTENT_TYPE'])) {
         foreach (self::$format_guesses as $mime_type => $guessed_format) {
             if ($_SERVER['CONTENT_TYPE'] === $mime_type) {
                 $format = $guessed_format;
             }
         }
     }
     if (preg_match('/\\.(' . implode('|', self::$format_guesses) . ')$/', $unconsumed, $match)) {
         $format = $match[1];
         $unconsumed = substr($unconsumed, 0, -strlen($match[0]));
     }
     // Get id from authorisation (either OAuth or standard)
     try {
         if (OAuth::isSigned()) {
             $user_id = OAuth::verify();
         } elseif (HTTPAuth::isSigned()) {
             $user_id = HTTPAuth::verify();
         } elseif ($GLOBALS['user']->id !== 'nobody') {
             $user_id = $GLOBALS['user']->id;
         }
         if (!$user_id) {
             throw new Exception('Unauthorized', 401);
         }
     } catch (Exception $e) {
         $status = sprintf('HTTP/1.1 %u %s', $e->getCode(), $e->getMessage());
         header($status, true, $e->getCode());
         die($status);
     }
     // Fake user identity
     $user = User::find($user_id);
     $GLOBALS['auth'] = new Seminar_Auth();
     $GLOBALS['auth']->auth = array('uid' => $user->user_id, 'uname' => $user->username, 'perm' => $user->perms);
     $GLOBALS['user'] = new Seminar_User();
     $GLOBALS['user']->fake_user = true;
     $GLOBALS['user']->register_globals = false;
     $GLOBALS['user']->start($user->user_id);
     $GLOBALS['perm'] = new Seminar_Perm();
     $GLOBALS['MAIL_VALIDATE_BOX'] = false;
     setTempLanguage($GLOBALS['user']->id);
     \Slim_Route::setDefaultConditions(array('course_id' => '[0-9a-f]{32}', 'message_id' => '[0-9a-f]{32}', 'range_id' => '[0-9a-f]{32}', 'semester_id' => '[0-9a-f]{32}', 'user_id' => '[0-9a-f]{32}'));
     $template_factory = new Flexi_TemplateFactory($this->dispatcher->plugin->getPluginPath());
     $template = $template_factory->open('app/views/api/' . $format . '.php');
     $router = RestIP\Router::getInstance(null, $template);
     $router->handleErrors();
     if (Studip\ENV === 'development') {
         error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
     } else {
         error_reporting(0);
     }
     if (Request::option('mode', 'compact') === 'complete') {
         $router->setMode(RestIP\Router::MODE_COMPLETE);
     } else {
         $router->setMode(RestIP\Router::MODE_COMPACT);
     }
     $env = $router->environment();
     $env['PATH_INFO'] = '/' . $unconsumed;
     $router->hook('slim.before.dispatch', function () use($router) {
         $route = reset($router->router()->getMatchedRoutes());
         $pattern = rtrim($route->getPattern(), '?');
         $method = strtolower(reset($route->getHttpMethods()));
         $routes = $router->getRoutes();
         $handler = $routes[$pattern][$method];
         $before = sprintf('%s::before', $handler);
         if (is_callable($before)) {
             call_user_func($before);
         }
     });
     $router->run();
     $router->hook('slim.after.dispatch', function () use($router) {
         $route = reset($router->router()->getMatchedRoutes());
         $pattern = rtrim($route->getPattern(), '?');
         $method = strtolower(reset($route->getHttpMethods()));
         $routes = $router->getRoutes();
         $handler = $routes[$pattern][$method];
         $after = sprintf('%s::after', $handler);
         if (is_callable($after)) {
             call_user_func($after);
         }
     });
     restoreLanguage();
     return new Trails_Response();
 }
Example #23
0
# Copyright (c)  2008 - Marcus Lunzenauer <*****@*****.**>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# load flexi lib
require_once dirname(__FILE__) . '/../../lib/flexi.php';
# where are the templates
$path_to_the_templates = dirname(__FILE__) . '/templates';
# we need a template factory
$factory = new Flexi_TemplateFactory($path_to_the_templates);
# open template
$template = $factory->open('hello_world');
# set name of the greetee
$template->set_attribute('name', 'Axel');
# render template
echo $template->render();
 /**
  * A textual description of the current rule.
  *
  * @return String
  */
 public function toString()
 {
     $factory = new Flexi_TemplateFactory(dirname(__FILE__) . '/templates/');
     $tpl = $factory->open('info');
     $tpl->set_attribute('rule', $this);
     return $tpl->render();
 }
Example #25
0
# Copyright (c)  2008 - Marcus Lunzenauer <*****@*****.**>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# load flexi lib
require_once dirname(__FILE__) . '/../../lib/flexi.php';
# where are the templates
$path_to_the_templates = dirname(__FILE__) . '/templates';
# we need a template factory
$factory = new Flexi_TemplateFactory($path_to_the_templates);
# open template
$template = $factory->open('js_template');
# set name of the greetee
$template->set_attribute('name', 'Axel');
# render template
echo $template->render();