/**
  * @expectedException \Exception
  */
 public function testMisformatedJSON()
 {
     $request = $this->getMockBuilder('\\Kanedo\\Request')->disableOriginalConstructor()->getMock();
     $testee = new Bookmark($request);
     $json = "{this is wroooong: lols'}";
     $testee->setUp($json);
 }
Esempio n. 2
0
 public function testGetsUrl()
 {
     $url = $this->getUrlMock();
     $comment = $this->getBookmarkCommentMock();
     $date = new DateTimeImmutable();
     $bookmark = new Bookmark($url, $comment, $date);
     $this->assertEquals($url, $bookmark->getWebsite());
 }
Esempio n. 3
0
 /**
  * Creates a new bookmark
  * @param $type
  * @param $object_id   the object who owns the bookmark
  * @param $owner       if not set, owner will be current user
  * @return bookmark id
  */
 public static function create($type, $object_id, $owner = 0)
 {
     $session = SessionHandler::getInstance();
     $o = new Bookmark();
     $o->type = $type;
     $o->value = $object_id;
     $o->owner = $owner ? $owner : $session->id;
     return $o->store();
 }
Esempio n. 4
0
 /**
  * Add or Delete Bookmark.
  */
 public function addDel($postId)
 {
     $row = Bookmark::model()->find('postId=:postId and userId=:userId', array(':postId' => $postId, ':userId' => Yii::app()->user->id));
     if (empty($row)) {
         $row = new Bookmark();
         $row->postId = $postId;
         $row->userId = Yii::app()->user->id;
         $row->save();
         return true;
     } else {
         $row->delete();
         return false;
     }
 }
Esempio n. 5
0
 /**
  * Show a date selector
  * @param  datetime $date1    date of start
  * @param  datetime $date2    date of ending
  * @param  string $randname random string (to prevent conflict in js selection)
  * @return nothing
  */
 static function showSelector($date1, $date2, $randname)
 {
     $request_string = self::getRequestString($_GET);
     echo "<div class='center'><form method='POST' action='?{$request_string}' name='form'" . " id='mreporting_date_selector'>\n";
     echo "<table class='tab_cadre'><tr class='tab_bg_1'>";
     echo '<td><table><tr class="tab_bg_1">';
     echo "<td>";
     Html::showDateFormItem("date1" . $randname, $date1, false);
     echo "</td>\n";
     echo "<td>";
     Html::showDateFormItem("date2" . $randname, $date2, false);
     echo "</td>\n";
     self::getReportSelectors();
     echo "</tr></table></td>";
     echo "<td rowspan='2' class='center'>";
     echo "<input type='submit' class='button' name='submit' Value=\"" . _sx('button', 'Post') . "\">";
     echo "</td>\n";
     echo "<td class='center'>";
     $_SERVER['REQUEST_URI'] .= "&date1" . $randname . "=" . $date1;
     $_SERVER['REQUEST_URI'] .= "&date2" . $randname . "=" . $date2;
     Bookmark::showSaveButton(Bookmark::URI);
     echo "</td>\n";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>\n";
 }
Esempio n. 6
0
 function showContent()
 {
     $notice = $this->nli->notice;
     $out = $this->nli->out;
     $nb = Bookmark::getByNotice($notice);
     if (empty($nb)) {
         common_log(LOG_ERR, "No bookmark for notice {$notice->id}");
         parent::showContent();
         return;
     } else {
         if (empty($nb->url)) {
             common_log(LOG_ERR, "No url for bookmark {$nb->id} for notice {$notice->id}");
             parent::showContent();
             return;
         }
     }
     $profile = $notice->getProfile();
     $out->elementStart('p', array('class' => 'entry-content'));
     // Whether to nofollow
     $attrs = array('href' => $nb->url, 'class' => 'bookmark-title');
     $nf = common_config('nofollow', 'external');
     if ($nf == 'never' || ($nf == 'sometimes' and $out instanceof ShowstreamAction)) {
         $attrs['rel'] = 'external';
     } else {
         $attrs['rel'] = 'nofollow external';
     }
     $out->elementStart('h3');
     $out->element('a', $attrs, $nb->title);
     $out->elementEnd('h3');
     // Replies look like "for:" tags
     $replies = $notice->getReplies();
     $tags = $notice->getTags();
     if (!empty($replies) || !empty($tags)) {
         $out->elementStart('ul', array('class' => 'bookmark-tags'));
         foreach ($replies as $reply) {
             $other = Profile::staticGet('id', $reply);
             if (!empty($other)) {
                 $out->elementStart('li');
                 $out->element('a', array('rel' => 'tag', 'href' => $other->profileurl, 'title' => $other->getBestName()), sprintf('for:%s', $other->nickname));
                 $out->elementEnd('li');
                 $out->text(' ');
             }
         }
         foreach ($tags as $tag) {
             $tag = trim($tag);
             if (!empty($tag)) {
                 $out->elementStart('li');
                 $out->element('a', array('rel' => 'tag', 'href' => Notice_tag::url($tag)), $tag);
                 $out->elementEnd('li');
                 $out->text(' ');
             }
         }
         $out->elementEnd('ul');
     }
     if (!empty($nb->description)) {
         $out->element('p', array('class' => 'bookmark-description'), $nb->description);
     }
     $out->elementEnd('p');
 }
Esempio n. 7
0
 protected function beforeSave()
 {
     $folderModel = Folder::model()->findByPk($this->folder_id);
     $existingBookmarkModel = Bookmark::model()->findSingleByAttributes(array('user_id' => \GO::user()->id, 'folder_id' => $folderModel->id));
     if (!empty($existingBookmarkModel)) {
         throw new \Exception(str_replace('%fn', $folderModel->name, \GO::t('bookmarkAlreadyExists', 'files')));
     }
     return parent::beforeSave();
 }
 /**
  * Handle the data
  *
  * @param array $data associative array of user & bookmark info from DeliciousBackupImporter::importBookmark()
  *
  * @return boolean success value
  */
 function handle($data)
 {
     $profile = Profile::staticGet('id', $data['profile_id']);
     try {
         $saved = Bookmark::saveNew($profile, $data['title'], $data['url'], $data['tags'], $data['description'], array('created' => $data['created'], 'distribute' => false));
     } catch (ClientException $e) {
         // Most likely a duplicate -- continue on with the rest!
         common_log(LOG_ERR, "Error importing delicious bookmark to {$data['url']}: " . $e->getMessage());
         return true;
     }
     return true;
 }
Esempio n. 9
0
 public function actionSet()
 {
     $book_id = (int) $_POST["book_id"];
     $orig_id = (int) $_POST["orig_id"];
     $pk = array("user_id" => Yii::app()->user->id, "book_id" => $book_id);
     if ($orig_id) {
         $pk["orig_id"] = $orig_id;
     }
     $bm = Bookmark::model()->findByAttributes($pk);
     if (!$bm) {
         $bm = new Bookmark();
         $bm->user_id = Yii::app()->user->id;
         $bm->book_id = $book_id;
         if ($orig_id) {
             $bm->orig_id = $orig_id;
         }
     }
     if (isset($_POST["note"])) {
         $post = $_POST;
         unset($post["book_id"]);
         unset($post["orig_id"]);
         $bm->setAttributes($post);
         $bm->watch = (int) $_POST["watch"];
         $new_ord = Yii::app()->db->createCommand("SELECT MAX(ord) FROM bookmarks WHERE user_id = :user_id AND orig_id IS NULL")->queryScalar(array(":user_id" => Yii::app()->user->id)) + 1;
         if ($orig_id) {
             // А есть ли закладка на перевод?
             if (!Yii::app()->db->createCommand("SELECT 1 FROM bookmarks WHERE user_id = :user_id AND book_id = :book_id AND orig_id IS NULL")->queryScalar(array(":user_id" => Yii::app()->user->id, ":book_id" => $book_id))) {
                 Yii::app()->db->createCommand("INSERT INTO bookmarks (user_id, book_id, ord) VALUES (:user_id, :book_id, :ord)")->execute(array(":user_id" => Yii::app()->user->id, ":book_id" => $book_id, ":ord" => $new_ord));
             }
         } else {
             $bm->ord = $new_ord;
         }
         if (!$bm->save()) {
             throw new CHttpException(500, $bm->getErrorsString());
         }
         echo json_encode(array("book_id" => (int) $bm->book_id, "orig_id" => (int) $bm->orig_id, "note" => $bm->note, "status" => "set"));
     } else {
         $this->renderPartial("set", array("bm" => $bm));
     }
 }
Esempio n. 10
0
 /**
  * This test case demonstrates an issue with the identity case in the
  * Doctrine_Table class.  The brief summary is that if you create a
  * record, then delete it, then create another record with the same
  * primary keys, the record can get into a state where it is in the
  * database but may appear to be marked as TCLEAN under certain
  * circumstances (such as when it comes back as part of a collection).
  * This makes the $record->exists() method return false, which prevents
  * the record from being deleted among other things.
  */
 public function testIdentityMapAndRecordStatus()
 {
     // load our user and our collection of pages
     $user = Doctrine_Query::create()->query('SELECT * FROM BookmarkUser u WHERE u.name=?', array('Anonymous'))->getFirst();
     $pages = Doctrine_Query::create()->query('SELECT * FROM Page');
     // bookmark the pages (manually)
     foreach ($pages as $page) {
         $bookmark = new Bookmark();
         $bookmark['page_id'] = $page['id'];
         $bookmark['user_id'] = $user['id'];
         $bookmark->save();
     }
     // select all bookmarks
     $bookmarks = Doctrine_Manager::connection()->query('SELECT * FROM Bookmark b');
     $this->assertEqual(count($bookmarks), 1);
     // verify that they all exist
     foreach ($bookmarks as $bookmark) {
         $this->assertTrue($bookmark->exists());
     }
     // now delete them all.
     $user['Bookmarks']->delete();
     // verify count when accessed directly from database
     $bookmarks = Doctrine_Query::create()->query('SELECT * FROM Bookmark');
     $this->assertEqual(count($bookmarks), 0);
     // now recreate bookmarks and verify they exist:
     foreach ($pages as $page) {
         $bookmark = new Bookmark();
         $bookmark['page_id'] = $page['id'];
         $bookmark['user_id'] = $user['id'];
         $bookmark->save();
     }
     // select all bookmarks for the user
     $bookmarks = Doctrine_Manager::connection()->query('SELECT * FROM Bookmark b');
     $this->assertEqual(count($bookmarks), 1);
     // verify that they all exist
     foreach ($bookmarks as $bookmark) {
         $this->assertTrue($bookmark->exists());
     }
 }
Esempio n. 11
0
 /**
  * Add a new bookmark
  *
  * @return void
  */
 function handlePost()
 {
     if (empty($this->title)) {
         // TRANS: Client exception thrown when trying to create a new bookmark without a title.
         throw new ClientException(_m('Bookmark must have a title.'));
     }
     if (empty($this->url)) {
         // TRANS: Client exception thrown when trying to create a new bookmark without a URL.
         throw new ClientException(_m('Bookmark must have an URL.'));
     }
     $options = array();
     ToSelector::fillOptions($this, $options);
     $saved = Bookmark::addNew($this->scoped, $this->title, $this->url, $this->tags, $this->description, $options);
 }
 function showContent()
 {
     $notice = $this->nli->notice;
     $out = $this->nli->out;
     $out->elementStart('p', array('class' => 'entry-content'));
     $nb = Bookmark::getByNotice($notice);
     $profile = $notice->getProfile();
     $atts = $notice->attachments();
     if (count($atts) < 1) {
         // Something wrong; let default code deal with it.
         // TRANS: Exception thrown when a bookmark has no attachments.
         // TRANS: %1$s is a bookmark ID, %2$s is a notice ID (number).
         throw new Exception(sprintf(_m('Bookmark %1$s (notice %2$d) has no attachments.'), $nb->id, $notice->id));
     }
     $att = $atts[0];
     $out->elementStart('h3');
     $out->element('a', array('href' => $att->url, 'class' => 'bookmark-title'), $nb->title);
     $out->elementEnd('h3');
     // Replies look like "for:" tags
     $replies = $notice->getReplies();
     $tags = $notice->getTags();
     if (!empty($replies) || !empty($tags)) {
         $out->elementStart('ul', array('class' => 'bookmark-tags'));
         foreach ($replies as $reply) {
             $other = Profile::staticGet('id', $reply);
             if (!empty($other)) {
                 $out->elementStart('li');
                 $out->element('a', array('rel' => 'tag', 'href' => $other->profileurl, 'title' => $other->getBestName()), sprintf('for:%s', $other->nickname));
                 $out->elementEnd('li');
                 $out->text(' ');
             }
         }
         foreach ($tags as $tag) {
             $tag = trim($tag);
             if (!empty($tag)) {
                 $out->elementStart('li');
                 $out->element('a', array('rel' => 'tag', 'href' => Notice_tag::url($tag)), $tag);
                 $out->elementEnd('li');
                 $out->text(' ');
             }
         }
         $out->elementEnd('ul');
     }
     if (!empty($nb->description)) {
         $out->element('p', array('class' => 'bookmark-description'), $nb->description);
     }
     $out->elementEnd('p');
 }
