예제 #1
0
/**
 * Compose screen: display link files iframe
 *
 * @param object Form
 * @param object LinkOwner object
 * @param string iframe name
 * @param boolean true if creating new owner object, false otherwise
 * @param boolean true to allow folding for this fieldset, false otherwise
 */
function attachment_iframe(&$Form, &$LinkOwner, $iframe_name = NULL, $creating = false, $fold = false)
{
    global $admin_url;
    global $current_User, $action;
    if ($LinkOwner->type == 'item' && !$LinkOwner->Item->get_type_setting('allow_attachments')) {
        // Attachments are not allowed for current post type
        return;
    }
    if (!isset($GLOBALS['files_Module'])) {
        return;
    }
    // Set title for modal window:
    $window_title = TS_('Attach files');
    if ($LinkOwner->type == 'item') {
        // Item
        $window_title = format_to_js(sprintf(T_('Attach files to "%s"'), $LinkOwner->Item->get('title')));
    } elseif ($LinkOwner->type == 'comment') {
        // Comment
        $window_title = format_to_js(sprintf(T_('Attach files to comment #%s'), $LinkOwner->Comment->ID));
    }
    $fieldset_title = T_('Images & Attachments');
    if ($creating) {
        // Creating new Item
        $fieldset_title .= ' ' . get_manual_link('images-attachments-panel') . ' - <a id="title_file_add" href="#" class="action_icon">' . get_icon('folder') . ' ' . T_('Attach existing files') . '</a>';
        $Form->begin_fieldset($fieldset_title, array('id' => 'itemform_createlinks', 'fold' => $fold));
        $Form->submit(array('actionArray[create_edit]', T_('Save post to start uploading files'), 'SaveEditButton'));
        if (get_param('p') > 0) {
            // Display a button to duplicate the attachments to new item:
            $Form->submit(array('actionArray[create_link]', T_('Save & Link files from original'), 'SaveEditButton'));
        }
        $Form->end_fieldset();
        return;
    }
    // Editing link owner
    $Blog =& $LinkOwner->get_Blog();
    if ($iframe_name == NULL) {
        $iframe_name = 'attach_' . generate_random_key(16);
    }
    $fieldset_title .= ' ' . get_manual_link('images-attachments-panel') . ' - ' . action_icon(T_('Refresh'), 'refresh', $admin_url . '?ctrl=links&amp;action=edit_links&amp;link_type=' . $LinkOwner->type . '&amp;mode=iframe&amp;iframe_name=' . $iframe_name . '&amp;link_object_ID=' . $LinkOwner->get_ID(), T_('Refresh'), 3, 4, array('target' => $iframe_name));
    if ($current_User->check_perm('files', 'view', false, $Blog->ID) && $LinkOwner->check_perm('edit', false)) {
        // Check that we have permission to edit owner:
        $attach_files_url = $admin_url . '?ctrl=files&amp;fm_mode=link_object&amp;link_type=item&amp;link_object_ID=' . $LinkOwner->get_ID();
        if ($linkowner_FileList = $LinkOwner->get_attachment_FileList(1)) {
            // Get first file of the Link Owner:
            $linkowner_File =& $linkowner_FileList->get_next();
            if (!empty($linkowner_File) && $current_User->check_perm('files', 'view', false, $linkowner_File->get_FileRoot())) {
                // Obtain and use file root of first file:
                $linkowner_FileRoot =& $linkowner_File->get_FileRoot();
                $attach_files_url .= '&amp;root=' . $linkowner_FileRoot->ID;
                $attach_files_url .= '&amp;path=' . dirname($linkowner_File->get_rdfs_rel_path()) . '/';
            }
        }
        $fieldset_title .= ' - ' . action_icon(T_('Attach existing files'), 'folder', $attach_files_url, T_('Attach existing files'), 3, 4, array('onclick' => 'return link_attachment_window( \'' . $iframe_name . '\', \'' . $LinkOwner->type . '\', \'' . $LinkOwner->get_ID() . '\' )')) . action_icon(T_('Attach existing files'), 'permalink', $attach_files_url, T_('Attach existing files'), 1, 0, array('target' => '_blank'));
    }
    // Get a count of links in order to deny folding when there is at least one link
    $links_count = count($LinkOwner->get_Links());
    $Form->begin_fieldset($fieldset_title, array('id' => 'itemform_links', 'fold' => $fold, 'deny_fold' => $links_count > 0));
    echo '<div id="attachmentframe_wrapper">' . '<iframe src="' . $admin_url . '?ctrl=links&amp;link_type=' . $LinkOwner->type . '&amp;action=edit_links&amp;mode=iframe&amp;iframe_name=' . $iframe_name . '&amp;link_object_ID=' . $LinkOwner->get_ID() . '" name="' . $iframe_name . '"' . ' width="100%" marginwidth="0" height="100%" marginheight="0" align="top" scrolling="auto" frameborder="0" id="attachmentframe"></iframe>' . '</div>';
    $Form->end_fieldset();
    ?>
<script type="text/javascript">
<?php 
    // Initialize JavaScript to build and open window
    echo_modalwindow_js();
    ?>

function link_attachment_window( iframe_name, link_owner_type, link_owner_ID, root, path, fm_highlight )
{
	openModalWindow( '<span class="loader_img loader_user_report absolute_center" title="<?php 
    echo T_('Loading...');
    ?>
"></span>',
		'90%', '80%', true, '<?php 
    echo $window_title;
    ?>
', '', true );
	jQuery.ajax(
	{
		type: 'POST',
		url: '<?php 
    echo get_samedomain_htsrv_url();
    ?>
async.php',
		data:
		{
			'action': 'link_attachment',
			'iframe_name': iframe_name,
			'link_owner_type': link_owner_type,
			'link_owner_ID': link_owner_ID,
			'crumb_link': '<?php 
    echo get_crumb('link');
    ?>
',
			'root': typeof( root ) == 'undefined' ? '' : root,
			'path': typeof( path ) == 'undefined' ? '' : path,
			'fm_highlight': typeof( fm_highlight ) == 'undefined' ? '' : fm_highlight
		},
		success: function(result)
		{
			openModalWindow( result, '90%', '80%', true, '<?php 
    echo $window_title;
    ?>
', '' );
		}
	} );
	return false;
}

jQuery( document ).ready( function()
{
	function update_attachment_frame_height()
	{
		var body_height = jQuery( '#attachmentframe' ).contents().find( 'body' ).height();
		if( body_height == 0 )
		{ // Some browsers cannot get iframe body height correctly, Use this default min value:
			body_height = 91;
		}

		if( body_height > jQuery( '#attachmentframe_wrapper' ).height() )
		{ // Expand the frame height if it is more than wrapper height (but max height is 320px):
			jQuery( '#attachmentframe_wrapper' ).css( 'height', body_height < 320 ? body_height : 320 );
		}
		// Set max-height on each iframe reload in order to avoid a space after upload button:
		jQuery( '#attachmentframe_wrapper' ).css( 'max-height', body_height );
	}

	jQuery( '#attachmentframe' ).bind( 'load', function()
	{ // Set proper height on frame loading:
		update_attachment_frame_height();
	} );

	jQuery( '#icon_folding_itemform_links, #title_folding_itemform_links' ).click( function()
	{ // Use this hack to fix frame height on show attachments fieldset if it was hidden before:
		update_attachment_frame_height();
	} );

	jQuery( '#attachmentframe_wrapper' ).resizable(
	{ // Make the frame wrapper resizable
		minHeight: 80,
		handles: 's',
		start: function( e, ui )
		{ // Create a temp div to disable the mouse over events inside the frame
			ui.element.append( '<div id="attachmentframe_disabler"></div>' );
		},
		stop: function( e, ui )
		{ // Remove the temp div element
			ui.element.find( '#attachmentframe_disabler' ).remove();
		},
		resize: function( e, ui )
		{ // Limit max height
			jQuery( '#attachmentframe_wrapper' ).resizable( 'option', 'maxHeight', jQuery( '#attachmentframe' ).contents().find( 'body' ).height() );
		}
	} );
	jQuery( document ).on( 'click', '#attachmentframe_wrapper .ui-resizable-handle', function()
	{ // Increase height on click
		jQuery( '#attachmentframe_wrapper' ).css( 'height', jQuery( '#attachmentframe_wrapper' ).height() + 80 );
	} );
} );
</script>
<?php 
}
예제 #2
0
/**
 * Send a result as javascript
 * automatically includes any Messages ( @see Log::display() )
 * no return from function as it terminates processing
 *
 * @author Yabba
 *
 * @todo dh> Move this out into some more specific (not always included) file.
 *
 * @param array $methods javascript funtions to call with array of parameters
 *		format : 'function_name' => array( param1, parm2, param3 )
 * @param boolean $send_as_html Wrap the script into an html page with script tag; default is to send as js file
 * @param string $target prepended to function calls : blank or window.parent
 */
function send_javascript_message($methods = array(), $send_as_html = false, $target = '')
{
    // lets spit out any messages
    global $Messages;
    ob_start();
    $Messages->display();
    $output = ob_get_clean();
    // set target
    $target = $target ? $target : param('js_target', 'string');
    if ($target) {
        // add trailing [dot]
        $target = trim($target, '.') . '.';
    }
    // target should be empty or window.parent.
    if ($target && $target != 'window.parent.') {
        debug_die('Unexpected javascript target');
    }
    if ($output) {
        // we have some messages
        $output = $target . 'DisplayServerMessages( \'' . format_to_js($output) . '\');' . "\n";
    }
    if (!empty($methods)) {
        // we have a methods to call
        foreach ($methods as $method => $param_list) {
            // loop through each requested method
            $params = array();
            if (!is_array($param_list)) {
                // lets make it an array
                $param_list = array($param_list);
            }
            foreach ($param_list as $param) {
                // add each parameter to the output
                if (!is_numeric($param)) {
                    // this is a string, quote it
                    $param = '\'' . format_to_js($param) . '\'';
                }
                $params[] = $param;
                // add param to the list
            }
            // add method and parameters
            $output .= $target . $method . '(' . implode(',', $params) . ');' . "\n";
        }
    }
    if ($send_as_html) {
        // we want to send as a html document
        headers_content_mightcache('text/html', 0);
        // Do NOT cache interactive communications.
        echo '<html><head></head><body><script type="text/javascript">' . "\n";
        echo $output;
        echo '</script></body></html>';
    } else {
        // we want to send as js
        headers_content_mightcache('text/javascript', 0);
        // Do NOT cache interactive communications.
        echo $output;
    }
    exit(0);
}
예제 #3
0
?>
' )
			.replace( '#labelstart#', '<?php 
echo format_to_js($Form->labelstart);
?>
' )
			.replace( '#labelend#', '<?php 
echo format_to_js($Form->labelend);
?>
' )
			.replace( '#inputstart#', '<?php 
echo format_to_js($Form->inputstart);
?>
' )
			.replace( '#inputend#', '<?php 
echo format_to_js($Form->inputend);
?>
' );
	}

	jQuery( '#button_add_field' ).click( function ()
	{	// Action for the button when we want to add a new field in the Additional info
		var field_id = jQuery( this ).parent().prev().find( 'option:selected' ).val();

		if( field_id == '' )
		{	// Mark select element of field types as error
			field_type_error( '<?php 
echo T_('Please select a field type.');
?>
' );
			// We should to stop the ajax request without field_id