| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
require_once(drupal_get_path('module', 'simplelist') .'/SimpleListController.php');
|
| 5 |
|
| 6 |
define('SIMPLELIST_UNPUBLISHED_NODES', 0);
|
| 7 |
define('SIMPLELIST_PUBLISHED_NODES', 1);
|
| 8 |
define('SIMPLELIST_ALL_NODES', 2);
|
| 9 |
|
| 10 |
define('SIMPLELIST_FORMAT_TEASER', 0);
|
| 11 |
define('SIMPLELIST_FORMAT_FULL', 1);
|
| 12 |
define('SIMPLELIST_FORMAT_THEME', 2);
|
| 13 |
define('SIMPLELIST_FORMAT_TITLE_LINK', 3);
|
| 14 |
|
| 15 |
/**
|
| 16 |
* Implements hook_block.
|
| 17 |
*
|
| 18 |
* @param unknown_type $op
|
| 19 |
* @param unknown_type $delta
|
| 20 |
* @param unknown_type $edit
|
| 21 |
* @return unknown
|
| 22 |
*/
|
| 23 |
function simplelist_block($op = 'list', $delta = 0, $edit = array()) {
|
| 24 |
if ($op == 'list') {
|
| 25 |
$items = array();
|
| 26 |
$query = "SELECT sl.slid, sl.name, sl.cache, sld.display_title FROM {simplelist} sl INNER JOIN {simplelist_display} sld ON (sl.slid = sld.slid AND sld.display_context = '%s')";
|
| 27 |
$result = db_query($query, "block");
|
| 28 |
while ($simple_list = db_fetch_object($result)) {
|
| 29 |
$items[$simple_list->name] = array('info' => ($simple_list->display_title?$simple_list->display_title:$simple_list->name), 'cache' => $simple_list->cache);
|
| 30 |
}
|
| 31 |
return $items;
|
| 32 |
}
|
| 33 |
else if ($op == 'view') {
|
| 34 |
$sl_controller = new SimpleListController($delta, 'block');
|
| 35 |
return $sl_controller->getRenderedList();
|
| 36 |
}
|
| 37 |
}
|
| 38 |
|
| 39 |
/**
|
| 40 |
* Implements hook_help().
|
| 41 |
*
|
| 42 |
* @param unknown_type $path
|
| 43 |
* @param unknown_type $arg
|
| 44 |
*/
|
| 45 |
function simplelist_help($path, $arg) {
|
| 46 |
switch ($path) {
|
| 47 |
case 'admin/build/simplelist':
|
| 48 |
return '<p>'. t('Simplelists are lists of nodes (or other items in the future). From this page you can edit, clone, or delete any existing simplelists, or add a new one.') .'</p>';
|
| 49 |
case 'admin/build/simplelist/add':
|
| 50 |
return '<p>'. t('Set a name for your list, choose a Filter and block display and/or page display options. A filter is the method you want to use to choose what nodes to display in the list. If you choose a block, you\'ll need to set how the nodes will display in the block. If you choose a page, you\'ll need to set how the nodes will display, and the path to display on. If you choose to use a theme function to display your nodes, the theme is named "simplelist__<name of simplelist>" - note that is two underscores.') .'</p>';
|
| 51 |
}
|
| 52 |
}
|
| 53 |
|
| 54 |
/**
|
| 55 |
* Implements hook_perm().
|
| 56 |
*
|
| 57 |
* @return unknown
|
| 58 |
*/
|
| 59 |
function simplelist_perm() {
|
| 60 |
return array('administer simplelist');
|
| 61 |
}
|
| 62 |
|
| 63 |
/**
|
| 64 |
* Implements hook_menu().
|
| 65 |
*
|
| 66 |
* @return array
|
| 67 |
*/
|
| 68 |
function simplelist_menu() {
|
| 69 |
$item = array();
|
| 70 |
|
| 71 |
$item['simplelist/filter/ahah'] = array(
|
| 72 |
'page callback' => '_simplelist_filter_ahah',
|
| 73 |
'access arguments' => array('administer simplelist'),
|
| 74 |
'type' => MENU_CALLBACK,
|
| 75 |
);
|
| 76 |
$item['simplelist/display/ahah'] = array(
|
| 77 |
'page callback' => '_simplelist_display_ahah',
|
| 78 |
'access arguments' => array('administer simplelist'),
|
| 79 |
'type' => MENU_CALLBACK,
|
| 80 |
);
|
| 81 |
$item['admin/build/simplelist'] = array(
|
| 82 |
'title' => 'SimpleList',
|
| 83 |
'page callback' => '_simplelist_admin_page',
|
| 84 |
'access arguments' => array('administer simplelist'),
|
| 85 |
'description' => 'Simplelist makes it easy to present nodes in list form without much/any coding.',
|
| 86 |
'type' => MENU_NORMAL_ITEM,
|
| 87 |
);
|
| 88 |
$item['admin/build/simplelist/list'] = array(
|
| 89 |
'title' => 'List',
|
| 90 |
'page callback' => '_simplelist_admin_page',
|
| 91 |
'access arguments' => array('administer simplelist'),
|
| 92 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 93 |
'weight' => '-1',
|
| 94 |
);
|
| 95 |
$item['admin/build/simplelist/add'] = array(
|
| 96 |
'title' => 'Add',
|
| 97 |
'page callback' => '_simplelist_admin_add_page',
|
| 98 |
'access arguments' => array('administer simplelist'),
|
| 99 |
'type' => MENU_LOCAL_TASK,
|
| 100 |
);
|
| 101 |
$item['admin/build/simplelist/delete/%'] = array(
|
| 102 |
'title' => 'Delete',
|
| 103 |
'page callback' => 'drupal_get_form',
|
| 104 |
'page arguments' => array('_simplelist_admin_delete_confirm', 4),
|
| 105 |
'access arguments' => array('administer simplelist'),
|
| 106 |
'type' => MENU_CALLBACK,
|
| 107 |
);
|
| 108 |
$item['admin/build/simplelist/%simplelist/edit'] = array(
|
| 109 |
'title' => 'Edit',
|
| 110 |
'page callback' => '_simplelist_admin_edit_page',
|
| 111 |
'page arguments' => array(3),
|
| 112 |
'access arguments' => array('administer simplelist'),
|
| 113 |
'weight' => -5,
|
| 114 |
'type' => MENU_CALLBACK,
|
| 115 |
);
|
| 116 |
$item['admin/build/simplelist/%simplelist/clone'] = array(
|
| 117 |
'title' => 'Clone',
|
| 118 |
'page callback' => '_simplelist_admin_clone_page',
|
| 119 |
'page arguments' => array(3),
|
| 120 |
'access arguments' => array('administer simplelist'),
|
| 121 |
'type' => MENU_CALLBACK,
|
| 122 |
);
|
| 123 |
|
| 124 |
// This section pulls out the simplelist pages to add to the menu.
|
| 125 |
$query = "SELECT slid, display_title, display_path FROM {simplelist_display} WHERE display_context = 'page'";
|
| 126 |
$result = db_query($query);
|
| 127 |
|
| 128 |
while ($row = db_fetch_object($result)) {
|
| 129 |
$count = 0;
|
| 130 |
$args = array($row->slid);
|
| 131 |
$path = $row->display_path;
|
| 132 |
if ($wild_pos = strpos($path, '%tid')) {
|
| 133 |
$arg_pos = substr_count($path, '/', 0, $wild_pos);
|
| 134 |
$path = str_replace('%tid', '%', $path, $count);
|
| 135 |
$args[] = 'tid';
|
| 136 |
$args[] = $arg_pos;
|
| 137 |
}
|
| 138 |
if ($wild_pos = strpos($path, '%node_type')) {
|
| 139 |
$arg_pos = substr_count($path, '/', 0, $wild_pos);
|
| 140 |
$path = str_replace('%node_type', '%simplelist_node_type', $path, $count);
|
| 141 |
$args[] = 'node_type';
|
| 142 |
$args[] = $arg_pos;
|
| 143 |
}
|
| 144 |
|
| 145 |
$item[$path] = array(
|
| 146 |
'title' => $row->display_title,
|
| 147 |
'page callback' => '_simplelist_path_display',
|
| 148 |
'page arguments' => $args,
|
| 149 |
'access callback' => '_simplelist_menu_access',
|
| 150 |
'access arguments' => array($row->slid),
|
| 151 |
'type' => MENU_CALLBACK,
|
| 152 |
);
|
| 153 |
}
|
| 154 |
|
| 155 |
return $item;
|
| 156 |
}
|
| 157 |
|
| 158 |
/**
|
| 159 |
* Wrapper function that is used by menu wildcards to load a simplelist for editing.
|
| 160 |
*
|
| 161 |
* @param int $slid
|
| 162 |
* @return simplelist
|
| 163 |
*/
|
| 164 |
function simplelist_load($slid) {
|
| 165 |
return SimpleListController::load_simple_list($slid, 'all');
|
| 166 |
}
|
| 167 |
|
| 168 |
/**
|
| 169 |
* Wrapper function that is used by menu wildcards to load a path.
|
| 170 |
*/
|
| 171 |
function simplelist_node_type_load($node_type) {
|
| 172 |
return node_get_types('type', $node_type);
|
| 173 |
}
|
| 174 |
|
| 175 |
/**
|
| 176 |
* A wrapper function to help a menu entry to easily check access rights.
|
| 177 |
*
|
| 178 |
* @param unknown_type $slid
|
| 179 |
* @return unknown
|
| 180 |
*/
|
| 181 |
function _simplelist_menu_access($slid) {
|
| 182 |
$access_rights = db_result(db_query("SELECT access FROM {simplelist} WHERE slid = %d", $slid));
|
| 183 |
|
| 184 |
if ($access_rights) {
|
| 185 |
global $user;
|
| 186 |
return SimpleListController::checkSimpleListAccess(unserialize($access_rights), $user->roles);
|
| 187 |
}
|
| 188 |
return TRUE;
|
| 189 |
}
|
| 190 |
|
| 191 |
/**
|
| 192 |
* Implements hook_theme, so that folks can define how to theme their blocks.
|
| 193 |
*
|
| 194 |
* @return array
|
| 195 |
* Theme function information
|
| 196 |
*/
|
| 197 |
function simplelist_theme() {
|
| 198 |
return array(
|
| 199 |
'simplelist' => array(
|
| 200 |
'arguments' => array('node' => NULL, 'simplelist' => NULL),
|
| 201 |
'pattern' => 'simplelist__',
|
| 202 |
),
|
| 203 |
'simplelist__simplelist_test_theme_list' => array(
|
| 204 |
'arguments' => array('node' => NULL, 'simplelist' => NULL),
|
| 205 |
),
|
| 206 |
);
|
| 207 |
}
|
| 208 |
|
| 209 |
/**
|
| 210 |
* Base default theme of a node, if the developer hasn't defined theme_simplelist__$simplelist->name.
|
| 211 |
*
|
| 212 |
* @param unknown_type $node
|
| 213 |
* @param unknown_type $simplelist
|
| 214 |
* @return unknown
|
| 215 |
*/
|
| 216 |
function theme_simplelist($node, $simplelist) {
|
| 217 |
return check_plain($node->title);
|
| 218 |
}
|
| 219 |
|
| 220 |
/**
|
| 221 |
* This is a test theme, just done to make sure the proper overrides work.
|
| 222 |
*
|
| 223 |
* @param unknown_type $node
|
| 224 |
* @param unknown_type $simplelist
|
| 225 |
* @return unknown
|
| 226 |
*/
|
| 227 |
function theme_simplelist__simplelist_test_theme_list($node, $simplelist) {
|
| 228 |
return 'I love '. check_plain($node->title);
|
| 229 |
}
|
| 230 |
|
| 231 |
/**
|
| 232 |
* This function handles the page-based simplelists - first it tries to set up any path arguments, then renders the page.
|
| 233 |
*
|
| 234 |
* The arguments may or may not be there, but will be set up in the dynamically set hook_menu items. The Controller knows what to do with them...
|
| 235 |
*
|
| 236 |
* @param unknown_type $slid
|
| 237 |
* @param unknown_type $type1
|
| 238 |
* @param unknown_type $id1
|
| 239 |
* @param unknown_type $type2
|
| 240 |
* @param unknown_type $id2
|
| 241 |
* @return unknown
|
| 242 |
*/
|
| 243 |
function _simplelist_path_display($slid, $type1 = '', $id1 = -1, $type2 = '', $id2 = -1) {
|
| 244 |
$controller = new SimpleListController($slid, 'page');
|
| 245 |
if ($type1 != '') {
|
| 246 |
$controller->setArgument($type1, $id1);
|
| 247 |
if ($type2 != '') {
|
| 248 |
$controller->setArgument($type2, $id2);
|
| 249 |
}
|
| 250 |
}
|
| 251 |
|
| 252 |
return $controller->getRenderedList();
|
| 253 |
}
|
| 254 |
|
| 255 |
/**
|
| 256 |
* Implements hook_simplelist_filter_list().
|
| 257 |
*
|
| 258 |
* @return unknown
|
| 259 |
*/
|
| 260 |
function simplelist_simplelist_filter_info() {
|
| 261 |
return array(
|
| 262 |
array('name' => 'SimpleListNodeFilter', 'title' => t('Simple Node Filter'), 'provides' => 'node'),
|
| 263 |
array('name' => 'SimpleListFilterNodeByUser', 'title' => t('Filter Node By User'), 'provides' => 'node'),
|
| 264 |
);
|
| 265 |
}
|
| 266 |
|
| 267 |
/**
|
| 268 |
* Implements hook_simplelist_filter_require().
|
| 269 |
*
|
| 270 |
*/
|
| 271 |
function simplelist_simplelist_filter_require() {
|
| 272 |
require_once(drupal_get_path('module', 'simplelist') .'/SimpleListNodeFilter.php');
|
| 273 |
require_once(drupal_get_path('module', 'simplelist') .'/SimpleListFilterNodeByUser.php');
|
| 274 |
}
|
| 275 |
|
| 276 |
/**
|
| 277 |
* Implements hook_simplelist_display_info().
|
| 278 |
*
|
| 279 |
* @param unknown_type $op
|
| 280 |
* @return unknown
|
| 281 |
*/
|
| 282 |
function simplelist_simplelist_display_info($op = 'list') {
|
| 283 |
return array(
|
| 284 |
array('name' => 'SimpleListDisplay', 'title' => t('Display as List'), 'accepts' => 'node'),
|
| 285 |
array('name' => 'SimpleListDisplayCascade', 'title' => t('Display as series of items'), 'accepts' => 'node'),
|
| 286 |
);
|
| 287 |
}
|
| 288 |
|
| 289 |
/**
|
| 290 |
* Implements hook_simplelist_display_require().
|
| 291 |
*
|
| 292 |
*/
|
| 293 |
function simplelist_simplelist_display_require() {
|
| 294 |
require_once(drupal_get_path('module', 'simplelist') .'/SimpleListDisplay.php');
|
| 295 |
require_once(drupal_get_path('module', 'simplelist') .'/SimpleListDisplayCascade.php');
|
| 296 |
}
|
| 297 |
|
| 298 |
/**
|
| 299 |
* Requires/includes all of the filter classes that simplelist knows of.
|
| 300 |
*
|
| 301 |
*/
|
| 302 |
function simplelist_require_all_filter_classes() {
|
| 303 |
module_invoke_all('simplelist_filter_require');
|
| 304 |
}
|
| 305 |
|
| 306 |
/**
|
| 307 |
* Requires/includes all of the display classes that simplelist knows of.
|
| 308 |
*
|
| 309 |
*/
|
| 310 |
function simplelist_require_all_display_classes() {
|
| 311 |
module_invoke_all('simplelist_display_require');
|
| 312 |
}
|
| 313 |
|
| 314 |
/**
|
| 315 |
* Returns the list of filter classes available to list from.
|
| 316 |
*
|
| 317 |
* @return unknown
|
| 318 |
*/
|
| 319 |
function _simplelist_get_filter_options() {
|
| 320 |
$filter_array = array();
|
| 321 |
|
| 322 |
$modules = module_implements('simplelist_filter_info');
|
| 323 |
foreach ($modules as $module) {
|
| 324 |
$items = module_invoke($module, 'simplelist_filter_info');
|
| 325 |
foreach ($items as $detail) {
|
| 326 |
$filter_array[$detail['name']] = $detail['title'];
|
| 327 |
}
|
| 328 |
}
|
| 329 |
|
| 330 |
return $filter_array;
|
| 331 |
}
|
| 332 |
|
| 333 |
/**
|
| 334 |
* Given a filter name, we fetch the type of objects that filter provides.
|
| 335 |
*
|
| 336 |
* @param unknown_type $filter_name
|
| 337 |
* @return unknown
|
| 338 |
*/
|
| 339 |
function _simplelist_get_filter_provides($filter_name) {
|
| 340 |
static $filter_provides = array();
|
| 341 |
if (!count($filter_provides)) {
|
| 342 |
$modules = module_implements('simplelist_filter_info');
|
| 343 |
foreach ($modules as $module) {
|
| 344 |
$items = module_invoke($module, 'simplelist_filter_info');
|
| 345 |
foreach ($items as $detail) {
|
| 346 |
$filter_provides[$detail['name']] = $detail['provides'];
|
| 347 |
}
|
| 348 |
}
|
| 349 |
}
|
| 350 |
|
| 351 |
if (isset($filter_provides[$filter_name])) {
|
| 352 |
return $filter_provides[$filter_name];
|
| 353 |
}
|
| 354 |
return NULL;
|
| 355 |
}
|
| 356 |
|
| 357 |
/**
|
| 358 |
* Returns the list of display classes available to list from.
|
| 359 |
*
|
| 360 |
* Placeholder as well.
|
| 361 |
*
|
| 362 |
* @return unknown
|
| 363 |
*/
|
| 364 |
function _simplelist_get_display_options($type = 'all') {
|
| 365 |
$display_array = array();
|
| 366 |
|
| 367 |
$modules = module_implements('simplelist_display_info');
|
| 368 |
foreach ($modules as $module) {
|
| 369 |
$items = module_invoke($module, 'simplelist_display_info');
|
| 370 |
foreach ($items as $detail) {
|
| 371 |
if ($type == 'all' || $type == $detail['accepts']) {
|
| 372 |
$display_array[$detail['name']] = $detail['title'];
|
| 373 |
}
|
| 374 |
}
|
| 375 |
}
|
| 376 |
|
| 377 |
return $display_array;
|
| 378 |
}
|
| 379 |
|
| 380 |
/*
|
| 381 |
* ADMIN SECTION STARTS HERE
|
| 382 |
*/
|
| 383 |
|
| 384 |
/**
|
| 385 |
* Page callback that displays a list of simplelists that have been defined.
|
| 386 |
*
|
| 387 |
*/
|
| 388 |
function _simplelist_admin_page() {
|
| 389 |
$num_rows = 25;
|
| 390 |
|
| 391 |
drupal_set_title(t('Administer Simplelists'));
|
| 392 |
|
| 393 |
$result = pager_query("SELECT sl.slid, name, description, display_context FROM {simplelist} sl INNER JOIN {simplelist_display} sld ON (sl.slid = sld.slid) ORDER BY sl.name", $num_rows);
|
| 394 |
|
| 395 |
$table_items = array();
|
| 396 |
while ($row = db_fetch_object($result)) {
|
| 397 |
$size = count($table_items) - 1;
|
| 398 |
if (size >= 0 && $row->name == $table_items[$size][0]) {
|
| 399 |
$table_items[$size][2] .= ', '. $row->display_context;
|
| 400 |
}
|
| 401 |
else {
|
| 402 |
$table_items[] = array(
|
| 403 |
$row->name,
|
| 404 |
$row->description,
|
| 405 |
$row->display_context,
|
| 406 |
theme('links', array(
|
| 407 |
array('title' => t('Edit'), 'href' => "admin/build/simplelist/$row->slid/edit"),
|
| 408 |
array('title' => t('Delete'), 'href' => "admin/build/simplelist/delete/$row->slid"),
|
| 409 |
array('title' => t('Clone'), 'href' => "admin/build/simplelist/$row->slid/clone"),
|
| 410 |
))
|
| 411 |
);
|
| 412 |
}
|
| 413 |
}
|
| 414 |
|
| 415 |
if ($table_items) {
|
| 416 |
$output = theme('table', array(t('Name'), t('Description'), t('Contexts'), t('Actions')), $table_items, array("cellpadding" => "4"), t('Existing Simplelists'));
|
| 417 |
$output .= theme('pager', NULL, $num_rows);
|
| 418 |
}
|
| 419 |
else {
|
| 420 |
$output .= t('<p>No Simplelists have currently been defined.</p>');
|
| 421 |
}
|
| 422 |
|
| 423 |
return $output;
|
| 424 |
}
|
| 425 |
|
| 426 |
/**
|
| 427 |
* Wrapper function callback to display the edit form when user wants to add a simplelist.
|
| 428 |
*
|
| 429 |
* @return unknown
|
| 430 |
*/
|
| 431 |
function _simplelist_admin_add_page() {
|
| 432 |
$simplelist = SimpleListController::getDefault();
|
| 433 |
|
| 434 |
drupal_set_title(t('Add a Simplelist'));
|
| 435 |
|
| 436 |
return drupal_get_form('_simplelist_edit_form', $simplelist, 'add');
|
| 437 |
}
|
| 438 |
|
| 439 |
/**
|
| 440 |
* Wrapper function callback to display the edit form (filled) when user wants to add a simplelist.
|
| 441 |
*
|
| 442 |
* @param unknown_type $simplelist
|
| 443 |
* @return unknown
|
| 444 |
*/
|
| 445 |
function _simplelist_admin_edit_page($simplelist = NULL) {
|
| 446 |
|
| 447 |
drupal_set_title(t('Edit a Simplelist'));
|
| 448 |
|
| 449 |
return drupal_get_form('_simplelist_edit_form', $simplelist);
|
| 450 |
}
|
| 451 |
|
| 452 |
/**
|
| 453 |
* Displays the simplelist edit page, with the fields pre-filled to clone the given simplelist.
|
| 454 |
*
|
| 455 |
* @param unknown_type $simplelist
|
| 456 |
* @return unknown
|
| 457 |
*/
|
| 458 |
function _simplelist_admin_clone_page($simplelist = NULL) {
|
| 459 |
|
| 460 |
drupal_set_title(t('Clone a Simplelist'));
|
| 461 |
|
| 462 |
$simplelist->slid = 0;
|
| 463 |
$simplelist->displays['block']->sldid = 0;
|
| 464 |
$simplelist->displays['page']->sldid = 0;
|
| 465 |
|
| 466 |
return drupal_get_form('_simplelist_edit_form', $simplelist);
|
| 467 |
}
|
| 468 |
|
| 469 |
/**
|
| 470 |
* Displays the confirm form to make sure the user really wants to delete a simplelist.
|
| 471 |
*
|
| 472 |
* @param unknown_type $form_state
|
| 473 |
* @param unknown_type $slid
|
| 474 |
* @return unknown
|
| 475 |
*/
|
| 476 |
function _simplelist_admin_delete_confirm(&$form_state, $slid = '') {
|
| 477 |
$simplelist = simplelist_load($slid);
|
| 478 |
|
| 479 |
if (!$simplelist) {
|
| 480 |
return drupal_goto('admin/build/simplelist');
|
| 481 |
}
|
| 482 |
|
| 483 |
$form['slid'] = array('#type' => 'value', '#value' => $simplelist->slid);
|
| 484 |
|
| 485 |
$form = confirm_form($form,
|
| 486 |
t('Are you sure you want to delete %title?', array('%title' => $nc->name)),
|
| 487 |
$_GET['destination'] ? $_GET['destination'] : 'admin/build/simplelist',
|
| 488 |
t('This action cannot be undone.'),
|
| 489 |
t('Delete'), t('Cancel')
|
| 490 |
);
|
| 491 |
return $form;
|
| 492 |
}
|
| 493 |
|
| 494 |
/**
|
| 495 |
* Handle the submit button to delete a nodecarousel.
|
| 496 |
*
|
| 497 |
* @param string $form_id
|
| 498 |
* Standard form_id for submit functions in formapi.
|
| 499 |
* @param array $form_state
|
| 500 |
* Array of form values for deletion.
|
| 501 |
*/
|
| 502 |
function _simplelist_admin_delete_confirm_submit($form, &$form_state) {
|
| 503 |
_simplelist_delete((object) $form_state['values']);
|
| 504 |
$form_state['redirect'] = 'admin/build/simplelist';
|
| 505 |
}
|
| 506 |
|
| 507 |
/**
|
| 508 |
* Deletes a given simplelist.
|
| 509 |
*
|
| 510 |
* @param unknown_type $form_values
|
| 511 |
*/
|
| 512 |
function _simplelist_delete($form_values) {
|
| 513 |
$form_values->slid = intval($form_values->slid);
|
| 514 |
|
| 515 |
if (!$form_values->slid) {
|
| 516 |
return;
|
| 517 |
}
|
| 518 |
|
| 519 |
db_query("DELETE FROM {simplelist_display} WHERE slid = %d", $form_values->slid);
|
| 520 |
db_query("DELETE FROM {simplelist_terms} WHERE slid = %d", $form_values->slid);
|
| 521 |
db_query("DELETE FROM {simplelist_types} WHERE slid = %d", $form_values->slid);
|
| 522 |
db_query("DELETE FROM {simplelist} WHERE slid = %d", $form_values->slid);
|
| 523 |
}
|
| 524 |
|
| 525 |
/**
|
| 526 |
* Rebuilds form for AHAH display call, and returns to the page the new fields.
|
| 527 |
*
|
| 528 |
* This is liberally poached from the Poll module. The tricky part of passing back form elements in AHAH is that the
|
| 529 |
* Form API checks with form_cache to make sure that the data it's sent matches with the form it's supposed to have.
|
| 530 |
*
|
| 531 |
* @param unknown_type $type
|
| 532 |
*/
|
| 533 |
function _simplelist_display_ahah($type = 'block') {
|
| 534 |
simplelist_require_all_display_classes();
|
| 535 |
if ($type == 'block') {
|
| 536 |
$class_name = $_POST['block_display_name'];
|
| 537 |
$form_area = 'block_display';
|
| 538 |
}
|
| 539 |
else {
|
| 540 |
$class_name = $_POST['page_display_name'];
|
| 541 |
$form_area = 'page_display';
|
| 542 |
}
|
| 543 |
_simplelist_common_ahah($type, $class_name, 'get_display_form', $form_area);
|
| 544 |
}
|
| 545 |
|
| 546 |
/**
|
| 547 |
* Rebuilds form for AHAH filter call, and returns to the page the new fields.
|
| 548 |
*
|
| 549 |
* This is liberally poached from the Poll module. The tricky part of passing back form elements in AHAH is that the
|
| 550 |
* Form API checks with form_cache to make sure that the data it's sent matches with the form it's supposed to have.
|
| 551 |
*
|
| 552 |
*/
|
| 553 |
function _simplelist_filter_ahah() {
|
| 554 |
simplelist_require_all_filter_classes();
|
| 555 |
$class_name = $_POST['filter_name'];
|
| 556 |
_simplelist_common_ahah('filter', $class_name, 'get_filter_form', 'SimpleListNodeFilter');
|
| 557 |
}
|
| 558 |
|
| 559 |
/**
|
| 560 |
* The common ahah form handling functionality.
|
| 561 |
*
|
| 562 |
* @param unknown_type $type
|
| 563 |
* The type of form elements - 'filter', 'block', or 'page'.
|
| 564 |
* @param unknown_type $class_name
|
| 565 |
* The name of the class providing the new form elements
|
| 566 |
* @param unknown_type $function_name
|
| 567 |
* The name of the function to get the form elements from on $class_name
|
| 568 |
* @param unknown_type $form_area
|
| 569 |
* The sub-section of the form which we're changing.
|
| 570 |
*/
|
| 571 |
function _simplelist_common_ahah($type, $class_name, $function_name, $form_area) {
|
| 572 |
|
| 573 |
// Get the form out of the cache.
|
| 574 |
$form_state = array('submitted' => FALSE);
|
| 575 |
$form_build_id = $_POST['form_build_id'];
|
| 576 |
$form = form_get_cache($form_build_id, $form_state);
|
| 577 |
|
| 578 |
// Get the new form elements from the display class.
|
| 579 |
if ($form['slid']['#value'] == 0) {
|
| 580 |
$simplelist = SimpleListController::getDefault();
|
| 581 |
}
|
| 582 |
else {
|
| 583 |
$simplelist = simplelist_load($form['slid']['#value']);
|
| 584 |
}
|
| 585 |
$form_elements = call_user_func(array($class_name, $function_name), $simplelist, $type);
|
| 586 |
|
| 587 |
if ($type == 'filter') {
|
| 588 |
$form_section = $form;
|
| 589 |
}
|
| 590 |
else {
|
| 591 |
$form_section = $form['display'];
|
| 592 |
}
|
| 593 |
// Remove the unwanted elements from the form, add in the new elements in $form_elements, and then put the form back in the cache.
|
| 594 |
foreach ($form_section[$type][$form_area] as $key => $item) {
|
| 595 |
unset($form_section[$type][$form_area][$key]);
|
| 596 |
}
|
| 597 |
$require_js = array();
|
| 598 |
foreach ($form_elements as $delta => $item) {
|
| 599 |
$form_section[$type][$form_area][$delta] = $item;
|
| 600 |
}
|
| 601 |
if ($type == 'filter') {
|
| 602 |
$form = $form_section;
|
| 603 |
}
|
| 604 |
else {
|
| 605 |
$form['display'] = $form_section;
|
| 606 |
}
|
| 607 |
|
| 608 |
form_set_cache($form_build_id, $form, $form_state);
|
| 609 |
$form += array(
|
| 610 |
'#post' => $_POST,
|
| 611 |
'#programmed' => FALSE,
|
| 612 |
);
|
| 613 |
|
| 614 |
// Rebuild the form.
|
| 615 |
$form = form_builder('_simplelist_edit_form', $form, $form_state);
|
| 616 |
|
| 617 |
// Render the new output.
|
| 618 |
if ($type == 'filter') {
|
| 619 |
$choice_form = $form[$type][$form_area];
|
| 620 |
}
|
| 621 |
else {
|
| 622 |
$choice_form = $form['display'][$type][$form_area];
|
| 623 |
}
|
| 624 |
unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers.
|
| 625 |
|
| 626 |
$output = theme('status_messages') . drupal_render($choice_form);
|
| 627 |
|
| 628 |
drupal_json(array('status' => TRUE, 'data' => $output));
|
| 629 |
}
|
| 630 |
|
| 631 |
/**
|
| 632 |
* Basic edit form - displays form for user to add/edit a simplelist.
|
| 633 |
*
|
| 634 |
* Note that filter and display-specific simplelist elements are handled by their class in the get_filter_form_submit
|
| 635 |
* or get_display_form_submit methods.
|
| 636 |
*
|
| 637 |
* @param unknown_type $form_state
|
| 638 |
* @param unknown_type $simplelist
|
| 639 |
* @param unknown_type $op
|
| 640 |
* @return unknown
|
| 641 |
*/
|
| 642 |
function _simplelist_edit_form(&$form_state, $simplelist, $op = '') {
|
| 643 |
simplelist_require_all_filter_classes();
|
| 644 |
simplelist_require_all_display_classes();
|
| 645 |
drupal_add_js('misc/autocomplete.js'); // Because if we need it it's better to have it now than mess with it in the AHAH.
|
| 646 |
$form = array();
|
| 647 |
|
| 648 |
$form['slid'] = array('#type' => 'value', '#value' => $simplelist->slid);
|
| 649 |
$form['simplelist'] = array('#type' => 'value', '#value' => $simplelist);
|
| 650 |
|
| 651 |
$form['basic-info'] = array(
|
| 652 |
'#type' => 'fieldset',
|
| 653 |
'#collapsible' => true,
|
| 654 |
'#collapsed' => false,
|
| 655 |
'#title' => t('Basic Information'),
|
| 656 |
);
|
| 657 |
|
| 658 |
$form['basic-info']['name'] = array(
|
| 659 |
'#type' => 'textfield',
|
| 660 |
'#title' => t('Name'),
|
| 661 |
'#default_value' => $simplelist->name,
|
| 662 |
'#size' => 20,
|
| 663 |
'#maxlength' => 32,
|
| 664 |
'#description' => t('The unique identifier of the simplelist. Only alphanumeric and _ allowed here'),
|
| 665 |
'#required' => true,
|
| 666 |
);
|
| 667 |
|
| 668 |
$form['basic-info']['access'] = array(
|
| 669 |
'#type' => 'checkboxes',
|
| 670 |
'#title' => t('Access'),
|
| 671 |
'#default_value' => $simplelist->access,
|
| 672 |
'#options' => user_roles(),
|
| 673 |
'#description' => t('Only the checked roles will be able to see this simplelist block or page in any form; if no roles are checked, access will not be restricted.'),
|
| 674 |
);
|
| 675 |
|
| 676 |
$form['basic-info']['description'] = array(
|
| 677 |
'#type' => 'textfield',
|
| 678 |
'#title' => t('Description'),
|
| 679 |
'#default_value' => $simplelist->description,
|
| 680 |
'#size' => 60,
|
| 681 |
'#maxlength' => 255,
|
| 682 |
'#description' => t('A description of the simplelist for the admin list.'),
|
| 683 |
);
|
| 684 |
|
| 685 |
$form['basic-info']['cache'] = array(
|
| 686 |
'#type' => 'select',
|
| 687 |
'#title' => 'Block Caching',
|
| 688 |
'#default_value' => $simplelist->cache,
|
| 689 |
'#options' => array(
|
| 690 |
BLOCK_NO_CACHE => t('No Caching'),
|
| 691 |
BLOCK_CACHE_PER_ROLE => t('Cache by role'),
|
| 692 |
BLOCK_CACHE_PER_USER => t('Cache by user'),
|
| 693 |
BLOCK_CACHE_PER_PAGE => t('Cache by page'),
|
| 694 |
BLOCK_CACHE_GLOBAL => t('Cache Globally')),
|
| 695 |
'#multiple' => FALSE,
|
| 696 |
'#required' => TRUE,
|
| 697 |
'#description' => t('How the block should be cached by drupal.'),
|
| 698 |
);
|
| 699 |
|
| 700 |
$form['basic-info']['published'] = array(
|
| 701 |
'#type' => 'select',
|
| 702 |
'#title' => 'Show Published Nodes?',
|
| 703 |
'#default_value' => $simplelist->published,
|
| 704 |
'#options' => array(
|
| 705 |
SIMPLELIST_UNPUBLISHED_NODES => t('Show only unpublished nodes'),
|
| 706 |
SIMPLELIST_PUBLISHED_NODES => t('Show only published nodes - Recommended'),
|
| 707 |
SIMPLELIST_ALL_NODES => t('Show all nodes'),
|
| 708 |
),
|
| 709 |
'#multiple' => FALSE,
|
| 710 |
'#required' => TRUE,
|
| 711 |
'#description' => t('Indicate if the list should filter nodes by their status. It\'s recommended that you leave it at \'Show only published nodes\'.'),
|
| 712 |
);
|
| 713 |
|
| 714 |
$form['filter'] = array(
|
| 715 |
'#type' => 'fieldset',
|
| 716 |
'#collapsible' => true,
|
| 717 |
'#collapsed' => false,
|
| 718 |
'#title' => t('Filter Options'),
|
| 719 |
);
|
| 720 |
|
| 721 |
$form['filter']['help'] = array(
|
| 722 |
'#value' => '<p>This section is where you indicate what sort of information you want to display, and the order to display it in.</p>',
|
| 723 |
'#weight' => -10,
|
| 724 |
);
|
| 725 |
|
| 726 |
$form['filter']['filter_name'] = array(
|
| 727 |
'#type' => 'select',
|
| 728 |
'#title' => t('Filter'),
|
| 729 |
'#default_value' => $simplelist->filter_name,
|
| 730 |
'#options' => _simplelist_get_filter_options(),
|
| 731 |
'#multiple' => FALSE,
|
| 732 |
'#required' => TRUE,
|
| 733 |
'#description' => t('What sort of a search for information you want.'),
|
| 734 |
'#weight' => -9,
|
| 735 |
'#ahah' => array(
|
| 736 |
'path' => 'simplelist/filter/ahah',
|
| 737 |
'wrapper' => 'filter-choices',
|
| 738 |
'method' => 'replace',
|
| 739 |
'effect' => 'fade',
|
| 740 |
),
|
| 741 |
);
|
| 742 |
|
| 743 |
// Container for just the filter choices.
|
| 744 |
$form['filter']['SimpleListNodeFilter'] = array(
|
| 745 |
'#prefix' => '<div id="filter-choices">',
|
| 746 |
'#suffix' => '</div>',
|
| 747 |
'#theme' => 'filter_choices',
|
| 748 |
);
|
| 749 |
|
| 750 |
$form_elements = call_user_func(array($simplelist->filter_name, 'get_filter_form'), $simplelist);
|
| 751 |
|
| 752 |
foreach ($form_elements as $delta => $item) {
|
| 753 |
$form['filter']['SimpleListNodeFilter'][$delta] = $item;
|
| 754 |
}
|
| 755 |
|
| 756 |
$form['display'] = array(
|
| 757 |
'#type' => 'fieldset',
|
| 758 |
'#collapsible' => true,
|
| 759 |
'#collapsed' => false,
|
| 760 |
'#title' => t('Display Options'),
|
| 761 |
);
|
| 762 |
|
| 763 |
$form['display']['block'] = array(
|
| 764 |
'#type' => 'fieldset',
|
| 765 |
'#collapsible' => TRUE,
|
| 766 |
'#collapsed' => FALSE,
|
| 767 |
'#title' => t('Block Display Options'),
|
| 768 |
);
|
| 769 |
|
| 770 |
$form['display']['block']['block_select'] = array(
|
| 771 |
'#type' => 'checkbox',
|
| 772 |
'#title' => 'Use Block?',
|
| 773 |
'#default_value' => (!empty($simplelist->displays['block']) && $simplelist->displays['block']->display_name != ''),
|
| 774 |
'#weight' => -9,
|
| 775 |
);
|
| 776 |
|
| 777 |
$block_display_options = _simplelist_get_display_options();
|
| 778 |
$form['display']['block']['block_display_name'] = array(
|
| 779 |
'#type' => 'select',
|
| 780 |
'#title' => t('Display'),
|
| 781 |
'#default_value' => $simplelist->displays['block']->display_name,
|
| 782 |
'#options' => $block_display_options,
|
| 783 |
'#multiple' => FALSE,
|
| 784 |
'#required' => TRUE,
|
| 785 |
'#description' => t('What sort of a block you want.'),
|
| 786 |
'#weight' => -7,
|
| 787 |
'#ahah' => array(
|
| 788 |
'path' => 'simplelist/display/ahah/block',
|
| 789 |
'wrapper' => 'block-display-choices',
|
| 790 |
'method' => 'replace',
|
| 791 |
'effect' => 'fade',
|
| 792 |
),
|
| 793 |
);
|
| 794 |
|
| 795 |
// Container for just the block display choices.
|
| 796 |
$form['display']['block']['block_display'] = array(
|
| 797 |
'#prefix' => '<div id="block-display-choices">',
|
| 798 |
'#suffix' => '</div>',
|
| 799 |
/*'#theme' => 'block_filter_choices',*/
|
| 800 |
);
|
| 801 |
|
| 802 |
$block_display_keys = array_keys($block_display_options);
|
| 803 |
$block_display_name = isset($simplelist->displays['block']->display_name) ? $simplelist->displays['block']->display_name : $block_display_keys[0];
|
| 804 |
$form_elements = call_user_func(array($block_display_name, 'get_display_form'), $simplelist, 'block');
|
| 805 |
|
| 806 |
foreach ($form_elements as $delta => $item) {
|
| 807 |
$form['display']['block']['block_display'][$delta] = $item;
|
| 808 |
}
|
| 809 |
|
| 810 |
$form['display']['page'] = array(
|
| 811 |
'#type' => 'fieldset',
|
| 812 |
'#collapsible' => TRUE,
|
| 813 |
'#collapsed' => FALSE,
|
| 814 |
'#title' => t('Page Display Options'),
|
| 815 |
);
|
| 816 |
|
| 817 |
$form['display']['page']['page_select'] = array(
|
| 818 |
'#type' => 'checkbox',
|
| 819 |
'#title' => 'Use Page?',
|
| 820 |
'#default_value' => (!empty($simplelist->displays['page']) && $simplelist->displays['page']->display_name != ''),
|
| 821 |
'#weight' => -9,
|
| 822 |
);
|
| 823 |
|
| 824 |
$page_display_options = _simplelist_get_display_options();
|
| 825 |
$form['display']['page']['page_display_name'] = array(
|
| 826 |
'#type' => 'select',
|
| 827 |
'#title' => t('Display'),
|
| 828 |
'#default_value' => $simplelist->displays['page']->display_name,
|
| 829 |
'#options' => $page_display_options,
|
| 830 |
'#multiple' => FALSE,
|
| 831 |
'#required' => TRUE,
|
| 832 |
'#description' => t('What sort of a page you want.'),
|
| 833 |
'#weight' => -9,
|
| 834 |
'#ahah' => array(
|
| 835 |
'path' => 'simplelist/display/ahah/page',
|
| 836 |
'wrapper' => 'page-display-choices',
|
| 837 |
'method' => 'replace',
|
| 838 |
'effect' => 'fade',
|
| 839 |
),
|
| 840 |
);
|
| 841 |
|
| 842 |
// Container for just the block display choices.
|
| 843 |
$form['display']['page']['page_display'] = array(
|
| 844 |
'#prefix' => '<div id="page-display-choices">',
|
| 845 |
'#suffix' => '</div>',
|
| 846 |
/*'#theme' => 'block_filter_choices',*/
|
| 847 |
);
|
| 848 |
|
| 849 |
$page_display_keys = array_keys($page_display_options);
|
| 850 |
$page_display_name = isset($simplelist->displays['page']->display_name) ? $simplelist->displays['page']->display_name : $page_display_keys[0];
|
| 851 |
|
| 852 |
$form_elements = call_user_func(array($page_display_name, 'get_display_form'), $simplelist, 'page');
|
| 853 |
|
| 854 |
foreach ($form_elements as $delta => $item) {
|
| 855 |
$form['display']['page']['page_display'][$delta] = $item;
|
| 856 |
}
|
| 857 |
|
| 858 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
|
| 859 |
|
| 860 |
return $form;
|
| 861 |
}
|
| 862 |
|
| 863 |
/**
|
| 864 |
* Validates that a given value is a whole number between 1 and 999
|
| 865 |
*
|
| 866 |
* @param string $value
|
| 867 |
* The value to check
|
| 868 |
* @return boolean
|
| 869 |
* True if the value is an integer between 1 and 999.
|
| 870 |
*/
|
| 871 |
function _simplelist_validate_numeric($value) {
|
| 872 |
return (is_numeric($value) && $value > 0 && $value <= 999 && $value == (int)$value );
|
| 873 |
}
|
| 874 |
|
| 875 |
/**
|
| 876 |
* Simplelist add/edit for validation.
|
| 877 |
*
|
| 878 |
* Note that we also call the filters and displays to use their own form validates.
|
| 879 |
*
|
| 880 |
* @param unknown_type $form
|
| 881 |
* @param unknown_type $form_state
|
| 882 |
*/
|
| 883 |
function _simplelist_edit_form_validate(&$form, &$form_state) {
|
| 884 |
simplelist_require_all_filter_classes();
|
| 885 |
simplelist_require_all_display_classes();
|
| 886 |
|
| 887 |
// Validate the name is good.
|
| 888 |
if (preg_match('![^a-z0-9_]!i', $form_state['values']['name'])) {
|
| 889 |
form_set_error('name', t('Simplelist Names can only contain the letters a-z, numbers, and the underscore character.'));
|
| 890 |
}
|
| 891 |
else {
|
| 892 |
// Assure that the name is unique.
|
| 893 |
$count = db_result(db_query("SELECT COUNT(slid) FROM {simplelist} WHERE name = '%s' AND slid <> %d", $form_state['values']['name'], $form_state['values']['slid']));
|
| 894 |
if ($count) {
|
| 895 |
form_set_error('name', t('Simplelist names must be unique - please choose a different name, as this one is already in use.'));
|
| 896 |
}
|
| 897 |
}
|
| 898 |
|
| 899 |
call_user_func(array($form_state['values']['filter_name'], 'get_filter_form_validate'), $form, $form_state);
|
| 900 |
|
| 901 |
if ($form_state['values']['block_select']) {
|
| 902 |
call_user_func(array($form_state['values']['block_display_name'], 'get_display_form_validate'), $form, $form_state, 'block');
|
| 903 |
}
|
| 904 |
|
| 905 |
if ($form_state['values']['page_select']) {
|
| 906 |
call_user_func(array($form_state['values']['page_display_name'], 'get_display_form_validate'), $form, $form_state, 'page');
|
| 907 |
}
|
| 908 |
|
| 909 |
// Make sure that *one* of the display areas is enabled, for goodness sakes.
|
| 910 |
if (! ($form_state['values']['block_select'] || $form_state['values']['page_select'])) {
|
| 911 |
form_set_error('block_select', t('A simplelist requires either the <em>Use Block?</em> or <em>Use Page?</em> to be displayed.'));
|
| 912 |
}
|
| 913 |
}
|
| 914 |
|
| 915 |
/**
|
| 916 |
* Simplelist add/edit submit function
|
| 917 |
*
|
| 918 |
* @param unknown_type $form_id
|
| 919 |
* @param unknown_type $form_state
|
| 920 |
*/
|
| 921 |
function _simplelist_edit_form_submit($form_id, &$form_state) {
|
| 922 |
simplelist_require_all_filter_classes();
|
| 923 |
simplelist_require_all_display_classes();
|
| 924 |
|
| 925 |
|
| 926 |
if ($form_state['values']['slid'] == 0) { // Inserting new simplelist.
|
| 927 |
_simplelist_insert($form_id, $form_state);
|
| 928 |
if ($form_state['values']['slid'] != 0) {
|
| 929 |
drupal_set_message('Simplelist '. $form_state['values']['name'] .' has been created');
|
| 930 |
}
|
| 931 |
}
|
| 932 |
else {
|
| 933 |
_simplelist_update($form_id, $form_state);
|
| 934 |
drupal_set_message('Simplelist '. $form_state['values']['name'] .' has been updated');
|
| 935 |
}
|
| 936 |
|
| 937 |
|
| 938 |
$form_state['redirect'] = 'admin/build/simplelist';
|
| 939 |
}
|
| 940 |
|
| 941 |
/**
|
| 942 |
* Prepare the access choices for writing to the db.
|
| 943 |
*
|
| 944 |
* @param unknown_type $form_state
|
| 945 |
* @return unknown
|
| 946 |
*/
|
| 947 |
function _simplelist_prepare_access($form_state) {
|
| 948 |
$access = array();
|
| 949 |
foreach ($form_state['values']['access'] as $key => $value) {
|
| 950 |
if ($value) {
|
| 951 |
$access[] = $key;
|
| 952 |
}
|
| 953 |
}
|
| 954 |
return $access;
|
| 955 |
}
|
| 956 |
|
| 957 |
/**
|
| 958 |
* Writes the new simplelist into the database.
|
| 959 |
*
|
| 960 |
* @param unknown_type $form_id
|
| 961 |
* @param unknown_type $form_state
|
| 962 |
*/
|
| 963 |
function _simplelist_insert($form_id, &$form_state) {
|
| 964 |
$query = "INSERT INTO {simplelist} (name, description, access, filter_name, filter_data, sort_name, sort_data, cache, published) ".
|
| 965 |
"VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)";
|
| 966 |
db_query($query, $form_state['values']['name'], $form_state['values']['description'], serialize(_simplelist_prepare_access($form_state)), $form_state['values']['filter_name'],
|
| 967 |
$form_state['values']['filter_data'], $form_state['values']['sort_name'], $form_state['values']['sort_data'],
|
| 968 |
$form_state['values']['cache'], $form_state['values']['published']);
|
| 969 |
|
| 970 |
$slid = db_last_insert_id('simplelist', 'slid');
|
| 971 |
$form_state['values']['slid'] = $slid;
|
| 972 |
call_user_func(array($form_state['values']['filter_name'], 'get_filter_form_submit'), $form_id, $form_state);
|
| 973 |
|
| 974 |
if ($form_state['values']['block_select']) {
|
| 975 |
call_user_func(array($form_state['values']['block_display_name'], 'get_display_form_submit'), $form_id, $form_state, 'block');
|
| 976 |
}
|
| 977 |
if ($form_state['values']['page_select']) {
|
| 978 |
call_user_func(array($form_state['values']['page_display_name'], 'get_display_form_submit'), $form_id, $form_state, 'page');
|
| 979 |
menu_rebuild();
|
| 980 |
}
|
| 981 |
}
|
| 982 |
|
| 983 |
/**
|
| 984 |
* Updates the simplelist into the database.
|
| 985 |
*
|
| 986 |
* @param unknown_type $form_id
|
| 987 |
* @param unknown_type $form_state
|
| 988 |
*/
|
| 989 |
function _simplelist_update($form_id, &$form_state) {
|
| 990 |
$slid = $form_state['values']['slid'];
|
| 991 |
$old_simplelist = $form_state['values']['simplelist'];
|
| 992 |
|
| 993 |
$query = "UPDATE {simplelist} SET name = '%s', description = '%s', access = '%s', filter_name = '%s', filter_data = '%s', ".
|
| 994 |
"sort_name = '%s', sort_data = '%s', cache = %d, published = %d WHERE slid = %d";
|
| 995 |
db_query($query, $form_state['values']['name'], $form_state['values']['description'], serialize(_simplelist_prepare_access($form_state)), $form_state['values']['filter_name'],
|
| 996 |
$form_state['values']['filter_data'], $form_state['values']['sort_name'], $form_state['values']['sort_data'],
|
| 997 |
$form_state['values']['cache'], $form_state['values']['published'], $slid);
|
| 998 |
|
| 999 |
// Are we changing filters? If so, we need to clean up after the old one...
|
| 1000 |
if ($old_simplelist->filter_name != $form_state['values']['filter_name']) {
|
| 1001 |
call_user_func(array($old_simplelist->filter_name, 'clear_existing_settings'), $slid, $form_id, $form_state);
|
| 1002 |
}
|
| 1003 |
call_user_func(array($form_state['values']['filter_name'], 'get_filter_form_submit'), $form_id, $form_state);
|
| 1004 |
|
| 1005 |
// Are we changing the block display? If so, we'll need to clean up after the old one...
|
| 1006 |
if ($old_simplelist->displays['block']->display_name != '' && $old_simplelist->displays['block']->display_name != $form_state['values']['block_display_name']) {
|
| 1007 |
call_user_func(array($old_simplelist->displays['block']->display_name, 'clear_existing_settings'), $slid, $form_id, $form_state, 'block');
|
| 1008 |
}
|
| 1009 |
call_user_func(array($form_state['values']['block_display_name'], 'get_display_form_submit'), $form_id, $form_state, 'block');
|
| 1010 |
|
| 1011 |
// And again, if we're changing the page display, we'll need to clean up after the old one...
|
| 1012 |
if ($old_simplelist->displays['page']->display_name != '' && $old_simplelist->displays['page']->display_name != $form_state['values']['page_display_name']) {
|
| 1013 |
call_user_func(array($old_simplelist->displays['page']->display_name, 'clear_existing_settings'), $slid, $form_id, $form_state, 'page');
|
| 1014 |
}
|
| 1015 |
$menu_rebuild = call_user_func(array($form_state['values']['page_display_name'], 'get_display_form_submit'), $form_id, $form_state, 'page');
|
| 1016 |
|
| 1017 |
if ($menu_rebuild) {
|
| 1018 |
menu_rebuild();
|
| 1019 |
}
|
| 1020 |
}
|