public function afterStoreCallback()
 {
     if (!$this->material['host_id'] && $this->material['user_id'] !== $GLOBALS['user']->id) {
         PersonalNotifications::add($this->material['user_id'], URLHelper::getURL("plugins.php/lernmarktplatz/market/details/" . $this->material->getId() . "#review_" . $this->getId()), $this->isNew() ? sprintf(_("%s hat ein Review zu '%s' geschrieben."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id']), $this->material['name']) : sprintf(_("%s hat ein Review zu '%s' verändert."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id']), $this->material['name']), "review_" . $this->getId(), Icon::create("support", "clickable"));
     }
     //only push if the comment is from this server and the material-server is different
     if ($this->material['host_id'] && !$this['host_id'] && $this->isDirty()) {
         $remote = new LernmarktplatzHost($this->material['host_id']);
         $myHost = LernmarktplatzHost::thisOne();
         $data = array();
         $data['host'] = array('name' => $myHost['name'], 'url' => $myHost['url'], 'public_key' => $myHost['public_key']);
         $data['data'] = $this->toArray();
         $data['data']['foreign_review_id'] = $data['data']['review_id'];
         unset($data['data']['review_id']);
         unset($data['data']['id']);
         unset($data['data']['user_id']);
         unset($data['data']['host_id']);
         $user_description_datafield = DataField::find(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")) ?: DataField::findOneBySQL("name = ?", array(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")));
         if ($user_description_datafield) {
             $datafield_entry = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($this['user_id'], $user_description_datafield->getId()));
         }
         $data['user'] = array('user_id' => $this['user_id'], 'name' => get_fullname($this['user_id']), 'avatar' => Avatar::getAvatar($this['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null);
         if (!$remote->isMe()) {
             $remote->pushDataToEndpoint("add_review/" . $this->material['foreign_material_id'], $data);
         }
     }
 }
 public function afterStoreCallback()
 {
     if ($this->isDirty()) {
         //add notification to writer of review
         if (!$this->review['host_id'] && $this->review['user_id'] !== $this['user_id']) {
             PersonalNotifications::add($this->review['user_id'], URLHelper::getURL("plugins.php/lernmarktplatz/market/discussion/" . $this['review_id'] . "#comment_" . $this->getId()), sprintf(_("%s hat einen Kommentar zu Ihrem Review geschrieben."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id'])), "comment_" . $this->getId(), Icon::create("support", "clickable"));
         }
         //add notification to all users of this servers who discussed this review but are neither the new
         //commentor nor the writer of the review
         $statement = DBManager::get()->prepare("\n                SELECT user_id\n                FROM lernmarktplatz_comments\n                WHERE review_id = :review_id\n                    AND host_id IS NULL\n                GROUP BY user_id\n            ");
         $statement->execute(array('review_id' => $this->review->getId()));
         foreach ($statement->fetchAll(PDO::FETCH_COLUMN, 0) as $user_id) {
             if (!in_array($user_id, array($this->review['user_id'], $this['user_id']))) {
                 PersonalNotifications::add($user_id, URLHelper::getURL("plugins.php/lernmarktplatz/market/discussion/" . $this['review_id'] . "#comment_" . $this->getId()), sprintf(_("%s hat auch einen Kommentar geschrieben."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id'])), "comment_" . $this->getId(), Icon::create("support", "clickable"));
             }
         }
         //only push if the comment is from this server and the material-server is different
         if (!$this['host_id']) {
             $myHost = LernmarktplatzHost::thisOne();
             $data = array();
             $data['host'] = array('name' => $myHost['name'], 'url' => $myHost['url'], 'public_key' => $myHost['public_key']);
             $data['data'] = $this->toArray();
             $data['data']['foreign_comment_id'] = $data['data']['comment_id'];
             unset($data['data']['comment_id']);
             unset($data['data']['id']);
             unset($data['data']['user_id']);
             unset($data['data']['host_id']);
             $user_description_datafield = DataField::find(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")) ?: DataField::findOneBySQL("name = ?", array(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")));
             if ($user_description_datafield) {
                 $datafield_entry = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($this['user_id'], $user_description_datafield->getId()));
             }
             $data['user'] = array('user_id' => $this['user_id'], 'name' => get_fullname($this['user_id']), 'avatar' => Avatar::getAvatar($this['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null);
             $statement = DBManager::get()->prepare("\n                    SELECT host_id\n                    FROM lernmarktplatz_comments\n                    WHERE review_id = :review_id\n                        AND host_id IS NOT NULL\n                    GROUP BY host_id\n                ");
             $statement->execute(array('review_id' => $this->review->getId()));
             $hosts = $statement->fetchAll(PDO::FETCH_COLUMN, 0);
             if ($this->review['host_id'] && !in_array($this->review['host_id'], $hosts)) {
                 $hosts[] = $this->review['host_id'];
             }
             if ($this->review->material['host_id'] && !in_array($this->review->material['host_id'], $hosts)) {
                 $hosts[] = $this->review->material['host_id'];
             }
             foreach ($hosts as $host_id) {
                 $remote = new LernmarktplatzHost($host_id);
                 if (!$remote->isMe()) {
                     $review_id = $this->review['foreign_review_id'] ?: $this->review->getId();
                     if ($this->review['foreign_review_id']) {
                         if ($this->review->host_id === $remote->getId()) {
                             $host_hash = null;
                         } else {
                             $host_hash = md5($this->review->host['public_key']);
                         }
                     } else {
                         $host_hash = md5($myHost['public_key']);
                     }
                     $remote->pushDataToEndpoint("add_comment/" . $review_id . "/" . $host_hash, $data);
                 }
             }
         }
     }
 }
Esempio n. 3
0
?>
" title="<?php 
echo _("Schreiben Sie einen Kommentar dazu.");
?>
">
                            <?php 
echo Icon::create("comment", "inactive")->asImg(14, array('class' => "text-bottom"));
?>
                        </a>
                        <?php 
echo date("j.n.Y G:i", $review['chdate']);
?>
                    </div>
                    <strong>
                        <? if ($review['host_id']) : ?>
                            <? $user = LernmarktplatzUser::find($review['user_id']) ?>
                            <a href="<?php 
echo PluginEngine::getLink($plugin, array(), "market/profile/" . $user->getId());
?>
">
                                <?php 
echo htmlReady($user->name);
?>
                            </a>
                        <? else : ?>
                            <? $user = new User($review['user_id']) ?>
                            <a href="<?php 
echo URLHelper::getLink("dispatch.php/profile", array('username' => $user['username']));
?>
">
                                <?php 
 public function fetchData()
 {
     if ($this['host_id']) {
         $host = new LernmarktplatzHost($this['host_id']);
         if ($host) {
             $data = $host->fetchItemData($this['foreign_material_id']);
             if (!$data) {
                 return false;
             }
             if ($data['deleted']) {
                 return "deleted";
             }
             //user:
             $user = LernmarktplatzUser::findOneBySQL("foreign_user_id", array($data['user']['user_id'], $host->getId()));
             if (!$user) {
                 $user = new LernmarktplatzUser();
                 $user['foreign_user_id'] = $data['user']['user_id'];
                 $user['host_id'] = $host->getId();
             }
             $user['name'] = $data['user']['name'];
             $user['avatar'] = $data['user']['avatar'] ?: null;
             $user['description'] = $data['user']['description'] ?: null;
             $user->store();
             //material:
             $material_data = $data['data'];
             unset($material_data['material_id']);
             unset($material_data['user_id']);
             unset($material_data['mkdate']);
             $this->setData($material_data);
             $this->store();
             //topics:
             $this->setTopics($data['topics']);
             foreach ((array) $data['reviews'] as $review_data) {
                 $currenthost = LernmarktplatzHost::findOneByUrl(trim($review_data['host']['url']));
                 if (!$currenthost) {
                     $currenthost = new LernmarktplatzHost();
                     $currenthost['url'] = trim($review_data['host']['url']);
                     $currenthost['last_updated'] = time();
                     $currenthost->fetchPublicKey();
                     if ($currenthost['public_key']) {
                         $currenthost->store();
                     }
                 }
                 if ($currenthost && $currenthost['public_key'] && !$currenthost->isMe()) {
                     $review = LernmarktplatzReview::findOneBySQL("foreign_review_id = ? AND host_id = ?", array($review_data['foreign_review_id'], $currenthost->getId()));
                     if (!$review) {
                         $review = new LernmarktplatzReview();
                         $review['foreign_review_id'] = $review_data['foreign_review_id'];
                         $review['material_id'] = $this->getId();
                         $review['host_id'] = $currenthost->getId();
                     }
                     $review['review'] = $review_data['review'];
                     $review['rating'] = $review_data['rating'];
                     if ($review_data['chdate']) {
                         $review['chdate'] = $review_data['chdate'];
                     }
                     if ($review_data['mkdate']) {
                         $review['mkdate'] = $review_data['mkdate'];
                     }
                     $user = LernmarktplatzUser::findOneBySQL("foreign_user_id", array($review_data['user']['user_id'], $currenthost->getId()));
                     if (!$user) {
                         $user = new LernmarktplatzUser();
                         $user['foreign_user_id'] = $review_data['user']['user_id'];
                         $user['host_id'] = $currenthost->getId();
                     }
                     $user['name'] = $review_data['user']['name'];
                     $user['avatar'] = $review_data['user']['avatar'] ?: null;
                     $user['description'] = $review_data['user']['description'] ?: null;
                     $user->store();
                     $review['user_id'] = $user->getId();
                     $review->store();
                 }
             }
         }
     }
     return true;
 }
 public function fetchRemoteSearch($text, $tag = false)
 {
     $endpoint_url = $this['url'] . "search_items";
     if ($tag) {
         $endpoint_url .= "?tag=" . urlencode(studip_utf8encode($text));
     } else {
         $endpoint_url .= "?text=" . urlencode(studip_utf8encode($text));
     }
     $output = @file_get_contents($endpoint_url);
     if ($output) {
         $output = studip_utf8decode(json_decode($output, true));
         foreach ((array) $output['results'] as $material_data) {
             $host = LernmarktplatzHost::findOneBySQL("public_key = ?", array($material_data['host']['public_key']));
             if (!$host) {
                 $host = new LernmarktplatzHost();
                 $host['url'] = $material_data['host']['url'];
                 $host->fetchPublicKey();
                 $host->store();
             }
             if (!$host->isMe()) {
                 //set user:
                 $user = LernmarktplatzUser::findOneBySQL("foreign_user_id", array($material_data['user']['user_id'], $host->getId()));
                 if (!$user) {
                     $user = new LernmarktplatzUser();
                     $user['foreign_user_id'] = $material_data['user']['user_id'];
                     $user['host_id'] = $host->getId();
                 }
                 $user['name'] = $material_data['user']['name'];
                 $user['avatar'] = $material_data['user']['avatar'] ?: null;
                 $user->store();
                 //set material:
                 $material_data['data']['foreign_material_id'] = $material_data['data']['id'];
                 $material = LernmarktplatzMaterial::findOneBySQL("foreign_material_id = ? AND host_id = ?", array($material_data['data']['foreign_material_id'], $host->getId()));
                 if (!$material) {
                     $material = new LernmarktplatzMaterial();
                 }
                 unset($material_data['data']['id']);
                 $material->setData($material_data['data']);
                 $material['host_id'] = $host->getId();
                 $material['user_id'] = $user->getId();
                 $material->store();
                 //set topics:
                 $material->setTopics($material_data['topics']);
             }
         }
     }
 }
Esempio n. 6
0
 /**
  * Adds or edits a comment to the material on this server from a client of another server.
  * Use this request only as a POST request, the body must be a JSON-object that carries all the
  * necessary variables.
  * The review_id is the foreign_review_id if the host_hash is not empty or the review_id if the host_hash is empty.
  * @param $material_id : ID of the item on this server.
  */
 public function add_comment_action($review_id, $host_hash = null)
 {
     if (Request::isPost()) {
         $public_key_hash = $_SERVER['HTTP_' . str_replace("-", "_", strtoupper($GLOBALS['LERNMARKTPLATZ_HEADER_PUBLIC_KEY_HASH']))];
         //MD5_HASH_OF_RSA_PUBLIC_KEY
         $signature = base64_decode($_SERVER['HTTP_' . str_replace("-", "_", strtoupper($GLOBALS['LERNMARKTPLATZ_HEADER_SIGNATURE']))]);
         //BASE64_RSA_SIGNATURE
         $host = LernmarktplatzHost::findOneBySQL("MD5(public_key) = ?", array($public_key_hash));
         if ($host && !$host->isMe()) {
             $body = file_get_contents('php://input');
             if ($host->verifySignature($body, $signature)) {
                 if ($host_hash) {
                     /*$review = LernmarktplatzReview::findOneBySQL("INNER JOIN lernmarktplatz_hosts ON (lernmarktplatz_hosts.host_id = lernmarktplatz_reviews.host_id) WHERE foreign_review_id = :id AND MD5(lernmarktplatz_hosts.public_key) = :host_hash", array(
                           'id' => $review_id,
                           'host_hash' => $host_hash
                       ));*/
                     $review = LernmarktplatzReview::findOneByForeign_review_id($review_id);
                 } else {
                     $review = LernmarktplatzReview::find($review_id);
                 }
                 if (!$review) {
                     throw new Exception("Unknown material.");
                 }
                 $data = studip_utf8decode(json_decode($body, true));
                 $user = LernmarktplatzUser::findOneBySQL("host_id = ? AND foreign_user_id = ?", array($host->getId(), $data['user']['user_id']));
                 if (!$user) {
                     $user = new LernmarktplatzUser();
                     $user['host_id'] = $host->getId();
                     $user['foreign_user_id'] = $data['user']['user_id'];
                 }
                 $user['name'] = $data['user']['name'];
                 $user['avatar'] = $data['user']['avatar'];
                 $user['description'] = $data['user']['description'] ?: null;
                 $user->store();
                 $comment = new LernmarktplatzComment();
                 $comment['user_id'] = $user->getId();
                 $comment['foreign_comment_id'] = $data['data']['foreign_comment_id'];
                 $comment['host_id'] = $host->getId();
                 $comment['review_id'] = $review->getId();
                 $comment['comment'] = $data['data']['comment'];
                 $comment['mkdate'] = $data['data']['mkdate'];
                 $comment['chdate'] = $data['data']['chdate'];
                 $comment->store();
                 echo "stored ";
             } else {
                 throw new Exception("Wrong signature, sorry.");
             }
         }
         $this->render_text("");
     } else {
         throw new Exception("USE POST TO PUSH.");
     }
 }
Esempio n. 7
0
<li id="comment_<?php 
echo $comment->getId();
?>
" class="review">
    <div class="avatar">
        <img width="50px" height="50px" src="<?php 
echo htmlReady($comment['host_id'] ? LernmarktplatzUser::find($comment['user_id'])->avatar : Avatar::getAvatar($comment['user_id'])->getURL(Avatar::MEDIUM));
?>
">
    </div>
    <div class="content">
        <div class="timestamp">
            <?php 
echo date("j.n.Y G:i", $comment['chdate']);
?>
        </div>
        <strong><?php 
echo htmlReady($comment['host_id'] ? LernmarktplatzUser::find($comment['user_id'])->name : get_fullname($comment['user_id']));
?>
</strong>
        <span class="origin">(<?php 
echo htmlReady($comment['host_id'] ? $comment->host['name'] : $GLOBALS['UNI_NAME_CLEAN']);
?>
)</span>
        <div class="review_text">
            <?php 
echo formatReady($comment['comment']);
?>
        </div>
    </div>
</li>
Esempio n. 8
0
<a href="<?php 
echo PluginEngine::getLink($plugin, array(), "market/details/" . $review['material_id']);
?>
">
    <?php 
echo Icon::create("arr_1left", "clickable")->asImg("20px", array('class' => "text-bottom"));
?>
    <?php 
echo _("Zurück");
?>
</a>

<div class="mainreview">
    <div style="margin-bottom: 10px;">
        <img width="50px" height="50px" src="<?php 
echo htmlReady($review['host_id'] ? LernmarktplatzUser::find($review['user_id'])->avatar : Avatar::getAvatar($review['user_id'])->getURL(Avatar::MEDIUM));
?>
" style="vertical-align: middle;">
        <span class="stars" style="vertical-align: middle;">
            <? $rating = round($review['rating'], 1) ?>
            <? $v = $rating >= 0.75 ? 3 : ($rating >= 0.25 ? 2 : "") ?>
            <?php 
echo Icon::create($plugin->getPluginURL() . "/assets/star{$v}.svg")->asImg(25);
?>
            <? $v = $rating >= 1.75 ? 3 : ($rating >= 1.25 ? 2 : "") ?>
            <?php 
echo Icon::create($plugin->getPluginURL() . "/assets/star{$v}.svg")->asImg(25);
?>
            <? $v = $rating >= 2.75 ? 3 : ($rating >= 2.25 ? 2 : "") ?>
            <?php 
echo Icon::create($plugin->getPluginURL() . "/assets/star{$v}.svg")->asImg(25);