Source de bookmarks.inc
<?
DEFINE("BOOKMARKS_COOKIE", "bookmarks");
DEFINE("SEPARATOR_ITEM", "VVV");
DEFINE("SEPARATOR_URL", "___");
if (isset($_COOKIE[BOOKMARKS_COOKIE]))
{
if (get_magic_quotes_gpc())
{
$_COOKIE[BOOKMARKS_COOKIE] = stripslashes($_COOKIE[BOOKMARKS_COOKIE]);
}
}
function getBookmarksList()
{
$result = '';
if (isset($_COOKIE[BOOKMARKS_COOKIE]))
{
$bm_list = explode(SEPARATOR_ITEM, $_COOKIE[BOOKMARKS_COOKIE]);
if (count($bm_list) > 0)
{
$result = ' <ul>
';
while(list($index, $item) = each($bm_list))
{
if (strlen($item) > 0)
{
$bm_elts = explode(SEPARATOR_URL, $item);
$result .= ' <li><a href="'.$bm_elts[0].'">'.$bm_elts[1].'</a></li>
';
}
}
$result .= ' </ul>
';
}
}
return $result;
}
function getBookmarksTable()
{
$result = '<tr><td colspan="3">Aucun marque-page enregistré</td></tr>';
if (isset($_COOKIE[BOOKMARKS_COOKIE]))
{
$bm_list = explode(SEPARATOR_ITEM, $_COOKIE[BOOKMARKS_COOKIE]);
array_shift($bm_list);
$count = count($bm_list);
if (($count > 0) && ($_COOKIE[BOOKMARKS_COOKIE] != ""))
{
$result = '';
$i = 0;
$id = getToBeChecked($count-1);
while(list($index, $item) = each($bm_list))
{
if (strlen($item) > 0)
{
if ($id == $index)
{
$selected = 'checked="checked" ';
}
else
{
$selected = '';
}
$bm_elts = explode(SEPARATOR_URL, $item);
$result .= ' <tr id="bm'.$i.'"><td><input '.$selected.'type="radio" name="bm-id" id="bmc'.$i.'" value="'.$i.'" /></td><td><label for="bmc'.$i.'">'.$bm_elts[1].'</label></td><td><a href="'.$bm_elts[0].'">'.$bm_elts[0].'</a></td></tr>
';
$i++;
}
}
}
}
return $result;
}
function getBookmarksLinks()
{
$result = '';
if (isset($_COOKIE[BOOKMARKS_COOKIE]))
{
$bm_list = explode(SEPARATOR_ITEM, $_COOKIE[BOOKMARKS_COOKIE]);
if (count($bm_list) > 0)
{
while(list($index, $item) = each($bm_list))
{
if (strlen($item) > 0)
{
$bm_elts = explode(SEPARATOR_URL, $item);
$result .= ' <link rel="Bookmark" href="'.$bm_elts[0].'" title="'.$bm_elts[1].'"></link>
';
}
}
}
}
return $result;
}
function getBookmarksForm($title)
{
$url = ($_SERVER['REQUEST_URI'] != '/') ? $_SERVER['REQUEST_URI'] : '/index.php';
$url = str_replace('&', '&', $url);
$action = $url;
if (isset($_REQUEST['source']))
{
$display_s = ' <input type="hidden" name="source" value="'.$_REQUEST['source'].'" />';
}
else if (isset($_REQUEST['script']))
{
$display_s = ' <input type="hidden" name="script" value="'.$_REQUEST['script'].'" />';
}
else
{
$display_s = '';
}
$result = ' <form action="'.$action.'" method="post" id="bm-form">
'.getBookMarksList().'
<div>
'.$display_s;
$result .= ' <input type="hidden" name="title" value="'.htmlentities($title).'" />
<input type="hidden" name="url" value="'.$url.'" />
<input type="submit" class="submit-button" name="bookmark" value="Ajouter" title="Ajouter la page courante dans la liste" />
</div>
<div class="box-link" id="bm-link">
<a href="/favoris.php" title="Pour supprimer ou changer l\'ordre des marque-pages">Gestion des marque-pages</a>
</div>
</form>
';
return $result;
}
function array_flip_values(&$array, $idx1, $idx2)
{
$tmp = $array[$idx1];
$array[$idx1] = $array[$idx2];
$array[$idx2] = $tmp;
}
function bookmark()
{
if ( (isset($_REQUEST['bookmark'])) && (isset($_REQUEST['title'])) && (isset($_REQUEST['url'])) )
{
if (get_magic_quotes_gpc())
{
$_REQUEST['url'] = stripslashes($_REQUEST['url']);
$_REQUEST['title'] = stripslashes($_REQUEST['title']);
}
$cookieValue = isset($_COOKIE[BOOKMARKS_COOKIE]) ? $_COOKIE[BOOKMARKS_COOKIE] : "";
if ($_REQUEST['bookmark'][0] == 'A')
{
if (strpos($cookieValue, SEPARATOR_ITEM.$_REQUEST['url'].SEPARATOR_URL) === false)
{
$cookieValue = $cookieValue.SEPARATOR_ITEM.$_REQUEST['url'].SEPARATOR_URL.$_REQUEST['title'];
setCookie(BOOKMARKS_COOKIE, $cookieValue, time() + (365*24*3600), "/");
$_COOKIE[BOOKMARKS_COOKIE] = $cookieValue;
}
}
}
if (isset($_REQUEST['bm-command']))
{
$id = (isset($_REQUEST['bm-id']) ? $_REQUEST['bm-id'] : 0);
$bm_list = explode(SEPARATOR_ITEM, $_COOKIE[BOOKMARKS_COOKIE]);
array_shift($bm_list);
$commandOk = true;
switch($_REQUEST['bm-command'][0])
{
case 'M':
if($id > 0)
{
array_flip_values($bm_list, $id, $id-1);
}
break;
case 'D':
if($id < (count($bm_list) - 1))
{
array_flip_values($bm_list, $id, $id+1);
}
break;
case 'S':
array_splice($bm_list,$id,1);
break;
case 'V':
$commandOk = false;
setCookie(BOOKMARKS_COOKIE, '', time() - (365*24), "/");
unset($_COOKIE[BOOKMARKS_COOKIE]);
break;
default:
$commandOk = false;
}
if ($commandOk)
{
$cookieValue = SEPARATOR_ITEM.implode(SEPARATOR_ITEM, $bm_list);
setCookie(BOOKMARKS_COOKIE, $cookieValue, time() + (365*24*3600), "/");
$_COOKIE[BOOKMARKS_COOKIE] = $cookieValue;
}
}
}
function getToBeChecked($max)
{
$id = (isset($_REQUEST['bm-id']) ? $_REQUEST['bm-id'] : 0);
if (isset($_REQUEST['bm-command']))
{
if ($_REQUEST['bm-command'][0] == 'M')
{
$id = max($id-1, 0);
}
else if ($_REQUEST['bm-command'][0] == 'D')
{
$id = min($id+1, $max);
}
}
return $id;
}
?>
DEFINE("BOOKMARKS_COOKIE", "bookmarks");
DEFINE("SEPARATOR_ITEM", "VVV");
DEFINE("SEPARATOR_URL", "___");
if (isset($_COOKIE[BOOKMARKS_COOKIE]))
{
if (get_magic_quotes_gpc())
{
$_COOKIE[BOOKMARKS_COOKIE] = stripslashes($_COOKIE[BOOKMARKS_COOKIE]);
}
}
function getBookmarksList()
{
$result = '';
if (isset($_COOKIE[BOOKMARKS_COOKIE]))
{
$bm_list = explode(SEPARATOR_ITEM, $_COOKIE[BOOKMARKS_COOKIE]);
if (count($bm_list) > 0)
{
$result = ' <ul>
';
while(list($index, $item) = each($bm_list))
{
if (strlen($item) > 0)
{
$bm_elts = explode(SEPARATOR_URL, $item);
$result .= ' <li><a href="'.$bm_elts[0].'">'.$bm_elts[1].'</a></li>
';
}
}
$result .= ' </ul>
';
}
}
return $result;
}
function getBookmarksTable()
{
$result = '<tr><td colspan="3">Aucun marque-page enregistré</td></tr>';
if (isset($_COOKIE[BOOKMARKS_COOKIE]))
{
$bm_list = explode(SEPARATOR_ITEM, $_COOKIE[BOOKMARKS_COOKIE]);
array_shift($bm_list);
$count = count($bm_list);
if (($count > 0) && ($_COOKIE[BOOKMARKS_COOKIE] != ""))
{
$result = '';
$i = 0;
$id = getToBeChecked($count-1);
while(list($index, $item) = each($bm_list))
{
if (strlen($item) > 0)
{
if ($id == $index)
{
$selected = 'checked="checked" ';
}
else
{
$selected = '';
}
$bm_elts = explode(SEPARATOR_URL, $item);
$result .= ' <tr id="bm'.$i.'"><td><input '.$selected.'type="radio" name="bm-id" id="bmc'.$i.'" value="'.$i.'" /></td><td><label for="bmc'.$i.'">'.$bm_elts[1].'</label></td><td><a href="'.$bm_elts[0].'">'.$bm_elts[0].'</a></td></tr>
';
$i++;
}
}
}
}
return $result;
}
function getBookmarksLinks()
{
$result = '';
if (isset($_COOKIE[BOOKMARKS_COOKIE]))
{
$bm_list = explode(SEPARATOR_ITEM, $_COOKIE[BOOKMARKS_COOKIE]);
if (count($bm_list) > 0)
{
while(list($index, $item) = each($bm_list))
{
if (strlen($item) > 0)
{
$bm_elts = explode(SEPARATOR_URL, $item);
$result .= ' <link rel="Bookmark" href="'.$bm_elts[0].'" title="'.$bm_elts[1].'"></link>
';
}
}
}
}
return $result;
}
function getBookmarksForm($title)
{
$url = ($_SERVER['REQUEST_URI'] != '/') ? $_SERVER['REQUEST_URI'] : '/index.php';
$url = str_replace('&', '&', $url);
$action = $url;
if (isset($_REQUEST['source']))
{
$display_s = ' <input type="hidden" name="source" value="'.$_REQUEST['source'].'" />';
}
else if (isset($_REQUEST['script']))
{
$display_s = ' <input type="hidden" name="script" value="'.$_REQUEST['script'].'" />';
}
else
{
$display_s = '';
}
$result = ' <form action="'.$action.'" method="post" id="bm-form">
'.getBookMarksList().'
<div>
'.$display_s;
$result .= ' <input type="hidden" name="title" value="'.htmlentities($title).'" />
<input type="hidden" name="url" value="'.$url.'" />
<input type="submit" class="submit-button" name="bookmark" value="Ajouter" title="Ajouter la page courante dans la liste" />
</div>
<div class="box-link" id="bm-link">
<a href="/favoris.php" title="Pour supprimer ou changer l\'ordre des marque-pages">Gestion des marque-pages</a>
</div>
</form>
';
return $result;
}
function array_flip_values(&$array, $idx1, $idx2)
{
$tmp = $array[$idx1];
$array[$idx1] = $array[$idx2];
$array[$idx2] = $tmp;
}
function bookmark()
{
if ( (isset($_REQUEST['bookmark'])) && (isset($_REQUEST['title'])) && (isset($_REQUEST['url'])) )
{
if (get_magic_quotes_gpc())
{
$_REQUEST['url'] = stripslashes($_REQUEST['url']);
$_REQUEST['title'] = stripslashes($_REQUEST['title']);
}
$cookieValue = isset($_COOKIE[BOOKMARKS_COOKIE]) ? $_COOKIE[BOOKMARKS_COOKIE] : "";
if ($_REQUEST['bookmark'][0] == 'A')
{
if (strpos($cookieValue, SEPARATOR_ITEM.$_REQUEST['url'].SEPARATOR_URL) === false)
{
$cookieValue = $cookieValue.SEPARATOR_ITEM.$_REQUEST['url'].SEPARATOR_URL.$_REQUEST['title'];
setCookie(BOOKMARKS_COOKIE, $cookieValue, time() + (365*24*3600), "/");
$_COOKIE[BOOKMARKS_COOKIE] = $cookieValue;
}
}
}
if (isset($_REQUEST['bm-command']))
{
$id = (isset($_REQUEST['bm-id']) ? $_REQUEST['bm-id'] : 0);
$bm_list = explode(SEPARATOR_ITEM, $_COOKIE[BOOKMARKS_COOKIE]);
array_shift($bm_list);
$commandOk = true;
switch($_REQUEST['bm-command'][0])
{
case 'M':
if($id > 0)
{
array_flip_values($bm_list, $id, $id-1);
}
break;
case 'D':
if($id < (count($bm_list) - 1))
{
array_flip_values($bm_list, $id, $id+1);
}
break;
case 'S':
array_splice($bm_list,$id,1);
break;
case 'V':
$commandOk = false;
setCookie(BOOKMARKS_COOKIE, '', time() - (365*24), "/");
unset($_COOKIE[BOOKMARKS_COOKIE]);
break;
default:
$commandOk = false;
}
if ($commandOk)
{
$cookieValue = SEPARATOR_ITEM.implode(SEPARATOR_ITEM, $bm_list);
setCookie(BOOKMARKS_COOKIE, $cookieValue, time() + (365*24*3600), "/");
$_COOKIE[BOOKMARKS_COOKIE] = $cookieValue;
}
}
}
function getToBeChecked($max)
{
$id = (isset($_REQUEST['bm-id']) ? $_REQUEST['bm-id'] : 0);
if (isset($_REQUEST['bm-command']))
{
if ($_REQUEST['bm-command'][0] == 'M')
{
$id = max($id-1, 0);
}
else if ($_REQUEST['bm-command'][0] == 'D')
{
$id = min($id+1, $max);
}
}
return $id;
}
?>
Si avez des problèmes ou des questions concernant ce fichier source, vous pouvez utiliser le Forum Sources du site