stese hat geschrieben:kannst du die felder vll. auch posten? falls in ein zwei jahren das file auf dem server mal nicht zu finden ist

ausserdem schaue ich mir gern den code vorher an bevor ich ein fremdes modul einsetze
Ist verständlich, hier die Felder...
Beschreibung:
Code: Alles auswählen
Modul zum Einbinden einer Datei per Auswahl. Unterstützt werden JS-, CSS-, PHP-
und HTML-Dateien. Damit ist es möglich, über die Artikel-/Kategorie-Konfiguration
eine Datei zusätzlich einzubinden. Ausgewählte JS-/CSS-Dateien werden mit
entsprechendem HTML-Tag, PHP-/-HTML-Dateien per cInclude eingebunden.
Autor: Murat Purc, murat@purc.de
Version: 1.0
Wichtig:
Unter "Administration -> Mandanten -> Mandanteneinstellungen" sind folgende
Variablen einzufügen:
Typ Name Wert
dir include.css css/
dir include.js js/
dir include.php includes/additional/
dir include.html includes/additional/
Die Werte für die Variablen sind Ordner im Clientverzeichnis (relativ zum cms-Pfad),
welche einzubindenede Dateien enthalten. Diese Ordner sollten vorhanden sein oder
ggf. angelegt werden.
Ordner "css/" und "js/" sind bei der Standardinstallation mit dabei,
"includes/additional/" hingegen ist anzulegen.
Modulinput:
Code: Alles auswählen
?><?php
// input IncludeFile
cInclude('classes', 'contenido/class.client.php');
/**
* Class to generate a selectbox used to select a file 2 include.
*
* @category Moduleinput
* @author Murat Purc, info@purc.de
* @copyright o-a c, 2006
* @date 09.08.2006
*/
class cModIncludeFile{
/**
* Prefix for found files, used for composing option data
* @var string $_sPrefix
*/
var $_sPrefix = " - ";
/**
* Constructor, sets some properties
*/
function cModIncludeFile(){
global $cfgClient, $client;
$this->_sPath = $cfgClient[$client]['path']['frontend'];
$oApiClient = new cApiClient($client);
$this->_aDirs['css']['name'] = mi18n("Style sheet file");
$this->_aDirs['css']['dir'] = $oApiClient->getProperty('dir', 'include.css');
$this->_aDirs['js']['name'] = mi18n("JavaScript file");
$this->_aDirs['js']['dir'] = $oApiClient->getProperty('dir', 'include.js');
$this->_aDirs['php']['name'] = mi18n("PHP file");
$this->_aDirs['php']['dir'] = $oApiClient->getProperty('dir', 'include.php');
$this->_aDirs['php']['ext'] = 'php|php3|php4|php5|inc';
$this->_aDirs['html']['name'] = mi18n("HTML file");
$this->_aDirs['html']['dir'] = $oApiClient->getProperty('dir', 'include.html');
$this->_aDirs['html']['ext'] = 'htm|html';
$this->_sIncFile = "CMS_VALUE[0]";
} // function cModIncludeFile()
/**
* Main function to get all select options.
* @return string Composed html options
*/
function generateIncOptions(){
$ret = '<option value="">'.mi18n("--- Select file ---").'</option>'."\n";
foreach ($this->_aDirs as $ext => $item) {
if (isset($item['ext'])) {
$ext = $item['ext'];
}
$ret .= $this->_generateOptions($item, $ext);
}
return $ret;
}
/**
* Creates options for a specific extention.
* @param array $aItem Include type array, see $this->_aDirs
* @param string $ext Allowed extentions
* @return string Composed html options
* @access private
*/
function _generateOptions($aItem, $ext) {
$aFiles = $this->_readDir($this->_sPath.$aItem['dir'], $ext);
if (!is_array($aFiles)) {
return '';
}
$ret .= '<option class="dir" value="">'.$aItem['name'].':</option>'."\n";
foreach ($aFiles as $pos => $file) {
$val = $aItem['dir'].$file;
$sel = ($val == $this->_sIncFile) ? ' selected="selected"' : '';
$ret .= '<option value="'.$val.'"'.$sel.'>'.$this->_sPrefix.$file.'</option>'."\n";
}
return $ret;
} // function _generateOptions()
/**
* Returns all found files inside a dir
* @param string $dir Directory to read
* @param string $allowedExt Extentions of files to get (restriction for returning all files)
* @return mixed Array of found files or false
* @access private
*/
function _readDir($dir, $allowedExt=null) {
$hDir = opendir($dir);
while ($sFile = readdir($hDir)) {
$bIsEmpty = ($sFile == '.' || $sFile == '..') ? true : false;
$bIsDir = (is_dir($dir.$sFile) && !$bIsEmpty) ? true : false;
if (!$bIsDir && !$bIsEmpty) {
if ($allowedExt == null) {
$aFiles[] = $sFile;
} else {
$tmp = explode('.', $sFile);
$sExt = strtolower($tmp[count($tmp)-1]);
if (strpos($allowedExt, $sExt) !== false) {
$aFiles[] = $sFile;
}
}
}
}
closedir($hDir);
# print "\n<!--\ndir: $dir\n";var_dump($aFiles);echo "\n-->\n";
return (is_array($aFiles)) ? $aFiles : false;
} // function _readDir()
} // class cModIncludeFile
$oMIF = new cModIncludeFile();
?>
<!-- MOD INCLUDEFILE -->
<style type="text/css">
option.dir{font-size:11px;font-weight:bold;font-style:italic;color:blue;border-bottom:1px blue dashed;}
</style>
<table cellspacing="0" cellpadding="3" border="0">
<tr><td valign="top" class="text_medium"><?php print mi18n("Select file to include"); ?></td></tr>
<tr><td><select name="CMS_VAR[0]" class="text_medium">
<?php echo $oMIF->generateIncOptions(); ?>
</select><br>
</td></tr>
</table>
<!-- /MOD INCLUDEFILE -->
<?php
unset($oMIF);
Moduloutput:
Code: Alles auswählen
<?php
// output IncludeFile
if (!class_exists('cModIncludeFile')) {
/**
* Class to include a selected file. Provides following filetypes:
* - JS and CSS, inclusion using corresponding HTML-Tag
* - PHP and HTML, inclusion using Contenido cInclude-Function
*
* @category Moduleoutput
* @author Murat Purc, info@purc.de
* @copyright o-a c, 2006
* @date 09.08.2006
*/
class cModIncludeFile{
/**
* Template for script tag output
* @var string $_sJSTagTpl
*/
var $_sJSTagTpl = '<script src="%s" type="text/javascript"></script>';
/**
* Template for css tag output
* @var string $_sCSSTagTpl
*/
var $_sCSSTagTpl = '<link rel="stylesheet" type="text/css" href="%s" media="all" />';
/**
* Constructor, sets some properties
*/
function cModIncludeFile(){
$this->_sIncFile = "CMS_VALUE[0]";
$this->_aExt['js'] = 'js';
$this->_aExt['css'] = 'css';
$this->_aExt['php'] = 'php|php3|php4|php5|inc';
$this->_aExt['html'] = 'htm|html';
}
/**
* Main function to include desired file. Check file extention and
* prints out a html-tag ord includes file using cInclude-Function.
*/
function generateOutput(){
if ($this->_sIncFile == '') {
return;
}
$tmp = explode('.', $this->_sIncFile);
$sExt = strtolower($tmp[count($tmp)-1]);
foreach($this->_aExt as $ext => $allowedExt) {
if (strpos($allowedExt, $sExt) !== false) {
$sExt = $ext;
break;
}
}
switch ($sExt) {
case 'js':
// selected file is a javascript file put out the script tag
print sprintf($this->_sJSTagTpl, $this->_sIncFile); break;
case 'css':
// selected file is a css file put out the css tag
print sprintf($this->_sCSSTagTpl, $this->_sIncFile); break;
case 'php':
// selected file is a php file, include file and pray that the user done right
cInclude('frontend', $this->_sIncFile); break;
case 'html':
// selected file is a html file
cInclude('frontend', $this->_sIncFile); break;
default:
break;
}
} // function generateOutput()
} // class cModIncludeFile
} // if (!class_exists('cModIncludeFile'))
$oMIF = new cModIncludeFile();
$oMIF->generateOutput();
#print "\n<!--\ndir: $dir\n";print_r($oMIF);print "\n-->\n";
unset($oMIF);
?>
Übersetzung (XML-Export):
Code: Alles auswählen
<?xml version="1.0" encoding="ISO-8859-1"?>
<module><translation origin-language-id="1" origin-language-name="deutsch"><string><original>Style sheet file</original>
<translation>Style Sheet Datei</translation>
</string>
<string><original>JavaScript file</original>
<translation>JavaScript Datei</translation>
</string>
<string><original>PHP file</original>
<translation>PHP Datei</translation>
</string>
<string><original>HTML file</original>
<translation>HTML Datei</translation>
</string>
<string><original>--- Select file ---</original>
<translation>--- Datei auswählen ---</translation>
</string>
<string><original>Select file to include</original>
<translation>Einzubindende Datei auswählen</translation>
</string>
</translation>
</module>
Gruß
xmurrix