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.


build_url() question

Login / Search

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

Community saint

I was working on a block, to show random images from the gallery.    It all works, you can see it here:

Air-RC Home - Air-RC

it works, all but the links to the images.    I use

Code (php)

$i_link = build_url(array('page'=>'_SELF','type'=>'image','id'=>$row['id'],'root'=>($root=='root')?NULL:$root),'_SELF');

this works in my gallery mod I was working on, but from the main screen obviously _SELF does not work to point to the gallery.   How do I get it to point to my gallery instead?

Thanks
Paul

Paul
Back to the top
 
Posted
Rating:
#78170
Avatar

Community saint

Well, I figured it out, but it is hard coded, and I know the function says not to hard code that.

Code (php)

$i_link = build_url(array('page'=>'_SELF','type'=>'image','id'=>$row['id'],'root'=>($root=='root')?NULL:$root),'mgalleries');

just put in the name of the 'zone' as the last item, in place of _SELF.    Any ideas how to reference the zone (which is not the one the user is currently in) without hard coding it?


Paul
Back to the top
 
Posted
Rating:
#78171
Avatar

Community saint

Oh, for those interested, here is all the stuff I made to make the block.

obviously 'mgalleries' needs to be changed to whatever we find out is the proper way to do it without hard coding, or the name of your gallery 'zone' if you made it other than in the welcome zone as I did.

Also obviously the thumb_url that get's passed to the template needs to be changed, I hard coded that one too as I don't know what function returns the base url for your site.

format used is:

Code

[block param='x']main_gallery_random[/block]

x is the # of images to display.

sources_custom\blocks\main_gallery_random.php

Code (php)

<?php

class Block_main_gallery_random
{

    function info()
    {
        $info=array();
        $info['author']='Paul Arbogast';
        $info['organisation']='www.air-rc.com';
        $info['hacked_by']=NULL;
        $info['hack_version']=NULL;
        $info['version']=1;
        $info['locked']=false;
        $info['parameters']=array('param');
        return $info;
    }


    function run($map)
    {

        require_code('galleries');
        require_lang('galleries');
        require_code('galleries2');

        $num_images=array_key_exists('param',$map)?intval($map['param']):3;
        $content=new ocp_tempcode();
        $position = 0;
        $root=get_param('root','root');

        $title="Random Gallery Images";

        $image_data=$GLOBALS['SITE_DB']->query('SELECT * FROM '.get_table_prefix().'images ORDER BY RAND() DESC LIMIT '.strval($num_images));

        foreach ($image_data as $row)
        {
              $i_comments = get_translated_tempcode($row['comments']);
              $i_submitter = $row['submitter'];
              $i_validated = $row['validated'];
              $i_add_date = get_timezoned_date($row['add_date']);
              $member_id=get_member_id_from_gallery_name($row['cat']);



              if (has_category_access(get_member(),'galleries',$row['cat']))
              {

                if (get_db_type()!='xml')
                {
                  $row['image_views']++;
                  $GLOBALS['SITE_DB']->query_update('images',array('image_views'=>$row['image_views']),array('id'=>$row['id']),'',1);
                }

                $i_link = build_url(array('page'=>'_SELF','type'=>'image','id'=>$row['id'],'root'=>($root=='root')?NULL:$root),'mgalleries');


                if ($position==0) {

                  $content->attach(do_template('GALLERY_RECENT_IMAGES_ITEM_LEFT',array('_GUID'=>'332a19b6a72505f8e1eb4d288df247ce',
                               'ID'=>strval($row['id']),
                               'CAT' => $row['cat'],
                               'THUMB_URL' => 'http://www.air-rc.com/'.$row['thumb_url'],
                               'VIEW_IMAGE' => $i_link
                               )));
                  $position = 1;
                } elseif ($position==1) {
                  $content->attach(do_template('GALLERY_RECENT_IMAGES_ITEM_MID',array('_GUID'=>'332a19b6a72505f8e1eb4d288df247ce',
                               'ID'=>strval($row['id']),
                               'CAT' => $row['cat'],
                               'THUMB_URL' => 'http://www.air-rc.com/'.$row['thumb_url'],
                               'VIEW_IMAGE' => $i_link
                               )));
                  $position = 2;
                } else {
                  $content->attach(do_template('GALLERY_RECENT_IMAGES_ITEM_RIGHT',array('_GUID'=>'332a19b6a72505f8e1eb4d288df247ce',
                               'ID'=>strval($row['id']),
                               'CAT' => $row['cat'],
                               'THUMB_URL' => 'http://www.air-rc.com/'.$row['thumb_url'],
                               'VIEW_IMAGE' => $i_link
                               )));
                  $position = 0;
                }
              }
        }
        return do_template('GALLERY_RECENT_IMAGES',array('_GUID'=>'332a19b6a72505f8e1eb4d288df247ce',
                          'TITLE'=>$title,
                          'CONTENT'=>$content));


    }

}

 


Last edit: by Arbo

Paul
Back to the top
 
Posted
Rating:
#78173
Avatar

Community saint

GALLERY_RECENT_IMAGES.tpl

Code

{+START,BOX,{TITLE},,{$?,{$GET,in_panel},panel,classic},,,}
   {+START,BOX,,,light}
       <table width='100%'>
       {CONTENT}
       </table>
   {+END}
{+END}

GALLERY_RECENT_IMAGES_ITEM_LEFT.tpl

Code

<tr>
  <td>
    <a href={VIEW_IMAGE*}><img style='display: block; margin-left: auto;margin-right: auto' src={THUMB_URL*}></a>
  </td>

GALLERY_RECENT_IMAGES_ITEM_MID.tpl

Code

  <td>
    <a href={VIEW_IMAGE*}><img style='display: block; margin-left: auto;margin-right: auto' src={THUMB_URL*}></a>
  </td>

GALLERY_RECENT_IMAGES_ITEM_RIGHT.tpl

Code

  <td>
    <a href={VIEW_IMAGE*}><img style='display: block; margin-left: auto;margin-right: auto' src={THUMB_URL*}></a>
  </td>
</tr>

Probably a better way with CSS and such, but it is what it is.

Of course the code could be modified to only do two rows and only use _LEFT and _RIGHT template.  That's how mine started but due to my layout I thought 3 wide was better.

Paul

Paul
Back to the top
 
Posted
Rating:
#78176
Avatar

:).

'_SELF' is just a shorthand to refer to the current page (if in the array of params) or the current zone (if passed as the zone parameter). It's used inside module code so as to make it possibly to rename a module without having to change its own code.

Instead of '_SELF' you would literally type the name of the page being linked to, i.e. 'galleries'. And the name of the zone, or a call to get_module_zone to do a smart search.

So whilst code written inside the galleries module might say:

Code

build_url(array('page'=>'_SELF',...),'_SELF')

Code external to it (i.e. running out of context) might say:

Code

build_url(array('page'=>'galleries',...),get_module_zone('galleries'))


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:
#78209
Avatar

Community saint

surprisingly, that does not work.   I created a zone that galleries, called 'mgalleries'.   I tried the get_module_zone with galleries and mgalleries, and neither returns a value, so the url comes out

 air-rc.com/index……

instead of

  air-rc.com/mgalleries/index….

so it seems get_module_zone is not returning anything.

Oh well, it works hard coded.

Thanks
Paul

Paul
Back to the top
 
Posted
Rating:
#78211
Avatar

get_module_zone('<pagename>') returns a zone name when that page is. If your page in the mgalleries zone is called galleries, and you have the single-public-zone (aka collapse zones) option on it would have found the standard galleries module in the root zone ('') instead, because it has a search order.


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
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: