1 of 2
1
Specifiying Images/CSS/JS in extensions/modules
Posted: 20 September 2008 04:36 AM   [ Ignore ]  
Summer Student
Total Posts:  11
Joined  03-01-2008

Hey guys,

I was testing some of my extension code and ran into a problem. How do you reference images for a module/extension in the CP?

So far I have tried:

'" . $PREFS->ini('site_url') . $PREFS->ini('system_folder') . "/extensions/lg_twitter_ext/bg.png'

Fails when you browse to a secondary msm site

'/" . $PREFS->ini('system_folder') . "/extensions/lg_twitter_ext/bg.png'

Fails when the user has EE installed in a sub folder

The only reliable way seems to be throwing all the files in a new folder in the themes directory as the user has to type this in manually.

I have seen Solspace call another CP page that returns the JS/CSS but this seems like a bit of overkill.

Any ideas?

Profile
 
 
Posted: 20 September 2008 04:37 AM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

I guess I should have posted that under my name not the company smile

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 20 September 2008 05:10 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  160
Joined  09-29-2007

have you tried with the constants PATH_EXT and PATH_MOD?

PATH_EXT.‘lg_twitter_ext/bg.png’

 Signature 

* Get the Sitemap Module and improve your site’s SEO

More Add-ons: iWebApp, Stand-Alone Image Editor, Landing Page, LogMeIn, Loop Plugin, Session Variables

Profile
 
 
Posted: 20 September 2008 05:18 AM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

