/**
	 * 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;
						$form_action = URL::get('admin_ajax', array('context' => 'media_panel'));
						$panel .= <<< UPLOAD_FORM
<form enctype="multipart/form-data" method="post" id="simple_upload" target="simple_upload_frame" action="{$form_action}" class="span-10" style="margin:0px auto;text-align: center">
	<p style="padding-top:30px;">%s <b style="font-weight:normal;color: #e0e0e0;font-size: 1.2em;">/{$path}</b></p>
	<p><input type="file" name="file"><input type="submit" name="upload" value="%s">
	<input type="hidden" name="path" value="{$fullpath}">
	<input type="hidden" name="panel" value="{$panelname}">
	</p>
</form>
<iframe id="simple_upload_frame" name="simple_upload_frame" style="width:1px;height:1px;" onload="simple_uploaded();"></iframe>
<script type="text/javascript">
var responsedata;
function simple_uploaded() {
	if (!$('#simple_upload_frame')[0].contentWindow) return;
	var response = $($('#simple_upload_frame')[0].contentWindow.document.body).text();
	if (response) {
		eval('responsedata = ' + response);
		window.setTimeout(simple_uploaded_complete, 500);
	}
}
function simple_uploaded_complete() {
	habari.media.jsonpanel(responsedata);
}
</script>
UPLOAD_FORM;

					$panel = sprintf( $panel, _t( "Upload to:" ), _t( "Upload" ) );
				}
			}
		}
		return $panel;
	}
Ejemplo n.º 2
0
    /**
     * Provide requested media panels for this plugin
     *
     * @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 'record':
                    $user = User::identify()->info->viddler__username;
                    $pass = User::identify()->info->viddler__password;
                    $auth = $this->viddler->user_authenticate(array('user' => $user, 'password' => $pass, 'get_record_token' => 1, 'record_token' => 1));
                    $sid = new SimpleXMLElement($auth);
                    $rt = $sid->record_token;
                    $panel .= "<div class=\"span-18\" style=\"padding-top:30px;color: #e0e0e0;margin: 0px auto;\">";
                    $panel .= $this->viddler->video_getrecordembed($rt);
                    $panel .= '</div>';
                    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>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>File added successfully.</p>';
                        } else {
                            $panel .= '<p>File could not be added to the silo.</p>';
                        }
                        $panel .= '<p><a href="#" onclick="habari.media.forceReload();habari.media.showdir(\'' . dirname($path) . '\');">Browse the current silo path.</a></p></div>';
                    } else {
                        $fullpath = self::SILO_NAME . '/' . $path;
                        $form_action = URL::get('admin_ajax', array('context' => 'media_panel'));
                        $panel .= <<<UPLOAD_FORM
<form enctype="multipart/form-data" method="post" id="simple_upload" target="simple_upload_frame" action="{$form_action}" class="span-10" style="margin:0px auto;text-align: center">
\t<p style="padding-top:30px;">Upload to: <b style="font-weight:normal;color: #e0e0e0;font-size: 1.2em;">/{$path}</b></p>
\t<p><input type="file" name="file"><input type="submit" name="upload" value="Upload">
\t<input type="hidden" name="path" value="{$fullpath}">
\t<input type="hidden" name="panel" value="{$panelname}">
\t</p>
</form>
<iframe id="simple_upload_frame" name="simple_upload_frame" style="width:1px;height:1px;" onload="simple_uploaded();"></iframe>
<script type="text/javascript">
var responsedata;
function simple_uploaded() {
\tif(!\$('#simple_upload_frame')[0].contentWindow) return;
\tvar response = \$(\$('#simple_upload_frame')[0].contentWindow.document.body).text();
\tif(response) {
\t\teval('responsedata = ' + response);
\t\twindow.setTimeout(simple_uploaded_complete, 500);
\t}
}
function simple_uploaded_complete() {
\thabari.media.jsonpanel(responsedata);
}
</script>
UPLOAD_FORM;
                    }
            }
        }
        return $panel;
    }
Ejemplo n.º 3
0
    /**
     * 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
<form enctype="multipart/form-data" method="post" id="simple_upload" target="simple_upload_frame" action="{$form_action}" class="span-10" style="margin:0px auto;text-align: center">
\t<p style="padding-top:30px;">%s <b style="font-weight:normal;color: #e0e0e0;font-size: 1.2em;">/{$path}</b></p>
\t<p><input type="file" name="file"><input type="submit" name="upload" value="%s">
\t<input type="hidden" name="path" value="{$fullpath}">
\t<input type="hidden" name="panel" value="{$panelname}">
\t<input type="hidden" name="token" value="{$token}">
\t<input type="hidden" name="token_ts" value="{$token_ts}">
\t</p>
</form>
<iframe id="simple_upload_frame" name="simple_upload_frame" style="width:1px;height:1px;" onload="simple_uploaded();"></iframe>
<script type="text/javascript">
var responsedata;
function simple_uploaded() {
\tif (!\$('#simple_upload_frame')[0].contentWindow) return;
\tvar response = \$(\$('#simple_upload_frame')[0].contentWindow.document.body).text();
\tif (response) {
\t\teval('responsedata = ' + response);
\t\twindow.setTimeout(simple_uploaded_complete, 500);
\t}
}
function simple_uploaded_complete() {
\thabari.media.jsonpanel(responsedata.data);
}
</script>
UPLOAD_FORM;
                        $panel = sprintf($panel, _t("Upload to:"), _t("Upload"));
                    }
            }
        }
        return $panel;
    }