Пример #1
0
 /**
  * @brief Creates the directory listing for the given path.
  *
  * @param string $path which should be displayed
  */
 public function generateDirectoryIndex($path)
 {
     // (owner_id = channel_id) is visitor owner of this directory?
     $is_owner = local_channel() && $this->auth->owner_id == local_channel() ? true : false;
     if ($this->auth->getTimezone()) {
         date_default_timezone_set($this->auth->getTimezone());
     }
     require_once 'include/conversation.php';
     require_once 'include/text.php';
     if ($this->auth->owner_nick) {
         $html = profile_tabs(get_app(), $is_owner ? true : false, $this->auth->owner_nick);
     }
     $files = $this->server->getPropertiesForPath($path, array('{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified'), 1);
     $parent = $this->server->tree->getNodeForPath($path);
     $parentpath = array();
     // only show parent if not leaving /cloud/; TODO how to improve this?
     if ($path && $path != "cloud") {
         list($parentUri) = \Sabre\HTTP\URLUtil::splitPath($path);
         $fullPath = \Sabre\HTTP\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
         $parentpath['icon'] = $this->enableAssets ? '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl('icons/parent' . $this->iconExtension) . '" width="24" alt="' . t('parent') . '"></a>' : '';
         $parentpath['path'] = $fullPath;
     }
     $f = array();
     foreach ($files as $file) {
         $ft = array();
         $type = null;
         // This is the current directory, we can skip it
         if (rtrim($file['href'], '/') == $path) {
             continue;
         }
         list(, $name) = \Sabre\HTTP\URLUtil::splitPath($file['href']);
         if (isset($file[200]['{DAV:}resourcetype'])) {
             $type = $file[200]['{DAV:}resourcetype']->getValue();
             // resourcetype can have multiple values
             if (!is_array($type)) {
                 $type = array($type);
             }
             foreach ($type as $k => $v) {
                 // Some name mapping is preferred
                 switch ($v) {
                     case '{DAV:}collection':
                         $type[$k] = t('Collection');
                         break;
                     case '{DAV:}principal':
                         $type[$k] = t('Principal');
                         break;
                     case '{urn:ietf:params:xml:ns:carddav}addressbook':
                         $type[$k] = t('Addressbook');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}calendar':
                         $type[$k] = t('Calendar');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}schedule-inbox':
                         $type[$k] = t('Schedule Inbox');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}schedule-outbox':
                         $type[$k] = t('Schedule Outbox');
                         break;
                     case '{http://calendarserver.org/ns/}calendar-proxy-read':
                         $type[$k] = 'Proxy-Read';
                         break;
                     case '{http://calendarserver.org/ns/}calendar-proxy-write':
                         $type[$k] = 'Proxy-Write';
                         break;
                 }
             }
             $type = implode(', ', $type);
         }
         // If no resourcetype was found, we attempt to use
         // the contenttype property
         if (!$type && isset($file[200]['{DAV:}getcontenttype'])) {
             $type = $file[200]['{DAV:}getcontenttype'];
         }
         if (!$type) {
             $type = t('Unknown');
         }
         $size = isset($file[200]['{DAV:}getcontentlength']) ? (int) $file[200]['{DAV:}getcontentlength'] : '';
         $lastmodified = isset($file[200]['{DAV:}getlastmodified']) ? $file[200]['{DAV:}getlastmodified']->getTime()->format('Y-m-d H:i:s') : '';
         $fullPath = \Sabre\HTTP\URLUtil::encodePath('/' . trim($this->server->getBaseUri() . ($path ? $path . '/' : '') . $name, '/'));
         $displayName = isset($file[200]['{DAV:}displayname']) ? $file[200]['{DAV:}displayname'] : $name;
         $displayName = $this->escapeHTML($displayName);
         $type = $this->escapeHTML($type);
         $icon = '';
         if ($this->enableAssets) {
             $node = $this->server->tree->getNodeForPath(($path ? $path . '/' : '') . $name);
             foreach (array_reverse($this->iconMap) as $class => $iconName) {
                 if ($node instanceof $class) {
                     $icon = '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl($iconName . $this->iconExtension) . '" alt="" width="24"></a>';
                     break;
                 }
             }
         }
         $parentHash = '';
         $owner = $this->auth->owner_id;
         $splitPath = explode('/', $fullPath);
         if (count($splitPath) > 3) {
             for ($i = 3; $i < count($splitPath); $i++) {
                 $attachName = urldecode($splitPath[$i]);
                 $attachHash = $this->findAttachHash($owner, $parentHash, $attachName);
                 $parentHash = $attachHash;
             }
         }
         $attachIcon = "";
         // "<a href=\"attach/".$attachHash."\" title=\"".$displayName."\"><i class=\"fa fa-arrow-circle-o-down\"></i></a>";
         // put the array for this file together
         $ft['attachId'] = $this->findAttachIdByHash($attachHash);
         $ft['fileStorageUrl'] = substr($fullPath, 0, strpos($fullPath, "cloud/")) . "filestorage/" . $this->auth->getCurrentUser();
         $ft['icon'] = $icon;
         $ft['attachIcon'] = $size ? $attachIcon : '';
         // @todo Should this be an item value, not a global one?
         $ft['is_owner'] = $is_owner;
         $ft['fullPath'] = $fullPath;
         $ft['displayName'] = $displayName;
         $ft['type'] = $type;
         $ft['size'] = $size;
         $ft['sizeFormatted'] = userReadableSize($size);
         $ft['lastmodified'] = $lastmodified ? datetime_convert('UTC', date_default_timezone_get(), $lastmodified) : '';
         $ft['iconFromType'] = getIconFromType($type);
         $f[] = $ft;
     }
     $output = '';
     if ($this->enablePost) {
         $this->server->emit('onHTMLActionsPanel', array($parent, &$output));
     }
     $html .= replace_macros(get_markup_template('cloud.tpl'), array('$header' => t('Files') . ": " . $this->escapeHTML($path) . "/", '$total' => t('Total'), '$actionspanel' => $output, '$shared' => t('Shared'), '$create' => t('Create'), '$upload' => t('Upload'), '$is_owner' => $is_owner, '$parentpath' => $parentpath, '$entries' => $f, '$name' => t('Name'), '$type' => t('Type'), '$size' => t('Size'), '$lastmod' => t('Last Modified'), '$parent' => t('parent'), '$edit' => t('Edit'), '$delete' => t('Delete'), '$nick' => $this->auth->getCurrentUser()));
     $a = get_app();
     \App::$page['content'] = $html;
     load_pdl($a);
     $theme_info_file = "view/theme/" . current_theme() . "/php/theme.php";
     if (file_exists($theme_info_file)) {
         require_once $theme_info_file;
         if (function_exists(str_replace('-', '_', current_theme()) . '_init')) {
             $func = str_replace('-', '_', current_theme()) . '_init';
             $func($a);
         }
     }
     construct_page($a);
 }
Пример #2
0
 public function run()
 {
     /*
      * Bootstrap the application, load configuration, load modules, load theme, etc.
      */
     require_once 'boot.php';
     sys_boot();
     \App::$language = get_best_language();
     load_translation_table(\App::$language, \App::$install);
     /**
      *
      * Important stuff we always need to do.
      *
      * The order of these may be important so use caution if you think they're all
      * intertwingled with no logical order and decide to sort it out. Some of the
      * dependencies have changed, but at least at one time in the recent past - the
      * order was critical to everything working properly
      *
      */
     if (\App::$session) {
         \App::$session->start();
     } else {
         session_start();
         register_shutdown_function('session_write_close');
     }
     /**
      * Language was set earlier, but we can over-ride it in the session.
      * We have to do it here because the session was just now opened.
      */
     if (array_key_exists('system_language', $_POST)) {
         if (strlen($_POST['system_language'])) {
             $_SESSION['language'] = $_POST['system_language'];
         } else {
             unset($_SESSION['language']);
         }
     }
     if (x($_SESSION, 'language') && $_SESSION['language'] !== $lang) {
         \App::$language = $_SESSION['language'];
         load_translation_table(\App::$language);
     }
     if (x($_GET, 'zid') && !\App::$install) {
         \App::$query_string = strip_zids(\App::$query_string);
         if (!local_channel()) {
             $_SESSION['my_address'] = $_GET['zid'];
             zid_init();
         }
     }
     if (x($_GET, 'zat') && !\App::$install) {
         \App::$query_string = strip_zats(\App::$query_string);
         if (!local_channel()) {
             zat_init();
         }
     }
     if (x($_SESSION, 'authenticated') || x($_POST, 'auth-params') || \App::$module === 'login') {
         require 'include/auth.php';
     }
     if (!x($_SESSION, 'sysmsg')) {
         $_SESSION['sysmsg'] = array();
     }
     if (!x($_SESSION, 'sysmsg_info')) {
         $_SESSION['sysmsg_info'] = array();
     }
     /*
      * check_config() is responsible for running update scripts. These automatically
      * update the DB schema whenever we push a new one out. It also checks to see if
      * any plugins have been added or removed and reacts accordingly.
      */
     if (\App::$install) {
         /* Allow an exception for the view module so that pcss will be interpreted during installation */
         if (\App::$module != 'view') {
             \App::$module = 'setup';
         }
     } else {
         check_config($a);
     }
     nav_set_selected('nothing');
     $Router = new Router($a);
     /* initialise content region */
     if (!x(\App::$page, 'content')) {
         \App::$page['content'] = '';
     }
     call_hooks('page_content_top', \App::$page['content']);
     $Router->Dispatch($a);
     // If you're just visiting, let javascript take you home
     if (x($_SESSION, 'visitor_home')) {
         $homebase = $_SESSION['visitor_home'];
     } elseif (local_channel()) {
         $homebase = z_root() . '/channel/' . \App::$channel['channel_address'];
     }
     if (isset($homebase)) {
         \App::$page['content'] .= '<script>var homebase = "' . $homebase . '";</script>';
     }
     // now that we've been through the module content, see if the page reported
     // a permission problem and if so, a 403 response would seem to be in order.
     if (is_array($_SESSION['sysmsg']) && stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) {
         header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.'));
     }
     call_hooks('page_end', \App::$page['content']);
     construct_page($a);
     killme();
 }
