Zum Inhalt springen

popup in extension

Erstellt am 28. Dezember 2005 · 18 Antworten · letzte Antwort am 6. November 2006

Tags: Frage

xtensionar ·

hallo,

ich hab ne extension geschrieben, welche folgendermassen aufgebaut ist:

sind 5 seiten zum durchklicken.
bei einem form-button submit verlinke ich immer wieder auf die selbe seite (class.tx_xxx_pi1.php), inkludiere dann je nach uebergebenem parameter eine entsprechende seite, welche mir die $content-variable erweitert und somit den gewuenschten inhalt anzeigt.

mein problem: bei einem klick auf einen link einer seite soll ein popup erscheinen. soweit kein problem, wenn der inhalt statisch waere. ist er aber nicht. wie ist es nun moeglich, so etwas zu realisieren? ich kann ja nicht einfach ein neues fenster per js oeffnen lassen und da html code reinschreiben, da ich ja so keinen db-zugriff habe (wenn ich richtig liege).

fuer tipps waere ich sehr dankbar! ;-)

xtensionar ·

danke, die hab ich mir angeschaut. jedoch kann ich nicht erkennen, wo dabei der link ist, bzw. das popup geoeffnet wird. ich poste mal den code, vielleicht koenntest du die entsprechende stelle nochmal zitieren. thx!

<?php
/***************************************************************
*  Copyright notice
*
*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*  A copy is found in the textfile GPL.txt and important notices to the license
*  from the author is found in LICENSE.txt distributed with these scripts.
*
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Shows a picture from uploads/* in enlarged format in a separate window.
 * Picture file and settings is supplied by GET-parameters: file, width, height, sample, alternativeTempPath, effects, frame, bodyTag, title, wrap, md5
 *
 * $Id: showpic.php,v 1.11 2005/04/01 14:37:14 typo3 Exp $
 * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
 *
 * @author		Kasper Skaarhoj	<kasperyyyy@typo3.com>
 */
/**
 * [CLASS/FUNCTION INDEX of SCRIPT]
 *
 *
 *
 *   97: class SC_tslib_showpic
 *  118:     function init()
 *  166:     function main()
 *  213:     function printContent()
 *
 * TOTAL FUNCTIONS: 3
 * (This index is automatically created/updated by the extension "extdeveval")
 *
 */


// *******************************
// Set error reporting
// *******************************
error_reporting (E_ALL ^ E_NOTICE);


// ***********************
// Paths are setup
// ***********************
define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
define('TYPO3_MODE','FE');
define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', (php_sapi_name()=='cgi'||php_sapi_name()=='isapi' ||php_sapi_name()=='cgi-fcgi')&&($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED'])? ($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED']):($_SERVER['ORIG_SCRIPT_FILENAME']?$_SERVER['ORIG_SCRIPT_FILENAME']:$_SERVER['SCRIPT_FILENAME']))));

define('PATH_site', dirname(PATH_thisScript).'/');
define('PATH_t3lib', PATH_site.'t3lib/');
define('PATH_tslib', PATH_site.'tslib/');
define('PATH_typo3conf', PATH_site.'typo3conf/');
define('TYPO3_mainDir', 'typo3/');		// This is the directory of the backend administration for the sites of this TYPO3 installation.

require_once(PATH_t3lib.'class.t3lib_div.php');
require_once(PATH_t3lib.'class.t3lib_extmgm.php');

// ******************
// Including config
// ******************
require_once(PATH_t3lib.'config_default.php');
if (!defined ('TYPO3_db')) 	die ('The configuration file was not included.');

require_once(PATH_t3lib.'class.t3lib_db.php');
$TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');

require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');





/**
 * Script Class, generating the page output.
 * Instantiated in the bottom of this script.
 *
 * @author	Kasper Skaarhoj <kasperyyyy@typo3.com>
 * @package TYPO3
 * @subpackage tslib
 */
class SC_tslib_showpic {
	var $content;		// Page content accumulated here.

		// Parameters loaded into these internal variables:
	var $file;
	var $width;
	var $height;
	var $sample;
	var $alternativeTempPath;
	var $effects;
	var $frame;
	var $bodyTag;
	var $title;
	var $wrap;
	var $md5;

	/**
	 * Init function, setting the input vars in the global space.
	 *
	 * @return	void
	 */
	function init()	{
			// Loading internal vars with the GET/POST parameters from outside:
		$this->file = t3lib_div::_GP('file');
		$this->width = t3lib_div::_GP('width');
		$this->height = t3lib_div::_GP('height');
		$this->sample = t3lib_div::_GP('sample');
		$this->alternativeTempPath = t3lib_div::_GP('alternativeTempPath');
		$this->effects = t3lib_div::_GP('effects');
		$this->frame = t3lib_div::_GP('frame');
		$this->bodyTag = t3lib_div::_GP('bodyTag');
		$this->title = t3lib_div::_GP('title');
		$this->wrap = t3lib_div::_GP('wrap');
		$this->md5 = t3lib_div::_GP('md5');

		// ***********************
		// Check parameters
		// ***********************
			// If no file-param is given, we must exit
		if (!$this->file)	{
			die('Parameter Error: No file given.');
		}

			// Chech md5-checksum: If this md5-value does not match the one submitted, then we fail... (this is a kind of security that somebody don't just hit the script with a lot of different parameters
		$md5_value = md5(
				$this->file.'|'.
				$this->width.'|'.
				$this->height.'|'.
				$this->effects.'|'.
				$this->bodyTag.'|'.
				$this->title.'|'.
				$this->wrap.'|'.
				$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'].'|');

		if ($md5_value!=$this->md5) {
			die('Parameter Error: Wrong parameters sent.');
		}

		// ***********************
		// Check the file. If must be in a directory beneath the dir of this script...
		// $this->file remains unchanged, because of the code in stdgraphic, but we do check if the file exists within the current path
		// ***********************

		$test_file=PATH_site.$this->file;
		if (!t3lib_div::validPathStr($test_file))	{
			die('Parameter Error: No valid filepath');
		}
		if (!@is_file($test_file))	{
			die('The given file was not found');
		}
	}

	/**
	 * Main function which creates the image if needed and outputs the HTML code for the page displaying the image.
	 * Accumulates the content in $this->content
	 *
	 * @return	void
	 */
	function main()	{

			// Creating stdGraphic object, initialize it and make image:
		$img = t3lib_div::makeInstance('t3lib_stdGraphic');
		$img->mayScaleUp = 0;
		$img->init();
		if ($this->sample)	{$img->scalecmd = '-sample';}
		if ($this->alternativeTempPath && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['allowedTempPaths'],$this->alternativeTempPath))	{
			$img->tempPath = $this->alternativeTempPath;
		}

			// Need to connect to database, because this is used (typo3temp_db_tracking, cached image dimensions).
		$GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password);
		$GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db);

		if (strstr($this->width.$this->height, 'm')) {$max='m';} else {$max='';}

		$this->height = t3lib_div::intInRange($this->height,0,1000);
		$this->width = t3lib_div::intInRange($this->width,0,1000);
		if ($this->frame)	{$this->frame = intval($this->frame);}
		$imgInfo = $img->imageMagickConvert($this->file,'web',$this->width.$max,$this->height,$img->IMparams($this->effects),$this->frame,'');


			// Create HTML output:
		$this->content='';
		$this->content.='
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>'.htmlspecialchars($this->title ? $this->title : "Image").'</title>
</head>
		'.($this->bodyTag ? $this->bodyTag : '<body>');

		if (is_array($imgInfo))	{
			$wrapParts = explode('|',$this->wrap);
			$this->content.=trim($wrapParts[0]).$img->imgTag($imgInfo).trim($wrapParts[1]);
		}
		$this->content.='
		</body>
		</html>';
	}

	/**
	 * Outputs the content from $this->content
	 *
	 * @return	void
	 */
	function printContent()	{
		echo $this->content;
	}
}

// Include extension?
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/showpic.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/showpic.php']);
}












// Make instance:
$SOBE = t3lib_div::makeInstance('SC_tslib_showpic');
$SOBE->init();
$SOBE->main();
$SOBE->printContent();
?>
steffenk ·

