Shortcodes for non-wordpress custom CMS - php

Trying to implement my own "shortcode"-type system on my cms.
substr() can possibly work as long as there isn't more than one shortcode in the content. I can't use <?php ?>, but must use a WYSIWYG type editor for entering in the shortcode, since it is the enduser who will be entering them via the content editor.
If someone enters a "Shortcode" that follows the rules I set, this class function will discover the shortcode, parse it and then replace the shortcode with other data pulled from mysql or another source.
I can get this to work, essentially no problem, if there is not more than one single shortcode entered into the content via WYSIWYG, but more than one and it breaks.
I've looked all over the internet for this and found various things, but most of them deal with Wordpress and the few that don't aren't approaching it as I need to. Found one threat on StackOverflow which provides a potential approach that I could use, but I really need advice and a place to start more than a full function. The Wordpress Shortcode system isn't helpful either.

Related

Dynamic content in PHP WordPress page

I have a ecommerce store website running with WordPress. I'd like to include a section with a -random custormer's product review, so that every time someone access the page, there will be a different comment there.
I'm not used to PHP, but I managed to create a shortcode which takes a random comment and returns the proper HTML. It is working fine (in eddition mode, every time I insert the shortcode a different comment appears).
My issue is that when I leave the page and return, the previous one is still there. I believe that it is being caused by cache, but I wouldn't like to disable the cache for the whole page.
How you I force the shortcode run again (I don't know if it is the right way to explain) and make sure that at every access, a different comment appears?
One solution I thought is to have JS code which would do preaty much the same thing my PHP code does, using Woocommerce API to get the data. But I'm wondering if there is a simpler solution to do that, like forcing the specific section not being cached or re-run the shortcode.
Thanks!
JS can't do what PHP does here: at most it can create an AJAX-call to the backend that then runs a query for a random comment and returns it. You need to render it thereafter. It's fairly standard, but overkill for your case.
Instead, you're going to want to check whether your caching mechanism supports ESI or something else that excluded parts of your code from being cached.

Find a process to check if a shortcode is/was present in a post : Something wrong in my tries

My purpose is to set some treatment options of the theme which depends of the presence of some shortcodes (and their parameters).
Detailed purpose, reasons of the need for information
In this way the user can define theme options into the "page" or the "article" (I meet this because the site needs some pages and articles as text displayed in single column, like a book and a side bar, while others using multimedia need full width on a PC with several panels).
what fails :
The shortcode is executed but I cannot get back into the theme that it has been and get the parameters for the execution of the theme.
The structure that I have implemented
the shortcode is defined into a class of a plugin
the shortcode function sets some values into the object of the plugin
class
several public functions of the object called by the theme return status and parameters
memorized into the object
Something wrong into this process
There is something wrong because when "page.php" is run the function included which asks to the object if the shortcode function has been run answers "not run".
This while it can be verified some line after (getting the post content) that the post displayed is with the shortcode treated.
Further when "sidebar" is executed the same question is answered "true".
May be
May be my concept is wrong because the process treatment of the post (shortcodes particularly) is done only when the content of the post is output by "the_content()" WP function (later and too late into the page.php) ?
If this is true I should have to analyse myself the content of the post before any treatment.
Nothing seems to be told about this (or not found) into the Wordpress Codex.
Question
Do you have any idea.
I have some ones for a solution but if the cause that I imagine is wrong I would have produced something too complicated.
Best regards
Trebly
Thanks for your informations.
During the short time since I post this subject I have developed the solution.
I confirm that the problem is that when you write
$pt = $post->get_content();
you get get the raw content before any shortcode treatment.
It is when you write into your theme
-?php the_content() ?-
that the shortcodes are treated and the result is buffered.
Then I read my $pt and search for the requested shortcode. If I find it, I analyse, get parameters and execute.
But this is not ended because you need to clear the shortcode or any other with a purpose of same type but not treated into your branch of code (the best is to not change the post_content). This is done by my process, the function called by the shortcode returning an empty string.
This is a mean to give instructions to the template about how to behave with the current content ( by the html content of pages, articles or others post lists).
Nevertheless it is not always possible for any content because many contents are introduced by shortcodes and you cannot generally give instructions at the second level. I say "generally" because you can develop shortcodes which will use a callback function launched before ob is sent. Then you can analyse the ob and make some changes. This is the theoretically impossible second level.
It is not easy to manage encoding but it is the way that I uses to produce Tables of Contents (headers or others user tags) for any output of WP.
Best regards
Trebly

conflicting functions when using two includes (mybb and wordpress)

I use MyBB for forum and Wordpress for blog. When I try to integrate both together into a page, I get conflicts between functions. The forum header and the wordpress includes have some functions with the same identifier.
I need both functions but I obviously can't change the name of something inside wordpress or mybb.
What are the solutions to these conflicting problems?
Can I deinclude an included file?
If I could use iframe then it wouldn't look good with the scrolls and the border. If this is the only way then how can I remove the border and the scrollbars so that it would look exactly the same when the code was in the original page itself?
First of all: That is a hell of a task.
Still thou, if you aim to do it, read up on namespaces.
I figure it is possible to add those to all wordpress classes and all myBB classes.
You would have to do a lot of rewriting, but some search and replace tools using regular expressions should be able to help you with that.
You could also try to havew them seperately (yourdomain.com/myBB and yourdomain.com/wp) and integrate them via webservices. So you myBB would access wordpress data via RSS?

How to Implement {script}folder/file{/script}

I am looking to build a plugin for Joomla that will allow me to play video using HTML5 first before resorting back to Flash. In my effort to make this plugin in more dynamic I would like to have an easy way of embedding the video. In similar plugins I have seen where the user can put in a specific phrase surrounded with brackets. Something similar to the following:
{html5video}media/video{/html5video}
What is this method called and where can I find more information on how to implement it into a plugin?
As per my knowledge there is no specific term defined in Joomla for this method, but those who are much familiar with Wordpress calls it SHORTCODE method
You will need to create a content plugin -
use regex , php preg_match_all and extract this string and replace with your desired code.
One such plugin is available in Joomla. You can check it in plugins\content\loadmodule
You may need to modify the regex pattern used in this plugin

PHP wordpress style related posts

Do you know how wordpress decides which related posts to show?I mean I know if it has tags, then it's easy but if it doesn't?
Best Regards,
Generally the 'related post' function of a Wordpress Blog is created by the owner of the blog, or using a plugin. I can imagine that those plugins either look for new posts with similar tags or in the same category as the post it is displaying.
As far as my knowledge extends, I do not believe that Wordpress has a show_related_posts function, although I may be wrong. If it does, it would be simple enough to look it up on the documentation at wordpress.org.
Also, another good part about OpenSource programming is that you can simply go in and look at any of the code that you are curious about. I personally use Notepad++, and when I find a function in Wordpress or any other CMS I am not famillar with, I simply copy and paste the function name, and do a Multi-File search on the function to figure out where it is declared.
I'm going to have to go with Chacha102, as far as I know this can only be done using plugins or by hacking the code yourself.
I did something similar by falling back on the post's category if it had no tags, works pretty well too.
This guy has the leading plugin for related posts. I'd download that and take a peek at his code and see how he does it. Then you can reverse engineer it and make it your own. The beauty of opensource.
http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/

Categories