protected function verifyDumpFiles($directory) { $tables = file_scan_directory($directory, '/.php$/'); foreach ($tables as $table) { $contents = rtrim(file_get_contents($table->uri)); $this->assertIdentical(substr($contents, -32), md5(substr($contents, 0, -33)), $table->uri); } }
/** * Fill generic file field with random files. * * @param Form $formObject * Form object. * @param string $field_name * Field name. * @param array $options * Options array. * * @return array * An array with 3 values: * (1) $success: Whether default values could be filled in the field. * (2) $values: Values that were filled for the field. * (3) $msg: Message in case there is an error. This will be empty if * $success is TRUE. */ public static function fillRandomValues(Form $formObject, $field_name, $options = array()) { $num = 1; $file_extensions = 'txt'; $scheme = 'public'; $show_description = FALSE; if (method_exists($formObject, 'getEntityObject')) { // This is an entity form. list($field, $instance, $num) = $formObject->getFieldDetails($field_name); $file_extensions = $instance['settings']['file_extensions']; $scheme = $field['settings']['uri_scheme']; $show_description = $instance['settings']['description_field']; } $extensions = str_replace(" ", "|", $file_extensions); $files = file_scan_directory('tests/assets', '/^.*\\.(' . $extensions . ')$/i'); $filenames = array(); foreach ($files as $file_name => $file_array) { $filenames[] = $file_array->uri; } if (!sizeof($filenames)) { return new Response(FALSE, array(), "Could not find a file to attach with any of the following extensions: " . $file_extensions); } $files = array(); for ($i = 0; $i < $num; $i++) { if ($show_description) { $files[] = array('uri' => $filenames[Utils::getRandomInt(0, sizeof($filenames) - 1)], 'description' => Utils::getRandomText(20), 'scheme' => $scheme); } else { $files[] = array('uri' => $filenames[Utils::getRandomInt(0, sizeof($filenames) - 1)], 'scheme' => $scheme); } } $files = Utils::normalize($files); $function = "fill" . Utils::makeTitleCase($field_name) . "Values"; return $formObject->{$function}($files); }
/** * Reads and merges in existing files for a given package or profile. */ protected function preparePackage(Package $package, array $existing_packages, FeaturesBundleInterface $bundle = NULL) { if (isset($existing_packages[$package->getMachineName()])) { $existing_directory = $existing_packages[$package->getMachineName()]; // Scan for all files. $files = file_scan_directory($existing_directory, '/.*/'); foreach ($files as $file) { // Skip files in the any existing configuration directory, as these // will be replaced. foreach (array_keys($this->featuresManager->getExtensionStorages()->getExtensionStorages()) as $directory) { if (strpos($file->uri, $directory) !== FALSE) { continue 2; } } // Merge in the info file. if ($file->name == $package->getMachineName() . '.info') { $files = $package->getFiles(); $files['info']['string'] = $this->mergeInfoFile($package->getFiles()['info']['string'], $file->uri); $package->setFiles($files); } else { // Determine if the file is within a subdirectory of the // extension's directory. $file_directory = dirname($file->uri); if ($file_directory !== $existing_directory) { $subdirectory = substr($file_directory, strlen($existing_directory) + 1); } else { $subdirectory = NULL; } $package->appendFile(['filename' => $file->filename, 'subdirectory' => $subdirectory, 'string' => file_get_contents($file->uri)]); } } } }
/** * Implements Drupal\Core\Updater\UpdaterInterface::canUpdateDirectory(). */ public static function canUpdateDirectory($directory) { if (file_scan_directory($directory, '/.*\\.module$/')) { return TRUE; } return FALSE; }
/** * Tests if the module cleans up the disk on uninstall. */ public function testPiwikUninstall() { $cache_path = 'public://piwik'; $site_id = '1'; $this->config('piwik.settings')->set('site_id', $site_id)->save(); $this->config('piwik.settings')->set('url_http', 'http://www.example.com/piwik/')->save(); $this->config('piwik.settings')->set('url_https', 'https://www.example.com/piwik/')->save(); // Enable local caching of piwik.js $this->config('piwik.settings')->set('cache', 1)->save(); // Load front page to get the piwik.js downloaded into local cache. But // loading the piwik.js is not possible as "url_http" is a test dummy only. // Create a dummy file to complete the rest of the tests. file_prepare_directory($cache_path, FILE_CREATE_DIRECTORY); file_unmanaged_save_data($this->randomMachineName(16), $cache_path . '/piwik.js'); // Test if the directory and piwik.js exists. $this->assertTrue(file_prepare_directory($cache_path), 'Cache directory "public://piwik" has been found.'); $this->assertTrue(file_exists($cache_path . '/piwik.js'), 'Cached piwik.js tracking file has been found.'); // Uninstall the module. $edit = []; $edit['uninstall[piwik]'] = TRUE; $this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall')); $this->assertNoText(\Drupal::translation()->translate('Configuration deletions'), 'No configuration deletions listed on the module install confirmation page.'); $this->drupalPostForm(NULL, NULL, t('Uninstall')); $this->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.'); // Test if the directory and all files have been removed. $this->assertFalse(file_scan_directory($cache_path, '/.*/'), 'Cached JavaScript files have been removed.'); $this->assertFalse(file_prepare_directory($cache_path), 'Cache directory "public://piwik" has been removed.'); }
/** * Reads and merges in existing files for a given package or profile. */ protected function preparePackage(array &$package, array $existing_packages, FeaturesBundleInterface $bundle = NULL) { if (isset($existing_packages[$package['machine_name']])) { $existing_directory = $existing_packages[$package['machine_name']]; // Scan for all files. $files = file_scan_directory($existing_directory, '/.*/'); foreach ($files as $file) { // Skip files in the install directory. if (strpos($existing_directory, InstallStorage::CONFIG_INSTALL_DIRECTORY) !== FALSE) { continue; } // Merge in the info file. if ($file->name == $package['machine_name'] . '.info') { $package['files']['info']['string'] = $this->mergeInfoFile($package['files']['info']['string'], $file->uri); } // Read in remaining files. else { // Determine if the file is within a subdirectory of the // extension's directory. $file_directory = dirname($file->uri); if ($file_directory !== $existing_directory) { $subdirectory = substr($file_directory, strlen($existing_directory) + 1); } else { $subdirectory = NULL; } $package['files'][] = [ 'filename' => $file->filename, 'subdirectory' => $subdirectory, 'string' => file_get_contents($file->uri) ]; } } } }
/** * Implements Drupal\Core\Updater\UpdaterInterface::canUpdateDirectory(). */ static function canUpdateDirectory($directory) { // This is a lousy test, but don't know how else to confirm it is a theme. if (file_scan_directory($directory, '/.*\\.module$/')) { return FALSE; } return TRUE; }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $tables = file_scan_directory($this->getDumpDirectory(), '/.php$/', array('recurse' => FALSE)); $this->loadDumps(array_keys($tables)); $this->installEntitySchema('user'); $this->installConfig(['migrate_drupal', 'system']); }
/** * A version-independent wrapper for drupal_system_listing(). * * Based on notes in change record at https://www.drupal.org/node/2198695. */ function systemListing($mask, $directory, $key = 'name', $min_depth = 1) { $files = array(); foreach (\Drupal::moduleHandler()->getModuleList() as $name => $module) { $files += file_scan_directory($module->getPath(), $mask, array('key' => $key)); } return $files; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // Log execution time. $start_time = microtime(TRUE); // Try to load the files count from cache. This function will accept two // arguments: // - cache object name (cid) // - cache bin, the (optional) cache bin (most often a database table) where // the object is to be saved. // // cache_get() returns the cached object or FALSE if object does not exist. if ($cache = \Drupal::cache()->get('cache_example_files_count')) { /* * Get cached data. Complex data types will be unserialized automatically. */ $files_count = $cache->data; } else { // If there was no cached data available we have to search filesystem. // Recursively get all files from Drupal's folder. $files_count = count(file_scan_directory('.', '/.*/')); // Since we have recalculated, we now need to store the new data into // cache. Complex data types will be automatically serialized before // being saved into cache. // Here we use the default setting and create an unexpiring cache item. // See below for an example that creates an expiring cache item. \Drupal::cache()->set('cache_example_files_count', $files_count, CacheBackendInterface::CACHE_PERMANENT); } $end_time = microtime(TRUE); $duration = $end_time - $start_time; // Format intro message. $intro_message = '<p>' . t('This example will search the entire drupal folder and display a count of the files in it.') . ' '; $intro_message .= t('This can take a while, since there are a lot of files to be searched.') . ' '; $intro_message .= t('We will search filesystem just once and save output to the cache. We will use cached data for later requests.') . '</p>'; $intro_message .= '<p>' . t('<a href="@url">Reload this page</a> to see cache in action.', array('@url' => request_uri())) . ' '; $intro_message .= t('You can use the button below to remove cached data.') . '</p>'; $form['file_search'] = array('#type' => 'fieldset', '#title' => t('File search caching')); $form['file_search']['introduction'] = array('#markup' => $intro_message); $color = empty($cache) ? 'red' : 'green'; $retrieval = empty($cache) ? t('calculated by traversing the filesystem') : t('retrieved from cache'); $form['file_search']['statistics'] = array('#type' => 'item', '#markup' => t('%count files exist in this Drupal installation; @retrieval in @time ms. <br/>(Source: <span style="color:@color;">@source</span>)', array('%count' => $files_count, '@retrieval' => $retrieval, '@time' => number_format($duration * 1000, 2), '@color' => $color, '@source' => empty($cache) ? t('actual file search') : t('cached')))); $form['file_search']['remove_file_count'] = array('#type' => 'submit', '#submit' => array(array($this, 'expireFiles')), '#value' => t('Explicitly remove cached file count')); $form['expiration_demo'] = array('#type' => 'fieldset', '#title' => t('Cache expiration settings')); $form['expiration_demo']['explanation'] = array('#markup' => t('A cache item can be set as CACHE_PERMANENT, meaning that it will only be removed when explicitly cleared, or it can have an expiration time (a Unix timestamp).')); $item = \Drupal::cache()->get('cache_example_expiring_item', TRUE); if ($item == FALSE) { $item_status = t('Cache item does not exist'); } else { $item_status = $item->valid ? t('Cache item exists and is set to expire at %time', array('%time' => $item->data)) : t('Cache_item is invalid'); } $form['expiration_demo']['current_status'] = array('#type' => 'item', '#title' => t('Current status of cache item "cache_example_expiring_item"'), '#markup' => $item_status); $form['expiration_demo']['expiration'] = array('#type' => 'select', '#title' => t('Time before cache expiration'), '#options' => array('never_remove' => t('CACHE_PERMANENT'), -10 => t('Immediate expiration'), 10 => t('10 seconds from form submission'), 60 => t('1 minute from form submission'), 300 => t('5 minutes from form submission')), '#default_value' => -10, '#description' => t('Any cache item can be set to only expire when explicitly cleared, or to expire at a given time.')); $form['expiration_demo']['create_cache_item'] = array('#type' => 'submit', '#value' => t('Create a cache item with this expiration'), '#submit' => array(array($this, 'createExpiringItem'))); $form['cache_clearing'] = array('#type' => 'fieldset', '#title' => t('Expire and remove options'), '#description' => t("We have APIs to expire cached items and also to just remove them. Unfortunately, they're all the same API, cache_clear_all")); $form['cache_clearing']['cache_clear_type'] = array('#type' => 'radios', '#title' => t('Type of cache clearing to do'), '#options' => array('expire' => t('Remove items from the "cache" bin that have expired'), 'remove_all' => t('Remove all items from the "cache" bin regardless of expiration'), 'remove_tag' => t('Remove all items in the "cache" bin with the tag "cache_example" set to 1')), '#default_value' => 'expire'); // Submit button to clear cached data. $form['cache_clearing']['clear_expired'] = array('#type' => 'submit', '#value' => t('Clear or expire cache'), '#submit' => array(array($this, 'cacheClearing')), '#access' => \Drupal::currentUser()->hasPermission('administer site configuration')); return $form; }
/** * Generate list of available styles definitions * @return $styles * Style names that found in skin directory */ function glossy_style_option() { $styles = array(); $skin_path = variable_get('glossy_skin_dir', drupal_get_path('theme', 'glossy') . '/css/skins'); if(is_dir($skin_path)) { $styles = file_scan_directory($skin_path, '/\.css$/i'); } asort($styles); return $styles; }
private function isImageFilename($filename, $directory) { $files = file_scan_directory($directory, '/.*' . $filename . '$/', array('recurse' => TRUE)); // First look for file with the exact name. foreach ($files as $uri => $file) { if ($file->filename == $filename && @getimagesize($uri)) { return $uri; } } // There is no file with the exact name. Return FALSE. return FALSE; }
public function __construct($filename, $directory = '') { $found = FALSE; // Some OBJ files provide full relative pathname. Extract just the filename. $path_info = pathinfo($filename); $filename = $path_info['basename']; $files = file_scan_directory($directory, '/.*' . $filename . '$/', array('recurse' => TRUE)); foreach ($files as $uri => $file) { if ($file->filename != $filename) { continue; } $found = TRUE; $handle = fopen($uri, 'r'); $material = NULL; $text = ''; while (($line = fgets($handle)) !== FALSE) { $line = trim($line); // Start of a new material. // Store the old material first. if (strpos($line, 'newmtl ') === 0) { // Start a new material. // First close the previous material. if (!empty($text)) { $material = new Material($text, $directory); if ($error = $material->getError()) { $this->error = $error; return; } $this->materials[$material->name] = $material; } $text = $line; } elseif (!empty($line) && strpos($line, '#') !== 0) { $text .= PHP_EOL . $line; } } // End of file. Create the material. if (!empty($text)) { $material = new Material($text, $directory); if ($error = $material->getError()) { $this->error = $error; return; } $this->materials[$material->name] = $material; } } if (!$found) { $this->error = 'File ' . $filename . ' doesn\'t exist.'; return; } }
function prepare($caller) { global $settings; foreach (file_scan_directory(__DIR__ . '/include/', '/.*\\.inc$/') as $include) { include_once $include->uri; } $settings = settings($caller); $install_file = $settings['script_path']['dirname'] . '/' . $settings['script_path']['filename'] . '.install'; $info_file = $settings['script_path']['dirname'] . '/' . $settings['script_path']['filename'] . '.info'; $includes = file_scan_directory($settings['script_path']['dirname'], '/.*\\.inc$/'); foreach ($includes as $include) { include_once $include->uri; } }
function migrate() { global $term_dir; $completed = array(); $names = $_POST['edit']['migrate']; foreach ($names as $name => $status) { $files = file_scan_directory($term_dir, $name); if (count($files) != 1) { print count($files) . " files match the name: {$name}"; exit; } $image = array_pop($files); $image->filename_orig = $image->filename; if ($status == 1) { $image->tid = migrate_term_image_get_tid($image->name); if (!taxonomy_get_term($image->tid)) { print "cant find the tid: {$tid}"; exit; } $t_i_image = db_fetch_object(db_query('SELECT path FROM {term_image} WHERE tid = %d', $image->tid)); if ($t_i_image) { $term->has_image = true; } if ($term->has_image) { taxonomy_image_delete($image->tid); } if (file_copy($image->filename) != 1) { print "couldnt copy file: {$image->filename} to new location"; exit; } db_query("INSERT INTO {term_image} (tid, path) VALUES (%d, '%s')", $image->tid, $image->filename); $completed[] = $image; } if ($_POST['edit']['delete'][$name] == 1) { file_delete($image->filename_orig); $deleted[] = $image; } } if ($c = count($completed)) { print "Updated {$c} terms"; } else { print "No terms updated"; } if ($c = count($deleted)) { print "Deleted {$c} node_image(s)"; } else { print "No images deleted"; } }
/** * Advanced theme settings. */ function perspective_form_system_theme_settings_alter(&$form, $form_state) { $form['perspective_theme_slogan'] = array('#type' => 'textarea', '#title' => t('Theme slogan'), '#default_value' => theme_get_setting('perspective_theme_slogan', 'perspective'), '#description' => t('This is heading message on the site.')); $form['perspective_footer_copyright'] = array('#type' => 'textarea', '#title' => t('Footer copyright message'), '#default_value' => theme_get_setting('perspective_footer_copyright', 'perspective'), '#description' => t('This is copyright message in footer region.')); $form['perspective_footer_social_links'] = array('#type' => 'textarea', '#title' => t('Footer Social links'), '#default_value' => theme_get_setting('perspective_footer_social_links', 'perspective'), '#description' => t('This is social links in footer region.')); $form['slider'] = array('#type' => 'fieldset', '#title' => t('Slider managment'), '#collapsible' => TRUE, '#collapsed' => FALSE); // Image upload section ====================================================== $banners = perspective_get_banners(); $form['slider']['banner']['images'] = array('#type' => 'vertical_tabs', '#title' => t('Banner images'), '#weight' => 2, '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE); $i = 0; foreach ($banners as $image_data) { $form['slider']['banner']['images'][$i] = array('#type' => 'fieldset', '#title' => t('Image !number: !title', array('!number' => $i + 1, '!title' => $image_data['image_title'])), '#weight' => $i, '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE, 'image' => _perspective_banner_form($image_data)); $i++; } $form['slider']['banner']['image_upload'] = array('#type' => 'file', '#title' => t('Upload a new image'), '#weight' => $i); $form['#submit'][] = 'perspective_settings_submit'; $form['home'] = array('#type' => 'fieldset', '#title' => t('Homepage settings'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['home']['perspective_homepage_type'] = array('#type' => 'select', '#title' => t('Hompage type'), '#options' => array('slider' => 'Slider', 'video' => 'Video'), '#default_value' => theme_get_setting('perspective_homepage_type', 'perspective')); if (theme_get_setting('perspective_homepage_type', 'perspective') == 'video') { $form['home']['video']['perspective_video_title'] = array('#type' => 'textfield', '#title' => t('Video title'), '#default_value' => theme_get_setting('perspective_video_title', 'perspective')); $form['home']['video']['perspective_video'] = array('#type' => 'textarea', '#title' => t('Video iframe code'), '#default_value' => theme_get_setting('perspective_video', 'perspective'), '#description' => t('This is iframe of video, or you can enter image code here.')); $form['home']['video']['perspective_video_description'] = array('#type' => 'textarea', '#title' => t('Description'), '#default_value' => theme_get_setting('perspective_video_description', 'perspective'), '#description' => t('Enter description.')); $form['home']['video']['perspective_video_link_title'] = array('#type' => 'textfield', '#title' => t('link title'), '#default_value' => theme_get_setting('perspective_video_link_title', 'perspective')); $form['home']['video']['perspective_video_link_url'] = array('#type' => 'textfield', '#title' => t('Link URL'), '#default_value' => theme_get_setting('perspective_video_link_url', 'perspective'), '#description' => t('This is the URL.')); } $blog_style_options = array('blog_meta_before' => t('[Default] big image - meta before'), 'blog_meta_after' => t('Big image - meta after'), 'blog_meta_icons_right' => t('Big image meta-icons right'), 'blog_meta_icons_left' => t('Big image meta-icons left'), 'blog_image_meta_31' => t('Image-Meta / 3:1'), 'blog_image_meta_13' => t('Meta-Image / 1:3'), 'blog_image_hidden_meta' => t('Hiden meta / Big image'), 'blog_small_image_left' => t('Small image left'), 'blog_small_image_right' => t('Small image right'), 'blog_75p_meta' => t('75% Image / Meta'), 'blog_meta_75p' => t('Meta / 75% Image')); $form['blog_display_setting'] = array('#type' => 'select', '#title' => t('Blog style options'), '#options' => $blog_style_options, '#default_value' => theme_get_setting('blog_display_setting', 'perspective')); $form['portfolio'] = array('#type' => 'fieldset', '#title' => t('Portfolio settings'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['portfolio']['default_portfolio'] = array('#type' => 'select', '#title' => t('Default portfolio display'), '#options' => array('1c' => 'Portfolio - 1col', '2c' => 'Portfolio - 2cols', '3c' => 'Portfolio - 3cols', '4c' => 'portfolio - 4cols'), '#default_value' => theme_get_setting('default_portfolio', 'perspective')); $form['portfolio']['default_nodes_portfolio'] = array('#type' => 'select', '#title' => t('Number nodes show on portfolio page'), '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30)), '#default_value' => theme_get_setting('default_nodes_portfolio', 'perspective')); $form['contact'] = array('#type' => 'fieldset', '#title' => t('Contact settings'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['contact']['contact_map'] = array('#type' => 'textarea', '#title' => 'Map embed code', '#default_value' => theme_get_setting('contact_map', 'perspective')); $form['skin'] = array('#type' => 'fieldset', '#title' => t('Skins settings'), '#collapsible' => TRUE, '#collapsed' => FALSE); $skins_options = array(); $dir = drupal_get_path('theme', 'perspective') . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'themes'; $files = file_scan_directory($dir, '/.*\\.css/'); if (!empty($files)) { foreach ($files as $file) { if (isset($file->filename)) { $skins_options[$file->name] = $file->filename; } } } $form['skin']['default_skin'] = array('#type' => 'select', '#title' => t('Default skin'), '#options' => $skins_options, '#default_value' => theme_get_setting('default_skin', 'perspective')); return $form; }
/** * Constructor * @param array $class_list list containing the classes of tests to be processed * default: NULL - run all tests */ function DrupalUnitTests($class_list = NULL) { static $classes; $this->DrupalTestSuite('Drupal Unit Tests'); /* Tricky part to avoid double inclusion */ if (!$classes) { $files = array(); foreach (module_list() as $module) { $module_path = drupal_get_path('module', $module); if (file_exists($module_path . '/tests/')) { $dir = $module_path . '/tests'; $tests = file_scan_directory($dir, '\\.test$'); $files = array_merge($files, $tests); } } $files = array_keys($files); $existing_classes = get_declared_classes(); foreach ($files as $file) { include_once $file; } $classes = array_diff(get_declared_classes(), $existing_classes); } if (!is_null($class_list)) { $classes = $class_list; } if (count($classes) == 0) { $this->addTestCase(new BadGroupTest($test_file, 'No new test cases')); return; } $groups = array(); foreach ($classes as $class) { if (!is_subclass_of($class, 'DrupalTestCase')) { if (!is_subclass_of($class, 'DrupalWebTestCase')) { continue; } } $this->_addClassToGroups($groups, $class); } foreach ($groups as $group_name => $group) { $group_test =& new DrupalTestSuite($group_name); foreach ($group as $key => $v) { $group_test->addTestCase($group[$key]); } $this->addTestCase($group_test); } }
function visia_form_system_theme_settings_alter(&$form, $form_state) { $form['settings'] = array('#type' => 'vertical_tabs', '#title' => t('Theme settings'), '#weight' => 2, '#collapsible' => TRUE, '#collapsed' => FALSE); $form['settings']['general'] = array('#type' => 'fieldset', '#title' => t('General settings'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['settings']['general']['enable_breadcrumb'] = array('#type' => 'checkbox', '#title' => t('Use breadcrumb'), '#default_value' => theme_get_setting('enable_breadcrumb')); $form['settings']['general']['use_parallax'] = array('#type' => 'checkbox', '#title' => t('Use Parallax'), '#default_value' => theme_get_setting('use_parallax')); $form['settings']['general']['content_column_size'] = array('#type' => 'select', '#title' => t('Content column size'), '#default_value' => theme_get_setting('content_column_size'), '#description' => t('Change size of main content column, default is 4'), '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5)); // bg background $dir = drupal_get_path('theme', 'visia') . DIRECTORY_SEPARATOR . 'stylesheets' . DIRECTORY_SEPARATOR . 'colors'; $files = file_scan_directory($dir, '/.*\\.css/'); $css_files = array(); if (!empty($files)) { foreach ($files as $file) { if (isset($file->filename)) { $css_files[$file->filename] = $file->filename; } } } $form['settings']['general']['theme_color'] = array('#type' => 'select', '#title' => t('Default theme color'), '#default_value' => theme_get_setting('theme_color'), '#description' => t('Colors availabe in <strong>!path/stylesheets/colors</strong> , you could also create new custom css file put in that directory and system will auto detects your css file.', array('!path' => base_path() . drupal_get_path('theme', 'visia'))), '#options' => $css_files); $form['settings']['general']['custom_theme_css'] = array('#type' => 'textarea', '#title' => t('Custom theme css'), '#default_value' => theme_get_setting('custom_theme_css'), '#description' => t('Custom your own css, eg: <strong>#page-title h2{color: #060606;}</strong>')); }
/** * Gets a list of files that can be used in tests. * * The first time this method is called, it will call * $this->generateFile() to generate binary and ASCII text files in the * public:// directory. It will also copy all files in * core/modules/simpletest/files to public://. These contain image, SQL, PHP, * JavaScript, and HTML files. * * All filenames are prefixed with their type and have appropriate extensions: * - text-*.txt * - binary-*.txt * - html-*.html and html-*.txt * - image-*.png, image-*.jpg, and image-*.gif * - javascript-*.txt and javascript-*.script * - php-*.txt and php-*.php * - sql-*.txt and sql-*.sql * * Any subsequent calls will not generate any new files, or copy the files * over again. However, if a test class adds a new file to public:// that * is prefixed with one of the above types, it will get returned as well, even * on subsequent calls. * * @param $type * File type, possible values: 'binary', 'html', 'image', 'javascript', * 'php', 'sql', 'text'. * @param $size * (optional) File size in bytes to match. Defaults to NULL, which will not * filter the returned list by size. * * @return array[] * List of files in public:// that match the filter(s). */ protected function getTestFiles($type, $size = NULL) { if (empty($this->generatedTestFiles)) { // Generate binary test files. $lines = [64, 1024]; $count = 0; foreach ($lines as $line) { $this->generateFile('binary-' . $count++, 64, $line, 'binary'); } // Generate ASCII text test files. $lines = [16, 256, 1024, 2048, 20480]; $count = 0; foreach ($lines as $line) { $this->generateFile('text-' . $count++, 64, $line, 'text'); } // Copy other test files from simpletest. $original = drupal_get_path('module', 'simpletest') . '/files'; $files = file_scan_directory($original, '/(html|image|javascript|php|sql)-.*/'); foreach ($files as $file) { file_unmanaged_copy($file->uri, PublicStream::basePath()); } $this->generatedTestFiles = TRUE; } $files = []; // Make sure type is valid. if (in_array($type, ['binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'])) { $files = file_scan_directory('public://', '/' . $type . '\\-.*/'); // If size is set then remove any files that are not of that size. if ($size !== NULL) { foreach ($files as $file) { $stats = stat($file->uri); if ($stats['size'] != $size) { unset($files[$file->uri]); } } } } usort($files, [$this, 'compareFiles']); return $files; }
/** * Tests if the module cleans up the disk on uninstall. */ public function testGoogleAnalyticsUninstall() { $cache_path = 'public://google_analytics'; $ua_code = 'UA-123456-1'; // Show tracker in pages. $this->config('google_analytics.settings')->set('account', $ua_code)->save(); // Enable local caching of analytics.js. $this->config('google_analytics.settings')->set('cache', 1)->save(); // Load page to get the analytics.js downloaded into local cache. $this->drupalGet(''); // Test if the directory and analytics.js exists. $this->assertTrue(file_prepare_directory($cache_path), 'Cache directory "public://google_analytics" has been found.'); $this->assertTrue(file_exists($cache_path . '/analytics.js'), 'Cached analytics.js tracking file has been found.'); // Uninstall the module. $edit = []; $edit['uninstall[google_analytics]'] = TRUE; $this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall')); $this->assertNoText(\Drupal::translation()->translate('Configuration deletions'), 'No configuration deletions listed on the module install confirmation page.'); $this->drupalPostForm(NULL, NULL, t('Uninstall')); $this->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.'); // Test if the directory and all files have been removed. $this->assertFalse(file_scan_directory($cache_path, '/.*/'), 'Cached JavaScript files have been removed.'); $this->assertFalse(file_prepare_directory($cache_path), 'Cache directory "public://google_analytics" has been removed.'); }
/** * Find all .po files for the current profile. */ function install_find_locales($profilename) { $locales = file_scan_directory('./profiles/' . $profilename . '/translations', '\\.po$', array('.', '..', 'CVS'), 0, FALSE); array_unshift($locales, (object) array('name' => 'en')); return $locales; }
/** * Determines what the most important (or only) info file is in a directory. * * Since there is no enforcement of which info file is the project's "main" * info file, this will get one with the same name as the directory, or the * first one it finds. Not ideal, but needs a larger solution. * * @param string $directory * Directory to search in. * * @return string * Path to the info file. */ public static function findInfoFile($directory) { $info_files = file_scan_directory($directory, '/.*\\.info.yml$/'); if (!$info_files) { return FALSE; } foreach ($info_files as $info_file) { if (Unicode::substr($info_file->filename, 0, -9) == drupal_basename($directory)) { // Info file Has the same name as the directory, return it. return $info_file->uri; } } // Otherwise, return the first one. $info_file = array_shift($info_files); return $info_file->uri; }
/** * {@inheritdoc} */ public function attached() { if ($plugin = $this->getPluginDefinition()) { $path = $this->getClassDirectory(); $jsdir = $path . '/js'; $cssdir = $path . '/css'; if (file_exists($jsdir)) { foreach (file_scan_directory($jsdir, '/.*\\.js$/') as $file) { $this->attached['js'][$file->uri] = array('data' => $file->uri, 'type' => 'file', 'group' => Config::get('openlayers.js_css.group'), 'weight' => Config::get('openlayers.js_css.weight')); } } if (file_exists($cssdir)) { foreach (file_scan_directory($cssdir, '/.*\\.css$/') as $file) { $this->attached['css'][$file->uri] = array('data' => $file->uri, 'type' => 'file', 'group' => Config::get('openlayers.js_css.group'), 'weight' => Config::get('openlayers.js_css.weight'), 'media' => Config::get('openlayers.js_css.media')); } } } return $this->attached; }
/** * Get a list files that can be used in tests. * * @param $type * File type, possible values: 'binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'. * @param $size * File size in bytes to match. Please check the tests/files folder. * @return * List of files that match filter. */ protected function backdropGetTestFiles($type, $size = NULL) { if (empty($this->generatedTestFiles)) { // Generate binary test files. $lines = array(64, 1024); $count = 0; foreach ($lines as $line) { simpletest_generate_file('binary-' . $count++, 64, $line, 'binary'); } // Generate text test files. $lines = array(16, 256, 1024, 2048, 20480); $count = 0; foreach ($lines as $line) { simpletest_generate_file('text-' . $count++, 64, $line); } // Copy other test files from simpletest. $original = backdrop_get_path('module', 'simpletest') . '/files'; $files = file_scan_directory($original, '/(html|image|javascript|php|sql)-.*/'); foreach ($files as $file) { file_unmanaged_copy($file->uri, config_get('system.core', 'file_public_path')); } $this->generatedTestFiles = TRUE; } $files = array(); // Make sure type is valid. if (in_array($type, array('binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'))) { $files = file_scan_directory('public://', '/' . $type . '\\-.*/'); // If size is set then remove any files that are not of that size. if ($size !== NULL) { foreach ($files as $file) { $stats = stat($file->uri); if ($stats['size'] != $size) { unset($files[$file->uri]); } } } } usort($files, array($this, 'backdropCompareFiles')); return $files; }
/** * Finds installer translations either for a specific or all languages. * * Filenames must match the pattern: * - 'drupal-[version].[langcode].po (if langcode is provided) * - 'drupal-[version].*.po (if no langcode is provided) * * @param string $langcode * (optional) The language code corresponding to the language for which we * want to find translation files. If omitted, information on all available * files will be returned. * * @return array * An associative array of file information objects keyed by file URIs as * returned by file_scan_directory(). * * @see file_scan_directory() */ public function findTranslationFiles($langcode = NULL) { $files = file_scan_directory($this->directory, $this->getTranslationFilesPattern($langcode), array('recurse' => FALSE)); return $files; }
/** * Test token value with a UTF file. * * @see https://www.drupal.org/node/1292436 */ public function testTokensUtf() { // Prepare a test text file. /** @var \Drupal\file\Entity\File $text_file */ $text_file = $this->getTestFile('text'); file_unmanaged_copy($text_file->getFileUri(), 'public://тест.txt'); $files = file_scan_directory('public://', '/тест\.txt/'); $utf_file = current($files); /** @var \Drupal\file\Entity\File $utf_file */ $utf_file = \Drupal::entityTypeManager() ->getStorage('file') ->create((array) $utf_file); $utf_file->save(); // Ensure tokens are processed correctly. $data = ['file' => $utf_file]; $this->assertToken('[file:ffp-name-only]', 'тест', $data); }
function covidien_contenttype_update($arg) { module_load_include('inc', 'content', 'includes/content.crud'); $module_name = $arg['module_name']; $import_new = $arg['import_new']; $import_updatearr = $arg['import_updatearr']; $import_deletearr = $arg['import_deletearr']; $import_ctdeletearr = $arg['import_ctdeletearr']; $import_update = array_keys($import_updatearr); $files = file_scan_directory(drupal_get_path('module', $module_name) . '/content_type', '.cck_import.inc'); if (is_array($import_ctdeletearr) && count($import_ctdeletearr) > 0) { foreach ($import_ctdeletearr as $key => $fields) { if (count($fields) > 0) { foreach ($fields as $field_name) { $field = array(); $field['field_name'] = $field_name; $field['type_name'] = $key; content_field_instance_delete($field['field_name'], $field['type_name'], FALSE); drupal_set_message('Deleted ' . $field['field_name'] . ' in ' . $field['type_name']); } } } // Clear caches and rebuild menu. content_clear_type_cache(TRUE); menu_rebuild(); } foreach ($files as $absolute => $file) { // Creating new content type. if (in_array($file->name, $import_new)) { $form_state = array(); $form_state['values']['type_name'] = '<create>'; $fh = fopen($file->filename, 'r'); $theData = fread($fh, filesize($file->filename)); fclose($fh); $form_state['values']['macro'] = "$theData"; drupal_execute('content_copy_import_form', $form_state); } // Updating existing content type. if (in_array($file->name, $import_update)) { // Add the new fileds to the content type $form_state = array(); $form_state['values']['type_name'] = $import_updatearr[$file->name]; $fh = fopen($file->filename, 'r'); $theData = fread($fh, filesize($file->filename)); eval($theData); fclose($fh); $form_state['values']['macro'] = "$theData"; drupal_execute('content_copy_import_form', $form_state); // Update Title filed label $title_label = $content['type']['title_label']; $type = $content['type']['type']; db_query("UPDATE {node_type} SET title_label = '%s' WHERE type = '%s'", $title_label, $type); // Update several fields at a time. if (count($content['fields']) > 0) { foreach ($content['fields'] as $key => $field) { if (is_array($field)) { $field['type_name'] = $content['type']['type']; if ($field['type_name'] != '' && $field['field_name'] != '') { content_field_instance_update($field, FALSE); drupal_set_message('updated ' . $field['field_name'] . ' in ' . $field['type_name']); } } } } /** * Code to remove the cck filed from content type. */ if (is_array($import_deletearr)) { $fields = $import_deletearr[$file->name]; } if (count($fields) > 0) { foreach ($fields as $field_name) { $field = array(); $field['field_name'] = $field_name; $field['type_name'] = $import_updatearr[$file->name]; content_field_instance_delete($field['field_name'], $field['type_name'], FALSE); drupal_set_message('Deleted ' . $field['field_name'] . ' in ' . $field['type_name']); } } // Clear caches and rebuild menu. content_clear_type_cache(TRUE); menu_rebuild(); } } }
/** * Check that the min_depth options lets us ignore files in the starting * directory. */ function testOptionMinDepth() { $files = file_scan_directory($this->path, '/^javascript-/', array('min_depth' => 0)); $this->assertEqual(2, count($files), 'No minimum-depth gets files in current directory.'); $files = file_scan_directory($this->path, '/^javascript-/', array('min_depth' => 1)); $this->assertTrue(empty($files), 'Minimum-depth of 1 successfully excludes files from current directory.'); }
/** * Count the number of images currently create for a style. */ function getImageCount(ImageStyleInterface $style) { return count(file_scan_directory('public://styles/' . $style->id(), '/.*/')); }
<?php $theme_path = drupal_get_path('theme', 'bootstrap'); require_once $theme_path . '/includes/bootstrap.inc'; require_once $theme_path . '/includes/theme.inc'; require_once $theme_path . '/includes/pager.inc'; require_once $theme_path . '/includes/form.inc'; require_once $theme_path . '/includes/admin.inc'; require_once $theme_path . '/includes/menu.inc'; // Load module specific files in the modules directory. $includes = file_scan_directory($theme_path . '/includes/modules', '/\\.inc$/'); foreach ($includes as $include) { if (module_exists($include->name)) { require_once $include->uri; } } // Auto-rebuild the theme registry during theme development. if (theme_get_setting('bootstrap_rebuild_registry') && !defined('MAINTENANCE_MODE')) { // Rebuild .info data. system_rebuild_theme_data(); // Rebuild theme registry. drupal_theme_rebuild(); } /** * hook_theme() */ function bootstrap_theme(&$existing, $type, $theme, $path) { // If we are auto-rebuilding the theme registry, warn about the feature. if (function_exists('user_access') && user_access('administer site configuration') && theme_get_setting('bootstrap_rebuild_registry') && (arg(0) == 'admin' || flood_is_allowed($GLOBALS['theme'] . '_rebuild_registry_warning', 3))) { flood_register_event($GLOBALS['theme'] . '_rebuild_registry_warning');