/[drupal]/contributions/modules/outline_designer/outline_designer.module
ViewVC logotype

Contents of /contributions/modules/outline_designer/outline_designer.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.13 - (show annotations) (download) (as text)
Thu Feb 19 19:31:55 2009 UTC (9 months ago) by btopro
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-RC3, HEAD
Changes since 1.12: +91 -20 lines
File MIME type: text/x-php
Fixed permission escalation issues and made a few patches
1 <?php
2 // $Id: outline_designer.module,v 1.12 2009/02/13 16:32:29 btopro Exp $
3 //ELMS: Outline Designer - Usability improvements for speedy outline creation in Drupal 6.x
4 //Copyright (C) 2008 The Pennsylvania State University
5 //
6 //Bryan Ollendyke
7 //bto108@psu.edu
8 //
9 //Keith D. Bailey
10 //kdb163@psu.edu
11 //
12 //12 Borland
13 //University Park, PA 16802
14 //
15 //This program is free software; you can redistribute it and/or modify
16 //it under the terms of the GNU General Public License as published by
17 //the Free Software Foundation; either version 2 of the License, or
18 //(at your option) any later version.
19
20 //This program is distributed in the hope that it will be useful,
21 //but WITHOUT ANY WARRANTY; without even the implied warranty of
22 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 //GNU General Public License for more details.
24
25 //You should have received a copy of the GNU General Public License along
26 //with this program; if not, write to the Free Software Foundation, Inc.,
27 //51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28
29 /**
30 * @file
31 * Massive usability improvement for quickly structuring / creating content.
32 *
33 * This lets you build out content quickly while obeying permissions.
34 */
35
36 /**
37 * Implementation of hook_init().
38 */
39 function outline_designer_init() {
40 if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'book' && arg(3) != '' && arg(3) != 'list' && arg(3) != 'settings' && arg(3) != 'outline_designer') {
41 drupal_add_css(drupal_get_path('module','outline_designer') .'/outline_designer.css');
42 drupal_add_js(drupal_get_path('module', 'outline_designer') .'/jquery.contextmenu.js');
43 drupal_add_js(drupal_get_path('module', 'outline_designer') .'/scripts.js','footer');
44 //still a weird issue with clean URLS needing to be turned off just to be safe
45 variable_set('clean_url','0');
46 //these are the misc javascript libraries that normally don't get included but we need to cause things ar einine
47 drupal_add_js('misc/jquery.form.js');
48 drupal_add_js('misc/ahah.js');
49 drupal_add_js('misc/progress.js');
50 drupal_add_js('misc/autocomplete.js');
51 drupal_add_js('misc/collapse.js');
52 drupal_add_js('misc/textarea.js');
53
54 //include thickbox which is required
55 _thickbox_doheader();
56
57 //Select only those that the book module say can be outlined
58 $types_ary = variable_get('book_allowed_types',array('page'));
59
60 //make sure default is allowed by this user
61 if (user_access(_outline_designer_get_pstr('create',variable_get('book_child_type','book')))) {
62 $default_type = variable_get('book_child_type','book');
63 }
64 else {
65 foreach ($types_ary as $current_type) {
66 if (user_access(_outline_designer_get_pstr('create',$current_type))) {
67 $default_type = $current_type;
68 }
69 }
70 }
71 //all paths passed to JS should have a trailing / by convention
72 $js = 'var factor = 1;
73 var DRUPAL_PATH = "'. base_path() .'";
74 var AJAX_PATH = "'. base_path() .'?q=outline_designer/ajax/";
75 var OD_PATH = "'. base_path() . drupal_get_path('module', 'outline_designer') .'/";
76 var OD_TYPES = Array();
77 var active_nid = "";
78 var ROOT_NID = "'. arg(3) .'";
79 var BOOK_DEFAULT_TYPE = "'. $default_type .'";
80 //build out the context menu options, very easy to add to!
81 var menu1 = [
82 {"Node":{icon: "'. base_path() . drupal_get_path('module', 'outline_designer') .'/images/node.png", disabled:true}},
83 $.contextMenu.separator,
84 {"Add Child":{ onclick:function(menuItem,menu) { od_add_child(); }, icon: "'. base_path() . drupal_get_path('module', 'outline_designer') .'/images/add.png", disabled:false } },
85 {"Edit":{ onclick:function(menuItem,menu) { od_edit(); }, icon: "'. base_path() . drupal_get_path('module', 'outline_designer') .'/images/edit.png", disabled:false } },
86 {"Rename":{ onclick:function(menuItem,menu) { od_rename(); }, icon: "'. base_path() . drupal_get_path('module', 'outline_designer') .'/images/rename.png", disabled:false } },
87 {"Duplicate":{ onclick:function(menuItem,menu) { od_duplicate(); }, icon: "'. base_path() . drupal_get_path('module', 'outline_designer') .'/images/duplicate.png", disabled:false } },
88 {"Delete":{ onclick:function(menuItem,menu) { od_delete(); }, icon: "'. base_path() . drupal_get_path('module', 'outline_designer') .'/images/delete.png", disabled:false } },
89 {"Change Type":{ onclick:function(menuItem,menu) { od_change_type(); }, icon: "'. base_path() . drupal_get_path('module', 'outline_designer') .'/images/change.png", disabled:false } },
90 {"Permissions":{ onclick:function(menuItem,menu) { od_permissions(); }, icon: "'. base_path() . drupal_get_path('module', 'outline_designer') .'/images/node.png", disabled:false } },
91
92 ];
93 var active_type = BOOK_DEFAULT_TYPE;' . "\n";
94 //make sure the user can submit these types via permissions
95 $types_allowed = "type=''";
96 for ($i=0; $i<count($types_ary); $i++) {
97 $types_allowed.=" OR type='". $types_ary[$i] ."'";
98 }
99 $ajax_ary = variable_get('ajax_types_default',array());
100 $result = db_query("SELECT type,name FROM {node_type} WHERE $types_allowed ORDER BY name");
101 while ($value = db_fetch_array($result)) {
102 //ensure there is no permission escalation being able to change to types they aren't allowed to
103 if (user_access(_outline_designer_get_pstr('create', $value['type']))) {
104 $js.= 'OD_TYPES["'. $value['type'] .'"] = Array("'. $value['name'] .'","'. variable_get("outline_designer_". $value['type'] ."_icon", drupal_get_path('module', 'outline_designer') ."/images/node.png") .'");'. "\n";
105 }
106 if( !isset($ajax_ary[$value['type'] . '_node_form']) ) {
107 $ajax_ary[$value['type'] . '_node_form'] = $value['type'] . '_node_form';
108 }
109 }
110 variable_set('ajax_types_default',$ajax_ary);
111 drupal_add_js($js,'inline');
112 //add in TinyMCE support if the module exists
113 if (module_exists('tinymce')) {
114 drupal_add_js(drupal_get_path('module', 'tinymce') .'/tinymce/jscripts/tiny_mce/tiny_mce.js');
115 tinymce_process_textarea('');
116 }
117 }
118 elseif (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'book' && (arg(3) == '' || arg(3) == 'list') ) {
119 drupal_add_css(drupal_get_path('module','outline_designer') .'/outline_designer.css');
120 $js = '
121 function od_add_book(){
122 window.location="'. base_path() .'?q=node/add/'. variable_get('book_child_type','book') .'&edit[book][bid]=new";
123 }
124 $(document).ready(function(){$(".sticky-table").parent().prepend('."'".'<div style="width:120px;" class="context-menu context-menu-theme-human"><div title="" class="context-menu-item"><div style="background-image: url('. base_path() . drupal_get_path('module', 'outline_designer') .'/images/add.png);" class="context-menu-item-inner" onclick="od_add_book();">Add Book</div></div></div>'."');});";
125 drupal_add_js($js,'inline');
126 }
127 }
128
129 /**
130 * Implemention of hook_form_alter().
131 */
132 function outline_designer_form_alter(&$form, $form_state, $form_id) {
133 if($form_id == 'book_admin_edit') {
134 $form['ahah'] = array(
135 '#type' => 'submit',
136 '#id' => 'reload_table',
137 '#value' => t('AHAH Submit'),
138 '#weight' => 1,
139 '#submit' => array(),
140 '#ahah' => array(
141 'event' => 'change',
142 'path' => 'outline_designer/ajax/reload_table/'. arg(3),
143 'wrapper' => 'book-admin-edit',
144 'method' => 'replace',
145 'effect' => 'fade',
146 ),
147 );
148 $od_path = drupal_get_path('module', 'outline_designer');
149 //unset things so that the form renders with everything stripped off
150 //helps OD work in browsers that respect <enter> button for submitting the whole page/form
151 $form["#submit"] = '';
152 $form["#action"] = '';
153 $form["#method"] = '';
154 $form["save"] ='';
155 $base_path = base_path();
156 foreach ($form['table'] as $key => $row) {
157 if($key != '#theme' && $key != '#tree') {
158 $type = db_result(db_query("SELECT type FROM {node} WHERE nid=%s",$row['nid']['#value']));
159 $form['table'][$key]['title']['#prefix'] = '<img id="node-'. $row['nid']['#value'] .'-icon" src="'. $base_path . variable_get("outline_designer_". $type ."_icon", $od_path ."/images/node.png") .'" alt="Nid: '. $row['nid']['#value'] .'" title="Nid: '. $row['nid']['#value'] .'" style="float:left; margin:2px;" /><img src="'. $base_path . $od_path .'/images/edit.png" id="node-'. $row['nid']['#value'] .'" class="outline_designer_edit_button" />';
160 }
161 }
162 }
163 }
164
165 /**
166 * Implementation of hook_perm().
167 */
168 function outline_designer_perm() {
169 return array('access ajax path');
170 }
171
172 /**
173 * Implementation of hook_block().
174 */
175 function outline_designer_block($op = 'list', $delta = 0, $edit = array()) {
176 // The $op parameter determines what piece of information is being requested.
177 switch ($op) {
178 case 'list':
179 $blocks[0] = array(
180 'info' => t('Outline Designer'),
181 );
182 return $blocks;
183 break;
184 case 'configure':
185 break;
186 case 'view': default:
187 switch($delta){
188 case 0:
189 // The subject is displayed at the top of the block. Note that it
190 // should be passed through t() for translation.
191 $block['subject'] = t('Outline Designer');
192 // The content of the block is typically generated by calling a custom function.
193 $block['content'] = l(t('Outline Designer'),'admin/content/book') .'<br />'. l(t('Settings'),'admin/content/book/settings') .'<br />'. l(t('Usability Settings'),'admin/content/book/outline_designer');
194 break;
195 }
196 return $block;
197 break;
198 }
199 }
200
201
202 /**
203 * Implementation of hook_menu().
204 */
205 function outline_designer_menu() {
206 $items = array();
207 $items['outline_designer/ajax'] = array(
208 'access arguments' => array('access ajax path'),
209 'page callback' => '_outline_designer_ajax',
210 'access callback' => TRUE,
211 'type' => MENU_CALLBACK);
212 $items['admin/content/book/outline_designer'] = array(
213 'title' => 'Usability',
214 'description' => 'The Outline Designer settings allow you to associate icons to content types for use in structuring book content.',
215 'page callback' => 'drupal_get_form',
216 'page arguments' => array('_outline_designer_settings'),
217 'type' => MENU_LOCAL_TASK,
218 'weight' => 9,
219 'access arguments' => array('administer site configuration'));
220 return $items;
221 }
222 /**
223 * Implementation of hook_settings().
224 */
225 function _outline_designer_settings($form_state) {
226 //build out a list of the packaged icons
227 $packaged_icons = 'Outline Designer Icons: ';
228 $icons = array('add', 'edit', 'delete', 'duplicate', 'rename', 'node', 'page', 'folder','change');
229 foreach ($icons as $title) {
230 $packaged_icons .='<img src="'. base_path() . drupal_get_path('module', 'outline_designer') .'/images/'. $title .'.png" title="'. $title .'" alt="'. $title .'" hspace="2px" />';
231 }
232 $packaged_icons .=' <br />Uploaded Icons: ';
233 //create it juuuust incase and make sure it's writable
234 $dir = file_create_path(file_directory_path() .'/outline_designer');
235 file_check_directory($dir, 1);
236
237 if ($handle = opendir('./'. file_directory_path() .'/outline_designer')) {
238 while (FALSE !== ($file = readdir($handle))) {
239 if ($file != "." && $file != "..") {
240 $packaged_icons .='<img src="'. base_path() . file_directory_path() .'/outline_designer/'. $file .'" title="'. $file .'" alt="'. $file .'" hspace="2px" />';
241 }
242 }
243 closedir($handle);
244 }
245 //hidden space to throw out the icons before the rest of the content
246 $form["outline_designer_hidden"] = array(
247 '#type' => 'hidden',
248 '#title' => 'Available icons',
249 '#suffix' => $packaged_icons,
250 );
251 $content_types = array();
252 $result = db_query("SELECT type, name FROM {node_type}");
253 while ($value = db_fetch_array($result)) {
254 array_push($content_types, t($value['type']));
255 //create a textfield incase they want to enter an icon that way
256 $form["outline_designer_". $value['type'] ."_icon_link"] = array(
257 '#type' => 'textfield',
258 '#title' => t("Link to ". $value['name'] ." Icon"),
259 '#default_value' => variable_get("outline_designer_". $value['type'] ."_icon", drupal_get_path('module', 'outline_designer') ."/images/node.png"),
260 '#description' => '<img src="'. base_path() . variable_get("outline_designer_". $value['type'] ."_icon", drupal_get_path('module', 'outline_designer') ."/images/node.png") .'" /> '. t("You can drag the icons from above onto this field to get the full path or add a path of your own."),
261 '#required' => FALSE,
262 );
263 //Create a upload field for each content type so icons can be added for them
264 $form["outline_designer_". $value['type'] ."_icon"] = array(
265 '#type' => 'file',
266 '#size' => '10',
267 '#title' => t("Icon for ". $value['name']),
268 '#description' => t("This icon will be associated with the %type-name content type in the outline designer. The icon must be 16x16, unless an <a href=@toolkit>image toolkit</a> is installed, and in jpg, gif or png format.", array('%type-name' => $value['type'], '@toolkit'=> url('admin/settings/image-toolkit'))),
269 '#required' => FALSE,
270 );
271 }
272 $form['#attributes'] = array('enctype' => "multipart/form-data");
273 $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
274 return $form;
275 }
276 /**
277 * Implementation of hook_settings_submit().
278 */
279 function _outline_designer_settings_submit($form, &$form_state) {
280 $dir = file_create_path(file_directory_path() .'/outline_designer');
281 $is_writable = file_check_directory($dir, 1);
282 if ($is_writable) {
283 $validators = array(
284 'file_validate_is_image' => array(),
285 '_outline_designer_validate_image_resolution' => array('16x16'),
286 'file_validate_size' => array(30 * 1024),
287 );
288 $result = db_query("SELECT type, name FROM {node_type}");
289 while ($value = db_fetch_array($result)) {
290 if ($file = file_save_upload("outline_designer_". $value['type'] ."_icon", $validators, $dir)) {
291 drupal_set_message(t('New '. $value['name'] .' icon saved.'));
292 variable_set("outline_designer_". $value['type'] ."_icon", $file->filepath);
293 }
294 else {
295 //this is the case when there is no image uploaded to associate the textfield icon to the icon page to use, this will allow for references to icons already used
296 $icon = $form_state['values']["outline_designer_". $value['type'] ."_icon_link"];
297 $base_path = base_path();
298 //pull off the site name if it was included
299 if ($base_path != '/' && $base_path != '') {
300 if (strpos(' '. $icon, $base_path ) != 0) {
301 $pos = strpos($icon, $base_path) + strlen($base_path);
302 $icon = substr($icon, $pos);
303 }
304 }
305 //clean up the string incase those other two didn't do the trick
306 $icon = substr($icon, strpos($icon, drupal_get_path('module', 'outline_designer')));
307 $icon = substr($icon, strpos($icon, file_directory_path()));
308 //potentially this isn't a valid icon path on our server...need to still check this
309 variable_set("outline_designer_". $value['type'] ."_icon", $icon);
310 }
311 }
312 }
313 drupal_set_message('Settings Saved!');
314 }
315
316 /**
317 * Implementation of the ajax menu hook
318 */
319 function _outline_designer_ajax() {
320 global $user;
321 //need to figure out which arg is which
322 //arg 0 is always "outline_designer"
323 //arg 1 is always "ajax"
324 $action = arg(2); //action that's being performed
325 $var1 = arg(3); //typically nid being acted on
326 $var2 = arg(4); //additional data like title, ect.
327 $var3 = arg(5); //even more data like type
328
329 if (isset($action)) {
330 switch ($action) {
331 //in: active nid, parent nid, new weight
332 //action:
333 //out: node id, node type, icon to render
334 case 'drag_drop':
335 $nid = $var1;
336 $parent_nid = $var2;
337 $weight = $var3;
338 //load the parent / active node
339 $node = node_load($nid);
340 $parent = node_load($parent_nid);
341 //set parent
342 $node->book['plid'] = $parent->book['mlid'];
343 $node->book['weight'] = $weight;
344 $node->revision = 1;
345 $node->log = "Outline Designer -- nid:$nid parent nid changed to $parent_nid";
346 node_save($node);
347 print "Node nid:$nid parent nid changed to $parent_nid";
348 break;
349 //in: node id, weight
350 //action: saved / updated node
351 //out: message
352 case 'reweight':
353 $nid = $var1;
354 $weight = $var2;
355 $node = node_load($nid);
356 //set parent / weight
357 $node->book['weight'] = $weight;
358 node_save($node);
359 print "Node nid:$nid weight has been updated";
360 break;
361 //in: nothing
362 //action: rebuild the HTML of the table
363 //out: AHAH tabledrag object
364 case 'reload_table':
365 $nid = $var1;
366 module_load_include('inc', 'book', 'book.admin');
367 $form_state = array('storage' => '', 'submitted' => '', 'post' => array());
368 $output = drupal_get_form('book_admin_edit',node_load($nid) );
369 drupal_json(array('status' => TRUE, 'data' => $output) );
370 break;
371 //in: node title, node parent id
372 //action: Insert a node
373 //out: parent menu id, and message / new nid
374 case 'add_child':
375 $title = $var1;
376 $type = $var2;
377 $parent_nid = $var3;
378 $title = str_replace("@2@F@",'/',$title);
379 //set the node
380 $node->title = $title;
381 $node->type = $type;
382 $node->uid = $user->uid;
383 //load up the parent of this new item and then copy over the book structure stuff
384 $parent = node_load($parent_nid);
385 $node->book['weight'] = -15;
386 $node->book['plid'] = $parent->book['mlid'];
387 $node->book['bid'] = $parent->book['bid'];
388 $node->book['menu_name'] = $parent->book['menu_name'];
389 $node->book['module'] = $parent->book['module'];
390 node_save($node);
391 watchdog('content', '@type: added %title.', array('@type' => $node->type, '%title' => $node->title));
392 print $parent->book['mlid'] .';msg:Node '. $node->nid .' added successfully!';
393 break;
394 //in: node id
395 //action: load node edit form
396 //out: page w/ edit form
397 case 'edit':
398 $nid = $var1;
399 $node = node_load($nid);
400 if ($user->uid == $node->uid && user_access(_outline_designer_get_pstr('edit own',$node->type))) {
401 module_load_include('inc', 'node', 'node.pages');
402 $output = node_page_edit($node);
403 }
404 elseif (user_access(_outline_designer_get_pstr('edit any',$node->type))) {
405 module_load_include('inc', 'node', 'node.pages');
406 $output = node_page_edit($node);
407 }
408 else {
409 $output = 0;
410 }
411 print $output;
412 break;
413 //in: node id, title
414 //action: rename a single node
415 //out: nothing
416 case 'rename':
417 $nid = $var1;
418 $newtitle = $var2;
419 $newtitle = str_replace("@2@F@",'/',$newtitle);
420 $node = node_load($nid);
421 if ($user->uid == $node->uid && user_access(_outline_designer_get_pstr('edit own',$node->type))) {
422 $node->log = "Outline Designer -- node renamed from ". $node->title ." to ". $newtitle;
423 watchdog('content', "Outline Designer -- node renamed from ". $node->title ." to ". $newtitle);
424 print "Node $nid renamed from ". $node->title ." to ". $newtitle;
425 $node->title = $newtitle;
426 $node->revision = 1;
427 node_save($node);
428 }
429 elseif (user_access(_outline_designer_get_pstr('edit any',$node->type))) {
430 $node->log = "Outline Designer -- node renamed from ". $node->title ." to ". $newtitle;
431 watchdog('content', "Outline Designer -- node renamed from ". $node->title ." to ". $newtitle);
432 print "Node $nid renamed from ". $node->title ." to ". $newtitle;
433 $node->title = $newtitle;
434 $node->revision = 1;
435 node_save($node);
436 }
437 else {
438 print 0;
439 }
440 break;
441 //in: root node id
442 //action: duplicate the node and associate the tree to the new branch (if multiple)
443 //out: new root node
444 case 'duplicate':
445 $nid = $var1;
446 $multiple = $var2;
447 $dup_title = $var3;
448 $node = node_load($nid);
449 //snag the whole branch if multiple == 1
450 if ($multiple == 0) {
451 $node->nid = NULL;
452 $node->created = NULL;
453 $node->uid = $user->uid;
454 $new_title = str_replace('%title',$node->title,$dup_title);
455 $node->title = $new_title;
456 node_save($node);
457 $nids = ' '. $nid . ' ';
458 }
459 else {
460 $nids = 's ';
461 $map = array();
462 //pull only the nodes that have this node as a parent
463 $mlid = $node->book['mlid'];
464 $result = db_query("SELECT link_path FROM {menu_links} WHERE p1=%s OR p2=%s OR p3=%s OR p4=%s OR p5=%s OR p6=%s OR p7=%s OR p8=%s OR p9=%s",$mlid,$mlid,$mlid,$mlid,$mlid,$mlid,$mlid,$mlid,$mlid);
465 while ($value = db_fetch_array($result)) {
466 $dup_node = node_load(str_replace('node/','',$value['link_path']));
467 $nids.= ' '. $dup_node->nid . ', ';
468 $dup_node->nid = NULL;
469 $dup_node->created = NULL;
470 $dup_node->uid = $user->uid;
471 $dup_node->revision = 1;
472 $dup_node->log = "Outline Designer -- Duplicate of old node nid:$old_nid";
473 if (isset($map[$dup_node->book['plid']]) ) {
474 $dup_node->book['plid'] = $map[$dup_node->book['plid']];
475 }
476 $new_title = str_replace('%title',$dup_node->title,$dup_title);
477 $dup_node->title = $new_title;
478 $old_mlid = $dup_node->book['mlid'];
479 $dup_node->book['mlid'] = NULL;
480 node_save($dup_node);
481 $map[$old_mlid] = $dup_node->book['mlid'];
482 }
483 }
484 print 'Duplicate node nid:'. $nid .' successful';
485 break;
486 //in: list of node ids to delete
487 //action: delete nodes
488 //out: completion response
489 case 'delete':
490 $nid = $var1;
491 $multiple = $var2;
492 $node = node_load($nid);
493 if ($multiple == 0) {
494 if ($user->uid == $node->uid && user_access(_outline_designer_get_pstr('delete own',$node->type))) {
495 print "Node $nid successfully removed!";
496 node_delete($nid);
497 }
498 elseif (user_access(_outline_designer_get_pstr('delete any',$node->type))) {
499 print "Node $nid successfully removed!";
500 node_delete($nid);
501 }
502 else {
503 print 0;
504 }
505 }
506 else {
507 $node = node_load($nid);
508 //pull only the nodes that have this node as a parent
509 $mlid = $node->book['mlid'];
510 $result = db_query("SELECT link_path FROM {menu_links} WHERE p1=%s OR p2=%s OR p3=%s OR p4=%s OR p5=%s OR p6=%s OR p7=%s OR p8=%s OR p9=%s",$mlid,$mlid,$mlid,$mlid,$mlid,$mlid,$mlid,$mlid,$mlid);
511 $del_count = 0;
512 $count = 0;
513 while ($value = db_fetch_array($result)) {
514 $count++;
515 $node = node_load(str_replace('node/','',$value['link_path']));
516 if ($user->uid == $node->uid && user_access(_outline_designer_get_pstr('delete own',$node->type))) {
517 $del_count++;
518 node_delete($node->nid);
519 }
520 elseif (user_access(_outline_designer_get_pstr('delete any',$node->type))) {
521 $del_count++;
522 node_delete($node->nid);
523 }
524 }
525 if ($del_count == 0) {
526 print 0;
527 }
528 elseif ($count != $del_count) {
529 print "A multiple delete was commited but you didn't have the permissions to delete ALL of the children nodes so some remain.";
530 }
531 else {
532 print "All nodes were deleted successfully.";
533 }
534 }
535 break;
536 //in: node id, node type name
537 //action: change node type and resave
538 //out: icon to render
539 case 'change_type':
540 $nid = $var1;
541 $new_type = $var2;
542 $node = node_load($nid);
543 if ($user->uid == $node->uid && user_access(_outline_designer_get_pstr('edit own',$node->type))) {
544 $log_msg = " Node $nid changed from '". $node->type ."' to '$new_type'";
545 $node->log = "Outline Designer -- ". $log_msg;
546 $node->type = $new_type;
547 node_save($node);
548 watchdog('content', "Outline Designer -- ". $log_msg);
549 print $log_msg;
550 }
551 elseif (user_access(_outline_designer_get_pstr('edit any',$node->type))) {
552 $log_msg = " Node $nid changed from '". $node->type ."' to '$new_type'";
553 $node->log = "Outline Designer -- ". $log_msg;
554 $node->type = $new_type;
555 node_save($node);
556 watchdog('content', "Outline Designer -- ". $log_msg);
557 print $log_msg;
558 }
559 else {
560 print 0;
561 }
562 break;
563 }
564 }
565 exit();
566 }
567
568 function _outline_designer_get_pstr($op, $type) {
569 $term = 'content';
570 switch ($type) {
571 // Panels are a totally special case
572 case 'panel':
573 if ($op == 'create') {
574 return 'create panel-nodes';
575 }
576 elseif ($op == 'edit') {
577 return 'administer panel-nodes';
578 }
579 elseif ($op == 'edit own') {
580 return 'edit own panel-nodes';
581 }
582 break;
583 default:
584 break;
585 }
586
587 return ($op .' '. $type .' '. $term);
588 }
589
590 function _outline_designer_validate_image_resolution(&$file, $dimensions) {
591 $errors = array();
592 // Check first that the file is an image.
593 if ($info = image_get_info($file->filepath)) {
594 // Check if the icon matches the given dimensions.
595 list($width, $height) = explode('x', $dimensions);
596 if ($info['width'] != $width || $info['height'] != $height) {
597 // Try to resize the image to fit the dimensions if it doesn't.
598 if (image_get_toolkit() && image_scale_and_crop($file->filepath, $file->filepath, $width, $height)) {
599 drupal_set_message(t('The image was resized to the allowed dimensions of %dimensions pixels.', array('%dimensions' => $dimensions)));
600 // Clear the cached filesize and refresh the image information.
601 clearstatcache();
602 $info = image_get_info($file->filepath);
603 $file->filesize = $info['file_size'];
604 }
605 else {
606 $errors[] = t('Image dimensions need to be %dimensions pixels.', array('%dimensions' => $maximum_dimensions));
607 }
608 }
609 }
610 return $errors;
611 }

  ViewVC Help
Powered by ViewVC 1.1.2