Error while uploading images with EasyMDE - django

I am using EasyMDE text editor on my Notemaking website, but for some reason, the uploadImage functionality doesn't work.
This is how I instantiate EasyMDE.
var easyMDE = new EasyMDE({
autofocus: true,
autorefresh: true,
spellChecker: false,
minHeight: '180px',
uploadImage:true,
});
Can some one help me fix this issue or point me in the right direction of how to solve it?

I was searching for a PHP method but this is what I got :
https://github.com/Ionaru/easy-markdown-editor/pull/71
Edit:-
I figured it out in PHP
You need to also set the "imageUploadEndpoint" value to another file and save your image and print json.
This is how I did in PHP.
Client-Side:
var easyMDE = new EasyMDE({
uploadImage:true,
imageUploadEndpoint: 'upload.php'
});
Server-Side(in upload.php):
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
header('Content-Type: application/json');
//logic for saving the file
if(image_saving_successful)
{
$url = the_filepath_for_the_image_saved
echo '{"data": {"filePath": "'.$url.'"}}';
http_response_code(200);
exit;
}else{
echo '{"error": "your_error_message"}';
http_response_code(400);
exit;
}
}else{
header('location: index.php');
exit;
}
?>
There are different response code for different error messages. Check Readme.md

Related

Create a {if} statement in WHMCS

Im trying to create a specific IF statement on the clientareaproductdetails.tpl file in WHMCS - bottom line i'm trying to display some text on a page depending on the product the customer is looking at.
So this is what I tried (which does not work)
{if $id == '17'} something {else} nothing {/if}
So if the product ID = 17 then display 'something' otherwise display 'nothing.
Any ideas if/how this is possible?
Thanks in advance.
H
If by product id, you mean the package id, then it explains why your code didn't work. $id variable is for service id.
To achieve what you want, Add a hook file (say: custom_product_message.php) to includes/hooks/ folder.
Then add the following code:
<?php
add_hook('ClientAreaProductDetailsOutput', 1, function($service) {
if (!is_null($service)) {
if ($service['service']->packageId == 17) {
return "something";
} else {
return 'nothing';
}
}
return '';
});
The idea is to use ClientAreaProductDetailsOutput hook to display a text in the clientarea productdetails page.

Handling 404 error Joomla 2.5

I try to redirect all my 404 error on my web site following those docs :
http://docs.joomla.org/Creating_a_Custom_404_Error_Page
So I edited my error.php :
<?php
defined('_JEXEC') or die;
if (($this->error->getCode()) == '404') {
header('Location: http://www.mywebsite.com');
exit;
}
if { (!isset($this->error)) {
$this->error = JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
$this->debug = false;
}
//get language and direction
$doc = JFactory::getDocument();
$this->language = $doc->language;
$this->direction = $doc->direction;
?>
But when I clic on a link that should redirect me to a 404 error page - which should now redirect to my home page, it goes to the following link instead :
http://www.mywebsite.com/index.php?Itemid=359
How may I solve that problem ?
Joomla needs an itemID when building a page. My guess is that your default page is item ID 359. Joomla is appending that to the URL most likely because you do not have SEF URLs with rewrite turned on.
Correct code that you need (and more general) is:
if (($this->error->getCode()) == '404') {
header('Location: /index.php');
exit;
}
Some suggested the below, but I just want to redirect to main page not to an article:
if (($this->error->getCode()) == '404') {
header('Location: /index.php?option=com_content&view=article&id=999');
exit;
}

PHP if / else statements don't seem to work for contact us with email

I've created some if / else statements to get a download when a user hit click
but dont work ,because you can direct download without field name or email ,please help me
contact. php for my site
http://my-easy-woodworking-projects.com
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'lulu#yahoo.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script>
var str = "download";
document.write(str.link("http://www.myshedplans.com/12BY8SHED.pdf"));
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to gordon#template-help.com');
window.location = 'contact_page.html';
</script>
<?php
}
?>
I'm not quite sure why that if/else isn't working for you but one thing that can happen is the interpreter forgets about the if statement when it gets down to the else. A way to get around this is by echoing your html code within the conditional block like bellow:
<?php
if ($mail_status) {
echo "<script>";
echo "var str = \"download\";";
echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));";
echo "</script>";
}
else {
echo "<script language=\"javascript\" type=\"text/javascript\">";
echo "alert('Message failed. Please, send an email to gordon#template-help.com');";
echo "window.location = 'contact_page.html';";
echo "</script>";
}
?>

Rest API Web Service - iOS

