HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Advise/help - making script

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#44474 (In Topic #9852)
Avatar

Honoured member

Hi there,

what should I use miniblocks of minimodule or something else to make my script.
I looked at the tutorials but I didn't realy find my answer there to give it a place.

What I'm trying to make is a kind of comcode for my forum to hide text and only show
it to users who replyed on it. (or the topic owner)

Currently I was making it as a miniblock that works fine, but when I have to use some variables
that are being used (to get the topic_id) I know they are used somewhere in the class to get
the topic info.

How do I get access to those variables or do I have to modify the ocf scripts?

Any advise?
Back to the top
 
Posted
Rating:
#44483
Avatar

Hi,

I think I understand your problem. You want to make a block that understands the context it is placed in. So if it's placed in a post, it needs to understand the context of that post's topic and be able to make decisions based on that.

That's interesting. You could just read URL parameters and make it work like that. But that's not very reliable as the post could be shown in many places (e.g. as a search result). Generally speaking ocPortal wasn't designed for blocks to ever understand their context. They make all their decisions based on global certainties (e.g. reading the DB) or by the parameters they take.

So one workaround would be to pass in a parameter to the block that is the topic ID it is to go in:

Code

[block topic_id="432"]my_example_block[/block]

Then the block just needs to use $map['topic_id'].

A couple of problems with this:
  • You don't know the topic ID until you've created the topic, so the post would need editing.
  • It's not very user-friendly (probably ok for staff to use, but not regular users).


I've thought of another solution. The OCF_TOPIC_POST template takes a parameter {TOPIC_ID}. You could add a bit of code to the start of that template:

Code

{$SET,MOST_RECENT_TOPIC,{TOPIC_ID}}
then in your block you could do:

Code

global $TEMPCODE_SETGET;
if ((isset($TEMPCODE_SETGET['MOST_RECENT_TOPIC'])) && (!is_guest()))
{
$has_posted_in=$GLOBALS['FORUM_DB']->query_value_null_ok('f_posts','id',array('p_poster'=>get_member(),'p_topic_id'=>$TEMPCODE_SETGET['MOST_RECENT_TOPIC']));
if (!is_null($has_posted_in)) // they have a post in the topic
{
// ...
}
}

The only problem with this code is that it only works when viewing the topic directly. But that's probably fine.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#44484
Avatar

Thinking about this some more, a better solution than a block might be to make a symbol.

1)

The same OCF_TOPIC_POST template change would be needed.

2)

You'd make a new sources_hooks/systems/symbols/MEMBER_HAS_POSTED_HERE.php file:

Code

<?

class Hook_symbol_MEMBER_HAS_POSTED_HERE
{
   function run($param)
   {
      if (!array_key_exists(0,$param)) return '_false';
      $topic_id=intval($param[0]);
      $has_posted_in=$GLOBALS['FORUM_DB']->query_value_null_ok('f_posts','id',array('p_poster'=>get_member(),'p_topic_id'=>$topic_id));
      if (!is_null($has_posted_in)) return '_true';
      return '_false';
   }
}

?>

I noticed a little bug in our sources/symbols.php that would stop this working.

Code

               $value=$EXTRA_SYMBOLS[$name]['ob']->run();
needs to be:

Code

               $value=$EXTRA_SYMBOLS[$name]['ob']->run($param);
(i.e. our code didn't pass through any symbols parameters, which you need here). This little fix will be in the next release also.

3)

Your Comcode would look like:

Code

{+START,IF,{$MEMBER_HAS_POSTED_HERE,{$GET,{TOPIC_ID}}}}
You have posted here
{+END}



Architecturally this is a lot cleaner and more in-tune with the ocPortal design. (I haven't tested any of this though.)


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#44489
Avatar

Honoured member

Hi Chris,

Thanks for replying and explaining (making kind of script).

I will try this out tomorrow because currently I'm busy with helping someone with
her computer (that got distroyed by avg).

I let you know if it works or not.

Again thnx
Back to the top
 
Posted
Rating:
#44491
Avatar

Honoured member

Chris,

2)

You'd make a new sources_hooks/systems/symbols/MEMBER_HAS_POSTED_HERE.php file:

