This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

DMeganoski
DMeganoski

Hello Team, I have a jquery plugin which fetch data from social networks.This plugin has 3 .php files as rss.php, facebook.php, twitter.php which i have to > use.how to use these php files in octobercms in pages.as i am using in pages it is not working.

er.shajidkhan13974 wrote on https://octobercms.com/forum/post/how-to-use-php-script-in-pages-of-octobercms

Moving this over to the support category so that others may find it easier.

If you have a jquery or other javascript plugin which requires php server-side processing scripts, you will need to leverage the ajax framework included with Octobercms.

Here is the documentation on the ajax framework. https://octobercms.com/docs/cms/ajax

It is included by default in all backend pages, but for frontend pages you will need to include the javascript files by adding the twig markup.

What you will want to do is create a function for each of the php pages you were provided, and place it in the 'code' section of the page. (This is not possible with some static pages plugins)

Then, you will have to modify the javascript. Search for where it makes the ajax call, look for each of the filenames. If you are lucky it will be a jquery

$.ajax({})
call, and that can be easily switched to a
$.request('name',{})
where 'name' is the name of the function in the page.

so… let's say you take all the code out of facebook.php and put it into a function called onUpdateFacebook()

so where it would say something like


$.ajax({
                    url: 'facebook.php',
                    data: {this: 'this', that: 'that'},
                    success: function(resp) {
                        // modify page
                    }
                });

you would change that to


$.request('onUpdateFacebook', {
                    data: {this: 'this', that: 'that'},
                    success: function(resp) {
                        // modify page
                    }
                });

Hopefully that gets you started on the right path.

Last updated

er.shajidkhan13974
er.shajidkhan13974

First of all thank you very much for correcting my post in right place. Actually i am totally new to octobercms i know how to add html theme in octobercms, but first time i am using jquery which is creating problem.I have read the document but i am not getting how to start with my jquery.the plugin name is "jquery social stream".will you please do it for me? if yes i will provide my link and backend un and pswrd.the un=admin and pswrd=admin

Last updated

wvelez
wvelez

@er.shajidkhan13974 Did you get your problem solved? I have similar, my theme's been working fine except for one script that calls a php file. The script work perfect with plain html and php but not from within the CMS. The script is below:

$(document).ready(function () {
    var twitterusername = "username";
    var notweets = "5";
    $.get('/noapitwitter/notwitterapi.php?endpoint=timeline&twitterusername=' + twitterusername + '&count=' + notweets, function (jsondata) {
        var data = $.parseJSON(jsondata);
        var i = 0;
        $.each(data, function () {
            i++;
            if (this['error']) {
                $('#twitter-feed1').append('<div class="twitter-article" id="tw1"><div class="twitter-text"><h1>' + this['error'] + '</h1></div></div>');
            } else {
                $('#twitter-feed1').append('<div class="twitter-article" id="tw1"><div class="twitter-pic"><a href="https://twitter.com/' + this['username'] + '" target="_blank"><img src="' + this['avatar'] + '" images="" twitter-feed-icon.png"="" width="42" height="42" alt="twitter icon"/></a></div><div class="twitter-text"><p><span class="tweetprofilelink"><a href="https://twitter.com/' + this['username'] + '" target="_blank"><strong>@' + this['username'] + '</strong></a></span><span class="tweet-time">' + this['date'] + '</span><br/><span>' + this['tweet'] + '</span></p></div><div class="tweet-bar"><a href="https://twitter.com/intent/tweet?in_reply_to=' + this['idoftweet'] + '" target="_blank"><img src="/noapitwitter/img/reply.png"></a><a href="https://twitter.com/intent/retweet?tweet_id=' + this['idoftweet'] + '" target="_blank"><img src="/noapitwitter/img/retweet.png"></a><a href="https://twitter.com/intent/favorite?tweet_id=' + this['idoftweet'] + '" target="_blank"><img src="/noapitwitter/img/favorite.png"></a></div></div>');
            }
        });
    });

});

Last updated

DMeganoski
DMeganoski

@er.shajidkhan13974 sorry, I barely have time enough to provide this help, I cannot do it for you.

@wvelez what you would want to do, then, is put the entire contents of notwitterapi.php into a function in your 'code' section of the template. For simplicity, let's call the function onNoTwitterApi


function onNoTwitterApi() {
    // file contents here
}

Then, change this line


 $.get('/noapitwitter/notwitterapi.php?endpoint=timeline&twitterusername=' + twitterusername + '&count=' + notweets, function (jsondata) {
    // keep same contents
})

to this


$.request('onNoTwitterApi', {
    data:{twitterusername:twitterusername,endpoint:'timeline',count:notweets},
    success: function(jsondata) {
        // same contents here
    }
})

Then, you will have to unfortunately change some of the php. You see, the original javascript is making a 'GET' request, while the api (as far as I know) only supports 'POST' requests.

So go through the php script, find where it gets the $_REQUEST variables for username, endpoint and count, and switch it to

\Input::get('username');
(Or search for how to get post variables in octobercms, this is the laravel method)

er.shajidkhan13974
er.shajidkhan13974

its ok DMeganoski i will try it.no wvelez my issue is not solved.did your script working now?

wvelez
wvelez

@DMeganoski I get an Uncaught SyntaxError: Unexpected token ). My apologies for being a newbie. Googled it first before posting but couldn't fix.

  $(document).ready(function () {
      var twitterusername = "username";
      var notweets = "5";
      $.request('onNoTwitterApi', {
      data:{twitterusername:twitterusername,endpoint:'timeline',count:notweets},
      success: function(jsondata) {
          var data = $.parseJSON(jsondata);
          var i = 0;
          $.each(data, function () {
              i++;
              if (this['error']) {
                  $('#twitter-feed1').append('<div class="twitter-article" id="tw1"><div class="twitter-text"><h1>' + this['error'] + '</h1></div></div>');
            } else {
                $('#twitter-feed1').append('<div class="twitter-article" id="tw1"><div class="twitter-pic"><a href="https://twitter.com/' + this['username'] + '" target="_blank"><img src="' + this['avatar'] + '" images="" twitter-feed-icon.png"="" width="42" height="42" alt="twitter icon"/></a></div><div class="twitter-text"><p><span class="tweetprofilelink"><a href="https://twitter.com/' + this['username'] + '" target="_blank"><strong>@' + this['username'] + '</strong></a></span><span class="tweet-time">' + this['date'] + '</span><br/><span>' + this['tweet'] + '</span></p></div><div class="tweet-bar"><a href="https://twitter.com/intent/tweet?in_reply_to=' + this['idoftweet'] + '" target="_blank"><img src="/noapitwitter/img/reply.png"></a><a href="https://twitter.com/intent/retweet?tweet_id=' + this['idoftweet'] + '" target="_blank"><img src="/noapitwitter/img/retweet.png"></a><a href="https://twitter.com/intent/favorite?tweet_id=' + this['idoftweet'] + '" target="_blank"><img src="/noapitwitter/img/favorite.png"></a></div></div>');
            }
        });
    });  **<=== Uncaught SyntaxError: Unexpected token )**
});

Last updated

er.shajidkhan13974
er.shajidkhan13974

is your issue solved now about php script wvelez?

Last updated

wvelez
wvelez

@er.shajidkhan13974, no I'm still having issues. I have a friend also helping me out on this and we can't figure it out.

DMeganoski
DMeganoski

@wvelez you were missing a closing bracket for your options object.


$(document).ready(function () {
    var twitterusername = "username";
    var notweets = "5";
    $.request('onNoTwitterApi', {
        data: {twitterusername: twitterusername, endpoint: 'timeline', count: notweets},
        success: function (jsondata) {
            var data = $.parseJSON(jsondata);
            var i = 0;
            $.each(data, function () {
                i++;
                if (this['error']) {
                    $('#twitter-feed1').append('');
                } else {
                    $('#twitter-feed1').append('');
                }
            });
        }
    });
});

Edit: wow, not sure what's going on there. It seems to be rendering the html. it shouldn't do that within a 'pre'. strange. You should be able to grab it if you quote this message.

Last updated

wvelez
wvelez

@DMeganoski, now I get the following: "AJAX handler 'onNoTwitterApi' was not found." The script is on the footer partial. Thanks for all your help.

zoombaro2970
zoombaro2970

Hi, I dont know if October can execute a php file directly from a page..

That is because I'm using martin paralax template and when I want to send the form to a php file october sends error: PAGE NOT FOUND

That is my simple code:

<form action="cotizar.php" method="post" class="col s12 center">

I have stored that php file inside every directory and the error keeps

Do you know how to run or call a php file from a october page or partial ?

Last updated

zoombaro2970
zoombaro2970

zoombaro2970 said:

Hi, I dont know if October can execute a php file directly from a page..

That is because I'm using martin paralax template and when I want to send the form to a php file october sends error: PAGE NOT FOUND

That is my simple code:

<form action="cotizar.php" method="post" class="col s12 center">

I have stored that php file inside every directory and the error keeps

Do you know how to run or call a php file from a october page or partial ?

Ok, I solved it.

.htaccess rules redirect all to CMS

So I do an exception to a new directory, just add this before REQUEST_FILENAME rule like this:

RewriteCond %{REQUEST_URI} !^/yourdirectory
RewriteCond %{REQUEST_FILENAME} -f

I think that this is not a best practice .. but October claims to be The platform that gets back to basics, so .. this is basic to me !!

janedoe
janedoe

same problem i am facing with a jquery plugin if there is way which can convert this jquery plugin to octobercms plugin.

Apoculos
Apoculos

zoombaro2970 said:

zoombaro2970 said:

Hi, I dont know if October can execute a php file directly from a page..

That is because I'm using martin paralax template and when I want to send the form to a php file october sends error: PAGE NOT FOUND

That is my simple code:

<form action="cotizar.php" method="post" class="col s12 center">

I have stored that php file inside every directory and the error keeps

Do you know how to run or call a php file from a october page or partial ?

Ok, I solved it.

.htaccess rules redirect all to CMS

So I do an exception to a new directory, just add this before REQUEST_FILENAME rule like this:

RewriteCond %{REQUEST_URI} !^/yourdirectory
RewriteCond %{REQUEST_FILENAME} -f

I think that this is not a best practice .. but October claims to be The platform that gets back to basics, so .. this is basic to me !!

Zoombaryo, can you give anymore details on what you did here?

I would love to execute just normal php scripts.. without having to do it in an "october" way. I setup some rules in the htaccess file for my directory.. but it does not work for me. I am basically just trying to access a php script to generate some xml for a jquery function.

RewriteCond %{REQUEST_URI} !^/scripts

RewriteCond %{REQUEST_FILENAME} -f

Last updated

1-14 of 14

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.