Example #1
0
}
/**
 * @var FileType
 */
global $edited_Filetype;
global $force_upload_forbiddenext;
global $rsc_path;
// Determine if we are creating or updating...
global $action;
$creating = is_create_action($action);
$Form = new Form(NULL, 'ftyp_checkchanges', 'post', 'compact');
$Form->global_icon(T_('Delete this filetype!'), 'delete', regenerate_url('action', 'action=delete'));
$Form->global_icon(T_('Cancel editing!'), 'close', regenerate_url('action'));
$Form->begin_form('fform', $creating ? T_('New file type') : T_('File type'));
$Form->add_crumb('filetype');
$Form->hidden_ctrl();
$Form->hidden('action', $creating ? 'create' : 'update');
if (!$creating) {
    $Form->hidden('ftyp_ID', $edited_Filetype->ID);
}
$Form->text_input('ftyp_extensions', $edited_Filetype->extensions, 40, T_('Extensions'), '', array('maxlength' => 30, 'required' => true, 'note' => sprintf('E.g. «%s»' . ', ' . T_('separated by whitespace'), 'html')));
$Form->text_input('ftyp_name', $edited_Filetype->name, 40, T_('File type name'), sprintf('E.g. «%s»', 'HTML file'), array('maxlength' => 30, 'required' => true));
$Form->text_input('ftyp_mimetype', $edited_Filetype->mimetype, 40, T_('Mime type'), sprintf('E.g. «%s»', 'text/html'), array('maxlength' => 50, 'required' => true));
$Form->select_input_array('ftyp_icon', $edited_Filetype->icon, get_available_filetype_icons(), T_('Icon'));
$Form->radio('ftyp_viewtype', $edited_Filetype->viewtype, array(array('browser', T_('Open with browser (popup)'), T_('Let the browser handle the file in a popup.')), array('text', T_('Open with text viewer (popup)'), T_('Use the online text viewer (recommended for .txt)')), array('image', T_('Open with image viewer (popup)'), T_('Use the online image viewer (recommended for .gif .png .jpg)')), array('external', T_('Open with external app (no popup)'), T_('Let the browser handle the file in a popup. Note: if you do not want Word to open inside of IE, you must uncheck "browse in same window" in Windows\' file types.')), array('download', T_('Download to disk (no popup)'), T_('Tell the browser to save the file to disk instead of displaying it.'))), T_('View type'), true);
// Check if the extension is in the array of the not allowed upload extensions from _advanced.php
$not_allowed = false;
$extensions = explode(' ', $edited_Filetype->extensions);
foreach ($extensions as $extension) {
    if (in_array($extension, $force_upload_forbiddenext)) {
        $not_allowed = true;
Example #2
0
 /**
  * Event handler: Called when displaying the block in the "Tools" menu.
  *
  * @see Plugin::AdminToolPayload()
  */
 function AdminToolPayload($params)
 {
     $Form = new Form();
     $Form->begin_form('fform');
     $Form->add_crumb('tools');
     $Form->hidden_ctrl();
     // needed to pass the "ctrl=tools" param
     $Form->hiddens_by_key(get_memorized());
     // needed to pass all other memorized params, especially "tab"
     $Form->hidden('action', 'geoip_find_country');
     echo '<p>' . T_('This tool finds all users that do not have a registration country yet and then assigns them a registration country based on their registration IP.') . '</p>';
     $Form->button(array('value' => T_('Find Registration Country for all Users NOW!')));
     if (!empty($this->text_from_AdminTabAction)) {
         // Display a report of executed action
         echo '<p><b>' . T_('Report') . ':</b></p>';
         echo $this->text_from_AdminTabAction;
     }
     $Form->end_form();
 }
Example #3
0
 /**
  * Event handler: Gets invoked when our tab is selected and should get displayed.
  *
  * @see Plugin::AdminTabPayload()
  */
 function AdminTabPayload()
 {
     echo 'Hello, this is the AdminTabPayload for the TEST plugin.';
     echo $this->text_from_AdminTabAction;
     // TODO: this is tedious.. should either be a global function (get_admin_Form()) or a plugin helper..
     $Form = new Form();
     $Form->begin_form();
     $Form->add_crumb('plugin_test');
     $Form->hidden_ctrl();
     // needed to pass the "ctrl=tools" param
     $Form->hiddens_by_key(get_memorized());
     // needed to pass all other memorized params, especially "tab"
     $Form->text_input($this->get_class_id() . '_text', $this->param_text, '20', 'Text');
     $Form->button_input();
     // default "submit" button
     $Form->end_form();
 }
Example #4
0
 /**
  * Event handler: Called when displaying the block in the "Tools" menu.
  *
  * @see Plugin::AdminToolPayload()
  */
 function AdminToolPayload($params)
 {
     $action = param_action();
     echo '<a name="geoip" style="position:relative;top:-60px"></a>';
     switch ($action) {
         case 'geoip_download':
             // Display a process of downloading of GeoIP.dat
             global $admin_url;
             $this->print_tool_log(sprintf(T_('Downloading GeoIP.dat file from the url: %s ...'), '<a href="' . $this->geoip_download_url . '" target="_blank">' . $this->geoip_download_url . '</a>'));
             // DOWNLOAD:
             $gzip_contents = fetch_remote_page($this->geoip_download_url, $info, 1800);
             if ($gzip_contents === false || $info['status'] != 200) {
                 // Downloading is Failed
                 if (empty($info['error'])) {
                     // Some unknown error
                     $this->print_tool_log(T_('The URL is not available. It may correspond to an old version of the GeoIP.dat file.'), 'error');
                 } else {
                     // Display an error of request
                     $this->print_tool_log(T_($info['error']), 'error');
                 }
                 break;
             }
             $this->print_tool_log(' OK.<br />');
             $plugin_dir = dirname(__FILE__);
             if (!is_writable($plugin_dir)) {
                 // Check the write rights
                 $this->print_tool_log(sprintf(T_('Plugin folder %s must be writable to receive GeoIP.dat. Please fix the write permissions and try again.'), '<b>' . $plugin_dir . '</b>'), 'error');
                 break;
             }
             $gzip_file_name = explode('/', $this->geoip_download_url);
             $gzip_file_name = $gzip_file_name[count($gzip_file_name) - 1];
             $gzip_file_path = $plugin_dir . '/' . $gzip_file_name;
             if (!save_to_file($gzip_contents, $gzip_file_path, 'w')) {
                 // Impossible to save file...
                 $this->print_tool_log(sprintf(T_('Unable to create file: %s'), '<b>' . $gzip_file_path . '</b>'), 'error');
                 if (file_exists($gzip_file_path)) {
                     // Remove file from disk
                     if (!@unlink($gzip_file_path)) {
                         // File exists without the write rights
                         $this->print_tool_log(sprintf(T_('Unable to remove file: %s'), '<b>' . $gzip_file_path . '</b>'), 'error');
                     }
                 }
                 break;
             }
             // UNPACK:
             $this->print_tool_log(sprintf(T_('Extracting of the file %s...'), '<b>' . $gzip_file_path . '</b>'));
             if (!function_exists('gzopen')) {
                 // No extension
                 $this->print_tool_log(T_('There is no \'zip\' or \'zlib\' extension installed!'), 'error');
                 break;
             }
             if (!($gzip_handle = @gzopen($gzip_file_path, 'rb'))) {
                 // Try to open gzip file
                 $this->print_tool_log(T_('Could not open the source file!'), 'error');
                 break;
             }
             if (!($out_handle = @fopen($plugin_dir . '/' . str_replace('.gz', '', $gzip_file_name), 'w'))) {
                 $this->print_tool_log(sprintf(T_('The file %s cannot be written to disk. Please check the filesystem permissions.'), '<b>' . $plugin_dir . '/' . str_replace('.gz', '', $gzip_file_name) . '</b>'), 'error');
                 break;
             }
             $i = 0;
             while (!gzeof($gzip_handle)) {
                 // Extract file by 4Kb
                 fwrite($out_handle, gzread($gzip_handle, 4096));
                 if ($i == 100) {
                     // Display the process dots after each 400Kb
                     $this->print_tool_log(' .');
                     $i = 0;
                 }
                 $i++;
             }
             $this->print_tool_log(' OK.<br />');
             fclose($out_handle);
             gzclose($gzip_handle);
             $this->print_tool_log(sprintf(T_('Remove gzip file %s...'), '<b>' . $gzip_file_path . '</b>'));
             if (@unlink($gzip_file_path)) {
                 $this->print_tool_log(' OK.<br />');
             } else {
                 // Failed on removing
                 $this->print_tool_log(sprintf(T_('Impossible to remove the file %s. You can do it manually.'), $gzip_file_path), 'warning');
             }
             // Success message
             $this->print_tool_log('<br /><span class="text-success">' . sprintf(T_('%s file was downloaded successfully.'), 'GeoIP.dat') . '</span>');
             // Try to enable plugin automatically:
             global $Plugins;
             $enable_return = $this->BeforeEnable();
             if ($enable_return === true) {
                 // Success enabling
                 $this->print_tool_log('<br /><span class="text-success">' . T_('The plugin has been enabled.') . '</span>');
                 if ($this->status != 'enabled') {
                     // Enable this plugin automatically:
                     $Plugins->set_Plugin_status($this, 'enabled');
                 }
             } else {
                 // Some restriction for enabling
                 $this->print_tool_log('<br /><span class="text-warning">' . T_('The plugin could not be automatically enabled.') . '</span>');
                 if ($this->status != 'needs_config') {
                     // Make this plugin incomplete because it cannot be enabled:
                     $Plugins->set_Plugin_status($this, 'needs_config');
                 }
             }
             break;
         default:
             // Display a form to find countries for users
             if ($this->status != 'enabled') {
                 // Don't allow use this tool when GeoIP plugin is not enabled
                 echo '<p class="error">' . T_('You must enable the GeoIP plugin before to use this tool.') . '</p>';
                 break;
             }
             $Form = new Form();
             $Form->begin_form('fform');
             $Form->add_crumb('tools');
             $Form->hidden_ctrl();
             // needed to pass the "ctrl=tools" param
             $Form->hiddens_by_key(get_memorized());
             // needed to pass all other memorized params, especially "tab"
             $Form->hidden('action', 'geoip_find_country');
             echo '<p>' . T_('This tool finds all users that do not have a registration country yet and then assigns them a registration country based on their registration IP.') . get_manual_link('geoip-plugin') . '</p>';
             $Form->button(array('value' => T_('Find Registration Country for all Users NOW!')));
             if (!empty($this->text_from_AdminTabAction)) {
                 // Display a report of executed action
                 echo '<p><b>' . T_('Report') . ':</b></p>';
                 echo $this->text_from_AdminTabAction;
             }
             $Form->end_form();
             break;
     }
 }