Well, I have a CakePHP 2.2.5 app which is basically management of users, and a user has a photo, and I create a PhotosController (as suggestion of this tutorial). I tested it and it works perfectly on Photos/View, including the ajax elements to be possible send a photo in a form without redirecting. And now I'm trying to connect all of this, but it ins't as easy as I think it should be.
My Photo add method:
public function add()
{
if ( $this->request->is( 'post' ) ) {
$this->Photo->create();
$json = array( 'result' => array( 'files' => array() ) );
if ( $this->Photo->save( $this->request->data ) ) {
$photo = $this->Photo->findById( $this->Photo->id );
$json['files'][0]['name'] = $photo['Photo']['basename'];
$json['files'][0]['size'] = $this->request->data['Photo']['file']['size'];
$json['files'][0]['url'] = $this->webroot . 'media/transfer/img/' . $photo['Photo']['basename'];
$json['files'][0]['thumbnail_url'] = $this->webroot . 'media/filter/thumbnail/img/' . $photo['Photo']['basename'];
}
else {
$json = 'Error';
$this->Session->setFlash( __( 'The photo could not be saved. Please, try again.' ) );
}
$this->RequestHandler->renderAs( $this , 'ajax' );
Configure::write( 'debug' , 0 );
$this->set( 'json' , json_encode( $json ) );
$this->render( '/Elements/ajax' );
}
My test View (on users controller):
<?php echo $this->Form->create(
'Photo' ,
array( 'url' => array( 'controller' => 'photos' ,
'action' => 'add'
) ,
'id' => 'fileupload' ,
'enctype' => 'multipart/form-data'
)
); ?>
<-- Some HTML HERE-->
<?php
echo $this->TB->input(
'Photo.file' ,
array(
'prepend' => 'Upload' ,
'type' => 'file' ,
'class' => 'fileUpload' ,
//'multiple' => 'multiple',
'div' => FALSE ,
'between' => FALSE ,
'after' => FALSE ,
'label' => FALSE ,
'help' => NULL ,
)
);
?>
</form>
<-- Some (already tested) Javascript to make this work HERE-->
The view renders without php errors, but when I upload a file I get an Javascript error, and the debug says:
GET http://<server>/<app>/users/add 404 (Not Found) jquery.min.js:1960
send jquery.min.js:1960
b.extend.ajax jquery.min.js:1840
(anonymous function) main.js:59
c jquery.min.js:215
p.fireWith jquery.min.js:249
b.extend.ready jquery.min.js:69
H jquery.min.js:10
Actually, I get this error on both, GET and POST methods (with some different line of jQuery of course).
Even the action is set to the PhotosController it is trying to access the Users. I think because of the view, as I din't specify users anywhere. I am trying to solve this problem for a week and I don't have more ideas.
Any help would be greatly appreciated.
Thanks in advance.
Related
On my mediawiki site, you need to log in to view and edit pages. But the sidebar is displayed even when you are not logged in. Since there is some confidential information, I would like to show the sidebar only when you are logged in.
Does anyone have an idea? Thanks.
Left grey box should be hidden
Right now, I have these restrictions in LocalSettings.php:
$wgWhitelistRead = array( "Spezial:Userlogin", "MediaWiki:Monobook.css", "api.php");
$wgGroupPermissions['*']['read'] = false; $wgGroupPermissions['user']['protect'] = true;
$wgGroupPermissions['user']['edit'] = true; $wgGroupPermissions['*']['createaccount'] = false;
If you wants to remove the sidenavbar when you are not logged in there is two way.
Use a token for it and.
Use a state give it's initial value false, when the login api success then true the state with this condition also you need your user id to check if it's there then show the sidenavbar.
I did some research for you and I found this, it should be what you are looking for.
CREDIT: https://sangkrit.net/how-to-hide-mediawiki-sidebar-from-visitors/
You can suppress the display of the sidebar from anonymous and un-logged-in users on your MediaWiki website. This can be done by creating a new PHP file in extensions folder then including the code in LocalSettings.php file.
Login to your MediaWiki website’s file manager or FTP, navigate to /extensions directory located in your site’s root and create a new folder /HideSidebar.
Open the folder, create a new PHP file with name HideSidebar.php and paste the following code:
<?php
if ( !defined( 'MEDIAWIKI' ) ) {
echo "Not a valid entry point";
exit( 1 );
}
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'HideSidebar',
'version' => '1.0.1',
'author' => 'Jlerner',
'url' => 'https://www.mediawiki.org/wiki/Extension:HideSidebar',
'description' => 'Allows to hide the sidebar from anonymous users',
);
$wgHooks['SkinBuildSidebar'][] = 'efHideSidebar';
function efHideSidebar($skin, &$bar) {
global $wgUser;
// Hide sidebar for anonymous users
if (!$wgUser->isLoggedIn()) {
$url = Title::makeTitle(NS_SPECIAL, 'UserLogin')->getLocalUrl();
$bar = array(
'navigation' => array(
array('text' => 'Login',
'href' => $url,
'id' => 'n-login',
'active' => '')
)
);
}
return true;
}
Now open LocalSettings.php file and add this line of code:
require_once "$IP/extensions/HideSidebar/HideSidebar.php";
Save changes and you are done.
Based on Adam's answer and Robert's comment on the site referenced:
This can be done by creating a new PHP file in extensions folder then including the code in LocalSettings.php file.
Login to your MediaWiki website’s file manager or FTP, navigate to /extensions directory located in your site’s root and create a new folder /HideSidebar.
Open the folder, create a new PHP file with name HideSidebar.php and paste the following (Updated) code:
<?php
if ( !defined( 'MEDIAWIKI' ) ) {
echo "Not a valid entry point";
exit( 1 );
}
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'HideSidebar',
'version' => '1.0.1',
'author' => 'Jlerner',
'url' => 'https://www.mediawiki.org/wiki/Extension:HideSidebar',
'description' => 'Allows to hide the sidebar from anonymous users',
);
$wgHooks['SkinBuildSidebar'][] = 'efHideSidebar';
function efHideSidebar($skin, &$bar) {
$user = RequestContext::getMain()->getUser();
// Hide sidebar for anonymous users
if ($user->getId() == 0) {
$url = Title::makeTitle(NS_SPECIAL, 'UserLogin')->getLocalUrl();
$bar = array(
'navigation' => array(
array('text' => 'Login',
'href' => $url,
'id' => 'n-login',
'active' => '')
)
);
}
return true;
}
Now open LocalSettings.php file and add this line of code:
require_once "$IP/extensions/HideSidebar/HideSidebar.php";
Save changes and you are done.
You'd just need to look for the body's class when logged in, and if it's .logged-in, do something like this:
body:not(.logged-in) .sidebar{
display: none;
}
i want to give online test with xui one api via sms api contact form how can i do this
http://dns/accescode/?api_key=*****&action=create_line&is_trial=1&username=trialeapi&exp_date=1hour&bouquet=???&allowed_outputs=???
Hello
i want to give online test with xui one api via sms api contact form how can i do this
ex: curl "array( 'username' => $username, 'password' => $password, 'max_connections' => $max_connections, 'is_restreamer' => $reseller, 'exp_date' => $expire_date, 'bouquet' => json_encode( $bouquet_ids ) ) ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query( $post_data ) ) ); $context = stream_context_create( $opts ); $api_result = json_decode( file_get_contents( $panel_url . "api.php?action=user&sub=create", false, $context ) ); ?>"
Example (API Success)
ex: curl "{"result":true,"created_id":14838,"username":"d4PSc5uCqF","password":"2ZiuRRZk4b"}"
The API returned as the username/password of the NEW line, as well as the ID so we can use it wherever we want.
Example(API Failed)
ex: curl "{"result":false,"error":"EXISTS"} {"result":false,"error":"PARAMETER ERROR"}"
I am trying to integrate a Stripe payment method in a web application. I am stuck: payment_init.php does not load, when I am redirected to the page. I get 403 Forbidden error code ("Forbidden. You don't have permission to access this resource.
Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request").
Here is my payment_init.php file's code:
<?php
// Include the Stripe PHP library
require_once 'stripe-php/init.php';
// Include the configuration file
require_once 'config.php';
$chosenService = $_POST['submitService'];
printf($chosenService);
// Product Details
if ($chosenService === "1") {
$productName = "Hajvágás (6900 HUF)";
$productID = "hc001";
$productPrice = 6900;
} elseif ($chosenService === "2") {
$productName = 'Hajvágás + Szakáll (9900 HUF)';
$productID = "hc002";
$productPrice = 9900;
};
$currency = "huf";
$description = "20% előleg Mobil Barber";
printf($productName);
// Set API key
\Stripe\Stripe::setApiKey(STRIPE_API_KEY);
$response = array(
'status' => 0,
'error' => array(
'message' => 'Invalid Request!'
)
);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$input = file_get_contents('php://input');
$request = json_decode($input);
}
if (json_last_error() !== JSON_ERROR_NONE) {
http_response_code(400);
echo json_encode($response);
exit;
}
if (!empty($request->createCheckoutSession)) {
printf($productName);
// Convert product price to cent
$stripeAmount = round($productPrice * 100, 2);
// Create new Checkout Session for the order
try {
printf($productName);
$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [[
'price_data' => [
'currency' => $currency,
'unit_amount' => $productPrice,
'product_data' => [
'name' => $productName,
'description' => $description,
],
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => STRIPE_SUCCESS_URL . '?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => STRIPE_CANCEL_URL,
]);
} catch (Exception $e) {
$api_error = $e->getMessage();
}
if (empty($api_error) && $checkout_session) {
$response = array(
'status' => 1,
'message' => 'Checkout Session created successfully!',
'sessionId' => $checkout_session->id
);
} else {
$response = array(
'status' => 0,
'error' => array(
'message' => 'Checkout Session creation failed! ' . $api_error
)
);
}
}
// Return response
echo json_encode($response);
When I print $chosenService and $productName variables outside the "if (!empty($request->createCheckoutSession)) {...}" condition, I get the parameters, so they are not NULL. But inside the condition I do not get anything back, neither NULL (does this mean that the $request is empty?). I even checked the Logs in Stripe dashboard, this is the err message there:
"parameter_missing - line_items[0][price_data][product_data][name]
Looks like you are missing the name field tied to a given line item's product_data.
This field is required in that it contains the name that will show up on associated invoice line item descriptions."
I would be really grateful, if someone could help me with this. Thank you in advance.
I don't think your problem is the $productName. I tested out the code you provided and it looks like the issue has to do with the price value. You convert the $productPrice to $stripeAmount but then you don't use it. Without the conversion the amounts for either of the services are less than the $0.50 threshold (with the USD = HUF conversion).
As their docs point out, Stripe requires your charge amounts to be valued between $0.50 and $999,999.00
I don't think this impacted your attempt here but it might also be worth updating the way in which you are invoking/using the Stripe PHP library to conform to the current standard: https://github.com/stripe/stripe-php#getting-started
It will mean you can more easily use the code snippets displayed in the API docs
I have written a custom calendar module for use with Beaver Builder.
I want to fetch posts from a custom post_type of 'event' to populate the calendar.
In my beaver builder module I have the following:
wp_enqueue_script( 'axios', 'https://unpkg.com/axios/dist/axios.min.js');
wp_enqueue_script( 'qs', 'https://unpkg.com/qs/dist/qs.js');
function get_ajax_event_calendar_posts() {
// Query Arguments
$args = array(
'post_type' => array('event'),
'post_status' => array('publish'),
'posts_per_page' => 40,
'nopaging' => true,
'order' => 'DESC',
'orderby' => 'date',
'cat' => 1,
);
// The Query
$ajaxposts = get_posts( $args ); // changed to get_posts from wp_query, because `get_posts` returns an array
echo json_encode( $ajaxposts );
wp_die(); // this is required to terminate immediately and return a proper response
}
// Fire AJAX action for both logged in and non-logged in users
add_action('wp_ajax_get_ajax_event_calendar_posts','get_ajax_event_calendar_posts');
add_action('wp_ajax_nopriv_get_ajax_event_calendar_posts', 'get_ajax_event_calendar_posts');
and in my modules JavaScript (frontend.php) I have:
var data = { action: "get_ajax_event_calendar_posts" };
axios.post("<?php echo admin_url('admin-ajax.php');?>", Qs.stringify(data))
.then(function(response) {
console.log(JSON.stringify(response.data));
})
.catch(function(error) {
console.log(error);
});
I have one post in 'event'. In the browser, I test the endpoint by visiting xxx.flywheelsites.com/wp-admin/admin-ajax.php?action=get_ajax_event_calendar_posts and receive an empty array []. I expect to receive a single event. I've looked in the admin and can see the post.
When clicking on the button in my module to make the Ajax request, I receive a 400 error
Checking the logs, I receive the following error message:
(MISSING)127.0.0.1 - 04/Jan/2020:16:41:40 +0000 "POST /.wordpress/wp-admin/admin-ajax.php" 400 /www/.wordpress/wp-admin/admin-ajax.php 64263000 4103576 709.963 4096 35.21%!
This error message doesn't really tell me anything. I also altered my axios method to use a GET - however, I receive the same error.
Any advice on how I can debug this would be really helpful. Thanks!
Wordpress, Astra Theme, Beaver Builder, hosted on flywheel.
** Edit **
To test, in my get_ajax_event_calendar_posts method I am echo'ing out 'hello world'
function get_ajax_event_calendar_posts() {
// Query Arguments
$args = array(
'post_type' => array('event'),
'post_status' => array('publish'),
'posts_per_page' => 40,
'nopaging' => true,
'order' => 'DESC',
'orderby' => 'date',
'cat' => 1,
);
// The Query
$ajaxposts = get_posts( $args ); // changed to get_posts from wp_query, because `get_posts` returns an array
echo 'hello world'; //json_encode( $ajaxposts );
wp_die(); // this is required to terminate immediately and return a proper response
}
I visit the url in my browser and see 'hello world' - so it seems there might be a problem in querying the data? The logs don't contain anything useful. However, from this I can see I can hit the route and get a response from it.
** Edit **
I can now view the posts when hitting the url directly. Appears to be an issue of cacheing.... I have updated my JS - yet the old files persist. I'm hopeful this is just a cacheing issue...
Using Beaver Builder, I had to clear Beaver Builders cache. To clear it, go into settings -> beaver-builder -> tools and click the clear cache button.
This is the part of my functions.php that doesn't work (I get no PHP ERROR, and also nothing showing up):
function calmar_studio_customizer_register ($wp_customize) {
$wp_customize -> add_section('calmar_studio_colors', array (
'title' => __('Colors', 'calmar_studio'),
'description' => 'Modify the theme colors',
));
$wp_customize -> add_setting('background_color', array (
'default' => '#fff',
));
$wp_customize -> add_control( new WP_Customize_Color_Control($wp_customize, 'background_color', array(
'label' => __('Edit Background Color', 'calmar_studio'),
'section' => 'calmar_studio_colors',
'settings' => 'background_color',
) ));
}
add_action('cutomize_register', 'calmar_studio_customize_register');
While not exactly solving the issue, I grabbed the Sample from https://gist.github.com/Abban/2968549 and copied it into my functions.php file. Works perfectly. Now I have to make tweaks, and get the items to Display on the page.
This could be the plugin conflict issue. Please deactivate plugins and try.
Thanks.