I have added a new directory in my joomla website:
http://sitedomain.tld/xxx/
then I have added index.php in that directory
here is the code
define( '_JEXEC', 1 );
define('JPATH_BASE', '..' );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( '../includes/defines.php' );
require_once ( '../includes/framework.php' );
//JDEBUG ? $_PROFILER->mark( 'afterLoad' ) : null;
/**
* CREATE THE APPLICATION
*
* NOTE :
*/
$mainframe =& JFactory::getApplication('site');
$template_name = $mainframe->getTemplate();;
$mainframe->initialise();
JPluginHelper::importPlugin('system');
/**
* ROUTE THE APPLICATION
*
* NOTE :
*/
$mainframe->route();
// authorization
$Itemid = JRequest::getInt( 'Itemid');
$mainframe->authorize($Itemid);
// trigger the onAfterRoute events
//JDEBUG ? $_PROFILER->mark('afterRoute') : null;
//$mainframe->triggerEvent('onAfterRoute');
/**
* DISPATCH THE APPLICATION
*
* NOTE :
*/
$option = JRequest::getCmd('option');
//$mainframe->dispatch($option);
// trigger the onAfterDispatch events
//JDEBUG ? $_PROFILER->mark('afterDispatch') : null;
//$mainframe->triggerEvent('onAfterDispatch');
/**
* RENDER THE APPLICATION
*
* NOTE :
*/
$mainframe->render();
/**
* RETURN THE RESPONSE
*/
var_dump($document->getHeadData());
echo JResponse::toString($mainframe->getCfg('gzip'));
sdwdwd
wdwd
When I view this page in the browser, all the dynamic links like CSS, JS and images were suffixed by the /xxx/ path which make them broken !
How can I drop this suffix or how do I change this suffix from /xxx to / to it points to the original files location?
I have tried setting the JDocument::setBase and also tried to play with the JURI object and changed its _path and _uri without any change
Thanks
Shouldn't JPATH_BASE be an absolute path (eg. realpath('..'))?
Also, you can try setting in template.
I don't recommend circumventing the Joomla rendering process like this. You would be much better off creating a component rather than trying to do whatever you're goals are here.
Essentially I think the issue is you're actually creating a new instance and too many things expect resources to be located in certain paths. You're asking for a lot of trouble here, I can't even being to think of all the settings that would be affected by this move. That is why I would not do this, and make a component.
Related
I work in a WP project using template parts, as they are multiple buttons instance in this project i created a button template that can take multiple arguments as such:
<?
/**
* Default button template
*
*/
$container_classes = $args["container_classes"]; //additional container classes
$button_type = $args['button_type']; // link | button | modal
$elem_classes = $args['elem_classes']; //additional classes for the button
$url = $args['url'] ?? null; //provides the url target
$text = $args['text'] ?? null; // text to display inside the button
$text_color = $args['text_color'] ?? "white"; // text color
$bg_color = $args['bg_color'] ?? 'cta';
$target = $args['target'] ?? "_self"; //target attribute
$icon = $args['icon'] ?? null; //If there is an icon, link to the icon
$modal_slug = $args['modal_slug'] ?? 'null'
?>
<div class="button-<?= $button_type ?> flex <?= $container_classes ?>">
{... All the button specifications and other logical checks ... }
</div>
I would now like to use this template in multiple sections. But with all those $args i would like to have suggestions when typing in the arguments in the get_template_part() function.
Is there a way of defining the possible $args in the template-part file as i've seen it being used in functions for instance ?
Exemple of predefined params for a function:
function get_template_part( $slug, $name = null, $args = array() ) {
/**
* Fires before the specified template part file is loaded.
*
* The dynamic portion of the hook name, `$slug`, refers to the slug name
* for the generic template part.
*
* #since 3.0.0
* #since 5.5.0 The `$args` parameter was added.
*
* #param string $slug The slug name for the generic template.
* #param string|null $name The name of the specialized template.
* #param array $args Additional arguments passed to the template.
*/
where the #param notation defines expected parameters.
I'm trying to have suggestion proposed by VsCode when using a template part and trying to figure out a way for the $args to reproduce the params behavior in the case of a function.
I am customizing the following theme.
https://github.com/inc2734/snow-monkey
And I'd like to add font - weight 300 to noto sans.
https://github.com/inc2734/snow-monkey/blob/9c817ca3c5176101db23185838260e2739163ebe/resources/src/css/foundation/_body/_body.php
"enqueue_noto_sans_jp.php" consists of the following code, only font-weight 400 is loaded.
<?php
/**
* #package mimizuku
* #author inc2734
* #license GPL-2.0+
*/
namespace Inc2734\Mimizuku_Core\Helper;
/**
* Enqueue Noto Sans JP
*
* #return void
*/
function enqueue_noto_sans_jp() {
wp_enqueue_style(
'noto-sans-jp',
'https://fonts.googleapis.com/css?family=Noto+Sans+JP&subset=japanese',
[],
wp_get_theme()->get( 'Version' )
);
}
I tried changing "enqueue_noto_sans_jp.php" directly as follows, but it was returned to the original timing at the most.
function enqueue_noto_sans_jp() {
wp_enqueue_style(
'noto-sans-jp',
'https://fonts.googleapis.com/css?family=Noto+Sans+JP:300,500,700&subset=japanese',
[],
wp_get_theme()->get( 'Version' )
);
}
Can I overwrite this with functions.php of the child theme?
Thanks your Help.
John,
Looks like you're on the right track using a child theme, but you only need to change the css part to load in your other fonts and apply css to the page to make use of them.
There is a really good guide to doing that here: https://nudgethemes.com/wordpress-how-to-change-your-theme-font/
I'm using Laravel localization to provide two different languages. I've got all the path stuff set up, and mydomain.com/en/bla delivers English and stores the 'en' session variable, and mydomain.com/he/bla delivers Hebrew and stores the 'he' session variable. However, I can't figure out a decent way to provide a language-switching link. How would this work?
I've solved my problem by adding this to the before filter in routes.php:
// Default language ($lang) & current uri language ($lang_uri)
$lang = 'he';
$lang_uri = URI::segment(1);
// Set default session language if none is set
if(!Session::has('language'))
{
Session::put('language', $lang);
}
// Route language path if needed
if($lang_uri !== 'en' && $lang_uri !== 'he')
{
return Redirect::to($lang.'/'.($lang_uri ? URI::current() : ''));
}
// Set session language to uri
elseif($lang_uri !== Session::get('language'))
{
Session::put('language', $lang_uri);
}
// Store the language switch links to the session
$he2en = preg_replace('/he\//', 'en/', URI::full(), 1);
$en2he = preg_replace('/en\//', 'he/', URI::full(), 1);
Session::put('he2en', $he2en);
Session::put('en2he', $en2he);
This is a post i posted originally on the laravel forums, but maybe it will help somebody else, so i post it here also.
I had some trouble with building a easy language switcher for my app, and the info on the forums where a little bit old (some posts), so i made this simple piece of code that makes it supereasy to change language on your app on the fly.
I have the language strings in my views as following:
{{ __('languagefile.the_language_string'); }}
And I get the languages with a URL, i think this is the best way, also its good for seo and for links that people share. Example:
www.myapp.com/fi/support (Finnish)
www.myapp.com/en/support (English)
www.myapp.com/sv/support (Swedish)
Ok, so the problem was that i wanted a easy way to change the language on the fly, without having to mess with sessions and cookies. Heres how i made it:
Make a library in your libraries folder called chooselang.php
Insert this code inside:
class Chooselang extends HTML {
/**
* Generate a Language changer link.
*
* <code>
* // Generate a link to the current location,
* // but still change the site langauge on the fly
* // Change $langcode to desired language, also change the Config::set('application.language', 'YOUR-LANG-HERE')); to desired language
* // Example
* echo Chooselang::langslug(URI::current() , $langcode = 'Finnish' . Config::set('application.language', 'fi'));
* </code>
*
* #param string $url
* #param string $langcode
* #param array $attributes
* #param bool $https
* #return string
*/
public static function langslug($url, $langcode = null, $attributes = array(), $https = null)
{
$url = URL::to($url, $https);
if (is_null($langcode)) $langcode = $url;
return '<a href="'.$url.'"'.static::attributes($attributes).'>'.static::entities($langcode).'</a>';
}
}
After this you are ready for getting your url switcher URL:s generated. Simply add them as you whould any other Blade links.
Example how to generate links for Finnish, Swedish and English (with Blade)
{{ Chooselang::langslug(URI::current() , $langcode = 'Fin' . Config::set('application.language', 'fi')); }}
{{ Chooselang::langslug(URI::current() , $langcode = 'Swe' . Config::set('application.language', 'sv')); }}
{{ Chooselang::langslug(URI::current() , $langcode = 'Eng' . Config::set('application.language', 'en')); }}
The above will generate URL:s that are always on the current page, and change the lang slug to the one you want. This way the language changes to the one you want, and the user naturally stays on the same page. The default language slug is never added to the url.
Generated urls look something like:
Fin
Swe
Eng
PS. The links are specially useful if you add them to your master template file.
You could have a Route to hand language change, for example:
Route::get('translate/(:any)', 'translator#set');
Then in the set action in the translator controller could alter the session, depending on the language code passed via the URL.
You could also alter the configuration setting by using
Config::set('application.language', $url_variable');
Controller Example - translate.php
public function action_set($url_variable)
{
/* Your code Here */
}
Just in case for future users if you want to use package for localization There is a great package at https://github.com/mcamara/laravel-localization. which is easy to install and has many helpers.
This question still comes in Google search, so here's the answer if you're using Laravel 4 or 5, and mcamara/laravellocalization.
<ul>
<li class="h5"><strong><span class="ee-text-dark">{{ trans('common.chooselanguage') }}:</span></strong> </li>
#foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
<li>
<a rel="alternate" hreflang="{{$localeCode}}" href="{{LaravelLocalization::getLocalizedURL($localeCode) }}">
<img src="/img/flags/{{$localeCode}}.gif" /> {{{ $properties['native'] }}}
</a>
</li>
#endforeach
</ul>
NOTE that this example shows flags (in public/img/flags/{{locale}}.gif), and to use it you will need a bit of .css, but you can modify it to display the text if you want...
FYI. The mcamara/laravellocalization documentation has examples and a LOT of helpers, so look through the documentation on github. (https://github.com/mcamara/laravel-localization)
Try use Session's. Somthing like this:
Controller:
class Language_Controller extends Base_Controller {
function __construct(){
$this->action_set();
parent::__construct();
}
private function checkLang($lang = null){
if(isset($lang)){
foreach($this->_Langs as $k => $v){
if(strcmp($lang, $k) == 0) $Check = true;
}
}
return isset($Check) ? $Check : false;
}
public function action_set($lang = null){
if(isset($lang) && $this->checkLang($lang)){
Session::put('lang', $lang);
$this->_Langs['current'] = $lang;
Config::set('application.language', $lang);
} else {
if(Session::has('lang')){
Config::set('application.language', Session::get('lang'));
$this->_Langs['current'] = Session::get('lang');
} else {
$this->_Langs['current'] = $this->_Default;
}
}
return Redirect::to('/');
}
}
In Route.php:
Route::get('lang/(:any)', 'language#set');
I've been doing it like this:
$languages = Config::get('lang.languages'); //returns array('hrv', 'eng')
$locale = Request::segment(1); //fetches first URI segment
//for default language ('hrv') set $locale prefix to "", otherwise set it to lang prefix
if (in_array($locale, $languages) && $locale != 'hrv') {
App::setLocale($locale);
} else {
App::setLocale('hrv');
$locale = null;
}
// "/" routes will be default language routes, and "/$prefix" routes will be routes for all other languages
Route::group(array('prefix' => $locale), function() {
//my routes here
});
Source: http://forumsarchive.laravel.io/viewtopic.php?pid=35185#p35185
What I'm doing consists of two steps:
I'm creating a languages table which consists of these fields:
id | name | slug
which hold the data im gonna need for the languages for example
1 | greek | gr
2 | english | en
3 | deutch | de
The Language model I use in the code below refers to that table.
So, in my routes.php I have something like:
//get the first segment of the url
$slug = Request::segment(1);
$requested_slug = "";
//I retrieve the recordset from the languages table that has as a slug the first url segment of request
$lang = Language::where('slug', '=', $slug)->first();
//if it's null, the language I will retrieve a new recordset with my default language
$lang ? $requested_slug = $slug : $lang = Language::where('slug', '=', **mydefaultlanguage**')->first();
//I'm preparing the $routePrefix variable, which will help me with my forms
$requested_slug == ""? $routePrefix = "" : $routePrefix = $requested_slug.".";
//and I'm putting the data in the in the session
Session::put('lang_id', $lang->id);
Session::put('slug', $requested_slug);
Session::put('routePrefix', $routePrefix );
Session::put('lang', $lang->name);
And then I can write me routes using the requested slug as a prefix...
Route::group(array('prefix' => $requested_slug), function()
{
Route::get('/', function () {
return "the language here is gonna be: ".Session::get('lang');
});
Route::resource('posts', 'PostsController');
Route::resource('albums', 'AlbumsController');
});
This works but this code will ask the database for the languages everytime the route changes in my app.
I don't know how I could, and if I should, figure out a mechanism that detects if the route changes to another language.
Hope that helped.
I have project-range meta tags that are need to be set.
I've put them in protected method _initMeta in Bootstrap class.
Are there any better options? What if I would like different set of this data for another languages?
protected function _initMeta(){
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('XHTML1_STRICT');
$view->headTitle()->headTitle('Foo title');
$view->headMeta()->appendName('keywords','foo');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
->appendHttpEquiv('Content-Language', 'any');
$view->headLink()->appendStylesheet('/foo.css')->headLink(array('rel' => 'favicon',
'href' => '/favicon.ico'),
'PREPEND');
}
I use config for basic (bootstrap) data as:
application.ini
resources.view.meta.name.Viewport = "width=device-width, initial-scale=1.0"
resources.view.meta.name.MobileOptimized = "width"
resources.view.meta.name.HandheldFriendly = "true"
resources.view.meta.name.Keywords = "basic,keywords"
...
; format resources.view.headStyle.{MEDIA}.nfile =
resources.view.headStyle.all.1.href = "/css/basic.css"
resources.view.headStyle.all.1.conditionalStylesheet =
resources.view.headStyle.all.1.extras.title = "Basic style"
resources.view.headStyle.all.1.extras.charset = "utf-8"
resources.view.headStyle.all.2.href = "/css/ie.css"
resources.view.headStyle.all.2.conditionalStylesheet = "IE"
resources.view.headStyle.all.2.extras.title = "Internet Explorer style"
resources.view.headStyle.all.2.extras.charset = "utf-8"
; print media example
resources.view.headStyle.print.1.href = "/css/print.css"
...
; format resources.view.headLink.{REL} =
resources.view.headLink.humans.href = "/humans.txt"
resources.view.headLink.humans.type = "text/plain"
; ___ will be replaced by space, __ by point (or set another nest separator)
resources.view.headLink.shortcut___icon.href = "/favicon.png"
resources.view.headLink.shortcut___icon.type = "image/png"
...
At this point, maybe you have some special data. For example in:
project1.ini
project.headLink.author.href = "https://plus.google.com/XXXXX?rel=author"
project.headLink.image_src.href = "/author.jpg"
project.headLink.image_src.type = "image/jpg"
And finally, you mix all in your
Bootstrap.php
(example for *_initHeadLink()*):
// $options = your app options (basic)
// $projectOptions = your project options (special)
// $assets_url = your assets url
if ( is_array($headStyle = $options['headStyle']) ) {
foreach ( $headStyle as $media => $value ) {
foreach ( $value as $style ) {
extract($style);
$this->view->headLink()->appendStylesheet($assets_url . $href, $media,
$conditionalStylesheet, $extras);
}
}
}
$headLinks = array();
if ( isset($options['headLink']) )
$headLinks = $options['headLink'];
if ( isset($projectOptions['headLink']) )
$headLinks = array_merge($headLinks, (array) $projectOptions['headLink']);
// *array key, is the value for rel
foreach ( $headLinks as $rel => $value ) {
$rel = str_replace(array('___', '__'), array(' ', '.'), $rel);
$this->view->headLink()->headLink(array_merge(array('rel' => $rel), (array) $value));
}
Then, you can override these data from your Controller: setName, set...
I hope it helps ;)
You have several ways of achieving this. First and foremost, make sure the moment you define the metadata you already know what language will be loaded for the current request. Sometimes this may not be easy to determine at bootstrap time.
Having said this, besides the bootstrap, you can set the metadata on a:
Front Controller Plugin class (using for example the dispatchLoopStartup() or predispatch() methods).
Action Helper class (using for example the init() or preDispatch() methods).
At those points of execution you probably already determined the language to use, and can set the metadata accordingly. You can always change the metadata afterwards in your action controllers for specific cases in your application, so you're never really stuck if you previously specified metadata.
In my own work, I have this setup:
Front Controller Plugin, dispatchLoopStartup() method: determine language to load, giving priority to a "lang" GET parameter in the request object, then browser language, then default site language. I also use this to determine if the request is a normal request or an ajax request; if it's the former case, I register an action helper, see next...
Action Helper, preDispatch() method: load metadata depending on language and other stuff, load Layout and widgets, etc.
Action controller, someAction() method: if necessary, change some of the previously set metadata, for example headTitle(), which can depend on the effectively loaded content.
This arrangement makes sense to me, maybe it can help your approach?
The bootstrap is way to early for my projects. I add them in my controller/actions
$keywords = 'php,zend,framework';
$this->view->headMeta($keywords,'keywords','name',array(),'SET');
... etc.
Actually very late almost at the end. At this point I would also know about language and other things.
Consider a view called render_thing, which I load from a controller like so:
$html = $this->load->view(
'render_thing',
array(
'someParam' => $globalParam
'permissionMode' => 'guest'
),
true
);
log($html);
Later on in that same controller, I load the view again, except I don't override the optional permissionMode parameter. I'm assume that in the view code, $permissionMode would be unset.
$moreHtml = $this->load->view(
'render_thing',
array(
'someParam' => 'blablabla'
),
true
);
However, in the render_thing view code, on the second call, $permissionMode is still 'guest'. Can you tell me what is going on here?
Thanks!!!
From Loader.php, Loader::_ci_load in the CodeIgniter source...
/*
* Extract and cache variables
*
* You can either set variables using the dedicated $this->load_vars()
* function or via the second parameter of this function. We'll merge
* the two types and cache them so that views that are embedded within
* other views can have access to these variables.
*/
if (is_array($_ci_vars))
{
$this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
}
extract($this->_ci_cached_vars);
So, this would be why the parameter is still set. load_vars is not a method, but vars is; problem is that it doesn't provide a facility to erase the cache. Therefore, since CodeIgniter is still PHP4 compatible, you may always do this: $this->load->_ci_cached_vars = array();.
I've had the same problem and figured out the problem in Loader.php as follows;
/*
* Extract and cache variables
*
* You can either set variables using the dedicated $this->load_vars()
* function or via the second parameter of this function. We'll merge
* the two types and cache them so that views that are embedded within
* other views can have access to these variables.
*/
if (is_array($_ci_vars))
{
$this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
}else{
$this->load->_ci_cached_vars = array();
}
extract($this->_ci_cached_vars);