Exemplo n.º 1
0
} else {
    $catTitleWithUrls = '';
}
$pagetitle = substr($pagetitle, 2);
// Header variables
$tplVars['loadjs'] = true;
// ADD A BOOKMARK
$saved = false;
$templatename = 'bookmarks.tpl';
if ($userservice->isLoggedOn() && POST_SUBMITTED != '') {
    if (!POST_TITLE || !POST_ADDRESS) {
        $tplVars['error'] = T_('Your bookmark must have a title and an address');
        $templatename = 'editbookmark.tpl';
    } else {
        $address = trim(POST_ADDRESS);
        if (!SemanticScuttle_Model_Bookmark::isValidUrl($address)) {
            $tplVars['error'] = T_('This bookmark URL may not be added');
            $templatename = 'editbookmark.tpl';
        } else {
            if ($bookmarkservice->bookmarkExists($address, $currentUserID)) {
                // If the bookmark exists already, edit the original
                $bookmark = $bookmarkservice->getBookmarkByAddress($address);
                header('Location: ' . createURL('edit', $bookmark['bId']));
                exit;
                // If it's new, save it
            } else {
                $title = trim(POST_TITLE);
                $description = trim(POST_DESCRIPTION);
                $privateNote = trim(POST_PRIVATENOTE);
                $status = intval(POST_STATUS);
                $categories = explode(',', $_POST['tags']);
Exemplo n.º 2
0
 public function testIsValidUrlInvalid()
 {
     $this->assertFalse(SemanticScuttle_Model_Bookmark::isValidUrl('javascript:alert("foo")'));
     $this->assertFalse(SemanticScuttle_Model_Bookmark::isValidUrl('foo://example.org/foo/bar'));
 }
Exemplo n.º 3
0
 /**
  * Adds a bookmark to the database.
  *
  * Security checks are being made here, but no error reasons will be
  * returned. It is the responsibility of the code that calls
  * addBookmark() to verify the data.
  *
  * @param string  $address     Full URL of the bookmark
  * @param string  $title       Bookmark title
  * @param string  $description Long bookmark description
  * @param string  $privateNote Private note for the user.
  * @param string  $status      Bookmark visibility / privacy settings:
  *                             0 - public
  *                             1 - shared
  *                             2 - private
  * @param array   $tags        Array of tags
  * @param string  $short       Short URL name. May be null
  * @param string  $date        Date when the bookmark has been created
  *                             originally. Used in combination with
  *                             $fromImport. Has to be a strtotime()
  *                             interpretable string.
  * @param boolean $fromApi     True when api call is responsible.
  * @param boolean $fromImport  True when the bookmark is from an import.
  * @param integer $sId         ID of user who creates the bookmark.
  *
  * @return mixed Integer bookmark ID if saving succeeded, false in
  *               case of an error. Error reasons are not returned.
  */
 public function addBookmark($address, $title, $description, $privateNote, $status, $tags, $short = null, $date = null, $fromApi = false, $fromImport = false, $sId = null)
 {
     if ($sId === null) {
         $userservice = SemanticScuttle_Service_Factory::get('User');
         $sId = $userservice->getCurrentUserId();
     }
     $address = $this->normalize($address);
     if (!SemanticScuttle_Model_Bookmark::isValidUrl($address)) {
         return false;
     }
     /*
      * Note that if date is NULL, then it's added with a date and
      * time of now, and if it's present,
      * it's expected to be a string that's interpretable by strtotime().
      */
     if (is_null($date) || $date == '') {
         $time = time();
     } else {
         $time = strtotime($date);
     }
     $datetime = gmdate('Y-m-d H:i:s', $time);
     if ($short === '') {
         $short = null;
     }
     // Set up the SQL insert statement and execute it.
     $values = array('uId' => intval($sId), 'bIp' => SemanticScuttle_Model_RemoteUser::getIp(), 'bDatetime' => $datetime, 'bModified' => $datetime, 'bTitle' => $title, 'bAddress' => $address, 'bDescription' => $description, 'bPrivateNote' => $privateNote, 'bStatus' => intval($status), 'bHash' => $this->getHash($address), 'bShort' => $short);
     $sql = 'INSERT INTO ' . $this->getTableName() . ' ' . $this->db->sql_build_array('INSERT', $values);
     $this->db->sql_transaction('begin');
     if (!($dbresult = $this->db->sql_query($sql))) {
         $this->db->sql_transaction('rollback');
         message_die(GENERAL_ERROR, 'Could not insert bookmark', '', __LINE__, __FILE__, $sql, $this->db);
     }
     // Get the resultant row ID for the bookmark.
     $bId = $this->db->sql_nextid($dbresult);
     if (!isset($bId) || !is_int($bId)) {
         $this->db->sql_transaction('rollback');
         message_die(GENERAL_ERROR, 'Could not insert bookmark', '', __LINE__, __FILE__, $sql, $this->db);
     }
     $uriparts = explode('.', $address);
     $extension = end($uriparts);
     unset($uriparts);
     $b2tservice = SemanticScuttle_Service_Factory::get('Bookmark2Tag');
     $attachok = $b2tservice->attachTags($bId, $tags, $fromApi, $extension, false, $fromImport);
     if (!$attachok) {
         $this->db->sql_transaction('rollback');
         message_die(GENERAL_ERROR, 'Could not insert bookmark', '', __LINE__, __FILE__, $sql, $this->db);
     }
     $this->db->sql_transaction('commit');
     // Everything worked out, so return the new bookmark's bId.
     return $bId;
 }