vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   How to show php widget in article pages only? (https://vborg.vbsupport.ru/showthread.php?t=307585)

SilverBoy 01-27-2014 11:48 PM

How to show php widget in article pages only?
 
Hi

I tried to display a PHP widget in article preview page and hide it from the layout in the section page, but I failed until now :(

So, any body can help me in this? and how can I pass variables to this widget? like parent section id, author name and author id for example?

Another question, how I can show any other widget like "last articles" widget in the article page only and hide it from the section page or show it in section page and hide it in the article preview page? what a specific condition I must add to the template?

Thanks in advance.

SilverBoy 01-29-2014 05:25 AM

Please help !!

tbworld 01-29-2014 05:30 AM

Quote:

Originally Posted by SilverBoy (Post 2477328)
Hi

I tried to display a PHP widget in article preview page and hide it from the layout in the section page, but I failed until now :(

So, any body can help me in this? and how can I pass variables to this widget? like parent section id, author name and author id for example?

Lets see your widget code and maybe I can give you a hand with the first part of your question. The second part of your question confuses me, as I do not understand on what condition you need to display the widget -- except not on both renders.

SilverBoy 01-29-2014 06:01 AM

Thank you for your reply

I tried in the first step to add condition to the widget template (I just use the default php eval widget to understand things), but I didn't figure out what is the condition that I must use in template to say this page is section or article !!

Then I tried to make plugin to bypass variables and stuck there too, I don't know even to let the plugin know which nodeid he is in !!

So by simple words, could you please help me in make widgets appear in article page of some sections (not all article pages) and hide them from their parent sections?

To be more specific, I want to add this php widgets,
1- the last articles from the same author and show it in the articles in opinion section articles only, and of curse it doesn't make sense to show it in the section page it self, so I need to bypass author information to the widget to make the query.
2- the related articles to this article, I already add them as special field in the DB when add/edit articles, so I need to by pass these fields too (It stored in cms_node table)
3- the last articles from this section, so I want to use the default recent article widget but need a condition to prevent it from appearing in the section page.

And of curse I need to bypass the issection value to the widget to display the widget of hide it.

I wish I made things clear to you now :).

Thanks in advance.

--------------- Added [DATE]1390979373[/DATE] at [TIME]1390979373[/TIME] ---------------

I forget the forth widget that I want, I want to add the most popular articles widget (the code of it is here in vb.org) but want to show it for the current section not for the whole site, so I need to bypass sectionid to it to modify the query.

Thanks.

tbworld 01-29-2014 06:20 AM

If you show your code, I will try to assist you in what you are working on, but only one step at a time. So I only need to know what your current programming question is and how I can exactly help you. I am replying to your request for help because you seem adept enough to handle this. If you need someone to do this for you please submit your inquiry to the unpaid/paid request forums.

Quote:

I tried in the first step to add condition to the widget template (I just use the default php eval widget to understand things), but I didn't figure out what is the condition that I must use in template to say this page is section or article !!
Show me the code and your condition for this widget... and carefully explain what you want (just) this conditional to do. :)

Have you successfully cloned a widget by using a new template? This is where you would add the additional template conditionals and variables you require -- of course they would have to be available from the PHP code.

SilverBoy 01-30-2014 01:01 AM

Hi again and thanks for your caring :)

Actually I can't give you all attempts that I made because they are a lot (I was trying for 3 days without any luck).

But here is the main things that I did
1- I duplicated the template that used by php eval widgets and name it the same name with "test" at the end.
2- I checked the cms_node table and find that the main fields that I must concentrate on are nodeid and issection.
3- I tried to add set of conditions to the template that I made without any luck.
4- I find the way to get the nodeid in the widget and print it in the widget it self and this is very big step but the problem that I faced here is the cache problem, the same nodeid printed in the widget in any section or article, so this make me crazy and if I make the full code to show what I want it will not updated in time !!

here is the code of the widget
PHP Code:

$mycontentid $this->content->getNodeId();
$issecion_get vB::$db->query_first("SELECT nodeid, issection FROM ".TABLE_PREFIX."cms_node WHERE nodeid = '$mycontentid'");
$output '';
$output .='<div class = "cms_widget_post_bit"><h4 class="cms_widget_post_header">'.$issecion_get[nodeid].$issecion_get[issection].' </h4></div>'

This widget shows the right nodeid and issecion values but need to remove the cache !!

Then for the template it self to display the widget or hide it I tried to make a plugin using this code
PHP Code:

$mycontentid $this->content->getNodeId();
  
$issecion_get vB::$db->query_first("SELECT nodeid, issection FROM ".TABLE_PREFIX."cms_node WHERE nodeid = '$mycontentid'");
 
$issecion $issecion_get[issection];
 
$mynodeid $issecion_get[nodeid]; 

but I don't know what is the propriate hook must I use, I tried too many hooks without results !!

and in the widget template I add a condition regarding the valuse of this code
HTML Code:

{vb:raw issection}<br>{vb:raw mynodeid}
<vb:if condition="!$issection">
<div class="cms_widget">
<div class="block">
<div class="cms_widget_header widget_header">
        <h3><img src="{vb:stylevar imgdir_siteicons}/php.png" alt="" /> {vb:raw title}</h3>
</div>
<div class="cms_widget_content widget_content">
{vb:raw output}
</div>
</div>
</div>
</vb:if>

You note that I even tried to print the values before rendering the widget but without luck too.

So please help me in this tow things:
1- disable the cache for this widget.
2- make the right condition using the plugin or any better way to can control when I want to show the widget and when I want to hide it.

At the end, this is something like case study and I think many users will get benefit of this if we can implement it, and you can imagine how many things you can do with php widgets if you get the power points of them.

Thanks in advance.

--------------- Added [DATE]1391049060[/DATE] at [TIME]1391049060[/TIME] ---------------

Another point, I want a way to control the cache time for php evaluation widgets, because I think in some widgets that are fixed in their section and don't need to refresh with every page load.

tbworld 01-30-2014 01:57 AM

Thanks for posting in detail, I will get bck to you after I review all this... :)

SilverBoy 01-30-2014 02:01 AM

Thank you, and your effort very appreciated.

Dead Eddie 01-31-2014 01:01 AM

Quote:

Originally Posted by SilverBoy (Post 2477854)

So please help me in this tow things:
1- disable the cache for this widget.
2- make the right condition using the plugin or any better way to can control when I want to show the widget and when I want to hide it.

0. You already have access to the content's properties. $this->content->getUsername(); $this->content->isSection(); etc. Look at the public functions of vBCms_Item_Content & vBCms_Item_Content_Article for the methods you can call.

You really don't need to directly query the database again for on-page content.

1. Caching is done in vBCms_Widget_ExecPhp::getPageView() between lines 174 & 175. For testing, I added the NodeId to the hash to make the cache unique to the current node...you can just comment out the reading of the cache on 175 if you want to.

This was my code in line 174 for testing:
PHP Code:

$hash $this->getHash($this->widget->getId() . $this->content->getNodeId()); 

But, no hooks. You have to modify the code.

2. Again, you'll have to directly modify the widget's code. Around line 173, add the following line:

PHP Code:

$view->issection $this->content->IsSection()?1:0

Then your conditional should work.

My sample widget code:

PHP Code:

$output 'Username: ' $this->content->getUsername() . '<br/>';
$output.='Content Type Id: ' .  $this->content->getContentTypeId() . '<br />';
$output.= 'Is Section: ' .  $this->content->IsSection() . '<br />'

My edited widget class code:

PHP Code:

$view = new vBCms_View_Widget($config['template_name']);
        
$view->class $this->widget->getClass();
        
$view->title $view->widget_title $this->widget->getTitle();
        
$view->description $this->widget->getDescription();
        
$view->issection $this->content->IsSection()?1:0;

        
$hash $this->getHash($this->widget->getId() . $this->content->getNodeId());
        
$view->output vB_Cache::instance()->read($hashtruetrue); 

Edit: In lieu of editing core code, you could also subclass the PHP widget and implement a new getPageView method. You'd have to install a new version of the widget...but it would make your changes less global.

SilverBoy 01-31-2014 01:34 AM

Thank you Dead Eddie for your help, I will make my tests and let you know.
But what about the default widgets like "recent articles widget"? could we make them show and hide as we want?

Now I just have one question, Is the cashing now working for every individual node? not for every widget? if this is write, is this will make any bad impact on the system performance (too many cashing, a lot of memory space to save them)?

Thanks :).

--------------- Added [DATE]1391138658[/DATE] at [TIME]1391138658[/TIME] ---------------

Hi Dead Eddie again
I think with this implementation we will may face some problems regarding other PHP eval exec widgets that didn't need to refresh every time, specially when we talking about high traffic board and CMS, so is there a way to keep caching for other widgets, I mean is there a way to deal with caching time like what other default widgets have and put the value to 0 for widgets that display unique value for every page and make it 30 minutes for example for widgets that display the same thing in all pages?

Thanks in advance.

--------------- Added [DATE]1391139712[/DATE] at [TIME]1391139712[/TIME] ---------------

How stupid I'm :)
I just put 0 in the caching time for this widget and it works fine :)


All times are GMT. The time now is 01:12 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01145 seconds
  • Memory Usage 1,805KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (6)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete