Esempio n. 1
0
 /**
  * Creates a new instance of the portfolio plugin
  *
  * @param string $name name of the instance
  * @param stdClass $data config data for the instance
  * @return portfolio_plugin_base
  */
 protected function enable_plugin($name = 'Instance name', $data = null)
 {
     $data = $data ?: new stdClass();
     $instance = portfolio_static_function($this->pluginname, 'create_instance', $this->pluginname, $name, $data);
     core_plugin_manager::reset_caches();
     return $instance;
 }
Esempio n. 2
0
 /**
  * Validate admin config form
  *
  * @param stdObject $data form data
  * @return array
  */
 public function validation($data)
 {
     global $DB;
     $errors = array();
     if ($DB->count_records('portfolio_instance', array('name' => $data['name'], 'plugin' => $data['plugin'])) > 1) {
         $errors = array('name' => get_string('err_uniquename', 'portfolio'));
     }
     $pluginerrors = array();
     if ($this->instance) {
         $pluginerrors = $this->instance->admin_config_validation($data);
     } else {
         $pluginerrors = portfolio_static_function($this->plugin, 'admin_config_validation', $data);
     }
     if (is_array($pluginerrors)) {
         $errors = array_merge($errors, $pluginerrors);
     }
     return $errors;
 }
/**
* helper function to check all the plugins for sanity and set any insane ones to invisible.
*
* @param array $plugins to check (if null, defaults to all)
*               one string will work too for a single plugin.
*
* @return array array of insane instances (keys= id, values = reasons (keys for plugin lang)
*/
function portfolio_plugin_sanity_check($plugins = null)
{
    global $DB;
    if (is_string($plugins)) {
        $plugins = array($plugins);
    } else {
        if (empty($plugins)) {
            $plugins = get_plugin_list('portfolio');
            $plugins = array_keys($plugins);
        }
    }
    $insane = array();
    foreach ($plugins as $plugin) {
        if ($result = portfolio_static_function($plugin, 'plugin_sanity_check')) {
            $insane[$plugin] = $result;
        }
    }
    if (empty($insane)) {
        return array();
    }
    list($where, $params) = $DB->get_in_or_equal(array_keys($insane));
    $where = ' plugin ' . $where;
    $DB->set_field_select('portfolio_instance', 'visible', 0, $where, $params);
    return $insane;
}
Esempio n. 4
0
 /**
  * Builds XHTML to display the control
  *
  * @param string $data Unused
  * @param string $query
  * @return string XHTML to display the control
  */
 public function output_html($data, $query = '')
 {
     global $CFG, $OUTPUT;
     $output = $OUTPUT->box_start('generalbox');
     $namestr = get_string('name');
     $pluginstr = get_string('plugin', 'portfolio');
     $plugins = get_plugin_list('portfolio');
     $plugins = array_keys($plugins);
     $instances = portfolio_instances(false, false);
     $alreadyplugins = array();
     // to avoid notifications being sent out while admin is editing the page
     define('ADMIN_EDITING_PORTFOLIO', true);
     $insane = portfolio_plugin_sanity_check($plugins);
     $insaneinstances = portfolio_instance_sanity_check($instances);
     $output .= portfolio_report_insane($insane, null, true);
     $output .= portfolio_report_insane($insaneinstances, $instances, true);
     $table = new html_table();
     $table->head = array($namestr, $pluginstr, '');
     $table->data = array();
     foreach ($instances as $i) {
         $row = '';
         $row .= '<a href="' . $this->baseurl . '&edit=' . $i->get('id') . '"><img src="' . $OUTPUT->old_icon_url('t/edit') . '" alt="' . get_string('edit') . '" /></a>' . "\n";
         $row .= '<a href="' . $this->baseurl . '&delete=' . $i->get('id') . '"><img src="' . $OUTPUT->old_icon_url('t/delete') . '" alt="' . get_string('delete') . '" /></a>' . "\n";
         if (array_key_exists($i->get('plugin'), $insane) || array_key_exists($i->get('id'), $insaneinstances)) {
             $row .= '<img src="' . $OUTPUT->old_icon_url('t/show') . '" alt="' . get_string('hidden', 'portfolio') . '" />' . "\n";
         } else {
             $row .= ' <a href="' . $this->baseurl . '&hide=' . $i->get('id') . '"><img src="' . $OUTPUT->old_icon_url('t/' . ($i->get('visible') ? 'hide' : 'show')) . '" alt="' . get_string($i->get('visible') ? 'hide' : 'show') . '" /></a>' . "\n";
         }
         $table->data[] = array($i->get('name'), $i->get_name() . ' (' . $i->get('plugin') . ')', $row);
         if (!in_array($i->get('plugin'), $alreadyplugins)) {
             $alreadyplugins[] = $i->get('plugin');
         }
     }
     $output .= $OUTPUT->table($table);
     $instancehtml = '<br /><br />' . get_string('addnewportfolio', 'portfolio') . ': <br /><br />';
     $addable = 0;
     foreach ($plugins as $p) {
         if (!portfolio_static_function($p, 'allows_multiple') && in_array($p, $alreadyplugins)) {
             continue;
         }
         if (array_key_exists($p, $insane)) {
             continue;
         }
         $instancehtml .= '<a href="' . $this->baseurl . '&amp;new=' . $p . '">' . portfolio_static_function($p, 'get_name') . ' (' . s($p) . ')' . '</a><br />' . "\n";
         $addable++;
     }
     if ($addable) {
         $output .= $instancehtml;
     }
     $output .= $OUTPUT->box_end();
     return highlight($query, $output);
 }
Esempio n. 5
0
 /**
  * This function creates a new instance of a plugin
  * saves it in the database, saves the config
  * and returns it.
  * You shouldn't need to override it
  * unless you're doing something really funky
  *
  * @param string $plugin portfolio plugin to create
  * @param string $name name of new instance
  * @param array $config what the admin config form returned
  * @return object subclass of portfolio_plugin_base
  */
 public static function create_instance($plugin, $name, $config)
 {
     global $DB, $CFG;
     $new = (object) array('plugin' => $plugin, 'name' => $name);
     if (!portfolio_static_function($plugin, 'allows_multiple_instances')) {
         // check we don't have one already
         if ($DB->record_exists('portfolio_instance', array('plugin' => $plugin))) {
             throw new portfolio_exception('multipleinstancesdisallowed', 'portfolio', '', $plugin);
         }
     }
     $newid = $DB->insert_record('portfolio_instance', $new);
     require_once $CFG->dirroot . '/portfolio/' . $plugin . '/lib.php';
     $classname = 'portfolio_plugin_' . $plugin;
     $obj = new $classname($newid);
     $obj->set_config($config);
     $obj->save();
     return $obj;
 }
Esempio n. 6
0
 // end setup, begin output
 if ($mform->is_cancelled()) {
     redirect($baseurl);
     exit;
 } else {
     if ($fromform = $mform->get_data()) {
         // unset whatever doesn't belong in fromform
         foreach (array('edit', 'new', 'plugin', 'sesskey', 'submitbutton') as $key) {
             unset($fromform->{$key});
         }
         //this branch is where you process validated data.
         if ($edit) {
             $instance->set_config($fromform);
             $instance->save();
         } else {
             portfolio_static_function($plugin, 'create_instance', $plugin, $fromform->name, $fromform);
         }
         $savedstr = get_string('instancesaved', 'portfolio');
         admin_externalpage_print_header();
         echo $OUTPUT->heading($savedstr);
         redirect($baseurl, $savedstr, 3);
         exit;
     } else {
         admin_externalpage_print_header();
         echo $OUTPUT->heading(get_string('configplugin', 'portfolio'));
         echo $OUTPUT->box_start();
         $mform->display();
         echo $OUTPUT->box_end();
         $return = false;
     }
 }
Esempio n. 7
0
$callbackcomponent = optional_param('callbackcomponent', null, PARAM_PATH);
// Callback component eg mod_forum - the component of the exporting content.
$callbackclass = optional_param('callbackclass', null, PARAM_ALPHAEXT);
// Callback class eg forum_portfolio_caller - the class to handle the exporting content.
$callerformats = optional_param('callerformats', null, PARAM_TAGLIST);
// Comma separated list of formats the specific place exporting content supports.
require_login();
// this is selectively called again with $course later when we know for sure which one we're in.
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/portfolio/add.php', array('id' => $dataid, 'sesskey' => sesskey()));
$PAGE->set_pagelayout('admin');
$exporter = null;
if ($postcontrol && $type && !$dataid) {
    // we're returning from an external system that can't construct dynamic return urls
    // this is a special "one export of this type only per session" case
    if (portfolio_static_function($type, 'allows_multiple_exports')) {
        throw new portfolio_exception('multiplesingleresume', 'portfolio');
    }
    if (!($dataid = portfolio_export_type_to_id($type, $USER->id))) {
        throw new portfolio_exception('invalidtempid', 'portfolio');
    }
} else {
    // we can't do this in the above case, because we're redirecting straight back from an external system
    // this is not really ideal, but since we're in a "staged" wizard, the session key is checked in other stages.
    require_sesskey();
    // pretty much everything in this page is a write that could be hijacked, so just do this at the top here
}
// if we have a dataid, it means we're in the middle of an export,
// so rewaken it and continue.
if (!empty($dataid)) {
    try {
Esempio n. 8
0
                    if (!portfolio_static_function($p, 'allows_multiple_instances') && in_array($p, $usedplugins)) {
                        continue;
                    }
                    // Check if it is misconfigured - if so store in array then display later
                    if (array_key_exists($p, $insane)) {
                        $insaneplugins[] = $p;
                    } else {
                        $select = new single_select(portfolio_action_url($p, 'pf'), 'action', $actionchoicesfornew, 'delete', null, 'applyto' . $p);
                        $select->set_label(get_string('action'), array('class' => 'accesshide'));
                        $table->data[] = array(portfolio_static_function($p, 'get_name'), $OUTPUT->render($select), '');
                    }
                }
            }
            // Loop through all the insane plugins
            if (!empty($insaneplugins)) {
                foreach ($insaneplugins as $p) {
                    $table->data[] = array(portfolio_static_function($p, 'get_name'), $strdelete . " " . $OUTPUT->help_icon($insane[$p], 'portfolio_' . $p), '');
                }
            }
            $output .= html_writer::table($table);
            $output .= $OUTPUT->box_end();
            echo $output;
            $return = false;
        }
    }
}
if ($return) {
    // Redirect to base
    redirect($baseurl);
}
echo $OUTPUT->footer();
Esempio n. 9
0
/**
 * Parse a file to find out what functions/methods exist in it, and add entries
 * for the remote-call-enabled functions to the database.
 *
 * The path to a file, e.g. auth/mnet/auth.php can be thought of as
 * type/parentname/docname
 *
 * @param  string   $type           mod, auth or enrol
 * @param  string   $parentname     Implementation of type, e.g. 'mnet' in the
 *                                  case of auth/mnet/auth.php
 * @return bool                     True on success, else false
 */
function mnet_get_functions($type, $parentname)
{
    global $CFG, $DB;
    $dataobject = new stdClass();
    $docname = $type . '.php';
    $publishes = array();
    if ('mod' == $type) {
        $docname = 'rpclib.php';
        $relname = '/mod/' . $parentname . '/' . $docname;
        $filename = $CFG->dirroot . $relname;
        if (file_exists($filename)) {
            include_once $filename;
        }
        $mnet_publishes = $parentname . '_mnet_publishes';
        if (function_exists($mnet_publishes)) {
            (array) ($publishes = $mnet_publishes());
        }
    } else {
        if ('portfolio' == $type) {
            $docname = 'lib.php';
            $relname = '/portfolio/type/' . $parentname . '/' . $docname;
            $filename = $CFG->dirroot . $relname;
            require_once $CFG->libdir . '/portfoliolib.php';
            $publishes = (array) portfolio_static_function($parentname, 'mnet_publishes');
        } else {
            if ('repository' == $type) {
                $docname = 'repository.class.php';
                $relname = '/repository/' . $parentname . '/' . $docname;
                $filename = $CFG->dirroot . $relname;
                require_once $CFG->dirroot . '/repository/lib.php';
                $publishes = (array) repository::static_function($parentname, 'mnet_publishes');
            } else {
                // auth or enrol
                $relname = '/' . $type . '/' . $parentname . '/' . $docname;
                $filename = $CFG->dirroot . $relname;
                if (file_exists($filename)) {
                    include_once $filename;
                }
                $class = $type . ($type == 'enrol' ? 'ment' : '') . '_plugin_' . $parentname;
                if (class_exists($class)) {
                    $object = new $class();
                    if (method_exists($object, 'mnet_publishes')) {
                        (array) ($publishes = $object->mnet_publishes());
                    }
                }
            }
        }
    }
    $methodServiceArray = array();
    foreach ($publishes as $service) {
        if (is_array($service['methods'])) {
            foreach ($service['methods'] as $methodname) {
                $methodServiceArray[$methodname][] = $service;
            }
        }
    }
    // Disable functions that don't exist (any more) in the source
    // Should these be deleted? What about their permissions records?
    $rpcrecords = $DB->get_records('mnet_rpc', array('parent' => $parentname, 'parent_type' => $type), 'function_name ASC ');
    if (!empty($rpcrecords)) {
        foreach ($rpcrecords as $rpc) {
            if (!array_key_exists($rpc->function_name, $methodServiceArray)) {
                $rpc->enabled = 0;
                $DB->update_record('mnet_rpc', $rpc);
            }
        }
    }
    if (!file_exists($filename)) {
        return false;
    }
    if (extension_loaded('tokenizer')) {
        include_once "{$CFG->dirroot}/{$CFG->admin}/mnet/MethodTable.php";
        $functions = (array) MethodTable::create($filename, false);
    }
    foreach ($methodServiceArray as $method => $servicearray) {
        if (!empty($functions[$method])) {
            $details = $functions[$method];
            $profile = $details['arguments'];
            if (!isset($details['returns'])) {
                array_unshift($profile, array('type' => 'void', 'description' => 'No return value'));
            } else {
                array_unshift($profile, $details['returns']);
            }
            $dataobject->profile = serialize($profile);
            $dataobject->help = $details['description'];
        } else {
            $dataobject->profile = serialize(array(array('type' => 'void', 'description' => 'No return value')));
            $dataobject->help = '';
        }
        $dataobject->function_name = $method;
        $dataobject->xmlrpc_path = $type . '/' . $parentname . '/' . $docname . '/' . $method;
        $dataobject->parent_type = $type;
        $dataobject->parent = $parentname;
        $dataobject->enabled = '0';
        if ($record_exists = $DB->get_record('mnet_rpc', array('xmlrpc_path' => $dataobject->xmlrpc_path))) {
            $dataobject->id = $record_exists->id;
            $dataobject->enabled = $record_exists->enabled;
            $DB->update_record('mnet_rpc', $dataobject);
        } else {
            $dataobject->id = $DB->insert_record('mnet_rpc', $dataobject, true);
        }
        foreach ($servicearray as $service) {
            $serviceobj = $DB->get_record('mnet_service', array('name' => $service['name']));
            if (false == $serviceobj) {
                $serviceobj = new stdClass();
                $serviceobj->name = $service['name'];
                $serviceobj->apiversion = $service['apiversion'];
                $serviceobj->offer = 1;
                $serviceobj->id = $DB->insert_record('mnet_service', $serviceobj, true);
            }
            if (false == $DB->get_record('mnet_service2rpc', array('rpcid' => $dataobject->id, 'serviceid' => $serviceobj->id))) {
                $obj = new stdClass();
                $obj->rpcid = $dataobject->id;
                $obj->serviceid = $serviceobj->id;
                $DB->insert_record('mnet_service2rpc', $obj, true);
            }
        }
    }
    return true;
}