I'm working with an custom back-end template in Joomla and now I'm come to a point that I need to support multiple languages.
In the begin of the development I did not think about multiple languages and that gives me some trouble now. That it is best to rewrite the code and make it "smarter" I know, but at this point there is not much time to rewrite this code.
In the backend I'm working with icons that are based on the page title. For example the page Article Manager requests the icon images/icon/article-manager.png. So you see what happens if the page title is for example German and is called Inhalt.
At this moment I use this code to generate the iconpath:
#Loading Joomla Document Module
$doc = JFactory::getDocument();
#Get the page title
$title = explode("-", $doc->title);
$title = trim(end($title));
#Generate icon path
$lastTitle = explode("-", $title);
if (strpos(end($lastTitle), ':')) {
$lastTitle = explode(":", end($lastTitle));
$lastTitle = $lastTitle[0];
$iconPath = trim($lastTitle);
$iconPath = 'templates/' . $this->template . '/images/icons/' . strtolower(str_replace(" ", "-", $iconPath)) . '.png';
} else {
$iconPath = trim(end($lastTitle));
$iconPath = 'templates/' . $this->template . '/images/icons/' . strtolower(str_replace(" ", "-", $iconPath)) . '.png';
}
Now I'm thinking of searching the database for the page/componetent/modul/plugin ID but is there a faster/easier way to edit it?
Work around
As earlier stated, icons generated by a page title is indeed a bad idea. But Lodder came with a pretty nice and easy work around. So I decided to follow his idea. I added an extra variable that checks if it is a 'subpage', when yes then it extends the icon file name with this subpage.
#Loading Joomla Application Module
$app = JFactory::getApplication();
#Genrate page icon
$comp = $app->input->get('option');
$view = $app->input->get('view');
if(!empty($view)) {
$iconFileName = $comp . '-' . $view;
} else {
$iconFileName = $comp;
}
$iconPath = 'templates/' . $this->template . '/images/icons/' . $iconFileName . '.png';
Basing the icons on the Page Title is a bad idea. Purely because as you have already mentioned, your site is multi-lingual, therefore different languages will result in different results.
I would personally base the icons on the component name. For example:
$jinput = JFactory::getApplication()->input;
$view = $jinput->get('option');
The above code will output com_content and will always be the same for all languages.
You can then simply name your icon com_content.png and call the icons like so:
$iconPath = 'templates/' . $this->template . '/images/icons/' . $view . '.png';
Hope this helps
Related
I am gonna try to explain this as best as possible. i have the following varibles
$name = main channel and $childs = sub channels, if i remove the childs from the HTML the main channel shows and not the sub channels, which is correct. but when i try to style the sub channels as a different color then the main it wont allow it, and if you notice i have 2 different images but it ignores the sub channel image and uses the main and only uses. I don't understand how i can remove the sub channel without any affect on the main channel, but but when i try to add a separate icon and css to the sub it ignores it completely.
private function renderChannels($channelId)
{
$content = "";
$imagePath = $this->imagePath;
foreach ($this->_channelDatas as $channel)
{
if($channel["pid"] == $channelId)
{
if($channel["show"])
{
$name = $this->toHTML($channel["channel_name"]);
$title = $name . " [" . $channel["cid"] . "]";
$link = "javascript:tsstatusconnect('" . $this->_javascriptName . "'," . $channel["cid"] . ")";
$users = $this->renderUsers($channel["cid"]);
$childs = $this->renderChannels($channel["cid"]);
$cid = $channel["cid"];
$content .= <<<HTML
<div class="comms-row comms-row-title">
<img src="resources/media/icons/sub_channel_icon.png">$name
<div class="comms-row-flags">$flags</div>
$users
<div class="comms-row"><img src="resources/media/icons/sub_channel_icon.png">$childs</div>
</div>
HTML;
Us CSS !important on duplicate declarations in the sub-channels. I've noticed the newer updates on Fire fox ignores declarations that are re-declared later. I don't know why. !important will work, but I'm sure there is a better way to do it.
I am having trouble to dynamic the url using codeigniter.
I need to display dynamic URL look like below.
http://example.com/[store-url]
I did that. But when i try to view non-dynamic url like
http://example.com/blog. It accesssing store page only.
So i have wrote in my routes like below and it is working.
$route['blog'] = "blog";
But here my problem is i am having lot pages such as /blog. all pages are pointing the stores pages only including admin control panel
There any solution for that without setting the routes
In the routes.php
First wirte the coding of Dynamic URL
like
include_once (APPPATH . 'helpers/inflector_helper.php');
$path = explode('/', $_SERVER['REQUEST_URI']);
if ($_SERVER['HTTP_HOST'] == 'www.expample.com') {
$controller = $path[1];
} else {
$controller = $path[2];
}
$route[$controller] = plural($controller) . "/view" . ucwords($controller);
$route[$controller . '/list'] = plural($controller) . "/view" . ucwords($controller);
$route[$controller . '/view/(:num)'] = plural($controller) . "/view" . ucwords($controller) . "/$1";
$route[$controller . '/view/(:num)/(:any)'] = plural($controller) . "/view" . ucwords($controller) . "/$1/$2";
I write my static url
$route['login'] = "authenticate_user/index";
$route['validate'] = "authenticate_user/validateUser";
$route['logout'] = "authenticate_user/logout";
I hope this should work.
First lemme tell you what i am trying to achieve here . Suppose there is a url like this http://www.example.com/?id=12345 now what i want is if there is an id parameter available in the url i want to append the same parameter to every url on that page . Opencart has a url library that generates url i am sure you all must be familiar with it too , i found a way to do what i want but it's working at just some random parts of the website like categories url's are generating with id parameter appended to it and other's dont .
here's what i tried so far
File : System/libray/url.php
here's the function
public function link($route, $args = '', $connection = 'NONSSL') {
if ($connection == 'NONSSL') {
$url = $this->url;
}else {
$url = $this->ssl;
}
$url .= 'index.php?route=' . $route;
if ($args) {
$url .= str_replace('&', '&', '&' . ltrim($args, '&'));
}
foreach ($this->rewrite as $rewrite) {
$url = $rewrite->rewrite($url);
}
if(isset($_GET['id']))
{
if(!empty($this->request->get['id']))
$url .= '&id='.$this->request->get['id'];
if(!empty($_GET['id']))
{
$url .= '&id='.$_GET['id'];
}
}
return $url;
}
The problem is that not everything uses this method to generate its URLs.
For example, anything to do with banners (e.g. the Carousel module) uses links that the admin sets manually in System->Design->Banners, so you would also need to edit the code for this too. The simplest and probably the correct way is to edit the data that the models spit out e.g.
model_design_banner->getBanner() becomes
public function getBanner($banner_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "banner_image bi LEFT JOIN " . DB_PREFIX . "banner_image_description bid ON (bi.banner_image_id = bid.banner_image_id) WHERE bi.banner_id = '" . (int)$banner_id . "' AND bid.language_id = '" . (int)$this->config->get('config_language_id') . "'");
if (isset($_GET['id'])) {
array_walk($query->rows, function(&$value) {
$value['link'] .= '&id=' . $_GET['id'];
});
}
return $query->rows;
}
It's either that, or edit the output in every single controller that uses this method.
That's just an example for banners, though. I don't recall off-hand which other modules will need to be edited, but if there's a particular one that's making you scratch your head, let me know and I'll give you another example to fix it.
I working on a flat-file-based project and I try to remove specific pattern from URL. The content is stored in a "content"-directory with markdown-files. I want sortable content-folder-names like:
contentfolder:
- 01-home
- 01-subpage
- 02-subpage2
- 02-page02
- 01-subpage
- 02-subpage2
etc...
At the moment, the URL would look something like this:
http://domain.com/01-home/02-subpage
This is really ugly ;)
I would prefer to get the url work as follows:
http://domain.com/home/subpage
I would prefer a solution, which works for every case of url:
http://domain.com/home/subpage/subsubpage/subsubsubpage
etc.
My script use at the moment the f3-Wildcard-Solution (GET /*). The requested URL will be replaced to get the content.
function find($path = "") {
$dirname = str_replace(globals::root(), "", globals::current());
if ($dirname == "/") {
$this->location = globals::content() . globals::home() . "/" . $path;
} else {
$this->location = globals::content() . $dirname . "/" . $path;
}
return $this;
}
Thank you guys!
Here's a solution, assuming that:
your markdown files are located in a content/ folder
every subfolder is prefixed with two digits and a hyphen (XX-something)
=>
$f3=require('lib/base.php');
$f3->set('CONTENT','content/');//location of markdown files
$f3->route('GET /*',function($f3,$params){
$path=str_replace('..','',$params[1]);//security
$dirs=glob($f3->get('CONTENT').'??-'.str_replace('/','/??-',$path));
if ($dirs) {
$dir=$dirs[0];//pick first match
echo \Markdown::instance()->convert($dir.'/default.md');
} else
$f3->error(404);
});
$f3->run();
I have the PHP code:
$uid = $xUS['id']; // Current user id
$uname = $xUS['x_username']; // Current user name
$ulink = ''; // Current user profile URL (leave blank for none)
$upic = $xUS['config_forum_avator_head']; // Current user
$ismod = 0; // Is current user a moderator?
$sig = md5($uid . $uname . $ismod . 's79tvi40k95bs6mw');
$ssoParams = '&uid=' . $uid . "&uname=" .
urlencode($uname) . "&ulink=" . urlencode($ulink) . "&upic=" . urlencode($upic)
. "&ismod=" . $ismod . "&sig=" . $sig;</i>
My Smarty template file:
<iframe width='550' height='500' src='http://chatroll.com/embed/chat/pibux-chatroom?id=tgybumotNmY&platform=php{$ssoParams}&w=$0' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' allowtransparency='true'></iframe>
In this, the {$ssoParams} variable is returning a null value. Why? Please help out.
Read Smarty docs for example: http://www.smarty.net/docsv2/en/language.variables.tpl#language.assigned.variables
You need to assign a variable like:
$smarty = new Smarty();
$smarty->assign('ssoParams', $ssoParams); // assign(smarty var, PHP var);
$smarty->display('template_file.tpl');
And of course you need to include smarty files, define templates etc.
For basic working example look example 2.9. here:
http://www.smarty.net/docsv2/en/installing.smarty.basic.tpl#id2778275