Created
May 23, 2012 22:47
-
-
Save tenken/2778316 to your computer and use it in GitHub Desktop.
Sample code to read remote files mounted for D7 access. This is just a working example and not an official module i support.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function views_fs_file_list_content() { | |
$page = array(); | |
$files = _views_fs_fetch_filelist(); | |
return $page; | |
} | |
function _views_fs_fetch_filelist() { | |
global $user; | |
return _views_fs_symfony_finder_files(); | |
} | |
function _view_fs_symfony_finder_files() { | |
$cl = libraries_load('Classloader'); | |
$f = libraries_load('Finder'); | |
require_once ($cl['library path'].'/UniversalClassLoader.php'); | |
use Symfony\Component\ClassLoader\UniversalClassLoader; | |
$loader = new UniversalClassLoader(); | |
$namespaces = array( | |
# 'Symfony' => '/../../sites/libraries/Symfony', | |
'Symfony\\Component\\Finder' => '/Users/david/Sites/2012/views_fs/dist/www/sites/all/libraries', | |
); | |
#print "Using namespaces: " . print_r($namespaces, TRUE); | |
$loader->registerNamespaces($namespaces); | |
$loader->register(); | |
$remote_mountpoint = variable_get('file_public_path', DRUPAL_ROOT . '/sites/default/files/remote_mountpoint'); | |
#print "\n\naccessing Mountpoint: $remote_mountpoint\n\n"; | |
use Symfony\Component\Finder\Finder; | |
$finder = new Finder(); | |
$iterator = $finder | |
->files() | |
->name('*.txt') | |
->depth('> 1') | |
->in($remote_mountpoint); | |
#var_dump($iterator); | |
$files = array(); | |
foreach ($iterator as $file) { | |
// $file is an splFileInfo | |
// http://php.net/manual/en/class.splfileinfo.php | |
#var_dump($file->getFilename()); | |
$files[]= array( | |
$file->getFilename(), | |
$file->getPathname(), | |
); | |
} | |
return $files; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = Filesystem Plugin | |
descprtion = "The module views_fs allows listing of file content from remote locations and defintion of an access policy to read/acess those files. This is useful if you want to provide 3rd party hosted file access within your drupal site, but dont care to import/migrate all the file content into your Drupal database." | |
core = 7.x | |
version = 7.x-1.0 | |
files[]= views_fs.callbacks.inc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_libraries_info() | |
*/ | |
function views_fs_libraries_info() { | |
$libraries['Classloader'] = array( | |
'title' => 'Symfony 2 Classloader Component', | |
'vendor_url' => 'https://github.com', | |
'download_url' => 'https://github.com/symfony/ClassLoader/zipball/2.0', | |
'files' => array( | |
'php' => array('UniversalClassLoader.php'), | |
), | |
'version' => '2.0', | |
'library path' => '/Users/david/Sites/2012/views_fs/dist/www/sites/all/libraries/Symfony/Component/Classloader', | |
); | |
$libraries['Finder'] = array( | |
'title' => 'Symfony 2 Finder Component', | |
'vendor_url' => 'https://github.com', | |
'download_url' => 'https://github.com/symfony/Finder/zipball/2.0', | |
'files' => array( | |
// A list of PHP files to load to make this library useable. | |
'php' => array('Finder.php'), | |
), | |
// So far as I can tell there is nothing to autodetect off of as | |
// download_url does not accept a Git URL pull, and none of the un-archived | |
// files contain ANY version tag information. | |
// | |
// The Symfony Component uses @api tags in their codebase to denote | |
// functions that WILL NOT change in major revisions. | |
// | |
// It is the developers responsability to assure that functions used via | |
// Finder use @api calls only to avoid adverse affects. | |
'version' => '2.0', | |
'library path' => '/Users/david/Sites/2012/views_fs/dist/www/sites/all/libraries/Symfony/Component/Finder', | |
); | |
return $libraries; | |
} | |
/** | |
* Implements hook_requirements() | |
*/ | |
function views_fs_requirements() { | |
$t = get_t(); | |
$requirements = array(); | |
$info = libraries_load('Finder'); | |
if (!$info['installed']) { | |
$requirements['Finder'] = array( | |
'severity' => REQUIREMENT_ERROR, | |
'title' => $t('Symphony Finder'), | |
'value' => $t('Failed to load the Symphony Finder Component'), | |
'description' => $t('Please make sure the Symfony Finder library is installed in the libraries directory. Symfony Finder can be found on !GitHub.', array('!GitHub' => l('GitHub', 'https://github.com/symfony/Finder'))), | |
); | |
} | |
else { | |
$requirements['Finder'] = array( | |
'severity' => REQUIREMENT_INFO, | |
'title' => $t('Symfony Finder Component'), | |
'value' => $info['version'], | |
); | |
} | |
$info = libraries_load('Classloader'); | |
if (!$info['installed']) { | |
$requirements['Classloader'] = array( | |
'severity' => REQUIREMENT_ERROR, | |
'title' => $t('Symphony Classloader'), | |
'value' => $t('Failed to load the Symphony Classloader Component'), | |
'description' => $t('Please make sure the Symfony Classloader library is installed in the libraries directory. Symfony Finder can be found on !GitHub.', array('!GitHub' => l('GitHub', 'https://github.com/symfony/ClassLoader'))), | |
); | |
} | |
else { | |
$requirements['Classloader'] = array( | |
'severity' => REQUIREMENT_INFO, | |
'title' => $t('Symfony Classloader Component'), | |
'value' => $info['version'], | |
); | |
} | |
return $requirements; | |
} | |
function views_fs_menu() { | |
$items['my-file-list'] = array( | |
'title' => 'My Archive Reports', | |
'page_callback' => 'views_fs_file_list_content', | |
'file' => 'view_fs.callbacks.inc', | |
'menu_name' => 'main_menu', | |
); | |
return $items; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment