PHP dynamic URL keeps adding/doubling the full path when i click a button on the site - redirect

I am running into an issue and I hope someone here can help. I have put together a dynamic URL manipulator that should just work out the path to the file being displayed, which it does and when I click a link, it should process the new link and replace the existing URL. The issue is that instead of replacing the URL with the new url path, it adds it to the end of the existing URL which is why it does not work. an example is as follows:
https://localhost/home/main/localhost/home/main/pages/about
the part from the second localhost... should replace the first url path but it adds to it and therefore it does not work. the code for this is as follows:
class Core {
protected $currentController = 'Pages';
protected $currentMethod = 'index';
protected $params = [];
public function __construct(){
//print_r($this->getUrl());
$url = $this->getUrl();
if(file_exists('../app/controllers/' . ucwords($url[0]). '.php')){
$this->currentController = ucwords($url[0]);
unset($url[0]);
}
require_once '../app/controllers/'. $this->currentController . '.php';
$this->currentController = new $this->currentController;
if(isset($url[1])){
if(method_exists($this->currentController, $url[1])){
$this->currentMethod = $url[1];
unset($url[1]);
}
}
$this->params = $url ? array_values($url) : [];
call_user_func_array([$this->currentController, $this->currentMethod], $this->params);
}
public function getUrl(){
if(isset($_GET['url'])){
$url = rtrim($_GET['url'], '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/', $url);
return $url;
}
}
}

Hi anyone who cares to know the solution to this, or have a similar issue and is looking to find a solution.
I found out that the issue was with the htaccess file which did not have the full root of the home page.
I had entered
RewriteBase /main/public
my app is in a subfolder called home so after updating it to the following, it works like a charm.
RewriteBase /home/main/public

Related

zend session namespace not working

I am unable to access zend session in included file via layout.
what i have done so far -
//bootstrap
public function _initSession()
{
Zend_Session::start();
$test = new Zend_Session_Namespace('test');
}
//controller
public function init(){
$test = new Zend_Session_Namespace('test');
$test->abc = 'defghi';
}
//layout include file
<?php include_once( APPLICATION_PATH . '/data/ga_test.php');?>
//ga_test.php
$test = new Zend_Session_Namespace('test');
echo 'this is ' . $test->abc;
I am not able to access the variable in ga_test file. I am getting an empty variable. But if I include ga_test end of each view file then it works. Obviously I don't want to go to every view file and include ga_test.php. Can I do this via layout.
I am sure, I am doing something wrong here. Any help would be really appreciated.
Thanks

Export CSV functionality for gird inside admin edit form tab magento

I have a magento grid collection inside admin edit form tab.I need a export csv functionality for the grid.Its working fine with full grid list without search filters.How to export csv for the filtered collection as well?
Go to your module or extension folder then /Block/Adminhtml/Blog/Grid.php. Open this Grid.php file and search the function protected function _prepareCollection() and add the following code under this function before return parent::_prepareColumns();.
$this->addExportType('*/*/exportCsv', Mage::helper('blog')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('blog')->__('XML'));
After add this code it may be looks like that:
Next, in this extension or module folder go to /controllers/Adminhtml/ and open the controller file and add the following code under the class (add the code bottom of the page before last '}')
public function exportCsvAction()
{
$fileName = 'blog.csv';
$content = $this->getLayout()->createBlock('[your-module-name]/adminhtml_[your-module-name]_grid')
->getCsv();
$this->_sendUploadResponse($fileName, $content);
}
public function exportXmlAction()
{
$fileName = 'blog.xml';
$content = $this->getLayout()->createBlock('[your-module-name]/adminhtml_[your-module-name]_grid')
->getXml();
$this->_sendUploadResponse($fileName, $content);
}
protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
{
$response = $this->getResponse();
$response->setHeader('HTTP/1.1 200 OK','');
$response->setHeader('Pragma', 'public', true);
$response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
$response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
$response->setHeader('Last-Modified', date('r'));
$response->setHeader('Accept-Ranges', 'bytes');
$response->setHeader('Content-Length', strlen($content));
$response->setHeader('Content-type', $contentType);
$response->setBody($content);
$response->sendResponse();
die;
}
Now replace the [your-module-name] text with your extension or module name and save then check.
* Please like if this post help you!*

Redirection from component to view in joomla 2.5.8

I am new to joomla. am using joomla 2.5.8 version. i have created one component. i can post form data from view to task in component. but i couldn't redirect from task to view. this is my simple function in controller. This URL is saved in Redirect manager.
function sample(){
$mainframes = JFactory::getApplication();
$link= JRoute::_('index.php?option=com_new',FALSE);
$msg = JText::_('welcome');
$mainframes->redirect($link,$msg);
}
This works for me in my component's custom task, release():
# Get iop_id from query string
$app = JFactory::getApplication();
$iop_id = $app->input->get('id');
$url = JRoute::_('index.php?option=com_iop&task=plan.edit&id=' . (int)$iop_id, false);
$app->redirect($url);
$id = JRequest::getVar('id');
$app = JFactory::getApplication();
$url = JRoute::_('index.php?option=com_iop&task=plan.edit&id=' . (int)$id);
$app->redirect($url);

How is defined current url in zend (inside job of a framework)

Tell please what script uses zend framework for definition current URL? More exactly I interest what use ZEND for definition domain name: this $_SERVER['HTTP_HOST'] or this
$_SERVER['SERVER_NAME'] ? (or may be something other)?
P.S. ( I search in documentation but not found, (I do not know this framework), also I search in google, but also not found answer on my question? )
Try use: $this->getRequest()->getRequestUri() to get current of requested URI.
In the view script use: $this->url() to get current URL.
Or using via static integrated Zend Controller front via instance:
$uri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
You can get a value of URI implementation via singleton to get a value of request() data:
$request = Zend_Controller_Front::getInstance()->getRequest();
$url = $request->getScheme() . '://' . $request->getHttpHost();
On the View use it as:
echo $this->serverUrl(true); # return with controller, action,...
You should avoid hardcode such as example (NOT TO USE!):
echo 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
instead of this example use as on a view:
$uri = $this->getRequest()->getHttpHost() . $this->view->url();
If you want using getRequest in ZEND more explore The Request Object.
SKIP IT BELOW (AUTOPSY EXAMPLE HOW WORKS IT).
Full of example code how getRequestUri() how it works and why is isRequest instead using $_SERVER is because on a platform specific is randomly get a data:
first if uri null, thand if requested from IIS set is as HTTP_X_REWRITE_URL. If not, check on IIS7 rewritten uri (include encoded uri). If not on IIS than REQUEST_URI will check scheme of HTTP_HOSTNAME, or if failed use as ORIG_PATH_INFO and grab a QUERY_STRING.
If is setted, grab a data automatically via string of returned object $this in a class.
If failed, than will be set a parsed string than set it.
if ($requestUri === null) {
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
$requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif (
// IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem)
isset($_SERVER['IIS_WasUrlRewritten'])
&& $_SERVER['IIS_WasUrlRewritten'] == '1'
&& isset($_SERVER['UNENCODED_URL'])
&& $_SERVER['UNENCODED_URL'] != ''
) {
$requestUri = $_SERVER['UNENCODED_URL'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$requestUri = $_SERVER['REQUEST_URI'];
// Http proxy reqs setup request uri with scheme and host [and port] + the url path, only use url path
$schemeAndHttpHost = $this->getScheme() . '://' . $this->getHttpHost();
if (strpos($requestUri, $schemeAndHttpHost) === 0) {
$requestUri = substr($requestUri, strlen($schemeAndHttpHost));
}
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI
$requestUri = $_SERVER['ORIG_PATH_INFO'];
if (!empty($_SERVER['QUERY_STRING'])) {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
return $this;
}
} elseif (!is_string($requestUri)) {
return $this;
} else {
// Set GET items, if available
if (false !== ($pos = strpos($requestUri, '?'))) {
// Get key => value pairs and set $_GET
$query = substr($requestUri, $pos + 1);
parse_str($query, $vars);
$this->setQuery($vars);
}
}
$this->_requestUri = $requestUri;
return $this;

Joomla plugin not being called

This is my 1st time I'm attempting to create a Joomla plugin and I need some help on getting this to work. The plugin is quite simple, I want to capture the HTTP_REFERER, check if the request was made from Google organic or paid results, pass the data to a session var and then submit it along with the values in a contact form. (there's a hidden field in my form and it gets the session var value). I use RSForms for creating my forms, just for the reference.
In the beginning, I hardcoded the following code into index.php at site root and it worked fine. Now, I'm trying to make a proper plugin but I can't get it to fire off when pages are loaded. I've tried all the system methods, still failing to get it to run.
This is my code:
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
class plgSystemRsformsGoogleReferer extends JPlugin
{
public function plgSystemRsformsGoogleReferer( &$subject, $config )
{
parent::__construct( $subject, $config );
}
function onAfterRender()
{
$session = & JFactory::getSession();
if (!$session->get('referrer', $origref, 'extref')) //If does not exist
{
$origref = $_SERVER['HTTP_REFERER'];
$session->set('referrer', $origref, 'extref');
$q = search_engine_query_string($session->get('referrer', $origref, 'extref'));
if(stristr($origref, 'aclk')) { // if referer is a google adwords link as opposed to an organic link
$type = ', paid link';
} else {
$type = ', organic result';
}
$ginfo = $q.$type;
$session->set('referrer', $ginfo, 'extref');
}
function search_engine_query_string($url = false) {
if(!$url && !$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false) {
return '';
}
$parts_url = parse_url($url);
$query = isset($parts_url['query']) ? $parts_url['query'] : (isset($parts_url['fragment']) ? $parts_url['fragment'] : '');
if(!$query) {
return '';
}
parse_str($query, $parts_query);
return isset($parts_query['q']) ? $parts_query['q'] : (isset($parts_query['p']) ? $parts_query['p'] : '');
}
}
}
And this is my manifest xml for the plugin installation (installation works fine):
<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="system" method="upgrade">
<name>RSForm Google Referer v1.1</name>
<author>Me</author>
<creationDate>July 2012</creationDate>
<copyright>(C) 2004-2012 www.mysite.com</copyright>
<license>Commercial</license>
<authorEmail>info#mysite.com</authorEmail>
<authorUrl>www.mysite.com</authorUrl>
<version>1.1</version>
<description><![CDATA[Track visitor's search terms and and attaches the information to the RSForm! Pro Forms emails when sent.]]></description>
<files>
<filename plugin="rsform_google_referer">rsform_google_referer.php</filename>
</files>
</install>
I feel I'm close but I can't get it to run, any suggestions will be appreciated. Thanks!
The name of the class is wrong. It needs to match the name of the plugin folder and that name of the plugin file. It should be:
class plgSystemRsform_Google_Referer extends JPlugin
That is Rsform not Rsforms and the underscores.