How it Works

to guide you to get your pages get bookmarked
Bookmarked 0 times
Bookmark

You can use any existing user management, but you don't need any.
Either your userids (integer) from your user database, any string key (such as IP-Addresses) can be used to identify your vistors and you can use Cookies too.
You should also tell the class if your user is authenticated or not. On this demo page I set the auth-value automatically to true and used your IP addresses as key to identify you.
Just include SBM script on every page where you like to offer bookmark function, initialize class and show form or bookmarks.
It's fully ajax driven for comfortable bookmarking but can be used without javascript as well

Upload and configure

I suggest to upload needed files into an own directory, i.e. sbm
these are the files you'll need

minimum
sbm
  sbm.class.php
minimum with ajax support
sbm
  sbm.ajax.php
  sbm.class.php
  sbm.min.js
with ajax support, when jquery file is needed
sbm
  jquery.3.4.1.min.js
  sbm.ajax.php
  sbm.class.php
  sbm.min.js

usage of animate.min.css will be discussed at the end of the manual

Configuring Simple Bookmark

you have to define at least the database connection settings

//DB Settings - only necessary if you're don't provide an existing DB-connection
  
var $db_host "localhost";                      //change if needed!!
  
var $db_user "hansGruber";                      //change is needed!!
  
var $db_pass "superSecret";                      //change is needed!!
  
var $db_name "nacatomi";                      //change is needed!!
//Your bookmarks table
  
var $bm_table "simpleBookmarks";
The setup routine will be called when accessing your website after you've included and initialized the class.

Include file and initialize Class

Include sbm.class.php and initialize Class on every page where you want to use the SBM functions
i.e.

<?php
  
include("sbm/sbm.class.php");
  
$sbm = new SimpleBM($uid,$auth,$db);
?>
Parameters
$uid
To identify the single users you should provide any key
this could be an ID (integer) you're already using in your user management
or a string, for example an email-address or anything else
and if you like to use cookies, you've to use "COOKIE" as key in uppercase
$auth
Indicates that the user is authenticated or not
true -> the user is authenticated to your management
false -> the user is NOT authenticated to your management
$db
optional To forward an existing database connection to use within the class or set it to false and define db-settings in sbm.class.php to create db connection within the class
More examples of initialization
With an user id (var $uid) and an variable that indicates that the user is authenticated
$sbm = new SimpleBM($uid,$auth);
Filled in the values of $uid (15) and authenticated authentication status (1)
$sbm = new SimpleBM(15,1);
Just the IP Address as key, there's no need to authenticatem so set it to 1
$sbm = new SimpleBM($_SERVER["REMOTE_ADDR"],1);
Cookie based, if you use COOKIE in uppercase a cookie will be set (usefull on rotating IPs), there's no need to authenticatem so set it to 1
$sbm = new SimpleBM("COOKIE",1);
If you like to use the cookie identification you have to include and call initiate the SBM-Class before any other outputs are made
Other Examples
$sbm = new SimpleBM($email,$auth);
$sbm = new SimpleBM($user->email,$auth);
$sbm = new SimpleBM($user->id,$user->auth);

Add Ajax Functionality

Add javascript files on every page to the footer (or header) where you want to use the SBM functions
i.e.

...
<
script type="text/javascript" src="sbm/jquery.3.4.1.min.js"></script>
<
script type="text/javascript" src="sbm/sbm.min.js" id="sbmjs"></script>
...
There's no need to include the jquery-file if it's already included.

But it's essential to include the sbm.min.js after the jquery including and don't forget the id sbmjs.
Please make sure, that the sbm.ajax.php, the sbm.min.js and the sbm.class.php are stored in the same directory. The path will be parsed automatically in the sbm javascript file (PHPscriptUrl) and therefore the id sbmjs has to be added to the script tag.

An uncompressed version is attached to the installation files too.

If you have any special authentication or database settings please add them to the sbm.ajax.php too.
Everything should work out of the box :)
additional information

By clicking the link with the ID bmf ... link can be generated automatically
... more info below

The value of the bookmarks will be increased by 1 after bookmarking, or reduced by 1 when unbookmarking. The number should be placed in an span with the classname sbmcount
... more info below

Bookmarks can be removed by clicking the removing link in the bookmarks list (class rmbm) and by clicking the link with the ID the link with the ID bmf
... more info below


Display Bookmark Links

You can use the showLink() method anywhere on your pages to enable bookmarking/un-bookmarking
If page is bookmarked an "Un-Bookmark" link will be displayed, otherwise "Bookmark" link is shown.

