I'm having some trouble with CKEditor.
I have created a blog for my website and a back end section to write new posts and approve comments etc. It's all working fine and I use CKEditor to write and edit posts.
When writing a text only post its fine, it gets stored in the database and subsequently appears on the website as it should. But If I write a post with an image in it it doesnt get stored in the database. All text and images disappear.
The title of the post goes into the database as this is just using a normal text box. But everything in the CKEditor disappears if I put an image in there.
Here are some screen shots:
I press the image button and enter in the explicit URL of the image stored on my server. (http://www.mydomain.com/images/image.jpg)
When I press ok the image is visible in CKEditor with the text above it.
When I submit the post and then return to it to view or edit it, the CKEditor is empty and only the Title is there. Checking the database I can see the title is entered but the body isnt.
If I dont enter an image everything works fine title and body go into the database and the blog post appears on the site.
Does anyone have any idea whats wrong here?
I actually discovered the answer myself
The image tags created in the CKEditor would be something like
<img src="images/picture.jpg">
and my SQL query would be something like
$query = "INSERT INTO Table (blog_body, blog_title) VALUES ('".$blogBody."','".$blogTitle."')";
or something along those lines.
To solve it I just swapped the quotation marks around. Placing the query in single quotes and swapping the quotes about the variables around.
This fixed my problem.
Just thought if someone else is having this trouble this may help
Related
I am trying to build a system where users can edit news stories. When they add images to the stories they will type #IMG1# if it is the image with id 1 they want in there.
When they upload the news, the #IMG1# code is str_replace() with something like this: <div id="image"><img src="images/image1.jpg"></div>
The issue for me is when they want to edit the news again, I want to replace all the image codes back, so the user sees the #IMG1# again, but it seems I cannot str_replace() back because of the html codes and the quotation marks? Is this true?
Is there a way to fix this?
I advise to leave news' text as is, with #IMG1# placeholders.
Only when you output this text for viewing - replace #IMG1# with <img> tag, but when user edits text - he still sees #IMG1# and can edit it.
Of course, as you will replace #IMG1# placeholders on each output, this can slower your system. As a solution - you can add additional field like renderedContent and on saving data render news text to this field and when output for viewing - take content from this field.
I'm new to using the FB share buttons terminology so forgive me if I use the wrong syntax in describing this.
My site is setup to load pages based on the passed parameters in the URL (...?page=somepage&imageid=idnum).
So I have my index file which contains my head, as well as sidebar, etc. Then my main body is generated according to the passed parameter. Simple Enough.
On the homepage, the main body is a gallery of images. When they click on one of those images it takes them to a page that just displays that one image. The page is loaded with parameters of ?page=detail&image_id=1 /*or whatever the id of that image is */
So when they click on the share on FB button on those individual images page, I would like it to populate with the image that is displayed on that page. What I have done is included a php file in my head tag. The php script included gets the page info and passed parameters and then fills out the image url based on the imageid.
echo '<meta property="og:image" content="http://www.chiseledimages.com/clients/vote/'.$imgurl.'"/>';
This works in that when displaying the page source, the meta tag with og:image shows perfectly, also in that when I run it through the FB Object debugger, it gets the correct image and doesn't show me any errors. It even posts the correct image when the users shares on their wall. What is does not do, is show the correct image in the pop window after the uses presses the share button on my site. So even though the result is what I want, the problem with the user not seeing the correct image in the share pop-up, may lead them not to want to share on their wall.
Current location of site: http://www.chiseledimages.com/clients/vote/
Example of a specific pages: http://chiseledimages.com/clients/vote/?page=detail&angel_id=1
Screenshots of pop-up with wrong image, but final posted story having correct image.
How can I make the image in the pop-up match the image that is going to be shared. Thanks.
Edit: I forgot to mention and I'm sure it matters that I'm using Addthis to implement the FB share.
Check https://developers.facebook.com/docs/reference/dialogs/feed/ - look for the 'picture' parameter description
I suggest to you use this http://support.addthis.com/customer/portal/articles/1365475-attribute-based-configuration#.UwPQB6LW6So. just follow their example and you good to go.
OK
I've actually spent 3 hours searching for how should I get images correctly on my drupal site so please don't get annoyed with this easy question. (sob...)
I want to upload an image to my front page as a button for redirecting to login page.
How CAN I achieve this?????I mean how should I store image as in Drupal and how can I get it in the position I want on the page???
I tried creating a content type called image and then created a View of block type but it doesn't seems correct to me.
What is the correct set of steps for storing and handling images in drupal??
Thanks
Create a block in your Drupal site and assign it to a region in the front page. Added the Image via PHP code there.
I have been working on a small product based site. This site has various products and descriptions along with images in it. I am using tinymce editor to upload the description and images.
But the problem is, when I copy-paste the image in the editor, it shows fine in localserver but in web it shows a sign like this \"\" and the url associated with the image is like: http://abc.com.au/products/\"abc.com.au/admin/data/test.jpg\".
Any suggestions?
Assuming you are saving the content from the editor window to a database, you need to use the stripslashes function on the string you pass from the editor to the database. That way, the content won't be altered. The slashes are added by default since characters like double quotes need to be escaped in order for the code to be parsed, as well as displayed, correctly.
I managed to create a simple blog and an admin page using PHP. I didn't use a CMS like wordpress because I wanted a deeper understanding of PHP.
I wanted to create an admin page that allowed the user to specify where in their blog posting they could put in a picture; for example, they can add a photo before the first paragraph or after.
My admin page as it is now is just a textarea input field and a submit button that submits text-only blog posts from the textarea field to the database. My thought process was that I could add img tags into the textarea input field, but the user's photos might be stored on their hard drive so I thought of the idea to store PHP code in the textarea input field to retrieve image files from the database. For example, if I wanted to place a photo after the first paragraph of the blog post, I would type something like this into the textarea field:
This is the first paragraph. Here is a photo of my vacation:
<? echo "<img src='getPhoto.php?page=blogPost'>"; ?>
Then I click the "submit button" and the paragraph with the PHP code gets submitted into my database. The page with the blog posting retrieves the text, "This is the first paragraph. Here is a photo of my vacation:" and the PHP code. The PHP code then retrieves and shows the photo.
The problem is that submitting PHP code with the blog text might be confusing for a user who is not tech-savvy or does not have any programming knowledge. The admin page should make it possible for the blog writer to place photos anywhere in their blog post without programming knowledge. I haven't found a tutorial yet that covers image placement in a PHP blog's admin page. Any help getting started would be appreciated.
One way to accomplish what you want is by implementing custom shortcodes. In you case it'd look something like this:
This is the first paragraph. Here is a photo of my vacation:
[image bahamas-00123]
How it works is that you do something like this:
$text = shortcodes($text);
You'd need a separate area for uploading photos and some way of keeping track of them (ie: sql, flatfiles) so you know that bahamas-00123 actually refers to /some/path/DSC-00123.JPG.
For some code please check the accepted answer of: How do I replace custom “tags” in a string?
You can use a text editor like ckeditor or tinymce to format the text and upload images. This way users need not be aware about the custom tags and they can place the image wherever they like.