Zen Cart Logo
Forums / General Questions / How to point image variable for the template directory in 'root/aaa/' folder?

How to point image variable for the template directory in 'root/aaa/' folder?

Views: 7,473

Results 1 to 13 of 13
26 Jul 2016, 2:40 AM
#1
oavs avatar

oavs

Totally Zenned

Join Date:
Jan 2006
Location:
Downunder - QLD - Gold Coast
Posts:
921
Plugin Contributions:
0

How to point image variable for the template directory in 'root/aaa/' folder?

Hi,

Some of my mod images aren't showing. Mod is installed in
https://www.abc.com/AAA/includes/modules/my_mod folder (not in admin)

I have following code
$this->icon = $template->get_template_dir('bbb.jpg', '' ,'','images/icons'). '/bbb.jpg';

and
$this->logo = $template->get_template_dir('ccc.jpg', '','' ,'images/icons'). '/ccc.jpg';

but when I follow the no-image icon it points to
https://www.abc.com/AAA/admin/includes/templates/template_default/images/icons/bbb.jpg

How can I modify the code so that images are correctly found and linked.

Can anyone please assist?

26 Jul 2016, 3:49 PM
#2
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,963
Plugin Contributions:
8

Re: How to point image variable for the template directory in 'root/aaa/' folder?

it looks like your reference to $this in your mod must have somehow included the admin directory.

how have you initialized $this in your mod? and is your admin directory named admin?

26 Jul 2016, 3:51 PM
#3
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to point image variable for the template directory in 'root/aaa/' folder?

If in the admin and trying to reach the store's modules directory where the "my_mod" info is installed in the template override directory in the modules directory, I think the following would work:

$this->variable = $template->get_template_dir('bbb.jpg', DIR_FS_CATALOG . DIR_WS_MODULES, $template_dir, '') . '/bbb.jpg';
26 Jul 2016, 4:18 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to point image variable for the template directory in 'root/aaa/' folder?

carlwhat:

it looks like your reference to $this in your mod must have somehow included the admin directory.

how have you initialized $this in your mod? and is your admin directory named admin?
Not quite carlwhat. See, the function/code that is trying to display the icon is located in the admin directory. The global $template variable is accessible from the admin, but the problem in the above code lies in the lack of "starting" directory. Therefore, the returned location is provided based on the current location which is the admin directory when the result(s) come back. It's centered around this function in includes/classes/template_func.php which "typically" looks in the includes/templates directory, but also could be used to look in other overrideable directories.

 function get_template_dir($template_code, $current_template, $current_page, $template_dir, $debug=false) {
    //	echo 'template_default/' . $template_dir . '=' . $template_code;
    if ($this->file_exists($current_template . $current_page, $template_code)) {
      return $current_template . $current_page . '/';
    } elseif ($this->file_exists(DIR_WS_TEMPLATES . 'template_default/' . $current_page, preg_replace('/\//', '', $template_code), $debug)) {
      return DIR_WS_TEMPLATES . 'template_default/' . $current_page;
    } elseif ($this->file_exists($current_template . $template_dir, preg_replace('/\//', '', $template_code), $debug)) {
      return $current_template . $template_dir;
    } else {
      return DIR_WS_TEMPLATES . 'template_default/' . $template_dir;
      //        return $current_template . $template_dir;
    }
  }

The only thing about the provided suggestion from above is that the entire path of the store is made visible (on the admin side to which I just found a solution) instead of simply copying the file to somewhere admin side and referencing it from there such that the same image is presented in two locations on the server. But whatever is desired I guess...

26 Jul 2016, 4:22 PM
#5
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to point image variable for the template directory in 'root/aaa/' folder?

mc12345678:

If in the admin and trying to reach the store's modules directory where the "my_mod" info is installed in the template override directory in the modules directory, I think the following would work:

$this->variable = $template->get_template_dir('bbb.jpg', DIR_FS_CATALOG . DIR_WS_MODULES, $template_dir, '') . '/bbb.jpg';


I'd like to offer a revision because of the concern I expressed above related to "publishing" the file path. Instead of DIR_FS_CATALOG, use DIR_WS_CATALOG or as necessary DIR_WS_HTTPS_CATALOG:

$this->variable = $template->get_template_dir('bbb.jpg', DIR_[b]W[/b]S_CATALOG . DIR_WS_MODULES, $template_dir, '') . '/bbb.jpg';


Though I also did just find that DIR_FS_CATALOG_MODULES is defined if you need a hard file path to a file in the modules directory.
26 Jul 2016, 4:38 PM
#6
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,963
Plugin Contributions:
8

Re: How to point image variable for the template directory in 'root/aaa/' folder?

mc12345678:

...Therefore, the returned location is provided based on the current location which is the admin directory when the result(s) come back. It's centered around this function in includes/classes/template_func.php which "typically" looks in the includes/templates directory, but also could be used to look in other overrideable directories.
...

ok, mc i am very confused! (not an unusual occurrence...)

the OP stated that the mod is NOT on the admin side. the function get_template_dir resides on the customer facing side as well.

if both of those statements are true, how did the admin get into the file path? how does the current location become the admin directory when the results come back?

thanks in advance.

26 Jul 2016, 4:47 PM
#7
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to point image variable for the template directory in 'root/aaa/' folder?

carlwhat:

ok, mc i am very confused! (not an unusual occurrence...)

the OP stated that the mod is NOT on the admin side. the function get_template_dir resides on the customer facing side as well.

if both of those statements are true, how did the admin get into the file path? how does the current location become the admin directory when the results come back?

thanks in advance.
No problem. I too was a little confused, but then thought about this: where are the shipping and payment modules installed? Catalog right? From where does one access/setup those modules? Admin, right? Want to "pretty your mod"? Add pictures... now, though the thing goes back to what is defined and when/where. If the images are to be visible on the Admin side and the store front side, then the path for the image(s) needs to be "flexible". So for example DIR_WS_CATALOG_MODULES doesn't exist on the store front, but does on the Admin side. So:

(defined('DIR_WS_CATALOG_MODULES') ? DIR_WS_CATALOG_MODULES : DIR_WS_MODULES)
Would address referencing the "correct" path depending if accessed from the Admin (first option) or catalog (second).

26 Jul 2016, 5:17 PM
#8
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to point image variable for the template directory in 'root/aaa/' folder?

I guess I didn't get into the directory path resolution part.

So, the path returned from the function is a relative path (begins without a forward slash /) by having the image to be displayed in the admin as part of "working with" the module (added to database to reference the store/catalog side "control file" or the database populated with a reference to a location), then the image is attempted to be displayed considering the original code using src="includes/templates/template_default/images/icons/bbbb.jpg" for example. Because the image path is presented on the admin side, the base path or place from which to reference that path includes the admin location. Therefore, the image path when "viewed" becomes admin centric.

Even if the OP does have files in the admin which would contradict the original statement in the OP, the reference is built the same way and the result is not catalog/admin centric, but relative to the location to where the image (or more specifically overrideable location) exists.

That help a little?

26 Jul 2016, 5:43 PM
#9
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,963
Plugin Contributions:
8

Re: How to point image variable for the template directory in 'root/aaa/' folder?

no, none of this makes sense to me....

the only place i see $current_template defined is here:

admin/includes/init_includes/init_image_handler.php

which could possibly explain how the admin part comes up. although i have not been able to reproduce it my testing.

with regards to the function get_template_dir, it includes the php function file_exists and in the php definition, i see no second parameter, and yet get_template_dir passes a second parameter when using the file_exists function, so frankly i have no idea what is going on there as well.

if the OP stored the icons in his template i would just use:

$this->icon = DIR_WS_TEMPLATE . 'images/icons/bbb.jpg';

and move on....

