Error $mainframe->set() in joomla 1.7 - joomla1.7

I have code in joomla 1.5
global $mainframe;
$html = "web solution";
$mainframe->set('JComponentTitle', $html);
Use in joomla 1.5 is OK
But when using joomla 1.7 is error Call to a member function set() on a non-object in ...
I want help for this idea

Try this:
global $app;
$html = "web solution";
$app->set('JComponentTitle', $html);

I think the using of global objects in joomla 1.6+ is deprecated. Instead of using $mainframe and global $app, I'd use something like :
$app = & JFactory::getApplication();
$html = 'web solution';
$app->set('JComponentTitle', $html);

Related

Passing XML and Outputting to Twig Template in SlimPHP 3

Currently using the SlimPHP 3 MVC framework and trying to XML output of a URL to the Twig template. I'm using the latest build of Guzzle if it helps.
I have my Controller set up and the function as follows:
public function getaws($request, $response, $args) {
$bucketname = $args['bucketname'];
$client = new \GuzzleHttp\Client();
$bucket = $client->request('GET', $bucketname . '.s3.amazonaws.com');
if($bucket) {
$buck = $bucket->getBody();
return $this->view->render($response, 'aws.twig', ['buck' => $buck]);
}
else {
$res = Array();
$res['message'] = 'Bucket Disabled or Unknown';
return $this->view->render($response, 'aws.twig', ['buck' => $res]);
}
}
In the Twig file - aws.twig I have only been able to output the entire XML response/body using:
{{ buck }}
I have tried typing:
{{ buck.Name }}
or
{{ buck.Key }}
Neither have worked. I've tried the ForEach loop as well and nothing comes from that at all. I'm completely at a loss. I've noticed that there doesn't seem to be an awful lot of help on SlimPHP but I like it and prefer using it to Laravel and no I won't switch to Laravel just to make life easier otherwise asking for help with this would be a waste of time.
Anyone who has had experience with SlimPHP 3, Twig templates and Guzzle - I'd very much like help with this.
Thanks!

Generating query strings in Laravel 4

I have a named route
Route::get('login/facebook', array(
'as' > 'login.facebook.authorise',
'uses' => 'AuthController#getFBAuthorise'
));
and want to produce a URL pointing to it with a query string appended.
For example:
URL::route('login.facebook.authorise', array("next"=>'/dashboard/')
would produce
/login/facebook?next=/dashboard/
Is something like this built in to the framework? If not, what is the best way to try and do this?
Thanks.
The URL helper can do this.
http://laravel.com/docs/helpers#urls
echo link_to_route('route.name', $title, $parameters = array(), $attributes = array());
EDIT: To get only the URL :
http://laravel.com/docs/routing#named-routes
$url = URL::route('route.name', $parameters);
I am a bit late to the party
Just dove into the classes and methods for building urls and you can do this:
link_to_route('login.facebook.authorise','Facebook Login',array('next'=>'/Dashboard/'))
So. the array will always fallback to query params unless the names are declared in the route.
If the use case for this is redirecting to a page after logging in then you could use
Redirect::intended('dashboard');
As seen here http://laravel.com/docs/security#authenticating-users
Sorry if that's not what you're trying to achieve.

Wordpress Plugin: Facebook comments box position

I have a problem with the "new" Facebook plugin for Wordpress. I would like to re-position it on my post page. I've read somewhere else (or maybe here) that you could use the comment box from developers.facebook.com but I want to use the original Facebook plugin. So here goes:
I've found (in the plugin folder) where Facebook have put the code to install comments box in my theme. It looks like this:
public static function the_content_comments_box( $content ) {
global $post;
if ( ! isset( $post ) )
return;
$options = get_option( 'facebook_comments' );
if ( ! is_array( $options ) || empty( $options ) )
return $content;
// closed posts can have comments from their previous open state
// display noscript version of these comments
$content .= "\n" . self::comments_markup( 'noscript' ) . "\n";
// no option via JS SDK to display comments yet not accept new comments
// only display JS SDK version of comments box display if we would like more comments
if ( comments_open( $post->ID ) ) {
$url = apply_filters( 'facebook_rel_canonical', get_permalink() );
if ( $url ) // false could happen. let JS SDK handle compatibility mode
$options['href'] = $url;
$content .= self::js_sdk_markup( $options );
}
return $content;
}
}
How do put the Facebook comments box in the bottom of my post page?
You can look at a random post page here: My temporary site What I'm ultimately trying to do is to have Facebook Comments box after Relaterede indlæg (related posts).
Is this at all possible?
I don't use the FB plugins for Wordpress because they seem bloated to me. However, here's a simple one-line code that I use to add a facebook comments box. You can place it anywhere in any template.
<div class="fb-comments" data-href="<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ?>"></div>
PLEASE NOTE: this method requires that you have the Facebook SDK installed on the site. Also, it won't work as a widget unless you have enabled the ability to execute PHP in your widgets (requires a plug-in).

Paginator (Migration from Cake 1.3 to 2.0)

I am struggling with the paginator in Cakephp 2.0. While I am trying to migrate my application to 2.0 I cant find any solution to jump directly to the last page. In 1.3 it was quiet to do that from outside like this:
echo $this->Html->link(__('Flights'), array('controller' => 'flights',
'action' => 'index','page' => 'last'));
but this little trick putting 'page:last' in does not work anymore in 2.0. Of course there is a Paginator function called last, but this would only help if I would be already inside the app. My Problem is to access from an outside link directly the last page of the paginator.
This is the simple way:
echo $this->Paginator->last('Any text');
Other way to get the number of the last page is:
echo $this->Paginator->counter(array('format' => '{:pages}'));
Then you can use it to generate your link.
For more info:
http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::last
Shortly after creating a bounty for this question I found the solution to MY problem using CakePHP 2.2.4. I was trying to accomplish the same task but instead using version 2.2.4 instead instead of 2.0. Basically if I had a link that looked like http://www.domain.com/articles/page:last that the controller's pagination method would know what page to go to and display the correct results (articles) for that page. For example, if I have 110 articles and the pagination limit is set to 25, by going to that URL it would display page 5 of 5, showing records 101-110. I also wanted the same capability if I go to “page:first”.
I needed to change my library file lib/Cake/Controller/Component/PaginatorComponent.php.
I changed
if (intval($page) < 1) {
$page = 1;
}
To
if ((intval($page) < 1 && $page != "last") || $page == "first") {
$page = 1;
}
I also added
if($page == "last"){
$page = $pageCount;
}
After the line
$pageCount = intval(ceil($count / $limit));
Christian Waschke, with this solution, you can use the same link helper exactly how you wrote it in your question. For me, the link helper looked like this
<?php echo $this->Html->link('Go to Last Page', array('controller' => 'articles', 'action' => 'index', 'page' => 'last')); ?>
You can 'calculate' the last page yourself if 'last' is passed as the page number;
I would discourage making modifications in the CakePHP library files as this will make it hard to perform upgrades in the future.
Basically, the PaginatorHelper uses viewVars that are calculated and set by the PaginatorComponent, as seen here: https://github.com/cakephp/cakephp/blob/master/lib/Cake/Controller/Component/PaginatorComponent.php#L212
You can replicate this in your action; for example:
public function index()
{
if (!empty($this->request->params['named']['page'])) {
switch($this->request->params['named']['page']) {
case 'first':
// replace the 'last' with actual number of the first page
$this->request->params['named']['page'] = 1;
break;
case 'last':
// calculate the last page
$limit = 10; // your limit here
$count = $this->Flight->find('count');
$pageCount = intval(ceil($count / $limit));
// replace the 'last' with actual number of the last page
$this->request->params['named']['page'] = $pageCount;
break;
}
}
// then, paginate as usual
$this->set('data', $this->paginate('Flight'));
}
To improve this, this logic should be moved to a separate method, or to a behavior. However; as seen above, it is not required to make modifications in the PaginatorComponent!
Also note that the 'find(count)' in my example does not take additional conditions, they should be added if required
If you have a look in the CakePHP 1.3 source for paginate(), the code above is comparable; https://github.com/cakephp/cakephp/blob/1.3/cake/libs/controller/controller.php#L1204

PHP. Write an anchor in the Smarty template. (Kohana 3 + KSmarty)

I'm learning Kohana 3.2.0 together with KSmarty for Kohana 3. I'd like to write an anchor on the page like this:
Page list
I can build the url in the controller and pass it to Smarty as a variable but. Is there a way to build the anchor or URL in Smarty template (including "http://www.mysite.cz" part)?
If it is not possible to build the anchor. Is it at least possible to build full URL?
The Reason: I have a main template which includes another template.
The main template will be used by multiple controllers and I would like to avoid building the URL in each controller. Therefore I'll be happy if KSmarty will be able to do it for me.
The only solution I have found is to write custom function. Save following code into function.url.php file in Smarty plugins directory:
function smarty_function_url($params, &$smarty)
{
$type = '';
if(isset($params['type'])) $type = $params['type'];
$protocol = 'http';
if(isset($params['protocol'])) $protocol = $params['protocol'];
$url = '';
if(isset($params['url'])) $url = $params['url'];
$text = '';
if(isset($params['text'])) $text = $params['text'];
switch($params['type'])
{
case 'url':
return Kohana_URL::site($url, $protocol);
case 'anchor':
$url = Kohana_URL::site($url, $protocol);
return "<a href='{$url}'>{$text}</a>";
default:
return Kohana_URL::base('http');
}
}
Examples of use in Smarty template:
{url}
{url type='url' url='admin/categories' protocol='https'}
{url type='anchor' url='admin/articles' text='List of articles'}
The first block in which variables are set I had to write otherwise Smarty was generating notice "Undefined variable...". I'm just PHP student, suggestions for code improvement are welcome.
Hope it will help the others.

Resources