public function replace_tag($tagdata = '', $params = '')
 {
     if ($tagdata == '') {
         return $tagdata;
     }
     $raw_content = parent::replace_tag($tagdata, $params);
     $content_obj = json_decode($raw_content);
     if (isset($content_obj->title_text)) {
         $tagdata = str_replace('{title_text}', $content_obj->title_text, $tagdata);
     }
     if (isset($content_obj->assets_file_id)) {
         ee()->load->add_package_path(PATH_THIRD . 'assets/');
         require_once PATH_THIRD . 'assets/sources/ee/file.ee.php';
         require_once PATH_THIRD . 'assets/helper.php';
         ee()->load->library('Assets_lib');
         $assets_file = ee()->assets_lib->get_file_by_id($content_obj->assets_file_id);
         $assets_helper = new Assets_helper();
         $tagdata = $assets_helper->parse_file_tag(array($assets_file), $tagdata);
     } else {
         if (isset($content_obj->file_id)) {
             require_once APPPATH . 'fieldtypes/file/ft.file.php';
             $ee_file = new File_ft();
             $file_info = ee()->file_field->parse_field($content_obj->file_id);
             if ($file_info) {
                 $tagdata = $ee_file->replace_tag($file_info, $params, $tagdata);
             }
         }
     }
     return $tagdata;
 }
Beispiel #2
0
 /**
  * Get files and parse them
  */
 public function files()
 {
     $tagdata = $this->EE->TMPL->tagdata;
     // Ignore if there's no tagdata
     if (!$tagdata) {
         return '';
     }
     $parameters = $this->_gather_file_parameters();
     $files = $this->EE->assets_lib->get_files($parameters);
     if ($files) {
         // is there a var_prefix?
         if (($var_prefix = $this->EE->TMPL->fetch_param('var_prefix')) !== FALSE) {
             $var_prefix = rtrim($var_prefix, ':') . ':';
             $tagdata = str_replace($var_prefix, '', $tagdata);
         }
         return Assets_helper::parse_file_tag($files, $tagdata);
     } else {
         return $this->EE->TMPL->no_results();
     }
 }
 /**
  * Perform the simple HTML upload for frontend forms.
  *
  * @param $file_info
  * @param $filedir_id
  * @return mixed
  */
 private function _simple_html_upload($file_info, $filedir_id)
 {
     $filename = $file_info['name'];
     try {
         $source = $this->EE->assets_lib->instantiate_source_type((object) array('source_type' => 'ee', 'filedir_id' => $filedir_id));
         $filedir = $source->settings();
         if ($filedir->max_size && filesize($file_info['tmp_name']) > $filedir->max_size) {
             return FALSE;
         }
         $filename = preg_replace('/[^a-z0-9_\\-\\.]/i', '_', $filename);
         $file_parts = explode('.', $filename);
         $ext = array_pop($file_parts);
         $file_base = join(".", $file_parts);
         $filename = $file_base . '.' . $ext;
         $target = $filedir->server_path . $filename;
         $i = 0;
         while (file_exists($target)) {
             if (is_numeric($i) && $i < 50) {
                 $i++;
             } else {
                 $i = uniqid('', TRUE);
             }
             $filename = $file_base . '_' . $i . '.' . $ext;
             $target = $filedir->server_path . $filename;
         }
         move_uploaded_file($file_info['tmp_name'], $target);
         $file_id = $this->EE->assets_lib->register_ee_file($filedir->id, $filename);
         if ($file_id) {
             Assets_helper::create_ee_thumbnails($target, $filedir->id);
             return $file_id;
         }
     } catch (Exception $exception) {
         // Skip this.
     }
 }
 /**
  * Set Sections
  */
 function set_sections()
 {
     // are we on the Publish page?
     if ($this->EE->input->get('C') == 'content_publish' && $this->EE->input->get('M') == 'entry_form') {
         $this->EE->lang->loadfile('matrix_multi_upload');
         $query = $this->EE->db->query('SELECT action_id FROM exp_actions WHERE class = "Matrix_multi_upload_mcp" AND method = "upload"');
         // is the module installed?
         if ($query->num_rows()) {
             $action_id = $query->row('action_id');
             // Prefs
             $group_id = $this->EE->session->userdata('group_id');
             $upload_prefs = Matrix_multi_upload_helper::get_upload_preferences($group_id);
             // are there any upload directories?
             if ($upload_prefs) {
                 foreach ($upload_prefs as $row) {
                     $upload_dirs[$row['id']] = $row['name'];
                 }
                 // add the Matrix Column section
                 $this->sections['1. ' . lang('choose_col')] = '<p>' . lang('choose_col_info') . '</p>' . '<div id="mmu_matrix_col"><p class="notice">' . lang('choose_col_notice') . '</p></div>';
                 // get the site url
                 if (($site_url = $this->EE->config->item('mmu_site_url')) === FALSE) {
                     $site_url = $this->EE->functions->fetch_site_index(0, 0);
                 }
                 // include CSS and JS
                 $this->_include_theme_js('lib/plupload/js/plupload.js');
                 $this->_include_theme_js('lib/plupload/js/plupload.html5.js');
                 $this->_include_theme_js('lib/plupload/js/plupload.flash.js');
                 $this->_include_theme_js('lib/plupload/js/jquery.plupload.queue/jquery.plupload.queue.js');
                 $this->_include_theme_js('scripts/matrix_multi_upload.js');
                 // make the upload URL available to JS
                 $this->_include_theme_css('styles/matrix_multi_upload.css');
                 $this->_insert_js('MMU.FileHandler.uploadUrl = "' . $site_url . QUERY_MARKER . 'ACT=' . $action_id . '";');
                 // add the Plupload sections
                 $this->sections['2. ' . lang('choose_filedir')] = '<p>' . lang('choose_filedir_info') . '</p>' . form_dropdown('mmu_filedir', $upload_dirs, '', 'id="mmu_filedir"');
                 $this->sections[lang('upload_files')] = '<div id="mmu_plupload" style="width: 450px; height: 330px;">' . 'You browser doesn’t support multi-file uploading.' . '</div>';
                 // -------------------------------------------
                 //  Assets integration
                 // -------------------------------------------
                 if (array_key_exists('assets', $this->EE->addons->get_installed())) {
                     $this->sections['2. ' . lang('choose_files')] = '<p>' . lang('choose_files_info') . '</p>' . '<input id="mmu_choose_files" type="button" value="' . lang('choose_files') . '">';
                     // include the sheet resources
                     require_once PATH_THIRD . 'assets/helper.php';
                     $assets_helper = new Assets_helper();
                     $assets_helper->include_sheet_resources();
                 }
             } else {
                 $this->sections['Error'] = 'Either no upload directories exist, or you don’t have permission to upload to any of them.';
             }
         } else {
             $this->sections['Error'] = 'The Matrix Multi-Upload module is not installed.';
         }
     } else {
         // just hide the tab
         $this->_insert_js('jQuery("#accessoryTabs a.matrix_multi_upload").parent("li").remove()');
     }
 }
Beispiel #5
0
 /**
  * Refresh a connection information and return authorization token.
  *
  * @throws Exception
  */
 private function _refresh_connection_information()
 {
     $settings = $this->_source_settings;
     $username = $settings->username;
     $api_key = $settings->api_key;
     $headers = array('Content-Type: application/json', 'Accept: application/json');
     $payload = Assets_helper::get_json(array('auth' => array('RAX-KSKEY:apiKeyCredentials' => array('username' => $username, 'apiKey' => $api_key))));
     $target_url = self::_make_authorization_request_url();
     $response = self::_do_request($target_url, 'POST', $headers, array(), $payload);
     $body = json_decode(substr($response, strpos($response, '{')));
     if (!$body) {
         throw new Exception(lang('wrong_credentials'));
     }
     $token = $body->access->token->id;
     $services = $body->access->serviceCatalog;
     if (!$token || !$services) {
         throw new Exception(lang('wrong_credentials'));
     }
     $regions = array();
     // Fetch region information
     foreach ($services as $service) {
         if ($service->name == 'cloudFilesCDN' || $service->name == 'cloudFiles') {
             foreach ($service->endpoints as $endpoint) {
                 if (empty($regions[$endpoint->region])) {
                     $regions[$endpoint->region] = array();
                 }
                 if ($service->name == 'cloudFilesCDN') {
                     $regions[$endpoint->region]['cdn_url'] = $endpoint->publicURL;
                 } else {
                     $regions[$endpoint->region]['storage_url'] = $endpoint->publicURL;
                 }
             }
         }
     }
     // Each region gets separate connection information
     foreach ($regions as $region => $data) {
         $connection_key = $this->_get_connection_key($username, $api_key, $region);
         $data = array('token' => $token, 'storage_url' => $data['storage_url'], 'cdn_url' => $data['cdn_url']);
         // Store this in the access store
         self::$_access_store[$connection_key] = $data;
         $this->_update_access_data($connection_key, $data);
     }
 }
Beispiel #6
0
 /**
  * Display the field
  *
  * @param $data
  * @return string
  */
 public function display_field($data)
 {
     ee()->load->library('table_lib');
     $vars = array('field_id' => $this->field_id, 'table_rows' => FALSE, 'table_num_rows' => 0, 'table_num_cols' => 0, 'celltypes' => ee()->table_lib->get_celltypes(), 'settings' => $this->settings, 'use_assets' => FALSE);
     $field_id = $this->field_id;
     $table_post_data = ee()->input->post('table_cell_' . $field_id);
     $entry_id = $this->content_id();
     /**
      * If we have POST data here it might be a result of a save with validation errors
      */
     if ($table_post_data) {
         $table_num_cols = 0;
         $table_num_rows = count($table_post_data);
         if ($table_num_rows > 0) {
             $table_num_cols = count($table_post_data[1]);
             // get number of cols for first row
         }
         // convert POST data to the format we get it from the db
         $table_rows = array();
         for ($j = 1; $j <= count($table_post_data); $j++) {
             $first_cell = $table_post_data[$j][1];
             reset($first_cell);
             $row_type = key($first_cell);
             $row_data = array('entry_id' => $entry_id, 'row' => $j, 'row_type' => $row_type);
             $col_data = $table_post_data[$j];
             for ($c = 1; $c <= count($col_data); $c++) {
                 $row_data['col_' . $c] = $col_data[$c][$row_type];
                 // @todo fix this when each cell can have different types?
             }
             $table_rows[] = $row_data;
         }
         $vars['table_rows'] = $table_rows;
         $vars['table_num_rows'] = $table_num_rows;
         $vars['table_num_cols'] = $table_num_cols;
     } else {
         if ($entry_id > 0) {
             // entry is saved so we look up the saved data
             $field_name = ee()->table_lib->get_field_name($field_id);
             $q = ee()->db->where('entry_id', $entry_id)->order_by('row')->get(Table_ft::TABLE_PREFIX . $field_name);
             $table_rows = $q->result_array();
             $table_num_rows = $q->num_rows();
             $table_num_cols = 0;
             // count columns
             if ($table_num_rows > 0) {
                 $col_id = 1;
                 while (isset($table_rows[0]['col_' . $col_id])) {
                     $table_num_cols++;
                     $col_id++;
                 }
             }
             $vars['table_rows'] = $table_rows;
             $vars['table_num_rows'] = $table_num_rows;
             $vars['table_num_cols'] = $table_num_cols;
         }
     }
     // Make sure that Assets is installed
     if (array_key_exists('assets', $this->EE->addons->get_installed())) {
         require_once PATH_THIRD . 'assets/helper.php';
         $assets_helper = new Assets_helper();
         $assets_helper->include_sheet_resources();
         $vars['use_assets'] = TRUE;
     }
     ee()->cp->add_to_head('<link rel="stylesheet" href="' . ee()->table_lib->get_theme_url() . 'css/table.min.css">');
     $dynamic_js_vars = array('field_id' => $field_id, 'factories' => ee()->table_lib->get_js_cell_factories(), 'use_assets' => $vars['use_assets']);
     $dynamic_js = ee()->load->view('table_dynamic_js', $dynamic_js_vars, TRUE);
     ee()->cp->add_to_head($dynamic_js);
     ee()->cp->add_to_head('<script type="text/javascript" src="' . ee()->table_lib->get_theme_url() . 'js/table.min.js' . '"></script>');
     return ee()->load->view('table_publish_view', $vars, TRUE);
 }