Esempio n. 13
0
 function getNotice()
 {
     $this->id = $this->trimmed('id');
     $this->bookmark = Bookmark::staticGet('id', $this->id);
     if (empty($this->bookmark)) {
         // TRANS: Client exception thrown when referring to a non-existing bookmark.
         throw new ClientException(_m('No such bookmark.'), 404);
     }
     $notice = Notice::staticGet('uri', $this->bookmark->uri);
     if (empty($notice)) {
         // Did we used to have it, and it got deleted?
         // TRANS: Client exception thrown when referring to a non-existing bookmark.
         throw new ClientException(_m('No such bookmark.'), 404);
     }
     return $notice;
 }
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::showMassiveActionsSubForm()
  **/
 static function showMassiveActionsSubForm(MassiveAction $ma)
 {
     global $CFG_GLPI;
     switch ($ma->getAction()) {
         case 'move_bookmark':
             $values = array('after' => __('After'), 'before' => __('Before'));
             Dropdown::showFromArray('move_type', $values, array('width' => '20%'));
             $param = array('name' => "bookmarks_id_ref", 'width' => '50%');
             $param['condition'] = "(`is_private`='1' AND `users_id`='" . Session::getLoginUserID() . "') ";
             $param['entity'] = -1;
             Bookmark::dropdown($param);
             echo "<br><br>\n";
             echo Html::submit(_x('button', 'Move'), array('name' => 'massiveaction')) . "</span>";
             return true;
     }
     return parent::showMassiveActionsSubForm($ma);
 }
 /**
  * Handle the data
  *
  * @param array $data associative array of user & bookmark info from DeliciousBackupImporter::importBookmark()
  *
  * @return boolean success value
  */
 function handle($data)
 {
     $profile = Profile::getKV('id', $data['profile_id']);
     try {
         $saved = Bookmark::saveNew($profile, $data['title'], $data['url'], $data['tags'], $data['description'], array('created' => $data['created'], 'distribute' => false));
     } catch (ClientException $ce) {
         // Most likely a duplicate -- continue on with the rest!
         common_log(LOG_ERR, "Error importing delicious bookmark to {$data['url']}: " . $ce->getMessage());
         return true;
     } catch (Exception $ex) {
         if (preg_match("/DB Error: already exists/", $ex->getMessage())) {
             common_log(LOG_ERR, "Error importing delicious bookmark to {$data['url']}: " . $ce->getMessage());
             return true;
         } else {
             throw $ex;
         }
     }
     return true;
 }
Esempio n. 16
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     OwnerDesignAction::prepare($argarray);
     $this->id = $this->trimmed('id');
     $this->bookmark = Bookmark::staticGet('id', $this->id);
     if (empty($this->bookmark)) {
         throw new ClientException(_('No such bookmark.'), 404);
     }
     $this->notice = Notice::staticGet('uri', $this->bookmark->uri);
     if (empty($this->notice)) {
         // Did we used to have it, and it got deleted?
         throw new ClientException(_('No such bookmark.'), 404);
     }
     $this->user = User::staticGet('id', $this->bookmark->profile_id);
     if (empty($this->user)) {
         throw new ClientException(_('No such user.'), 404);
     }
     $this->profile = $this->user->getProfile();
     if (empty($this->profile)) {
         throw new ServerException(_('User without a profile.'));
     }
     $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
     return true;
 }
Esempio n. 17
0
 /**
  * Completion of the URL $_GET values with the $_SESSION values or define default values
  *
  * @param $itemtype                 item type to manage
  * @param $params          array    params to parse
  * @param $usesession               Use datas save in session (true by default)
  * @param $forcebookmark            force trying to load parameters from default bookmark:
  *                                  used for global search (false by default)
  *
  * @return parsed params array
  **/
 static function manageParams($itemtype, $params = array(), $usesession = true, $forcebookmark = false)
 {
     global $CFG_GLPI, $DB;
     $redirect = false;
     $default_values = array();
     $default_values["start"] = 0;
     $default_values["order"] = "ASC";
     $default_values["sort"] = 1;
     $default_values["is_deleted"] = 0;
     if ($CFG_GLPI['allow_search_view'] == 2) {
         $default_criteria = 'view';
     } else {
         $options = self::getCleanedOptions($itemtype);
         foreach ($options as $key => $val) {
             if (is_array($val)) {
                 $default_criteria = $key;
                 break;
             }
         }
     }
     $default_values["criteria"] = array(0 => array('field' => $default_criteria, 'link' => 'contains', 'value' => ''));
     $default_values["metacriteria"] = array();
     // Reorg search array
     // start
     // order
     // sort
     // is_deleted
     // itemtype
     // criteria : array (0 => array (link =>
     //                               field =>
     //                               searchtype =>
     //                               value =>   (contains)
     // metacriteria : array (0 => array (itemtype =>
     //                                  link =>
     //                                  field =>
     //                                  searchtype =>
     //                                  value =>   (contains)
     if ($itemtype != 'AllAssets' && class_exists($itemtype) && method_exists($itemtype, 'getDefaultSearchRequest')) {
         $default_values = array_merge($default_values, call_user_func(array($itemtype, 'getDefaultSearchRequest')));
     }
     // First view of the page or force bookmark : try to load a bookmark
     if ($forcebookmark || $usesession && !isset($params["reset"]) && !isset($_SESSION['glpisearch'][$itemtype])) {
         $query = "SELECT `bookmarks_id`\n                   FROM `glpi_bookmarks_users`\n                   WHERE `users_id`='" . Session::getLoginUserID() . "'\n                         AND `itemtype` = '{$itemtype}'";
         if ($result = $DB->query($query)) {
             if ($DB->numrows($result) > 0) {
                 $IDtoload = $DB->result($result, 0, 0);
                 // Set session variable
                 $_SESSION['glpisearch'][$itemtype] = array();
                 // Load bookmark on main window
                 $bookmark = new Bookmark();
                 // Only get datas for bookmarks
                 if ($forcebookmark) {
                     $params = $bookmark->getParameters($IDtoload);
                 } else {
                     $bookmark->load($IDtoload, false);
                 }
             }
         }
     }
     // Force reorder criterias
     if (isset($params["criteria"]) && is_array($params["criteria"]) && count($params["criteria"])) {
         $tmp = $params["criteria"];
         $params["criteria"] = array();
         foreach ($tmp as $val) {
             $params["criteria"][] = $val;
         }
     }
     if (isset($params["metacriteria"]) && is_array($params["metacriteria"]) && count($params["metacriteria"])) {
         $tmp = $params["metacriteria"];
         $params["metacriteria"] = array();
         foreach ($tmp as $val) {
             $params["metacriteria"][] = $val;
         }
     }
     if ($usesession && isset($params["reset"])) {
         if (isset($_SESSION['glpisearch'][$itemtype])) {
             unset($_SESSION['glpisearch'][$itemtype]);
         }
     }
     if (isset($params) && is_array($params) && $usesession) {
         foreach ($params as $key => $val) {
             $_SESSION['glpisearch'][$itemtype][$key] = $val;
         }
     }
     foreach ($default_values as $key => $val) {
         if (!isset($params[$key])) {
             if ($usesession && isset($_SESSION['glpisearch'][$itemtype][$key])) {
                 $params[$key] = $_SESSION['glpisearch'][$itemtype][$key];
             } else {
                 $params[$key] = $val;
                 $_SESSION['glpisearch'][$itemtype][$key] = $val;
             }
         }
     }
     return $params;
 }
Esempio n. 18
0
 /**
  * deleteBookmark
  * Delete an existing bookmark.
  * Takes the file id in parameter.
  * Not supported.
  */
 public static function deletebookmark($input)
 {
     self::check_version($input, "1.9.0");
     $id = self::check_parameter($input, 'id');
     $type = Subsonic_XML_Data::getAmpacheType($id);
     $bookmark = new Bookmark(Subsonic_XML_Data::getAmpacheId($id), $type);
     if ($bookmark->id) {
         $bookmark->remove();
         $r = Subsonic_XML_Data::createSuccessResponse();
     } else {
         $r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
     }
     self::apiOutput($input, $r);
 }
Esempio n. 19
0
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief 
*/
if (!isset($_GET["type"])) {
    $_GET["type"] = -1;
}
if (!isset($_GET["itemtype"])) {
    $_GET["itemtype"] = -1;
}
if (!isset($_GET["url"])) {
    $_GET["url"] = "";
}
$bookmark = new Bookmark();
if (isset($_POST["add"])) {
    $bookmark->check(-1, 'w', $_POST);
    $bookmark->add($_POST);
    $_GET["action"] = "load";
    // Force popup on load.
    $_SESSION["glpipopup"]["name"] = "load_bookmark";
} else {
    if (isset($_POST["update"])) {
        $bookmark->check($_POST["id"], 'w');
        // Right to update the bookmark
        $bookmark->check(-1, 'w', $_POST);
        // Right when entity change
        $bookmark->update($_POST);
        $_GET["action"] = "load";
    } else {
Esempio n. 20
0
 /**
  * Print generic search form
  *
  *@param $itemtype type to display the form
  *@param $params parameters array may include field, contains, sort, is_deleted, link, link2, contains2, field2, type2
  *
  *@return nothing (displays)
  *
  **/
 function showGenericSearch($params)
 {
     global $CFG_GLPI;
     $itemtype = "PluginResourcesDirectory";
     $itemtable = $this->table;
     // Default values of parameters
     $p['link'] = array();
     //
     $p['field'] = array();
     $p['contains'] = array();
     $p['searchtype'] = array();
     $p['sort'] = '';
     $p['is_deleted'] = 0;
     $p['link2'] = '';
     //
     $p['contains2'] = '';
     $p['field2'] = '';
     $p['itemtype2'] = '';
     $p['searchtype2'] = '';
     foreach ($params as $key => $val) {
         $p[$key] = $val;
     }
     $options = Search::getCleanedOptions("PluginResourcesDirectory");
     $target = $CFG_GLPI["root_doc"] . "/plugins/resources/front/directory.php";
     // Instanciate an object to access method
     $item = NULL;
     if (class_exists($itemtype)) {
         $item = new $itemtype();
     }
     $linked = Search::getMetaItemtypeAvailable($itemtype);
     echo "<form name='searchform{$itemtype}' method='get' action=\"{$target}\">";
     echo "<table class='tab_cadre_fixe' >";
     echo "<tr class='tab_bg_1'>";
     echo "<td>";
     echo "<table>";
     // Display normal search parameters
     for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) {
         echo "<tr><td class='left' width='50%'>";
         // First line display add / delete images for normal and meta search items
         if ($i == 0) {
             echo "<input type='hidden' disabled  id='add_search_count' name='add_search_count' value='1'>";
             echo "<a href='#' onClick = \"document.getElementById('add_search_count').disabled=false;document.forms['searchform{$itemtype}'].submit();\">";
             echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/plus.png\" alt='+' title='" . __s('Add a search criterion') . "'></a>&nbsp;&nbsp;&nbsp;&nbsp;";
             if ($_SESSION["glpisearchcount"][$itemtype] > 1) {
                 echo "<input type='hidden' disabled  id='delete_search_count' name='delete_search_count' value='1'>";
                 echo "<a href='#' onClick = \"document.getElementById('delete_search_count').disabled=false;document.forms['searchform{$itemtype}'].submit();\">";
                 echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/moins.png\" alt='-' title='" . __s('Delete a search criterion') . "'></a>&nbsp;&nbsp;&nbsp;&nbsp;";
             }
             if (is_array($linked) && count($linked) > 0) {
                 echo "<input type='hidden' disabled id='add_search_count2' name='add_search_count2' value='1'>";
                 echo "<a href='#' onClick = \"document.getElementById('add_search_count2').disabled=false;document.forms['searchform{$itemtype}'].submit();\">";
                 echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_plus.png\" alt='+' title='" . __s('Add a global search criterion') . "'></a>&nbsp;&nbsp;&nbsp;&nbsp;";
                 if ($_SESSION["glpisearchcount2"][$itemtype] > 0) {
                     echo "<input type='hidden' disabled  id='delete_search_count2' name='delete_search_count2' value='1'>";
                     echo "<a href='#' onClick = \"document.getElementById('delete_search_count2').disabled=false;document.forms['searchform{$itemtype}'].submit();\">";
                     echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_moins.png\" alt='-' title='" . __s('Delete a global search criterion') . "'></a>&nbsp;&nbsp;&nbsp;&nbsp;";
                 }
             }
             $itemtable = getTableForItemType($itemtype);
         }
         // Display link item
         if ($i > 0) {
             echo "<select name='link[{$i}]'>";
             echo "<option value='AND' ";
             if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "AND") {
                 echo "selected";
             }
             echo ">AND</option>\n";
             echo "<option value='OR' ";
             if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR") {
                 echo "selected";
             }
             echo ">OR</option>\n";
             echo "<option value='AND NOT' ";
             if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "AND NOT") {
                 echo "selected";
             }
             echo ">AND NOT</option>\n";
             echo "<option value='OR NOT' ";
             if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR NOT") {
                 echo "selected";
             }
             echo ">OR NOT</option>";
             echo "</select>&nbsp;";
         }
         // display select box to define serach item
         echo "<select id='Search{$itemtype}{$i}' name=\"field[{$i}]\" size='1'>";
         echo "<option value='view' ";
         if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "view") {
             echo "selected";
         }
         echo ">" . __('Items seen') . "</option>\n";
         reset($options);
         $first_group = true;
         $selected = 'view';
         foreach ($options as $key => $val) {
             // print groups
             if (!is_array($val)) {
                 if (!$first_group) {
                     echo "</optgroup>\n";
                 } else {
                     $first_group = false;
                 }
                 echo "<optgroup label='{$val}'>";
             } else {
                 if (!isset($val['nosearch']) || $val['nosearch'] == false) {
                     echo "<option title=\"" . Html::cleanInputText($val["name"]) . "\" value='{$key}'";
                     if (is_array($p['field']) && isset($p['field'][$i]) && $key == $p['field'][$i]) {
                         echo "selected";
                         $selected = $key;
                     }
                     echo ">" . Toolbox::substr($val["name"], 0, 28) . "</option>\n";
                 }
             }
         }
         if (!$first_group) {
             echo "</optgroup>\n";
         }
         echo "<option value='all' ";
         if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "all") {
             echo "selected";
         }
         echo ">" . __('All') . "</option>";
         echo "</select>&nbsp;\n";
         echo "</td><td class='left'>";
         echo "<div id='SearchSpan{$itemtype}{$i}'>\n";
         $_POST['itemtype'] = $itemtype;
         $_POST['num'] = $i;
         $_POST['field'] = $selected;
         $_POST['searchtype'] = is_array($p['searchtype']) && isset($p['searchtype'][$i]) ? $p['searchtype'][$i] : "";
         $_POST['value'] = is_array($p['contains']) && isset($p['contains'][$i]) ? stripslashes($p['contains'][$i]) : "";
         include GLPI_ROOT . "/ajax/searchoption.php";
         echo "</div>\n";
         $params = array('field' => '__VALUE__', 'itemtype' => $itemtype, 'num' => $i, 'value' => $_POST["value"], 'searchtype' => $_POST["searchtype"]);
         Ajax::updateItemOnSelectEvent("Search{$itemtype}{$i}", "SearchSpan{$itemtype}{$i}", $CFG_GLPI["root_doc"] . "/ajax/searchoption.php", $params, false);
         echo "</td></tr>\n";
     }
     $metanames = array();
     if (is_array($linked) && count($linked) > 0) {
         for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) {
             echo "<tr><td class='left'>";
             $rand = mt_rand();
             // Display link item (not for the first item)
             echo "<select name='link2[{$i}]'>";
             echo "<option value='AND' ";
             if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "AND") {
                 echo "selected";
             }
             echo ">AND</option>\n";
             echo "<option value='OR' ";
             if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR") {
                 echo "selected";
             }
             echo ">OR</option>\n";
             echo "<option value='AND NOT' ";
             if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "AND NOT") {
                 echo "selected";
             }
             echo ">AND NOT</option>\n";
             echo "<option value='OR NOT' ";
             if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR NOT") {
                 echo "selected";
             }
             echo ">OR NOT</option>\n";
             echo "</select>&nbsp;";
             // Display select of the linked item type available
             echo "<select name='itemtype2[{$i}]' id='itemtype2_" . $itemtype . "_" . $i . "_{$rand}'>";
             echo "<option value=''>" . Dropdown::EMPTY_VALUE . "</option>";
             foreach ($linked as $key) {
                 if (!isset($metanames[$key])) {
                     $linkitem = new $key();
                     $metanames[$key] = $linkitem->getTypeName();
                 }
                 echo "<option value='{$key}'>" . Toolbox::substr($metanames[$key], 0, 20) . "</option>\n";
             }
             echo "</select>&nbsp;";
             echo "</td><td>";
             // Ajax script for display search met& item
             echo "<span id='show_" . $itemtype . "_" . $i . "_{$rand}'>&nbsp;</span>\n";
             $params = array('itemtype' => '__VALUE__', 'num' => $i, 'field' => is_array($p['field2']) && isset($p['field2'][$i]) ? $p['field2'][$i] : "", 'value' => is_array($p['contains2']) && isset($p['contains2'][$i]) ? $p['contains2'][$i] : "", 'searchtype2' => is_array($p['searchtype2']) && isset($p['searchtype2'][$i]) ? $p['searchtype2'][$i] : "");
             Ajax::updateItemOnSelectEvent("itemtype2_" . $itemtype . "_" . $i . "_{$rand}", "show_" . $itemtype . "_" . $i . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params, false);
             if (is_array($p['itemtype2']) && isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i])) {
                 $params['itemtype'] = $p['itemtype2'][$i];
                 Ajax::updateItem("show_" . $itemtype . "_" . $i . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params, false);
                 echo "<script type='text/javascript' >";
                 echo "window.document.getElementById('itemtype2_" . $itemtype . "_" . $i . "_{$rand}').value='" . $p['itemtype2'][$i] . "';";
                 echo "</script>\n";
             }
             echo "</td></tr></table>";
             echo "</td></tr>\n";
         }
     }
     echo "</table>\n";
     echo "</td>\n";
     echo "<td width='150px'>";
     echo "<table width='100%'>";
     // Display deleted selection
     echo "<tr>";
     // Display submit button
     echo "<td width='80' class='center'>";
     echo "<input type='submit' value=\"" . _sx('button', 'Search') . "\" class='submit' >";
     echo "</td><td>";
     Bookmark::showSaveButton(Bookmark::SEARCH, $itemtype);
     echo "<a href='{$target}?reset=reset' >";
     echo "&nbsp;&nbsp;<img title=\"" . __s('Blank') . "\" alt=\"" . __s('Blank') . "\" src='" . $CFG_GLPI["root_doc"] . "/templates/infotel/pics/reset.png' class='calendrier'></a>";
     echo "</td></tr></table>\n";
     echo "</td></tr>";
     echo "</table>\n";
     // For dropdown
     echo "<input type='hidden' name='itemtype' value='{$itemtype}'>";
     // Reset to start when submit new search
     echo "<input type='hidden' name='start' value='0'>";
     Html::closeForm();
 }