Its my first time to use web service in iOS.
REST was my first choice and I use code igniter to form it.
I have my Controller:
require APPPATH.'/libraries/REST_Controller.php';
class Sample extends REST_Controller
{
function example_get()
{
$this->load->helper('arh');
$this->load->model('users');
$users_array = array();
$users = $this->users->get_all_users();
foreach($users as $user){
$new_array = array(
'id'=>$user->id ,
'name'=>$user->name,
'age'=>$user->age,
);
array_push( $users_array, $new_array);
}
$data['users'] = $users_array;
if($data)
{
$this->response($data, 200);
}
}
function user_put()
{
$this->load->model('users');
$this->users->insertAUser();
$message = array('message' => 'ADDED!');
$this->response($message, 200);
}
}
, using my web browser, accessing the URL http://localhost:8888/restApi/index.php/sample/example/format/json really works fine and gives this output:
{"users":[{"id":"1","name":"Porcopio","age":"99"},{"id":"2","name":"Name1","age":"24"},{"id":"3","name":"Porcopio","age":"99"},{"id":"4","name":"Porcopio","age":"99"},{"id":"5","name":"Luna","age":"99"}]}
, this gives me a great output using RKRequest by RestKit in my app.
The problem goes with the put method. This URL :
http://localhost:8888/restApi/index.php/sample/user
always give me an error like this:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<xml>
<status/>
<error>Unknown method.</error>
This is my Users model
<?php
class Users extends CI_Model {
function __construct()
{
parent::__construct();
}
function get_all_users()
{
$this->load->database();
$query = $this->db->get('users');
return $query->result();
}
function insertAUser(){
$this->load->database();
$data = array('name'=> "Sample Name", 'age'=>"99");
$this->db->insert('users', $data);
}
}
?>
What is the work around for my _put method why am I not inserting anything?
Thanks all!
Unless you set the method to PUT or POST, your web server is not going to treat it as such. When you enter URLs in a browser bar, that is almost always a GET request. You might try to use curl like
curl -X POST -d #filename http://your.url.path/whatever
Another link would be: https://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request
So you should be able to do a PUT similarly (perhaps with no data). Not really sure if this should be iOS tagged though :)
I got this problem by using Firefox plug in rest Client.
I just have to indicate the headers and the body to make put and post work.

opencart 1.5 how to add module in a header

Please some one tell me how can I position modules like slider or banner in header or how can we define additional regions for the modules.
Well, I am working on it.
Firstly, you should add a new position in the admin page.
Which means you should change three files and add some lines into each.
For example, if you want to add slideshow into header, you should add a new position in
$this->data['text_header'] = $this->language->get('text_header'); // in admin/controller/slideshow.php
////////////////////////////////////////////////
$_['text_header'] = 'Header'; // in admin/language/slideshow.php
////////////////////////////////////////////////
<?php if ($module['position'] == 'header') { ?> // in admin/view/slideshow.tpl
<option value="header" selected="selected"><?php echo $text_header; ?></option>
<?php } else { ?>
<option value="header"><?php echo $text_header; ?></option>
<?php } ?>
Then a new position for slideshow has been defined. and you can choose it in the admin page.
After that, you should add those codes in catalog/view/header.tpl
<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>
Then, in the catalog/controller/header.php, add some codes like content_top.php does:
$layout_id = 1;
$module_data = array();
$this->load->model('setting/extension');
$extensions = $this->model_setting_extension->getExtensions('module');
foreach ($extensions as $extension) {
$modules = $this->config->get($extension['code'] . '_module');
if ($modules) {
foreach ($modules as $module) {
if ($module['layout_id'] == $layout_id && $module['position'] == 'header' && $module['status']) {
$module_data[] = array(
'code' => $extension['code'],
'setting' => $module,
'sort_order' => $module['sort_order']
);
}
}
}
}
$sort_order = array();
foreach ($module_data as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $module_data);
$this->data['modules'] = array();
foreach ($module_data as $module) {
$module = $this->getChild('module/' . $module['code'], $module['setting']);
if ($module) {
$this->data['modules'][] = $module;
}
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/header.tpl';
} else {
$this->template = 'default/template/common/header.tpl';
}
$this->render();
Then all done.
The only problem for this code is the slideshow cannot display as a slideshow but a static picture or pictures.
Wish you could solve it out and reply to me.
My question post:
Opencart developement: change slideshow's position
do what Huawei Chen wrote and then add these to header:
<script type="text/javascript" src="catalog/view/javascript/jquery/nivo-slider/jquery.nivo.slider.pack.js"></script>
<link rel="stylesheet" type="text/css" href="catalog/view/theme/default/stylesheet/slideshow.css" media="screen" />
and slider will be working
You can learn from controller/common/column_right.php
Check module position (line 50), you can adapt it to "header":
$module['position'] == 'column_right'
Set the output (line 69), you can adapt it to something like "header_mod" :
$this->data['modules']
You need to modificate module at admin to show additional module position.
There is no "header" module position options at admin page.
You can also use an extension that places 2 positions in header and footer. It create the same hooks, like column_left and content_top, etc.
it works with VQmod for opencart 1.5x
I think this extension will make your life super simple. http://www.opencart.com/index.php?route=extension/extension/info&token=extension_id=14467
You can add unlimited number of positions to your header, add columns and change there width all through admin
Regards
This guide helped me:
http://www.mywork.com.au/blog/create-new-module-layout-position-opencart-1-5/
I was using 1.5.6.1 Opencart version.
I read all of your answer. Forget all things.
It's very easy to call any module into header section.
Open your catalog/controller/common/header.php file
$this->data['YOUR_MODULE_NAME'] = $this->getChild('module/YOUR_MODULE_NAME');
Now Open .tpl file of header, which is located at
catalog/view/theme/YOUR_THEME/template/common/header.tpl
and echo your desire module whenever you want, like as:
<?php echo $YOUR_MODULE_NAME;?>
That's it. you are done.
You must know that your new position is a new child.
file: catalog/controller/common/header.php
$this->children = array(
'module/language',
'module/currency',
'module/cart'
);
add your new position, like this:
$this->children = array(
'common/content_new',
'module/language',
'module/currency',
'module/cart'
);
now you can echo your new position in your header.tpl