/**
  * Method for to append new track into database
  *
  */
 function append()
 {
     $dispatcher = JDispatcher::getInstance();
     // Send the appropriate error code response.
     JResponse::clearHeaders();
     JResponse::setHeader('Content-Type', 'application/json; charset=utf-8');
     JResponse::sendHeaders();
     $total = $_GET['total'];
     $one_procent = 1 / ($total / 100);
     $curr_index = number_format($_GET['total'] * $_GET['status'] / 100, 0, '', '');
     $path_from_cache = explode('*|*', JFactory::getApplication()->getUserState('com_playjoom.path.array'));
     $php_array['status'] = $_GET['status'] + $one_procent;
     //$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => 'Add track no '.$curr_index.' in path: '.base64_decode(($path_from_cache[$curr_index] - 1)), 'priority' => JLog::INFO, 'section' => 'admin')));
     if (isset($path_from_cache[$curr_index])) {
         $model = $this->getModel('savetracks');
         $model->AddTrackItem(base64_decode($path_from_cache[$curr_index]), 'audio');
     }
     // Bei 100% ist Schluss ;)
     if ($php_array['status'] > 100) {
         $php_array['status'] = 100;
     }
     if ($php_array['status'] != 100 && isset($path_from_cache[$curr_index])) {
         $php_array['message'] = JText::_('COM_PLAYJOOM_SAVETRACKS_CURRENT_STATUS') . ' ' . ($curr_index + 1) . ' / ' . $total . ' - ' . round($php_array['status'], 1) . '%';
         $php_array['message_path'] = JText::_('COM_PLAYJOOM_SAVETRACKS_PATH_STATUS') . ' ' . base64_decode($path_from_cache[$curr_index]);
     } else {
         //Clear UserStates in session
         JFactory::getApplication()->setUserState('com_playjoom.savetracks', null);
         JFactory::getApplication()->setUserState('com_playjoom.path.array', null);
         JFactory::getApplication()->setUserState('com_playjoom.path.data', null);
         $php_array['message'] = 'done';
     }
     // Output as PHP arrays as JSON Objekt
     echo json_encode($php_array);
 }
Example #2
0
 /**
  * Send response in JSON-format
  * @param array $data
  * @param bool  $result
  */
 public function send(array $data = array(), $result = true)
 {
     $data['result'] = $result;
     JResponse::allowCache(false);
     JResponse::setHeader('Last-Modified', gmdate('D, d M Y H:i:s', time()) . ' GMT', true);
     JResponse::setHeader('Content-Type', 'application/json; charset=utf-8', true);
     JResponse::sendHeaders();
     jexit(json_encode($data));
 }
Example #3
0
 /**
  * Execute and display a template script.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise a JError object.
  */
 public function display($tpl = Null)
 {
     $app = JFactory::getApplication();
     $jinput = JFactory::getApplication()->input;
     $date = JFactory::getDate();
     $layout = $jinput->get('layout');
     if ($layout == 'saveTables') {
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select($db->quoteName('manifest_cache'));
         $query->from($db->quoteName('#__extensions'));
         $query->where($db->quoteName('element') . " = " . $db->quote('com_bwpostman'));
         $db->SetQuery($query);
         $manifest = json_decode($db->loadResult(), true);
         $version = str_replace('.', '_', $manifest['version']);
         $filename = "BwPostman_" . $version . "_Tables_" . $date->format("Y-m-d_H:i") . '.xml';
         $mime_type = "application/xml";
         // Maybe we need other headers depending on browser type...
         jimport('joomla.environment.browser');
         $browser = JBrowser::getInstance();
         $user_browser = $browser->getBrowser();
         JResponse::clearHeaders();
         JResponse::setHeader('Content-Type', $mime_type, true);
         // Joomla will overwrite this...
         JResponse::setHeader('Content-Disposition', "attachment; filename=\"{$filename}\"", true);
         JResponse::setHeader('Expires', gmdate('D, d M Y H:i:s') . ' GMT', true);
         JResponse::setHeader('Pragma', 'no-cache', true);
         if ($user_browser == "msie") {
             JResponse::setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
             JResponse::setHeader('Pragma', 'public', true);
         }
         // Joomla overwrites content-type, we can't use JResponse::setHeader()
         $document = JFactory::getDocument();
         $document->setMimeEncoding("application/xml");
         @ob_end_clean();
         ob_start();
         JResponse::sendHeaders();
         // Get the export data
         $model = $this->getModel('maintenance');
         readfile($model->saveTables(false));
     }
     if ($layout == 'doRestore') {
         $model = $this->getModel();
         $dest = $app->getUserState('com_bwpostman.maintenance.dest', '');
         $model->restoreTables($dest);
     }
     if ($layout == 'checkTables') {
         $model = $this->getModel();
         echo '<div class="modal" rel="{size: {x: 700, y: 500}}">';
         $model->checkTables();
         echo '</div>';
     }
 }
Example #4
0
 /**
  * Method to handle a send a JSON response. The body parameter
  * can be a JException object for when an error has occurred or
  * a JObject for a good response.
  *
  * @param	object	$body	JObject on success, JException on failure.
  * @return	void
  */
 public function sendResponse($body)
 {
     // Check if we need to send an error code.
     if (JError::isError($body)) {
         // Send the appropriate error code response.
         JResponse::setHeader('status', $body->getCode());
         JResponse::sendHeaders();
     }
     // Send the JSON response.
     echo json_encode(new UsersLevelResponse($body));
     // Close the application.
     $app = JFactory::getApplication();
     $app->close();
 }
Example #5
0
 public function __construct()
 {
     parent::__construct();
     $stateModel = VmModel::getModel('state');
     $states = array();
     //retrieving countries id
     $countries = vRequest::getString('virtuemart_country_id');
     $countries = explode(',', $countries);
     foreach ($countries as $country) {
         $states[$country] = $stateModel->getStates((int) $country, true, true);
     }
     JResponse::setHeader("Content-type", "application/json");
     JResponse::sendHeaders();
     echo json_encode($states);
     jExit();
 }
Example #6
0
 /**
  * Method to render the plugin datas
  * this is an entry point to plugin to easy renders json or html
  *
  *
  * @access    public
  */
 function display($cachable = false, $urlparams = false)
 {
     if (!($type = vRequest::getCmd('vmtype', NULL))) {
         $type = vRequest::getCmd('type', 'vmcustom');
     }
     $typeWhiteList = array('vmcustom', 'vmcalculation', 'vmuserfield', 'vmpayment', 'vmshipment');
     if (!in_array($type, $typeWhiteList)) {
         return FALSE;
     }
     $name = vRequest::getCmd('name', 'none');
     $nameBlackList = array('plgVmValidateCouponCode', 'plgVmRemoveCoupon', 'none');
     if (in_array($name, $nameBlackList)) {
         echo 'You got logged';
         return FALSE;
     }
     JPluginHelper::importPlugin($type, $name);
     $dispatcher = JDispatcher::getInstance();
     // if you want only one render simple in the plugin use jExit();
     // or $render is an array of code to echo as html or json Objects!
     $render = NULL;
     $dispatcher->trigger('plgVmOnSelfCallFE', array($type, $name, &$render));
     if ($render) {
         // Get the document object.
         $document = JFactory::getDocument();
         if (vRequest::getCmd('cache') == 'no') {
             JResponse::setHeader('Cache-Control', 'no-cache, must-revalidate');
             JResponse::setHeader('Expires', 'Mon, 6 Jul 2000 10:00:00 GMT');
         }
         $format = vRequest::getCmd('format', 'json');
         if ($format == 'json') {
             $document->setMimeEncoding('application/json');
             // Change the suggested filename.
             JResponse::setHeader('Content-Disposition', 'attachment;filename="' . $type . '.json"');
             JResponse::setHeader("Content-type", "application/json");
             JResponse::sendHeaders();
             echo json_encode($render);
             jExit();
         } else {
             echo $render;
             jExit();
         }
     } else {
     }
 }
Example #7
0
 /**
  * Execute and display a template script.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise a JError object.
  */
 public function display($tpl = Null)
 {
     $app = JFactory::getApplication();
     // Get the post data
     $post = $app->getUserState('com_bwpostman.subscribers.export.data');
     if ($post['fileformat'] == 'csv') {
         $mime_type = "application/csv";
     } else {
         $mime_type = "application/xml";
     }
     $date = JFactory::getDate();
     $filename = "BackupList_BwPostman_from_" . $date->format("Y-m-d");
     // Maybe we need other headers depending on browser type...
     jimport('joomla.environment.browser');
     $browser = JBrowser::getInstance();
     $user_browser = $browser->getBrowser();
     JResponse::clearHeaders();
     JResponse::setHeader('Content-Type', $mime_type, true);
     // Joomla will overwrite this...
     if ($post['fileformat'] == 'csv') {
         JResponse::setHeader('Content-Disposition', "attachment; filename=\"{$filename}.csv\"", true);
     } else {
         JResponse::setHeader('Content-Disposition', "attachment; filename=\"{$filename}.xml\"", true);
     }
     JResponse::setHeader('Expires', gmdate('D, d M Y H:i:s') . ' GMT', true);
     JResponse::setHeader('Pragma', 'no-cache', true);
     if ($user_browser == "msie") {
         JResponse::setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
         JResponse::setHeader('Pragma', 'public', true);
     }
     // Joomla overwrites content-type, we can't use JResponse::setHeader()
     $document = JFactory::getDocument();
     $document->setMimeEncoding($mime_type);
     @ob_end_clean();
     ob_start();
     JResponse::sendHeaders();
     // Get the export data
     $model = $this->getModel('subscriber');
     echo $model->export($post);
 }
Example #8
0
 /**
  * Send response in JSON-format
  * @param array $data
  * @param bool  $result
  */
 public function send(array $data = array(), $result = true)
 {
     $data['result'] = $result;
     if (!isset($data['message'])) {
         $data['message'] = false;
     }
     if ($this->app->jbversion->joomla('3')) {
         $app = JFactory::getApplication();
         $app->allowCache(false);
         $app->setHeader('Last-Modified', gmdate('D, d M Y H:i:s', time()) . ' GMT', true);
         $app->setHeader('Content-Type', 'application/json; charset=utf-8', true);
         $app->sendHeaders();
     } else {
         JResponse::allowCache(false);
         JResponse::setHeader('Last-Modified', gmdate('D, d M Y H:i:s', time()) . ' GMT', true);
         JResponse::setHeader('Content-Type', 'application/json; charset=utf-8', true);
         JResponse::sendHeaders();
     }
     if (JDEBUG) {
         $data['mpu'] = round(memory_get_peak_usage(true) / 1024 / 1024, 2) . ' M';
     }
     jexit(json_encode($data));
 }
Example #9
0
 public function sendHeaders()
 {
     if (version_compare($this->version, '3.2', 'ge')) {
         JFactory::getApplication()->sendHeaders();
     } else {
         JResponse::sendHeaders();
     }
 }
Example #10
0
 public function download()
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationAdministrator */
     $type = $this->input->get->getCmd("type");
     $model = $this->getModel();
     try {
         switch ($type) {
             case "locations":
                 $output = $model->getLocations();
                 $fileName = "locations.xml";
                 break;
             case "currencies":
                 $output = $model->getCurrencies();
                 $fileName = "currencies.xml";
                 break;
             case "countries":
                 $output = $model->getCountries();
                 $fileName = "countries.xml";
                 break;
             case "states":
                 $output = $model->getStates();
                 $fileName = "states.xml";
                 break;
             default:
                 // Error
                 $output = "";
                 $fileName = "error.xml";
                 break;
         }
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_VIRTUALCURRENCY_ERROR_SYSTEM'));
     }
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.path');
     jimport('joomla.filesystem.archive');
     $tmpFolder = JPath::clean($app->get("tmp_path"));
     $date = new JDate();
     $date = $date->format("d_m_Y_H_i_s");
     $archiveName = JFile::stripExt(basename($fileName)) . "_" . $date;
     $archiveFile = $archiveName . ".zip";
     $destination = $tmpFolder . DIRECTORY_SEPARATOR . $archiveFile;
     // compression type
     $zipAdapter = JArchive::getAdapter('zip');
     $filesToZip[] = array('name' => $fileName, 'data' => $output);
     $zipAdapter->create($destination, $filesToZip, array());
     $filesize = filesize($destination);
     JResponse::setHeader('Content-Type', 'application/octet-stream', true);
     JResponse::setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
     JResponse::setHeader('Content-Transfer-Encoding', 'binary', true);
     JResponse::setHeader('Pragma', 'no-cache', true);
     JResponse::setHeader('Expires', '0', true);
     JResponse::setHeader('Content-Disposition', 'attachment; filename=' . $archiveFile, true);
     JResponse::setHeader('Content-Length', $filesize, true);
     $doc = JFactory::getDocument();
     $doc->setMimeEncoding('application/octet-stream');
     JResponse::sendHeaders();
     echo file_get_contents($destination);
     JFactory::getApplication()->close();
 }
Example #11
0
 /**
  * Sends all headers prior to returning the string
  *
  * @access public
  * @param boolean 	$compress	If true, compress the data
  * @return string
  */
 function toString($compress = false)
 {
     $data = JResponse::getBody();
     // Don't compress something if the server is going todo it anyway. Waste of time.
     if ($compress && !ini_get('zlib.output_compression') && ini_get('output_handler') != 'ob_gzhandler') {
         $data = JResponse::_compress($data);
     }
     if (JResponse::allowCache() === false) {
         JResponse::setHeader('Expires', 'Mon, 1 Jan 2001 00:00:00 GMT', true);
         // Expires in the past
         JResponse::setHeader('Last-Modified', gmdate("D, d M Y H:i:s") . ' GMT', true);
         // Always modified
         JResponse::setHeader('Cache-Control', 'no-store, no-cache, must-revalidate', true);
         // Extra CYA
         JResponse::setHeader('Cache-Control', 'post-check=0, pre-check=0', false);
         // HTTP/1.1
         JResponse::setHeader('Pragma', 'no-cache');
         // HTTP 1.0
     }
     JResponse::sendHeaders();
     return $data;
 }
Example #12
0
 public function sendHeaders()
 {
     JResponse::sendHeaders();
 }
Example #13
0
    exit;
}
$fh = fopen($file, 'rb') or die('cannot open file: ' . $fileName);
$fileSize = filesize($file) - ($pos > 0 ? $pos + 1 : 0);
fseek($fh, $pos);
$binary_header = strtoupper(JFile::getExt($file)) . pack('C', 1) . pack('C', 1) . pack('N', 9) . pack('N', 9);
session_cache_limiter('none');
JResponse::clearHeaders();
JResponse::setHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT', true);
JResponse::setHeader('Last-Modified', gmdate("D, d M Y H:i:s") . ' GMT', true);
JResponse::setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true);
JResponse::setHeader('Pragma', 'no-cache', true);
JResponse::setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true);
JResponse::setHeader('Content-Length', $pos > 0 ? $fileSize + 13 : $fileSize, true);
JResponse::setHeader('Content-Type', 'video/x-flv', true);
JResponse::sendHeaders();
if ($pos > 0) {
    print $binary_header;
}
$limit_bw = true;
$packet_size = 90 * 1024;
$packet_interval = 0.3;
while (!feof($fh)) {
    if (!$limit_bw) {
        print fread($fh, filesize($file));
    } else {
        $time_start = microtime(true);
        print fread($fh, $packet_size);
        $time_stop = microtime(true);
        $time_difference = $time_stop - $time_start;
        if ($time_difference < $packet_interval) {
Example #14
0
 function download()
 {
     jimport('joomla.filesystem.file');
     $session = JFactory::getSession();
     $mainframe = JFactory::getApplication();
     jimport('joomla.filesystem.file');
     $k2_params = JComponentHelper::getParams('com_k2');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/tables');
     $id = JRequest::getInt('orderItem');
     $attachment = JTable::getInstance('K2Attachment', 'Table');
     if ($mainframe->isSite()) {
         $token = JRequest::getVar('orderItem');
         $check = JString::substr($token, JString::strpos($token, '_') + 1);
         if ($check != JApplication::getHash($id . $session->getToken())) {
             JError::raiseError(404, JText::_('K2_NOT_FOUND'));
         }
     }
     $attachment->load($id);
     $path = $k2_params->get('attachmentsFolder', NULL);
     if (is_null($path)) {
         $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments';
     } else {
         $savepath = $path;
     }
     $file = $savepath . DS . $attachment->filename;
     if (JFile::exists($file)) {
         require_once JPATH_ADMINISTRATOR . '/components/com_k2/lib/class.upload.php';
         $handle = new Upload($file);
         if ($mainframe->isSite()) {
             $attachment->hit();
         }
         $len = filesize($file);
         $filename = basename($file);
         ob_end_clean();
         JResponse::clearHeaders();
         JResponse::setHeader('Pragma', 'public', true);
         JResponse::setHeader('Expires', '0', true);
         JResponse::setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
         JResponse::setHeader('Content-Type', $handle->file_src_mime, true);
         JResponse::setHeader('Content-Disposition', 'attachment; filename=' . $filename . ';', true);
         JResponse::setHeader('Content-Transfer-Encoding', 'binary', true);
         JResponse::setHeader('Content-Length', $len, true);
         JResponse::sendHeaders();
         echo JFile::read($file);
     } else {
         echo JText::_('K2_FILE_DOES_NOT_EXIST');
     }
     $mainframe->close();
 }
Example #15
0
	/**
	 * Method to handle a send a JSON response. The data parameter
	 * can be a JException object for when an error has occurred or
	 * a JObject for a good response.
	 *
	 * @param	object	$response	JObject on success, JException on failure.
	 *
	 * @return	void
	 * @since	1.6
	 */
	public function sendResponse($response)
	{
		// Check if we need to send an error code.
		if (JError::isError($response)) {
			// Send the appropriate error code response.
			JResponse::setHeader('status', $response->getCode());
			JResponse::setHeader('Content-Type', 'application/json; charset=utf-8');
			JResponse::sendHeaders();
		}

		// Send the JSON response.
		echo json_encode(new JInstallationJsonResponse($response));

		// Close the application.
		$app = JFactory::getApplication();
		$app->close();
	}
Example #16
0
 /**
  * Method for sending the page header
  *
  * @param string $playlistFileName Name of the playlist file
  * @param string $playlistType     Mimetype of the playlist
  * @param int    $playlistSize     Data size of the created playlist
  *
  * @return void
  */
 public function setHeader($playlistFileName, $playlistType, $playlistSize)
 {
     //Setup web server
     if (isset($_SERVER['SERVER_SOFTWARE'])) {
         $sf = $_SERVER['SERVER_SOFTWARE'];
     } else {
         $sf = getenv('SERVER_SOFTWARE');
     }
     if (!strpos($sf, 'IIS')) {
         @apache_setenv('no-gzip', 1);
     }
     @ini_set('zlib.output_compression', 0);
     ignore_user_abort(false);
     JResponse::clearHeaders();
     header("HTTP/1.1 200 OK");
     JResponse::setHeader('Accept-Range', 'bytes', true);
     JResponse::setHeader('X-Pad', 'avoid browser bug');
     JResponse::setHeader('Content-Type', $playlistType, true);
     JResponse::setHeader('Content-Disposition', 'inline; filename=' . $playlistFileName . ';', true);
     JResponse::setHeader('Content-Range', 'bytes 0-' . ($playlistSize - 1) . '/' . $playlistSize, true);
     JResponse::setHeader('Content-Length', (string) $playlistSize, true);
     JResponse::setHeader('Content-Transfer-Encoding', 'binary', true);
     JResponse::setHeader('Cache-Control', 'no-cache, must-revalidate', true);
     JResponse::setHeader('Pragma', 'no-cache', true);
     JResponse::setHeader('Connection', 'close', true);
     JResponse::sendHeaders();
 }
Example #17
0
    function __construct()
    {
        ob_start();
        // Display time it took to create the entire page in the footer
        jimport('joomla.error.profiler');
        $__kstarttime = JProfiler::getmicrotime();
        $kunena_config = KunenaFactory::getConfig();
        kimport('error');
        KunenaError::initialize();
        // First of all take a profiling information snapshot for JFirePHP
        if (JDEBUG) {
            require_once JPATH_COMPONENT . '/lib/kunena.profiler.php';
            $__profiler = KProfiler::GetInstance();
            $__profiler->mark('Start');
        }
        $func = JString::strtolower(JRequest::getCmd('func', JRequest::getCmd('view', '')));
        $do = JRequest::getCmd('do', '');
        $task = JRequest::getCmd('task', '');
        $format = JRequest::getCmd('format', 'html');
        JRequest::setVar('func', $func);
        // Workaround for Joomla 1.7.3 login bug, see: https://github.com/joomla/joomla-platform/pull/740
        if ($func == 'profile' && ($task == 'login' || $task == 'logout')) {
            require_once KUNENA_PATH_FUNCS . '/profile.php';
            $page = new CKunenaProfile(JFactory::getUser()->id, $task);
        }
        require_once KUNENA_PATH . '/router.php';
        if ($func && !isset(KunenaRouter::$functions[$func])) {
            // If func is not legal, raise joomla error
            return JError::raiseError(404, 'Kunena function "' . $func . '" not found');
        }
        $kunena_app = JFactory::getApplication();
        if (empty($_POST) && $format == 'html') {
            $me = KunenaFactory::getUser();
            $menu = JSite::getMenu();
            $active = $menu->getActive();
            // Joomla 1.6+ multi-language support
            if (isset($active->language) && $active->language != '*') {
                $language = JFactory::getDocument()->getLanguage();
                if (strtolower($active->language) != strtolower($language)) {
                    $this->redirect(KunenaRoute::_(null, false));
                }
            }
            // Legacy menu item and Itemid=0 support with redirect and notice
            if (empty($active->query['view'])) {
                $new = $menu->getItem(KunenaRoute::getItemID());
                if ($new) {
                    if ($active) {
                        if ($active->route == $new->route) {
                            KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_CONFLICT', $active->route, $active->id, $new->id), 'menu');
                            $menu->setActive($new->id);
                            $active = $new;
                        } else {
                            KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_LEGACY', $active->route, $active->id, $new->route, $new->id), 'menu');
                            $this->redirect(KunenaRoute::_(null, false));
                        }
                    } else {
                        KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_NO_ITEM_REDIRECT', $new->route, $new->id));
                        $this->redirect(KunenaRoute::_(null, false));
                    }
                } elseif (!$active) {
                    KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_NO_ITEM'));
                }
            }
            if (!$func || $func == 'entrypage') {
                // If we are currently in entry page, we need to show and highlight default menu item
                if (!empty($active->query['defaultmenu'])) {
                    $defaultitem = $active->query['defaultmenu'];
                    if ($defaultitem > 0) {
                        $newitem = $menu->getItem($defaultitem);
                        if (!$newitem) {
                            KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_NOT_EXISTS'), 'menu');
                        } elseif (empty($newitem->component) || $newitem->component != 'com_kunena') {
                            KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_NOT_KUNENA'), 'menu');
                        } elseif ($active->route == $newitem->route) {
                            // Special case: we are using Entry Page instead of menu alias and we have identical menu alias
                            if ($active->id != $newitem->id) {
                                $defaultitem = !empty($newitem->query['defaultmenu']) ? $newitem->query['defaultmenu'] : $newitem->id;
                                $newitem2 = $menu->getItem($defaultitem);
                                if (empty($newitem2->component) || $newitem2->component != 'com_kunena') {
                                    $defaultitem = $newitem->id;
                                }
                                if ($defaultitem) {
                                    $menu->setActive($defaultitem);
                                    $active = $menu->getActive();
                                }
                            }
                        } else {
                            $oldlocation = KunenaRoute::getCurrentMenu();
                            $menu->setActive($defaultitem);
                            $active = $menu->getActive();
                            $newlocation = KunenaRoute::getCurrentMenu();
                            if (!$oldlocation || $oldlocation->id != $newlocation->id) {
                                // Follow Default Menu Item if it's not in the same menu
                                $this->redirect(KunenaRoute::_($defaultitem, false));
                            }
                        }
                        if (is_object($active)) {
                            foreach ($active->query as $var => $value) {
                                if ($var == 'view') {
                                    $var = 'func';
                                }
                                if ($var == 'func' && $value == 'entrypage') {
                                    $value = $func;
                                }
                                JRequest::setVar($var, $value);
                            }
                            $func = JRequest::getCmd('func');
                        }
                    }
                }
            }
            $newItemid = KunenaRoute::getItemid();
            if ($active && $newItemid && !KunenaRoute::getCurrentMenu() && $active->id != $newItemid) {
                $newroute = KunenaRoute::_($newItemid, false);
                if (strpos('/' . $active->route, $newroute) === 0) {
                    $menu->setActive($newItemid);
                    $active = $menu->getActive();
                } else {
                    $this->redirect(KunenaRoute::_(null, false));
                }
            }
        }
        global $message;
        global $kunena_this_cat;
        // Get all the variables we need and strip them in case
        $action = JRequest::getCmd('action', '');
        $catid = JRequest::getInt('catid', 0);
        $contentURL = JRequest::getVar('contentURL', '');
        $email = JRequest::getVar('email', '');
        $favoriteMe = JRequest::getVar('favoriteMe', '');
        $fb_authorname = JRequest::getVar('fb_authorname', '');
        $fb_thread = JRequest::getInt('fb_thread', 0);
        $id = JRequest::getInt('id', 0);
        $mesid = JRequest::getInt('mesid', 0);
        $limit = JRequest::getInt('limit', 0);
        $limitstart = JRequest::getInt('limitstart', 0);
        $markaction = JRequest::getVar('markaction', '');
        $message = JRequest::getVar('message', '');
        $page = JRequest::getInt('page', 0);
        $parentid = JRequest::getInt('parentid', 0);
        $pid = JRequest::getInt('pid', 0);
        $replyto = JRequest::getInt('replyto', 0);
        $resubject = JRequest::getVar('resubject', '');
        $rowid = JRequest::getInt('rowid', 0);
        $rowItemid = JRequest::getInt('rowItemid', 0);
        $subject = JRequest::getVar('subject', '');
        $subscribeMe = JRequest::getVar('subscribeMe', '');
        $thread = JRequest::getInt('thread', 0);
        $topic_emoticon = JRequest::getVar('topic_emoticon', '');
        $userid = JRequest::getInt('userid', 0);
        $no_html = JRequest::getBool('no_html', 0);
        // If JFirePHP is installed and enabled, leave a trace of the Kunena startup
        if (JDEBUG == 1 && defined('JFIREPHP')) {
            // FB::trace("Kunena Startup");
        }
        // Redirect Forum Jump
        if (isset($_POST['func']) && $func == "showcat") {
            header("HTTP/1.1 303 See Other");
            header("Location: " . KunenaRoute::_('index.php?option=com_kunena&func=showcat&catid=' . $catid, false));
            $kunena_app->close();
        }
        $kunena_my =& JFactory::getUser();
        $kunena_db =& JFactory::getDBO();
        $document = JFactory::getDocument();
        $document->addScriptDeclaration('// <![CDATA[
var kunena_toggler_close = "' . JText::_('COM_KUNENA_TOGGLER_COLLAPSE') . '";
var kunena_toggler_open = "' . JText::_('COM_KUNENA_TOGGLER_EXPAND') . '";
// ]]>');
        global $lang, $topic_emoticons;
        // Class structure should be used after this and all the common task should be moved to this class
        require_once JPATH_COMPONENT . '/class.kunena.php';
        // Central Location for all internal links
        require_once JPATH_COMPONENT . '/lib/kunena.link.class.php';
        require_once JPATH_COMPONENT . '/lib/kunena.smile.class.php';
        // Redirect profile (menu item) to the right component
        if ($func == 'profile' && !$do && empty($_POST)) {
            $redirect = 1;
            if (!empty($active)) {
                $params = new JParameter($active->params);
                $redirect = $params->get('integration', 1);
            }
            if ($redirect) {
                $profileIntegration = KunenaFactory::getProfile();
                if (!$profileIntegration instanceof KunenaProfileKunena) {
                    $url = CKunenaLink::GetProfileURL($kunena_my->id, false);
                    if ($url) {
                        $this->redirect($url);
                    }
                }
            }
        }
        // Check for JSON request
        if ($func == "json") {
            if (JDEBUG == 1 && defined('JFIREPHP')) {
                FB::log('Kunena JSON request');
            }
            // URL format for JSON requests: e.g: index.php?option=com_kunena&func=json&action=autocomplete&do=getcat
            require_once JPATH_COMPONENT . '/lib/kunena.ajax.helper.php';
            $ajaxHelper =& CKunenaAjaxHelper::getInstance();
            // Get the document object.
            $document =& JFactory::getDocument();
            // Set the MIME type for JSON output.
            $document->setMimeEncoding('application/json');
            // Change the suggested filename.
            if ($action != 'uploadfile') {
                JResponse::setHeader('Content-Disposition', 'attachment; filename="kunena.json"');
            }
            $value = JRequest::getVar('value', '');
            JResponse::sendHeaders();
            if ($kunena_config->board_offline && !CKunenaTools::isAdmin()) {
                // when the forum is offline, we don't entertain json requests
                json_encode(array('status' => '0', 'error' => @sprintf(_KUNENA_FORUM_OFFLINE)));
            } else {
                // Generate reponse
                echo $ajaxHelper->generateJsonResponse($action, $do, $value);
            }
            $kunena_app->close();
        }
        if ($kunena_config->board_offline && !CKunenaTools::isAdmin()) {
            // if the board is offline
            echo $kunena_config->offline_message;
        } else {
            if ($kunena_config->regonly && !$kunena_my->id) {
                // if we only allow registered users
                if (file_exists(KUNENA_JTEMPLATEPATH . '/css/kunena.forum-min.css')) {
                    CKunenaTools::addStyleSheet(KUNENA_JTEMPLATEURL . '/css/kunena.forum-min.css');
                } else {
                    CKunenaTools::addStyleSheet(KUNENA_TMPLTCSSURL);
                }
                echo '<div id="Kunena">';
                $this->header = JText::_('COM_KUNENA_LOGIN_NOTIFICATION');
                $this->body = JText::_('COM_KUNENA_LOGIN_FORUM');
                CKunenaTools::loadTemplate('/login.php');
                echo '</div>';
            } else {
                // =======================================================================================
                // Forum is online:
                //intercept the RSS request; we should stop afterwards
                if ($func == 'rss') {
                    require_once JPATH_COMPONENT . '/funcs/rss.php';
                    $feed = new CKunenaRSSView($catid);
                    $feed->display();
                    $kunena_app->close();
                }
                if ($func == 'fb_pdf' || $func == 'pdf') {
                    $httpReferer = JRequest::getVar('HTTP_REFERER', JURI::base(true), 'server');
                    if (KUNENA_JOOMLA_COMPAT == '1.5') {
                        include JPATH_COMPONENT . '/lib/kunena.pdf.php';
                        $kunena_app->close();
                    }
                }
                $format = JRequest::getCmd('format', 'html');
                if ($format != 'html') {
                    echo "Kunena: Unsupported output format {$format}, please use only format=html or .html";
                    $kunena_app->close();
                }
                $integration = KunenaFactory::getProfile();
                $integration->open();
                //time format
                include_once JPATH_COMPONENT . '/lib/kunena.timeformat.class.php';
                $document =& JFactory::getDocument();
                if (file_exists(KUNENA_ABSTMPLTPATH . '/initialize.php')) {
                    require_once KUNENA_ABSTMPLTPATH . '/initialize.php';
                } else {
                    require_once KPATH_SITE . '/template/default/initialize.php';
                }
                // Insert WhoIsOnlineDatas
                require_once KUNENA_PATH_LIB . '/kunena.who.class.php';
                $who =& CKunenaWhoIsOnline::getInstance();
                $who->insertOnlineDatas();
                // include required libraries
                jimport('joomla.template.template');
                // Kunena Current Template Icons Pack
                if (file_exists(KUNENA_ABSTMPLTPATH . '/icons.php')) {
                    include KUNENA_ABSTMPLTPATH . '/icons.php';
                } else {
                    include KUNENA_PATH_TEMPLATE_DEFAULT . '/icons.php';
                }
                if (JDEBUG) {
                    $__profiler->mark('Session Start');
                }
                // We only save session for registered users
                $kunena_session = KunenaFactory::getSession(true);
                if ($kunena_my->id > 0) {
                    // new indicator handling
                    if ($markaction == "allread") {
                        if (!JRequest::checkToken()) {
                            $kunena_app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
                            while (@ob_end_clean()) {
                            }
                            $kunena_app->redirect(CKunenaLink::GetCategoryURL('listcat', $catid, false));
                        }
                        $kunena_session->markAllCategoriesRead();
                    }
                    if (!$kunena_session->save()) {
                        $kunena_app->enqueueMessage(JText::_('COM_KUNENA_ERROR_SESSION_SAVE_FAILED'), 'error');
                    }
                    if ($markaction == "allread") {
                        while (@ob_end_clean()) {
                        }
                        $kunena_app->redirect(CKunenaLink::GetCategoryURL('listcat', $catid, false), JText::_('COM_KUNENA_GEN_ALL_MARKED'));
                    }
                    $userprofile = KunenaFactory::getUser();
                    if (!$userprofile->exists()) {
                        $userprofile->save();
                    }
                    // Assign previous visit without user offset to variable for templates to decide
                    $this->prevCheck = $kunena_session->lasttime;
                } else {
                    // For guests we don't show new posts
                    $this->prevCheck = CKunenaTimeformat::internalTime() + 60;
                }
                if (JDEBUG) {
                    $__profiler->mark('Session End');
                }
                //Get the topics this user has already read this session from #__kunena_sessions
                $this->read_topics = explode(',', $kunena_session->readtopics);
                /*       _\|/_
                             (o o)
                     +----oOO-{_}-OOo--------------------------------+
                     |    Until this section we have included the    |
                     |   necessary files and gathered the required   |
                     |     variables. Now let's start processing     |
                     |                     them                      |
                     +----------------------------------------------*/
                //Check if the catid requested is a parent category, because if it is
                //the only thing we can do with it is 'listcat' and nothing else
                if ($func == "showcat") {
                    if ($catid != 0) {
                        $kunena_db->setQuery("SELECT parent FROM #__kunena_categories WHERE id='{$catid}'");
                        $catParent = intval($kunena_db->loadResult());
                        if (KunenaError::checkDatabaseError()) {
                            return;
                        }
                    }
                    if ($catid == 0 || $catParent == 0) {
                        $this->redirect(CKunenaLink::GetCategoryURL('listcat', $catid, false));
                    }
                }
                $kunena_app->setUserState('com_kunena.redirect', null);
                ?>

<div id="Kunena"><?php 
                if ($kunena_config->board_offline) {
                    ?>
<span id="fbOffline"><?php 
                    echo JText::_('COM_KUNENA_FORUM_IS_OFFLINE');
                    ?>
</span> <?php 
                }
                ?>
 <?php 
                if (JDEBUG) {
                    $__profiler->mark('Profilebox Start');
                }
                CKunenaTools::loadTemplate('/menu.php');
                CKunenaTools::displayLoginBox();
                if (JDEBUG) {
                    $__profiler->mark('Profilebox End');
                }
                // Handle help / rules menuitems
                if ($func == 'article') {
                    $func = $do;
                }
                if (JDEBUG) {
                    $__profiler->mark('$func Start');
                }
                switch ($func) {
                    case 'who':
                        require_once KUNENA_PATH_LIB . '/kunena.who.class.php';
                        $online =& CKunenaWhoIsOnline::getInstance();
                        $online->displayWho();
                        break;
                    case 'announcement':
                        require_once KUNENA_PATH_LIB . '/kunena.announcement.class.php';
                        $ann = CKunenaAnnouncement::getInstance();
                        $ann->display();
                        break;
                    case 'poll':
                        require_once KUNENA_PATH_LIB . '/kunena.poll.class.php';
                        $kunena_polls =& CKunenaPolls::getInstance();
                        $kunena_polls->display();
                        break;
                    case 'polls':
                        require_once KUNENA_PATH_LIB . '/kunena.poll.class.php';
                        $kunena_polls =& CKunenaPolls::getInstance();
                        $kunena_polls->polldo();
                        break;
                    case 'stats':
                        require_once KUNENA_PATH_LIB . '/kunena.stats.class.php';
                        $kunena_stats = new CKunenaStats();
                        $kunena_stats->showStats();
                        break;
                    case 'myprofile':
                    case 'userprofile':
                    case 'fbprofile':
                    case 'profile':
                    case 'moderateuser':
                        require_once KUNENA_PATH_FUNCS . '/profile.php';
                        $page = new CKunenaProfile($userid, $task ? $task : $do);
                        $page->display();
                        break;
                    case 'userlist':
                        require_once KUNENA_PATH_FUNCS . '/userlist.php';
                        $page = new CKunenaUserlist();
                        $page->display();
                        break;
                    case 'post':
                        require_once KUNENA_PATH_FUNCS . '/post.php';
                        $page = new CKunenaPost();
                        $page->display();
                        break;
                    case 'view':
                        require_once KUNENA_PATH_FUNCS . '/view.php';
                        $layout = $kunena_app->getUserStateFromRequest("com_kunena.view_layout", 'layout', 'view');
                        $page = new CKunenaView($layout, $catid, $id, $limitstart, $limit, $mesid);
                        $page->display(true, true);
                        break;
                    case 'showcat':
                        require_once KUNENA_PATH_FUNCS . '/showcat.php';
                        $page = new CKunenaShowcat($catid, $page);
                        $page->display();
                        break;
                    case 'listcat':
                        require_once KUNENA_PATH_FUNCS . '/listcat.php';
                        $page = new CKunenaListcat($catid);
                        $page->display();
                        break;
                    case 'review':
                        require_once KUNENA_PATH_LIB . '/kunena.review.php';
                        $review = new CKunenaReview($catid);
                        $review->display();
                        break;
                    case 'rules':
                    case 'help':
                        CKunenaTools::loadTemplate('/' . $func . '.php');
                        break;
                    case 'report':
                        require_once KUNENA_PATH_LIB . '/kunena.report.class.php';
                        $report = new CKunenaReport();
                        $report->display();
                        break;
                    case 'latest':
                    case 'mylatest':
                    case 'noreplies':
                    case 'subscriptions':
                    case 'favorites':
                    case 'userposts':
                    case 'unapproved':
                    case 'deleted':
                        require_once KUNENA_PATH_FUNCS . '/latestx.php';
                        if ($do) {
                            $func = $do;
                        }
                        $page = new CKunenaLatestX($func, $page);
                        $page->display();
                        break;
                    case 'search':
                    case 'advsearch':
                        require_once JPATH_COMPONENT . '/lib/kunena.search.class.php';
                        $kunenaSearch = new CKunenaSearch();
                        $kunenaSearch->show();
                        break;
                    case 'markthisread':
                        if (!JRequest::checkToken('get')) {
                            $kunena_app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
                            while (@ob_end_clean()) {
                            }
                            $kunena_app->redirect(CKunenaLink::GetCategoryURL('showcat', $catid, false), JText::_('COM_KUNENA_GEN_FORUM_MARKED'));
                        }
                        // Mark all unread topics in the category to read
                        $readTopics = $kunena_session->readtopics;
                        $kunena_db->setQuery("SELECT thread FROM #__kunena_messages WHERE catid='{$catid}' AND parent=0 AND thread NOT IN ({$readTopics})");
                        $readForum = $kunena_db->loadResultArray();
                        if (KunenaError::checkDatabaseError()) {
                            return;
                        }
                        $readTopics = implode(',', array_merge(explode(',', $readTopics), $readForum));
                        $kunena_db->setQuery("UPDATE #__kunena_sessions set readtopics='{$readTopics}' WHERE userid={$kunena_my->id}");
                        $kunena_db->query();
                        if (KunenaError::checkDatabaseError()) {
                            return;
                        }
                        while (@ob_end_clean()) {
                        }
                        $kunena_app->redirect(CKunenaLink::GetCategoryURL('showcat', $catid, false), JText::_('COM_KUNENA_GEN_FORUM_MARKED'));
                        break;
                    case 'subscribecat':
                        if (!JRequest::checkToken('get')) {
                            $kunena_app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
                            if ($userid == 0) {
                                while (@ob_end_clean()) {
                                }
                                $kunena_app->redirect(CKunenaLink::GetCategoryURL('showcat', $catid, false));
                            } else {
                                while (@ob_end_clean()) {
                                }
                                $kunena_app->redirect(CKunenaLink::GetProfileURL($userid, false));
                            }
                        }
                        $success_msg = '';
                        if ($catid && $kunena_my->id) {
                            $query = "INSERT INTO #__kunena_subscriptions_categories (catid, userid) VALUES ('{$catid}','{$kunena_my->id}')";
                            $kunena_db->setQuery($query);
                            if (@$kunena_db->query() && $kunena_db->getAffectedRows() == 1) {
                                $success_msg = JText::_('COM_KUNENA_GEN_CATEGORY_SUBCRIBED');
                            }
                            KunenaError::checkDatabaseError();
                        }
                        while (@ob_end_clean()) {
                        }
                        $kunena_app->redirect(CKunenaLink::GetCategoryURL('showcat', $catid, false), $success_msg);
                        break;
                    case 'unsubscribecat':
                        if (!JRequest::checkToken('get')) {
                            $kunena_app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
                            if ($userid == 0) {
                                while (@ob_end_clean()) {
                                }
                                $kunena_app->redirect(CKunenaLink::GetCategoryURL('showcat', $catid, false), $success_msg);
                            } else {
                                while (@ob_end_clean()) {
                                }
                                $kunena_app->redirect(CKunenaLink::GetProfileURL($userid, false), $success_msg);
                            }
                        }
                        $success_msg = '';
                        if ($catid && $kunena_my->id) {
                            $query = "DELETE FROM #__kunena_subscriptions_categories WHERE catid={$catid} AND userid={$kunena_my->id}";
                            $kunena_db->setQuery($query);
                            if ($kunena_db->query() && $kunena_db->getAffectedRows() == 1) {
                                $success_msg = JText::_('COM_KUNENA_GEN_CATEGORY_UNSUBCRIBED');
                            }
                            KunenaError::checkDatabaseError();
                        }
                        if ($userid == 0) {
                            while (@ob_end_clean()) {
                            }
                            $kunena_app->redirect(CKunenaLink::GetCategoryURL('showcat', $catid, false), $success_msg);
                        } else {
                            while (@ob_end_clean()) {
                            }
                            $kunena_app->redirect(CKunenaLink::GetProfileURL($userid, false), $success_msg);
                        }
                        break;
                    case 'karma':
                        include JPATH_COMPONENT . '/lib/kunena.karma.php';
                        break;
                    case 'thankyou':
                        require_once JPATH_COMPONENT . '/lib/kunena.thankyou.php';
                        $thankyou = new CKunenaThankyou();
                        $thankyou->setThankyou();
                        break;
                    case 'bulkactions':
                        switch ($do) {
                            case "bulkDel":
                                CKunenaTools::KDeletePosts();
                                break;
                            case "bulkMove":
                                CKunenaTools::KMovePosts($catid);
                                break;
                            case "bulkFavorite":
                                if (!JRequest::checkToken()) {
                                    $kunena_app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
                                    while (@ob_end_clean()) {
                                    }
                                    $kunena_app->redirect(CKunenaLink::GetProfileURL($kunena_my->id, false));
                                }
                                require_once JPATH_ROOT . '/administrator/components/com_kunena/libraries/api.php';
                                $KunenaUserAPI = new KunenaUserAPI();
                                $cb = KGetArrayReverseInts("cb");
                                $result = $KunenaUserAPI->unfavoriteThreads($kunena_my->id, $cb);
                                if ($result) {
                                    $message = JText::_('COM_KUNENA_USER_UNFAVORITE_YES');
                                } else {
                                    $message = JText::_('COM_KUNENA_POST_UNFAVORITED_TOPIC');
                                }
                                while (@ob_end_clean()) {
                                }
                                $kunena_app->redirect(CKunenaLink::GetProfileURL($kunena_my->id, false), $message);
                                break;
                            case "bulkSub":
                                if (!JRequest::checkToken()) {
                                    $kunena_app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
                                    while (@ob_end_clean()) {
                                    }
                                    $kunena_app->redirect(CKunenaLink::GetProfileURL($kunena_my->id, false));
                                }
                                require_once JPATH_ROOT . '/administrator/components/com_kunena/libraries/api.php';
                                $KunenaUserAPI = new KunenaUserAPI();
                                $cb = KGetArrayReverseInts("cb");
                                $result = $KunenaUserAPI->unsubscribeThreads($kunena_my->id, $cb);
                                if ($result) {
                                    $message = JText::_('COM_KUNENA_USER_UNSUBSCRIBE_YES');
                                } else {
                                    $message = JText::_('COM_KUNENA_POST_NO_UNSUBSCRIBED_TOPIC');
                                }
                                while (@ob_end_clean()) {
                                }
                                $kunena_app->redirect(CKunenaLink::GetProfileURL($kunena_my->id, false), $message);
                                break;
                            case "bulkDelPerm":
                                CKunenaTools::KDeletePerm();
                                break;
                            case "bulkRestore":
                                CKunenaTools::KUndelete();
                                break;
                        }
                        break;
                    case 'template':
                        jimport('joomla.filesystem.path');
                        $name = JRequest::getString('name', JRequest::getString('kunena_template', '', 'COOKIE'));
                        while (@ob_end_clean()) {
                        }
                        if ($name) {
                            $name = JPath::clean($name);
                            if (!is_readable(KPATH_SITE . "/template/{$name}/template.xml")) {
                                $name = 'default';
                            }
                            setcookie('kunena_template', $name, 0, JURI::root(true) . '/');
                        } else {
                            setcookie('kunena_template', null, time() - 3600, JURI::root(true) . '/');
                        }
                        $kunena_app->redirect(CKunenaLink::GetKunenaURL(false));
                        break;
                    case 'credits':
                        include JPATH_COMPONENT . '/lib/kunena.credits.php';
                        break;
                    default:
                        require_once KUNENA_PATH_FUNCS . '/listcat.php';
                        $page = new CKunenaListcat($catid);
                        $page->display();
                        break;
                }
                if (JDEBUG) {
                    $__profiler->mark('$func End');
                }
                // Bottom Module
                CKunenaTools::showModulePosition('kunena_bottom');
                // PDF and RSS
                if ($kunena_config->enablerss || $kunena_config->enablepdf) {
                    if ($catid > 0) {
                        kimport('category');
                        $category = KunenaCategory::getInstance($catid);
                        if ($category->pub_access == 0 && $category->parent) {
                            $rss_params = '&amp;catid=' . (int) $catid;
                        }
                    } else {
                        $rss_params = '';
                    }
                    if (isset($rss_params) || $kunena_config->enablepdf) {
                        echo '<div class="krss-block">';
                        if ($kunena_config->enablepdf && $func == 'view' && KUNENA_JOOMLA_COMPAT == '1.5') {
                            // FIXME: add better translation:
                            echo CKunenaLink::GetPDFLink($catid, $limit, $limitstart, $id, CKunenaTools::showIcon('kpdf', JText::_('PDF')), 'nofollow', '', JText::_('PDF'));
                        }
                        if ($kunena_config->enablerss && isset($rss_params)) {
                            if ($kunena_config->rss_specification == 'atom1.0') {
                                $rss_specification = 'application/atom+xml';
                            } else {
                                $rss_specification = 'application/rss+xml';
                            }
                            $document->addCustomTag('<link rel="alternate" type="' . $rss_specification . '" title="' . JText::_('COM_KUNENA_LISTCAT_RSS') . '" href="' . CKunenaLink::GetRSSURL($rss_params) . '" />');
                            echo CKunenaLink::GetRSSLink(CKunenaTools::showIcon('krss', JText::_('COM_KUNENA_LISTCAT_RSS')), 'follow', $rss_params);
                        }
                        echo '</div>';
                    }
                }
                $template = KunenaFactory::getTemplate();
                $this->params = $template->params;
                // Credits
                echo '<div class="kcredits kms"> ' . CKunenaLink::GetTeamCreditsLink($catid, JText::_('COM_KUNENA_POWEREDBY')) . ' ' . CKunenaLink::GetCreditsLink();
                if ($this->params->get('templatebyText') != '') {
                    echo ' :: <a href ="' . $this->params->get('templatebyLink') . '" rel="follow">' . $this->params->get('templatebyText');
                    if ($this->params->get('templatebyName')) {
                        echo ' ' . $this->params->get('templatebyName') . '</a>';
                    } else {
                        echo '</a>';
                    }
                }
                echo '</div>';
                // display footer
                // Show total time it took to create the page
                $__ktime = JProfiler::getmicrotime() - $__kstarttime;
                ?>
	<div class="kfooter">
		<span class="kfooter-time"><?php 
                echo JText::_('COM_KUNENA_FOOTER_TIME_TO_CREATE') . '&nbsp;' . sprintf('%0.2f', $__ktime) . '&nbsp;' . JText::_('COM_KUNENA_FOOTER_TIME_SECONDS');
                ?>
</span>
	</div>
</div>
<!-- closes Kunena div -->
<?php 
                $document->addHeadLink(KunenaRoute::_(), 'canonical', 'rel', '');
                $integration = KunenaFactory::getProfile();
                $integration->close();
                //$params = JComponentHelper::getParams( 'com_kunena' );
                //if ($params->get( 'show_page_title' )) $document->setTitle ( $params->get( 'page_title' ) );
                if (empty($_POST) && $format == 'html') {
                    $default = KunenaRoute::getDefault();
                    if ($default) {
                        $menu->setActive($default->id);
                    }
                }
            }
        }
        // end of online
        if (JDEBUG == 1) {
            $__profiler->mark('Done');
            $__queries = $__profiler->getQueryCount();
            if (defined('JFIREPHP')) {
                FB::log($__profiler->getBuffer(), 'Kunena Profiler');
                if ($__queries > 50) {
                    FB::error($__queries, 'Kunena Queries');
                } else {
                    if ($__queries > 35) {
                        FB::warn($__queries, 'Kunena Queries');
                    } else {
                        FB::log($__queries, 'Kunena Queries');
                    }
                }
            }
        }
        ob_end_flush();
    }
Example #18
0
 /**
  * Json task for recalculation of prices
  *
  * @author Max Milbers
  * @author Patrick Kohl
  *
  */
 public function recalculate()
 {
     //$post = vRequest::get('request');
     $virtuemart_product_idArray = vRequest::getInt('virtuemart_product_id', array());
     //is sanitized then
     if (is_array($virtuemart_product_idArray) and !empty($virtuemart_product_idArray[0])) {
         $virtuemart_product_id = $virtuemart_product_idArray[0];
     } else {
         $virtuemart_product_id = $virtuemart_product_idArray;
     }
     $customProductData = vRequest::getVar('customProductData', array());
     //is sanitized then
     /*$customPrices = array();
     		$customVariants = vRequest::getVar ('customPrice', array()); //is sanitized then
     		//echo '<pre>'.print_r($customVariants,1).'</pre>';
     
     		//MarkerVarMods
     		foreach ($customVariants as $customVariant) {
     			//foreach ($customVariant as $selected => $priceVariant) {
     			//In this case it is NOT $selected => $variant, because we get it that way from the form
     			foreach ($customVariant as $priceVariant => $selected) {
     				//Important! sanitize array to int
     				$selected = (int)$selected;
     				$customPrices[$selected] = $priceVariant;
     			}
     		}*/
     $quantityArray = vRequest::getInt('quantity', array());
     //is sanitized then
     if (is_array($quantityArray) and !empty($quantityArray[0])) {
         $quantity = $quantityArray[0];
     } else {
         $quantity = $quantityArray;
     }
     if (empty($quantity)) {
         $quantity = 1;
     }
     $product_model = VmModel::getModel('product');
     if (!empty($virtuemart_product_id)) {
         $prices = $product_model->getPrice($virtuemart_product_id, $quantity);
     } else {
         jexit();
     }
     $priceFormated = array();
     if (!class_exists('CurrencyDisplay')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php';
     }
     $currency = CurrencyDisplay::getInstance();
     $priceFieldsRoots = array('basePrice', 'variantModification', 'basePriceVariant', 'basePriceWithTax', 'discountedPriceWithoutTax', 'salesPrice', 'priceWithoutTax', 'salesPriceWithDiscount', 'discountAmount', 'taxAmount', 'unitPrice');
     foreach ($priceFieldsRoots as $name) {
         // 		echo 'Price is '.print_r($name,1).'<br />';
         //if ($name != 'costPrice') {
         if (isset($prices[$name])) {
             $priceFormated[$name] = $currency->createPriceDiv($name, '', $prices, TRUE);
         }
         //}
     }
     // Get the document object.
     $document = JFactory::getDocument();
     // stAn: setName works in JDocumentHTML and not JDocumentRAW
     if (method_exists($document, 'setName')) {
         $document->setName('recalculate');
     }
     JResponse::setHeader('Cache-Control', 'no-cache, must-revalidate');
     JResponse::setHeader('Expires', 'Mon, 6 Jul 2000 10:00:00 GMT');
     // Set the MIME type for JSON output.
     $document->setMimeEncoding('application/json');
     JResponse::setHeader('Content-Disposition', 'attachment;filename="recalculate.json"', TRUE);
     JResponse::sendHeaders();
     echo json_encode($priceFormated);
     jexit();
 }
Example #19
0
	function plgVmOnSelfCallFE ($type, $name, &$render) {
		if ($name != $this->_name || $type != 'vmpayment') {
			return FALSE;
		}
		$action = vRequest::getCmd('action');
		$virtuemart_paymentmethod_id = vRequest::getInt('virtuemart_paymentmethod_id');
		//Load the method
		if (!($this->_currentMethod = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) {
			return NULL; // Another method was selected, do nothing
		}

		if (!class_exists('VirtueMartCart')) {
			require(JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php');
		}
		switch ($action) {

			case 'updateCartWithAmazonAddress':
				//$client = $this->getOffAmazonPaymentsService_Client();
				//$this->setOrderReferenceDetails()
				$return = $this->updateCartWithAmazonAddress();
				$json = array();
				$json['reload'] = $return['error'];
				$json['error_msg'] = '';
				if (isset($return['error_msg'])) {
					$json['error_msg'] = $this->rendererErrorMessage($return['error_msg']);
				}


				JResponse::setHeader('Cache-Control', 'no-cache, must-revalidate');
				JResponse::setHeader('Expires', 'Mon, 6 Jul 2000 10:00:00 GMT');
				// Set the MIME type for JSON output.
				$document = JFactory::getDocument();
				$document->setMimeEncoding('application/json');
				JResponse::setHeader('Content-Disposition', 'attachment;filename="amazon.json"', TRUE);
				JResponse::sendHeaders();

				echo json_encode($json);
				jExit();
				//JFactory::getApplication()->close();
				break;


			case 'leaveAmazonCheckout':
				$this->leaveAmazonCheckout();
				$json = array();
				JResponse::setHeader('Cache-Control', 'no-cache, must-revalidate');
				JResponse::setHeader('Expires', 'Mon, 6 Jul 2000 10:00:00 GMT');
				// Set the MIME type for JSON output.
				$document = JFactory::getDocument();
				$document->setMimeEncoding('application/json');
				JResponse::setHeader('Content-Disposition', 'attachment;filename="amazon.json"', TRUE);
				JResponse::sendHeaders();

				echo json_encode($json);
				jExit();
				break;

			case 'resetAmazonReferenceId':
				$this->clearAmazonSession();
				break;
			case 'onInvalidPaymentNewAuthorization':
				$this->onInvalidPaymentNewAuthorization();
				break;
			default:
				$this->amazonError(vmText::_('VMPAYMENT_AMAZON_INVALID_NOTIFICATION_TASK'));
				return;
		}

	}
 /**
  * Json task for recalculation of prices
  *
  * @author Max Milbers
  * @author Patrick Kohl
  */
 public function recalculate()
 {
     $virtuemart_product_idArray = vRequest::getInt('virtuemart_product_id', array());
     //is sanitized then
     if (is_array($virtuemart_product_idArray) and !empty($virtuemart_product_idArray[0])) {
         $virtuemart_product_id = $virtuemart_product_idArray[0];
     } else {
         $virtuemart_product_id = $virtuemart_product_idArray;
     }
     $quantity = 0;
     $quantityArray = vRequest::getInt('quantity', array());
     //is sanitized then
     if (is_array($quantityArray)) {
         if (!empty($quantityArray[0])) {
             $quantity = $quantityArray[0];
         }
     } else {
         $quantity = (int) $quantityArray;
     }
     if (empty($quantity)) {
         $quantity = 1;
     }
     $product_model = VmModel::getModel('product');
     if (!empty($virtuemart_product_id)) {
         $prices = $product_model->getPrice($virtuemart_product_id, $quantity);
     } else {
         jexit();
     }
     $priceFormated = array();
     if (!class_exists('CurrencyDisplay')) {
         require VMPATH_ADMIN . DS . 'helpers' . DS . 'currencydisplay.php';
     }
     $currency = CurrencyDisplay::getInstance();
     $priceFieldsRoots = array('basePrice', 'variantModification', 'basePriceVariant', 'basePriceWithTax', 'discountedPriceWithoutTax', 'salesPrice', 'priceWithoutTax', 'salesPriceWithDiscount', 'discountAmount', 'taxAmount', 'unitPrice');
     foreach ($priceFieldsRoots as $name) {
         if (isset($prices[$name])) {
             $priceFormated[$name] = $currency->createPriceDiv($name, '', $prices, TRUE);
         }
     }
     // Get the document object.
     $document = JFactory::getDocument();
     // stAn: setName works in JDocumentHTML and not JDocumentRAW
     if (method_exists($document, 'setName')) {
         $document->setName('recalculate');
     }
     // Also return all messages (in HTML format!):
     // Since we are in a JSON document, we have to temporarily switch the type to HTML
     // to make sure the html renderer is actually used
     $previoustype = $document->getType();
     $document->setType('html');
     $msgrenderer = $document->loadRenderer('message');
     $priceFormated['messages'] = $msgrenderer->render('Message');
     $document->setType($previoustype);
     JResponse::setHeader('Cache-Control', 'no-cache, must-revalidate');
     JResponse::setHeader('Expires', 'Mon, 6 Jul 2000 10:00:00 GMT');
     // Set the MIME type for JSON output.
     $document->setMimeEncoding('application/json');
     //JResponse::setHeader ('Content-Disposition', 'attachment;filename="recalculate.json"', TRUE);
     JResponse::sendHeaders();
     echo json_encode($priceFormated);
     jexit();
 }
 /**
  * Method to handle a send a JSON response. The body parameter
  * can be a Exception object for when an error has occurred or
  * a JObject for a good response.
  *
  * @param   mixed $data JObject on success, Exception on error. [optional]
  *
  * @since       1.1.0
  */
 public static function sendResponse($data = null)
 {
     $app = JFactory::getApplication();
     // Create the response object.
     $response = new JObject();
     // Send the assigned error code if we are catching an exception.
     if ($data instanceof Exception) {
         // Log the error
         JLog::add($data->getMessage(), JLog::ERROR);
         JResponse::setHeader('status', $data->getCode());
         JResponse::sendHeaders();
         // Prepare the error response.
         $response->error = true;
         $response->header = JText::_('COM_FILEDSANDFILTERS_FILTERS_ERROR_HEADER');
         $response->message = $data->getMessage();
     } else {
         $document = JFactory::getDocument();
         // Prepare the response data.
         $response->head = $document->getHeadData();
         $response->body = $document->getBuffer('component', 'fieldsandfilters');
         JResponse::setBody($response->body);
         JPluginHelper::importPlugin('system');
         $app->triggerEvent('onAfterRender');
         $response->body = JResponse::getBody();
         $response->hash = md5(serialize($app->input->get('fieldsandfilters', array(), 'array')));
         $response->setProperties($data->getProperties(true));
     }
     // The old token is invalid so send a new one.
     $response->token = JFactory::getSession()->getFormToken();
     $response->requestID = $app->input->get('requestID', 0, 'alnum');
     // Add the buffer.
     // $response->buffer = JDEBUG ? ob_get_contents() : ob_end_clean();
     if (self::$app_swap && self::$app_swap instanceof JApplication) {
         JFactory::$application = self::$app_swap;
         self::$app_swap = null;
     }
     if (self::$doc_swap && self::$doc_swap instanceof JDocument) {
         JFactory::$document = self::$doc_swap;
         self::$doc_swap = null;
     }
     // Send the JSON response.
     echo json_encode($response);
     // Close the application.
     $app->close();
 }
Example #22
0
 /**
  * Performs the setups of each package
  *
  * @return  void
  *
  * @since   0.10.1
  */
 public function executesetup()
 {
     $options['format'] = '{DATE}\\t{TIME}\\t{LEVEL}\\t{CODE}\\t{MESSAGE}';
     $options['text_file'] = 'playjoom_update.php';
     JLog::addLogger($options, JLog::INFO, array('Update', 'databasequery', 'jerror'));
     // Send the appropriate error code response.
     JResponse::clearHeaders();
     JResponse::setHeader('Content-Type', 'application/json; charset=utf-8');
     JResponse::sendHeaders();
     $total = $_GET['total'];
     $one_procent = 1 / ($total / 100);
     $curr_index = number_format($_GET['total'] * $_GET['status'] / 100, 0, '', '');
     $path_from_cache = explode('*|*', JFactory::getApplication()->getUserState('com_playjoomupdate.paths.array'));
     $php_array['status'] = $_GET['status'] + $one_procent;
     if (isset($path_from_cache[$curr_index])) {
         //Install extensions
         $installer = JInstaller::getInstance();
         $installer->setPath('source', $path_from_cache[$curr_index]);
         $installer->setPath('extension_root', $path_from_cache[$curr_index]);
         //Check extension packages for install
         if (!$installer->setupInstall()) {
             JLog::add('Some problems with install package!', JLog::ERROR, 'Update');
             $package_status = false;
         } else {
             JLog::add('The Install package ' . $path_from_cache[$curr_index] . ' is okay.', JLog::INFO, 'Update');
             $package_status = true;
             $manifest = $installer->getManifest();
             //Get file array
             $model = $this->getModel('default');
             $extension_id = $model->checkExtensionProtected($manifest);
             //Install extension package
             $install_extensions = new JInstaller();
             if ($extension_id != 0) {
                 $model->setExtensionProtected($extension_id, 0);
                 $install_extensions->install($path_from_cache[$curr_index]);
                 JLog::add('Install package ' . $manifest->name . ' is done.', JLog::INFO, 'Update');
                 $model->setExtensionProtected($model->checkNewExtensionID($manifest), 1);
             } else {
                 $install_extensions->install($path_from_cache[$curr_index]);
             }
         }
     }
     // Bei 100% ist Schluss ;)
     if ($php_array['status'] > 100) {
         $php_array['status'] = 100;
     }
     if ($php_array['status'] != 100 && isset($path_from_cache[$curr_index])) {
         $php_array['message'] = JText::_('COM_PLAYJOOMUPDATE_INSTALLING_EXTENSIONS_CURRENT_STATUS') . ' ' . ($curr_index + 1) . ' / ' . $total . ' - ' . round($php_array['status'], 1) . '%';
         if ($package_status) {
             $php_array['message_path'] = JText::_('COM_PLAYJOOMUPDATE_INSTALLING_EXTENSIONS_PATH_STATUS') . ' ' . $path_from_cache[$curr_index] . ' Done.';
         } else {
             $php_array['message_path'] = JText::_('COM_PLAYJOOMUPDATE_INSTALLING_EXTENSIONS_PATH_STATUS') . ' ' . $path_from_cache[$curr_index] . ' failed.';
         }
     } else {
         $php_array['message'] = JText::_('COM_PLAYJOOMUPDATE_INSTALLING_EXTENSIONS_DONE');
     }
     // Output as PHP arrays as JSON Objekt
     echo json_encode($php_array);
 }
Example #23
0
 function download()
 {
     $mainframe = JFactory::getApplication();
     $user = JFactory::getUser();
     jimport('joomla.filesystem.file');
     $params = JComponentHelper::getParams('com_k2');
     $id = JRequest::getInt('id');
     JPluginHelper::importPlugin('k2');
     $dispatcher = JDispatcher::getInstance();
     $attachment = JTable::getInstance('K2Attachment', 'Table');
     if ($mainframe->isSite()) {
         $token = JRequest::getVar('id');
         $check = JString::substr($token, JString::strpos($token, '_') + 1);
         $hash = version_compare(JVERSION, '3.0', 'ge') ? JApplication::getHash($id) : JUtility::getHash($id);
         if ($check != $hash) {
             JError::raiseError(404, JText::_('K2_NOT_FOUND'));
         }
     }
     $attachment->load($id);
     // For front-end ensure that user has access to the item
     if ($mainframe->isSite()) {
         $item = JTable::getInstance('K2Item', 'Table');
         $item->load($attachment->itemID);
         $category = JTable::getInstance('K2Category', 'Table');
         $category->load($item->catid);
         if (!$item->id || !$category->id) {
             JError::raiseError(404, JText::_('K2_NOT_FOUND'));
         }
         if (K2_JVERSION == '15' && ($item->access > $user->get('aid', 0) || $category->access > $user->get('aid', 0))) {
             JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
         }
         if (K2_JVERSION != '15' && (!in_array($category->access, $user->getAuthorisedViewLevels()) || !in_array($item->access, $user->getAuthorisedViewLevels()))) {
             JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
         }
     }
     $dispatcher->trigger('onK2BeforeDownload', array(&$attachment, &$params));
     $path = $params->get('attachmentsFolder', NULL);
     if (is_null($path)) {
         $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments';
     } else {
         $savepath = $path;
     }
     $file = $savepath . DS . $attachment->filename;
     if (JFile::exists($file)) {
         require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php';
         $handle = new Upload($file);
         $dispatcher->trigger('onK2AfterDownload', array(&$attachment, &$params));
         if ($mainframe->isSite()) {
             $attachment->hit();
         }
         $len = filesize($file);
         $filename = basename($file);
         ob_end_clean();
         JResponse::clearHeaders();
         JResponse::setHeader('Pragma', 'public', true);
         JResponse::setHeader('Expires', '0', true);
         JResponse::setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
         JResponse::setHeader('Content-Type', $handle->file_src_mime, true);
         JResponse::setHeader('Content-Disposition', 'attachment; filename=' . $filename . ';', true);
         JResponse::setHeader('Content-Transfer-Encoding', 'binary', true);
         JResponse::setHeader('Content-Length', $len, true);
         JResponse::sendHeaders();
         echo JFile::read($file);
     } else {
         echo JText::_('K2_FILE_DOES_NOT_EXIST');
     }
     $mainframe->close();
 }
 /**
  * The main code of the Dispatcher. It spawns the necessary controller and
  * runs it.
  *
  * @throws Exception
  *
  * @return  null|JError
  */
 public function dispatch()
 {
     if (!FOFPlatform::getInstance()->authorizeAdmin($this->input->getCmd('option', 'com_foobar'))) {
         if (version_compare(JVERSION, '3.0', 'ge')) {
             throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
         } else {
             return JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
         }
     }
     $this->transparentAuthentication();
     // Merge English and local translations
     FOFPlatform::getInstance()->loadTranslations($this->component);
     $canDispatch = true;
     if (FOFPlatform::getInstance()->isCli()) {
         $canDispatch = $canDispatch && $this->onBeforeDispatchCLI();
     }
     $canDispatch = $canDispatch && $this->onBeforeDispatch();
     if (!$canDispatch) {
         JResponse::setHeader('Status', '403 Forbidden', true);
         if (version_compare(JVERSION, '3.0', 'ge')) {
             throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
         } else {
             return JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
         }
     }
     // Get and execute the controller
     $option = $this->input->getCmd('option', 'com_foobar');
     $view = $this->input->getCmd('view', $this->defaultView);
     $task = $this->input->getCmd('task', null);
     if (empty($task)) {
         $task = $this->getTask($view);
     }
     // Pluralise/sungularise the view name for typical tasks
     if (in_array($task, array('edit', 'add', 'read'))) {
         $view = FOFInflector::singularize($view);
     } elseif (in_array($task, array('browse'))) {
         $view = FOFInflector::pluralize($view);
     }
     $this->input->set('view', $view);
     $this->input->set('task', $task);
     $config = $this->config;
     $config['input'] = $this->input;
     $controller = FOFController::getTmpInstance($option, $view, $config);
     $status = $controller->execute($task);
     if (!$this->onAfterDispatch()) {
         JResponse::setHeader('Status', '403 Forbidden', true);
         if (version_compare(JVERSION, '3.0', 'ge')) {
             throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
         } else {
             return JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
         }
     }
     $format = $this->input->get('format', 'html', 'cmd');
     $format = empty($format) ? 'html' : $format;
     if ($format == 'html') {
         // In HTML views perform a redirection
         if ($controller->redirect()) {
             return;
         }
     } else {
         // In non-HTML views just exit the application with the proper HTTP headers
         if ($controller->hasRedirect()) {
             $headers = JResponse::sendHeaders();
             jexit();
         }
     }
 }
Example #25
0
 /**
  * Method for sending the page header
  *
  * @param string $playlistFileName Name of the playlist file
  * @param string $playlistType     Mimetype of the playlist
  * @param int    $playlistSize     Data size of the created playlist
  *
  * @return void
  */
 public function setHeader($filename, $archiveType, $archiveSize)
 {
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__ . ":" . __LINE__, 'message' => 'Set Header for download filename: ' . $filename . ', archive type: ' . $archiveType . ', archive size: ' . $archiveSize, 'priority' => JLog::ERROR, 'section' => 'site')));
     //Setup web server
     if (isset($_SERVER['SERVER_SOFTWARE'])) {
         $sf = $_SERVER['SERVER_SOFTWARE'];
     } else {
         $sf = getenv('SERVER_SOFTWARE');
     }
     if (!strpos($sf, 'IIS')) {
         @apache_setenv('no-gzip', 1);
     }
     @ini_set('zlib.output_compression', 0);
     ignore_user_abort(false);
     JResponse::clearHeaders();
     header("HTTP/1.1 200 OK");
     JResponse::setHeader('Accept-Range', 'bytes', true);
     JResponse::setHeader('X-Pad', 'avoid browser bug');
     JResponse::setHeader('Content-Type', $archiveType, true);
     JResponse::setHeader('Content-Disposition', 'inline; filename=' . $filename . ';', true);
     JResponse::setHeader('Content-Range', 'bytes 0-' . ($archiveSize - 1) . '/' . $archiveSize, true);
     JResponse::setHeader('Content-Length', (string) $archiveSize, true);
     JResponse::setHeader('Content-Transfer-Encoding', 'binary', true);
     JResponse::setHeader('Cache-Control', 'no-cache, must-revalidate', true);
     JResponse::setHeader('Pragma', 'no-cache', true);
     JResponse::setHeader('Connection', 'close', true);
     JResponse::sendHeaders();
 }
Example #26
0
function ajaxSwitchEditor()
{
    doSwitchEditor(false);
    JResponse::clearHeaders();
    JResponse::setHeader('Pragma', 'public', true);
    JResponse::setHeader('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT', true);
    // Date in the past
    JResponse::setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT', true);
    JResponse::setHeader('Cache-Control', 'no-store, no-cache, must-revalidate', true);
    // HTTP/1.1
    JResponse::setHeader('Cache-Control: pre-check=0, post-check=0, max-age=0', true);
    // HTTP/1.1
    JResponse::setHeader('Pragma', 'no-cache', true);
    JResponse::setHeader('Expires', '0', true);
    JResponse::setHeader('Content-Transfer-Encoding', 'none', true);
    JResponse::setHeader('Content-Type', 'text/xml', true);
    // joomla will overwrite this...
    $d = JFactory::getDocument();
    $d->setMimeEncoding('text/xml');
    JResponse::sendHeaders();
}
Example #27
0
 /**
  * Method to handle a send a JSON response. The body parameter
  * can be a Exception object for when an error has occurred or
  * a JObject for a good response.
  *
  * @param   mixed  $data  JObject on success, Exception on error. [optional]
  *
  * @return  void
  *
  * @since   2.5
  */
 public static function sendResponse($data = null)
 {
     static $log;
     if ($log == null) {
         $options['format'] = '{DATE}\\t{TIME}\\t{LEVEL}\\t{CODE}\\t{MESSAGE}';
         $options['text_file'] = 'indexer.php';
         $log = JLog::addLogger($options);
     }
     $backtrace = null;
     // Send the assigned error code if we are catching an exception.
     if ($data instanceof Exception) {
         JLog::add($data->getMessage(), JLog::ERROR);
         JResponse::setHeader('status', $data->getCode());
         JResponse::sendHeaders();
     }
     // Create the response object.
     $response = new FinderIndexerResponse($data);
     // Add the buffer.
     $response->buffer = JDEBUG ? ob_get_contents() : ob_end_clean();
     // Send the JSON response.
     echo json_encode($response);
     // Close the application.
     JFactory::getApplication()->close();
 }
Example #28
0
 function download($front = false)
 {
     $mainframe =& JFactory::getApplication();
     jimport('joomla.filesystem.file');
     $params =& JComponentHelper::getParams('com_k2');
     $id = JRequest::getInt('id');
     JPluginHelper::importPlugin('k2');
     $dispatcher =& JDispatcher::getInstance();
     $attachment =& JTable::getInstance('K2Attachment', 'Table');
     $attachment->load($id);
     $dispatcher->trigger('onK2BeforeDownload', array(&$attachment, &$params));
     $path = $params->get('attachmentsFolder', NULL);
     if (is_null($path)) {
         $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments';
     } else {
         $savepath = $path;
     }
     $file = $savepath . DS . $attachment->filename;
     if (JFile::exists($file)) {
         require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php';
         $handle = new Upload($file);
         $dispatcher->trigger('onK2AfterDownload', array(&$attachment, &$params));
         if ($front) {
             $attachment->hit();
         }
         $len = filesize($file);
         $filename = basename($file);
         JResponse::clearHeaders();
         JResponse::setHeader('Pragma', 'public', true);
         JResponse::setHeader('Expires', '0', true);
         JResponse::setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
         JResponse::setHeader('Content-Type', $handle->file_src_mime, true);
         JResponse::setHeader('Content-Disposition', 'attachment; filename=' . $filename . ';', true);
         JResponse::setHeader('Content-Transfer-Encoding', 'binary', true);
         JResponse::setHeader('Content-Length', $len, true);
         JResponse::sendHeaders();
         echo JFile::read($file);
     } else {
         echo JText::_('File does not exist');
     }
     $mainframe->close();
 }
Example #29
0
	/**
	 * Json task for recalculation of prices
	 *
	 * @author Max Milbers
	 * @author Patrick Kohl
	 *
	 */
	public function recalculate () {

		//$post = JRequest::get('request');

//		echo '<pre>'.print_r($post,1).'</pre>';
		jimport ('joomla.utilities.arrayhelper');
		$virtuemart_product_idArray = JRequest::getVar ('virtuemart_product_id', array()); //is sanitized then
		if(is_array($virtuemart_product_idArray)){
			JArrayHelper::toInteger ($virtuemart_product_idArray);
			$virtuemart_product_id = $virtuemart_product_idArray[0];
		} else {
			$virtuemart_product_id = $virtuemart_product_idArray;
		}

		$customPrices = array();
		$customVariants = JRequest::getVar ('customPrice', array()); //is sanitized then
		//echo '<pre>'.print_r($customVariants,1).'</pre>';

		//MarkerVarMods
		foreach ($customVariants as $customVariant) {
			//foreach ($customVariant as $selected => $priceVariant) {
			//In this case it is NOT $selected => $variant, because we get it that way from the form
			foreach ($customVariant as $priceVariant => $selected) {
				//Important! sanitize array to int
				$selected = (int)$selected;
				$customPrices[$selected] = $priceVariant;
			}
		}
		//echo '<pre>'.print_r($customPrices,1).'</pre>';
		jimport ('joomla.utilities.arrayhelper');
		$quantityArray = JRequest::getVar ('quantity', array()); //is sanitized then
		JArrayHelper::toInteger ($quantityArray);

		$quantity = 1;
		if (!empty($quantityArray[0])) {
			$quantity = $quantityArray[0];
		}

		$product_model = VmModel::getModel ('product');

		//VmConfig::$echoDebug = TRUE;
		$prices = $product_model->getPrice ($virtuemart_product_id, $customPrices, $quantity);

		$priceFormated = array();
		if (!class_exists ('CurrencyDisplay')) {
			require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
		}
		$currency = CurrencyDisplay::getInstance ();
		foreach ($prices as $name => $product_price) {
// 		echo 'Price is '.print_r($name,1).'<br />';
			if ($name != 'costPrice') {
				$priceFormated[$name] = $currency->createPriceDiv ($name, '', $prices, TRUE);
			}
		}

		// Get the document object.
		$document = JFactory::getDocument ();
		$document->setName ('recalculate');
		JResponse::setHeader ('Cache-Control', 'no-cache, must-revalidate');
		JResponse::setHeader ('Expires', 'Mon, 6 Jul 2000 10:00:00 GMT');
		// Set the MIME type for JSON output.
		$document->setMimeEncoding ('application/json');
		JResponse::setHeader ('Content-Disposition', 'attachment;filename="recalculate.json"', TRUE);
		JResponse::sendHeaders ();
		echo json_encode ($priceFormated);
		jexit ();
	}
 /**
  * The main code of the Dispatcher. It spawns the necessary controller and
  * runs it.
  *
  * @return  null|Exception
  */
 public function dispatch()
 {
     // Timezone fix; avoids errors printed out by PHP 5.3.3+
     list($isCli, $isAdmin) = self::isCliAdmin();
     if ($isAdmin) {
         // Master access check for the back-end, Joomla! 1.6 style.
         $user = JFactory::getUser();
         if (!$user->authorise('core.manage', $this->input->getCmd('option', 'com_foobar')) && !$user->authorise('core.admin', $this->input->getCmd('option', 'com_foobar'))) {
             if (version_compare(JVERSION, '3.0', 'ge')) {
                 throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
             } else {
                 return JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
             }
         }
     } elseif (!$isCli) {
         // Perform transparent authentication for front-end requests
         $this->transparentAuthentication();
     }
     // Merge English and local translations
     if ($isAdmin) {
         $paths = array(JPATH_ROOT, JPATH_ADMINISTRATOR);
     } else {
         $paths = array(JPATH_ADMINISTRATOR, JPATH_ROOT);
     }
     $jlang = JFactory::getLanguage();
     $jlang->load($this->component, $paths[0], 'en-GB', true);
     $jlang->load($this->component, $paths[0], null, true);
     $jlang->load($this->component, $paths[1], 'en-GB', true);
     $jlang->load($this->component, $paths[1], null, true);
     $canDispatch = true;
     if ($isCli) {
         $canDispatch = $canDispatch && $this->onBeforeDispatchCLI();
     }
     $canDispatch = $canDispatch && $this->onBeforeDispatch();
     if (!$canDispatch) {
         JResponse::setHeader('Status', '403 Forbidden', true);
         if (version_compare(JVERSION, '3.0', 'ge')) {
             throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
         } else {
             return JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
         }
     }
     // Get and execute the controller
     $option = $this->input->getCmd('option', 'com_foobar');
     $view = $this->input->getCmd('view', $this->defaultView);
     $task = $this->input->getCmd('task', '');
     if (empty($task)) {
         $task = $this->getTask($view);
     }
     // Pluralise/sungularise the view name for typical tasks
     if (in_array($task, array('edit', 'add', 'read'))) {
         $view = FOFInflector::singularize($view);
     } elseif (in_array($task, array('browse'))) {
         $view = FOFInflector::pluralize($view);
     }
     $this->input->set('view', $view);
     $this->input->set('task', $task);
     $config = $this->config;
     $config['input'] = $this->input;
     $controller = FOFController::getTmpInstance($option, $view, $config);
     $status = $controller->execute($task);
     if (!$this->onAfterDispatch()) {
         JResponse::setHeader('Status', '403 Forbidden', true);
         if (version_compare(JVERSION, '3.0', 'ge')) {
             throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
         } else {
             return JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
         }
     }
     $format = $this->input->get('format', 'html', 'cmd');
     $format = empty($format) ? 'html' : $format;
     if ($format == 'html') {
         // In HTML views perform a redirection
         if ($controller->redirect()) {
             return;
         }
     } else {
         // In non-HTML views just exit the application with the proper HTTP headers
         if ($controller->hasRedirect()) {
             $headers = JResponse::sendHeaders();
             jexit();
         }
     }
 }