Example #1
0
 /**
  * Returns a list of Moodle plugins supporting the mobile app.
  *
  * @return array an array of objects containing the plugin information
  */
 public static function get_plugins_supporting_mobile()
 {
     global $CFG;
     require_once $CFG->libdir . '/adminlib.php';
     $pluginsinfo = [];
     $plugintypes = core_component::get_plugin_types();
     foreach ($plugintypes as $plugintype => $unused) {
         // We need to include files here.
         $pluginswithfile = core_component::get_plugin_list_with_file($plugintype, 'db' . DIRECTORY_SEPARATOR . 'mobile.php');
         foreach ($pluginswithfile as $plugin => $notused) {
             $path = core_component::get_plugin_directory($plugintype, $plugin);
             $component = $plugintype . '_' . $plugin;
             $version = get_component_version($component);
             require_once "{$path}/db/mobile.php";
             foreach ($addons as $addonname => $addoninfo) {
                 $plugininfo = array('component' => $component, 'version' => $version, 'addon' => $addonname, 'dependencies' => !empty($addoninfo['dependencies']) ? $addoninfo['dependencies'] : array(), 'fileurl' => '', 'filehash' => '', 'filesize' => 0);
                 // All the mobile packages must be under the plugin mobile directory.
                 $package = $path . DIRECTORY_SEPARATOR . 'mobile' . DIRECTORY_SEPARATOR . $addonname . '.zip';
                 if (file_exists($package)) {
                     $plugininfo['fileurl'] = $CFG->wwwroot . '' . str_replace($CFG->dirroot, '', $package);
                     $plugininfo['filehash'] = sha1_file($package);
                     $plugininfo['filesize'] = filesize($package);
                 }
                 $pluginsinfo[] = $plugininfo;
             }
         }
     }
     return $pluginsinfo;
 }
Example #2
0
 /**
  * Updates the translator database with the strings from files
  *
  * This should be executed each time before going to the translation page
  *
  * @param string $lang language code to checkout
  * @param progress_bar $progressbar optionally, the given progress bar can be updated
  */
 public static function checkout($lang, progress_bar $progressbar = null)
 {
     global $DB;
     // make sure that all components are registered
     $current = $DB->get_records('tool_customlang_components', null, 'name', 'name,version,id');
     foreach (self::list_components() as $component) {
         if (empty($current[$component])) {
             $record = new stdclass();
             $record->name = $component;
             if (!($version = get_component_version($component))) {
                 $record->version = null;
             } else {
                 $record->version = $version;
             }
             $DB->insert_record('tool_customlang_components', $record);
         } elseif ($version = get_component_version($component)) {
             if (is_null($current[$component]->version) or $version > $current[$component]->version) {
                 $DB->set_field('tool_customlang_components', 'version', $version, array('id' => $current[$component]->id));
             }
         }
     }
     unset($current);
     // initialize the progress counter - stores the number of processed strings
     $done = 0;
     $strinprogress = get_string('checkoutinprogress', 'tool_customlang');
     // reload components and fetch their strings
     $stringman = get_string_manager();
     $components = $DB->get_records('tool_customlang_components');
     foreach ($components as $component) {
         $sql = "SELECT stringid, id, lang, componentid, original, master, local, timemodified, timecustomized, outdated, modified\n                      FROM {tool_customlang} s\n                     WHERE lang = ? AND componentid = ?\n                  ORDER BY stringid";
         $current = $DB->get_records_sql($sql, array($lang, $component->id));
         $english = $stringman->load_component_strings($component->name, 'en', true, true);
         if ($lang == 'en') {
             $master =& $english;
         } else {
             $master = $stringman->load_component_strings($component->name, $lang, true, true);
         }
         $local = $stringman->load_component_strings($component->name, $lang, true, false);
         foreach ($english as $stringid => $stringoriginal) {
             $stringmaster = isset($master[$stringid]) ? $master[$stringid] : null;
             $stringlocal = isset($local[$stringid]) ? $local[$stringid] : null;
             $now = time();
             if (!is_null($progressbar)) {
                 $done++;
                 $donepercent = floor(min($done, self::ROUGH_NUMBER_OF_STRINGS) / self::ROUGH_NUMBER_OF_STRINGS * 100);
                 $progressbar->update_full($donepercent, $strinprogress);
             }
             if (isset($current[$stringid])) {
                 $needsupdate = false;
                 $currentoriginal = $current[$stringid]->original;
                 $currentmaster = $current[$stringid]->master;
                 $currentlocal = $current[$stringid]->local;
                 if ($currentoriginal !== $stringoriginal or $currentmaster !== $stringmaster) {
                     $needsupdate = true;
                     $current[$stringid]->original = $stringoriginal;
                     $current[$stringid]->master = $stringmaster;
                     $current[$stringid]->timemodified = $now;
                     $current[$stringid]->outdated = 1;
                 }
                 if ($stringmaster !== $stringlocal) {
                     $needsupdate = true;
                     $current[$stringid]->local = $stringlocal;
                     $current[$stringid]->timecustomized = $now;
                 }
                 if ($needsupdate) {
                     $DB->update_record('tool_customlang', $current[$stringid]);
                     continue;
                 }
             } else {
                 $record = new stdclass();
                 $record->lang = $lang;
                 $record->componentid = $component->id;
                 $record->stringid = $stringid;
                 $record->original = $stringoriginal;
                 $record->master = $stringmaster;
                 $record->timemodified = $now;
                 $record->outdated = 0;
                 if ($stringmaster !== $stringlocal) {
                     $record->local = $stringlocal;
                     $record->timecustomized = $now;
                 } else {
                     $record->local = null;
                     $record->timecustomized = null;
                 }
                 $DB->insert_record('tool_customlang', $record);
             }
         }
     }
     if (!is_null($progressbar)) {
         $progressbar->update_full(100, get_string('checkoutdone', 'tool_customlang'));
     }
 }
Example #3
0
 /**
  * Updates the translator database with the strings from files
  *
  * This should be executed each time before going to the translation page
  *
  * @param string $lang language code to checkout
  */
 public static function checkout($lang)
 {
     global $DB;
     // make sure that all components are registered
     $current = $DB->get_records('report_customlang_components', null, 'name', 'name,version,id');
     foreach (self::list_components() as $component) {
         if (empty($current[$component])) {
             $record = new stdclass();
             $record->name = $component;
             if (!($version = get_component_version($component))) {
                 $record->version = null;
             } else {
                 $record->version = $version;
             }
             $DB->insert_record('report_customlang_components', $record);
         } elseif ($version = get_component_version($component)) {
             if (is_null($current[$component]->version) or $version > $current[$component]->version) {
                 $DB->set_field('report_customlang_components', 'version', $version, array('id' => $current[$component]->id));
             }
         }
     }
     unset($current);
     // reload components and fetch their strings
     $stringman = get_string_manager();
     $components = $DB->get_records('report_customlang_components');
     foreach ($components as $component) {
         $sql = "SELECT stringid, id, lang, componentid, original, master, local, timemodified, timecustomized, outdated, modified\n                      FROM {report_customlang} s\n                     WHERE lang = ? AND componentid = ?\n                  ORDER BY stringid";
         $current = $DB->get_records_sql($sql, array($lang, $component->id));
         $english = $stringman->load_component_strings($component->name, 'en', true, true);
         if ($lang == 'en') {
             $master =& $english;
         } else {
             $master = $stringman->load_component_strings($component->name, $lang, true, true);
         }
         $local = $stringman->load_component_strings($component->name, $lang, true, false);
         foreach ($english as $stringid => $stringoriginal) {
             $stringmaster = isset($master[$stringid]) ? $master[$stringid] : null;
             $stringlocal = isset($local[$stringid]) ? $local[$stringid] : null;
             $now = time();
             if (isset($current[$stringid])) {
                 $needsupdate = false;
                 $currentoriginal = $current[$stringid]->original;
                 $currentmaster = $current[$stringid]->master;
                 $currentlocal = $current[$stringid]->local;
                 if ($currentoriginal !== $stringoriginal or $currentmaster !== $stringmaster) {
                     $needsupdate = true;
                     $current[$stringid]->original = $stringoriginal;
                     $current[$stringid]->master = $stringmaster;
                     $current[$stringid]->timemodified = $now;
                     $current[$stringid]->outdated = 1;
                 }
                 if ($stringmaster !== $stringlocal) {
                     $needsupdate = true;
                     $current[$stringid]->local = $stringlocal;
                     $current[$stringid]->timecustomized = $now;
                 }
                 if ($needsupdate) {
                     $DB->update_record('report_customlang', $current[$stringid]);
                     continue;
                 }
             } else {
                 $record = new stdclass();
                 $record->lang = $lang;
                 $record->componentid = $component->id;
                 $record->stringid = $stringid;
                 $record->original = $stringoriginal;
                 $record->master = $stringmaster;
                 $record->timemodified = $now;
                 $record->outdated = 0;
                 if ($stringmaster !== $stringlocal) {
                     $record->local = $stringlocal;
                     $record->timecustomized = $now;
                 } else {
                     $record->local = null;
                     $record->timecustomized = null;
                 }
                 $DB->insert_record('report_customlang', $record);
             }
         }
     }
 }
