/** * Display Grid Cell */ function grid_display_field($data) { // include the resources Assets_helper::include_sheet_resources(); if (!isset($this->cache['included_grid_resources'])) { Assets_helper::include_js('grid.js'); $this->cache['included_grid_resources'] = TRUE; } return $this->_build_field($data, 'grid'); }
/** * 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']; }
/** * 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()'); } }
/** * 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); }