Esempio n. 21
0
if (Session::haveRight("config", "r")) {
    // Check only read as we probably use the replicate (no 'w' in this case)
    echo "<tr class='tab_bg_3 center'><td colspan='" . ($crit > 0 ? '3' : '2') . "'>";
    echo "<a href='./doublons.config.php'>" . __('Report configuration', 'reports') . "</a></td></tr>\n";
}
echo "<tr class='tab_bg_1'><td class='right'>" . _n('Criterion', 'Criteria', 2) . "</td><td>";
echo "<select name='crit'>";
foreach ($crits as $key => $val) {
    echo "<option value='{$key}'" . ($crit == $key ? "selected" : "") . ">{$val}</option>";
}
echo "</select></td>";
if ($crit > 0) {
    echo "<td>";
    //Add parameters to uri to be saved as bookmarks
    $_SERVER["REQUEST_URI"] = buildBookmarkUrl($_SERVER["REQUEST_URI"], $crit);
    Bookmark::showSaveButton(Bookmark::SEARCH, 'Computer');
    echo "</td>";
}
echo "</tr>\n";
echo "<tr class='tab_bg_1 center'><td colspan='" . ($crit > 0 ? '3' : '2') . "'>";
echo "<input type='submit' value='valider' class='submit'/>";
echo "</td></tr>\n";
echo "</table>\n";
Html::closeForm();
if ($crit == 5) {
    // Search Duplicate IP Address - From glpi_networking_ports
    $IPBlacklist = "AA.`ip` != ''\n                   AND AA.`ip` != '0.0.0.0'";
    if (TableExists("glpi_plugin_reports_doublons_backlists")) {
        $res = $DB->query("SELECT `addr`\n                         FROM `glpi_plugin_reports_doublons_backlists`\n                         WHERE `type` = '2'");
        while ($data = $DB->fetch_array($res)) {
            if (strpos($data["addr"], '%')) {
function displaySearchForm()
{
    global $_SERVER, $_GET, $CFG_GLPI;
    echo "<form action='" . $_SERVER["PHP_SELF"] . "' method='post'>";
    echo "<table class='tab_cadre' cellpadding='5'>";
    echo "<tr class='tab_bg_1' align='center'>";
    echo "<td>";
    echo __('Initial contract period') . " :";
    $values = array();
    $values["sup"] = ">";
    $values["inf"] = "<";
    $values["equal"] = "=";
    if (isset($_GET["contains"][1])) {
        if (strstr($_GET["contains"][1], "lt;")) {
            $_GET["dropdown_sup_inf"] = "inf";
            $_GET["dropdown_calendar"] = str_replace("lt;", "", $_GET["contains"][1]);
            $_GET["dropdown_calendar"] = str_replace("&", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("\\", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("'", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace(" 00:00:00", "", $_GET["dropdown_calendar"]);
            $_GET["contains"][1] = "<" . $_GET["dropdown_calendar"];
        }
        if (strstr($_GET["contains"][1], "gt;")) {
            $_GET["dropdown_sup_inf"] = "sup";
            $_GET["dropdown_calendar"] = str_replace("gt;", "", $_GET["contains"][1]);
            $_GET["dropdown_calendar"] = str_replace("&", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("\\", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("'", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace(" 00:00:00", "", $_GET["dropdown_calendar"]);
            $_GET["contains"][1] = ">" . $_GET["dropdown_calendar"];
        }
        if (strstr($_GET["contains"][1], "LIKE")) {
            $_GET["dropdown_sup_inf"] = "equal";
            $_GET["dropdown_calendar"] = str_replace("=", "", $_GET["contains"][1]);
            $_GET["dropdown_calendar"] = str_replace("&", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("\\", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("'", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("%", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("LIKE ", "", $_GET["dropdown_calendar"]);
            $_GET["contains"][1] = "LIKE '" . $_GET["dropdown_calendar"] . "%'";
        }
    }
    Dropdown::showFromArray("dropdown_sup_inf", $values, array('value' => isset($_GET["dropdown_sup_inf"]) ? $_GET["dropdown_sup_inf"] : "sup"));
    echo "</td>\n      <td width='120'>";
    Html::showDateFormItem("dropdown_calendar", isset($_GET["dropdown_calendar"]) ? $_GET["dropdown_calendar"] : 0);
    echo "</td>";
    echo "<td>" . __('Location') . "</td>";
    echo "<td>";
    Dropdown::show("Location", array('name' => "location", 'value' => isset($_GET["location"]) ? $_GET["location"] : ""));
    echo "</td>";
    // Display Reset search
    echo "<td>";
    echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/fusioninventory/report/ports_date_connections.php?reset_search=reset_search' ><img title=\"" . __('Blank') . "\" alt=\"" . __('Blank') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/reset.png' class='calendrier'></a>";
    echo "</td>";
    echo "<td>";
    //Add parameters to uri to be saved as bookmarks
    $_SERVER["REQUEST_URI"] = buildBookmarkUrl($_SERVER["REQUEST_URI"], $_GET);
    Bookmark::showSaveButton(Bookmark::SEARCH, 'PluginFusioninventoryNetworkport2');
    echo "</td>";
    echo "<td>";
    echo "<input type='submit' value='Valider' class='submit' />";
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    Html::closeForm();
}
Esempio n. 23
0
    return;
}
$userid = get_userid();
if (isset($_POST["editbookmark"])) {
    $validinfo = true;
    if ($title == "") {
        $validinfo = false;
        $error .= "<li>" . lang('nofieldgiven', array(lang('title'))) . "</li>";
    }
    if ($myurl == "") {
        $validinfo = false;
        $error .= "<li>" . lang('nofieldgiven', array(lang('url'))) . "</li>";
    }
    if ($validinfo) {
        cmsms()->GetBookmarkOperations();
        $markobj = new Bookmark();
        $markobj->bookmark_id = $bookmark_id;
        $markobj->title = $title;
        $markobj->url = $myurl;
        $markobj->user_id = $userid;
        $result = $markobj->save();
        if ($result) {
            redirect("listbookmarks.php" . $urlext);
            return;
        } else {
            $error .= "<li>" . lang('errorupdatingbookmark') . "</li>";
        }
    }
} else {
    if ($bookmark_id != -1) {
        $query = "SELECT * from " . cms_db_prefix() . "admin_bookmarks WHERE bookmark_id = ?";
Esempio n. 24
0
 public function executeConfirmEmail($request)
 {
     // we only accept GET method
     $this->forward404Unless($request->isMethod('get'));
     $email = EmailPeer::getFromField(EmailPeer::CONFIRM_CODE, $this->getRequestParameter('confirm_code'));
     if ($email) {
         if ($email->getIsPrimary() && !$email->getActualEmail()) {
             // if invited, send acceptance email and add to quick contact
             $user = $email->getUser();
             if ($user->getInvitedBy()) {
                 // add to bookmark
                 $b = new Bookmark();
                 $b->setUser($user->getUserRelatedByInvitedBy());
                 $b->setTag($user->retrievePrimaryJotag());
                 $b->save();
                 // give credit to the inviter
                 $credits = $user->getUserRelatedByInvitedBy()->giveCredit(OptionPeer::retrieveOption('BONUS_ACCEPT_CREDIT'));
                 Mailer::sendEmail($user->getUserRelatedByInvitedBy()->getPrimaryEmail(), 'inviteAccepted', array('owner' => $user->getUserRelatedByInvitedBy(), 'user' => $user, 'email' => $email, 'credits' => $credits), $user->getUserRelatedByInvitedBy()->getPreferedLanguage());
             }
             // activate primary jotag
             $jotag = $email->getUser()->retrievePrimaryJotag();
             $jotag->setStatus(TagPeer::ST_ACTIVE);
             $jotag->save();
             $this->setMessage('ACCOUNT_CONFIRM', 'SUCCESS');
         } else {
             $this->setMessage('EMAIL_CONFIRM', 'SUCCESS');
         }
         $email->setIsConfirmed(true);
         $email->setConfirmCode(null);
         $email->setActualEmail(null);
         $email->save();
     } else {
         $this->setMessage('EMAIL_CONFIRM_ERROR', 'ERROR');
     }
     $this->redirect('@homepage');
 }
Esempio n. 25
0
 /**
  *  Проверяет имеется ли тема в закладках
  * @param  integer  $user_id id пользователя
  * @return boolean  имеется ли тема в закладках
  */
 public function isBookmarked($user_id)
 {
     return Bookmark::exists(['conditions' => ['topic_id = ? AND user_id = ?', $this->id, $user_id]]);
 }
Esempio n. 26
0
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#$Id: makebookmark.php 7647 2012-01-01 15:28:10Z calguy1000 $
global $CMS_ADMIN_PAGE;
$CMS_ADMIN_PAGE = 1;
require_once '../include.php';
$urlext = '?' . CMS_SECURE_PARAM_NAME . '=' . $_SESSION[CMS_USER_KEY];
include_once "header.php";
check_login();
$config = cmsms()->GetConfig();
$link = $_SERVER['HTTP_REFERER'];
$newmark = new Bookmark();
$newmark->user_id = get_userid();
$newmark->url = $link;
$newmark->title = $_GET['title'];
$result = $newmark->save();
if ($result) {
    header('HTTP_REFERER: ' . $config['admin_url'] . '/index.php');
    redirect($link);
} else {
    include_once "header.php";
    echo "<h3>" . lang('erroraddingbookmark') . "</h3>";
}
Esempio n. 27
0
}
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
    $sortorder = "ASC";
}
if (!$sortfield) {
    $sortfield = "position";
}
$limit = $conf->liste_limit;
/*
 * Actions
 */
if ($_GET["action"] == 'delete') {
    $bookmark = new Bookmark($db);
    $res = $bookmark->remove($_GET["bid"]);
    if ($res > 0) {
        header("Location: " . $_SERVER["PHP_SELF"]);
        exit;
    } else {
        $mesg = '<div class="error">' . $bookmark->error . '</div>';
    }
}
/*
 * View
 */
$userstatic = new User($db);
llxHeader();
print_fiche_titre($langs->trans("Bookmarks"));
if ($mesg) {
Esempio n. 28
0
    $_GET['type'] = intval($_GET['type']);
}
if (!isset($_GET["itemtype"])) {
    $_GET["itemtype"] = -1;
} else {
    if (!is_subclass_of($_GET['itemtype'], 'CommonDBTM')) {
        throw new \RuntimeException('Invalid name provided!');
    }
}
if (!isset($_GET["url"])) {
    $_GET["url"] = "";
}
if (!isset($_GET["action"])) {
    $_GET["action"] = "";
}
$bookmark = new Bookmark();
if (isset($_POST["add"])) {
    $bookmark->check(-1, CREATE, $_POST);
    $bookmark->add($_POST);
} else {
    if (isset($_POST["update"])) {
        $bookmark->check($_POST["id"], UPDATE);
        // Right to update the bookmark
        $bookmark->check(-1, CREATE, $_POST);
        // Right when entity change
        $bookmark->update($_POST);
        $_GET["action"] = "";
    } else {
        if ($_GET["action"] == "edit" && isset($_GET['mark_default']) && isset($_GET["id"])) {
            $bookmark->check($_GET["id"], READ);
            if ($_GET["mark_default"] > 0) {
Esempio n. 29
0
 /**
  * Save a new notice bookmark
  *
  * @param Profile $profile     To save the bookmark for
  * @param string  $title       Title of the bookmark
  * @param string  $url         URL of the bookmark
  * @param mixed   $rawtags     array of tags or string
  * @param string  $description Description of the bookmark
  * @param array   $options     Options for the Notice::saveNew()
  *
  * @return Notice saved notice
  */
 static function saveNew($profile, $title, $url, $rawtags, $description, $options = null)
 {
     if (!common_valid_http_url($url)) {
         throw new ClientException(_m('Only web bookmarks can be posted (HTTP or HTTPS).'));
     }
     $nb = self::getByURL($profile, $url);
     if (!empty($nb)) {
         // TRANS: Client exception thrown when trying to save a new bookmark that already exists.
         throw new ClientException(_m('Bookmark already exists.'));
     }
     if (empty($options)) {
         $options = array();
     }
     if (array_key_exists('uri', $options)) {
         $other = Bookmark::getKV('uri', $options['uri']);
         if (!empty($other)) {
             // TRANS: Client exception thrown when trying to save a new bookmark that already exists.
             throw new ClientException(_m('Bookmark already exists.'));
         }
     }
     if (is_string($rawtags)) {
         if (empty($rawtags)) {
             $rawtags = array();
         } else {
             $rawtags = preg_split('/[\\s,]+/', $rawtags);
         }
     }
     $nb = new Bookmark();
     $nb->id = UUID::gen();
     $nb->profile_id = $profile->id;
     $nb->url = $url;
     $nb->title = $title;
     $nb->description = $description;
     if (array_key_exists('created', $options)) {
         $nb->created = $options['created'];
     } else {
         $nb->created = common_sql_now();
     }
     if (array_key_exists('uri', $options)) {
         $nb->uri = $options['uri'];
     } else {
         // FIXME: hacks to work around router bugs in
         // queue daemons
         $r = Router::get();
         $path = $r->build('showbookmark', array('id' => $nb->id));
         if (empty($path)) {
             $nb->uri = common_path('bookmark/' . $nb->id, false, false);
         } else {
             $nb->uri = common_local_url('showbookmark', array('id' => $nb->id), null, null, false);
         }
     }
     $nb->insert();
     $tags = array();
     $replies = array();
     // filter "for:nickname" tags
     foreach ($rawtags as $tag) {
         if (strtolower(mb_substr($tag, 0, 4)) == 'for:') {
             // skip if done by caller
             if (!array_key_exists('replies', $options)) {
                 $nickname = mb_substr($tag, 4);
                 $other = common_relative_profile($profile, $nickname);
                 if (!empty($other)) {
                     $replies[] = $other->getUri();
                 }
             }
         } else {
             $tags[] = common_canonical_tag($tag);
         }
     }
     $hashtags = array();
     $taglinks = array();
     foreach ($tags as $tag) {
         $hashtags[] = '#' . $tag;
         $attrs = array('href' => Notice_tag::url($tag), 'rel' => $tag, 'class' => 'tag');
         $taglinks[] = XMLStringer::estring('a', $attrs, $tag);
     }
     // Use user's preferences for short URLs, if possible
     try {
         $user = User::getKV('id', $profile->id);
         $shortUrl = File_redirection::makeShort($url, empty($user) ? null : $user);
     } catch (Exception $e) {
         // Don't let this stop us.
         $shortUrl = $url;
     }
     // TRANS: Bookmark content.
     // TRANS: %1$s is a title, %2$s is a short URL, %3$s is the bookmark description,
     // TRANS: %4$s is space separated list of hash tags.
     $content = sprintf(_m('"%1$s" %2$s %3$s %4$s'), $title, $shortUrl, $description, implode(' ', $hashtags));
     // TRANS: Rendered bookmark content.
     // TRANS: %1$s is a URL, %2$s the bookmark title, %3$s is the bookmark description,
     // TRANS: %4$s is space separated list of hash tags.
     $rendered = sprintf(_m('<span class="xfolkentry">' . '<a class="taggedlink" href="%1$s">%2$s</a> ' . '<span class="description">%3$s</span> ' . '<span class="meta">%4$s</span>' . '</span>'), htmlspecialchars($url), htmlspecialchars($title), htmlspecialchars($description), implode(' ', $taglinks));
     $options = array_merge(array('urls' => array($url), 'rendered' => $rendered, 'tags' => $tags, 'replies' => $replies, 'object_type' => ActivityObject::BOOKMARK), $options);
     if (!array_key_exists('uri', $options)) {
         $options['uri'] = $nb->uri;
     }
     try {
         $saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options);
     } catch (Exception $e) {
         $nb->delete();
         throw $e;
     }
     if (empty($saved)) {
         $nb->delete();
     }
     return $saved;
 }
Esempio n. 30
0
require_once DOL_DOCUMENT_ROOT . '/bookmarks/class/bookmark.class.php';
$langs->load("bookmarks");
$langs->load("other");
// Security check
if (!$user->rights->bookmark->lire) {
    restrictedArea($user, 'bookmarks');
}
$id = GETPOST("id");
$action = GETPOST("action", "alpha");
$title = GETPOST("title", "alpha");
$url = GETPOST("url", "alpha");
$target = GETPOST("target", "alpha");
$userid = GETPOST("userid", "int");
$position = GETPOST("position", "int");
$backtopage = GETPOST('backtopage', 'alpha');
$bookmark = new Bookmark($db);
/*
 * Actions
 */
if ($action == 'add' || $action == 'addproduct' || $action == 'update') {
    if ($action == 'update') {
        $invertedaction = 'edit';
    } else {
        $invertedaction = 'create';
    }
    $error = 0;
    if (GETPOST("cancel")) {
        if (empty($backtopage)) {
            $backtopage = GETPOST("urlsource") ? GETPOST("urlsource") : (!empty($url) ? $url : DOL_URL_ROOT . '/bookmarks/list.php');
        }
        header("Location: " . $backtopage);