Example #4
0
 /**
  * Implements getPlatformInfo
  */
 public function getPlatformInfo()
 {
     global $CFG;
     return array('name' => 'Moodle', 'version' => $CFG->version, 'h5pVersion' => get_component_version('mod_hvp'));
 }
/**
 * Function to require any potential callback files, throwing exceptions
 * if an issue occurs.
 *
 * @param string $component This is the name of the component in Moodle, eg 'mod_forum'
 * @param string $class Name of the class containing the callback functions
 *     activity components should ALWAYS use their name_portfolio_caller
 *     other locations must use something unique
 */
function portfolio_include_callback_file($component, $class = null)
{
    global $CFG;
    require_once $CFG->libdir . '/adminlib.php';
    // It's possible that they are passing a file path rather than passing a component.
    // We want to try and convert this to a component name, eg. mod_forum.
    $pos = strrpos($component, '/');
    if ($pos !== false) {
        // Get rid of the first slash (if it exists).
        $component = ltrim($component, '/');
        // Get a list of valid plugin types.
        $plugintypes = get_plugin_types(false);
        // Assume it is not valid for now.
        $isvalid = false;
        // Go through the plugin types.
        foreach ($plugintypes as $type => $path) {
            if (strrpos($component, $path) === 0) {
                // Found the plugin type.
                $isvalid = true;
                $plugintype = $type;
                $pluginpath = $path;
            }
        }
        // Throw exception if not a valid component.
        if (!$isvalid) {
            throw new coding_exception('Somehow a non-valid plugin path was passed, could be a hackz0r attempt, exiting.');
        }
        // Remove the file name.
        $component = trim(substr($component, 0, $pos), '/');
        // Replace the path with the type.
        $component = str_replace($pluginpath, $plugintype, $component);
        // Ok, replace '/' with '_'.
        $component = str_replace('/', '_', $component);
        // Place a debug message saying the third parameter should be changed.
        debugging('The third parameter sent to the function set_callback_options should be the component name, not a file path, please update this.', DEBUG_DEVELOPER);
    }
    // Check that it is a valid component.
    if (!get_component_version($component)) {
        throw new portfolio_button_exception('nocallbackcomponent', 'portfolio', '', $component);
    }
    // Obtain the component's location.
    if (!($componentloc = get_component_directory($component))) {
        throw new portfolio_button_exception('nocallbackcomponent', 'portfolio', '', $component);
    }
    // Check if the component contains the necessary file for the portfolio plugin.
    // These are locallib.php, portfoliolib.php and portfolio_callback.php.
    $filefound = false;
    if (file_exists($componentloc . '/locallib.php')) {
        $filefound = true;
        require_once $componentloc . '/locallib.php';
    }
    if (file_exists($componentloc . '/portfoliolib.php')) {
        $filefound = true;
        debugging('Please standardise your plugin by renaming your portfolio callback file to locallib.php, or if that file already exists moving the portfolio functionality there.', DEBUG_DEVELOPER);
        require_once $componentloc . '/portfoliolib.php';
    }
    if (file_exists($componentloc . '/portfolio_callback.php')) {
        $filefound = true;
        debugging('Please standardise your plugin by renaming your portfolio callback file to locallib.php, or if that file already exists moving the portfolio functionality there.', DEBUG_DEVELOPER);
        require_once $componentloc . '/portfolio_callback.php';
    }
    // Ensure that we found a file we can use, if not throw an exception.
    if (!$filefound) {
        throw new portfolio_button_exception('nocallbackfile', 'portfolio', '', $component);
    }
    if (!is_null($class) && !class_exists($class)) {
        throw new portfolio_button_exception('nocallbackclass', 'portfolio', '', $class);
    }
}
Example #6
0
/**
* Function to require any potential callback files, throwing exceptions
* if an issue occurs.
*
* @param string $callbackfile This is the location of the callback file '/mod/forum/locallib.php'
* @param string $class Name of the class containing the callback functions
* activity components should ALWAYS use their name_portfolio_caller
* other locations must use something unique
*/
function portfolio_include_callback_file($callbackfile, $class = null) {
    global $CFG;
    require_once($CFG->libdir . '/adminlib.php');

    // Get the last occurrence of '/' in the file path.
    $pos = strrpos($callbackfile, '/');
    // Get rid of the first slash (if it exists).
    $callbackfile = ltrim($callbackfile, '/');
    // Get a list of valid plugin types.
    $plugintypes = get_plugin_types(false);
    // Assume it is not valid for now.
    $isvalid = false;
    // Go through the plugin types.
    foreach ($plugintypes as $type => $path) {
        if (strrpos($callbackfile, $path) === 0) {
            // Found the plugin type.
            $isvalid = true;
            $plugintype = $type;
            $pluginpath = $path;
        }
    }
    // Throw exception if not a valid component.
    if (!$isvalid) {
        throw new coding_exception('Somehow a non-valid plugin path was passed, could be a hackz0r attempt, exiting.');
    }
    // Keep record of the filename.
    $filename = substr($callbackfile, $pos);
    // Remove the file name.
    $component = trim(substr($callbackfile, 0, $pos), '/');
    // Replace the path with the type.
    $component = str_replace($pluginpath, $plugintype, $component);
    // Ok, replace '/' with '_'.
    $component = str_replace('/', '_', $component);
    // Check that it is a valid component.
    if (!get_component_version($component)) {
        throw new portfolio_button_exception('nocallbackcomponent', 'portfolio', '', $component);
    }

    // Obtain the component's location.
    if (!$componentloc = get_component_directory($component)) {
        throw new portfolio_button_exception('nocallbackcomponent', 'portfolio', '', $component);
    }

    // Check if the filename does not meet any of the expected names.
    if (($filename != 'locallib.php') && ($filename != 'portfoliolib.php') && ($filename != 'portfolio_callback.php')) {
        debugging('Please standardise your plugin by keeping your portfolio callback functionality in the file locallib.php.', DEBUG_DEVELOPER);
    }

    // Throw error if file does not exist.
    if (!file_exists($componentloc . '/' . $filename)) {
        throw new portfolio_button_exception('nocallbackfile', 'portfolio', '', $callbackfile);
    }

    require_once($componentloc . '/' . $filename);

    if (!is_null($class) && !class_exists($class)) {
        throw new portfolio_button_exception('nocallbackclass', 'portfolio', '', $class);
    }
}
 /**
  * Returns environment info: php version, db vendor, db version,
  * moodle version and plugin version.
  *
  * @return array
  */
 public static function get_environment_info()
 {
     global $DB, $CFG;
     require_once "{$CFG->libdir}/environmentlib.php";
     require_once "{$CFG->libdir}/adminlib.php";
     $envinfo = array('system' => php_uname('s'), 'server' => php_sapi_name(), 'phpversion' => normalize_version(phpversion()), 'dbvendor' => $DB->get_dbvendor(), 'dbversion' => '', 'moodleversion' => '', 'pluginversion' => '');
     $dbinfo = $DB->get_server_info();
     if (!empty($dbinfo['version'])) {
         $envinfo['dbversion'] = normalize_version($dbinfo['version']);
     }
     if ($version = get_component_version('moodle')) {
         $envinfo['moodleversion'] = normalize_version($version);
     }
     if ($version = get_component_version('block_mhaairs')) {
         $envinfo['pluginversion'] = normalize_version($version);
     }
     return (object) $envinfo;
 }