Beispiel #7
0
 /**
  * Returns a path for the thumbnail source
  * @return mixed
  */
 public function get_thumbnail_source_path()
 {
     $path = Assets_helper::ensure_cache_path('assets/s3_sources') . $this->file_id . '.jpg';
     if (!file_exists($path)) {
         $location = $this->get_local_copy();
         @rename($location, $path);
     }
     return Assets_helper::ensure_cache_path('assets/s3_sources') . $this->file_id . '.jpg';
 }
 /**
  * Perform image actions - resize and save dimensions. If no bucket name provided, $uri is treated as filesystem path
  *
  * @param $uri
  * @param $file_id
  * @param mixed $bucket false for uri to be treated as a filesystem path
  * @return bool
  */
 private function _perform_image_actions($uri, $file_id, $bucket = FALSE)
 {
     $this->EE->load->library('filemanager');
     $cache_path = 'assets/s3_sources';
     $cache_path = Assets_helper::ensure_cache_path($cache_path);
     if ($bucket) {
         $target = Assets_helper::get_temp_file();
         $this->_s3_set_creds($this->settings()->access_key_id, $this->settings()->secret_access_key);
         $this->s3->getObject($bucket, $this->_get_path_prefix() . $uri, $target);
         $uri = $target;
     }
     list($width, $height) = getimagesize($uri);
     $data = array('width' => $width, 'height' => $height);
     $this->_update_file($data, $file_id);
     if (strtolower($this->EE->config->item('assets_cache_remote_images')) !== "no") {
         $target_path = $cache_path . $file_id . '.jpg';
         $this->EE->assets_lib->resize_image($uri, $target_path, self::IMAGE_SOURCE_SIZE);
     }
     @unlink($uri);
 }
 /**
  * Get source
  *
  * @param StdCLass $data_object
  * @param bool $ignore_restrictions if set to TRUE, this source will not impose any filedir restrictions
  * @return Assets_base_source
  * @throws Exception
  */
 public function instantiate_source_type($data_object, $ignore_restrictions = FALSE)
 {
     $source_key = $data_object->source_type . '_' . (isset($data_object->source_id) ? $data_object->source_id : '') . '_' . (isset($data_object->filedir_id) ? $data_object->filedir_id : '') . (int) $ignore_restrictions;
     if (empty($this->cache['sources'][$source_key])) {
         require_once PATH_THIRD . 'assets/sources/' . $data_object->source_type . '/source.' . $data_object->source_type . '.php';
         require_once PATH_THIRD . 'assets/sources/' . $data_object->source_type . '/file.' . $data_object->source_type . '.php';
         $source_class = 'Assets_' . $data_object->source_type . '_source';
         if ($data_object->source_type == 'ee') {
             $settings = $this->EE->db->get_where('upload_prefs', array('id' => $data_object->filedir_id))->row();
             if (empty($settings)) {
                 throw new Exception(lang('unknown_source'));
             }
             $source_id = $data_object->filedir_id;
         } else {
             $settings = $this->EE->db->get_where('assets_sources', array('source_id' => $data_object->source_id, 'source_type' => $data_object->source_type))->row();
             if (empty($settings)) {
                 throw new Exception(lang('unknown_source'));
             }
             $source_id = $data_object->source_id;
             $settings = Assets_helper::apply_source_overrides($source_id, json_decode($settings->settings));
         }
         $this->cache['sources'][$source_key] = new $source_class($source_id, $settings, $ignore_restrictions);
     }
     if (empty($this->cache['sources'][$source_key])) {
         throw new Exception(lang('invalid_source_path'));
     }
     return $this->cache['sources'][$source_key];
 }