You mean sources_custom/hooks/systems/symbols/MEMBER_HAS_POSTED_HERE.
php ??

the folder symbols doesn't exists there does it needs to be created as while?
Back to the top
 
Posted
Rating:
#44494
Avatar

Whoops, sorry yes. And yes, you need to make the folder.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#44513
Avatar

Honoured member

Hi Chris,

I edited the OCF_TOPIC_POST and the symbols.php
and added the hooks to my sources_custom/hooks/systems/sysmbols

but I receive the following error:

A parameter, TOPIC_ID, is referenced in the template, , but not passed


The text of the topic/post is showen left top of the screen.

-Edit-
Hmm it seems not to be the text from the post but only the word testing
I didn't add this anywhere :/

Not sure what I did now but I receive this message:
Fatal error: Cannot use object of type Hook_symbol_MEMBER_HAS_POSTED_HERE as array in */sources/symbols.php on line 1502


Last edit: by boomerirc
Back to the top
 
Posted
Rating:
#44518
Avatar

Another bug in sources/symbols.php…

Code

$EXTRA_SYMBOLS[$name]=object_factory('Hook_symbol_'.filter_naughty_harsh($name));
should be:

Code

$EXTRA_SYMBOLS[$name]['ob']=object_factory('Hook_symbol_'.filter_naughty_harsh($name));

and the Comcode should have been:

Code

{+START,IF,{$MEMBER_HAS_POSTED_HERE,{$GET,TOPIC_ID}}}
You have posted here
{+END}

Hopefully that'll sort it.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#44521
Avatar

Honoured member

Hi Chris,

Thanks for replying, only when I push on the preview button I still get the message that it is missing the TOPIC_ID

Code


A parameter, TOPIC_ID, is referenced in the template, OCF_TOPIC_POST, but not passed


When I save it and reply on the post
it doesn't show that I have posted..

I checked the state it returns and that's _false I will have a look at the php file

-edit-

TOPIC_ID doesn't return any results.

It looks like the MEMBER_HAS_POSTED_HERE.php doesn't get any param's from the script at all.


Last edit: by boomerirc
Back to the top
 
Posted
Rating:
#44546
Avatar

Hi,

Small change to what I said for OCF_TOPIC_POST is needed:

Code

{+START,IF_PASSED,TOPIC_ID}
{$SET,MOST_RECENT_TOPIC,{TOPIC_ID}}
{+END}

I'd forgotten the preview doesn't pass a topic ID in.


For the other problem, are you sure you made the symbols.php change that passes in $param to run()?


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#44551
Avatar

Honoured member

about the param this is what I have (just a snap out of the source)

Code

 if (array_key_exists($name,$EXTRA_SYMBOLS))
 {
 if (!array_key_exists('ob',$EXTRA_SYMBOLS[$name]))
 {
 require_code('hooks/systems/symbols/'.filter_naughty_harsh($name));
 $EXTRA_SYMBOLS[$name]=object_factory('Hook_symbol_'.filter_naughty_harsh($name));
 }
 $value=$EXTRA_SYMBOLS[$name]['ob']->run($param);
 break;
 }
 $value='';
 $GLOBALS['DEFERRED_ERRORS'][]=do_lang_tempcode('MISSING_SYMBOL',escape_html($name));

I did a print_r return of the param, and the hook knows that it is a array, only it's empty.
Back to the top
 
Posted
Rating:
#44553
Avatar

Ok I've actually tested it now  :lol: .

The Comcode should have been:

Code

{+START,IF,{$MEMBER_HAS_POSTED_HERE,{$GET,MOST_RECENT_TOPIC}}}
You have posted here
{+END}

Otherwise it works.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#44558
Avatar

Honoured member

So if I understand you, it works fine for you?

I just tryed at my forum but it doesn't display the "You have posted here"


Uhmm ps. it should be comcode tag?
Back to the top
 
Posted
Rating:
#44560
Avatar

I didn't think of it as a custom comcode tag but that's a good idea. Could you tried it just as plain Comcode? That does work for me.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#44561
Avatar

Honoured member

Not sure what happend, plain comcode works fine.

When I try comcode tag now it works fine too…
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: