Example #1
0
 /**
  * Add a menu item to the user hover dropdown
  *
  * @param string          $hook         the name of the hook
  * @param string          $type         the type of the hook
  * @param \ElggMenuItem[] $return_value current menu items
  * @param array           $params       supplied params
  *
  * @return void|\ElggMenuItem[]
  */
 public static function register($hook, $type, $return_value, $params)
 {
     static $user_dirs;
     if (!elgg_is_admin_logged_in()) {
         return;
     }
     if (empty($params) || !is_array($params)) {
         return;
     }
     $user = elgg_extract('entity', $params);
     if (!$user instanceof \ElggUser) {
         return;
     }
     if (!isset($user_dirs)) {
         $user_dirs = [];
     }
     // save in a static for performance when viewing user listings
     if (!isset($user_dirs[$user->getGUID()])) {
         $user_dirs[$user->getGUID()] = false;
         $edl = new \Elgg\EntityDirLocator($user->getGUID());
         $path = $edl->getPath();
         if (is_dir(elgg_get_data_path() . $path)) {
             $path = substr($path, 0, -1);
             $user_dirs[$user->getGUID()] = \ElggMenuItem::factory(['name' => 'dataroot-browser', 'text' => elgg_echo('dataroot_browser:menu:user_hover'), 'href' => elgg_http_add_url_query_elements('admin/administer_utilities/dataroot_browser', ['dir' => $path]), 'is_trusted' => true, 'section' => 'admin']);
         }
     }
     if (empty($user_dirs[$user->getGUID()])) {
         return;
     }
     $return_value[] = $user_dirs[$user->getGUID()];
     return $return_value;
 }
Example #2
0
 /**
  * Serves an icon
  * Terminates the script and sends headers on error
  * @return void
  */
 public function serve()
 {
     if (headers_sent()) {
         return;
     }
     if (!$this->guid || !$this->icontime || !$this->path || !$this->hmac) {
         header("HTTP/1.1 404 Not Found");
         exit;
     }
     $etag = $this->icontime . $this->guid;
     if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"{$etag}\"") {
         header("HTTP/1.1 304 Not Modified");
         exit;
     }
     $this->openDbLink();
     $values = $this->getDatalistValue(array('dataroot', '__site_secret__'));
     $this->closeDbLink();
     if (empty($values)) {
         header("HTTP/1.1 404 Not Found");
         exit;
     }
     $data_root = $values['dataroot'];
     $key = $values['__site_secret__'];
     $hmac = hash_hmac('sha256', $this->guid . $this->path, $key);
     if ($this->hmac !== $hmac) {
         header("HTTP/1.1 403 Forbidden");
         exit;
     }
     $locator = new \Elgg\EntityDirLocator($this->dir_guid);
     $filename = $data_root . $locator->getPath() . $this->path;
     if (!file_exists($filename)) {
         header("HTTP/1.1 404 Not Found");
         exit;
     }
     $filesize = filesize($filename);
     $ext = pathinfo($filename, PATHINFO_EXTENSION);
     switch ($ext) {
         default:
             $mimetype = 'image/jpeg';
             break;
         case 'png':
             $mimetype = 'image/png';
             break;
         case 'gif':
             $mimetype = 'image/gif';
             break;
     }
     header("Content-type: {$mimetype}");
     header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+6 months")), true);
     header("Pragma: public");
     header("Cache-Control: public");
     header("Content-Length: {$filesize}");
     header("ETag: \"{$etag}\"");
     readfile($filename);
     exit;
 }
Example #3
0
 public function testGetPath()
 {
     $size = \Elgg\EntityDirLocator::BUCKET_SIZE;
     foreach ($this->guids as $guid) {
         $test = new \Elgg\EntityDirLocator($guid);
         // we start at 1 since there are no guids of 0
         if ($guid < 5000) {
             $path = "1/{$guid}/";
         } elseif ($guid < 10000) {
             $path = "5000/{$guid}/";
         } elseif ($guid < 15000) {
             $path = "10000/{$guid}/";
         } elseif ($guid < 20000) {
             $path = "15000/{$guid}/";
         }
         $this->assertSame($path, $test->getPath());
     }
 }