woida meint den Passus unter // Create HTML output:
Dort wird der Inhalt des Popups erzeugt. In T3 wird diese Datei in einem Popup aufgerufen.

Den Aufruf des Popups musst Du wohl händisch machen, als Inhalt kannst Du eine PHP-Datei nehmen und den Inhalt dynamisch gestalten.

xtensionar ·

ja, das php zeuch und der db zugriff ist nicht das problem. ich wuerde das ganze gerne in einer .php file speichern, diese dann irgendwie inkludieren, so wie ich es bisher bei "normalen" seiten gemacht habe.

wie ich aber das s**t popup aufrufe, ist mir ein raetsel. mit typolink solls anscheinend gehn, allerdings finde ich da nur eine referenz, aber kein tutorial. mmmm...

hat da jemand n beispiel? daaaanke ;-)

boonkerz ·

Hallo,

Ich machs mal ganz einfach z.b. so:

$imgTSConfig['imageLinkWrap'] = '1';
$imgTSConfig['imageLinkWrap.']['enable'] = '1';
$imgTSConfig['file'] = 'pfad/'.$key;
$imgTSConfig['file.']['width']='170';
						
$content.=$this->cObj->IMAGE($imgTSConfig).' ';

Key ist die Bild Datei :-)

MFG
Thomas Peterson

woida ·

Mein Posting bezog sich auf

xtensionar schrieb

ich kann ja nicht einfach ein neues fenster per js oeffnen lassen und da html code reinschreiben, da ich ja so keinen db-zugriff habe (wenn ich richtig liege).

Damit du siehst wie man aus einem Popup heraus DB-Zugriff bekommt.

Das Popup kannst du wie du schon selbst rausgefunden hast, per typolink öffnen.
Ich weiß aber nicht, ob wir vom selben typolink sprechen: für das typolink, das ich meine braucht man kein Tutorial. Die Anwendung geht ganz klar aus der Doku (https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/Functions/Typolink.html)raus, zumal auch ein Beispiel dabei ist.
Für deinen Anwendungszweck ist wohl der Parameter "JSwindow_params" relevant.

lukas1981 ·

Also,

ich sehe da ja überhaupt kein Problem, da du ja deine Extension ja per JS-Befehl wieder aufrufen kannst. Die übermittelten Parameter lassen das Script dann die gewünschte Ausgabe tätigen. GGf. musst du den Linkbefehl so erweitern, dass er dir einen bestimmten Seitentyp öffnet, der bsp. keine Navigation oder ähnliches beinhaltet. Nur den reinen "Content"... Dies ist hier mit einem unschönen Workaround gemacht, da dies in diesem Falle leider nicht anders funktionierte... (Z.31 ff)

In einem meiner Projekte habe ich das so realisiert...

	/**
	 *  Returns JS Window A TAG (from tt_address)
	 *
	 * @access	public
	 * @param	int		ID of User
	 * @return	string  Name of searched user
	 */
	function GetContactNameByIdinJsWindow($id) {
		$name = $this->GetContactNameById($id);

		if ($name != $this->pi_getLL('nodata')) {
			/**
			 * Build link
			 *
			 * Attention:
			 * The used name is just one placeholder. This placeholder is replaced on line 157
			 */
			$link = $this->pi_linkToPage(
				'###NAME###',
				$GLOBALS["TSFE"]->id,
				'',
				array($this->prefixId . '[userdetails]' => $id)
			);

			// convert link into JS Window tag
            $ret = $this->pi_openAtagHrefInJSwindow(
            	$link,
            	'',
            	'width=360, height=333, status=0, menubar=0, scrollbars=1, resizable=0'
            );
            // code to link to a special site type (naughty)
            $link = str_replace(
            	$GLOBALS["TSFE"]->id,
            	$GLOBALS["TSFE"]->id . '.' . $this->onlyContentPageType,
            	$link
            );

            // not very nice nor valid, but the only way to make the popup open with correct interpreted vars
            $ret = str_replace('&', '&', $ret);
            $ret = str_replace('###NAME###', $name, $ret);

		} else {

			// just show the "no entry" string, without a link
			$ret = $name;
		}

		return $ret;
	}

In Zeile 39 musst du das erste "&" durch das entsprechende htmlentities ersetzen, da es sonst mit einigen Browsern zu Schwierigkeiten kommt und die Parameter nicht korrekt interpretiert werden.

HTH a lil' bit

Lukas

xtensionar ·

mm..ich bin in typo3 absoluter vollnoob ;-(, darum noch ein paar fragen:

- kann ich einen link auf eine php-file generieren (das sollte gehn)
- kann ich von der php-file dann auf die db zugreifen? (denke das ist ein problem)

- ich muss ja auf irgendetwas verlinken, ist das dann eine in typo3 angelegte seite mit einer ID?
- kann ich nicht einer funktion eine gefuellte $content-variable mitgeben, welche mir dann den inhalt in einem popup ausgibt?

das sind ziemlich grundsaetziche fragen, allerdings fehlt mir noch irgendwie das verstaendnis fuer typo3. die bisherige extension war eigentilch komplett php basiert...

waere dankbar fuer antworten!

woida ·

- kann ich einen link auf eine php-file generieren (das sollte gehn)

ja, siehe Funktion typolink

xtensionar schrieb

- kann ich von der php-file dann auf die db zugreifen? (denke das ist ein problem)

xtensionar schrieb

ja, das php zeuch und der db zugriff ist nicht das problem.

Was jetzt? Problem oder nicht? wenn ja, siehe showpic.php

- ich muss ja auf irgendetwas verlinken, ist das dann eine in typo3 angelegte seite mit einer ID?

Ich habe keine Ahnung auf was du verlinken willst. Wenn du auf google.de verlinke willst, brauchst du keine id

- kann ich nicht einer funktion eine gefuellte $content-variable mitgeben, welche mir dann den inhalt in einem popup ausgibt?

ja, siehe Funktion printContent() in Zeile 223

xtensionar ·

oki, erst mal danke

d.h. ich koennte es folgendermassen loesen:

mache mit typolink ein popup, index ich auf die file popup.php verweise.
in der popup.php ist es kein problem einen db-zugriff zu haben?
dann den ganzen html-code in die content-variable schreiben und mit printContent raushauen.

ist das prinzip richtig?

thx!

xtensionar ·

..und noch ne frage:

warum muss ich denn typolink nehmen? ich koennte doch auch in meinem php file gleich javascript schreiben und damit mein popup aufrufen, oder nicht? macht das n unterschied beim db-zugriff?

danke!

xtensionar ·

hi nochmal,

mir ist noch eine andere loesung eingefallen

<script language="JavaScript1.2" type="text/javascript">
<!--
      function popup(content) {
      
	var w = 800;
	var h = 100;
	var x = 100;
	var y = 100;
	
        var popupWindow = window.open("", "", "width="+w+",height="+h+",left="+x+",top="+y+",screenX="+x+",screenY="+y);
        
	popupWindow.document.write(content);
      }
-->
</script>

dann kann ich in der datei (auf welche ich typo3 db zugriff habe) popup("<html>...</html>") aufrufen und dieses beschreiben. ganz ideal ist das aber leider auch nicht, da der titel je nach browser unterschiedlich aussieht (im FF: "about:").

ist es moeglich auch im popup db zugriff (d.h. zugriff auf die variable $GLOBALS['TYPO3_DB']) zu bekommen? das waere die sauberste loesung..?

danke!

woida ·

ist es moeglich auch im popup db zugriff (d.h. zugriff auf die variable $GLOBALS['TYPO3_DB']) zu bekommen? das waere die sauberste loesung..?

Wie oft stellst du diese Frage noch????

Liest du eingentlich meine Antworten???

xtensionar ·

ja, ich geb mein bestes, ich sollte die showpic.php anschauen.

reicht es wenn ich

define('PATH_thisScript',str_replace('//','/', str_replace('\','/', (php_sapi_name()=='cgi'||php_sapi_name()=='isapi' ||php_sapi_name()=='cgi-fcgi')&&($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED'])? ($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED']):($_SERVER['ORIG_SCRIPT_FILENAME']?$_SERVER['ORIG_SCRIPT_FILENAME']:$_SERVER['SCRIPT_FILENAME']))));
 
define('PATH_site', dirname(PATH_thisScript).'/');
define('PATH_t3lib', PATH_site.'t3lib/');
require_once(PATH_t3lib.'class.t3lib_db.php');
$TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');

im der popup.php inkludiere? ist dann $GLOBALS['TYPO3_DB']) bekannt?

danke!

woida ·

Ja, das schaut gut aus.
Da ich es aber noch nicht ausprobiert habe, mußt du es halt testen obs geht.

xtensionar ·

soo, wie versprochen, fuer alle die das selbe problem haben.

es geht darum: wie kann ich auf die db zugreifen, wenn ich nicht mehr in der "typo3 umgebung" bin. das passiert, wenn man z.b. ein popup aufmacht (das geht einfach mit javascript, ohne typolink oder sonstigen schnickschnack).

der code, der inkludiert werden muss:

error_reporting (E_ALL ^ E_NOTICE);

// ***********************
// Paths are setup
// ***********************

define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', php_sapi_name()=='xcgi'||php_sapi_name()=='isapi'||php_sapi_name()=='cgi-fcgi' ? $HTTP_SERVER_VARS['PATH_TRANSLATED']:$HTTP_SERVER_VARS['SCRIPT_FILENAME'])));
define('PATH_typo3', dirname(dirname(dirname(dirname(dirname(PATH_thisScript))))).'/typo3/');
define('PATH_site', dirname(PATH_typo3).'/');
define('PATH_tslib', PATH_site.'tslib/');
define('PATH_t3lib', PATH_typo3.'t3lib/');
define('PATH_typo3conf', PATH_site.'typo3conf/');
define('TYPO3_MODE','BE');

require(PATH_t3lib.'class.t3lib_div.php');
require(PATH_t3lib.'class.t3lib_extmgm.php');
require(PATH_t3lib.'config_default.php');
require(PATH_typo3conf.'localconf.php');
require_once(PATH_tslib.'class.tslib_fe.php');
require_once(PATH_t3lib.'class.t3lib_userauth.php');
require_once(PATH_tslib.'class.tslib_feuserauth.php');
require_once(PATH_t3lib.'class.t3lib_tstemplate.php');
require_once(PATH_t3lib.'class.t3lib_page.php');
require_once(PATH_tslib.'class.tslib_content.php');

$typoVersion = t3lib_div::int_from_ver($GLOBALS['TYPO_VERSION']);
if($typoVersion >= 3006000) require_once(PATH_t3lib.'class.t3lib_cs.php');   // are we are with Typo3 3.6.0?

if (!defined ('TYPO3_db'))  die ('The configuration file was not included.');

if($typoVersion >= 3006000) {   // are we are with Typo3 3.6.0?
	require_once(PATH_t3lib.'class.t3lib_db.php');
	$TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
}

require_once(PATH_t3lib.'class.t3lib_timetrack.php');
$GLOBALS['TT'] = new t3lib_timeTrack;

// ***********************************
// Creating a fake $TSFE object
// ***********************************

$TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
$id = isset($HTTP_GET_VARS['id'])?$HTTP_GET_VARS['id']:0;
$GLOBALS['TSFE'] = new $TSFEclassName($TYPO3_CONF_VARS, $id, '0', 1, '', '','','');
$GLOBALS['TSFE']->connectToMySQL();
$GLOBALS['TSFE']->initFEuser();
$GLOBALS['TSFE']->fetch_the_id();
$GLOBALS['TSFE']->getPageAndRootline();
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->tmpl->getFileName_backPath = PATH_site;
$GLOBALS['TSFE']->forceTemplateParsing = 1;
$GLOBALS['TSFE']->getConfigArray();

moeglicherweise sind paar zeilen ueberfluessig, aber es funktioniert ;-)

thx an alle fuer die hilfe...

Jehu ·

Hallo xtensionar,

ich stehe vor dem selben Problem und habe deine Lösung ausprobiert.
Ich erhalte allerdings die Meldung

localconf.php is not found!

Woran kann das liegen?

Grüße
Jehu