Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Redirecting K2 Author Pages to new profile page with Metamod?

Redirecting K2 Author Pages to new profile page with Metamod?

Dear Metamod Developers & Community,

Originally I had planned to use the K2 Author Page as the public profile for users by customizing its layout, but I've decided to use a different component to do the job. Unfortunately it's not possible to disable K2 Author Pages, and K2 comments (image and links) and K2 modules link to those pages, too. Luckily, the URLs to K2 Author Pages and the other component I'm using both include user ID numbers.

This would be an example of a user's K2 Author Page URL:
www.mysite.com/component/k2/author/1863?Itemid=495

And the other component's profile page for the same user I'm hoping to redirect to is:
www.mysite.com/profile/page/1863?task=page.display&page_id=6

As you can see, the "1863" is the user's ID #.

Do you think it would be possible to use Metamod to redirect all users away from K2 Author Pages to their Social Factory profile page by writing a recipe that focus on the users' ID #s? If so, any additional information about creating a redirect of this kind would be greatly appreciated!

I'm using:
Joomla 3.6.5
PHP 5.6.27
K2 2.7.0
Social Factory 3.5.7

Thank you!

Kind regards,

Scott Oman

baituo01
Intermediate Modder
ranks
useravatar
Offline
46 Posts
Administrator has disabled public posting

Re: Redirecting K2 Author Pages to new profile page with Metamod?

Hi Scott,

yes that should be pretty easy to do.

Try this:

$url = $core_genius->info("url");
$c = preg_match('#^http://www\.mysite\.com/component/k2/author/([0-9]+)#', $url, $matches);
if ($c) {
  $newurl = "http://www.mysite.com/profile/page/" . $matches[1] . "?task=page.display&page_id=6";
  $app = JFactory::getApplication();
  $app->redirect($newurl);
}

There are other ways of doing this too which might be better if the URL ever changes (e.g. using or not using SEF urls). But try the code above and see if that does the right thing for you.

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: Redirecting K2 Author Pages to new profile page with Metamod?

Thanks so much, Metamodguy!

Unfortunately the recipe doesn't seem to work at this time but I sincerely appreciate your support.

I'm currently using Metamod with the following recipe just to rotate between some modules on the frontpage etc.

session_start();
/* set a different "instance name" for each module that you want to show only once */
$instance_name = "module_counter1";
/* use as many or as few as you like, or "0" for no module */
$modules = array(179,168,178,177);
if (!isset($_SESSION[$instance_name]) ||
$_SESSION[$instance_name] == "") {
$_SESSION[$instance_name] = rand(0,(count($modules)));
}


$index = $_SESSION[$instance_name] % count($modules);
$_SESSION[$instance_name]++;
$module_no = $modules[$index];
if ($module_no > 0) return $module_no;

With that instance I've added a module class suffix _zmovies. I'm not sure if it's 'all' right but it functions the way I want, so I guess in that respect, it is "right" wink

Anyway, I tried adding the code you gave me to that instance of metamod in the PHP area. It had no effect.

Then I created a new instance of metamod which I entitled Metamod Redirect, added the code you gave me to the PHP area, and published. I tried publishing in a non-specified position as well as in right position. Again, there was no effect.

Am I doing something wrong? Or is it possible that that recipe just isn't working in my set up?

Thanks so much!

Kind regards,

Scott

baituo01
Intermediate Modder
ranks
useravatar
Offline
46 Posts
Administrator has disabled public posting

Re: Redirecting K2 Author Pages to new profile page with Metamod?

Never mind!! I made a mistake. It's working great.

Thank you! Metamod is amazing!

baituo01
Intermediate Modder
ranks
useravatar
Offline
46 Posts
Administrator has disabled public posting

Re: Redirecting K2 Author Pages to new profile page with Metamod?

Dear Metamodguy,

The only additional question I have about this recipe is about the speed at which the redirect happens.

Currently the www.mysite.com/component/k2/author/1863?Itemid=495  URL appears briefly and then the redirect occurs.

Is there anything that can be added so that the url above isn't flashed and/or the redirect occurs slightly faster without the pause?

Thanks very much!

baituo01
Intermediate Modder
ranks
useravatar
Offline
46 Posts
Administrator has disabled public posting

Re: Redirecting K2 Author Pages to new profile page with Metamod?

just subscribing

baituo01
Intermediate Modder
ranks
useravatar
Offline
46 Posts
Administrator has disabled public posting

Re: Redirecting K2 Author Pages to new profile page with Metamod?

Hi,

the reason for the delay is that MetaMod is a module, therefore gets rendered/executed quite late in the process of page creation. Sure it's convenient, but it does have that delay.

To get the PHP code to be executed earlier in the process, you could consider putting the code into your template index.php (note you would need to use a different piece of PHP to get the current URL since you would have access to $core_genius), or use Chameleon to do it, as Chameleon runs much earlier in the process of page creation, almost as soon as the request is received. That way you can bypass lots of the page creation process and jump to the redirect quicker.

Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: Redirecting K2 Author Pages to new profile page with Metamod?

Thanks, Stephen.

Is it possible to tell me what would need to change in this code if I were to insert it into the index.php or is it a kind of thing that you can't be sure of / need to play with?

$url = $core_genius->info("url");
$c = preg_match('#^http://www\.mysite\.com/component/k2/author/([0-9]+)#', $url, $matches);
if ($c) {
  $newurl = "http://www.mysite.com/profile/page/" . $matches[1] . "?task=page.display&page_id=6";
  $app = JFactory::getApplication();
  $app->redirect($newurl);
}

I just learned about your Chameleon product. I think I'll ask a couple questions in that forum since I have a few other important problems I still need to resolve and am not sure exactly how to go about doing it. I'd definitely be willing to pay for Chameleon if it could do the job.

Kind regards,

Scott

baituo01
Intermediate Modder
ranks
useravatar
Offline
46 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1667
Total Polls:
6
Total Posts:
5909
Posts this week:
1
User Info:
 
Total Users:
10137
Newest User:
lexispoker1
Members Online:
1
Guests Online:
225

Online: 
liaskas

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked