<![CDATA[ Newspublisher seperate Image upload field - My Forums]]> https://forums.modx.com/thread/?thread=86893 <![CDATA[Re: Newspublisher seperate Image upload field]]> https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field?page=2#dis-post-481523 BobRay Oct 30, 2013, 10:48 PM https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field?page=2#dis-post-481523 <![CDATA[Re: Newspublisher seperate Image upload field]]> https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field?page=2#dis-post-481520
I created a new TV (file) which is a file upload field and created a new media source that opens the users device file storage. Set basePathRelative to 'No'. I might have changed something else here but I can't remember.

Then in the NewsPublisher outerTpl I added the enctype to multipart form data.

I also then changed the npFileTpl slightly so it doesn't use the filebrowser
<div id="np-[[+npx.fieldName]]-container" class="np-file">
        [[+np.error_[[+npx.fieldName]]]]
        <label class="fieldlabel" for="np-[[+npx.fieldName]]" title="[[+npx.help]]">[[+npx.caption]]: </label>
        <input name="[[+npx.fieldName]]" class="file" id="np-[[+npx.fieldName]]" type="file"  value="[[+np.[[+npx.fieldName]]]]" />
        <!--<button type="button" onclick="var popup=window.open('[[+npx.browserUrl]]', 'Select file...', 'width=' + Math.min(screen.availWidth,1000) + ',height=' + Math.min(screen.availHeight*0.9,700) + 'status=no,location=no,toolbar=no,menubar=no');popup.focus();browserPathInput=getElementById('np-[[+npx.fieldName]]');">[[%np_launch_file_browser]]</button>-->
    </div>


Finally (not the greatest idea but it works) I edited the Newspublisher class file to include the image upload processing.
// John Davison - ImageUpload Edit
			if(!empty($_FILES['file']['name'])) {
				if ($_FILES['file']['error'] > 0) {
					$this->setError('Errors with file upload' . $_FILES['file']['error']);
					$linkURL = '';
				} else {
					function findexts ($filename) 
					 { 
						 $filename = strtolower($filename) ; 
						 $exts = split("[/\\.]", $filename) ; 
						 $n = count($exts)-1; 
						 $exts = $exts[$n]; 
						 return $exts; 
					 } 
					$ext = findexts($_FILES['file']['name']);
					$ran = rand();
					$ran2 = $ran . '.';
					$destination = "assets/uploads/";
					$destination = $destination . $ran2.$ext;
					move_uploaded_file($_FILES['file']['tmp_name'], $destination);
					/* create the image link URL */
			        $linkURL = '<img src="'. $destination . '" style="max-width:400px;" /> <br />';
				}
			} 
			
            /* these *might* be in the $_POST array. Set them if not */
            $fields['published'] = isset($_POST['published'])? $_POST['published']: $this->published;
            $fields['hidemenu'] = isset($_POST['hidemenu'])? $_POST['hidemenu']: $this->hideMenu;
            $fields['template'] = isset ($_POST['template']) ? $_POST['template'] : $this->template;
            $fields['parent'] = isset ($_POST['parent']) ? $_POST['parent'] : $this->parentId;
            $fields['searchable'] = isset ($_POST['searchable']) ? $_POST['searchable'] : $this->searchable;
            $fields['cacheable'] = isset ($_POST['cacheable']) ? $_POST['cacheable'] : $this->cacheable;
            $fields['richtext'] = isset ($_POST['richtext']) ? $_POST['richtext'] : $this->richtext;
            $fields['createdby'] = $this->modx->user->get('id');
            $fields['content']  = $this->header . $linkURL . $fields['content'] . $this->footer;
            $fields['context_key'] = $this->modx->context->get('key');


As it's just a couple of Super Users who will have access to this I'm not too concerned about the security as the resource that contains the NewsPublisher snippet call is restricted to those users.

A bit hacky but it seems to suffice.

