Joomla - Why does JControllerForm->cancel attempt to check in item? - joomla

I've come across a situation where, if a user tries to edit a checked out item, it seems they get stuck on the edit page because when they click cancel the controller cancel method attempts to check in the item which obviously it can't do and as a result redirects back to the item view which essentially renders the cancel method button useless...
I can't make sense of this as it would seem to me it would redirect to the list view if it can't check it in...??? Can anyone explain the logic to this because I don't understand.
I don't want to override the method to workaround this without understanding why Joomla does it...
Here is the cancel method from JcontrollerForm:
public function cancel($key = null)
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$app = JFactory::getApplication();
$model = $this->getModel();
$table = $model->getTable();
$checkin = property_exists($table, 'checked_out');
$context = "$this->option.edit.$this->context";
if (empty($key))
{
$key = $table->getKeyName();
}
$recordId = $app->input->getInt($key);
// Attempt to check-in the current record.
if ($recordId)
{
if ($checkin)
{
if ($model->checkin($recordId) === false)
{
// Check-in failed, go back to the record and display a notice.
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError()));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend($recordId, $key), false
)
);
return false;
}
}
}
// Clean the session data and redirect.
$this->releaseEditId($context, $recordId);
$app->setUserState($context . '.data', null);
$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToListAppend(), false
)
);
return true;
}

You can edit a checked out item if use "save to new." You are right that if an item is currently checked out it shouldn't attempt to check in prior to the save to new being done.

Related

How can I download pdf before loading another view in laravel?

after completing a registration formular, when user clicks submit button, I want to first download a pdf and then redirect user to a view. Here is my code :
public function formularSave(Request $request) {
if(!isset($_REQUEST['token'])) {
abort(404);
}
$token = $_REQUEST['token'];
$upd_app = Application::where('token', $token)->update([
'status' => 22
]);
$result = "Registration complete.";
$html .= 'Some test code here
<br>
<p>Date: '.date('d.m.Y H:i:s').'</p>
';
$pdf = PDF::loadHTML($html);
$filename = substr(md5(uniqid().time()), 0, 17) . '.pdf';
$pdf->save(storage_path().'/app/public/uploads/rezolutii/'.$filename);
//code for download pdf HERE!!!!
return view('site.pages.registercomplete', compact('result'));
}
How can I download the pdf, after I create it?
It's impossible on Laravel.
This will not work. Your browser operates on simple requests one goes out one comes in.
There is no way for browser to know if user finished downloading the file and saved it somewhere. The final response from browser if file to be downloaded, nothing can follow that as far as I understand.
Now I'm not sure how that can be handled in javascript but in pure html requests it will not work.
Check this https://laracasts.com/discuss/channels/laravel/redirect-after-download

Add Woocommerce Default Product Sorting

I need to change the default sorting to another sorting.
I want on my /shop/ page category and tags pages the products to show by default the last modified.When i edit a product and i change something inside the product to move on the first row.
Is there anyone who can help me with this please?
Best Regards
WooCommerce - Change default catalog sort order. Similarly do for shop page, etc by hooks.
/**
* This code should be added to functions.php of your theme
**/
add_filter('woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby');
function custom_default_catalog_orderby() {
return 'post_modified'; // Can also use title and price
}
[or]
add_filter('woocommerce_get_catalog_ordering_args', 'am_woocommerce_catalog_orderby');
function am_woocommerce_catalog_orderby( $args ) {
$args['orderby'] = 'last_modified';
$args['order'] = 'desc';
return $args;
}
Ref: https://gist.github.com/mikejolley/1622323
Or ref : this can do it in admin panel. but need to add the hooks in functions.php as mentioend above . Manageable in woocomerce admin panel.
http://www.remicorson.com/woocommerce-sort-products-from-oldest-to-most-recent/
Try this option it worked for me fine .
This worked for me. Manageable in woocomerce admin panel. http://www.remicorson.com/woocommerce-sort-products-from-oldest-to-most-recent/ . Add the following in your current theme (functions.php) file.
// Filters
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
// Apply custom args to main query
function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'oldest_to_recent' == $orderby_value ) {
$args['orderby'] = 'post_modified';
$args['order'] = 'DESC';
}
return $args;
}
/* Create new sorting method */
function custom_woocommerce_catalog_orderby( $sortby ) {
$sortby['oldest_to_recent'] =
__( 'Based on Last modified to be displayed recent', 'woocommerce' );
return $sortby;
}
Go to your admin panel http://localhost/wpppame/wp-admin/admin.php?page=wc-settings&tab=products&section=display and then you will see the new option added. Select it and click save. Then go to front end of localhost/wpppame/shop, you can see the changes in the page.

cakephp ajax function issue

I have 2 functions in "events" (index, event_ajax)controller in my cakephp(2.5) web site. I'm trying to load HTML block to 'index.ctp' page by calling to 'event_ajax' function using ajax. When I call to this function it shows nothing. Look at 'net' tab in firebug it shows internal server error and 'net'->'Response' tab I can see whole layout is loaded.
I'm little confuse about in this scenario, can any one give a little explanation for following questions??? thanks in advance :)
Is it possible to call actions in same controller using ajax function ??
How 'Response' tab shows layout when '$this->layout' is set to NULL ??
when type url 'example.com/events/event_ajax', output data still '$this->autoRender=false'. how can this happen ??
this is my 'event_ajax' action.
public function event_ajax($x=1) {
$this->layout = NULL;
$this->autoRender = false ;
$contName = $this->Page->conName($x);
$latestContEvents = $this->Page->latestContEvent($x);
$internal = '';
if (!empty($latestContEvents)){
foreach ($latestContEvents AS $latestContEvent){
$internal .= '<li class="pull-left"> <div class="content-wrapper">'..... //do something
}
else {
$internal = '<p> No events found for this continent</p>';
}
$ContEvents = '<div class="carousel events-location-carousel">'.$internal.'</div> ';
return $ContEvents;
// return json_encode($ContEvents);
}
Try with
$this->layout = 'ajax';

How to logout from site?

How to logout from all pages of view, when I click on logout link I just from only one page when I am trying to logout from another page its not work.
My controller code is:
public function do_login()
{
$this->user = $this->input->post('user_email',TRUE);
$this->pass = $this->input->post('user_pass',TRUE);
$this->pass=md5(sha1(sha1($this->pass)));
$u = new User();
$login_data = array('email' => $this->user, 'password' => $this->pass);
$u->where($login_data)->get();
if(!empty($u->id) && $u->id > 0 )
{
$_SESSION['user_id'] = $u->id;
$_SESSION['user_name']= $u->username;
$_SESSION['fullname']= $u->fullname;
$_SESSION['is_verefied'] = $u->active;
$_SESSION['user_email']= $u->email;
$u->lastlogin = time();
$u->save();
setcookie("logged", 1, time()+86400);
if(empty($_POST['referer']))
{
if(empty($_GET['referer']))
{
$url = "./";
}
else
{
$url = $_GET['referer'];
}
}
else
{
$url = $_POST['referer'];
}
redirect($url);
}
else
{
$this->template->set_layout('inner');
$this->template->build('login_view',$this->data);
}
}
public function logout()
{
setcookie("logged", 0, time()+86400);
$_COOKIE["logged"] = '';
$_SESSION['user_id'] = '';
$_SESSION['user_name']= '';
$_SESSION['fullname']= '';
$_SESSION['is_verefied'] = '';
$_SESSION['user_email']= '';
redirect('./home/index/logout');
}
When I logout from site, and click back from browser the user information session its not deleted.
The back button of your browser might get you to cached version of you page, cached from back when you were logged it. Also, I suggest you use CodeIgniter's sessions.
To make sure you're doing everything right.
Destroy the session:
$this->session->sess_destroy();
Clear the cookie, make sure you use the same domain as when you set it up, and that the time is set to past:
setcookie('logged', '', time()-3600); // minus one hour
This script will log the user out of all pages that have a session started on them. You know a page uses sessions if this code is at the top of the code for that page:
<?php session_start(); ?>
Logging out of a website is simply clearing any session data and then destroying it.
Try the following in your logout.php:
<?php
session_start();
// what were doing here is checking for any cookies used by the session.
//If there are any, we are going to delete the data with it.
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
//now lets unset the session and destroy it
session_unset();
session_destroy();
// for the redirect, we simple use the php header to send the redirect url to the browser
header("Location: login");
Make sure when using the header function that there is no output, caused by blank spaces or html. As a logout page, there should be no output anyways since navigating to the logout page should log the user out and immediately redirect.
I use this script on all my sites and it works great. Anywhere I want the logout link to appear, I just link to the page as such:
Logout
Just make a file called logout.php and put this code into it.
Hope this helps you!

WordPress plugin: finding the <!--more--> in the_content

I'm writing a WordPress plugin that filters the_content, and I'd like to make use of the <!--more--> tag, but it appears that it has been stripped out by the time it reaches me. This appears to be not a filter, but a function of the way WordPress works.
I could of course resort to reloading the already-loaded content from the database, but that sounds like it might cause other troubles. Is there any good way for me to get the raw content without the <!--more--> removed?
Chances are, by the time your plugin runs, <!--more--> has been converted to <span id="more-1"></span>
This is what I use in my plugin, which injects some markup immediately after the <!--more--> tag:
add_filter('the_content', 'inject_content_filter', 999);
function inject_content_filter($content) {
$myMarkup = "my markup here<br>";
$content = preg_replace('/<span id\=\"(more\-\d+)"><\/span>/', '<span id="\1"></span>'."\n\n". $myMarkup ."\n\n", $content);
return $content;
}
You can use the follow code:
The !is_single() will avoid display the more link in the View Post page.
add_filter('the_content', 'filter_post_content');
function filter_post_content($content,$post_id='') {
if ($post_id=='') {
global $post;
$post_id = $post->ID;
}
// Check for the "more" tags
$more_pos = strpos($filtered_content, '<!--more-->');
if ($more_pos && !is_single()) {
$filtered_content = substr($filtered_content, 0, $more_pos);
$replace_by = '<a href="' . get_permalink($post_id) . '#more-' . $post_id
. '" class="more-link">Read More <span class="meta-nav">→</span></a>';
$filtered_content = $filtered_content . $replace_by;
}
return $filtered_content;
}
Based on Frank Farmer's answer I solved to add thumbnail photo after the generated more tag (<span id="more-...) in single.php file with this:
// change more tag to post's thumbnail in single.php
add_filter('the_content', function($content)
{
if(has_post_thumbnail())
{
$post_thumbnail = get_the_post_thumbnail(get_the_ID(), 'thumbnail', array('class'=>'img img-responsive img-thumbnail', 'style'=>'margin-top:5px;'));
$content = preg_replace('/<span id\=\"(more\-\d+)"><\/span>/', '<span id="\1"></span>'.$post_thumbnail, $content);
}
return $content;
}, 999);

Resources