~ubuntu-branches/ubuntu/raring/extplorer/raring-proposed

« back to all changes in this revision

Viewing changes to include/bookmarks.php

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Goirand
  • Date: 2010-07-05 19:53:12 UTC
  • Revision ID: james.westby@ubuntu.com-20100705195312-i92s1udelus7gl52
Tags: upstream-2.1.0b6+dfsg
ImportĀ upstreamĀ versionĀ 2.1.0b6+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// ensure this file is being included by a parent file
 
3
if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' );
 
4
/**
 
5
 * @version $Id: bookmarks.php 158 2009-11-10 08:07:05Z soeren $
 
6
 * @package eXtplorer
 
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)
 
10
 * 
 
11
 * @license
 
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/
 
16
 * 
 
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
 
20
 * under the License.
 
21
 * 
 
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."
 
32
 * 
 
33
*/
 
34
/**
 
35
 * reads all bookmarks from the bookmark ini file
 
36
 *
 
37
 * @return array
 
38
 */
 
39
 
 
40
 
 
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';
 
48
                } else {
 
49
                        $bookmarkfile .= $mainframe->getUserName().'.php';
 
50
                }
 
51
        } else {
 
52
                $bookmarkfile .= $my->id . '.php';
 
53
        }
 
54
        if( file_exists( $bookmarkfile )) {
 
55
                return parse_ini_file( $bookmarkfile );
 
56
        }
 
57
        else {
 
58
                if( !is_writable( dirname( $bookmarkfile ) ) && !chmod( dirname( $bookmarkfile ), 0777 )) {
 
59
                        return array( $GLOBALS['messages']['homelink'] => '' );
 
60
                } else {
 
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'] => '' );
 
63
                }
 
64
        }
 
65
}
 
66
 
 
67
function strip_invalid_key_char($s, $replacement ="") {
 
68
  return preg_replace('/[{}|&~![()"]/u', $replacement, $s);
 
69
}
 
70
 
 
71
/**
 
72
 * Adds a new bookmark to the bookmark ini file
 
73
 *
 
74
 * @param string $dir
 
75
 */
 
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';
 
85
                } else {
 
86
                        $bookmarkfile .= $mainframe->getUserName().'.php';
 
87
                }
 
88
        } else {
 
89
                $bookmarkfile .= $my->id . '.php';
 
90
        }
 
91
        while( @ob_end_clean() );
 
92
 
 
93
        header( "Status: 200 OK" );
 
94
 
 
95
        switch ( $task ) {
 
96
                case 'add':
 
97
 
 
98
                        if( in_array( $dir, $bookmarks )) {
 
99
                                echo ext_alertBox( $GLOBALS['messages']['already_bookmarked'] ); exit;
 
100
                        }
 
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'] );
 
105
                        break;
 
106
 
 
107
                case 'remove':
 
108
 
 
109
                        if( !in_array( $dir, $bookmarks )) {
 
110
                                echo ext_alertBox( $GLOBALS['messages']['not_a_bookmark'] ); exit;
 
111
                        }
 
112
                        $bookmarks = array_flip( $bookmarks );
 
113
                        unset( $bookmarks[$dir] );
 
114
                        $bookmarks = array_flip( $bookmarks );
 
115
                        $msg = ext_successBox( $GLOBALS['messages']['bookmark_was_removed'] );
 
116
        }
 
117
 
 
118
        $inifile = "; <?php if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' ); ?>\n";
 
119
        $inifile .= $GLOBALS['messages']['homelink']."=\n";
 
120
 
 
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";
 
125
        }
 
126
        if( !is_writable( $bookmarkfile )) {
 
127
                echo ext_alertBox( sprintf( $GLOBALS['messages']['bookmarkfile_not_writable'], $task, $bookmarkfile ) ); exit;
 
128
        }
 
129
        file_put_contents( $bookmarkfile, $inifile );
 
130
 
 
131
        echo $msg;
 
132
        echo list_bookmarks($dir);
 
133
        exit;
 
134
}
 
135
 
 
136
/**
 
137
 * Lists all bookmarked directories in a dropdown list.
 
138
 *
 
139
 * @param string $dir
 
140
 */
 
141
function list_bookmarks( $dir ) {
 
142
 
 
143
        $bookmarks = read_bookmarks();
 
144
        $bookmarks = array_flip($bookmarks);
 
145
 
 
146
        foreach( $bookmarks as $bookmark ) {
 
147
                $len = strlen( $bookmark );
 
148
                if( $len > 40 ) {
 
149
                        $first_part = substr( $bookmark, 0, 20 );
 
150
                        $last_part = substr( $bookmark, -20 );
 
151
                        $bookmarks[$bookmark] = $first_part . '...' . $last_part;
 
152
                }
 
153
        }
 
154
 
 
155
 
 
156
        $html = $GLOBALS['messages']['quick_jump'].': ';
 
157
        if( !empty($dir[0]) && @$dir[0] == '/' ) {
 
158
                $dir = substr( $dir, 1);
 
159
        }
 
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" />';
 
163
 
 
164
        $addlink=$removelink='';
 
165
 
 
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']) .'\', '
 
173
                                        .'scripts: true, '
 
174
                                        .'params: { '
 
175
                                                .'action:\'modify_bookmark\', '
 
176
                                                .'task: \'add\', '
 
177
                                                .'requestType: \'xmlhttprequest\', '
 
178
                                                .'alias: text, '
 
179
                                                .'dir: \''.$dir.'\', '
 
180
                                                .'option: \'com_extplorer\' '
 
181
                                        .'} '
 
182
                                .'}); '
 
183
                        .'}'
 
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']) .'\', '
 
192
                                        .'scripts: true, '
 
193
                                        .'params: { '
 
194
                                                .'action:\'modify_bookmark\', '
 
195
                                                .'task: \'remove\', '
 
196
                                                .'dir: \''.$dir.'\', '
 
197
                                                .'option: \'com_extplorer\' '
 
198
                                        .'} '
 
199
                                .'}); '
 
200
                        .'}'
 
201
                .'}); return false;" title="'.$GLOBALS['messages']['lbl_remove_bookmark'].'">'.$img_remove.'</a>';
 
202
        }
 
203
 
 
204
        $html .= $addlink .'&nbsp;'.$removelink;
 
205
 
 
206
        return $html;
 
207
}
 
208
 
 
209
?>
 
 
b'\\ No newline at end of file'