Beispiel #10
0
 /**
  * Inserts the Wygwam config JS in the page foot.
  *
  * @static
  * @param array $settings The field settings
  */
 public static function insert_config_js($settings)
 {
     $EE = get_instance();
     $global_settings = self::get_global_settings();
     // starting point
     $config = self::base_config();
     // -------------------------------------------
     //  Editor Config
     // -------------------------------------------
     if ($EE->db->table_exists('wygwam_configs') && is_numeric($settings['config']) && ($query = $EE->db->select('settings')->get_where('wygwam_configs', array('config_id' => $settings['config']))) && $query->num_rows()) {
         // merge custom settings into config
         $custom_settings = unserialize(base64_decode($query->row('settings')));
         $config = array_merge($config, $custom_settings);
     } else {
         $settings['config'] = 'default';
     }
     // skip if already included
     if (isset(self::$_included_configs) && in_array($settings['config'], self::$_included_configs)) {
         return;
     }
     // language
     if (!isset($config['language']) || !$config['language']) {
         $lang_map = self::lang_map();
         $language = $EE->session->userdata('language');
         $config['language'] = isset($lang_map[$language]) ? $lang_map[$language] : 'en';
     }
     // toolbar
     if (is_array($config['toolbar'])) {
         $config['toolbar'] = self::create_toolbar($config['toolbar']);
     }
     // css
     if (!$config['contentsCss']) {
         unset($config['contentsCss']);
     }
     // extraPlugins
     $config['extraPlugins'] = (isset($config['extraPlugins']) && $config['extraPlugins'] ? $config['extraPlugins'] . ',' : '') . 'wygwam,embedmedia,readmore';
     // -------------------------------------------
     //  File Browser Config
     // -------------------------------------------
     $user_group = $EE->session->userdata('group_id');
     $upload_dir = isset($config['upload_dir']) ? $config['upload_dir'] : NULL;
     $upload_prefs = self::get_upload_preferences($user_group, $upload_dir);
     // before doing anything, make sure that the user has access to any upload directories
     // (taking into account the upload directory setting)
     if ($upload_prefs) {
         $file_browser = isset($global_settings['file_browser']) ? $global_settings['file_browser'] : 'ee';
         // no EE file browser for SafeCracker
         if (REQ == 'PAGE' && $file_browser == 'ee') {
             $file_browser = 'ckfinder';
         }
         switch ($file_browser) {
             case 'ckfinder':
                 // CKFinder can only pull files from a single upload directory, so make sure it's set
                 if (!$upload_dir) {
                     break;
                 }
                 if (!isset($_SESSION)) {
                     @session_start();
                 }
                 if (!isset($_SESSION['wygwam_' . $config['upload_dir']])) {
                     $_SESSION['wygwam_' . $config['upload_dir']] = array();
                 }
                 $sess =& $_SESSION['wygwam_' . $config['upload_dir']];
                 // add the FCPATH if this is a relative path
                 if (!preg_match('/^(\\/|\\\\|[a-zA-Z]+:)/', $upload_prefs['server_path'])) {
                     $upload_prefs['server_path'] = FCPATH . $upload_prefs['server_path'];
                 }
                 $sess['p'] = $upload_prefs['server_path'];
                 $sess['u'] = $upload_prefs['url'];
                 $sess['t'] = $upload_prefs['allowed_types'];
                 $sess['s'] = $upload_prefs['max_size'];
                 $sess['w'] = $upload_prefs['max_width'];
                 $sess['h'] = $upload_prefs['max_height'];
                 $config['filebrowserImageBrowseUrl'] = self::theme_url() . 'lib/ckfinder/ckfinder.html?Type=Images&id=' . $config['upload_dir'];
                 $config['filebrowserImageUploadUrl'] = self::theme_url() . 'lib/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $config['upload_dir'];
                 if ($upload_prefs['allowed_types'] == 'all') {
                     $config['filebrowserBrowseUrl'] = self::theme_url() . 'lib/ckfinder/ckfinder.html?id=' . $config['upload_dir'];
                     $config['filebrowserUploadUrl'] = self::theme_url() . 'lib/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files&id=' . $config['upload_dir'];
                     $config['filebrowserFlashBrowseUrl'] = self::theme_url() . 'lib/ckfinder/ckfinder.html?Type=Flash&id=' . $config['upload_dir'];
                     $config['filebrowserFlashUploadUrl'] = self::theme_url() . 'lib/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash&id=' . $config['upload_dir'];
                 }
                 break;
             case 'assets':
                 // make sure Assets is actually installed
                 // (otherwise, just use the EE File Manager)
                 if (array_key_exists('assets', $EE->addons->get_installed())) {
                     // include sheet resources
                     if (!class_exists('Assets_helper')) {
                         require PATH_THIRD . 'assets/helper.php';
                     }
                     $assets_helper = new Assets_helper();
                     $assets_helper->include_sheet_resources();
                     // if no upload directory was set, just default to "all"
                     if (!$upload_dir) {
                         $upload_dir = '"all"';
                     }
                     $config['filebrowserBrowseFunc'] = 'function(params) { Wygwam.loadAssetsSheet(params, ' . $upload_dir . ', "any"); }';
                     $config['filebrowserImageBrowseFunc'] = 'function(params) { Wygwam.loadAssetsSheet(params, ' . $upload_dir . ', "image"); }';
                     $config['filebrowserFlashBrowseFunc'] = 'function(params) { Wygwam.loadAssetsSheet(params, ' . $upload_dir . ', "flash"); }';
                     break;
                 }
             default:
                 // load the file browser
                 $EE->load->library('file_field');
                 $EE->file_field->browser();
                 // if no upload directory was set, just default to "all"
                 if (!$upload_dir) {
                     $upload_dir = '"all"';
                 }
                 $config['filebrowserBrowseFunc'] = 'function(params) { Wygwam.loadEEFileBrowser(params, ' . $upload_dir . ', "any"); }';
                 $config['filebrowserImageBrowseFunc'] = 'function(params) { Wygwam.loadEEFileBrowser(params, ' . $upload_dir . ', "image"); }';
         }
     }
     // add any site page data to wygwam config
     if ($pages = self::get_all_page_data()) {
         $EE->lang->loadfile('wygwam');
         $site_page_string = lang('wygwam_site_page');
         foreach ($pages as $page) {
             $config['link_types'][$site_page_string][] = array('label' => $page[2], 'url' => $page[4]);
         }
     }
     // -------------------------------------------
     //  'wygwam_config' hook
     //   - Override any of the config settings
     //
     if ($EE->extensions->active_hook('wygwam_config')) {
         $config = $EE->extensions->call('wygwam_config', $config, $settings);
     }
     //
     // -------------------------------------------
     unset($config['upload_dir']);
     // -------------------------------------------
     //  JSONify Config and Return
     // -------------------------------------------
     $config_literals = self::config_literals();
     $config_booleans = self::config_booleans();
     $js = '';
     foreach ($config as $setting => $value) {
         if (!in_array($setting, $config_literals)) {
             if (in_array($setting, $config_booleans)) {
                 $value = $value == 'y' ? TRUE : FALSE;
             }
             $value = $EE->javascript->generate_json($value, TRUE);
             // Firefox gets an "Unterminated string literal" error if this line gets too long,
             // so let's put each new value on its own line
             if ($setting == 'link_types') {
                 $value = str_replace('","', "\",\n\t\t\t\"", $value);
             }
         }
         $js .= ($js ? ',' . NL : '') . "\t\t" . '"' . $setting . '": ' . $value;
     }
     // Strip out any non-space whitespace chars
     $js = str_replace(array(chr(10), chr(11), chr(12), chr(13)), ' ', $js);
     self::insert_js(NL . "\t" . 'Wygwam.configs["' . $settings['config'] . '"] = {' . NL . $js . NL . "\t" . '};' . NL);
     self::$_included_configs[] = $settings['config'];
 }
Beispiel #11
0
 /**
  * Get upload POST parameters for form uploads
  *
  * @param string $bucket Bucket name
  * @param string $uriPrefix Object URI prefix
  * @param constant $acl ACL constant
  * @param integer $lifetime Lifetime in seconds
  * @param integer $maxFileSize Maximum filesize in bytes (default 5MB)
  * @param string $successRedirect Redirect URL or 200 / 201 status code
  * @param array $amzHeaders Array of x-amz-meta-* headers
  * @param array $headers Array of request headers or content type as a string
  * @param boolean $flashVars Includes additional "Filename" variable posted by Flash
  * @return object
  */
 public static function getHttpUploadPostParams($bucket, $uriPrefix = '', $acl = self::ACL_PRIVATE, $lifetime = 3600, $maxFileSize = 5242880, $successRedirect = "201", $amzHeaders = array(), $headers = array(), $flashVars = false)
 {
     // Create policy object
     $policy = new stdClass();
     $policy->expiration = gmdate('Y-m-d\\TH:i:s\\Z', time() + $lifetime);
     $policy->conditions = array();
     $obj = new stdClass();
     $obj->bucket = $bucket;
     array_push($policy->conditions, $obj);
     $obj = new stdClass();
     $obj->acl = $acl;
     array_push($policy->conditions, $obj);
     $obj = new stdClass();
     // 200 for non-redirect uploads
     if (is_numeric($successRedirect) && in_array((int) $successRedirect, array(200, 201))) {
         $obj->success_action_status = (string) $successRedirect;
     } else {
         // URL
         $obj->success_action_redirect = $successRedirect;
     }
     array_push($policy->conditions, $obj);
     if ($acl !== self::ACL_PUBLIC_READ) {
         array_push($policy->conditions, array('eq', '$acl', $acl));
     }
     array_push($policy->conditions, array('starts-with', '$key', $uriPrefix));
     if ($flashVars) {
         array_push($policy->conditions, array('starts-with', '$Filename', ''));
     }
     foreach (array_keys($headers) as $headerKey) {
         array_push($policy->conditions, array('starts-with', '$' . $headerKey, ''));
     }
     foreach ($amzHeaders as $headerKey => $headerVal) {
         $obj = new stdClass();
         $obj->{$headerKey} = (string) $headerVal;
         array_push($policy->conditions, $obj);
     }
     array_push($policy->conditions, array('content-length-range', 0, $maxFileSize));
     $policy = base64_encode(str_replace('\\/', '/', Assets_helper::get_json($policy)));
     // Create parameters
     $params = new stdClass();
     $params->AWSAccessKeyId = self::$__accessKey;
     $params->key = $uriPrefix . '${filename}';
     $params->acl = $acl;
     $params->policy = $policy;
     unset($policy);
     $params->signature = self::__getHash($params->policy);
     if (is_numeric($successRedirect) && in_array((int) $successRedirect, array(200, 201))) {
         $params->success_action_status = (string) $successRedirect;
     } else {
         $params->success_action_redirect = $successRedirect;
     }
     foreach ($headers as $headerKey => $headerVal) {
         $params->{$headerKey} = (string) $headerVal;
     }
     foreach ($amzHeaders as $headerKey => $headerVal) {
         $params->{$headerKey} = (string) $headerVal;
     }
     return $params;
 }
Beispiel #12
0
 /**
  * Returns a local copy of the file
  *
  * @return mixed
  */
 public function get_local_copy()
 {
     $location = Assets_helper::get_temp_file();
     copy($this->server_path, $location);
     clearstatcache();
     return $location;
 }
Beispiel #13
0
 /**
  * Replace Size
  */
 function replace_size($data, $params)
 {
     $this->_apply_params($data, $params);
     if (!$data) {
         return;
     }
     $size = $data[0]->size();
     if (isset($params['unformatted']) && $params['unformatted'] == "yes") {
         return $size;
     }
     $size = Assets_helper::format_filesize($size);
     return $size == '2 GB' ? '> 2 GB' : $size;
 }
Beispiel #14
0
 /**
  * Settings page
  */
 function settings()
 {
     if ($this->EE->session->userdata['group_id'] != 1) {
         $this->_forbidden();
     }
     $this->_set_page_title(lang('settings'));
     $vars['base'] = $this->base;
     $vars['settings'] = Assets_helper::get_global_settings();
     $this->EE->load->library('table');
     return $this->EE->load->view('mcp/settings', $vars, TRUE);
 }
Beispiel #15
0
 /**
  * Applies filedir overrides from config.php file.
  * @param $filedir
  * @return mixed
  */
 public static function apply_filedir_overrides($filedir)
 {
     static $overrides = null;
     if (is_null($overrides)) {
         $overrides = get_instance()->config->item('upload_preferences');
     }
     if (isset($overrides[$filedir->id])) {
         foreach ($overrides[$filedir->id] as $property => $value) {
             $filedir->{$property} = $value;
         }
     }
     $filedir->server_path = rtrim(Assets_helper::normalize_path($filedir->server_path), '/') . '/';
     return $filedir;
 }