something seemingly so simple gets to be so complex.

26 Jul 2016, 7:07 PM
#10
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to point image variable for the template directory in 'root/aaa/' folder?

Did you look in the catalog side of the store?

Have to back track a little, but in the initialization of the admin side, the includes/classes/template_func.php file is loaded... the $this->file_exists command references the function file_exists inside the above class.

Okay, bouncing ball:
admin/index.php loads includes/application_top.php
App_top loads admin/includes/auto_loaders/config.core.php
The core loads admin/includes/init_includes/init_templates.php
That assigns $template_dir based on a database lookup.
Also requires the catalog/classes/template_func.php file.
$template is initialized referencing DIR_WS_TEMPLATE, the constant is set to being DIR_WS_TEMPLATES and the $template_dir.

Now, the image(s) as identified are located in the modules directory... so one somewhat has to question why then use a template function? Well, on the catalog side there is a zen_get_module_directory function, but it doesn't appear that the function is made available on the admin side unless there is some other circuitous route that I've missed. At any rate, the template_directory function can kind of do the same thing if fed the applicable information.

As to "just set it to" DIR_WS_TEMPLATE and then the sub-path off of the template, sure could if the image(s) were stored in the template directory first of all, and second if stored on the admin side's template directory because again admin would appear in the path when referenced from the admin which is the only way that the admin directory could even get involved when/if properly coded. Which is what gets back to the "complexity". Write everything so that the code can be picked up and moved elsewhere and continue functioning. But yes, an obvious solution is to store the images elsewhere. :)

26 Jul 2016, 7:25 PM
#11
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,963
Plugin Contributions:
8

Re: How to point image variable for the template directory in 'root/aaa/' folder?

thanks mc. now i see that ZC has decided to rewrite a named function in PHP. that solves my second parameter issue. :)

as far as the loading and the rest of it, i'm sure that would all fall into place. i appreciate the help in understanding what is going on.

frankly, i tried to replicate the OP's problem of the admin coming up but was unsuccessful in doing that. so without having the same config where the problem manifests itself, it becomes tougher to solve, at least for me.

and i will leave it at that. interested thread for me, that's for sure...

best.

26 Jul 2016, 7:43 PM
#12
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to point image variable for the template directory in 'root/aaa/' folder?

carlwhat:

thanks mc. now i see that ZC has decided to rewrite a named function in PHP. that solves my second parameter issue. :)

as far as the loading and the rest of it, i'm sure that would all fall into place. i appreciate the help in understanding what is going on.

frankly, i tried to replicate the OP's problem of the admin coming up but was unsuccessful in doing that. so without having the same config where the problem manifests itself, it becomes tougher to solve, at least for me.

and i will leave it at that. interested thread for me, that's for sure...

best.

Simplest "remake" of the issue I can think of:
In catalog, includes/modules/mydir
Create a file that defines a variable like provided above, say:

<?php
$image_path = $template->get_template_dir('bbb.jpg', '' ,'','images/icons'). '/bbb.jpg';

Now on the admin side, create a file in the admin directory like:

<?php
require('includes/application_top.php');

include(DIR_FS_CATALOG_MODULES . 'mydir/newfile.php');
echo zen_image($image_path);

Besides missing a lot of the admin portion(s) of the above and proper html "sections" I would expect that the path of the missing image would point to the templates directory of the admin using the template_default directory (as override of the file won't be found and if not in an override, it has to be in the base directory, right? :) )

So then after logging into admin, if you "navigate" to that second file, it should try to display the image referenced.

26 Jul 2016, 11:20 PM
#13
oavs avatar

oavs

Totally Zenned

Join Date:
Jan 2006
Location:
Downunder - QLD - Gold Coast
Posts:
921
Plugin Contributions:
0

Re: How to point image variable for the template directory in 'root/aaa/' folder?

Hi,

Thank you for your help.

All I did was upload the files as per the mod instructions. My admin is called nimda.