4images Forum & Community
General / Allgemeines => Programming => Topic started by: Semi Kolon on June 03, 2009, 06:25:58 PM
-
Hey i got a problem adding PHP code to my side :(
I want this code:
<?php
//
//BACKLINKSELLER WEBSITE-CODE VERSION 1.4
//
//Ihre Domain-ID. (Diese ist standardmaessig richtig eingestellt)
$BACKLINK_SELLER['DOMAIN_ID'] = '908****';
//Ihre Account-ID. (Diese ist standardmaessig richtig eingestellt)
$BACKLINK_SELLER['ACCOUNT_ID'] = '3543****';
//Wenn Sie folgenden Parameter auf TRUE setzen, dann
//werden alle Fehlermeldungen ausgegeben und Sie
//können somit leichter die Fehlerursache feststellen
$BACKLINK_SELLER['DEBUG_FLAG'] = false; //true (aktiviert) oder false (deaktiviert)
//Wenn Sie diesen Parameter aktivieren, dann wird von unserem Server
//ein HTML-Code mit einem Beispiel-Textlink zurückgeben
//Somit können Sie die Verbindung mit unserem Server testen,
//auch wenn auf Ihrer Webseite noch keine Textlinks gebucht sind.
//ACHTUNG: BITTE VERGESSEN SIE NICHT, DIESE OPTION
//NACH DEM TEST WIEDER ZU DEAKTIVIEREN
$BACKLINK_SELLER['TEST_FLAG'] = false; //true (aktiviert) oder false (deaktiviert)
//Benutzerdefinierte HTML-Code, der vor jedem Textlink hinzugefügt wird
//(Diese Einstellung ist optional)
$BACKLINK_SELLER['HTML_BEFORE_BACKLINK'] = '';
//Benutzerdefinierte HTML-Code, der nach jedem Textlink hinzugefügt wird
//(Diese Einstellung ist optional)
$BACKLINK_SELLER['HTML_AFTER_BACKLINK'] = '<br>';
//Hier wird die CSS-Class Bezeichnung definiert, welche
//bei jedem Hyperlink hinzugefügt wird. Zum Beispiel
//<a href='...' class='class_908****'>...</a>
//Wir empfehlen diesen Wert durch einen anderen zu ersetzen.
$BACKLINK_SELLER['HYPERLINK_CLASS'] = 'class_908****';
//URL, die zu der Seite Ihrer Webpräsenz führt (z.B. http://www.example.com/my_page/)
//(Die Defaulteinstellung muss in den meisten Fällen nicht geändert werden)
$requestUri = $_SERVER['REQUEST_URI'];
if(substr($requestUri, 0, 1) == '/') {$requestUri = substr($requestUri, 1);} //remove leading slash
$requestUri = str_replace('http://www.website.de/', '', $requestUri); //make sure that request uri is without domain
$BACKLINK_SELLER['PAGE_URL'] = 'http://www.website.de/' . $requestUri;
//Mit einem aktivierten Caching wird der zurückgegebene HTML-Code
//in einer Datei für mindestens eine Stunde gespeichert.
//Bitte definieren Sie auch einen gültigen Dateipfad (siehe weiter unten)
//ACHTUNG: WIR EMPFEHLEN DAS CACHING ZU AKTIVIEREN, DA DIES DIE
//ZUGRIFFSZEITEN IHRER WEBSEITE ERHÖHT. AUSSERDEM BESEITIGT DAS AKTIVIERTE
//CACHING EINIGE TIMEOUT-PROBLEME, FALLS UNSER SERVER VORÜBERGEHEND NICHT ZUR VERFÜGUNG STEHT.
$BACKLINK_SELLER['CACHING_ENABLED_FLAG'] = true; //true (aktiviert) oder false (deaktiviert)
//Dateipfad zu der Caching-Datei.
//Für jede URL wird eine solche Datei angelegt
//ACHTUNG: DIESE DATEI MUSS SCHREIB- UND LESE-RECHTE BESITZEN.
//SIE KÖNNEN DIESE RECHTE ÜBER DIE CHMOD-EINSTELLUNG SETZEN.
//BITTE KONFIGURIEREN SIE AUCH EINEN UNTERVERZEICHNIS, IN DEM DIESE
//CACHE-DATEIEN ERSTELLT WERDEN - ANSONSTEN WERDEN DIESE DIREKT IM
//ROOT-VERZEICHNISS IHRER WEBPRESENZ ERSTELLT.
$BACKLINK_SELLER['CACHED_FILE_PATH'] = $_SERVER['DOCUMENT_ROOT'] . '/bs-908***-' . md5($BACKLINK_SELLER['PAGE_URL']) . '.txt';
//IP von dem Benutzer, der auf Ihre Webpräsenz zugreift
$BACKLINK_SELLER['USER_IP'] = $_SERVER['REMOTE_ADDR'];
define("BACKLINK_SELLER", serialize($BACKLINK_SELLER));
class BacklinkSeller
{
var $config = null;
function retrieveHTML()
{
$this->config = unserialize(BACKLINK_SELLER);
if($this->config['CACHING_ENABLED_FLAG']) {return $this->retrieveHTMLWithCaching();}
return $this->retrieveHTMLFromServer();
}
function retrieveHTMLWithCaching()
{
if($this->isCachedFileExpired())
{
$response = $this->retrieveHTMLFromServer();
//if server is down then cache HTML response for max 48 hours
if($response == 'UNABLE_TO_CONNECT' && $this->isCachedFileExpired(48))
{
//backlinkseller server is still not available
//in this case we empty cached file
$this->writeHTMLToCachedFile('');
}
else
{
//update cached file
$this->writeHTMLToCachedFile($response);
}
}
return $this->loadHTMLFromCachedFile();
}
function retrieveHTMLFromServer()
{
//build request
$request = '/channel.php?domain_id=' . $this->config['DOMAIN_ID'] .
'&account_id=' . $this->config['ACCOUNT_ID'] .
'&html_before=' . urlencode($this->config['HTML_BEFORE_BACKLINK']) .
'&html_after=' . urlencode($this->config['HTML_AFTER_BACKLINK']) .
'&page=' . urlencode($this->config['PAGE_URL']) .
'&user_ip=' . $this->config['USER_IP'];
if($this->config['TEST_FLAG']) {$request .= '&test=1';}
if(isset($this->config['HYPERLINK_CLASS'])) {$request .= '&class=' . urlencode($this->config['HYPERLINK_CLASS']);}
//try to connect to backlinkseller server
@$socket = fsockopen('channel.backlinkseller.de', 80, $errorNumber, $errorMessage, 5);
if(!$socket) {return 'UNABLE_TO_CONNECT';}
//retrieve response
$response = null;
stream_set_timeout($socket, 5);
fwrite($socket, 'GET ' . $request . " HTTP/1.1\r\nHost: channel.backlinkseller.de\r\n\r\n");
$response = fread($socket, 1000000);
fclose($socket);
if(strpos($response, "\r\n\r\n") !== false)
{$response = trim(substr($response, strpos($response, "\r\n\r\n")));}
if(!$this->config['DEBUG_FLAG']) //if debug is disabled
{
//if response contains any message and not HTML code as expected
if(substr($response, 0, 7) == 'ERROR: ' || substr($response, 0, 4) == 'OK: ')
{return '';} //do not display this message
}
return $response;
}
function writeHTMLToCachedFile($html)
{
$handle = fopen($this->config['CACHED_FILE_PATH'], 'w');
flock($handle, LOCK_EX);
fwrite($handle, $html);
flock($handle, LOCK_UN);
fclose($handle);
}
function loadHTMLFromCachedFile()
{
if(file_exists($this->config['CACHED_FILE_PATH']))
{return file_get_contents($this->config['CACHED_FILE_PATH']);}
return '';
}
function isCachedFileExpired($hoursToLive = 1)
{
if(!file_exists($this->config['CACHED_FILE_PATH'])) {return true;}
if(filemtime($this->config['CACHED_FILE_PATH']) < time() - (60 * 60 * $hoursToLive)){return true;}
return false;
}
}
//output backlinkseller html with backlinks
$backlinkseller = new BacklinkSeller();
echo($backlinkseller->retrieveHTML());
?>
I want the result of this code "Textlink" to appear on my index.php side in the template from "random_image"...
this is the output $backlinkseller = new BacklinkSeller();
echo($backlinkseller->retrieveHTML()); needed
I hope anyone is able to help me, i tried for hours...
-
Did you try add this code into home.html template?
-
yeah i did but it didn't work, just got some error messages...
-
what error messages exactly?
-
hey V@no,
Warning: fopen(/home/www/web**/html/doodling-dev/4images/bs-908***-f23f8a1072e1d7dbb6aa0e8a1210102a.txt) [function.fopen]: failed to open stream: Permission denied in /home/www/web**/html/doodling-dev/4images/includes/template.php(102) : eval()'d code on line 245
Warning: flock(): supplied argument is not a valid stream resource in /home/www/web**/html/doodling-dev/4images/includes/template.php(102) : eval()'d code on line 246
Warning: fwrite(): supplied argument is not a valid stream resource in /home/www/web**/html/doodling-dev/4images/includes/template.php(102) : eval()'d code on line 247
Warning: flock(): supplied argument is not a valid stream resource in /home/www/web**/html/doodling-dev/4images/includes/template.php(102) : eval()'d code on line 248
Warning: fclose(): supplied argument is not a valid stream resource in /home/www/web**/html/doodling-dev/4images/includes/template.php(102) : eval()'d code on line 249
this is my template.php
<?php
/**************************************************************************
* *
* 4images - A Web Based Image Gallery Management System *
* ---------------------------------------------------------------- *
* *
* File: template.php *
* Copyright: (C) 2002 Jan Sorgalla *
* Email: jan@4homepages.de *
* Web: http://www.4homepages.de *
* Scriptversion: 1.7.6 *
* *
* Never released without support from: Nicky (http://www.nicky.net) *
* *
**************************************************************************
* *
* Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz- *
* bedingungen (Lizenz.txt) für weitere Informationen. *
* --------------------------------------------------------------- *
* This script is NOT freeware! Please read the Copyright Notice *
* (Licence.txt) for further information. *
* *
*************************************************************************/
if (!defined('ROOT_PATH')) {
die("Security violation");
}
class Template {
var $no_error = 0;
var $val_cache = array();
var $missing_val_cache = array();
var $template_cache = array();
var $template_path;
var $template_extension = "html";
var $start = "{";
var $end = "}";
function Template($template_path = "") {
if (!@is_dir($template_path)) {
$this->error("Couldn't open Template-Pack ".$template_path, 1);
}
$this->template_path = $template_path;
}
function register_vars($var_name, $value = "") {
if (!is_array($var_name)) {
$this->val_cache[$var_name] = $value;
}
else {
$this->val_cache = array_merge($this->val_cache, $var_name);
}
}
function un_register_vars($var_list) {
$vars = explode(",", $var_list);
foreach ($vars as $val) {
unset($this->val_cache[trim($val)]);
}
}
function cache_templates($template_list) {
$template_list = explode(",", $template_list);
foreach ($template_list as $val) {
$val = trim($val);
if (!isset($this->template_cache[$val])) {
$this->get_template($val);
}
}
}
function get_template($template) {
if (!isset($this->template_cache[$template])) {
$path = $this->template_path."/".$template.".".$this->template_extension;
$line = @implode("", @file($path));
if (empty($line)) {
$this->error("Couldn't open Template ".$path, 1);
}
if (defined('EXEC_PHP_CODE') && EXEC_PHP_CODE == 0) {
$line = preg_replace("/<[\?|%]+(php|=)?(.*)[\?|%]+>/siU", "", $line);
$line = preg_replace("/<script\s+language\s?=\s?[\"|']?php[\"|']?>(.*)<\/script>/siU", "", $line);
}
$line = $this->compile_template($line);
$this->template_cache[$template] = $line;
}
return $this->template_cache[$template];
}
function parse_template($template) {
$template = $this->get_template($template);
// Don't show error notices
$old = error_reporting(E_ALL ^ E_NOTICE);
extract($this->val_cache);
ob_start();
//echo $template;
eval("?>".$template."<?php return 1;");
$str = ob_get_contents();
ob_end_clean();
// Reset error_reporting
error_reporting($old);
return $str;
}
function compile_template($template)
{
// Replace <?xml by printing them via php to avoid error messages when short_open_tags is on
$template = preg_replace('/<\?xml/i', "<?php echo '<?xml'; ?>", $template);
// Compile variables in PHP code
preg_match_all(
"/<[\?|%]+(php|=)?(.*)[\?|%]+>/siU",
$template,
$regs,
PREG_SET_ORDER
);
for ($i = 0; isset($regs[$i]); $i++) {
// Fix single quotes
$parsed = preg_replace_callback(
"/=\s*'(.*)".preg_quote($this->start)."([A-Z0-9_]+)".preg_quote($this->end)."(.*)';/Usi",
array(&$this, '_fix_php_quotes'),
$regs[$i][0]
);
$parsed = preg_replace_callback(
'='.preg_quote($this->start).'([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
array(&$this, '_compile_php_var'),
$parsed
);
$template = str_replace($regs[$i][0], $parsed, $template);
}
// Compile variables
$template = preg_replace_callback(
'='.preg_quote($this->start).'([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
array(&$this, '_compile_var'),
$template
);
// Compile condition tags
$template = preg_replace_callback(
'='.preg_quote($this->start).'if(not?)?\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
array(&$this, '_compile_condition_start'),
$template
);
$template = preg_replace_callback(
'='.preg_quote($this->start).'endif(not?)?\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
array(&$this, '_compile_condition_end'),
$template
);
return $template;
}
function _compile_php_var(&$matches) {
return '{$' . trim($matches[1]) . '}';
}
function _fix_php_quotes(&$matches) {
return '= "' . str_replace('"', '\\"', $matches[1])
. $this->start.$matches[2].$this->end
. str_replace('"', '\\"', $matches[3]) . '";';
}
function _compile_var(&$matches) {
$name = trim($matches[1]);
if (!isset($this->val_cache[$name])) {
return $matches[0];
}
// Header and Footer are parsed in print_template()
if ($name == 'header' || $name == 'footer') {
return $matches[0];
}
return '<?php echo $' . $name . '; ?>';
}
function _compile_condition_start(&$matches) {
$name = trim($matches[2]);
if (!isset($this->val_cache[$name])) {
return $matches[0];
}
if ($matches[1] == 'not' || $matches[1] == 'no') {
return '<?php if (empty($' . $name . ') || $' . $name . ' === REPLACE_EMPTY){ ?>';
}
return '<?php if (!empty($' . $name . ') && $' . $name . ' !== REPLACE_EMPTY){ ?>';
}
function _compile_condition_end(&$matches) {
$name = trim($matches[2]);
if (!isset($this->val_cache[$name])) {
return $matches[0];
}
return '<?php } ?>';
}
function parse_array($array) {
static $keys;
foreach ($array as $key => $val) {
if (is_array($val)) {
$array[$key] = $this->parse_array($val);
}
else {
if (!isset($keys) || count($keys) != count($this->val_cache)) {
$keys = array_keys($this->val_cache);
array_walk($keys, array(&$this, '_prepare_key'));
}
$array[$key] = str_replace($keys, $this->val_cache, $val);
}
}
return $array;
}
function _prepare_key(&$item) {
$item = $this->start.$item.$this->end;
}
function print_template($template) {
if (strpos($template, $this->start.'header'.$this->end) !== false) {
$header = $this->parse_template("header");
$template = str_replace($this->start.'header'.$this->end, $header, $template);
}
if (strpos($template, $this->start.'footer'.$this->end) !== false) {
$footer = $this->parse_template("footer");
$template = str_replace($this->start.'footer'.$this->end, $footer, $template);
}
print $this->clean_template($template);
}
function clean_template($template) {
$search_array = array(
'='.preg_quote($this->start).'([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
'='.preg_quote($this->start).'if(not?)?\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
'='.preg_quote($this->start).'endif(not?)?\s+([A-Z0-9_]+)'.preg_quote($this->end).'=Usi',
);
$replace_array = array(
"",
"",
""
);
$template = preg_replace($search_array, $replace_array, $template);
return $template;
}
function error($errmsg, $halt = 0) {
if (!$this->no_error) {
global $user_info;
//if (isset($user_info['user_level']) && $user_info['user_level'] == ADMIN){
echo "<br /><font color='#FF0000'><b>Template Error</b></font>: ".$errmsg."<br />";
/*} else {
echo "<br /><font color='#FF0000'><b>An unexpected error occured. Please try again later.</b></font><br />";
}*/
if ($halt) {
exit;
}
}
}
} // end of class
?>
i hope you are able to help me, thanks a lot!
-
Warning: fopen(/home/www/web**/html/doodling-dev/4images/bs-908***-f23f8a1072e1d7dbb6aa0e8a1210102a.txt) [function.fopen]: failed to open stream: Permission denied in /home/www/web**/html/doodling-dev/4images/includes/template.php(102) : eval()'d code on line 245
Check permissions.
It's trying save files in your 4images root directory. Create a new folder (with CHMOD 777 I presume) and add it in:
$BACKLINK_SELLER['CACHED_FILE_PATH'] = $_SERVER['DOCUMENT_ROOT'] . '/your_new_folder_name/bs-908***-' . md5($BACKLINK_SELLER['PAGE_URL']) . '.txt';
-
great! it works now 8) thank you soo much!
-
Cool dude! Gr8. For more informations in PHP Code, Check these awesome sites and you'll learn from them:
thanxxxxxxxxxxxxxxxx :D
[Edit]
gotcha.. thank you for your offers :lol: