~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/portfoliolib.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
534
534
}
535
535
 
536
536
/**
 
537
 * Return whether there are visible instances in portfolio.
 
538
 *
 
539
 * @return bool true when there are some visible instances.
 
540
 */
 
541
function portfolio_has_visible_instances() {
 
542
    global $DB;
 
543
    return $DB->record_exists('portfolio_instance', array('visible' => 1));
 
544
}
 
545
 
 
546
/**
537
547
 * Supported formats currently in use.
538
548
 * Canonical place for a list of all formats
539
549
 * that portfolio plugins and callers
815
825
    if (is_string($plugins)) {
816
826
        $plugins = array($plugins);
817
827
    } else if (empty($plugins)) {
818
 
        $plugins = get_plugin_list('portfolio');
 
828
        $plugins = core_component::get_plugin_list('portfolio');
819
829
        $plugins = array_keys($plugins);
820
830
    }
821
831
 
1224
1234
 * @return object|array|string
1225
1235
 */
1226
1236
function portfolio_rewrite_pluginfile_url_callback($contextid, $component, $filearea, $itemid, $format, $options, $matches) {
1227
 
    $matches = $matches[0]; // no internal matching
 
1237
    $matches = $matches[0]; // No internal matching.
 
1238
 
 
1239
    // Loads the HTML.
1228
1240
    $dom = new DomDocument();
1229
 
    if (!$dom->loadXML($matches)) {
1230
 
        return $matches;
1231
 
    }
 
1241
    if (!$dom->loadHTML($matches)) {
 
1242
        return $matches;
 
1243
    }
 
1244
 
 
1245
    // Navigates to the node.
 
1246
    $xpath = new DOMXPath($dom);
 
1247
    $nodes = $xpath->query('/html/body/child::*');
 
1248
    if (empty($nodes) || count($nodes) > 1) {
 
1249
        // Unexpected sequence, none or too many nodes.
 
1250
        return $matches;
 
1251
    }
 
1252
    $dom = $nodes->item(0);
 
1253
 
1232
1254
    $attributes = array();
1233
 
    foreach ($dom->documentElement->attributes as $attr => $node) {
 
1255
    foreach ($dom->attributes as $attr => $node) {
1234
1256
        $attributes[$attr] = $node->value;
1235
1257
    }
1236
1258
    // now figure out the file
1281
1303
        // Get rid of the first slash (if it exists).
1282
1304
        $component = ltrim($component, '/');
1283
1305
        // Get a list of valid plugin types.
1284
 
        $plugintypes = get_plugin_types(false);
 
1306
        $plugintypes = core_component::get_plugin_types();
1285
1307
        // Assume it is not valid for now.
1286
1308
        $isvalid = false;
1287
1309
        // Go through the plugin types.
1288
1310
        foreach ($plugintypes as $type => $path) {
 
1311
            // Getting the path relative to the dirroot.
 
1312
            $path = preg_replace('|^' . preg_quote($CFG->dirroot, '|') . '/|', '', $path);
1289
1313
            if (strrpos($component, $path) === 0) {
1290
1314
                // Found the plugin type.
1291
1315
                $isvalid = true;
1313
1337
    }
1314
1338
 
1315
1339
    // Obtain the component's location.
1316
 
    if (!$componentloc = get_component_directory($component)) {
 
1340
    if (!$componentloc = core_component::get_component_directory($component)) {
1317
1341
        throw new portfolio_button_exception('nocallbackcomponent', 'portfolio', '', $component);
1318
1342
    }
1319
1343
 
1360
1384
 * @return mixed
1361
1385
 */
1362
1386
function portfolio_rewrite_pluginfile_urls($text, $contextid, $component, $filearea, $itemid, $format, $options=null) {
1363
 
    $pattern = '/(<[^<]*?="@@PLUGINFILE@@\/[^>]*?(?:\/>|>.*?<\/[^>]*?>))/';
 
1387
    $patterns = array(
 
1388
        '(<(a|A)[^<]*?href="@@PLUGINFILE@@/[^>]*?>.*?</(a|A)>)',
 
1389
        '(<(img|IMG)\s[^<]*?src="@@PLUGINFILE@@/[^>]*?/?>)',
 
1390
    );
 
1391
    $pattern = '~' . implode('|', $patterns) . '~';
1364
1392
    $callback = partial('portfolio_rewrite_pluginfile_url_callback', $contextid, $component, $filearea, $itemid, $format, $options);
1365
1393
    return preg_replace_callback($pattern, $callback, $text);
1366
1394
}