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);
                 }
             }
         }
     }
 }
예제 #3
0
 public function hosts_action()
 {
     //init
     LernmarktplatzHost::thisOne();
     $this->hosts = LernmarktplatzHost::findAll();
     foreach ($this->hosts as $host) {
         if (strpos($host['public_key'], "\r") !== false) {
             $host['public_key'] = str_replace("\r", "", $host['public_key']);
             $host->store();
         }
     }
     if (!function_exists("curl_init")) {
         PageLayout::postMessage(MessageBox::error(_("Ihr PHP hat kein aktiviertes cURL-Modul.")));
     }
     $plugin = PluginManager::getInstance()->getPluginInfo(get_class($this->plugin));
     $plugin_roles = RolePersistence::getAssignedPluginRoles($plugin['id']);
     $nobody_allowed = false;
     foreach ($plugin_roles as $role) {
         if (strtolower($role->rolename) === "nobody") {
             $nobody_allowed = true;
         }
     }
     if (!$nobody_allowed) {
         PageLayout::postMessage(MessageBox::error(_("Dieses Plugin ist nicht für nobody freigegeben. Damit kann sich dieser Marktplatz nicht mit anderen Stud.IP verbinden.")));
     }
     //zufällig einen Host nach Neuigkeiten fragen:
     if (count($this->hosts) > 1) {
         $index = rand(0, count($this->hosts) - 1);
         while ($this->hosts[$index]->isMe()) {
             $index++;
             if ($index >= count($this->hosts)) {
                 $index = 0;
             }
         }
         $this->askForHosts($this->hosts[$index]);
     }
 }
예제 #4
0
            <td><?php 
echo _("MD5-Hash");
?>
</td>
            <td><?php 
echo md5(LernmarktplatzHost::thisOne()->public_key);
?>
</td>
        </tr>
        <tr>
            <td><?php 
echo _("Key");
?>
</td>
            <td><?php 
echo nl2br(htmlReady(LernmarktplatzHost::thisOne()->public_key));
?>
</td>
        </tr>
    </tbody>
</table>


<h2><?php 
echo _("Statistik");
?>
</h2>
<table class="default nohover">
    <tr>
        <td><?php 
echo _("Anzahl verbundener Server");
 public function pushDataToIndexServers($delete = false)
 {
     $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_material_id'] = $data['data']['material_id'];
     unset($data['data']['material_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);
     $data['topics'] = array();
     foreach ($this->getTopics() as $tag) {
         if ($tag['name']) {
             $data['topics'][] = $tag['name'];
         }
     }
     if ($delete) {
         $data['delete_material'] = 1;
     }
     foreach (LernmarktplatzHost::findBySQL("index_server = '1' AND allowed_as_index_server = '1' ") as $index_server) {
         if (!$index_server->isMe()) {
             echo " push ";
             $index_server->pushDataToEndpoint("push_data", $data);
         }
     }
 }
 public function pushDataToEndpoint($endpoint, $data, $curl_multi_request = false)
 {
     $data = studip_utf8encode($data);
     $payload = json_encode($data);
     $myHost = LernmarktplatzHost::thisOne();
     $endpoint_url = $this['url'] . $endpoint;
     $request = curl_init();
     curl_setopt($request, CURLOPT_URL, $endpoint_url);
     curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($request, CURLOPT_VERBOSE, 0);
     curl_setopt($request, CURLOPT_CONNECTTIMEOUT, 5);
     curl_setopt($request, CURLOPT_POST, true);
     curl_setopt($request, CURLOPT_POSTFIELDS, $payload);
     curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($request, CURLOPT_SSL_VERIFYHOST, false);
     $header = array($GLOBALS['LERNMARKTPLATZ_HEADER_SIGNATURE'] . ": " . base64_encode($myHost->createSignature($payload)), $GLOBALS['LERNMARKTPLATZ_HEADER_PUBLIC_KEY_HASH'] . ": " . md5($myHost['public_key']));
     curl_setopt($request, CURLOPT_HTTPHEADER, $header);
     if ($curl_multi_request) {
         return $request;
     } else {
         $result = curl_exec($request);
         $response_code = curl_getinfo($request, CURLINFO_HTTP_CODE);
         curl_close($request);
         return $response_code < 300;
     }
 }
예제 #7
0
 /**
  * Returns data of a given item including where to download it and the structure, decription, etc.
  * If item is not hosted on this server, just relocate the request to the real server.
  *
  * This endpoint should be called by a remote whenever a client wants to view the details of an item.
  *
  * @param $item_id : ID of the item on this server.
  */
 public function get_item_data_action($item_id)
 {
     $material = new LernmarktplatzMaterial($item_id);
     if ($material->isNew()) {
         $this->render_json(array('deleted' => 1));
     } elseif (!$material['foreign_material_id']) {
         $me = LernmarktplatzHost::thisOne();
         $topics = array();
         foreach ($material->getTopics() as $topic) {
             $topics[] = $topic['name'];
         }
         $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($material['user_id'], $user_description_datafield->getId()));
         }
         $reviews = array();
         foreach ($material->reviews as $review) {
             if ($review['host_id']) {
                 $user = LernmarktplatzUser::findOneBySQL("user_id = ?", array($review['user_id']));
                 $user = array('user_id' => $review['user_id'], 'name' => $user['name'], 'avatar' => $user['avatar'], 'description' => $user['description']);
             } else {
                 if ($user_description_datafield) {
                     $user_description = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($review['user_id'], $user_description_datafield->getId()));
                 }
                 $user = array('user_id' => $review['user_id'], 'name' => get_fullname($review['user_id']), 'avatar' => Avatar::getAvatar($review['user_id'])->getURL(Avatar::NORMAL), 'description' => $user_description['content'] ?: null);
             }
             $reviews[] = array('foreign_review_id' => $review['foreign_review_id'] ?: $review->getId(), 'review' => $review['review'], 'rating' => $review['rating'], 'user' => $user, 'host' => array('name' => $review['host_id'] ? $review->host['name'] : $me['name'], 'url' => $review['host_id'] ? $review->host['url'] : $me['url'], 'public_key' => $review['host_id'] ? $review->host['public_key'] : $me['public_key']), 'mkdate' => $review['mkdate'], 'chkdate' => $review['chdate']);
         }
         $this->render_json(array('data' => array('name' => $material['name'], 'short_description' => $material['short_description'], 'description' => $material['description'], 'content_type' => $material['content_type'], 'front_image_content_type' => $material['front_image_content_type'], 'url' => ($GLOBALS['LERNMARKTPLATZ_PREFERRED_URI'] ?: $GLOBALS['ABSOLUTE_URI_STUDIP']) . "/plugins.php/lernmarktplatz/market/download/" . $item_id, 'structure' => $material['structure'], 'license' => $material['license']), 'user' => array('user_id' => $material['user_id'], 'name' => User::find($material['user_id'])->getFullName(), 'avatar' => Avatar::getAvatar($material['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null), 'topics' => $topics, 'reviews' => $reviews));
     } else {
         $host = new LernmarktplatzHost($material['host_id']);
         header("Location: " . $host['url'] . "get_item_data/" . $item_id);
         return;
     }
 }