2
// ensure this file is being included by a parent file
3
if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' );
5
* @version $Id: bookmarks.php 158 2009-11-10 08:07:05Z soeren $
7
* @copyright soeren 2007-2009
8
* @author The eXtplorer project (http://sourceforge.net/projects/extplorer)
9
* @author The The QuiX project (http://quixplorer.sourceforge.net)
12
* The contents of this file are subject to the Mozilla Public License
13
* Version 1.1 (the "License"); you may not use this file except in
14
* compliance with the License. You may obtain a copy of the License at
15
* http://www.mozilla.org/MPL/
17
* Software distributed under the License is distributed on an "AS IS"
18
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
19
* License for the specific language governing rights and limitations
22
* Alternatively, the contents of this file may be used under the terms
23
* of the GNU General Public License Version 2 or later (the "GPL"), in
24
* which case the provisions of the GPL are applicable instead of
25
* those above. If you wish to allow use of your version of this file only
26
* under the terms of the GPL and not to allow others to use
27
* your version of this file under the MPL, indicate your decision by
28
* deleting the provisions above and replace them with the notice and
29
* other provisions required by the GPL. If you do not delete
30
* the provisions above, a recipient may use your version of this file
31
* under either the MPL or the GPL."
35
* reads all bookmarks from the bookmark ini file
41
function read_bookmarks() {
42
global $my, $mainframe;
43
$bookmarkfile = _EXT_PATH.'/config/bookmarks_'.$GLOBALS['file_mode'].'_';
44
if( empty( $my->id )) {
45
if( class_exists('jfactory') ) {
46
$user = JFactory::getUser();
47
$bookmarkfile .= $user->get('id').'.php';
49
$bookmarkfile .= $mainframe->getUserName().'.php';
52
$bookmarkfile .= $my->id . '.php';
54
if( file_exists( $bookmarkfile )) {
55
return parse_ini_file( $bookmarkfile );
58
if( !is_writable( dirname( $bookmarkfile ) ) && !chmod( dirname( $bookmarkfile ), 0777 )) {
59
return array( $GLOBALS['messages']['homelink'] => '' );
61
file_put_contents( $bookmarkfile, ";<?php if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' ); ?>\n{$GLOBALS['messages']['homelink']}=\n" );
62
return array( $GLOBALS['messages']['homelink'] => '' );
67
function strip_invalid_key_char($s, $replacement ="") {
68
return preg_replace('/[{}|&~![()"]/u', $replacement, $s);
72
* Adds a new bookmark to the bookmark ini file
76
function modify_bookmark( $task, $dir ) {
77
global $my, $user, $mainframe;
78
$alias = substr( extGetParam($_REQUEST,'alias'), 0, 150 );
79
$bookmarks = read_bookmarks();
80
$bookmarkfile = _EXT_PATH.'/config/bookmarks_'.$GLOBALS['file_mode'].'_';
81
if( empty( $my->id )) {
82
if( class_exists('jfactory') ) {
83
$user = JFactory::getUser();
84
$bookmarkfile .= $user->get('id').'.php';
86
$bookmarkfile .= $mainframe->getUserName().'.php';
89
$bookmarkfile .= $my->id . '.php';
91
while( @ob_end_clean() );
93
header( "Status: 200 OK" );
98
if( in_array( $dir, $bookmarks )) {
99
echo ext_alertBox( $GLOBALS['messages']['already_bookmarked'] ); exit;
101
//$alias = preg_replace('~[^\w-.\/\\\]~','', $alias ); // Make the alias ini-safe by removing all non-word characters
102
$alias = strip_invalid_key_char($alias, "_");
103
$bookmarks[$alias] = $dir; //we deal with the flippped array here
104
$msg = ext_successBox( $GLOBALS['messages']['bookmark_was_added'] );
109
if( !in_array( $dir, $bookmarks )) {
110
echo ext_alertBox( $GLOBALS['messages']['not_a_bookmark'] ); exit;
112
$bookmarks = array_flip( $bookmarks );
113
unset( $bookmarks[$dir] );
114
$bookmarks = array_flip( $bookmarks );
115
$msg = ext_successBox( $GLOBALS['messages']['bookmark_was_removed'] );
118
$inifile = "; <?php if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' ); ?>\n";
119
$inifile .= $GLOBALS['messages']['homelink']."=\n";
121
foreach( $bookmarks as $alias => $directory ) { //changed by pokemon
122
if( empty( $directory ) || empty( $alias ) ) continue;
123
if( $directory[0] == $GLOBALS['separator']) $directory = substr( $directory, 1 );
124
$inifile .= "$alias=$directory\n";
126
if( !is_writable( $bookmarkfile )) {
127
echo ext_alertBox( sprintf( $GLOBALS['messages']['bookmarkfile_not_writable'], $task, $bookmarkfile ) ); exit;
129
file_put_contents( $bookmarkfile, $inifile );
132
echo list_bookmarks($dir);
137
* Lists all bookmarked directories in a dropdown list.
141
function list_bookmarks( $dir ) {
143
$bookmarks = read_bookmarks();
144
$bookmarks = array_flip($bookmarks);
146
foreach( $bookmarks as $bookmark ) {
147
$len = strlen( $bookmark );
149
$first_part = substr( $bookmark, 0, 20 );
150
$last_part = substr( $bookmark, -20 );
151
$bookmarks[$bookmark] = $first_part . '...' . $last_part;
156
$html = $GLOBALS['messages']['quick_jump'].': ';
157
if( !empty($dir[0]) && @$dir[0] == '/' ) {
158
$dir = substr( $dir, 1);
160
$html .= ext_selectList( 'favourites', $dir, $bookmarks, 1, '', 'onchange="chDir( this.options[this.options.selectedIndex].value);" style="max-width: 200px;"');
161
$img_add = '<img src="'._EXT_URL.'/images/_bookmark_add.png" border="0" alt="'.$GLOBALS['messages']['lbl_add_bookmark'].'" align="absmiddle" />';
162
$img_remove = '<img src="'._EXT_URL.'/images/_remove.png" border="0" alt="'.$GLOBALS['messages']['lbl_remove_bookmark'].'" align="absmiddle" />';
164
$addlink=$removelink='';
166
if( !isset( $bookmarks[$dir] ) && $dir != '' && $dir != '/' ) {
167
$addlink = '<a href="'.make_link('modify_bookmark', $dir ).'&task=add" onclick="'
168
.'Ext.Msg.prompt(\''.ext_Lang::msg('lbl_add_bookmark',true).'\', \''.ext_Lang::msg('enter_alias_name', true ).':\', '
169
.'function(btn, text){ '
170
.'if (btn == \'ok\') { '
171
.'Ext.get(\'bookmark_container\').load({ '
172
.'url: \''. basename( $GLOBALS['script_name']) .'\', '
175
.'action:\'modify_bookmark\', '
177
.'requestType: \'xmlhttprequest\', '
179
.'dir: \''.$dir.'\', '
180
.'option: \'com_extplorer\' '
184
.'}); return false;" title="'.$GLOBALS['messages']['lbl_add_bookmark'].'" >'.$img_add.'</a>';
185
} elseif( $dir != '' && $dir != '/' ) {
186
$removelink = '<a href="'.make_link('modify_bookmark', $dir ).'&task=remove" onclick="'
187
.'Ext.Msg.confirm(\''.ext_Lang::msg('lbl_remove_bookmark', true ).'\',\''.ext_Lang::msg('lbl_remove_bookmark', true ).'?\', '
188
.'function(btn, text){ '
189
.'if (btn == \'yes\') { '
190
.'Ext.get(\'bookmark_container\').load({ '
191
.'url: \''. basename( $GLOBALS['script_name']) .'\', '
194
.'action:\'modify_bookmark\', '
195
.'task: \'remove\', '
196
.'dir: \''.$dir.'\', '
197
.'option: \'com_extplorer\' '
201
.'}); return false;" title="'.$GLOBALS['messages']['lbl_remove_bookmark'].'">'.$img_remove.'</a>';
204
$html .= $addlink .' '.$removelink;
b'\\ No newline at end of file'