Cheers.

]]>
jonboy Oct 30, 2013, 10:15 PM https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field?page=2#dis-post-481520
<![CDATA[Re: Newspublisher seperate Image upload field]]> https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field?page=2#dis-post-481398
Greatly appreciated.]]>
jonboy Oct 29, 2013, 11:27 AM https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field?page=2#dis-post-481398
<![CDATA[Re: Newspublisher seperate Image upload field]]> https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-481339 Quote from: jonboy at Oct 28, 2013, 10:33 AM

Is it possible to use FileUpload in conjunction with Newspublisher and embed an image within a post?

I've never tried it. It should be possible to put a tag for FileUpload in the content of the NewsPublisher Resource, but the image wouldn't be associated with the saved page unless you write a plugin to connect it somehow (e.g., write the image path to one of the page's TVs). I think OnDocFormSave will be fired so a plugin attached to that might work.

BTW, you might try Discuss. It might have image-upload capability and could be phone friendly.]]>
BobRay Oct 28, 2013, 05:23 PM https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-481339
<![CDATA[Re: Newspublisher seperate Image upload field]]> https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-481273
Thanks for the reply.

Is it possible to use FileUpload in conjunction with Newspublisher and embed an image within a post?

The other guys who use the site want it all to be done within that site rather than using a 3rd party site like flikr or photobucket e.t.c. To recap I need to use the Newpublisher add on to create a new Article Post (this works a treat) but need to embed an image into the Article Post using FileUpload.

If anyone can help with this, there is a budget available.

Cheers.]]>
jonboy Oct 28, 2013, 10:33 AM https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-481273
<![CDATA[Re: Newspublisher seperate Image upload field]]> https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-480090 http://bobsguides.com/fileupload-tutorial.html]]> BobRay Oct 12, 2013, 03:37 AM https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-480090 <![CDATA[Re: Newspublisher seperate Image upload field]]> https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-480012 Quote from: BobRay at Oct 11, 2013, 06:11 AM
I wouldn't recommend altering the NewsPublisher PHP code.

Have you tried the FileUpload snippet to see how that works on a phone?

You might also try having the users upload the images to a public service like Flickr, Picassa, Instagram, or something similar (your account or theirs). Then you could have a plain text TV with the URL of the photo.


Hi Bob

Thanks for your reply.

How do I use the FileUpload snippet? I wasn't sure about that..

]]>
jonboy Oct 11, 2013, 08:20 AM https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-480012
<![CDATA[Re: Newspublisher seperate Image upload field]]> https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-479992
Have you tried the FileUpload snippet to see how that works on a phone?

You might also try having the users upload the images to a public service like Flickr, Picassa, Instagram, or something similar (your account or theirs). Then you could have a plain text TV with the URL of the photo.

]]>
BobRay Oct 11, 2013, 06:11 AM https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-479992
<![CDATA[Re: Newspublisher seperate Image upload field]]> https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-479968
Sorry - I thought I had replied to your post.

I'm still struggling to get this working.

How would I go about using Formit to embed a photo into a Article? Is this really complicated? I only have moderate experience with PHP and developing for ModX.

I did try something else, which was to edit the npfiletpl chunk so that it shows a simple file upload. The issue would then be processing the image upload and embedding it within the content. I did look around lines 1411 of newspublisher.class.php
$fields['content']  = $this->header . isset ($_POST['ImageUpload']) ? $_POST['ImageUpload']:  $fields['content'] . $this->footer;


I'd need to use the URL/filename of the uploaded Image there I'm thinking.

Am I anywhere close or, beond struggling smiley

Thanks.]]>
jonboy Oct 11, 2013, 01:40 AM https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-479968
<![CDATA[Re: Newspublisher seperate Image upload field]]> https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-478836
You might try one of the MODX Gallery extras, they should do the same thing and give you the extra fields and even some image processing if you like.

If you were going to go to FormIt, I'd skip using NewsPublisher and just use a FormIt postHook to embed the photo in a resource.]]>
BobRay Sep 26, 2013, 11:14 PM https://forums.modx.com/thread/86893/newspublisher-seperate-image-upload-field#dis-post-478836