Can I use PHP SDK and JAVASCRIPT SDK at the same time? - javascript

I have a php program/app which asks for input, generate an image and post th image link to user's timeline (processor.php). I used PHP SDK in posting to timeline since I am more familiar with PHP. Now, in my gallery.php, i want to show like buttons for each generated image. I am aware that i have no option but use JS SDK in making button. but is it fine if i use two different SDK's in a single app?
processor.php - PHP SDK
gallerry.php - JS SDK
thanks for your answer! I would love to try your suggetions too

There shouldn't be any problem using PHP and JS in the same application, quite a common use case. You would normally use PHP to create the Web Application structure, handle backend logic, and then use JS to handle UI events.
There's nothing special about combining the two, just create the Web page with JS as normal for the view, and use PHP to build it.
Hope this helps.

Yes, there is no problem, the two APIs are designed to work together. The PHP API is usually used to created the backend logic (for example OAuth implementation, posting and getting data, etc) and the JS API to handle user iniated events.
Also see this: https://stackoverflow.com/a/6728092/1107118 on how to handle login state. Normally the JS API is used for logging in too, and then with the PHP API you take the access token and do the backend actions.

Related

How to call a plugin outside of Wordpress?

So, I need to call a plugin from outside my woocommerce websites. I have my own database that connects to Woocommerce throught REST API when it comes to products, orders and etc. My problem is, now I need to call a plugin on admin.php?page=pluginName&action=action&orderid=123456.The server that communicates with woocommerce is using classic ASP. I already tried to simply do a POST but of course wordpress asks me for login. I even tried to post it to a custom php page inside woocommerce and then post it to the plugin page but no success. Is there any way to call the plugin URL without having to login every time? It can be a php code inside my woocommerce FTP that recieves a POST with the order ID (the only query string that changes on each recordet) and then makes an AJAX POST to the plugin or something
Tried to create a custom PHP code to retrieve the POST and then do a wp_remote_post to the admin.php URL but nothing works. I just need to run the url, the plugin does the rest then
WordPress plugins rely on a lot of WordPress core code to function. Getting them to stand alone will be a LOT of work and your result will be brittle if you can get it to work at all. (Brittle === anything might break it, including a core or plugin update.)
WordPress's REST API is the best way to access WordPress, including plugin functionality, from some other network server. WooCommerce also supports REST, documented here. It offers an API key subsystem allowing secure authentication.
It's a programming task, but not unreasonably hard, to write a small plugin that adds a REST endpoint or two for a special purpose. But it's possible the one of the existing WooCommerce REST endpoints will serve your purpose. (You didn't tell us what it is, so it's hard to give more detailed advice.)

Generate equivalent HTML generated by Javascript (VueJS) on backend

I am asking this because I don't know if it's possible and don't know the terms to label this.
I have a VueJS crud app that grabs data from an API backend, and then renders it in great HTML. Thanks JavaScript, and V8 since I use Chrome.
Now, I'd like to send someone an HTML email with a snippet of the table embedded. That is a backend process. But I obviously don't want to rewrite the VueJS HTML on the backend or in another place.
Is there any way, from the backend only, to call the VueJS coding and grab the HTML, or an innerHTML section, as if I'd called it on the front end?
The answer to this is to use NodeJS and perform Server Side Rendering
This will require using the render method in VueJS which is different than what my CRUD application is written in.
Also as discussed in the link above, reactivity doesn't exist on the server side.
And in addition, the actual data that would be listed in a table needs to be pre-fetched.

Using a server to send/receive information between a mobile phone and web page

I am trying to set up a simple set up as follows:
Have a mobile app with a page consisting of 4 lines (4 html paragraph lines (I am using phonegap)).
I want to use a web page from which I will input the data for those 4 lines. This information is sent to a server and that server transfers this information to that app on that mobile phone. Now, those 4 lines on the mobile phone is filled with the new information.
Similarly user inputs information on another page consisting of 10 lines of li (list). This information is again sent to the server and to the web page where the information is displayed.
I can almost feel the "internet police guys" getting all hyped and ready to vote this question down. But please understand that I have been on this site and various forums desperate to find a tutorial to guide me to do this and not able to find.
I am trying to use ajax to perform this setup. Confused how I would be using the php file. Information such as password n username is going to go in that php file to connect to the server. But php is a server side script thus needs to sit at the public_html folder. How do I use the php file from my desktop? Write a separate javascript to access it?
It is the concept that is confusing me. I am familiar with html,js,php.
I would appreciate any guidance or maybe a link to a tutorial which would help me to do the concept I mentioned. Thanks for listening.
You will need to create an API using PHP. This API is uploaded to your server and is considered "RESTful". Google a tutorial for what fits your needs. You can set all sorts of rules in this API such as requiring any requests to have an ID or access token.
Since you are using PhoneGap, your HTML and JS files rest on the device, so you will need to allow permissions to your API from anywhere. For this you will have to speak to your host provider about unless you know how to configure it yourself (some providers restrict what you want to do by default as an extra security precaution against XSS attacks).
Next, you can either use jQuery, or you can write some AJAX calls by writing the JavaScript yourself.
The most efficient way for this to work is to send JSON objects to and from the API. You will include a "command" in the JSON when you are sending from your app. On the PHP side, you will retrieve this command and use the rest of the data included in your JSON object to process the request. Your API will need to encode a JSON object for return (such as a user's profile information).
Here is a basic PHP API tutorial to get you going that explains some of the features of a RESTful API: PHP API
Here is a simple AJAX function (you will probably want to make this much more modular): AJAX
As broad as your question is, it seems like the best/easiest thing for you to do will be for you to first create a PHP webpage that will access a SQL database to perform the record updating. Actually, this should serve all of your needs for your mobile users assuming you don't need push notifications for live data updates.
I am assuming, since you are using phone gap, that you are more comfortable with web languages. After you get the webpage fully operational, then you should start building your app based on that exact same SQL database. With mobile app development there are a lot more "what if's" (what if the phone rings, what if the app is running in the background, what if there is no cellular service, etc...)
It is always easier to start with what you know and build on that, rather than starting with a new development platform and troubleshooting as problems arise.

How to handle Async Notification in Pyjamas?

I am writing a web application using Pyjamas. .
The core functionality of my application is to show some Events which are generated asynchronously, in an HTML table (using the corresponding pyjamas widget).
Is it possible to send these notifications to the pyjamas application running in the browser?
I have been looking for an example without success.
I don't know if you are familiar with the pyjamas bookreader?
If not, there's a lot of information and some examples about ajax over there.
http://pyjs.org/book/Bookreader.html#Rest%20of%20the%20World

How to build an interactive Ajax Web Widget?

I am looking to create a web widget that can be easily integrated into any website using javascript and posts a form to my server, returns the data and displays the results appropriately. This will all happend in a small area of the host websites screen, like google adsense. I am aware that this is XSS and also the cross domain issues with ajax.
What I need help with is cementing the flow of such a widget. Has anyone done anything like this before?
The general process is:
Website embeds javascript - external js
Javascript renders a form
User submits form with POST data
POST data is sent to external server
Server responds and updates widget to display tabular data
Is this possible? How could it be achieved? Should I use / avoid using a JS framework such as Prototype / JQUery for this project?
If anyone knows any good tutorial resources for building widgets that would be great.
Any help would be greatly appreciated.
using a library like jQuery is not possible, since you don't know whether the website that uses your widget has the jQUery-library referenced.
If you use an iframe, and show something of your own host, you are able to use a library if I'm not mistaken.

Categories

Resources