id_from_path($folder, $one_only); } } /** * Get partial templates of the Google Drive remote storage, the partial template is recognised by its name. To find out a name of partial template, look for the partial call syntax in the template, it's enclosed by double curly braces (i.e. {{> partial_template_name }}) * * @param Array $partial_templates A collection of filterable partial templates * @return Array an associative array keyed by name of the partial templates */ public function get_partial_templates($partial_templates) { ob_start(); ?> {{input_folder_label}}: {{#if is_authenticate_with_google}} {{input_select_folder_label}} {{/if}}
{{input_enhanced_folder_label}} {{#if is_authenticate_with_google}}
{{/if}} sprintf(__('Enter the path of the %s folder you wish to use here.', 'updraftplus'), 'Google Drive').' '.__('If the folder does not already exist, then it will be created.').' '.sprintf(__('e.g. %s', 'updraftplus'), 'MyBackups/WorkWebsite.').' '.sprintf(__('If you leave it blank, then the backup will be placed in the root of your %s', 'updraftplus'), 'Google Drive').' '.sprintf(__('In %s, path names are case sensitive.', 'updraftplus'), 'Google Drive'), 'input_enhanced_folder_label' => sprintf(__('In %s, path names are case sensitive.', 'updraftplus'), 'Google Drive'), ); } /** * Returns the Google Drives addon HTML content to be displayed on the page * DEVELOPER NOTE: Please don't use/call this method anymore as it was used as a partial template of Google Drive storage, and it's consider to be removed in future versions. Once the Google Drive template is CSP-compliant, this should be removed and should be placed in the class child instead of the base class. @see get_partial_templates() * * @param [String] $folder_opts - the free HTML content that will be replaced by the content in this method * @param [Object] $backup_module_object - the backup module object this will allow us to get and use various functions * @return [String] the premium HTML content that will be displayed on the page */ public function options_googledrive_others($folder_opts, $backup_module_object) {// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Unused parameters are for future use. $classes = $backup_module_object->get_css_classes(); return ' '.__('Google Drive', 'updraftplus').' '.__('Folder', 'updraftplus').': output_settings_field_name_and_id('folder', true).' value="{{folder}}" class="updraft_input--wide"> {{#if is_authenticate_with_google}} {{input_select_folder_label}} {{/if}}
'.htmlspecialchars(sprintf(__('In %s, path names are case sensitive.', 'updraftplus'), 'Google Drive')).' {{#if is_authenticate_with_google}}
{{/if}} '; } /** * Modifies handlebar template options * * @param array $opts * @return array - New handerbar template options */ public function transform_options_googledrive_options($opts) { if (!isset($opts['folder'])) { if (isset($opts['parentid'])) { if (is_array($opts['parentid'])) { if (isset($opts['parentid']['name'])) { $opts['folder'] = $opts['parentid']['name']; } else { $opts['folder'] = empty($opts['parentid']['id']) ? '' : '#'.$opts['parentid']['id']; } } else { $opts['folder'] = empty($opts['parentid']) ? '' : '#'.$opts['parentid']; } } else { $opts['folder'] = 'UpdraftPlus'; } } return $opts; } /** * This function will return all user directories in Google Drive. * * @param Array $node_array - The default value * @param Array $params - The search parameters * @return Array $node_array - Array results for JSTree */ public function jstree_googledrive($node_array, $params) { if (!isset($params['node']['id']) || !isset($params['instance_id'])) return $node_array; $options = UpdraftPlus_Options::get_updraft_option('updraft_googledrive'); $instance_id = $params['instance_id']; if (!isset($options['settings'][$instance_id])) return $node_array; if ('#' == $params['node']['id']) { $search = 'root'; } else { $search = $params['node']['id']; } $googledrive = UpdraftPlus_Storage_Methods_Interface::get_storage_object('googledrive'); $googledrive->set_options($options['settings'][$instance_id], false, $instance_id); $folders = $googledrive->list_folders($search); if ($folders) { foreach ($folders as $folder) { $node_array[] = array( 'text' => $folder['name'], 'parent' => $params['node']['id'], 'children' => true, 'id' => $folder['id'], 'icon' => 'jstree-folder', 'data' => $folder ); } } return $node_array; } }