function install_blocktype_viewtypes_for_plugin($blocktype) { safe_require('blocktype', $blocktype); $blocktype = blocktype_namespaced_to_single($blocktype); db_begin(); delete_records('blocktype_installed_viewtype', 'blocktype', $blocktype); if ($viewtypes = call_static_method(generate_class_name('blocktype', $blocktype), 'get_viewtypes')) { foreach ($viewtypes as $vt) { insert_record('blocktype_installed_viewtype', (object) array('blocktype' => $blocktype, 'viewtype' => $vt)); } } db_commit(); }
function generate_class_name() { $args = func_get_args(); if (count($args) == 2 && $args[0] == 'blocktype') { return 'PluginBlocktype' . ucfirst(blocktype_namespaced_to_single($args[1])); } return 'Plugin' . implode('', array_map('ucfirst', $args)); }