You are here

function filedepot_main in filedepot 7

Same name and namespace in other branches
  1. 6 filedepot.module \filedepot_main()

Implementation of hook_main().

If user passes in a valid group id or group name as the argument 1 then the group context will be set. After that you will only see folders that are sub-folders of the Group Root level folder

If you don't pass in any arguments, no group or folder id, then the group context will be reset and all folders available to user will be displayed

1 string reference to 'filedepot_main'
filedepot_menu in ./filedepot.module
Implementation of hook_menu().

File

./filedepot.module, line 663
filedepot.module Filedepot: File Management Module developed by Nextide www.nextide.ca Full featured document managment module with a desktop application feel. Integrated Organic Group, Role and User permissions to secure folders, automated…

Code

function filedepot_main() {
  $cid = 0;
  $filedepot = NULL;

  //filedepot_filedepot();
  $grpid = 0;
  $arg1 = arg(1);
  $arg2 = arg(2);
  $libpaths = array();
  $libpaths['jquery.blockui'] = libraries_get_path('jquery.blockui');
  $libpaths['html_encoder'] = libraries_get_path('html_encoder');

  // Check to see if the library path exists
  if ($libpaths['jquery.blockui'] === FALSE || !file_exists($libpaths['jquery.blockui']) || ($libpaths['html_encoder'] === FALSE || !file_exists($libpaths['html_encoder']))) {
    return drupal_set_message(t(filedepot_libraryfix_message()), 'error');
  }
  if ($arg1 === 'folder' and $arg2 > 0) {
    $cid = intval($arg2);
  }
  elseif (filedepot_is_ogmode_enabled() === TRUE and !empty($arg1)) {
    $grpcontext = $arg1;
    module_load_include('php', 'filedepot', 'lib-common');
    if (intval($grpcontext) > 0) {

      // Verify this is a valid group id
      if (function_exists('og_get_group')) {
        $wrapper = entity_metadata_wrapper('group', $grpcontext);
        if (is_object($wrapper
          ->value())) {
          $grpid = $wrapper->gid
            ->value();
        }
      }
      else {
        if (og_is_group('node', $grpcontext) === TRUE) {
          $grpid = $grpcontext;
        }
      }
    }
    else {

      // Get the gid from the group name
      $grpcontext = strtolower($grpcontext);
      if (function_exists('og_get_group_ids')) {
        $group_ids = og_get_group_ids('group');
        foreach ($group_ids as $key => $gid) {
          $grp = og_get_group('group', $gid);
          if (strtolower($grp->label) == $grpcontext) {
            $grpid = $grp->gid;
            break;
          }
        }
      }
      else {
        $entity_info = og_get_all_group_bundle();
        if (isset($entity_info['node'])) {
          $entity = filedepot_get_group_entity_query();
          if (count($entity) > 0) {
            foreach ($entity['node'] as $obj) {
              $node = node_load($obj->nid);
              if (strtolower($node->title) == $grpcontext) {
                $grpid = $node->nid;
                break;
              }
            }
          }
        }
      }
    }
    if ($grpid > 0) {
      ctools_include('object-cache');
      $cache = ctools_object_cache_set('filedepot', 'grpid', $grpid);
    }
  }
  else {
    $grpid = 0;
    ctools_include('object-cache');
    $cache = ctools_object_cache_set('filedepot', 'grpid', $grpid);
  }

  // Initialize down here to allow the group id to be set for organic groups - otherwise it will cause caching issues
  $filedepot = filedepot_filedepot();
  $yui_base_url = variable_get('filedepot_yui_baseurl', 'http://yui.yahooapis.com/2.7.0/build/');
  $modulepath = drupal_get_path('module', 'filedepot');
  drupal_add_css($modulepath . '/css/filedepot.css');
  $yuiloader = array(
    '#type' => 'markup',
    '#markup' => '<script type="text/javascript" src="' . $yui_base_url . 'yuiloader/yuiloader.js"></script>',
  );
  drupal_add_html_head($yuiloader, 'yuiloader_script');
  drupal_add_js($modulepath . '/js/filedepotlanguage.js');
  drupal_add_js($modulepath . '/js/nexpro.js');
  drupal_add_js($modulepath . '/js/initapplication.js');
  drupal_add_js($modulepath . '/js/common.js');

  // Libraries version 2 support
  drupal_add_js(libraries_get_path('jquery.blockui') . '/jquery.blockui.js');
  drupal_add_js(libraries_get_path('html_encoder') . '/html_encoder.js');
  drupal_set_breadcrumb();

  // Check that private file stream is setup
  $streams = file_get_stream_wrappers();
  if (!array_key_exists('private', $streams)) {
    drupal_set_message(t('Warning: Your private file system path is not setup and is required - @path', array(
      '@path' => 'admin/config/media/file-system',
    )), 'warning');
    watchdog('Warning', 'Your private file system path is not setup and is required for the filedepot module');
  }
  return theme('filedepot_mainpage', array(
    'cid' => $cid,
  ));
}