id )) { if( class_exists('jfactory') ) { $user = JFactory::getUser(); $bookmarkfile .= $user->get('id').'.php'; } else { $bookmarkfile .= $mainframe->getUserName().'.php'; } } else { $bookmarkfile .= $my->id . '.php'; } if( file_exists( $bookmarkfile )) { return parse_ini_file( $bookmarkfile ); } else { if( !is_writable( dirname( $bookmarkfile ) ) && !chmod( dirname( $bookmarkfile ), 0777 )) { return array( $GLOBALS['messages']['homelink'] => '' ); } else { file_put_contents( $bookmarkfile, ";\n{$GLOBALS['messages']['homelink']}=\n" ); return array( $GLOBALS['messages']['homelink'] => '' ); } } } function strip_invalid_key_char($s, $replacement ="") { return preg_replace('/[{}|&~![()"]/u', $replacement, $s); } /** * Adds a new bookmark to the bookmark ini file * * @param string $dir */ function ext_modify_bookmark( $task, $dir ) { global $my, $user, $mainframe; $alias = substr( extGetParam($_REQUEST,'alias'), 0, 150 ); // CSRF Security Check if( !ext_checkToken($GLOBALS['__POST']["token"]) ) { ext_Result::sendResult('tokencheck', false, 'Request failed: Security Token not valid.'); } $bookmarks = read_bookmarks(); $bookmarkfile = _EXT_PATH.'/config/bookmarks_'.$GLOBALS['file_mode'].'_'; if( empty( $my->id )) { if( class_exists('jfactory') ) { $user = JFactory::getUser(); $bookmarkfile .= $user->get('id').'.php'; } else { $bookmarkfile .= $mainframe->getUserName().'.php'; } } else { $bookmarkfile .= $my->id . '.php'; } while( @ob_end_clean() ); header( "Status: 200 OK" ); switch ( $task ) { case 'add': if( in_array( $dir, $bookmarks )) { echo ext_alertBox( $GLOBALS['messages']['already_bookmarked'] ); exit; } //$alias = preg_replace('~[^\w-.\/\\\]~','', $alias ); // Make the alias ini-safe by removing all non-word characters $alias = strip_invalid_key_char($alias, "_"); $bookmarks[$alias] = $dir; //we deal with the flippped array here $msg = ext_successBox( $GLOBALS['messages']['bookmark_was_added'] ); break; case 'remove': if( !in_array( $dir, $bookmarks )) { echo ext_alertBox( $GLOBALS['messages']['not_a_bookmark'] ); exit; } $bookmarks = array_flip( $bookmarks ); unset( $bookmarks[$dir] ); $bookmarks = array_flip( $bookmarks ); $msg = ext_successBox( $GLOBALS['messages']['bookmark_was_removed'] ); } $inifile = "; \n"; $inifile .= $GLOBALS['messages']['homelink']."=\n"; foreach( $bookmarks as $alias => $directory ) { //changed by pokemon if( empty( $directory ) || empty( $alias ) ) continue; if( $directory[0] == $GLOBALS['separator']) $directory = substr( $directory, 1 ); $inifile .= "$alias=$directory\n"; } if( !is_writable( $bookmarkfile )) { echo ext_alertBox( sprintf( $GLOBALS['messages']['bookmarkfile_not_writable'], $task, $bookmarkfile ) ); exit; } file_put_contents( $bookmarkfile, $inifile ); echo $msg; echo ext_list_bookmarks($dir); exit; } /** * Lists all bookmarked directories in a dropdown list. * * @param string $dir */ function ext_list_bookmarks( $dir ) { $bookmarks = read_bookmarks(); $bookmarks = array_flip($bookmarks); foreach( $bookmarks as $bookmark ) { $len = strlen( $bookmark ); if( $len > 40 ) { $first_part = substr( $bookmark, 0, 20 ); $last_part = substr( $bookmark, -20 ); $bookmarks[$bookmark] = $first_part . '...' . $last_part; } } $html = $GLOBALS['messages']['quick_jump'].': '; if( !empty($dir[0]) && @$dir[0] == '/' ) { $dir = substr( $dir, 1); } $html .= ext_selectList( 'favourites', $dir, $bookmarks, 1, '', 'onchange="chDir( this.options[this.options.selectedIndex].value);" style="max-width: 200px;"'); $img_add = ''.$GLOBALS['messages']['lbl_add_bookmark'].''; $img_remove = ''.$GLOBALS['messages']['lbl_remove_bookmark'].''; $addlink=$removelink=''; if( !isset( $bookmarks[$dir] ) && $dir != '' && $dir != '/' ) { $addlink = ''.$img_add.''; } elseif( $dir != '' && $dir != '/' ) { $removelink = ''.$img_remove.''; } $html .= $addlink .' '.$removelink; return $html; } ?>