Esempio n. 1
0
 function test_nobody_path()
 {
     $path = Avatar::getNobody()->getCustomAvatarPath(Avatar::NORMAL);
     $this->assertEquals("/dynamic/user/nobody_normal.png", $path);
 }
Esempio n. 2
0
function head (&$module, $data, $a) {
    if ($module->config->getValue("Main", "showcontact")
            && $module->config->getValue("Main", "showimage"))
        $colspan = " colspan=\"2\"";
    else
        $colspan = "";

    echo "<tr><td width=\"100%\">\n";
    echo "<table" . $module->config->getAttributes("PersondetailsHeader", "table") . ">\n";
    if (!$module->config->getValue('PersondetailsHeader', 'hidename')) {
        echo "<tr" . $module->config->getAttributes("PersondetailsHeader", "tr") . ">";
        echo "<td$colspan width=\"100%\"";
        echo $module->config->getAttributes("PersondetailsHeader", "headlinetd") . ">";
        echo "<font" . $module->config->getAttributes("PersondetailsHeader", "font") . ">";
        echo $data["fullname"];
        echo "</font></td></tr>\n";
    }

    if ($module->config->getValue("Main", "showimage")
            || $module->config->getValue("Main", "showcontact")) {
        echo "<tr>";
        if ($module->config->getValue("Main", "showcontact")
                && ($module->config->getValue("Main", "showimage") == "right"
                || !$module->config->getValue("Main", "showimage"))) {
                echo "<td" . $module->config->getAttributes("PersondetailsHeader", "contacttd") . ">";
                echo kontakt($module, $data) . "</td>\n";
        }

        if ($module->config->getValue("Main", "showimage")) {
            echo "<td" . $module->config->getAttributes("PersondetailsHeader", "picturetd") . ">";
            echo "<img src=\"".Avatar::getNobody()->getUrl(Avatar::NORMAL)."\" alt=\"Foto " . $data["fullname"] . "\"";
            echo $module->config->getAttributes("PersondetailsHeader", "img") . ">";
        }

        if ($module->config->getValue("Main", "showcontact")
                && $module->config->getValue("Main", "showimage") == "left") {
            echo "<td" . $module->config->getAttributes("PersondetailsHeader", "contacttd") . ">";
            echo kontakt($module, $data) . "</td>\n";
        }

        echo "</tr>\n";
        if ($module->config->getValue('Main', 'showcontact')
                && $module->config->getValue('Contact', 'separatelinks')) {
            echo "<tr><td";
            if ($module->config->getValue('Main', 'showimage'))
                echo ' colspan="2"';
            echo $module->config->getAttributes('PersondetailsHeader', 'contacttd') . ">\n";
            echo kontakt($module, $data, TRUE);
            echo "</td></tr>\n";
        }
    }

    echo "</table>\n</td></tr>\n";
}
Esempio n. 3
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."));
     }
 }
    function getContent ($args = NULL, $raw = FALSE) {
        if ($raw) {
            $this->setRawOutput();
        }

        if (!$all_groups = get_all_statusgruppen($this->config->range_id)) {
            die($GLOBALS["EXTERN_ERROR_MESSAGE"]);
        } else {
            $all_groups = array_keys($all_groups);
        }

        if (!$group_ids = $this->config->getValue('Main', 'groupsvisible')) {
            die($GLOBALS["EXTERN_ERROR_MESSAGE"]);
        } else {
            $group_ids = array_intersect($all_groups, $group_ids);
        }

        if (!is_array($group_ids)) {
            die($GLOBALS["EXTERN_ERROR_MESSAGE"]);
        }

        if (!$visible_groups = get_statusgruppen_by_id($this->config->range_id, $group_ids)) {
            die($GLOBALS["EXTERN_ERROR_MESSAGE"]);
        }

        $sort = $this->config->getValue('Main', 'sort');
        $query_order = '';
        foreach ($sort as $key => $position) {
            if ($position > 0) {
                $query_order[$position] = $this->data_fields[$key];
            }
        }
        if ($query_order) {
            ksort($query_order, SORT_NUMERIC);
            $query_order = ' ORDER BY ' . implode(',', $query_order);
        }

        $grouping = $this->config->getValue("Main", "grouping");
        if (!$nameformat = $this->config->getValue('Main', 'nameformat')) {
            $nameformat = 'full_rev';
        }

        if(!$grouping) {
            $query = "SELECT DISTINCT ui.raum, ui.sprechzeiten, ui.Telefon, inst_perms, Email, aum.user_id, ";
            $query .= 'username, aum.Vorname, title_front, title_rear, ';
            $query .= $GLOBALS['_fullname_sql'][$nameformat] . " AS fullname, aum.Nachname ";
            if ($query_order != '') {
                $query .= "FROM statusgruppe_user LEFT JOIN auth_user_md5 aum USING(user_id) ";
                $query .= "LEFT JOIN user_info USING(user_id) LEFT JOIN user_inst ui USING(user_id) ";
                $query .= "WHERE statusgruppe_id IN (?) AND Institut_id = ? AND ".get_ext_vis_query()."$query_order";
            } else {
                $query .= "FROM statusgruppen s LEFT JOIN statusgruppe_user su USING(statusgruppe_id) ";
                $query .= "LEFT JOIN auth_user_md5 aum USING(user_id) ";
                $query .= "LEFT JOIN user_info USING(user_id) LEFT JOIN user_inst ui USING(user_id) ";
                $query .= "WHERE su.statusgruppe_id IN (?) AND Institut_id = ? ";
                $query .= "' AND ".get_ext_vis_query()." ORDER BY ";
                $query .= "s.position ASC, su.position ASC";
            }
            $parameters = array($this->config->getValue('Main', 'groupsvisible'), $this->config->range_id);
            $statement = DBManager::get()->prepare($query);
            $statement->execute($parameters);
            $row = $statement->fetch(PDO::FETCH_ASSOC);
            $visible_groups = array('');
        }

        // generic data fields
        $generic_datafields = $this->config->getValue('TemplateGeneric', 'genericdatafields');

        $data['data_fields'] = $this->data_fields;
        $defaultaddress = $this->config->getValue('Main', 'defaultadr');
        if (! $defaultaddress) {
           $db_out =& $row;
        }

        $content = null;
        $i = 0;
        $aliases_groups = $this->config->getValue('Main', 'groupsalias');
        foreach ($visible_groups as $group_id => $group) {
            if ($grouping) {
                if ($query_order == '') {
                    $query_order = ' ORDER BY su.position';
                }
                $query = 'SELECT ui.raum, ui.sprechzeiten, ui.Telefon, inst_perms, Email, aum.user_id, ';
                $query .= 'username, aum.Vorname, title_front, title_rear, ';
                $query .= $GLOBALS['_fullname_sql'][$nameformat] . " AS fullname, aum.Nachname ";
                $query .= 'FROM statusgruppe_user su LEFT JOIN auth_user_md5 aum USING(user_id) ';
                $query .= 'LEFT JOIN user_info USING(user_id) LEFT JOIN user_inst ui USING(user_id) ';
                $query .= "WHERE su.statusgruppe_id = ? AND ".get_ext_vis_query()." AND Institut_id = ? $query_order";

                $parameters = array($group_id, $this->config->range_id );
                $statement = DBManager::get()->prepare($query);
                $statement->execute($parameters);
                $row = $statement->fetch(PDO::FETCH_ASSOC);

                if($aliases_groups[$group_id]) {
                    $group = $aliases_groups[$group_id];
                }
            }


            if ($row !== false) {
                if($aliases_groups[$group_id]) {
                    $content['PERSONS']['GROUP'][$i]['GROUPTITLE-SUBSTITUTE'] = ExternModule::ExtHtmlReady($aliases_groups[$group_id]);
                }
                $content['PERSONS']['GROUP'][$i]['GROUPTITLE'] = ExternModule::ExtHtmlReady($group);
                $content['PERSONS']['GROUP'][$i]['GROUP-NO'] = $i + 1;

                $j = 0;
                do{
                    $visibilities = get_local_visibility_by_id($row['user_id'], 'homepage', true);
                    $user_perm = $visibilities['perms'];
                    $visibilities = json_decode($visibilities['homepage'], true);

                    if ($defaultaddress) {
                        $query = 'SELECT ui.raum, ui.sprechzeiten, ui.Telefon, inst_perms,  Email, ';
                        $query .= 'title_front, title_rear, ';
                        $query .= 'aum.user_id, username, ' . $GLOBALS['_fullname_sql'][$nameformat];
                        $query .= ' AS fullname, aum.Nachname, aum.Vorname FROM auth_user_md5 aum LEFT JOIN ';
                        $query .= 'user_info USING(user_id) LEFT JOIN ';
                        $query .= "user_inst ui USING(user_id) WHERE aum.user_id = '" . $row['user_id'];
                        $query .= "' AND ".get_ext_vis_query().' AND externdefault = 1';

                        $statement2 = DBManager::get()->prepare($query);
                        $statement2->execute();
                        $db_out = $statement2->fetch(PDO::FETCH_ASSOC);
                        //no default
                        if ($db_out === false) {
                            $query = 'SELECT ui.raum, ui.sprechzeiten, ui.Telefon, inst_perms,  Email, ';
                            $query .= 'title_front, title_rear, ';
                            $query .= 'aum.user_id, username, ' . $GLOBALS['_fullname_sql'][$nameformat];
                            $query .= ' AS fullname, aum.Nachname, aum.Vorname FROM auth_user_md5 aum LEFT JOIN ';
                            $query .= 'user_info USING(user_id) LEFT JOIN ';
                            $query .= "user_inst ui USING(user_id) WHERE aum.user_id = '" . $row['user_id'];
                            $query .= "' AND ".get_ext_vis_query()." AND Institut_id = ? " ;
                            $statement2 = DBManager::get()->prepare($query);
                            $params = array($this->config->range_id);
                            $statement2->execute($params);
                            $db_out = $statement2->fetch(PDO::FETCH_ASSOC);
                        }
                    }
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['FULLNAME'] = ExternModule::ExtHtmlReady($db_out['fullname']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['LASTNAME'] = ExternModule::ExtHtmlReady($db_out['Nachname']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['FIRSTNAME'] = ExternModule::ExtHtmlReady($db_out['Vorname']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['TITLEFRONT'] = ExternModule::ExtHtmlReady($db_out['title_front']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['TITLEREAR'] = ExternModule::ExtHtmlReady($db_out['title_rear']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['PERSONDETAIL-HREF'] = $this->elements['LinkInternTemplate']->createUrl(array('link_args' => 'username='******'username']));
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['USERNAME'] = $db_out['username'];

                    if (is_element_visible_externally( $row['user_id'], $user_perm, 'picture', $visibilities['picture'])) {
                        $avatar = Avatar::getAvatar($db_out['user_id']);
                    } else {
                        $avatar = Avatar::getNobody();
                    }
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['IMAGE-URL-SMALL'] = $avatar->getURL(Avatar::SMALL);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['IMAGE-URL-MEDIUM'] = $avatar->getURL(Avatar::MEDIUM);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['IMAGE-URL-NORMAL'] = $avatar->getURL(Avatar::NORMAL);

                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['PHONE'] = ExternModule::ExtHtmlReady($db_out['Telefon']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['ROOM'] = ExternModule::ExtHtmlReady($db_out['raum']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['EMAIL'] = get_visible_email($row['user_id']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['EMAIL-LOCAL'] = array_shift(explode('@', $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['EMAIL']));
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['EMAIL-DOMAIN'] = array_pop(explode('@', $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['EMAIL']));
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['OFFICEHOURS'] = ExternModule::ExtHtmlReady($db_out['sprechzeiten']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['PERSON-NO'] = $j + 1;

                    // generic data fields
                    if (is_array($generic_datafields)) {
                        $localEntries = DataFieldEntry::getDataFieldEntries($db_out['user_id'], 'user');
                        #$datafields = $datafields_obj->getLocalFields($db_out->f('user_id'));
                        $k = 1;
                        foreach ($generic_datafields as $datafield) {
                            if (isset($localEntries[$datafield]) &&
                                    is_object($localEntries[$datafield] &&
                                    is_element_visible_externally($db_out['user_id'],
                                        $user_perm, $localEntries[$datafield]->getId(),
                                        $visibilities[$localEntries[$datafield]->getId()]))) {
                                if ($localEntries[$datafield]->getType() == 'link') {
                                    $localEntry = ExternModule::extHtmlReady($localEntries[$datafield]->getValue());
                                } else {
                                    $localEntry = $localEntries[$datafield]->getDisplayValue();
                                }
                                if ($localEntry) {
                                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['DATAFIELD_' . $k] = $localEntry;
                                }
                            }
                            $k++;
                        }
                    }
                    $j++;
                }while ($row = $statement->fetch(PDO::FETCH_ASSOC));
            }
            $i++;
        }

        return $content;
    }