// use Plugins_admin, because a plugin might be disabled $Plugin =& $admin_Plugins->get_by_ID($plugin_ID); if (!$Plugin) { bad_request_die('Invalid Plugin.'); } param('set_type', 'string', ''); // "Settings" or "UserSettings" if ($set_type != 'Settings') { bad_request_die('Invalid set_type param!'); } param('set_path', '/^\\w+(?:\\[\\w+\\])+$/', ''); load_funcs('plugins/_plugin.funcs.php'); // Init the new setting set: _set_setting_by_path($Plugin, $set_type, $set_path, array()); // Get the new plugin setting set and display it with a fake Form $r = get_plugin_settings_node_by_path($Plugin, $set_type, $set_path, false); $Form = new Form(); // fake Form to display plugin setting autoform_display_field($set_path, $r['set_meta'], $Form, $set_type, $Plugin, NULL, $r['set_node']); break; case 'set_object_link_position': // Change a position of a link on the edit item screen (fieldset "Images & Attachments") // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('link'); // Check item/comment edit permission below after we have the $LinkOwner object ( we call LinkOwner->check_perm ... ) param('link_ID', 'integer', true); param('link_position', 'string', true); $LinkCache =& get_LinkCache(); if (($Link =& $LinkCache->get_by_ID($link_ID)) === false) { // Bad request with incorrect link ID echo '';
/** * Helper method for "add_settings_set" and "delete_settings_set" action. * * Walks the given settings path and either inits the target entry or unsets it ($init_value=NULL). * * @param Plugin * @param string Settings type ("Settings" or "UserSettings") * @param string The settings path, e.g. 'setting[0]foo[1]'. (Is used as array internally for recursion.) * @param mixed The initial value of the setting, typically array() - NULL to unset it (action "delete_settings_set" uses it) * @return array|false */ function _set_setting_by_path(&$Plugin, $set_type, $path, $init_value = array()) { $r = get_plugin_settings_node_by_path($Plugin, $set_type, $path, true); if ($r === false) { return false; } // Make return value handier. Note: list() would copy and destroy the references (setting and set_node)! $set_name =& $r['set_name']; $set_node =& $r['set_node']; $set_meta =& $r['set_meta']; $set_parent =& $r['set_parent']; $set_key =& $r['set_key']; $setting =& $r['setting']; #pre_dump( $r ); #if( isset($set_node) && $init_value !== NULL ) #{ // Setting already exists (and we do not want to delete), e.g. page reload! # return false; # /* # while( isset($l_setting[ $path[0] ]) ) # { // bump the index until not set # $path[0]++; # } # */ #} #else if (is_null($init_value)) { // NULL is meant to unset it unset($set_parent[$set_key]); } else { // Init entries: // destroys reference: $set_node = $init_value; // Copy meta entries: foreach ($set_meta['entries'] as $k => $v) { if (isset($v['defaultvalue'])) { // set to defaultvalue $set_node[$k] = $v['defaultvalue']; } else { if (isset($v['type']) && $v['type'] == 'array') { $set_node[$k] = array(); } else { $set_node[$k] = ''; } } } } // Set it into $Plugin->Settings or $Plugin->UserSettings: $Plugin->{$set_type}->set($set_name, $setting); return $setting; }