本文整理汇总了PHP中FormUI::media_panel方法的典型用法代码示例。如果您正苦于以下问题:PHP FormUI::media_panel方法的具体用法?PHP FormUI::media_panel怎么用?PHP FormUI::media_panel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormUI
的用法示例。
在下文中一共展示了FormUI::media_panel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter_media_panels
/**
* Provide requested media panels for this plugin
*
* Regarding Uploading:
* A panel is returned to the media bar that contains a form, an iframe, and a javascript function.
* The form allows the user to select a file, and is submitted back to the same URL that produced this panel in the first place.
* This has the result of submitting the uploaded file to here when the form is submitted.
* To prevent the panel form from reloading the whole publishing page, the form is submitted into the iframe.
* An onload event attached to the iframe calls the function.
* The function accesses the content of the iframe when it loads, which should contain the results of the request to obtain this panel, which are in JSON format.
* The JSON data is passed to the habari.media.jsonpanel() function in media.js to process the data and display the results, just like when displaying a panel normally.
*
* @param string $panel The HTML content of the panel to be output in the media bar
* @param MediaSilo $silo The silo for which the panel was requested
* @param string $path The path within the silo (silo root omitted) for which the panel was requested
* @param string $panelname The name of the requested panel
* @return string The modified $panel to contain the HTML output for the requested panel
*
* @todo Move the uploaded file from the temporary location to the location indicated by the path field.
*/
public function filter_media_panels($panel, $silo, $path, $panelname)
{
$class = __CLASS__;
if ($silo instanceof $class) {
switch ($panelname) {
case 'mkdir':
$fullpath = self::SILO_NAME . '/' . $path;
$form = new FormUI('habarisilomkdir');
$form->append('static', 'ParentDirectory', '<div style="margin: 10px auto;">' . _t('Parent Directory:') . " <strong>/{$path}</strong></div>");
// add the parent directory as a hidden input for later validation
$form->append('hidden', 'path', 'null:unused')->value = $path;
$form->append('hidden', 'action', 'null:unused')->value = $panelname;
$dir_text_control = $form->append('text', 'directory', 'null:unused', _t('What would you like to call the new directory?'));
$dir_text_control->add_validator(array($this, 'mkdir_validator'));
$form->append('submit', 'submit', _t('Submit'));
$form->media_panel($fullpath, $panelname, 'habari.media.forceReload();');
$form->on_success(array($this, 'dir_success'));
$panel = $form->get();
/* form submission magicallly happens here */
return $panel;
break;
case 'rmdir':
$fullpath = self::SILO_NAME . '/' . $path;
$form = new FormUI('habarisilormdir');
$form->append('static', 'RmDirectory', '<div style="margin: 10px auto;">' . _t('Directory:') . " <strong>/{$path}</strong></div>");
// add the parent directory as a hidden input for later validation
$form->append('hidden', 'path', 'null:unused')->value = $path;
$form->append('hidden', 'action', 'null:unused')->value = $panelname;
$dir_text_control = $form->append('static', 'directory', _t('Are you sure you want to delete this directory?'));
$form->append('submit', 'submit', _t('Delete'));
$form->media_panel($fullpath, $panelname, 'habari.media.forceReload();');
$form->on_success(array($this, 'dir_success'));
$panel = $form->get();
/* form submission magicallly happens here */
return $panel;
break;
case 'delete':
$fullpath = self::SILO_NAME . '/' . $path;
$form = new FormUI('habarisilodelete');
$form->append('static', 'RmFile', '<div style="margin: 10px auto;">' . _t('File:') . " <strong>/{$path}</strong></div>");
// add the parent directory as a hidden input for later validation
$form->append('hidden', 'path', 'null:unused')->value = $path;
$dir_text_control = $form->append('static', 'directory', '<p>' . _t('Are you sure you want to delete this file?') . '</p>');
$form->append('submit', 'submit', _t('Delete'));
$form->media_panel($fullpath, $panelname, 'habari.media.forceReload();');
$form->on_success(array($this, 'do_delete'));
$panel = $form->get();
return $panel;
break;
case 'upload':
if (isset($_FILES['file'])) {
if (isset($_POST['token']) && isset($_POST['token_ts']) && self::verify_token($_POST['token'], $_POST['token_ts'])) {
$size = Utils::human_size($_FILES['file']['size']);
$panel .= '<div class="span-18" style="padding-top:30px;color: #e0e0e0;margin: 0px auto;"><p>' . _t('File: ') . $_FILES['file']['name'];
$panel .= $_FILES['file']['size'] > 0 ? "({$size})" : '';
$panel .= '</p>';
$path = self::SILO_NAME . '/' . preg_replace('%\\.{2,}%', '.', $path) . '/' . $_FILES['file']['name'];
$asset = new MediaAsset($path, false);
$asset->upload($_FILES['file']);
if ($asset->put()) {
$msg = _t('File uploaded: %s', array($_FILES['file']['name']));
$panel .= '<p>' . $msg . '</p>';
EventLog::log($msg, 'info');
} else {
$upload_errors = array(1 => _t('The uploaded file exceeds the upload_max_filesize directive in php.ini.'), 2 => _t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'), 3 => _t('The uploaded file was only partially uploaded.'), 4 => _t('No file was uploaded.'), 6 => _t('Missing a temporary folder.'), 7 => _t('Failed to write file to disk.'), 8 => _t('A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help.'));
$msg = _t('File upload failed: %s', array($_FILES['file']['name']));
$panel .= '<p>' . $msg . '</p>';
$panel .= '<p><strong>' . $upload_errors[$_FILES['file']['error']] . '</strong></p>';
EventLog::log($msg . ' ' . $upload_errors[$_FILES['file']['error']], 'err');
}
$panel .= '<p><a href="#" onclick="habari.media.forceReload();habari.media.showdir(\'' . dirname($path) . '\');">' . _t('Browse the current silo path.') . '</a></p></div>';
} else {
$panel .= '<p><strong>' . _t('Suspicious behaviour or too much time has elapsed. Please upload your file again.') . '</strong></p>';
}
} else {
$token_ts = time();
$token = self::create_token($token_ts);
$fullpath = self::SILO_NAME . '/' . $path;
$form_action = URL::get('admin_ajax', array('context' => 'media_upload'));
$panel .= <<<UPLOAD_FORM
//.........这里部分代码省略.........
示例2: filter_media_panels
/**
* Provide requested media panels for this plugin
*
* Regarding Uploading:
* A panel is returned to the media bar that contains a form, an iframe, and a javascript function.
* The form allows the user to select a file, and is submitted back to the same URL that produced this panel in the first place.
* This has the result of submitting the uploaded file to here when the form is submitted.
* To prevent the panel form from reloading the whole publishing page, the form is submitted into the iframe.
* An onload event attached to the iframe calls the function.
* The function accesses the content of the iframe when it loads, which should contain the results of the request to obtain this panel, which are in JSON format.
* The JSON data is passed to the habari.media.jsonpanel() function in media.js to process the data and display the results, just like when displaying a panel normally.
*
* @param string $panel The HTML content of the panel to be output in the media bar
* @param MediaSilo $silo The silo for which the panel was requested
* @param string $path The path within the silo (silo root omitted) for which the panel was requested
* @param string $panelname The name of the requested panel
* @return string The modified $panel to contain the HTML output for the requested panel
*
* @todo Move the uploaded file from the temporary location to the location indicated by the path field.
*/
public function filter_media_panels( $panel, $silo, $path, $panelname)
{
$class = __CLASS__;
if ( $silo instanceof $class ) {
switch ( $panelname ) {
case 'mkdir':
$fullpath = self::SILO_NAME . '/' . $path;
$form = new FormUI( 'habarisilomkdir' );
$form->append( 'static', 'ParentDirectory', '<div style="margin: 10px auto;">' . _t('Parent Directory:') . " <strong>/{$path}</strong></div>" );
// add the parent directory as a hidden input for later validation
$form->append( 'hidden', 'path', 'null:unused' )->value = $path;
$form->append( 'hidden', 'action', 'null:unused')->value = $panelname;
$dir_text_control = $form->append( 'text', 'directory', 'null:unused', _t('What would you like to call the new directory?') );
$dir_text_control->add_validator( array( $this, 'mkdir_validator' ) );
$form->append( 'submit', 'submit', _t('Submit') );
$form->media_panel($fullpath, $panelname, 'habari.media.forceReload();');
$form->on_success( array( $this, 'dir_success' ) );
$panel = $form->get(); /* form submission magicallly happens here */
return $panel;
break;
case 'rmdir':
$fullpath = self::SILO_NAME . '/' . $path;
$form = new FormUI( 'habarisilormdir' );
$form->append( 'static', 'RmDirectory', '<div style="margin: 10px auto;">' . _t('Directory:') . " <strong>/{$path}</strong></div>" );
// add the parent directory as a hidden input for later validation
$form->append( 'hidden', 'path', 'null:unused' )->value = $path;
$form->append( 'hidden', 'action', 'null:unused')->value = $panelname;
$dir_text_control = $form->append( 'static', 'directory', _t('Are you sure you want to delete this directory?') );
$form->append( 'submit', 'submit', _t('Delete') );
$form->media_panel($fullpath, $panelname, 'habari.media.forceReload();');
$form->on_success( array( $this, 'dir_success' ) );
$panel = $form->get(); /* form submission magicallly happens here */
return $panel;
break;
case 'delete':
$fullpath = self::SILO_NAME . '/' . $path;
$form = new FormUI( 'habarisilodelete' );
$form->append( 'static', 'RmFile', '<div style="margin: 10px auto;">' . _t('File:') . " <strong>/{$path}</strong></div>" );
// add the parent directory as a hidden input for later validation
$form->append( 'hidden', 'path', 'null:unused' )->value = $path;
$dir_text_control = $form->append( 'static', 'directory', '<p>' . _t('Are you sure you want to delete this file?') . '</p>');
$form->append( 'submit', 'submit', _t('Delete') );
$form->media_panel($fullpath, $panelname, 'habari.media.forceReload();');
$form->on_success( array( $this, 'do_delete' ) );
$panel = $form->get();
return $panel;
break;
case 'upload':
if ( isset( $_FILES['file'] ) ) {
$size = Utils::human_size($_FILES['file']['size']);
$panel .= "<div class=\"span-18\" style=\"padding-top:30px;color: #e0e0e0;margin: 0px auto;\"><p>" . _t( "File Uploaded: " ) . "{$_FILES['file']['name']} ($size)</p>";
$path = self::SILO_NAME . '/' . preg_replace('%\.{2,}%', '.', $path). '/' . $_FILES['file']['name'];
$asset = new MediaAsset($path, false);
$asset->upload( $_FILES['file'] );
if ( $asset->put() ) {
$panel .= '<p>' . _t( 'File added successfully.' ) . '</p>';
}
else {
$panel .= '<p>' . _t( 'File could not be added to the silo.' ) . '</p>';
}
$panel .= '<p><a href="#" onclick="habari.media.forceReload();habari.media.showdir(\'' . dirname($path) . '\');">' . _t( 'Browse the current silo path.' ) . '</a></p></div>';
}
else {
$fullpath = self::SILO_NAME . '/' . $path;
//.........这里部分代码省略.........
示例3: filter_media_panels
/**
* Display the different media panels
*
* @param string $panel HTML content to be output
* @param object $silo Silo object
* @param string $path Current silo path
* @param string $panelname Curren panel name
* @return string The modified panel output
*/
public function filter_media_panels($panel, $silo, $path, $panelname)
{
$class = __CLASS__;
if ($silo instanceof $class) {
switch ($panelname) {
case 'new-album':
$fullpath = self::SILO_NAME . '/' . $path;
$form = new FormUI('picasasilo-newalbum');
$today = date('d/m/Y', time());
// first column
$form->append('static', 'col1', '<div class="column">');
$form->append('text', 'album_name', 'null:unused', 'Album name');
$form->append('textarea', 'album_summary', 'null:unused', 'Summary');
$form->append('text', 'album_date', 'null:unused', 'Date');
$form->album_date->value = $today;
$form->append('static', 'col2', '</div>');
// second column
$form->append('static', 'col3', '<div class="column">');
$form->append('text', 'album_location', 'null:unused', 'Location');
$form->append('select', 'album_visibility', 'null:unused', 'Visibility');
$form->album_visibility->options = array('public' => 'Public', 'private' => 'Anyone with the link', 'protected' => 'Private');
$form->append('static', 'col4', '</div>');
// clear columns
$form->append('static', 'colend', '<br style="clear: both">');
$form->append('submit', 'create-album', 'Create');
$form->media_panel($fullpath, $panelname, 'habari.media.forceReload();');
$form->on_success(array($this, 'create_album'));
$panel = $form->get();
return $panel;
break;
case 'upload':
if (isset($_FILES['upload_file'])) {
$panel = $this->upload_photo();
} else {
$fullpath = self::SILO_NAME . '/' . $path;
$action = URL::get('admin_ajax', array('context' => 'media_panel'));
$picasa = new Picasa();
// collect album names
$xml = $picasa->get_albums();
foreach ($xml->channel->item as $album) {
$title = (string) $album->title;
$options .= "<option value='" . $title . "'>" . $title . "</option>";
}
// create a form that sends the request to an IFrame (as done in the Habari Silo)
$static = <<<PICASA_UPLOAD
\t\t\t\t\t\t<form enctype="multipart/form-data" method="post" id="picasasilo-upload" target="picasa_upload_frame" action="{$action}" class="span-10" style="margin:0px auto;" target="picasa_upload_frame">
\t\t\t\t\t\t <div class="formcontrol"><input type="file" name="upload_file"></div>
\t\t\t\t\t\t<div class="formcontrol">
\t\t\t\t\t\t\t\t<label for="upload">Album:</label>
\t\t\t\t\t\t\t\t<select name="upload_album">{$options}</select>
\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t<div class="formcontrol">
\t\t\t\t\t\t\t\t<label for="summary">Summary:</label>
\t\t\t\t\t\t\t\t<textarea name="summary"></textarea>
\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t <div class="formcontrol"><input type="submit" name="upload" value="Upload"></div>
\t\t\t\t\t\t <input type="hidden" name="path" value="{$fullpath}">
\t\t\t\t\t\t <input type="hidden" name="panel" value="{$panelname}">
\t\t\t\t\t\t
</form>
\t\t\t\t\t\t<iframe id="picasa_upload_frame" name="picasa_upload_frame" style="width:1px;height:1px;" onload="picasa_uploaded();">
\t\t\t\t\t\t</iframe>
\t\t\t\t\t\t<script type="text/javascript">
\t\t\t\t\t\t\t\tvar responsedata;
\t\t\t\t\t function picasa_uploaded()
\t\t\t\t\t\t\t\t{
\t\t\t\t\t\t\t\t\tif(!jQuery('#picasa_upload_frame')[0].contentWindow)return;
\t\t\t\t\t\t\t\t\tvar response = jQuery(jQuery('#picasa_upload_frame')[0].contentWindow.document.body).text();
\t\t\t\t\t\t\t\t\tif(response)
\t\t\t\t\t\t\t\t\t{
\t\t\t\t\t\t\t\t\t\teval('responsedata = ' + response);
\t\t\t\t\t\t\t\t\t\twindow.setTimeout(picasa_uploaded_complete, 500);
\t\t\t\t\t\t\t\t\t}
\t\t\t\t\t\t\t\t}
\t\t\t\t\t\t\t\tfunction picasa_uploaded_complete()
\t\t\t\t\t\t\t\t{
\t\t\t\t\t\t\t\t\thabari.media.jsonpanel(responsedata);
\t\t\t\t\t\t\t\t}
\t\t\t\t\t\t</script>
PICASA_UPLOAD;
$panel = $static;
}
return $panel;
break;
}
}
}