solved Convert PHP file for use in Smarty template

alt=
Brodephat
@brodephat
6 years ago
7 posts
Hello,

I have been and still am looking for how to convert a php file I now use for use in the Jamroom smarty engine.

I currently have a php file that is used to post to Twitter when called upon.
The message that gets posted is dropped into the php file from a variable when it is called.

Like such:

https://example.com/post.php?message=Hello

The php file grabs the value of message from the URL call and uses it to make the post

When the php file is called it will not display anything because it's not needed.

I want to use Jamroom so that when a user creates their account, they can enter the needed Twitter API keys into their profile and the system would generate the template using those values to do what the stand alone php file does. The values do not need to be displayed to the end user or visitor, just used to do the same thing the current php file is doing.

The template can be hidden from view but must be accessible via a URL in the browser per user account.

I purchased the Form Builder and learned how to add the API key fields to the users profile info.

Does doing this require creating a module?
Would the template be a profile template or user template?
Can the template work even if the user is not logged in?



updated by @brodephat: 10/31/18 08:42:43AM
michael
@michael
6 years ago
7,692 posts
There is already a module that posts to twitter, its called OneAll

Modules: OneAll
https://www.jamroom.net/the-jamroom-network/networkmarket/47/oneall-social

If you wanted to turn your existing php file into a jamroom module then you can do it that way too.

Yes, everything in jamroom is a module.

The most basic module has a directory, a changelog.txt an include.php and in your case, if you want it to control a URL then it needs an index.php

Example
* call your module xxPost and place it in /modules/xxPost/
/modules/xxPost/changelog.txt
/modules/xxPost/include.php
/modules/xxPost/index.php

/modules/xxPost/changelog.txt
Changelog for Post to Twitter module

Version 1.0.0
 - Initial Release

/modules/xxPost/include.php
<?php
/**
 * @copyright ..........................
 * @author ........ .......... <someone [at] somewhere [dot] com>
 */


// make sure we are not being called directly
defined('APP_DIR') or exit();

/**
 * meta
 */
function xxPost_meta(){
    $_tmp = array(
        'name'        => 'Post to Twitter',
        'url'         => 'post',
        'version'     => '1.0.0',
        'developer'   => 'Sombody Somwhere, ©' . strftime('%Y'),
        'description' => 'Somthing about your module here',
        'category'    => 'custom'
    );
    return $_tmp;
}

/**
 * init
 */
function xxPost_init(){
    return true;
}

That will get your module appearing in the ACP. If you cant see it run the INTEGRITY CHECK. Then go to the INFO tab of the module and check the checkbox to activate it.

Next make it do something
/modules/xxPost/index.php
<?php
/**
 * @copyright ..........................
 * @author ........ .......... <someone [at] somewhere [dot] com>
 */


// make sure we are not being called directly
defined('APP_DIR') or exit();

//------------------------------
// create
//------------------------------
function view_xxPost_message($_post, $_user, $_conf)
{ // the $_post array contains anything coming in on the URL and the _message part of this function is the url. // this function will fire when you visit example.com/post/message // So you can either have the url example.com/post/message/message=hello // then $_post['message'] will equal "hello" or you can skip the name and just use the url example.com/post/message/hello // and "hello" can be found on either $_post['_1'] or $_post['_2'] need to check. // put the contents of your PHP file in this function and return whatever you want echoed to the screen return 'all the processing has completed'; or to return to a different location: jrCore_location("{$_conf['jrCore_base_url']}/somewhere/you/want/to/redirect/to"); }


Docs: "Freelancers Read this"
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/3513/freelance-developers-read-this
updated by @michael: 05/17/18 02:24:21AM
alt=
Brodephat
@brodephat
6 years ago
7 posts
Thanks so much. This will help me off to a better start than I have been trying so far. I used to create stuff for my Jamroom site many years ago and this new version since returning to Jamroom is sooo different.
michael
@michael
6 years ago
7,692 posts
agreed. Ask for anything you get stuck at here. There is a lot to learn about how things connect, but once you get the hang of it its WAY more configurable than it every used to be.

There is a system called "Events and Listeners" that allow you to tap into data before it reaches the screen so you can override modules functionality without changing the module.

Docs: "Events and Listeners"
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/1011/events-and-listeners

and the module developers guide

Docs: "Module developers guide"
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide
alt=
Brodephat
@brodephat
6 years ago
7 posts
Great, I did get the module to shows up.

In version 3, whenever an account is created, a folder containing the files for that account is created. I haven't seen this in version 5, did I miss it somewhere?

Do the modules have the ability to display user profile info of just that user?

In other words as a profile or user url.
michael
@michael
6 years ago
7,692 posts
in jr3 there was {debug}. in jr6 there is still {debug}, its still just as useful. Really useful.

Docs: "{debug}"
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/1477/debug

Put that into any template you want to know what variables are available for.

$_user array is all the stuff of the user looking at the screen
$_post array is all the stuff coming in from the address bar or POST
$_profile array is sometimes avaliable depending on the template, but usually available when looking at a profile.

No, there are no file system files created.

JR6 has a thing called DATASTORES which are key => value database tables and are super useful.

Docs: "datastores"
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/1023/datastores

Any user can have multiple profiles and any profile can have multilple users managing it, so there is no 1:1 relationship.
alt=
Brodephat
@brodephat
6 years ago
7 posts
Okay, so I now have the module grabbing the post data and I have the user submitted data showing up as well.

I don't seem to be grasping how to execute php.

What I'm doing is taking certain values from the _user data and the _post data and running them through a php code to produce a formatted tweet that then gets posted to the Twitter account of the user.

Ohh also I have noticed that when I downgrade a user, they are not able to see the user data they must enter (Twitter api codes) for this to work however the information they posted while upgraded was still available and still usable. I would like to know how to prevent the user data from showing up in the template if they are down graded. Basically if the post url is sent to the profile url everything still shows up making the downgrade ineffective.

I believe it has something to do with profile quotas I think. I'm looking to see what I can find.
michael
@michael
6 years ago
7,692 posts
Brodephat:
... when I downgrade a user....
what does that mean?
alt=
Brodephat
@brodephat
6 years ago
7 posts
I want it so the bottom level is a free level but you don't have access in your profile settings to put in your personal api codes that come from Twitter. If you buy another level (upgrade) you will have access to the form input fields to put in your api codes. If you stop or cancel your subscription, the system moves you back (downgrade) to the free level.

That part works fine but I did notice that even when a user is moved back to the Free level and have no access to the api codes form fields under Profile settings, the values they put in while on level 2 are still there (I guess due to being in the Datastores).
alt=
Brodephat
@brodephat
6 years ago
7 posts
This is how the URL flows: https://www.socialradioads.com/wnia-gospel-radio/tweet/?pass=NotNeeded&artist=21:03&title=Chozen&album=Total%20Attention&cover=2103-totalattention.jpg&requester=Billy&reqmessage=Love%20this%20song%20thanks%20for%20playing%20it!

The link with the variables are generated from another source, then sent to this url where Jamroom is self hosted.

The data comes thru as you will see on the page.

But I'm having trouble understanding where and how to put my current php codes into the module so that the php can process the information.
alt=
Brodephat
@brodephat
6 years ago
7 posts
I put my php in the function but got a blank page. Is the function where it should be placed?

Tags