array('label' => 'Example Domain', 'url' => 'http://example.com/', 'tags' => '', 'description' => 'Example Domain', 'uref' => '1831883622'), ); $aRemove = array( 0 => 'http://', 1 => 'https://', ); /*DATA-END*/ /*******************************************************************************/ /* Add/delete bookmarks */ /*******************************************************************************/ $bReWriteScript = false; // do we rewrite the script with updated data? $sNewBookmark = ''; $uploadOk = 1; $dtagFlag = 0; $deleteEverything = false; if(isset($_GET["RadioButton1"])) { if($_GET["RadioButton1"] == 'Label_and_Url') $showurl = true; else $showurl = false; } if(isset($_GET["RadioButton2"])) { if($_GET["RadioButton2"] == 'Label') $sortaccordingto = 'label'; else $sortaccordingto = 'url'; } if(isset($_GET["return"]) || isset($_GET["menu_2"])) $bReWriteScript = true; //to add functionality for 'More' button if(isset($_GET["deletetag"])) { $dtag = $_GET["dtag"]; if ($dtag == $sNoTagLabel) $dtag = ''; foreach ($aBookmarks as $key => $value) { if ($value['tags'] == $dtag) {unset($aBookmarks[$key]); $dtagFlag = 1;} else if (strstr($value['tags'], $dtag)) { $repiecetag = ''; $dtagpieces = explode(',', $value['tags']); foreach ($dtagpieces as $rrvalue) { if (!strstr($dtag, trim($rrvalue))) { $repiecetag .= trim($rrvalue) . ","; } } $repiecetag = rtrim($repiecetag, ','); $aBookmarks[$key]['tags'] = $repiecetag; //directly using $value doesn't work $dtagFlag = 1; } } $bReWriteScript = true; } if(isset($_GET["delete"])) { if(count($aBookmarks) > 0) $deleteEverything = true; unset($aBookmarks); $bReWriteScript = true; } if(isset($_POST["uploadfile"])) { $target_dir = "uploads/"; $target_file = $target_dir.basename($_FILES["fileToUpload"]["name"]); $dFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); $tagfield = trim($_POST["tagfield"]); $repiecetag = ''; $dtagpieces = explode(',', $tagfield); foreach ($dtagpieces as $tvalue) { $repiecetag .= trim($tvalue) . ","; } $repiecetag = rtrim($repiecetag, ','); $tagfield = $repiecetag; // Check file size if ($_FILES["fileToUpload"]["size"] > 500000) { $uploadError = 'Sorry, file is too large.'; $uploadOk = 0; } // Allow certain file formats if($dFileType != "htm" && $dFileType != "html") { $uploadError = 'Bad File Type or File not Present!'; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { goto exitupload; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { $uploadOk = 2; $uploadFileName = basename($_FILES["fileToUpload"]["name"]); } else { echo "Sorry, there was an error uploading your file."; exit(); } } $file = fopen($target_file , "r"); unset($aBookmarks1); $pos1 = $pos2 = $pos3 = false; while(! feof($file)) { $prev_pos1 = $pos1; $prev_pos2 = $pos2; $prev_pos3 = $pos3; $prev_anch = $anch; $prev_desc = $desc; $prev_textdesc = ''; $pos1 = $pos2 = $pos3 = false; $line = fgets($file); if($pos = stripos($line, 'A HREF=')) { $pos1 = pos; $pos = $pos + 8; $anchsta = substr($line, $pos); //anchor start $pos = stripos($anchsta, '"'); //anchor ends $anch = substr($anchsta, 0, $pos); //the anchor } if($pos1 == true) { $pos = stripos($anchsta, '>'); $pos2 = $pos; $pos = $pos + 1; $descsta = substr($anchsta, $pos); //description starts $pos = stripos($descsta, '<'); //description ends $desc = substr($descsta, 0, $pos); //the description } if($pos = stripos($line, '
')) { $pos3 = $pos; $pos = $pos + 4; $textdesc = trim(substr($line, $pos)); //textual description starts } //if $prev_pos1 true and $pos3 true and $pos1 false fill prev & present 3 if (($prev_pos1 == true) && ($pos3 == true) && ($pos1 == false)) { $aBookmarks1[] = array('label' => $prev_desc, 'url' => $prev_anch, 'tags' => $tagfield, 'description' => $textdesc); } //if $prev_pos1 true and $pos1 true and $pos3 false fill prev 2 if (($prev_pos1 == true) && ($pos1 == true) && ($pos3 == false)) { $aBookmarks1[] = array('label' => $prev_desc, 'url' => $prev_anch, 'tags' => $tagfield, 'description' => ''); } //if $prev_pos1 true and $pos1 true and $pos3 true fill both prev 2 and present 3 if (($prev_pos1 == true) && ($pos1 == true) && ($pos3 == true)) { $aBookmarks1[] = array('label' => $prev_desc, 'url' => $prev_anch, 'tags' => $tagfield, 'description' => $prev_textdesc); $aBookmarks1[] = array('label' => $desc, 'url' => $anch, 'tags' => $tagfield, 'description' => $textdesc); $pos1 = false; $pos2 = false; $pos3 = false; } //if $pos1 true and $pos3 true fill present 3 if (($pos1 == true) && ($pos3 == true)) { $aBookmarks1[] = array('label' => $desc, 'url' => $anch, 'tags' => $tagfield, 'description' => $textdesc); $pos1 = false; $pos2 = false; $pos3 = false; } //if $prev_pos1 true and $pos1 false and $pos3 false fill prev 2 if (($prev_pos1 == true) && ($pos1 == false) && ($pos3 == false)) { $aBookmarks1[] = array('label' => $prev_desc, 'url' => $prev_anch, 'tags' => $tagfield, 'description' => ''); } } //if $pos1 true fill present 2 if ($pos1 == true) { $aBookmarks1[] = array('label' => $desc, 'url' => $anch, 'tags' => $tagfield, 'description' => ''); } fclose($file); foreach ($aBookmarks1 as $key => $value) if ($value['label'] == '') unset($aBookmarks1[$key]); $aBookmarks = array_merge($aBookmarks, $aBookmarks1); $iNextIndex = count($aBookmarks); $bReWriteScript = true; exitupload: } if ($_POST['sizetext'] == ' Apply ') $bReWriteScript = true; if(isset($_GET["removelist"])) { $value = trim($_GET["removeurl"]); lp1: $value = rtrim($value, '\\'); //was breaking the script! $value = rtrim($value, '/'); if ($value[(strlen($value) - 1)] == '\\') goto lp1; if ($value[(strlen($value)-1)] == ':') $value .= '//'; if ($value != '') { $aRemove[] = $value; $aRemove = array_unique($aRemove); sort($aRemove); $stop = 1; $total = count($aRemove); while ((($aRemove[0][0] == "[") || ($aRemove[0][0] == "(")) && ($stop < $total)){ $aRemove[] = array_shift($aRemove); $stop++; } $bReWriteScript = true; } } if(isset($_GET["ureset"])) { $rrvalue = $_GET["url-reset"]; if ($rrvalue != '') { //button could be pressed without selection foreach ($aRemove as $key => $value) { if ($value == $rrvalue) unset($aRemove[$key]); } $bReWriteScript = true; } } if (isset($_GET['submit'])) { $geturl = trim($_GET['url']); $getlabel = trim($_GET['label']); $getdesc = trim($_GET['description']); $gettags = trim($_GET['tags']); $repiecetag = ''; $dtagpieces = explode(',', $gettags); foreach ($dtagpieces as &$tvalue) $tvalue = trim($tvalue); $dtagpieces = array_unique($dtagpieces); sort($dtagpieces); foreach ($dtagpieces as $tvalue) { if ($tvalue == $sNoTagLabel) $tvalue = ''; //'no-tags' is not an allowed value $repiecetag .= trim($tvalue) . ","; } $repiecetag = rtrim($repiecetag, ','); $gettags = $repiecetag; if ($getlabel == false) $getlabel = $geturl; if ($geturl == true) { $aNewBookmark = array( 'label' => $getlabel, 'url' => $geturl, 'tags' => $gettags, 'description' => $getdesc ); $aBookmarks[$iNextIndex] = $aNewBookmark; // add new bookmark at next index $iNextIndex++; // updated the index for next time $sNewBookmark = $geturl; $bReWriteScript = true; } } if (isset($_GET['uid']) && $_GET['action'] == 'delete') { $aBookmarkTags = explode(',', $aBookmarks[intval($_GET['uid'])]['tags']); // first just remove the tag from the bookmark's record (it may have more than one) foreach ($aBookmarkTags as $iIndex => $aBookmarkTag) { if ($aBookmarkTag == $_GET['tag']) { unset($aBookmarkTags[$iIndex]); } } $aBookmarks[intval($_GET['uid'])]['tags'] = implode(',', $aBookmarkTags); // if there are no more tags for this bookmark, remove the record completely if ($aBookmarks[intval($_GET['uid'])]['tags'] == '') { unset($aBookmarks[intval($_GET['uid'])]); } $bReWriteScript = true; } if ($bReWriteScript) { reset($aBookmarks); function cmp($a, $b){ return strcmp($a["tags"].$a["url"], $b["tags"].$b["url"]); } usort($aBookmarks, "cmp"); //writing this sort wasn't trivial! $checkdupvalue = '0'; $checkduptag = '0'; //eliminate duplicate entries foreach ($aBookmarks as $key => $value) { //let's give a (hopefully) unique reference to the entries... if ($aBookmarks[$key]['uref'] == '') $aBookmarks[$key]['uref'] = mt_rand(); foreach ($aRemove as $rrvalue) { //might as well eliminate unwanted urls at this point if (rtrim($rrvalue, '/') == rtrim($value['url'], '/')) {unset($aBookmarks[$key]); unset($aNewBookmark);} if (((substr($rrvalue, 0, 1) == "[") && (substr($rrvalue, -1) == "]")) || ((substr($rrvalue, 0, 1) == "(") && (substr($rrvalue, -1) == ")"))) { if (strstr($value['url'], trim($rrvalue, "[]()/"))) {unset($aBookmarks[$key]); unset($aNewBookmark);} } } if (($value['url'] == $checkdupvalue) && ($value['tags'] == $checkduptag)) unset($aBookmarks[$key]); else {$checkdupvalue = $value['url']; $checkduptag = $value['tags'];} } $sScriptContents = file_get_contents($sScriptName); // get the contents of this very file $sPreData = substr($sScriptContents, 0, strpos($sScriptContents, '/*DATA-START*/') + strlen('/*DATA-START*/')); // grab everything AFTER /*DATA-START*/ $sAftData = substr($sScriptContents, strpos($sScriptContents, '/*DATA-END*/')); // grab everything UP TO /*DATA-END*/ $sNewData = "\n"; // build new data (as PHP) to insert in the middle $sNewData .= "\t" . '$fSize = ' . ($_POST['fSize'] ? $_POST['fSize'] : $fSize) . ';' . "\n"; $sNewData .= "\t" . '$sortaccordingto = \'' . $sortaccordingto . '\';' . "\n"; $sNewData .= "\t" . '$showurl = ' . ($showurl ? 'true' : 'false') . ';' . "\n"; $sNewData .= "\t" . '$iNextIndex = ' . $iNextIndex . ';' . "\n"; $sNewData .= "\t" . '$aBookmarks = array(' . "\n"; foreach ($aBookmarks as $iIndex => $aBookmark) { $sNewData .= "\t\t" . $iIndex . ' => array(\'label\' => \'' . str_replace('\'', '\\\'', $aBookmark['label']) . '\', \'url\' => \'' . str_replace('\'', '\\\'', $aBookmark['url']) . '\', \'tags\' => \'' . str_replace('\'', '\\\'', $aBookmark['tags']) . '\', \'description\' => \'' . str_replace('\'', '\\\'', $aBookmark['description']) . '\', \'uref\' => \'' . $aBookmark['uref'] . '\'),' . "\n"; } $sNewData .= "\t" . ');' . "\n"; $sNewData .= "\t" . '$aRemove = array(' . "\n"; foreach ($aRemove as $key => $value) { $sNewData .= "\t\t" . $key . ' => \'' . str_replace('\'', '\\\'', $value) . '\',' . "\n"; } $sNewData .= "\t" . ');' . "\n\t"; if ($bEnableBackups) { file_put_contents($bBackupFilename, $sScriptContents); // if condfigured to do so, save a copy of current script before overwriting } file_put_contents($sScriptName, $sPreData . $sNewData . $sAftData); // overwrite current script file with new data } /*******************************************************************************/ /* Build a tags array from tags used in bookmarks data, sort alphabetically */ /*******************************************************************************/ $aTags = array(); foreach ($aBookmarks as $aBookmark) { if ($aBookmark['tags'] != '') { $aBookmarkTags = explode(',', $aBookmark['tags']); $aTags = array_merge($aTags, $aBookmarkTags); } } $aTags = array_unique($aTags); sort($aTags); array_unshift($aTags, $sNoTagLabel); /*******************************************************************************/ /* Identify current tag, default to no-tags */ /*******************************************************************************/ $sCurrentTag = $sNoTagLabel; if ($_GET['tag'] != '' && in_array($_GET['tag'], $aTags)) { $sCurrentTag = $_GET['tag']; } else if ($_POST['tag'] != '' && in_array($_POST['tag'], $aTags)) { $sCurrentTag = $_POST['tag']; } if (isset($_GET['menu_1']) || isset($_POST['menu_1']) || isset($_GET['deletetag']) || isset($_GET['delete'])) $inMenu1 = true; else $inMenu1 = false; if (isset($_GET['menu_2']) || isset($_POST['fSize']) || isset($_GET['removelist']) || isset($_GET['ureset'])) $inMenu2 = true; else $inMenu2 = false; if ($inMenu1 == false && $inMenu2 == false) $inMain = true; else $inMain = false; ?> <?php echo htmlentities($sPageTitle); ?> '; echo '' . "\n"; echo '
' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; echo '
'; echo "\n"; $aCurrentTagBookmarks = array(); foreach ($aBookmarks as $iIndex => $aBookmark) { $aBookmarkTags = explode(',', $aBookmark['tags']); if (in_array($sCurrentTag, $aBookmarkTags) || ($aBookmark['tags'] == '' && $sCurrentTag == $sNoTagLabel)) { // here we use the label and uid (to maintain uniqueness) as the key instead so it's easier to sort later if ($sortaccordingto == 'label') { $aCurrentTagBookmarks[($aBookmark['label'] . $iIndex)] = array( //sorting according to label 'uid' => $iIndex, 'label' => $aBookmark['label'], 'url' => $aBookmark['url'], 'description' => $aBookmark['description'], 'uref' => $aBookmark['uref'] ); } if ($sortaccordingto == 'url') { $aCurrentTagBookmarks[($aBookmark['url'] . $iIndex)] = array( //sorting according to url 'uid' => $iIndex, 'label' => $aBookmark['label'], 'url' => $aBookmark['url'], 'description' => $aBookmark['description'], 'uref' => $aBookmark['uref'] ); } } } //ksort($aCurrentTagBookmarks); uksort($aCurrentTagBookmarks, 'strnatcasecmp'); if (sizeof($aCurrentTagBookmarks) > 0) { echo "\t" . '' . "\n"; } else { echo "\t" . '

No bookmarks in "' . htmlentities($sCurrentTag) . '".

' . "\n"; } echo "\t"; } ?>

User: Guest_001

Upload Bookmarks File
(from Firefox, SeaMonkey, etc...)
 
Add Single Bookmarks
Delete Multiple Entries
END; echo "\n"; echo ' ' . "\n"; echo <<
⚠Use these buttons with caution!
Display Options
' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; echo '
END; echo ' ' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; echo '
' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; echo <<
More Options      
Return to Main     
 
END; if ($aNewBookmark) { echo '
The following URL: ' . $aNewBookmark['url'] . ' was added to Bookmarks within: '; if ($aNewBookmark['tags']) echo $aNewBookmark['tags']; else echo $sNoTagLabel; echo '
'; } else if($sNewBookmark) { echo '
The following URL: ' . $sNewBookmark . ' was not added to Bookmarks because it is present in the remove list.
'; } if ($uploadOk == 0) { echo '
Upload Error: ' . $uploadError . '
'; } if ($uploadOk == 2) { echo '
The file \'' . $uploadFileName . '\' has been uploaded within: '; if ($tagfield) echo $tagfield; else echo $sNoTagLabel; echo '
'; } if ($dtagFlag == 1) { if ($dtag == '') $dtag = $sNoTagLabel; echo '
Tag \'' . $dtag . '\' has been emptied.
'; } if ($deleteEverything) { echo '
Everything was Deleted!
'; } } //END OF 'if ($inMenu1)' if ($inMenu2) { $target_dir = "./"; $target_name = 'Bookmarks_' . date("mdy") . '.html'; //to be used where there is no zip support $target_zip = 'Bkmks_' . date("mdy") . '.zip'; $target_file = $target_dir . $target_zip; $downloadOk = 1; $sNewData = '' . "\n"; $sNewData .='' . "\n"; $sNewData .='Bookmarks' . "\n"; $sNewData .='

Bookmarks

' . "\n"; $sNewData .='

' . "\n"; $lenBeforeNewData = strlen($sNewData); if (isset($_GET['downloadbookmarksall'])) { if ($sortaccordingto == 'label') { function cmp_($a, $b){ return strcmp($a["label"], $b["label"]); } usort($aBookmarks, "cmp_"); } if ($sortaccordingto == 'url') { function cmp_($a, $b){ return strcmp($a["url"], $b["url"]); } usort($aBookmarks, "cmp_"); } foreach ($aBookmarks as $value) { $sNewData .= '

' . $value['label'] . '' . ($value['description'] ? '
' . $value['description']:'') . "\n"; } $lenAfterNewData = strlen($sNewData); if($lenAfterNewData > $lenBeforeNewData) $outputzip = true; } if (isset($_GET['downloadbookmarks'])) { $sDownloadTag = $_GET["dtag"]; unset($aCurrentTagBookmarks); $aCurrentTagBookmarks = array(); foreach ($aBookmarks as $iIndex => $aBookmark) { $aBookmarkTags = explode(',', $aBookmark['tags']); if (in_array($sDownloadTag, $aBookmarkTags) || ($aBookmark['tags'] == '' && $sDownloadTag == $sNoTagLabel)) { // here we use the label and uid (to maintain uniqueness) as the key instead so it's easier to sort later if ($sortaccordingto == 'label') { $aCurrentTagBookmarks[($aBookmark['label'] . $iIndex)] = array( //sorting according to label 'uid' => $iIndex, 'label' => $aBookmark['label'], 'url' => $aBookmark['url'], 'description' => $aBookmark['description'] ); } if ($sortaccordingto == 'url') { $aCurrentTagBookmarks[($aBookmark['url'] . $iIndex)] = array( //sorting according to url 'uid' => $iIndex, 'label' => $aBookmark['label'], 'url' => $aBookmark['url'], 'description' => $aBookmark['description'] ); } } } //ksort($aCurrentTagBookmarks); uksort($aCurrentTagBookmarks, 'strnatcasecmp'); foreach ($aCurrentTagBookmarks as $value) { $sNewData .= '
' . $value['label'] . '' . ($value['description'] ? '
' . $value['description']:'') . "\n"; } $lenAfterNewData = strlen($sNewData); if($lenAfterNewData > $lenBeforeNewData) $outputzip = true; } $sNewData .='

' . "\n"; if ($outputzip) { //file_put_contents($target_dir . $target_name, $sNewData); //to be used where there is no zip support $zip = new ZipArchive(); $zipFileName = $target_zip; $opened = $zip->open( $zipFileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE ); if( $opened !== true ){ die("cannot open {$zipFileName} for writing."); } $zip->addFromString( "bookmarks.html", $sNewData); $zip->close(); } if (isset($_POST['fSize'])) {$fSizeOld = $fSize; $fSize = $_POST['fSize'];} if ($_POST['sizetext'] == 'Increase') {$fSize++; if ($fSize == 12) $fSize++;} if ($_POST['sizetext'] == 'Decrease') {$fSize--; if ($fSize == 12) $fSize--;} echo <<

User: Guest_001

END; if ($outputzip){ echo "\t\t\t\t\t\t\t\t\t\t\t" . '' . "\n"; echo "\t\t\t\t\t\t\t\t\t\t" . '' . "\n"; echo "\t\t\t\t\t\t\t\t\t" . '
Download Bookmarks File
END; echo "\n"; echo ' ' . "\n"; echo <<
OR
 
' . "\n"; echo "\t\t\t\t\t\t\t\t\t\t\t" . 'If download does not start automatically click
this link: ' . $target_zip . '' . "\n"; } else if($_GET['downloadbookmarks'] || $_GET['downloadbookmarksall']){ echo "\t\t\t\t\t\t\t\t\t\t\t" . '
' . "\n"; echo "\t\t\t\t\t\t\t\t\t\t\t" . 'Tag is Empty!' . "\n"; } else echo "\t\t\t\t\t\t\t\t\t\t\t" . '' . "\n"; echo "\t\t\t\t\t\t\t\t\t\t\t" . '
'; echo '
' . "\n"; echo <<
Adjust Text Size
  • Text Text Text Text
    Link Link Link Link
    Text Text Text Text
  • Refreshing... END; if (($_POST['sizetext'] == ' Apply ') && ($fSizeOld != $fSize)) echo 'Text Size Changed!' . "\n"; echo <<
    END; echo ' 15) echo ' disabled'; echo '>    ' . "\n"; echo '     ' . "\n"; echo '    ' . "\n"; echo ' ' . "\n"; echo '
    Auto Remove the following URLs:

    Previous Options
    Return to Main     
     
    END; } //END OF 'if ($inMenu2)' ?> '; echo 'setTimeout(function(){window.location = "./' . $target_zip . '"}, 1000);'; //echo 'window.location = "./' . $target_zip . '"'; echo '' . "\n"; } ?>