Beispiel #16
0
 /**
  * Create EE thumbnails.
  *
  * @param $image_path
  * @param $upload_folder_id
  * @return mixed
  */
 public static function create_ee_thumbnails($image_path, $upload_folder_id)
 {
     if (!class_exists('Assets_ee_source')) {
         require_once PATH_THIRD . 'assets/sources/ee/source.ee.php';
     }
     $preferences = self::_get_EE()->filemanager->fetch_upload_dir_prefs($upload_folder_id);
     $preferences['file_name'] = pathinfo($image_path, PATHINFO_BASENAME);
     $preferences['server_path'] = Assets_ee_source::resolve_server_path(Assets_helper::normalize_path($preferences['server_path']));
     // Trick Filemanager into creating the thumbnail where WE need it
     $preferences['server_path'] .= str_replace($preferences['server_path'], '', str_replace(pathinfo($image_path, PATHINFO_BASENAME), '', $image_path));
     // On Windows machines CI's Image_lib gets all sorts of confused, so have to make sure our paths use the DIRECTORY_SEPARATOR separator
     if (DIRECTORY_SEPARATOR === "\\") {
         $preferences['server_path'] = str_replace('/', '\\', $preferences['server_path']);
         $image_path = str_replace('/', '\\', $image_path);
     }
     return self::_get_EE()->filemanager->create_thumb($image_path, $preferences);
 }
Beispiel #17
0
 /**
  * Return the path to the thumbnail
  *
  * @param $size
  * @return string
  */
 public function get_thumb_path($size)
 {
     $path = Assets_helper::ensure_cache_path('assets/thumbs/' . $this->file_id);
     return $path . $this->file_id . '_' . $size . '.' . $this->extension();
 }
Beispiel #18
0
<h2><?php 
echo $file->filename();
?>
</h2>

<form class="assets-filedata">
	<table cellspacing="0" cellpadding="0" border="0">
		<tr class="assets-fileinfo">
			<th scope="row"><?php 
echo lang('size');
?>
</th>
			<td><?php 
echo Assets_helper::format_filesize($file->size());
?>
</td>
		</tr>
		<tr class="assets-fileinfo">
			<th scope="row"><?php 
echo lang('kind');
?>
</th>
			<td><?php 
echo ucfirst(lang($file->kind()));
?>
</td>
		</tr>
	<?php 
if ($file->kind() == 'image') {
    ?>
		<tr class="assets-fileinfo">
 /**
  * Load the folder structure for data migration
  *
  * @param $path
  * @param $folder_structure
  */
 private function _load_folder_structure($path, &$folder_structure)
 {
     // starting with underscore or dot gets ignored
     $list = glob($path . '[!_.]*', GLOB_MARK);
     if (is_array($list) && count($list) > 0) {
         foreach ($list as $item) {
             // parse folders and add files
             $item = Assets_helper::normalize_path($item);
             if (substr($item, -1) == '/') {
                 // add with dropped slash and parse
                 $folder_structure[] = substr($item, 0, -1);
                 $this->_load_folder_structure($item, $folder_structure);
             }
         }
     }
 }
Beispiel #20
0
		<?php 
    }
    ?>

		<?php 
    if (in_array('date', $cols)) {
        ?>
			<td class="assets-lv-date"><?php 
        echo Assets_helper::format_date($file->date());
        ?>
</td>
		<?php 
    }
    ?>

		<?php 
    if (in_array('size', $cols)) {
        ?>
			<td class="assets-lv-size"><?php 
        echo Assets_helper::format_filesize($file->size());
        ?>
</td>
		<?php 
    }
    ?>
	</tr>
<?php 
}
if ($thumbs) {
    Assets_helper::queue_thumb_css($thumbs, FALSE);
}
Beispiel #21
0
 /**
  * Return true if a file path is allowed according to settings.
  *
  * @param $path
  * @return bool
  */
 protected function _is_allowed_file_path($path)
 {
     $filename = pathinfo($path, PATHINFO_BASENAME);
     $path_to = pathinfo($path, PATHINFO_DIRNAME);
     // Check if folder is allowed
     if (!empty($path_to) && $path_to != '.' && !$this->_is_allowed_folder_path($path_to)) {
         return FALSE;
     }
     return Assets_helper::is_allowed_file_name($filename);
 }
Beispiel #22
0
    echo $thumb_html;
    ?>
		<?php 
    if ($show_filenames) {
        ?>
			<div class="assets-tv-filename"><?php 
        echo $file->filename();
        ?>
</div>
		<?php 
    }
    ?>
		<?php 
    if ($field_name) {
        ?>
			<input type="hidden" name="<?php 
        echo $field_name;
        ?>
[]" value="<?php 
        echo $file->file_id();
        ?>
" />
		<?php 
    }
    ?>
	</li>
<?php 
}
if ($thumbs) {
    Assets_helper::queue_thumb_css($thumbs, !empty($field_name));
}