Пример #3
0
    if (!$a->error && function_exists($a->module . '_content')) {
        $arr = array('content' => $a->page['content']);
        call_hooks($a->module . '_mod_content', $arr);
        $a->page['content'] = $arr['content'];
        $func = $a->module . '_content';
        $arr = array('content' => $func($a));
        call_hooks($a->module . '_mod_aftercontent', $arr);
        $a->page['content'] .= $arr['content'];
    }
}
// If you're just visiting, let javascript take you home
if (x($_SESSION, 'visitor_home')) {
    $homebase = $_SESSION['visitor_home'];
} elseif (local_channel()) {
    $homebase = $a->get_baseurl() . '/channel/' . $a->channel['channel_address'];
}
if (isset($homebase)) {
    $a->page['content'] .= '<script>var homebase = "' . $homebase . '";</script>';
}
// now that we've been through the module content, see if the page reported
// a permission problem and if so, a 403 response would seem to be in order.
if (stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) {
    header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.'));
}
call_hooks('page_end', $a->page['content']);
if (!$a->install) {
    check_cron_broken();
}
construct_page($a);
session_write_close();
exit;
Пример #4
0
 /**
  * @brief Creates the directory listing for the given path.
  *
  * @param string $path which should be displayed
  */
 public function generateDirectoryIndex($path)
 {
     // (owner_id = channel_id) is visitor owner of this directory?
     $is_owner = local_user() && $this->auth->owner_id == local_user() ? true : false;
     if ($this->auth->timezone) {
         date_default_timezone_set($this->auth->timezone);
     }
     require_once 'include/conversation.php';
     if ($this->auth->owner_nick) {
         $html = profile_tabs(get_app(), $is_owner ? true : false, $this->auth->owner_nick);
     }
     $files = $this->server->getPropertiesForPath($path, array('{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified'), 1);
     $parent = $this->server->tree->getNodeForPath($path);
     $parentpath = array();
     // only show parent if not leaving /cloud/; TODO how to improve this?
     if ($path && $path != "cloud") {
         list($parentUri) = DAV\URLUtil::splitPath($path);
         $fullPath = DAV\URLUtil::encodePath($this->server->getBaseUri() . $parentUri);
         $parentpath['icon'] = $this->enableAssets ? '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl('icons/parent' . $this->iconExtension) . '" width="24" alt="' . t('parent') . '"></a>' : '';
         $parentpath['path'] = $fullPath;
     }
     $f = array();
     foreach ($files as $file) {
         $ft = array();
         $type = null;
         // This is the current directory, we can skip it
         if (rtrim($file['href'], '/') == $path) {
             continue;
         }
         list(, $name) = DAV\URLUtil::splitPath($file['href']);
         if (isset($file[200]['{DAV:}resourcetype'])) {
             $type = $file[200]['{DAV:}resourcetype']->getValue();
             // resourcetype can have multiple values
             if (!is_array($type)) {
                 $type = array($type);
             }
             foreach ($type as $k => $v) {
                 // Some name mapping is preferred
                 switch ($v) {
                     case '{DAV:}collection':
                         $type[$k] = t('Collection');
                         break;
                     case '{DAV:}principal':
                         $type[$k] = t('Principal');
                         break;
                     case '{urn:ietf:params:xml:ns:carddav}addressbook':
                         $type[$k] = t('Addressbook');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}calendar':
                         $type[$k] = t('Calendar');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}schedule-inbox':
                         $type[$k] = t('Schedule Inbox');
                         break;
                     case '{urn:ietf:params:xml:ns:caldav}schedule-outbox':
                         $type[$k] = t('Schedule Outbox');
                         break;
                     case '{http://calendarserver.org/ns/}calendar-proxy-read':
                         $type[$k] = 'Proxy-Read';
                         break;
                     case '{http://calendarserver.org/ns/}calendar-proxy-write':
                         $type[$k] = 'Proxy-Write';
                         break;
                 }
             }
             $type = implode(', ', $type);
         }
         // If no resourcetype was found, we attempt to use
         // the contenttype property
         if (!$type && isset($file[200]['{DAV:}getcontenttype'])) {
             $type = $file[200]['{DAV:}getcontenttype'];
         }
         if (!$type) {
             $type = t('Unknown');
         }
         $size = isset($file[200]['{DAV:}getcontentlength']) ? (int) $file[200]['{DAV:}getcontentlength'] : '';
         $lastmodified = isset($file[200]['{DAV:}getlastmodified']) ? $file[200]['{DAV:}getlastmodified']->getTime()->format('Y-m-d H:i:s') : '';
         $fullPath = DAV\URLUtil::encodePath('/' . trim($this->server->getBaseUri() . ($path ? $path . '/' : '') . $name, '/'));
         $displayName = isset($file[200]['{DAV:}displayname']) ? $file[200]['{DAV:}displayname'] : $name;
         $displayName = $this->escapeHTML($displayName);
         $type = $this->escapeHTML($type);
         $icon = '';
         if ($this->enableAssets) {
             $node = $this->server->tree->getNodeForPath(($path ? $path . '/' : '') . $name);
             foreach (array_reverse($this->iconMap) as $class => $iconName) {
                 if ($node instanceof $class) {
                     $icon = '<a href="' . $fullPath . '"><img src="' . $this->getAssetUrl($iconName . $this->iconExtension) . '" alt="" width="24"></a>';
                     break;
                 }
             }
         }
         $parentHash = "";
         $owner = $this->auth->owner_id;
         $splitPath = split("/", $fullPath);
         if (count($splitPath) > 3) {
             for ($i = 3; $i < count($splitPath); $i++) {
                 $attachName = urldecode($splitPath[$i]);
                 $attachHash = $this->findAttachHash($owner, $parentHash, $attachName);
                 $parentHash = $attachHash;
             }
         }
         $attachIcon = "";
         // "<a href=\"attach/".$attachHash."\" title=\"".$displayName."\"><i class=\"icon-download\"></i></a>";
         // put the array for this file together
         $ft['attachId'] = $this->findAttachIdByHash($attachHash);
         $ft['fileStorageUrl'] = substr($fullPath, 0, strpos($fullPath, "cloud/")) . "filestorage/" . $this->auth->channel_name;
         $ft['icon'] = $icon;
         $ft['attachIcon'] = $size ? $attachIcon : '';
         // @todo Should this be an item value, not a global one?
         $ft['is_owner'] = $is_owner;
         $ft['fullPath'] = $fullPath;
         $ft['displayName'] = $displayName;
         $ft['type'] = $type;
         $ft['size'] = $size;
         $ft['sizeFormatted'] = $this->userReadableSize($size);
         $ft['lastmodified'] = $lastmodified ? datetime_convert('UTC', date_default_timezone_get(), $lastmodified) : '';
         $f[] = $ft;
     }
     // Storage and quota for the account (all channels of the owner of this directory)!
     $limit = service_class_fetch($owner, 'attach_upload_limit');
     $r = q("SELECT SUM(filesize) AS total FROM attach WHERE aid = %d", intval($this->auth->channel_account_id));
     $used = $r[0]['total'];
     if ($used) {
         $quotaDesc = t('%1$s used');
         $quotaDesc = sprintf($quotaDesc, $this->userReadableSize($used));
     }
     if ($limit && $used) {
         $quotaDesc = t('%1$s used of %2$s (%3$s&#37;)');
         $quotaDesc = sprintf($quotaDesc, $this->userReadableSize($used), $this->userReadableSize($limit), round($used / $limit, 1));
     }
     // prepare quota for template
     $quota['used'] = $used;
     $quota['limit'] = $limit;
     $quota['desc'] = $quotaDesc;
     $html .= replace_macros(get_markup_template('cloud_directory.tpl'), array('$header' => t('Files') . ": " . $this->escapeHTML($path) . "/", '$parentpath' => $parentpath, '$entries' => $f, '$quota' => $quota, '$name' => t('Name'), '$type' => t('Type'), '$size' => t('Size'), '$lastmod' => t('Last Modified'), '$parent' => t('parent'), '$edit' => t('Edit'), '$delete' => t('Delete'), '$total' => t('Total')));
     $output = '';
     if ($this->enablePost) {
         $this->server->broadcastEvent('onHTMLActionsPanel', array($parent, &$output));
     }
     $html .= $output;
     get_app()->page['content'] = $html;
     construct_page(get_app());
 }