PATH_EXT and PATH_MOD print out the system path… not a url :(

PATH_EXT = /Users/Leevi/Sites/Internal/ee.1.6.4-20080710/ee-admin/extensions/

So no good :(

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 20 September 2008 05:39 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  160
Joined  09-29-2007

what about using $PREFS->ini(‘cp_url’) and removing the index.php?

$url = str_replace('index.php', '', $PREFS->ini('cp_url', false));

 Signature 

* Get the Sitemap Module and improve your site’s SEO

More Add-ons: iWebApp, Stand-Alone Image Editor, Landing Page, LogMeIn, Loop Plugin, Session Variables

Profile
 
 
Posted: 20 September 2008 06:10 AM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

@Ben:

The issue with that is that people may be masking their control panel index page. So they could be using admin.php inside a different folder.

I’m starting to think this is one of those 80-20 situations.

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 20 September 2008 06:26 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  160
Joined  09-29-2007

it may well be. good luck!

 Signature 

* Get the Sitemap Module and improve your site’s SEO

More Add-ons: iWebApp, Stand-Alone Image Editor, Landing Page, LogMeIn, Loop Plugin, Session Variables

Profile
 
 
Posted: 20 September 2008 06:54 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  716
Joined  07-02-2007

Well typically i do this:

$this->lib_path        = $PREFS->ini('site_url', TRUE).$PREFS->ini('system_folder', TRUE).'modules/'.$this->module_name.'/lib/';

Even if people mask their CP it will still work since the original CP url is always accessible.
Or am i wrong?

I guess that’s why Solspace went for the “themes” solution, since that always works..

 Signature 

Truly ExpressionEngine


Fielder Module ( Mass Custom Fields )
Super Cache (Cache heavy tag output)
reCAPTCHA Extension
Rewrite Module


See all my EE Addons (8)

Profile
 
 
Posted: 20 September 2008 07:03 AM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006
Victor Gutierrez - 20 September 2008 06:54 AM

Well typically i do this:

$this->lib_path        = $PREFS->ini('site_url', TRUE).$PREFS->ini('system_folder', TRUE).'modules/'.$this->module_name.'/lib/';

Even if people mask their CP it will still work since the original CP url is always accessible.
Or am i wrong?

I guess that’s why Solspace went for the “themes” solution, since that always works..

The issue with that approach is that a msm site has a different site url which doesn’t contain the EE installation. :( So the assets are 404

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 21 September 2008 05:08 PM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

Bump… Do any Ellislab developers have any suggestions? smile

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 21 September 2008 05:11 PM   [ Ignore ]   [ # 10 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6543
Joined  04-15-2006

Just out of interest is there no way of finding the path of your extension itself and then working back from there?

Just a thought though.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 21 September 2008 05:21 PM   [ Ignore ]   [ # 11 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

I can find the server path… not sure if I can turn that into a url… checking the dev docs now smile

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 21 September 2008 06:08 PM   [ Ignore ]   [ # 12 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

Ok answering my own post here but I think the best way to reference images and scripts for extensions and modules is to:

1. create a new folder in the /themes/cp_themes/default/ directory
2. put all your images / css / js in there
3. build the url:

$PREFS->ini('theme_folder_url', 1) . "cp_themes/".$PREFS->ini('cp_theme')."/lg_twitter/admin.js"

This way your extension can be tweaked for custom cp themes in the future. Seems ok and is fail proof on msm sites and masked CPs

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 22 September 2008 09:17 AM   [ Ignore ]   [ # 13 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23522
Joined  05-20-2002

Seems reasonable from here.  I took a look- Tag is using the THEME_FOLDER constant, which is defined in core.system.php

// ----------------------------------------------
//  Theme Paths
// ----------------------------------------------

    
if ($PREFS->ini('theme_folder_path') !== FALSE && $PREFS->ini('theme_folder_path') != '')
    
{
        $theme_path
= preg_replace("#/+#", "/", $PREFS->ini('theme_folder_path').'/');
    
}
    
else
    
{
           $theme_path
= substr(PATH, 0, - strlen($PREFS->ini('system_folder').'/')).'themes/';
        
$theme_path = preg_replace("#/+#", "/", $theme_path);
    
}
    
    define
('PATH_THEMES',         $theme_path);
    
define('PATH_SITE_THEMES',    PATH_THEMES.'site_themes/');
    
define('PATH_MBR_THEMES',    PATH_THEMES.'profile_themes/');
    
define('PATH_CP_IMG',         $PREFS->ini('theme_folder_url', 1).'cp_global_images/');
    
    if (
REQ == 'CP')
    
{
        define
('PATH_CP_THEME', PATH_THEMES.'cp_themes/');
    
}
    
    
unset($theme_path);


But I’m not dead sure what the preferred approach is.  Took a look at the file upload button in publish, it’s using

/** --------------------------------
        /**  Upload link        
        /** --------------------------------*/
        
        
$up_img = '<img src="'.PATH_CP_IMG.'upload_file.gif" border="0"  width="16" height="16">line('file_upload').'" />';


I’m going to shift this down to ‘Modules’ and give the crew a bump on it.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 22 September 2008 03:37 PM   [ Ignore ]   [ # 14 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

Hey Robin,

Thanks for your input. Using the PATH_CP_IMG variable and the $PREFS->ini(‘theme_folder_url’, 1) method is the only foolproof way I have found so far.

Honestly its not too much extra time to implememnt but it does mean that the installation has a couple of extra steps. Unfortunatley sometimes that’s all it takes to confuse someone.

Cheers

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 28 October 2008 04:08 PM   [ Ignore ]   [ # 15 ]  
Grad Student
Avatar
Rank
Total Posts:  48
Joined  02-29-2008

I was wondering if anyone gave this some extra thought (preferably the developers at EllisLab)?

The ideal situation would be to have a directory called css/img/js in your module directory to simplify installation, but how does one get the path to that folder in a foolproof way? I intend to use this module I’m developing myself, but making things easier is never a bad thing…

 Signature 
Profile
 
 
Posted: 28 October 2008 04:37 PM   [ Ignore ]   [ # 16 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006
Wizz - 28 October 2008 04:08 PM

I was wondering if anyone gave this some extra thought (preferably the developers at EllisLab)?

The ideal situation would be to have a directory called css/img/js in your module directory to simplify installation, but how does one get the path to that folder in a foolproof way? I intend to use this module I’m developing myself, but making things easier is never a bad thing…

There is no fool proof way unless you use the themes directory. I have rebuilt most of my extensions using this technique and it works well.

Image Attachments
TextMateScreenSnapz001.png
Click thumbnail to see full-size image
 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 28 October 2008 05:02 PM   [ Ignore ]   [ # 17 ]  
Grad Student
Avatar
Rank
Total Posts:  48
Joined  02-29-2008

Hmmm… I might have found a way to include css and js files in the module directory.

$DSP->body .= '<style type="text/css">'.$DSP->file_open(PATH_MOD.'/'.$this->module_name'/css/cp.css').'</style>';


Same goes for js-files…

Any thoughts on this?

 Signature 
Profile
 
 
Posted: 28 October 2008 05:32 PM   [ Ignore ]   [ # 18 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

The main issue with that approach is that the pages will be much bigger to download and the browser cannot cache the resource.

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
   
1 of 2
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64912 Total Logged-in Users: 29
Total Topics: 81863 Total Anonymous Users: 19
Total Replies: 440097 Total Guests: 173
Total Posts: 521960    
Members ( View Memberlist )
Newest Members:  bjmohrAqua193Bios Elementmjpoteetguimogranwelshmrcfthenetmonkeybenekwhobutsb