Author Topic: Small add-on for the new release  (Read 578 times)

Offline iceat

  • Posts: 108
  • Gender: Male
    • Medialoft
Small add-on for the new release
« on: July 02, 2015, 09:54:15 PM »
I'd like to propose an add-on for the next release:

In /framework/frontend.functions.php add the following function:

Code:
Only registered users can see contents. Please click here to Register or Login.
With this function you can build smarter templates:

Code:
Only registered users can see contents. Please click here to Register or Login.
Webdesign/-Development, Freelance

> http://www.medialoft.be

Offline Martin Hecht

  • Betatester
  • **
  • Posts: 527
  • Gender: Male
    • meine Homepage
Re: Small add-on for the new release
« Reply #1 on: July 03, 2015, 10:14:13 AM »
i'm wondering if "hasModules" is a good name for this function. If I understand it correctly, the function checks if there are modules in a particular block of the current page and returns the number of sections found.
In the example for the template it looks like a check, if the $wb class supports modules at all, which is of course not what the function does.
Therefore, I would propose to call it something like "getModulesCountBySe ction"

Offline iceat

  • Posts: 108
  • Gender: Male
    • Medialoft
Re: Small add-on for the new release
« Reply #2 on: July 03, 2015, 10:16:51 AM »
You're apparently not a frontend developer :)

We need a small function name for it's ease of use. Maybe countModules. This would be a more correct name since you receive the amount
Webdesign/-Development, Freelance

> http://www.medialoft.be

Offline DarkViper

  • Forum administrator
  • *****
  • Posts: 2935
  • Gender: Female
Re: Small add-on for the new release
« Reply #3 on: July 03, 2015, 10:18:51 AM »

In /framework/frontend.functions.php add the following function:
Quote
   // Function to check if a module position has active modules
   // Added by Frederick Giët, July 2 2015
   public function hasModules($section_id = 1) {
      global $database;
      $sql = "select count(section_id) as counter from ".TABLE_PREFIX."sections where page_id = ".intval($this->page_id)." and block = ".intval($section_id);
      $result = $database->query($sql);
      $page = $result->fetchRow();
      return intval($page[0]);
   }
The red marked code will throw a fatal error. (frontend.functions. php is not a class..)
There is no care for page settings. Not every visitor is allowed to see each page, not every section is visible at all times...
To give you an idea, i post a (not 100%) corrected version..
Code:
Only registered users can see contents. Please click here to Register or Login.The function page_content($iBlock) is part of file frontend.functions.php
From this it's a logic decision to place the depending function hasBlockVisibleSections($iBlock) in that file too.
Code:
Only registered users can see contents. Please click here to Register or Login.
« Last Edit: July 03, 2015, 10:25:32 AM by DarkViper »
Der blaue Planet - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen

"You have to take the men as they are ... but you can not leave them like that !!" :-P
Ein einziger Buchstabendreher kann einen ganzen Satz urinieren.

Offline iceat

  • Posts: 108
  • Gender: Male
    • Medialoft
Re: Small add-on for the new release
« Reply #4 on: July 03, 2015, 10:21:18 AM »
i'm sorry, i meant class.frontend

i have a working version here, I've tested it naturally :)
Webdesign/-Development, Freelance

> http://www.medialoft.be

fischstäbchenbrenner

  • Guest
Re: Small add-on for the new release
« Reply #5 on: July 03, 2015, 10:49:24 AM »
Why dont you do this thing as it is usually done?:

Code:
Only registered users can see contents. Please click here to Register or Login.
A page can be empty even though there are modules. Example: Code-Module.

Offline iceat

  • Posts: 108
  • Gender: Male
    • Medialoft
Re: Small add-on for the new release
« Reply #6 on: July 03, 2015, 11:06:49 AM »
Because that's a retarded amount of code for a template builder. You're right about the code module, maybe add this check to the function i created.
Webdesign/-Development, Freelance

> http://www.medialoft.be

fischstäbchenbrenner

  • Guest
Re: Small add-on for the new release
« Reply #7 on: July 03, 2015, 11:34:46 AM »
It is a "retarded amount" using a save, simple and fast method - and do lots of database querys instead? I dont think so.



Offline iceat

  • Posts: 108
  • Gender: Male
    • Medialoft
Re: Small add-on for the new release
« Reply #8 on: July 03, 2015, 02:44:54 PM »
Allright, here we go:

First of all:

This:
Code:
Only registered users can see contents. Please click here to Register or Login.
Is shorter and easier to remember and reuse then this:

Code:
Only registered users can see contents. Please click here to Register or Login.
Especially if you want to use it multiple times in a template to check on different blocks.

Second:

The page_content function runs 1 or 2 queries for the same result:

Code:
Only registered users can see contents. Please click here to Register or Login.
If no content is found:

Code:
Only registered users can see contents. Please click here to Register or Login.
While my function only does 1

Code:
Only registered users can see contents. Please click here to Register or Login.
Where do you see me make 'lots of database querys'?
Webdesign/-Development, Freelance

> http://www.medialoft.be

Offline iceat

  • Posts: 108
  • Gender: Male
    • Medialoft
Re: Small add-on for the new release
« Reply #9 on: July 03, 2015, 02:49:49 PM »
Also, the function returns the amount of modules which can be used for other stuff.
Webdesign/-Development, Freelance

> http://www.medialoft.be

Offline iceat

  • Posts: 108
  • Gender: Male
    • Medialoft
Re: Small add-on for the new release
« Reply #10 on: July 03, 2015, 02:53:36 PM »
A page can be empty even though there are modules. Example: Code-Module.

Modules with hidden content can be shown in other places then the ones made variable in your template, since they probably won't have to published on that location.
Webdesign/-Development, Freelance

> http://www.medialoft.be

fischstäbchenbrenner

  • Guest
Re: Small add-on for the new release
« Reply #11 on: July 03, 2015, 03:29:15 PM »
There is no need to remember a function - its simply copy and paste. You wont make a new template every day.
And of course you know: a small number of chars doesnt make the code faster.

If you need these functions in your template - why dont you put it into your template code?
No module will need it, no other templates, its only for your template.

And - by the way: What about timebased output? Not only the sections, even modules themself can have whatever-based output. Some modules have an empty view.php (they only do something in the backend)

The only way to find out if there is any output, is to generate the output und THEN check, if there is any content.

Offline iceat

  • Posts: 108
  • Gender: Male
    • Medialoft
Re: Small add-on for the new release
« Reply #12 on: July 03, 2015, 04:08:03 PM »
- Correct, i forgot the date check, a small extension on my query and it's fixed. You could've told me that in a more constructive way :)
- Only i need it? I let you search the forum for my thread in the past where a lot of people were enthousiastic about it when i launched it as a plugin
- Professional site builders build new templates EVERY day
- My piece of code is faster
- ...

You sir, are just plain arrogant and that attitude is why after 10 years WebsiteBaker is still in the stone age.
Webdesign/-Development, Freelance

> http://www.medialoft.be

fischstäbchenbrenner

  • Guest
Re: Small add-on for the new release
« Reply #13 on: July 03, 2015, 04:21:00 PM »
I dont want to argue here.
fact is: there IS a simple working solution which works ALWAYS, in any cases.
Your solution does not work always.

Why dont you put your code into your templates, if you need it? It ist simple!

Quote
You sir, are just plain arrogant and that attitude is why after 10 years WebsiteBaker is still in the stone age.
As you see, my english ist not that good. But this sounds friendly to me - thanks!

 

postern-length