<?php echo $sbm->showlink($title); ?>
Parameters
$title
optional, the title for your bookmark,
if not set Javascript tries to set current Pagetitle, if this doesn't work, the title will be generated from the URL to bookmark
Examples
echo $sbm->showlink();
echo $sbm->showlink("Title I like to get used for it");
echo $sbm->showlink($post->headline);
In the demo I've put the
<?php echo $sbm->showlink(); ?>
into the header.php file, which is included on every page

Show/Manage Bookmarks for Users

To show your users their bookmarks and let them manage their you can call stored bookmarks

<?php echo $sbm->bookmarks($array); ?>
Parameters
$array
optional true/false - indicates if a HTML formated string should return or an array to build and format it by yourself
More info to the outputs can be found here if you have bookmarks saved
The multi dimensional array contains id, title, url and created and you can do whatever you what with this array :)
To generate a link to delete bookmarks you have to use bm_action and bm_id, i.e.
<a href="?bm_action=rm&bm_id=15">remove</a>
Examples
echo $sbm->bookmarks();
$arr $sbm->bookmarks(true);

Count how often Single Page is bookmarked

Display number of bookmarks of each page on the page itself

<?php echo $sbm->CountBM($url); ?>
Parameters
$url
optional - if not set, the current url (where you call the function) will be used
Examples
echo $sbm->CountBM();
echo $sbm->CountBM("http://yoursite.tld/yourpath/yourfile.php");
to dynamically increase/decrease count use the sbmcount class
Bookmarked <span class="sbmcount"><?php echo $sbm->countBM(); ?></span> times
In the demo I've put the
Bookmarked <span class="sbmcount"><?php echo $sbm->countBM(); ?></span> times
into the header.php file, which is included on every page

Bookmarks in Dropdown

To show your users their bookmarks in a dropdown and let them jump to the bookmarks you can use

<?php echo $sbm->bookmarksDropdown(); ?>

You can see this in the Bookmarks in this demo.
You could include this code anywhere on your page.

Style and localize

you can either use the $layoutStyle-Array. For the array returns on bookmarks and bookmark stats you can build your own outputs. You could also modify the corresponding methods in the class to fit your needs.

var $layoutStyle = array(
  
//showed in showlink() method
    
"bookmarked_class" => "btn btn-outline-secondary",
    
"bookmarked_text" => "Bookmarked <i class='fas fa-bookmark'></i>",
    
    
"bookmark_class" => "btn btn-outline-primary",
    
"bookmark_text" => "Bookmark <i class='far fa-bookmark'></i>",
    
    
"show_bookmarks_link" => false,
    
"bookmarks_link_text" => "<small>[Your Bookmarks]</small>",

  
//messages
    
"bookmarked_success_text" => "This page has been bookmarked successfully.",
    
"removed_success_text" => "This page has been removed from your bookmarks successfully.",
    
"please_authenticate_to_view" => "Please authenticate to view your bookmarks",
    
"please_authenticate_to_bookmark" => "Please authenticate to bookmark",

  
//no bookmarks found on bookmark listing
    
"no_bookmarks_found" => "<strong>No bookmarks found</strong>",

  
//used on bookmarks list page
    
"remove_bookmark_text" => "<i class='fas fa-times'></i> remove bookmark",
    
"remove_bookmark_class" => "btn btn-outline-danger btn-sm",
    
"dateTimeFormat" => 'Y-m-d G:i',     //more information on https://php.net/manual/en/function.date.php

  //the select dropdown
    
"dropdown_select_class" => "form-control",
    
"dropdown_select_text" => "--Your Bookmarks--",
);

Show Bookmarks Overview

you get an overview of all stored bookmarks of all users with

echo <?php $sbm->BookmarkStats($array); ?>
Parameters
$array
optional true/false - indicates if a HTML formated string should return or an array to build and format it by yourself
More info to the outputs can be found here if there are any bookmarks saved
The multi dimensional array contains number of bookmarks, title and url and you can do whatever you what with this array :)
Examples
echo $sbm->BookmarkStats();
$arr $sbm->BookmarkStats(true);

Animated notifications - AJAX ONLY

if you like animated notifications when adding/removing bookmarks you can get those with animate.css

If your webproject already uses animate.css the notifications should be already animated, if notyou have to upload the animate.min.css into the bookmarks folder and add the param data-option to the script tag

upload css file
sbm
  animate.min.php
add data-option param
...
<
script type="text/javascript" src="sbm/sbm.min.js" id="sbmjs" data-option="animate"></script>
...