Categories > TinyButStrong general >

Joomla 2.5+ > TBS > Accessing Joomla Article ID

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Bruce Decker
Date: 2012-12-11
Time: 20:29

Joomla 2.5+ > TBS > Accessing Joomla Article ID

The TBS plug in for Jooma passes three handy arrays as discussed in the Plug-in manual on this site.  Namely:
    $TBS->JoomlaArticle: A reference to the article that is being rendered by the view. For example: $TBS->JoomlaParams->title and $TBS->JoomlaParams->id
    $TBS->JoomlaParams: A reference to an associative array of relevant parameters.
    $TBS->JoomlaLimitstart: An integer that determines the "page" of the content that is to be generated.
However, I've discovered on Joomla 2.5, that the reference $TBS->JoomlaParams->id does not hold the id as it did on prior Joomla releases.  Looking at code, I see that the plugin code simply passes the $article array into $TBS in the main tinybutstrong script.  The underlaying issues is that it appears the Joomla no longer stores the article id in the $params array nor does it seem to occur in $article or $limitstart which are also explosed in $TBS array.

so, my solution was to modify the main script in the //Wrappers to developers section as follows:

        // Wrappers for developpers;
        $TBS->JoomlaArticleId = &$ArtId;  // added by Bruce Decker   

        $TBS->JoomlaParams = &$params;

        $TBS->JoomlaLimitstart = &$limitstart;

        $TBS->JoomlaArticle = &$article;


So now I can reference the article id in my article as $TBS->JoomlaArticleId

I wonder if this should be folded into the code and the documentation updated or if I've missed a simpler solution?
By: Bruce Decker
Date: 2012-12-11
Time: 23:21

Re: Joomla 2.5+ > TBS > Accessing Joomla Article ID

Upon looking at this further, I think there are a few issues:

1) Joomla no longer keeps the Article ID in the $params array, it's now in the $article array
2) We pass only the $article->text portion of the article tot he initialization routine... see below

[CODE]
tbs_plugin_InitTBS($TBS, $article->text);
[/CODE]

So, the additional elements of the $article array are effectively stripped and since the stripped version of $article is all that is picked up by the $TBS wrapper code, the article ID is not added.

So, the above solution still works but I think that perhaps it would be better to add another array to $TBS called, perhaps, JoomlaFullArticle which carries _all_ of the Joomla $article elements.

Here is my mod to the main scripts doing it this way:

[CODE]
    $ArtId = $article->id;
        $FullArticle = $article; // * Added by Bruce Decker


        if (!tbs_plugin_CheckArticle($ArtId)) return ''; // Exit the plug if the article is not allowed

       

        tbs_plugin_InitTBS($TBS, $article->text);

        tbs_plugin_SqlDbInit($TBS); // retrieve SQL information and them them as custom property of $TBS



        // Wrappers for developpers; 

        $TBS->JoomlaParams = &$params;

        $TBS->JoomlaLimitstart = &$limitstart;

        $TBS->JoomlaArticle = &$article;
       
        $TBS->JoomlaFullArticle =&$FullArticle; //added by Bruce Decker
[/CODE]

By making a copy of the $article array before it gets stripped by the initialization function, we can then add it to the $TBS array as a developer wrapper and the entire article should be sent across to the article including the id.

The documentation will need to be changed in the Plug-in manual from:

[CODE]
Three properties are given by the TinyButStrong plug-in to retrieve information about the current Joomla context:

    $TBS->JoomlaArticle: A reference to the article that is being rendered by the view. For example: $TBS->JoomlaParams->title and $TBS->JoomlaParams->id
    $TBS->JoomlaParams: A reference to an associative array of relevant parameters.
    $TBS->JoomlaLimitstart: An integer that determines the "page" of the content that is to be generated.
[/CODE]

TO:

[CODE]

For Jooma 1.6 and above:
Note: To fit the new structures of Joomla 1.6 and above, the following should be noted for references to the $TBS array:

Three properties are given by the TinyButStrong plug-in to retrieve information about the current Joomla context:

    $TBS->JoomlaFullArticle: A reference to the article that is being rendered by the view. For example: $TBS->JoomlaFullArticle->title and $TBS->JoomlaFullArticle->id
    $TBS->JoomaArticle->text A reference to only the Joomla Article Text (not the entire article array with all params (see JoomlaFullArticle)
    $TBS->JoomlaParams: A reference to an associative array of relevant parameters. (Note: JoomlaParams->id was deprecated at Joomla 1.6,  See JoomlaFullArticle->id)
    $TBS->JoomlaLimitstart: An integer that determines the "page" of the content that is to be generated.
[/CODE]

I thought about adding a 'id' element to the JoomlaParams array for legacy compatibility but was concerned that I might muck-up the works internally.  But that would be nice if it could be done cleanly.

This research, code and opinion is donated to the project (if any of it is deemed worthy of consideration).
By: Skrol29
Date: 2012-12-14
Time: 00:07

Re: Joomla 2.5+ > TBS > Accessing Joomla Article ID

Hi Bruce,

Thank for sharing this study and code.

Why is it particularly interesting to retrieve the article ID in the  Dynamic TBS Article ? I mean: Joomla can move other properties from Params to Article. Why should we have a enhancement for this once?

Another point your study is showing out is that  Dynamic TBS Articles cannot be displayed in stripped mode. But I can see lot of situations when such a dynamic article could be a problem if display striped or to display fully when stripped is expected. For example, how to behave in stripped mode when the Dynamic Article have user inputs?
By: Bruce Decker
Date: 2012-12-14
Time: 00:37

Re: Joomla 2.5+ > TBS > Accessing Joomla Article ID

Hi Skrol:
To answer your questions:

Why is it particularly interesting to retrieve the article?
I have a TBS plug-in that is called write a record to a database that consists of the user id, article id and timedate.  I use this to create a log of who has viewed a article.  I used TBS because I like it and I can create the script for performing this logging out of a tbs {script=} call.  But the script needs to know the ID of the article.  In SEF mode, it was cumbersome to try to get the article ID from the URI so I started to think that perhaps the article ID might be somewhere within $TBS.  I saw the reference to $TBS->JoomlaParams->id in the manual and thought it would be a perfect way to get the article id for my script.  But, then I discovered that Joomla had moved id out of $params into $article.  The problem then was that the main tbs script was putting only the $article->text into $TBS so while the article id was there in Joomla's $article array, I could not access it via $TBS and $article was not exposed, as far as I could tell, within my tbs script.  I remembered that in the TBS content plug-in, you could tell TBS only to function with certain article IDs.  So I started looked at TBS code and found in the main script where you were passing $article->text to OnContentPrepare and then within a function where you were loading the $TBS arrays.  I didn't want to touch the passing of $article->text to $article because I thought it might disrupt other areas of TBS.  So, I copied $article to my own variable so that I could later pass it $TBS and get _all_ of $article rather than just $article->text in $TBS.

I see the issue with stripped mode but hadn't considered that when I wrote this.  I'm using the term 'stripped' to mean that $article was 'stripped down' to only $article->text when passed to $TBS in the developer wrapper section.  I'd be happy if $TBS->JoomlaArticle->id was available but the only element available is $TBS->JoomlaArticle->text as far as I can tell. 

My study and mode was an attempt to have the article id as found in $article->id exposed via $TBS and to do no harm to other functions in TBS that may have problems if I was to otherwise manipulate $article in order to allow other elements of $article to be passed.

At the end of the day, it does not matter to me where id can be found so long as it is available (like it was under J1.5 in $TBS->JoomlaParams.

TBS is wonderful and non of this is meant as criticism but offered only in the spirit of helping to keep this great tool in sync with the changes in Joomla.

Thanks again Skrol.