Example #4
0
            $result = mysql_query($q, $mysql_dblink);
            if ($result) {
                $row = mysql_fetch_object($result);
                while ($row) {
                    if ($row->name == 'dataroot') {
                        $data_root = $row->value;
                    }
                    $row = mysql_fetch_object($result);
                }
            }
            @mysql_close($mysql_dblink);
        }
    }
}
if (isset($data_root)) {
    $locator = new \Elgg\EntityDirLocator($guid);
    $entity_path = $data_root . $locator->getPath();
    $filename = $entity_path . "groups/{$group_guid}{$size}.jpg";
    $filecontents = @file_get_contents($filename);
    // try fallback size
    if (!$filecontents && $size !== "medium") {
        $filename = $entity_path . "groups/{$group_guid}medium.jpg";
        $filecontents = @file_get_contents($filename);
    }
    if ($filecontents) {
        $filesize = strlen($filecontents);
        header("Content-type: image/jpeg");
        header("Expires: " . gmdate("D, d M Y H:i:s \\G\\M\\T", strtotime("+6 months")), true);
        header("Pragma: public");
        header("Cache-Control: public");
        header("Content-Length: {$filesize}");
Example #5
0
 /**
  * Construct a file path matrix for an entity.
  *
  * @param int $guid The guid of the entity to store the data under.
  *
  * @return string The path where the entity's data will be stored relative to the data dir.
  * @deprecated 1.9 Use \Elgg\EntityDirLocator()
  */
 protected function makeFileMatrix($guid)
 {
     elgg_deprecated_notice('\\ElggDiskFilestore::makeFileMatrix() is deprecated by \\Elgg\\EntityDirLocator', 1.9);
     $entity = get_entity($guid);
     if (!$entity instanceof \ElggEntity) {
         return false;
     }
     $dir = new \Elgg\EntityDirLocator($guid);
     return $dir->getPath();
 }
Example #6
0
    exit;
}
$size = "medium";
if (!empty($_GET['size'])) {
    $size = strtolower($_GET['size']);
    if (!in_array($size, array('large', 'medium', 'small', 'tiny', 'master', 'topbar'))) {
        $size = "medium";
    }
}
$initialRoot = dirname(dirname(__DIR__));
$backupRoot = dirname(dirname(dirname($initialRoot)));
if (!(include_once "{$initialRoot}/vendor/autoload.php")) {
    require_once "{$backupRoot}/vendor/autoload.php";
}
$data_root = \Elgg\Application::getDataPath();
$locator = new \Elgg\EntityDirLocator($guid);
$user_path = $data_root . $locator->getPath();
$filename = $user_path . "profile/{$guid}{$size}.jpg";
$filesize = @filesize($filename);
if ($filesize) {
    header("Content-type: image/jpeg");
    header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+6 months")), true);
    header("Pragma: public");
    header("Cache-Control: public");
    header("Content-Length: {$filesize}");
    header("ETag: \"{$etag}\"");
    readfile($filename);
    exit;
}
// something went wrong so load engine and try to forward to default icon
\Elgg\Application::start();
Example #7
0
/**
 * Returns an array of documents to be deleted from the elastic index
 *
 * @return array
 */
function elasticsearch_get_documents_for_deletion()
{
    $plugin = elgg_get_plugin_from_id('elasticsearch');
    $locator = new \Elgg\EntityDirLocator($plugin->getGUID());
    $documents_path = elgg_get_data_path() . $locator->getPath() . 'documents_for_deletion/';
    $dir = @opendir($documents_path);
    if (!$dir) {
        return [];
    }
    $documents = [];
    while (($file = readdir($dir)) !== false) {
        if (is_dir($file)) {
            continue;
        }
        $contents = unserialize(file_get_contents($documents_path . $file));
        if (!is_array($contents)) {
            continue;
        }
        $documents[$file] = $contents;
    }
    return $documents;
}
Example #8
0
/**
 * Returns an array of documents to be deleted from the elastic index
 *
 * @return array
 */
function elasticsearch_get_documents_for_deletion()
{
    $plugin = elgg_get_plugin_from_id('elasticsearch');
    $locator = new \Elgg\EntityDirLocator($plugin->getGUID());
    $documents_path = elgg_get_data_path() . $locator->getPath() . 'documents_for_deletion/';
    $dir = @opendir($documents_path);
    if (!$dir) {
        return [];
    }
    $documents = [];
    while (($file = readdir($dir)) !== false) {
        if (is_dir($file)) {
            continue;
        }
        $contents = unserialize(file_get_contents($documents_path . $file));
        if (!is_array($contents)) {
            continue;
        }
        $deletion_time = elgg_extract('time', $contents);
        if (!empty($deletion_time) && $deletion_time > time()) {
            // not yet scheduled for deletion, (only if deletion failed once before)
            continue;
        }
        unset($contents['time']);
        $documents[$file] = $contents;
    }
    return $documents;
}
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function serve()
 {
     if (headers_sent()) {
         return;
     }
     $query = $this->get('q');
     $query = unserialize(base64_decode($query));
     $this->uid = $query['uid'];
     $this->d = $query['d'];
     $this->ts = $query['ts'];
     $this->path = $query['path'];
     $this->hmac = $query['mac'];
     if (!$this->uid || !$this->ts || !$this->path || !$this->hmac) {
         header("HTTP/1.1 400 Bad Request");
         exit;
     }
     $etag = md5($this->ts . $this->uid);
     $ifNoneMatch = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim(stripslashes($_SERVER['HTTP_IF_NONE_MATCH']), '"') : false;
     if ($ifNoneMatch == $etag) {
         header('HTTP/1.0 304 Not Modified');
         exit;
     }
     $values = $this->getDatalistValue(array('dataroot', '__site_secret__'));
     if (empty($values)) {
         header("HTTP/1.1 404 Not Found");
         exit;
     }
     $data_root = $values['dataroot'];
     $key = $values['__site_secret__'];
     $hmac = hash_hmac('sha256', $this->uid . $this->path, $key);
     if ($this->hmac !== $hmac) {
         header("HTTP/1.1 403 Forbidden");
         exit;
     }
     $locator = new \Elgg\EntityDirLocator($this->d);
     $d = $locator->getPath();
     $filename = "{$data_root}{$d}{$this->path}";
     if (!file_exists($filename) || !is_readable($filename)) {
         header("HTTP/1.1 404 Not Found");
         exit;
     }
     $filesize = filesize($filename);
     $ext = pathinfo($filename, PATHINFO_EXTENSION);
     switch ($ext) {
         default:
             $mimetype = 'application/otcet-stream';
             break;
         case 'jpg':
         case 'jpeg':
             $mimetype = 'image/jpeg';
             break;
         case 'png':
             $mimetype = 'image/png';
             break;
         case 'gif':
             $mimetype = 'image/gif';
             break;
     }
     header("Content-type: {$mimetype}");
     header("Content-disposition: inline");
     header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+6 months")), true);
     header("Pragma: public");
     header("Cache-Control: public");
     header("Content-Length: {$filesize}");
     header("ETag: \"{$etag}\"");
     readfile($filename);
     exit;
 }
Example #10
0
                    $contents .= date("Y/n/j", $last_action) . "<br>";
                } else {
                    if ($lastlogin > 1) {
                        $contents .= elgg_echo('lastlogin:today') . "<br>";
                    } else {
                        $contents .= elgg_echo('lastlogin:hour') . "<br>";
                    }
                }
            }
        } else {
            $contents .= elgg_echo('lastlogin:never') . "<br>";
        }
        $add_it = true;
    }
    if (elgg_get_plugin_setting('registered_visibility', 'lastlogin') == "all" || elgg_get_plugin_setting('registered_visibility', 'lastlogin') == "admin" && elgg_is_admin_logged_in()) {
        $time_created = $vars['entity']->time_created;
        $contents .= elgg_echo('lastlogin:joindate') . ": " . date("Y/n/j", $time_created) . "<br>";
        $add_it = true;
    }
    if (elgg_get_plugin_setting('guid_visibility', 'lastlogin') == "yes" && elgg_is_admin_logged_in()) {
        $user_guid = $vars['entity']->guid;
        $contents .= elgg_echo('lastlogin:guid') . ": " . $user_guid . "<br>";
        $user_data_dir_location = new \Elgg\EntityDirLocator($user_guid);
        $contents .= elgg_echo('lastlogin:data_dir') . ": " . $user_data_dir_location->getPath() . "<br>";
        $add_it = true;
    }
    $contents .= "</div>";
    if ($add_it) {
        echo $contents;
    }
}
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function serve()
 {
     if (headers_sent()) {
         return;
     }
     if (!$this->uid || !$this->ts || !$this->path || !$this->hmac) {
         header("HTTP/1.1 400 Bad Request");
         exit;
     }
     $etag = md5($this->ts . $this->uid);
     if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"{$etag}\"") {
         header("HTTP/1.1 304 Not Modified");
         exit;
     }
     $this->openDbLink();
     $values = $this->getDatalistValue(array('dataroot', '__site_secret__'));
     $this->closeDbLink();
     if (empty($values)) {
         header("HTTP/1.1 404 Not Found");
         exit;
     }
     $data_root = $values['dataroot'];
     $key = $values['__site_secret__'];
     $hmac = hash_hmac('sha256', $this->uid . $this->path, $key);
     if ($this->hmac !== $hmac) {
         header("HTTP/1.1 403 Forbidden");
         exit;
     }
     if (\hypeJunction\Integration::isElggVersionBelow('1.9.0')) {
         $time_created = date('Y/m/d', $this->dts);
         $d = "{$time_created}/{$this->d}/";
     } else {
         $locator = new \Elgg\EntityDirLocator($this->d);
         $d = $locator->getPath();
     }
     $filename = "{$data_root}{$d}{$this->path}";
     if (!file_exists($filename) || !is_readable($filename)) {
         header("HTTP/1.1 404 Not Found");
         exit;
     }
     $filesize = filesize($filename);
     $ext = pathinfo($filename, PATHINFO_EXTENSION);
     switch ($ext) {
         default:
             $mimetype = 'application/otcet-stream';
             break;
         case 'jpg':
         case 'jpeg':
             $mimetype = 'image/jpeg';
             break;
         case 'png':
             $mimetype = 'image/png';
             break;
         case 'gif':
             $mimetype = 'image/gif';
             break;
     }
     header("Content-type: {$mimetype}");
     header("Content-disposition: inline");
     header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+6 months")), true);
     header("Pragma: public");
     header("Cache-Control: public");
     header("Content-Length: {$filesize}");
     header("ETag: \"{$etag}\"");
     readfile($filename);
     exit;
 }