" .$path["script"].$inc; die("FATAL ERROR: Couldn´t load element ".$ghjkjh); } } notify_add($ghjkjh." modules loaded."); unset($ghjkjh); // Set up db-connection // setEnvironment(); // memory etc. if ( createDBConnection() ) notify_add("Connected to database"); else{ if ( $runtime['debug']===1){ } else{ // version 2 header($_SERVER["SERVER_PROTOCOL"]." 503 Service Temporarily Unavailable", true, 503); //Service Temporarily Unavailable status code to the client. $retryAfterSeconds = 240; //The number of seconds that the client should wait before retrying. header('Retry-After: ' . $retryAfterSeconds); //Send a Retry-After header to the client. echo '

503 Service Temporarily Unavailable

'; //Send a message to the browser so that the user knows what is going on. echo '

Our site is currently under maintenance. (db)

'; exit; //Kill the PHP script. } // die("fatal error"); } // include_once('search.routing01.inc.php'); include_once('search.routing02.inc.php'); // setEnvironment(); // memory etc. decodeUrl(); // mod_rewrite-helper: // generate var1 - varX from http://dev.netsupport24.com/branchen/5.01/test1/test2/test3/ereswwrfdf/dfgdgdfg?autob=4535345&key2=mit%20ein/emn&var1=23 parseIncomingVars(); // utf8-handling, setIncomingVars(); // caching if ( isset($runtime['cache']) && (int)$runtime['cache']>=3){ if ( isset($runtime["cache_id"]) && $runtime["cache_id"]!="" ){ notify_add($fn." Cache checked ... "); $resultString = cacheRead($runtime["cache_id"]); if (isset($resultString) && $resultString!=FALSE && $resultString!=""){ notify_add($fn." Cache ... & found."); print $resultString; notify_print(); die(''); } } else{ notify_add($fn." INFO: No cache_id defined"); } } // Build page context $page['VRS'] = VERSION; // $page["body_addElementBottom"]= '
'. str_replace( array('.netsupport24','.rapidnodes','.net', '.com', '.de'),'', $_SERVER["SERVER_NAME"]).'
'; //if ($runtime['debug']===1){ print "
"; var_dump($page["body_addElementBottom"]);  var_dump($_SERVER); die($fn);}
// $page['version'] = VERSION;
$page['backendhost'] = 'www'.substr($_SERVER["SERVER_NAME"],3,(strpos($_SERVER["SERVER_NAME"],'.'))-3);
$page['version'] = VERSION.' | '.str_replace( array('.netsupport24','.rapidnodes','.net', '.com', '.de'),'', $_SERVER["SERVER_NAME"]);
$page['copyright'] =  'We.';
$page['STATIC_URL'] =  $global["STATIC_URL"];
$page['STORIES_LIMIT'] =  6;

// Get distributor job information based on requested website
/*
$page['job'] = loadDistributionJob(
     $_SERVER['HTTP_X_ORIG_HOST'] ?: $_SERVER['HTTP_HOST'],
    $_SERVER['HTTP_X_ORIG_URL'] ?:  $_SERVER['REQUEST_URI'] );
*/
$temp_host = '';
if ( isset($_SERVER['HTTP_X_ORIG_HOST'])) $temp_host = $_SERVER['HTTP_X_ORIG_HOST'];
if ( isset($_SERVER['HTTP_HOST'])) $temp_host = $_SERVER['HTTP_HOST'];
$temp_url='';
if (isset($_SERVER['HTTP_X_ORIG_URL'])) $temp_url=$_SERVER['HTTP_X_ORIG_URL'];
if (isset($_SERVER['REQUEST_URI'])) $temp_url=$_SERVER['REQUEST_URI'];
$page['job'] = loadDistributionJob( $temp_host, $temp_url );

loadDistributionJob_additionalValues();




if (!$page['job']) {
    header("HTTP/1.0 404 Not Found");
    echo "

Not Found

\n

The requested URL was not found on this server.

"; if ( $runtime['debug']===1 ){ print "
ERROR in loadDistributionJob() --> no data found\n"; /* var_dump($page); notify_print(); */  }
    die();
}


// load the right crawler
$include_crawler1 = array('/modules/search/crawler.php');
$include_crawler2 = array('/modules/search/crawler2.php');
$include_crawler = $include_crawler1;
// if ($debug===1){
//    print '
'; var_dump($page); print '
'; // } if ( (int)$page['job']['crawler_version']===2 ) $include_crawler = $include_crawler2; foreach ($include_crawler as $inc){ ( !isset($ghjkjh) ) ? $ghjkjh=0 : $ghjkjh++; if (!include_once($path["script"].$inc)) { if ( $runtime['debug']===1 ) print "
" .$path["script"].$inc;
        die("FATAL ERROR: Couldn´t load element ".$ghjkjh);
    }
}
notify_add($fn.'OK - load crawler version '.$include_crawler[0]); unset($ghjkjh);



// Get template path

if (isset($_GET['page'])){
    $p = $_GET['page'];
    $runtime['template_page']['folder'] = 'cn_new_crawler';
    $pf = DATAPATH."/template/page/".$runtime['template_page']['folder']."/pages/".$p.".tmpl";
    if (file_exists($pf)) $page['page'] = $p;
    unset($p, $pf);
}

// Get search parameters if they are present
/*
// --> this is handled at search.routing02.inc.php now
if ( isset($_GET['search']) && $_GET['search'] !="" ) {
    $page['search_word'] = trim($_GET['search']);

}*/

// Other
// $city = (key_exists('city', $_GET)) ? trim($_GET['city']) : $page['job']['city'];
$city = ( isset($_GET["city"]) ) ? trim($_GET['city']) : $page['job']['city'];
//    if ( isset($runtime['debug']) && ($runtime['debug']===TRUE || $runtime['debug']===1) ){ print "
"; var_dump(get_defined_vars()); }
$page['city'] = $city;
$page['categories'] = $global["categories_config"];
$page['date'] = strftime("%A").date(', d.m.Y');

// Ads
//addPageVar_AdsPremiumUI_run($ResultArray); // sets e.g. $page["AdsPremiumUI"]

// Add city to categories
if ( !isset($global["category_img_base_url"]) ) $global["category_img_base_url"]="";
$rds[$city] = array( 'keywords' => $city, 'image' => $global["category_img_base_url"]."/Reise.jpg" );
$page['categories'] = $rds + $page['categories'];
unset($rds);

if ( isset($runtime["LocalContent"]) ){
    unset($page["listingCompanies"]);
    $page["listingCompanies"] = $runtime["LocalContent"];
    notify_add($fn.'INFO: Overwrite $page["listingCompanies"] with $runtime["LocalContent"]');
}

// Is this a CN_premium page?
if (isset($page['job']['content_url']['CN_premium']) && $page['job']['content_url']['CN_premium']!=""){
    $cn_premium = (int)$page['job']['content_url']['CN_premium'];
    notify_add($fn.'set cn_premium to '.$cn_premium);
}

// load geo-info (federal_state, suburbs, ...
if (!include('./plugin/1_beforeSearch/geo.inc.php')) notify_add("ERRRO: cannot load './plugin/1_beforeSearch/geo.inc.php'");

// Get content
notify_add("Preparing content...");

$crawler = new Crawler($job=$page["job"]);

switch( $runtime["displayMode"] ){
    case "page":
        break;
    case "remoteContent":
        $page['remoteContent'] = displayRemoteContent($_GET['remoteContent']);
        break;
    case "static":
        notify_add($fn.' ... switched to displayMode "static"');
        $file = $global["TemplatePath"] . "/page" . $_GET["page"];  // $_GET["page"] is defined in routing
        notify_add($fn.'set displayMode to "static" (313)');
        displayStaticFiles($file); // special case "static": if exists, display and die
        die();
        break;
    case "story":
        notify_add($fn.' ... switched to displayMode "story"');
        if ( (isset($_GET['story']) && (int)$_GET['story']>0) || ( isset($runtime["displayMode"]) && $runtime["displayMode"]=='story' ) ){
            // Search single story
            $page['is_details_page'] = true;
            $story_id = (int)$_GET['story'];
            notify_add($fn.'Searching for article with ID='.$story_id);

            /* create a switch for random pick crawler or database */
            // $page['story'] = $crawler->getStory($story_id);
            $page['story'] = getStoryDB($story_id);

            $page['similar'] = $crawler->getSimilar($story_id, 7);
            $page['story_stats'] = $crawler->getStats($story_id);

        }
        break;
    case "Search":                     // Search articles
        notify_add($fn.' ... switched to displayMode "search"');

        if ( isset($page['search_word']) && $page['search_word']!="" ) {
                notify_add("Search for articles: {$page['search_word']}");
            $global_search = (bool)$_GET['gs'];
            $location = !$global_search && $page['city'] ? $page['city'] : null;
            $page['search_global'] = !$location;
                notify_add(' ... start search for '.$page['search_word']);
                notify_add(' ... $location='.$location);
            $page['search_result'] = $crawler->search($page['search_word'], $location);

                notify_add('... start a companysearch');
                // $ci_search_api_master = 'https://dev14.netsupport24.net/UI/07_output-client/5.071/CompanyIndexSearch.01.inc.php?token=test123&&lon={LON}&lat={LAT}&q=*{QUERY}}*&ql=*{CITY}*&format=html&template=citynews';
                $ci_search_api_master = 'https://www23.rapidnodes.net/UI/07_output-client/5.071/CompanyIndexSearch.01.inc.php?token=test123&&lon={LON}&lat={LAT}&q=*{QUERY}}*&ql=*{CITY}*&format=html&template=citynews';
                $ci_search_api = str_replace(   array('{QUERY}', '{CITY}', '{POSTALCODE}', '{LON}', '{LAT}'),
                                                array( $page['search_word'], $page['city'], $page["geo"]["suburbs"][0]["postcode"], $page['job']['lon'], $page['job']['lat']),
                                                $ci_search_api_master);
                $page['search_result_company']['content'] = file_get_contents_withCache( $ci_search_api );
                $page['search_result_company']['count'] = ''; // TODO: add count of results
                notify_add(' ... search finished');
        }
        break;
    default:    // start and others
        notify_add($fn.' ... switched to displayMode "default"');
        //include('search.story-list01.php');
        include('search.story-list02.php');
        break;
}




if (isset($page['page']) && $page['page']!="" ) {

    // Do not process articles or anything
    notify_add("Open static page: {$page['page']}");
    $page['page_path'] = "page/" . $page['job']['template_details']['folder'] . "/pages/" . $page['page'] . ".tmpl";
    notify_add("...from: ".$page['page_path']);

}
/*
// add the DPA-TopStory - do not run, if premium-page
if ( !isset($page["job"]["is_premium"]) || ( isset($page["job"]["is_premium"]) && (int)$page["job"]["is_premium"]<1)   ) {
    notify_add("displayMode before DPA-TopStory: ".$runtime["displayMode"]);
    if ( isset($runtime["displayMode"]) && $runtime["displayMode"]=='start' ) {
        if (include('./plugin/3_afterSearch/addDpaTopStory.php')){

        addDpaTopStory_run();}
        notify_add($fn."DPATopStoryEnd");
    }
}
*/


// just load the newsflash, if we are at /-level
notify_add("displayMode before newsflash: ".$runtime["displayMode"]);
if ( isset($runtime["displayMode"]) && $runtime["displayMode"]=='start' ) {

    // version - compilation at backend
/*    if (!include('./plugin/3_afterSearch/addNewsflash.php')) die("FATAL ERROR");
    addNewsflash_run();
    notify_add("1"); */

    // version 2 - compilation at VARNISH - changed order, TRENDING TOPIC first
    $page["newsflash"]["local"] = ''; // {if $entry.newsflash.national}{$entry.newsflash.national}{/if}
// todo : including events with esi tag like this does not work
//    $page["newsflash"]["local"] = '';
    $page["newsflash"]["regional"] = ' https://dev5.netsupport24.net/CN/07_output-client/5.07/apiLatestNewsRadius.CN.php?location=Pirna&radius=5
 */

if ( isset($_REQUEST["debug"]) && (int)$_REQUEST["debug"]===1){
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    $runtime["debug"]=1;
} else{
    error_reporting(0);
}


// define some VARs
$fn = 'apiLatestNewsRadius.CN';

$server_group_1 = array(    "dev14.netsupport24.net", "beta14.netsupport24.net", "www14.netsupport24.net",
                            "dev15.netsupport24.net", "beta15.netsupport24.net", "www15.netsupport24.net",
                            "dev23.netsupport24.net", "beta23.netsupport24.net", "www23.netsupport24.net",
                            "dev24.netsupport24.net", "beta24.netsupport24.net", "www24.netsupport24.net" );
$server_group_2 = array(    "dev5.netsupport24.net", "beta5.netsupport24.net", "www5.netsupport24.net" );
if ( isset($_SERVER['SERVER_NAME']) && in_array($_SERVER['SERVER_NAME'], $server_group_1)){
        $version = str_replace( dirname(__DIR__,1).'/', '', __DIR__);
        $path = array(
            'root' => dirname(__DIR__, 2),
            'data' => dirname(__DIR__, 5).'/_data/CN',
            'cache' => dirname(__DIR__, 5).'/_data/CN/5.19/cache', // /var/www/clients/client4/web3/web/_data/CN/5.19/cache/
            'script' => __DIR__
        );
}
elseif ( isset($_SERVER['SERVER_NAME']) && in_array($_SERVER['SERVER_NAME'], $server_group_2)){
    $path["data"]='/var/customers/webs/webmDSS/netsupport24.net/_data/CN';     // DOCUMENT_ROOT -> 	/var/customers/webs/webmDSS/netsupport24.net/web-dev/
    $path['cache'] = dirname(__DIR__, 5).'/_data/CN/5.19/cache'; // /var/www/clients/client4/web3/web/_data/CN/5.19/cache/
    $path["root"]='/var/customers/webs/webmDSS/netsupport24.net/web-dev/CN';
    $path["script"]=$path["root"].'/07_output-client/5.09';
}
else{ die(""); }


$limit=15; // speed: 1000/90sec
$time_start = microtime(true);
if (!isset($runtime)) $runtime = array();
$global = array(
    "debug" => TRUE,
    'debug_allowed' => array(0,1),
    "FileNameLength" => 12,
    "allowed_format" => array("html","json","text", "none"),
    "format_default" => 'html',
    "CachePath" => $path['cache'],

);
$location = array();
$tags = array();
$tag_ids = array();
$includes = array(
    $path["data"]."/5.19/config/config_database_external.inc.php",
    $path["root"]."/00_resources/inq.modules/6.01/global.inc.php",
    $path["root"]."/00_resources/inq.modules/6.01/array/array.inc.php",
    $path["root"]."/00_resources/inq.modules/6.01/cache/cache.inc.php",
    $path["root"]."/00_resources/inq.modules/6.01/database/mysql8.php",
    $path["root"]."/00_resources/inq.modules/6.01/file/func.file.php",
    $path["root"]."/00_resources/inq.modules/6.01/json/json.inc.php",
);



// DO THE INLUDES
foreach($includes as $inc){
    if ( $runtime["debug"]===1 ) {
  //      print "\n \$global".var_dump($global);
        print "\n ... load ".$inc;
    }
    if (!include_once($inc)) {
        print "
";
        if ( $runtime["debug"]===1 ) print "\n... load ".$inc;
        die("FATAL ERROR: could not load file: ".$inc);
    }
}

// correct some VARs
$global["debug"]=TRUE; //--> overwritte the value from /global.inc.php
$timestamp=time();


notify_add($fn." started -------------------------------");

// manage some incoming VARs
( isset($_REQUEST["location"]) && $_REQUEST["location"]!="" ) ? $location['in'] = $_REQUEST["location"] : die("FATAL ERROR: Missing incoming VAR") ;
( isset($_REQUEST["radius"]) && $_REQUEST["radius"]!="" && (int)$_REQUEST["radius"]>0 ) ? $radius = (int)$_REQUEST["radius"] : $radius=5;
( isset($_REQUEST["limit"]) && $_REQUEST["limit"]!="" && (int)$_REQUEST["limit"]>0 ) ? $limit = (int)$_REQUEST["limit"] : $limit=5;
( isset($_REQUEST["debug"]) && (int)$_REQUEST["debug"]===1 && $global["debug"]===TRUE ) ? $runtime["debug"]=1 : $runtime["debug"]=0;
( isset($_REQUEST["publisher_id"]) && (int)$_REQUEST["publisher_id"]>1  ) ? $q_add_publisher="AND publisher_id=".(int)$_REQUEST["publisher_id"]." " : $q_add_publisher = "";
( isset($_REQUEST["picture"]) && (int)$_REQUEST["picture"]>0  ) ? $q_add_picture=' AND story_thumb<>""': $q_add_picture = '';
( isset($_REQUEST["format"]) && in_array($_REQUEST["format"],$global["allowed_format"])  ) ? $runtime["format"]=$_REQUEST["format"] : $runtime["format"]=$global["format_default"];

// Try to return recent cached value
require_once __DIR__."/classes/InqCache.php";
$cache = new InqCache();
$cached = $cache->get(1800);
if ($runtime['format'] == 'json') {
    if ($cached) {
        echo json_response($cached, 200);
        die();
    }
} else {
    if ($cached) die($cached);
}


    if ($runtime["debug"]===1){ notify_add($fn.' ... started'); }

if ( createDBConnection() ) notify_add("Connected to database");
else{
    if ( $runtime["debug"]===1){      }
    else{
        // version 2
        header($_SERVER["SERVER_PROTOCOL"]." 503 Service Temporarily Unavailable", true, 503);      //Service Temporarily Unavailable status code to the client.
        $retryAfterSeconds = 240;                                                                   //The number of seconds that the client should wait before retrying.
        header('Retry-After: ' . $retryAfterSeconds);                                               //Send a Retry-After header to the client.
        echo '

503 Service Temporarily Unavailable

'; //Send a message to the browser so that the user knows what is going on. echo '

Our site is currently under maintenance. (db)

'; exit; //Kill the PHP script. } // die("fatal error"); } // get location (lon/lat) for the given cityname $api_master = "https://api.geo.inquence.com/api/v1/location?q={KEYWORD}&country=DE"; $api_url = str_replace("{KEYWORD}", $location['in'], $api_master ); // $location['details'] = callJSONAPI($api_url,TRUE,84000); $location['details'] = callJSONAPI2($api_url,TRUE,10,2,1,"curl"); if ( $location['details']===FALSE ){ die(""); } if ($runtime["debug"]===1) { $msg = "JSON call to '".$api_url."' finished"; notify_add($fn.$msg); print "\n"; // notify_print(); // closeDBConnection(); // die($fn." die in line 124"); } // $location['details']['data']['lon'] // $location['details']['data']['lat'] if ( !isset($location['details']['data']['lon']) || $location['details']['data']['lon']=="" || !isset( $location['details']['data']['lat'] ) || $location['details']['data']['lat']=="" ){ if ($runtime["debug"]===1){ print "\nlon: ".$location['details']['data']['lon']; print "\nlat: ".$location['details']['data']['lat']."\n"; var_dump($location['details']); } closeDBConnection(); die(""); } // get all tags ids $limit_tags = 500; $query_master = 'SELECT tag_id, ( 3959 * acos ( cos ( radians({LAT}) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians({LON}) ) + sin ( radians({LAT}) ) * sin( radians( lat ) ) ) ) AS distance FROM dug_tags_location HAVING distance < {RADIUS} ORDER BY distance LIMIT 0 , '.$limit_tags.';'; $query = str_replace( array('{LON}','{LAT}','{RADIUS}', '{LIMIT}'), array( $location['details']['data']['lon'], $location['details']['data']['lat'], $radius, $limit_tags ), $query_master ); if ( $runtime["debug"]===1 ) { notify_add($fn.$query); } $tags = executeQuery($query); if ( !isset($tags) || !is_array($tags) || count($tags)<1 ){ closeDBConnection(); die(""); } if ($runtime["debug"]===1) { $msg = "... loaded tags from database"; notify_add($fn . $msg); } // find all articles (max. 5 days) for each tag-id foreach ($tags as $tag){ $tag_ids[] = $tag['tag_id']; } // $tag_time_max = $timestamp-(86400*3); // if ( $q_add_publisher!="" ) $tag_time_max = $timestamp-(86400*30); // $query = 'SELECT * FROM dug_stories_tags WHERE tag_id IN (' . implode(',',$tag_ids) . ') AND tag_time > '.$tag_time_max.' ORDER BY tag_time LIMIT 400;'; $query = 'SELECT * FROM dug_stories_tags WHERE tag_id IN (' . implode(',',$tag_ids) . ') /* ORDER BY tag_time LIMIT 200; */'; if ( $runtime["debug"]===1 ) { print "
\n".$query; }
$story_ids = executeQuery($query);

if ($runtime["debug"]===1) {     $msg = "... loaded story_ids from database";     notify_add($fn . $msg); }


// load blacklist domains
$path['config'] = str_replace('/cache', '/config', $path['cache']);
$runtime['blacklist_source'] = $path['config'].'/LSRblacklist.txt';
$runtime['blacklist_array'] = file($runtime['blacklist_source'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
if ( isset($runtime['blacklist_array']) && is_array($runtime['blacklist_array']) && count($runtime['blacklist_array'])>0 ){
    $q_add_lsrdomain = ' AND domain NOT IN ("' . implode('", "', $runtime['blacklist_array']) . '")';
} else{ $q_add_lsrdomain=''; }



// load articles details
$article_ids = array();
$story_time_max = $timestamp-(86400*10);
foreach( $story_ids as $story_id){ $article_ids[] = $story_id['story_id']; }
// $query = 'SELECT * FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ')';
$query = 'SELECT story_id, story_title, story_time, story_thumb, story_desc FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ') AND story_time>'.$story_time_max.'
AND processing>79 '.$q_add_lsrdomain . $q_add_picture.' AND story_cat<>100 '.$q_add_publisher.' ORDER BY story_time DESC LIMIT 0,'.$limit;
    if ( $runtime["debug"]===1 ) { print "
\n".$query; }
$news = executeQuery($query);

// create a fallback for to less articles
if ( !isset($news) || !is_array($news) || count($news)<$limit){
    $story_time_max = $timestamp-(86400*60);
    foreach( $story_ids as $story_id){ $article_ids[] = $story_id['story_id']; }
// $query = 'SELECT * FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ')';
    $query = 'SELECT story_id, story_title, story_time, story_thumb, story_desc FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ') AND story_time>'.$story_time_max.'
AND processing>79 '.$q_add_picture. $q_add_lsrdomain . ' AND story_cat<>100 '.$q_add_publisher.' ORDER BY story_time DESC LIMIT 0,'.$limit;
    if ( $runtime["debug"]===1 ) { print "
\n".$query; }
    $news = executeQuery($query);
}



// create output
if ( !isset($news) || !is_array($news) || count($news)<1 ){
    if ( $runtime["format"]==='json' ){ http_response_code(500); closeDBConnection(); die();  }
    closeDBConnection();
    die(''); // no stories found
}

// deal with data
$i = -1; $i_max=count($news)-1;
while ( $i++<$i_max){
    if ( isset($q_add_publisher) && $q_add_publisher!="" ){ // special case "dpa"
        $news[$i]['story_url'] = 'https://www.hier-aktuell.de/artikel/'.$news[$i]['story_id'];
    }
}



$links=array(); $i=0;
if ( $runtime["format"]=='json' ){
    $cache->set($news);
    echo json_response($news, 200);
    closeDBConnection();
    die();
}


// (B) HTML OUTPUT
$template = file_get_contents('template_LatestNews.html'); // needs {HEADLINE} & {LINKS}
// $links_master = '
  • {STORY_TITLE}
  • '; $links_master_internal = '
  • {STORY_TITLE}
  • '; $links_master_external = '
  • {STORY_TITLE}
  • '; if ($runtime["debug"]===1){ $links_master_internal = '
  • {STORY_TITLE}
  • '; } foreach( $news as $article ){ if ($i++>=$limit) continue; if ( isset($article['story_url']) && $article['story_url']!="" ) $links_master = $links_master_external; else { $article['story_url']=''; $links_master = $links_master_internal; } $links[] = str_replace( array('{STORY_ID}','{STORY_TITLE}','{STORY_THUMB}', '{STORY_URL}'), array( $article['story_id'], $article['story_title'], $article['story_thumb'], $article['story_url']), $links_master ); } if ( $radius <= 5){ $headline = 'Nachrichten aus '.$location['in']; } else{ $headline = $location['in'].' und Umgebung'; } $output = str_replace( array( '{HEADLINE}', '{LINKS}'), array( $headline, implode("\n", $links)), $template); if ( $runtime["debug"]===0 ){ $output = preg_replace('//Uis', '', $output); // remove all comments in public html } closeDBConnection(); if ($output) { $cache->set($output); die($output); } else { die($cache->get() ?: ''); } // merge & order this data // generate the output $output = array( 'status' => 'ok', 'content' => $data, ); // $output = json_encode($output, TRUE); $output = json_encode($output, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); header('Access-Control-Allow-Origin: *'); header("Content-type: application/json; charset=utf-8"); print $output; closeDBConnection(); die(); '; // {if $entry.newsflash.regional}{$entry.newsflash.local}{/if} $page["newsflash"]["national"] = ' https://dev5.netsupport24.net/CN/07_output-client/5.07/apiLatestNewsRadius.CN.php?location=Pirna&radius=5 */ if ( isset($_REQUEST["debug"]) && (int)$_REQUEST["debug"]===1){ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $runtime["debug"]=1; } else{ error_reporting(0); } // define some VARs $fn = 'apiLatestNewsRadius.CN'; $server_group_1 = array( "dev14.netsupport24.net", "beta14.netsupport24.net", "www14.netsupport24.net", "dev15.netsupport24.net", "beta15.netsupport24.net", "www15.netsupport24.net", "dev23.netsupport24.net", "beta23.netsupport24.net", "www23.netsupport24.net", "dev24.netsupport24.net", "beta24.netsupport24.net", "www24.netsupport24.net" ); $server_group_2 = array( "dev5.netsupport24.net", "beta5.netsupport24.net", "www5.netsupport24.net" ); if ( isset($_SERVER['SERVER_NAME']) && in_array($_SERVER['SERVER_NAME'], $server_group_1)){ $version = str_replace( dirname(__DIR__,1).'/', '', __DIR__); $path = array( 'root' => dirname(__DIR__, 2), 'data' => dirname(__DIR__, 5).'/_data/CN', 'cache' => dirname(__DIR__, 5).'/_data/CN/5.19/cache', // /var/www/clients/client4/web3/web/_data/CN/5.19/cache/ 'script' => __DIR__ ); } elseif ( isset($_SERVER['SERVER_NAME']) && in_array($_SERVER['SERVER_NAME'], $server_group_2)){ $path["data"]='/var/customers/webs/webmDSS/netsupport24.net/_data/CN'; // DOCUMENT_ROOT -> /var/customers/webs/webmDSS/netsupport24.net/web-dev/ $path['cache'] = dirname(__DIR__, 5).'/_data/CN/5.19/cache'; // /var/www/clients/client4/web3/web/_data/CN/5.19/cache/ $path["root"]='/var/customers/webs/webmDSS/netsupport24.net/web-dev/CN'; $path["script"]=$path["root"].'/07_output-client/5.09'; } else{ die(""); } $limit=15; // speed: 1000/90sec $time_start = microtime(true); if (!isset($runtime)) $runtime = array(); $global = array( "debug" => TRUE, 'debug_allowed' => array(0,1), "FileNameLength" => 12, "allowed_format" => array("html","json","text", "none"), "format_default" => 'html', "CachePath" => $path['cache'], ); $location = array(); $tags = array(); $tag_ids = array(); $includes = array( $path["data"]."/5.19/config/config_database_external.inc.php", $path["root"]."/00_resources/inq.modules/6.01/global.inc.php", $path["root"]."/00_resources/inq.modules/6.01/array/array.inc.php", $path["root"]."/00_resources/inq.modules/6.01/cache/cache.inc.php", $path["root"]."/00_resources/inq.modules/6.01/database/mysql8.php", $path["root"]."/00_resources/inq.modules/6.01/file/func.file.php", $path["root"]."/00_resources/inq.modules/6.01/json/json.inc.php", ); // DO THE INLUDES foreach($includes as $inc){ if ( $runtime["debug"]===1 ) { // print "\n \$global".var_dump($global); print "\n ... load ".$inc; } if (!include_once($inc)) { print "
    ";
            if ( $runtime["debug"]===1 ) print "\n... load ".$inc;
            die("FATAL ERROR: could not load file: ".$inc);
        }
    }
    
    // correct some VARs
    $global["debug"]=TRUE; //--> overwritte the value from /global.inc.php
    $timestamp=time();
    
    
    notify_add($fn." started -------------------------------");
    
    // manage some incoming VARs
    ( isset($_REQUEST["location"]) && $_REQUEST["location"]!="" ) ? $location['in'] = $_REQUEST["location"] : die("FATAL ERROR: Missing incoming VAR") ;
    ( isset($_REQUEST["radius"]) && $_REQUEST["radius"]!="" && (int)$_REQUEST["radius"]>0 ) ? $radius = (int)$_REQUEST["radius"] : $radius=5;
    ( isset($_REQUEST["limit"]) && $_REQUEST["limit"]!="" && (int)$_REQUEST["limit"]>0 ) ? $limit = (int)$_REQUEST["limit"] : $limit=5;
    ( isset($_REQUEST["debug"]) && (int)$_REQUEST["debug"]===1 && $global["debug"]===TRUE ) ? $runtime["debug"]=1 : $runtime["debug"]=0;
    ( isset($_REQUEST["publisher_id"]) && (int)$_REQUEST["publisher_id"]>1  ) ? $q_add_publisher="AND publisher_id=".(int)$_REQUEST["publisher_id"]." " : $q_add_publisher = "";
    ( isset($_REQUEST["picture"]) && (int)$_REQUEST["picture"]>0  ) ? $q_add_picture=' AND story_thumb<>""': $q_add_picture = '';
    ( isset($_REQUEST["format"]) && in_array($_REQUEST["format"],$global["allowed_format"])  ) ? $runtime["format"]=$_REQUEST["format"] : $runtime["format"]=$global["format_default"];
    
    // Try to return recent cached value
    require_once __DIR__."/classes/InqCache.php";
    $cache = new InqCache();
    $cached = $cache->get(1800);
    if ($runtime['format'] == 'json') {
        if ($cached) {
            echo json_response($cached, 200);
            die();
        }
    } else {
        if ($cached) die($cached);
    }
    
    
        if ($runtime["debug"]===1){ notify_add($fn.' ... started'); }
    
    if ( createDBConnection() ) notify_add("Connected to database");
    else{
        if ( $runtime["debug"]===1){      }
        else{
            // version 2
            header($_SERVER["SERVER_PROTOCOL"]." 503 Service Temporarily Unavailable", true, 503);      //Service Temporarily Unavailable status code to the client.
            $retryAfterSeconds = 240;                                                                   //The number of seconds that the client should wait before retrying.
            header('Retry-After: ' . $retryAfterSeconds);                                               //Send a Retry-After header to the client.
            echo '

    503 Service Temporarily Unavailable

    '; //Send a message to the browser so that the user knows what is going on. echo '

    Our site is currently under maintenance. (db)

    '; exit; //Kill the PHP script. } // die("fatal error"); } // get location (lon/lat) for the given cityname $api_master = "https://api.geo.inquence.com/api/v1/location?q={KEYWORD}&country=DE"; $api_url = str_replace("{KEYWORD}", $location['in'], $api_master ); // $location['details'] = callJSONAPI($api_url,TRUE,84000); $location['details'] = callJSONAPI2($api_url,TRUE,10,2,1,"curl"); if ( $location['details']===FALSE ){ die(""); } if ($runtime["debug"]===1) { $msg = "JSON call to '".$api_url."' finished"; notify_add($fn.$msg); print "\n"; // notify_print(); // closeDBConnection(); // die($fn." die in line 124"); } // $location['details']['data']['lon'] // $location['details']['data']['lat'] if ( !isset($location['details']['data']['lon']) || $location['details']['data']['lon']=="" || !isset( $location['details']['data']['lat'] ) || $location['details']['data']['lat']=="" ){ if ($runtime["debug"]===1){ print "\nlon: ".$location['details']['data']['lon']; print "\nlat: ".$location['details']['data']['lat']."\n"; var_dump($location['details']); } closeDBConnection(); die(""); } // get all tags ids $limit_tags = 500; $query_master = 'SELECT tag_id, ( 3959 * acos ( cos ( radians({LAT}) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians({LON}) ) + sin ( radians({LAT}) ) * sin( radians( lat ) ) ) ) AS distance FROM dug_tags_location HAVING distance < {RADIUS} ORDER BY distance LIMIT 0 , '.$limit_tags.';'; $query = str_replace( array('{LON}','{LAT}','{RADIUS}', '{LIMIT}'), array( $location['details']['data']['lon'], $location['details']['data']['lat'], $radius, $limit_tags ), $query_master ); if ( $runtime["debug"]===1 ) { notify_add($fn.$query); } $tags = executeQuery($query); if ( !isset($tags) || !is_array($tags) || count($tags)<1 ){ closeDBConnection(); die(""); } if ($runtime["debug"]===1) { $msg = "... loaded tags from database"; notify_add($fn . $msg); } // find all articles (max. 5 days) for each tag-id foreach ($tags as $tag){ $tag_ids[] = $tag['tag_id']; } // $tag_time_max = $timestamp-(86400*3); // if ( $q_add_publisher!="" ) $tag_time_max = $timestamp-(86400*30); // $query = 'SELECT * FROM dug_stories_tags WHERE tag_id IN (' . implode(',',$tag_ids) . ') AND tag_time > '.$tag_time_max.' ORDER BY tag_time LIMIT 400;'; $query = 'SELECT * FROM dug_stories_tags WHERE tag_id IN (' . implode(',',$tag_ids) . ') /* ORDER BY tag_time LIMIT 200; */'; if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
    $story_ids = executeQuery($query);
    
    if ($runtime["debug"]===1) {     $msg = "... loaded story_ids from database";     notify_add($fn . $msg); }
    
    
    // load blacklist domains
    $path['config'] = str_replace('/cache', '/config', $path['cache']);
    $runtime['blacklist_source'] = $path['config'].'/LSRblacklist.txt';
    $runtime['blacklist_array'] = file($runtime['blacklist_source'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
    if ( isset($runtime['blacklist_array']) && is_array($runtime['blacklist_array']) && count($runtime['blacklist_array'])>0 ){
        $q_add_lsrdomain = ' AND domain NOT IN ("' . implode('", "', $runtime['blacklist_array']) . '")';
    } else{ $q_add_lsrdomain=''; }
    
    
    
    // load articles details
    $article_ids = array();
    $story_time_max = $timestamp-(86400*10);
    foreach( $story_ids as $story_id){ $article_ids[] = $story_id['story_id']; }
    // $query = 'SELECT * FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ')';
    $query = 'SELECT story_id, story_title, story_time, story_thumb, story_desc FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ') AND story_time>'.$story_time_max.'
    AND processing>79 '.$q_add_lsrdomain . $q_add_picture.' AND story_cat<>100 '.$q_add_publisher.' ORDER BY story_time DESC LIMIT 0,'.$limit;
        if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
    $news = executeQuery($query);
    
    // create a fallback for to less articles
    if ( !isset($news) || !is_array($news) || count($news)<$limit){
        $story_time_max = $timestamp-(86400*60);
        foreach( $story_ids as $story_id){ $article_ids[] = $story_id['story_id']; }
    // $query = 'SELECT * FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ')';
        $query = 'SELECT story_id, story_title, story_time, story_thumb, story_desc FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ') AND story_time>'.$story_time_max.'
    AND processing>79 '.$q_add_picture. $q_add_lsrdomain . ' AND story_cat<>100 '.$q_add_publisher.' ORDER BY story_time DESC LIMIT 0,'.$limit;
        if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
        $news = executeQuery($query);
    }
    
    
    
    // create output
    if ( !isset($news) || !is_array($news) || count($news)<1 ){
        if ( $runtime["format"]==='json' ){ http_response_code(500); closeDBConnection(); die();  }
        closeDBConnection();
        die(''); // no stories found
    }
    
    // deal with data
    $i = -1; $i_max=count($news)-1;
    while ( $i++<$i_max){
        if ( isset($q_add_publisher) && $q_add_publisher!="" ){ // special case "dpa"
            $news[$i]['story_url'] = 'https://www.hier-aktuell.de/artikel/'.$news[$i]['story_id'];
        }
    }
    
    
    
    $links=array(); $i=0;
    if ( $runtime["format"]=='json' ){
        $cache->set($news);
        echo json_response($news, 200);
        closeDBConnection();
        die();
    }
    
    
    // (B) HTML OUTPUT
    $template = file_get_contents('template_LatestNews.html'); // needs {HEADLINE} & {LINKS}
    // $links_master = '
  • {STORY_TITLE}
  • '; $links_master_internal = '
  • {STORY_TITLE}
  • '; $links_master_external = '
  • {STORY_TITLE}
  • '; if ($runtime["debug"]===1){ $links_master_internal = '
  • {STORY_TITLE}
  • '; } foreach( $news as $article ){ if ($i++>=$limit) continue; if ( isset($article['story_url']) && $article['story_url']!="" ) $links_master = $links_master_external; else { $article['story_url']=''; $links_master = $links_master_internal; } $links[] = str_replace( array('{STORY_ID}','{STORY_TITLE}','{STORY_THUMB}', '{STORY_URL}'), array( $article['story_id'], $article['story_title'], $article['story_thumb'], $article['story_url']), $links_master ); } if ( $radius <= 5){ $headline = 'Nachrichten aus '.$location['in']; } else{ $headline = $location['in'].' und Umgebung'; } $output = str_replace( array( '{HEADLINE}', '{LINKS}'), array( $headline, implode("\n", $links)), $template); if ( $runtime["debug"]===0 ){ $output = preg_replace('//Uis', '', $output); // remove all comments in public html } closeDBConnection(); if ($output) { $cache->set($output); die($output); } else { die($cache->get() ?: ''); } // merge & order this data // generate the output $output = array( 'status' => 'ok', 'content' => $data, ); // $output = json_encode($output, TRUE); $output = json_encode($output, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); header('Access-Control-Allow-Origin: *'); header("Content-type: application/json; charset=utf-8"); print $output; closeDBConnection(); die(); '; // {if $entry.newsflash.regional}{$entry.newsflash.regional}{/if} // $page["newsflash"]["local"]=' https://dev5.netsupport24.net/CN/07_output-client/5.07/apiLatestNewsRadius.CN.php?location=Pirna&radius=5 */ if ( isset($_REQUEST["debug"]) && (int)$_REQUEST["debug"]===1){ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $runtime["debug"]=1; } else{ error_reporting(0); } // define some VARs $fn = 'apiLatestNewsRadius.CN'; $server_group_1 = array( "dev14.netsupport24.net", "beta14.netsupport24.net", "www14.netsupport24.net", "dev15.netsupport24.net", "beta15.netsupport24.net", "www15.netsupport24.net", "dev23.netsupport24.net", "beta23.netsupport24.net", "www23.netsupport24.net", "dev24.netsupport24.net", "beta24.netsupport24.net", "www24.netsupport24.net" ); $server_group_2 = array( "dev5.netsupport24.net", "beta5.netsupport24.net", "www5.netsupport24.net" ); if ( isset($_SERVER['SERVER_NAME']) && in_array($_SERVER['SERVER_NAME'], $server_group_1)){ $version = str_replace( dirname(__DIR__,1).'/', '', __DIR__); $path = array( 'root' => dirname(__DIR__, 2), 'data' => dirname(__DIR__, 5).'/_data/CN', 'cache' => dirname(__DIR__, 5).'/_data/CN/5.19/cache', // /var/www/clients/client4/web3/web/_data/CN/5.19/cache/ 'script' => __DIR__ ); } elseif ( isset($_SERVER['SERVER_NAME']) && in_array($_SERVER['SERVER_NAME'], $server_group_2)){ $path["data"]='/var/customers/webs/webmDSS/netsupport24.net/_data/CN'; // DOCUMENT_ROOT -> /var/customers/webs/webmDSS/netsupport24.net/web-dev/ $path['cache'] = dirname(__DIR__, 5).'/_data/CN/5.19/cache'; // /var/www/clients/client4/web3/web/_data/CN/5.19/cache/ $path["root"]='/var/customers/webs/webmDSS/netsupport24.net/web-dev/CN'; $path["script"]=$path["root"].'/07_output-client/5.09'; } else{ die(""); } $limit=15; // speed: 1000/90sec $time_start = microtime(true); if (!isset($runtime)) $runtime = array(); $global = array( "debug" => TRUE, 'debug_allowed' => array(0,1), "FileNameLength" => 12, "allowed_format" => array("html","json","text", "none"), "format_default" => 'html', "CachePath" => $path['cache'], ); $location = array(); $tags = array(); $tag_ids = array(); $includes = array( $path["data"]."/5.19/config/config_database_external.inc.php", $path["root"]."/00_resources/inq.modules/6.01/global.inc.php", $path["root"]."/00_resources/inq.modules/6.01/array/array.inc.php", $path["root"]."/00_resources/inq.modules/6.01/cache/cache.inc.php", $path["root"]."/00_resources/inq.modules/6.01/database/mysql8.php", $path["root"]."/00_resources/inq.modules/6.01/file/func.file.php", $path["root"]."/00_resources/inq.modules/6.01/json/json.inc.php", ); // DO THE INLUDES foreach($includes as $inc){ if ( $runtime["debug"]===1 ) { // print "\n \$global".var_dump($global); print "\n ... load ".$inc; } if (!include_once($inc)) { print "
    ";
            if ( $runtime["debug"]===1 ) print "\n... load ".$inc;
            die("FATAL ERROR: could not load file: ".$inc);
        }
    }
    
    // correct some VARs
    $global["debug"]=TRUE; //--> overwritte the value from /global.inc.php
    $timestamp=time();
    
    
    notify_add($fn." started -------------------------------");
    
    // manage some incoming VARs
    ( isset($_REQUEST["location"]) && $_REQUEST["location"]!="" ) ? $location['in'] = $_REQUEST["location"] : die("FATAL ERROR: Missing incoming VAR") ;
    ( isset($_REQUEST["radius"]) && $_REQUEST["radius"]!="" && (int)$_REQUEST["radius"]>0 ) ? $radius = (int)$_REQUEST["radius"] : $radius=5;
    ( isset($_REQUEST["limit"]) && $_REQUEST["limit"]!="" && (int)$_REQUEST["limit"]>0 ) ? $limit = (int)$_REQUEST["limit"] : $limit=5;
    ( isset($_REQUEST["debug"]) && (int)$_REQUEST["debug"]===1 && $global["debug"]===TRUE ) ? $runtime["debug"]=1 : $runtime["debug"]=0;
    ( isset($_REQUEST["publisher_id"]) && (int)$_REQUEST["publisher_id"]>1  ) ? $q_add_publisher="AND publisher_id=".(int)$_REQUEST["publisher_id"]." " : $q_add_publisher = "";
    ( isset($_REQUEST["picture"]) && (int)$_REQUEST["picture"]>0  ) ? $q_add_picture=' AND story_thumb<>""': $q_add_picture = '';
    ( isset($_REQUEST["format"]) && in_array($_REQUEST["format"],$global["allowed_format"])  ) ? $runtime["format"]=$_REQUEST["format"] : $runtime["format"]=$global["format_default"];
    
    // Try to return recent cached value
    require_once __DIR__."/classes/InqCache.php";
    $cache = new InqCache();
    $cached = $cache->get(1800);
    if ($runtime['format'] == 'json') {
        if ($cached) {
            echo json_response($cached, 200);
            die();
        }
    } else {
        if ($cached) die($cached);
    }
    
    
        if ($runtime["debug"]===1){ notify_add($fn.' ... started'); }
    
    if ( createDBConnection() ) notify_add("Connected to database");
    else{
        if ( $runtime["debug"]===1){      }
        else{
            // version 2
            header($_SERVER["SERVER_PROTOCOL"]." 503 Service Temporarily Unavailable", true, 503);      //Service Temporarily Unavailable status code to the client.
            $retryAfterSeconds = 240;                                                                   //The number of seconds that the client should wait before retrying.
            header('Retry-After: ' . $retryAfterSeconds);                                               //Send a Retry-After header to the client.
            echo '

    503 Service Temporarily Unavailable

    '; //Send a message to the browser so that the user knows what is going on. echo '

    Our site is currently under maintenance. (db)

    '; exit; //Kill the PHP script. } // die("fatal error"); } // get location (lon/lat) for the given cityname $api_master = "https://api.geo.inquence.com/api/v1/location?q={KEYWORD}&country=DE"; $api_url = str_replace("{KEYWORD}", $location['in'], $api_master ); // $location['details'] = callJSONAPI($api_url,TRUE,84000); $location['details'] = callJSONAPI2($api_url,TRUE,10,2,1,"curl"); if ( $location['details']===FALSE ){ die(""); } if ($runtime["debug"]===1) { $msg = "JSON call to '".$api_url."' finished"; notify_add($fn.$msg); print "\n"; // notify_print(); // closeDBConnection(); // die($fn." die in line 124"); } // $location['details']['data']['lon'] // $location['details']['data']['lat'] if ( !isset($location['details']['data']['lon']) || $location['details']['data']['lon']=="" || !isset( $location['details']['data']['lat'] ) || $location['details']['data']['lat']=="" ){ if ($runtime["debug"]===1){ print "\nlon: ".$location['details']['data']['lon']; print "\nlat: ".$location['details']['data']['lat']."\n"; var_dump($location['details']); } closeDBConnection(); die(""); } // get all tags ids $limit_tags = 500; $query_master = 'SELECT tag_id, ( 3959 * acos ( cos ( radians({LAT}) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians({LON}) ) + sin ( radians({LAT}) ) * sin( radians( lat ) ) ) ) AS distance FROM dug_tags_location HAVING distance < {RADIUS} ORDER BY distance LIMIT 0 , '.$limit_tags.';'; $query = str_replace( array('{LON}','{LAT}','{RADIUS}', '{LIMIT}'), array( $location['details']['data']['lon'], $location['details']['data']['lat'], $radius, $limit_tags ), $query_master ); if ( $runtime["debug"]===1 ) { notify_add($fn.$query); } $tags = executeQuery($query); if ( !isset($tags) || !is_array($tags) || count($tags)<1 ){ closeDBConnection(); die(""); } if ($runtime["debug"]===1) { $msg = "... loaded tags from database"; notify_add($fn . $msg); } // find all articles (max. 5 days) for each tag-id foreach ($tags as $tag){ $tag_ids[] = $tag['tag_id']; } // $tag_time_max = $timestamp-(86400*3); // if ( $q_add_publisher!="" ) $tag_time_max = $timestamp-(86400*30); // $query = 'SELECT * FROM dug_stories_tags WHERE tag_id IN (' . implode(',',$tag_ids) . ') AND tag_time > '.$tag_time_max.' ORDER BY tag_time LIMIT 400;'; $query = 'SELECT * FROM dug_stories_tags WHERE tag_id IN (' . implode(',',$tag_ids) . ') /* ORDER BY tag_time LIMIT 200; */'; if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
    $story_ids = executeQuery($query);
    
    if ($runtime["debug"]===1) {     $msg = "... loaded story_ids from database";     notify_add($fn . $msg); }
    
    
    // load blacklist domains
    $path['config'] = str_replace('/cache', '/config', $path['cache']);
    $runtime['blacklist_source'] = $path['config'].'/LSRblacklist.txt';
    $runtime['blacklist_array'] = file($runtime['blacklist_source'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
    if ( isset($runtime['blacklist_array']) && is_array($runtime['blacklist_array']) && count($runtime['blacklist_array'])>0 ){
        $q_add_lsrdomain = ' AND domain NOT IN ("' . implode('", "', $runtime['blacklist_array']) . '")';
    } else{ $q_add_lsrdomain=''; }
    
    
    
    // load articles details
    $article_ids = array();
    $story_time_max = $timestamp-(86400*10);
    foreach( $story_ids as $story_id){ $article_ids[] = $story_id['story_id']; }
    // $query = 'SELECT * FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ')';
    $query = 'SELECT story_id, story_title, story_time, story_thumb, story_desc FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ') AND story_time>'.$story_time_max.'
    AND processing>79 '.$q_add_lsrdomain . $q_add_picture.' AND story_cat<>100 '.$q_add_publisher.' ORDER BY story_time DESC LIMIT 0,'.$limit;
        if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
    $news = executeQuery($query);
    
    // create a fallback for to less articles
    if ( !isset($news) || !is_array($news) || count($news)<$limit){
        $story_time_max = $timestamp-(86400*60);
        foreach( $story_ids as $story_id){ $article_ids[] = $story_id['story_id']; }
    // $query = 'SELECT * FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ')';
        $query = 'SELECT story_id, story_title, story_time, story_thumb, story_desc FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ') AND story_time>'.$story_time_max.'
    AND processing>79 '.$q_add_picture. $q_add_lsrdomain . ' AND story_cat<>100 '.$q_add_publisher.' ORDER BY story_time DESC LIMIT 0,'.$limit;
        if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
        $news = executeQuery($query);
    }
    
    
    
    // create output
    if ( !isset($news) || !is_array($news) || count($news)<1 ){
        if ( $runtime["format"]==='json' ){ http_response_code(500); closeDBConnection(); die();  }
        closeDBConnection();
        die(''); // no stories found
    }
    
    // deal with data
    $i = -1; $i_max=count($news)-1;
    while ( $i++<$i_max){
        if ( isset($q_add_publisher) && $q_add_publisher!="" ){ // special case "dpa"
            $news[$i]['story_url'] = 'https://www.hier-aktuell.de/artikel/'.$news[$i]['story_id'];
        }
    }
    
    
    
    $links=array(); $i=0;
    if ( $runtime["format"]=='json' ){
        $cache->set($news);
        echo json_response($news, 200);
        closeDBConnection();
        die();
    }
    
    
    // (B) HTML OUTPUT
    $template = file_get_contents('template_LatestNews.html'); // needs {HEADLINE} & {LINKS}
    // $links_master = '
  • {STORY_TITLE}
  • '; $links_master_internal = '
  • {STORY_TITLE}
  • '; $links_master_external = '
  • {STORY_TITLE}
  • '; if ($runtime["debug"]===1){ $links_master_internal = '
  • {STORY_TITLE}
  • '; } foreach( $news as $article ){ if ($i++>=$limit) continue; if ( isset($article['story_url']) && $article['story_url']!="" ) $links_master = $links_master_external; else { $article['story_url']=''; $links_master = $links_master_internal; } $links[] = str_replace( array('{STORY_ID}','{STORY_TITLE}','{STORY_THUMB}', '{STORY_URL}'), array( $article['story_id'], $article['story_title'], $article['story_thumb'], $article['story_url']), $links_master ); } if ( $radius <= 5){ $headline = 'Nachrichten aus '.$location['in']; } else{ $headline = $location['in'].' und Umgebung'; } $output = str_replace( array( '{HEADLINE}', '{LINKS}'), array( $headline, implode("\n", $links)), $template); if ( $runtime["debug"]===0 ){ $output = preg_replace('//Uis', '', $output); // remove all comments in public html } closeDBConnection(); if ($output) { $cache->set($output); die($output); } else { die($cache->get() ?: ''); } // merge & order this data // generate the output $output = array( 'status' => 'ok', 'content' => $data, ); // $output = json_encode($output, TRUE); $output = json_encode($output, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); header('Access-Control-Allow-Origin: *'); header("Content-type: application/json; charset=utf-8"); print $output; closeDBConnection(); die(); '; // {if $entry.newsflash.regional}{$entry.newsflash.local}{/if} // $page["newsflash"]["regional"]=' https://dev5.netsupport24.net/CN/07_output-client/5.07/apiLatestNewsRadius.CN.php?location=Pirna&radius=5 */ if ( isset($_REQUEST["debug"]) && (int)$_REQUEST["debug"]===1){ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $runtime["debug"]=1; } else{ error_reporting(0); } // define some VARs $fn = 'apiLatestNewsRadius.CN'; $server_group_1 = array( "dev14.netsupport24.net", "beta14.netsupport24.net", "www14.netsupport24.net", "dev15.netsupport24.net", "beta15.netsupport24.net", "www15.netsupport24.net", "dev23.netsupport24.net", "beta23.netsupport24.net", "www23.netsupport24.net", "dev24.netsupport24.net", "beta24.netsupport24.net", "www24.netsupport24.net" ); $server_group_2 = array( "dev5.netsupport24.net", "beta5.netsupport24.net", "www5.netsupport24.net" ); if ( isset($_SERVER['SERVER_NAME']) && in_array($_SERVER['SERVER_NAME'], $server_group_1)){ $version = str_replace( dirname(__DIR__,1).'/', '', __DIR__); $path = array( 'root' => dirname(__DIR__, 2), 'data' => dirname(__DIR__, 5).'/_data/CN', 'cache' => dirname(__DIR__, 5).'/_data/CN/5.19/cache', // /var/www/clients/client4/web3/web/_data/CN/5.19/cache/ 'script' => __DIR__ ); } elseif ( isset($_SERVER['SERVER_NAME']) && in_array($_SERVER['SERVER_NAME'], $server_group_2)){ $path["data"]='/var/customers/webs/webmDSS/netsupport24.net/_data/CN'; // DOCUMENT_ROOT -> /var/customers/webs/webmDSS/netsupport24.net/web-dev/ $path['cache'] = dirname(__DIR__, 5).'/_data/CN/5.19/cache'; // /var/www/clients/client4/web3/web/_data/CN/5.19/cache/ $path["root"]='/var/customers/webs/webmDSS/netsupport24.net/web-dev/CN'; $path["script"]=$path["root"].'/07_output-client/5.09'; } else{ die(""); } $limit=15; // speed: 1000/90sec $time_start = microtime(true); if (!isset($runtime)) $runtime = array(); $global = array( "debug" => TRUE, 'debug_allowed' => array(0,1), "FileNameLength" => 12, "allowed_format" => array("html","json","text", "none"), "format_default" => 'html', "CachePath" => $path['cache'], ); $location = array(); $tags = array(); $tag_ids = array(); $includes = array( $path["data"]."/5.19/config/config_database_external.inc.php", $path["root"]."/00_resources/inq.modules/6.01/global.inc.php", $path["root"]."/00_resources/inq.modules/6.01/array/array.inc.php", $path["root"]."/00_resources/inq.modules/6.01/cache/cache.inc.php", $path["root"]."/00_resources/inq.modules/6.01/database/mysql8.php", $path["root"]."/00_resources/inq.modules/6.01/file/func.file.php", $path["root"]."/00_resources/inq.modules/6.01/json/json.inc.php", ); // DO THE INLUDES foreach($includes as $inc){ if ( $runtime["debug"]===1 ) { // print "\n \$global".var_dump($global); print "\n ... load ".$inc; } if (!include_once($inc)) { print "
    ";
            if ( $runtime["debug"]===1 ) print "\n... load ".$inc;
            die("FATAL ERROR: could not load file: ".$inc);
        }
    }
    
    // correct some VARs
    $global["debug"]=TRUE; //--> overwritte the value from /global.inc.php
    $timestamp=time();
    
    
    notify_add($fn." started -------------------------------");
    
    // manage some incoming VARs
    ( isset($_REQUEST["location"]) && $_REQUEST["location"]!="" ) ? $location['in'] = $_REQUEST["location"] : die("FATAL ERROR: Missing incoming VAR") ;
    ( isset($_REQUEST["radius"]) && $_REQUEST["radius"]!="" && (int)$_REQUEST["radius"]>0 ) ? $radius = (int)$_REQUEST["radius"] : $radius=5;
    ( isset($_REQUEST["limit"]) && $_REQUEST["limit"]!="" && (int)$_REQUEST["limit"]>0 ) ? $limit = (int)$_REQUEST["limit"] : $limit=5;
    ( isset($_REQUEST["debug"]) && (int)$_REQUEST["debug"]===1 && $global["debug"]===TRUE ) ? $runtime["debug"]=1 : $runtime["debug"]=0;
    ( isset($_REQUEST["publisher_id"]) && (int)$_REQUEST["publisher_id"]>1  ) ? $q_add_publisher="AND publisher_id=".(int)$_REQUEST["publisher_id"]." " : $q_add_publisher = "";
    ( isset($_REQUEST["picture"]) && (int)$_REQUEST["picture"]>0  ) ? $q_add_picture=' AND story_thumb<>""': $q_add_picture = '';
    ( isset($_REQUEST["format"]) && in_array($_REQUEST["format"],$global["allowed_format"])  ) ? $runtime["format"]=$_REQUEST["format"] : $runtime["format"]=$global["format_default"];
    
    // Try to return recent cached value
    require_once __DIR__."/classes/InqCache.php";
    $cache = new InqCache();
    $cached = $cache->get(1800);
    if ($runtime['format'] == 'json') {
        if ($cached) {
            echo json_response($cached, 200);
            die();
        }
    } else {
        if ($cached) die($cached);
    }
    
    
        if ($runtime["debug"]===1){ notify_add($fn.' ... started'); }
    
    if ( createDBConnection() ) notify_add("Connected to database");
    else{
        if ( $runtime["debug"]===1){      }
        else{
            // version 2
            header($_SERVER["SERVER_PROTOCOL"]." 503 Service Temporarily Unavailable", true, 503);      //Service Temporarily Unavailable status code to the client.
            $retryAfterSeconds = 240;                                                                   //The number of seconds that the client should wait before retrying.
            header('Retry-After: ' . $retryAfterSeconds);                                               //Send a Retry-After header to the client.
            echo '

    503 Service Temporarily Unavailable

    '; //Send a message to the browser so that the user knows what is going on. echo '

    Our site is currently under maintenance. (db)

    '; exit; //Kill the PHP script. } // die("fatal error"); } // get location (lon/lat) for the given cityname $api_master = "https://api.geo.inquence.com/api/v1/location?q={KEYWORD}&country=DE"; $api_url = str_replace("{KEYWORD}", $location['in'], $api_master ); // $location['details'] = callJSONAPI($api_url,TRUE,84000); $location['details'] = callJSONAPI2($api_url,TRUE,10,2,1,"curl"); if ( $location['details']===FALSE ){ die(""); } if ($runtime["debug"]===1) { $msg = "JSON call to '".$api_url."' finished"; notify_add($fn.$msg); print "\n"; // notify_print(); // closeDBConnection(); // die($fn." die in line 124"); } // $location['details']['data']['lon'] // $location['details']['data']['lat'] if ( !isset($location['details']['data']['lon']) || $location['details']['data']['lon']=="" || !isset( $location['details']['data']['lat'] ) || $location['details']['data']['lat']=="" ){ if ($runtime["debug"]===1){ print "\nlon: ".$location['details']['data']['lon']; print "\nlat: ".$location['details']['data']['lat']."\n"; var_dump($location['details']); } closeDBConnection(); die(""); } // get all tags ids $limit_tags = 500; $query_master = 'SELECT tag_id, ( 3959 * acos ( cos ( radians({LAT}) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians({LON}) ) + sin ( radians({LAT}) ) * sin( radians( lat ) ) ) ) AS distance FROM dug_tags_location HAVING distance < {RADIUS} ORDER BY distance LIMIT 0 , '.$limit_tags.';'; $query = str_replace( array('{LON}','{LAT}','{RADIUS}', '{LIMIT}'), array( $location['details']['data']['lon'], $location['details']['data']['lat'], $radius, $limit_tags ), $query_master ); if ( $runtime["debug"]===1 ) { notify_add($fn.$query); } $tags = executeQuery($query); if ( !isset($tags) || !is_array($tags) || count($tags)<1 ){ closeDBConnection(); die(""); } if ($runtime["debug"]===1) { $msg = "... loaded tags from database"; notify_add($fn . $msg); } // find all articles (max. 5 days) for each tag-id foreach ($tags as $tag){ $tag_ids[] = $tag['tag_id']; } // $tag_time_max = $timestamp-(86400*3); // if ( $q_add_publisher!="" ) $tag_time_max = $timestamp-(86400*30); // $query = 'SELECT * FROM dug_stories_tags WHERE tag_id IN (' . implode(',',$tag_ids) . ') AND tag_time > '.$tag_time_max.' ORDER BY tag_time LIMIT 400;'; $query = 'SELECT * FROM dug_stories_tags WHERE tag_id IN (' . implode(',',$tag_ids) . ') /* ORDER BY tag_time LIMIT 200; */'; if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
    $story_ids = executeQuery($query);
    
    if ($runtime["debug"]===1) {     $msg = "... loaded story_ids from database";     notify_add($fn . $msg); }
    
    
    // load blacklist domains
    $path['config'] = str_replace('/cache', '/config', $path['cache']);
    $runtime['blacklist_source'] = $path['config'].'/LSRblacklist.txt';
    $runtime['blacklist_array'] = file($runtime['blacklist_source'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
    if ( isset($runtime['blacklist_array']) && is_array($runtime['blacklist_array']) && count($runtime['blacklist_array'])>0 ){
        $q_add_lsrdomain = ' AND domain NOT IN ("' . implode('", "', $runtime['blacklist_array']) . '")';
    } else{ $q_add_lsrdomain=''; }
    
    
    
    // load articles details
    $article_ids = array();
    $story_time_max = $timestamp-(86400*10);
    foreach( $story_ids as $story_id){ $article_ids[] = $story_id['story_id']; }
    // $query = 'SELECT * FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ')';
    $query = 'SELECT story_id, story_title, story_time, story_thumb, story_desc FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ') AND story_time>'.$story_time_max.'
    AND processing>79 '.$q_add_lsrdomain . $q_add_picture.' AND story_cat<>100 '.$q_add_publisher.' ORDER BY story_time DESC LIMIT 0,'.$limit;
        if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
    $news = executeQuery($query);
    
    // create a fallback for to less articles
    if ( !isset($news) || !is_array($news) || count($news)<$limit){
        $story_time_max = $timestamp-(86400*60);
        foreach( $story_ids as $story_id){ $article_ids[] = $story_id['story_id']; }
    // $query = 'SELECT * FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ')';
        $query = 'SELECT story_id, story_title, story_time, story_thumb, story_desc FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ') AND story_time>'.$story_time_max.'
    AND processing>79 '.$q_add_picture. $q_add_lsrdomain . ' AND story_cat<>100 '.$q_add_publisher.' ORDER BY story_time DESC LIMIT 0,'.$limit;
        if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
        $news = executeQuery($query);
    }
    
    
    
    // create output
    if ( !isset($news) || !is_array($news) || count($news)<1 ){
        if ( $runtime["format"]==='json' ){ http_response_code(500); closeDBConnection(); die();  }
        closeDBConnection();
        die(''); // no stories found
    }
    
    // deal with data
    $i = -1; $i_max=count($news)-1;
    while ( $i++<$i_max){
        if ( isset($q_add_publisher) && $q_add_publisher!="" ){ // special case "dpa"
            $news[$i]['story_url'] = 'https://www.hier-aktuell.de/artikel/'.$news[$i]['story_id'];
        }
    }
    
    
    
    $links=array(); $i=0;
    if ( $runtime["format"]=='json' ){
        $cache->set($news);
        echo json_response($news, 200);
        closeDBConnection();
        die();
    }
    
    
    // (B) HTML OUTPUT
    $template = file_get_contents('template_LatestNews.html'); // needs {HEADLINE} & {LINKS}
    // $links_master = '
  • {STORY_TITLE}
  • '; $links_master_internal = '
  • {STORY_TITLE}
  • '; $links_master_external = '
  • {STORY_TITLE}
  • '; if ($runtime["debug"]===1){ $links_master_internal = '
  • {STORY_TITLE}
  • '; } foreach( $news as $article ){ if ($i++>=$limit) continue; if ( isset($article['story_url']) && $article['story_url']!="" ) $links_master = $links_master_external; else { $article['story_url']=''; $links_master = $links_master_internal; } $links[] = str_replace( array('{STORY_ID}','{STORY_TITLE}','{STORY_THUMB}', '{STORY_URL}'), array( $article['story_id'], $article['story_title'], $article['story_thumb'], $article['story_url']), $links_master ); } if ( $radius <= 5){ $headline = 'Nachrichten aus '.$location['in']; } else{ $headline = $location['in'].' und Umgebung'; } $output = str_replace( array( '{HEADLINE}', '{LINKS}'), array( $headline, implode("\n", $links)), $template); if ( $runtime["debug"]===0 ){ $output = preg_replace('//Uis', '', $output); // remove all comments in public html } closeDBConnection(); if ($output) { $cache->set($output); die($output); } else { die($cache->get() ?: ''); } // merge & order this data // generate the output $output = array( 'status' => 'ok', 'content' => $data, ); // $output = json_encode($output, TRUE); $output = json_encode($output, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); header('Access-Control-Allow-Origin: *'); header("Content-type: application/json; charset=utf-8"); print $output; closeDBConnection(); die(); '; // {if $entry.newsflash.regional}{$entry.newsflash.regional}{/if} // $page["newsflash"]["national"]='
    '; // {if $entry.newsflash.national}{$entry.newsflash.national}{/if} // $page["newsflash"]["national"]=''; // {if $entry.newsflash.national}{$entry.newsflash.national}{/if} // version 1 - compilation at VARNISH /* $page["newsflash"]["local"]=' https://dev5.netsupport24.net/CN/07_output-client/5.07/apiLatestNewsRadius.CN.php?location=Pirna&radius=5 */ if ( isset($_REQUEST["debug"]) && (int)$_REQUEST["debug"]===1){ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $runtime["debug"]=1; } else{ error_reporting(0); } // define some VARs $fn = 'apiLatestNewsRadius.CN'; $server_group_1 = array( "dev14.netsupport24.net", "beta14.netsupport24.net", "www14.netsupport24.net", "dev15.netsupport24.net", "beta15.netsupport24.net", "www15.netsupport24.net", "dev23.netsupport24.net", "beta23.netsupport24.net", "www23.netsupport24.net", "dev24.netsupport24.net", "beta24.netsupport24.net", "www24.netsupport24.net" ); $server_group_2 = array( "dev5.netsupport24.net", "beta5.netsupport24.net", "www5.netsupport24.net" ); if ( isset($_SERVER['SERVER_NAME']) && in_array($_SERVER['SERVER_NAME'], $server_group_1)){ $version = str_replace( dirname(__DIR__,1).'/', '', __DIR__); $path = array( 'root' => dirname(__DIR__, 2), 'data' => dirname(__DIR__, 5).'/_data/CN', 'cache' => dirname(__DIR__, 5).'/_data/CN/5.19/cache', // /var/www/clients/client4/web3/web/_data/CN/5.19/cache/ 'script' => __DIR__ ); } elseif ( isset($_SERVER['SERVER_NAME']) && in_array($_SERVER['SERVER_NAME'], $server_group_2)){ $path["data"]='/var/customers/webs/webmDSS/netsupport24.net/_data/CN'; // DOCUMENT_ROOT -> /var/customers/webs/webmDSS/netsupport24.net/web-dev/ $path['cache'] = dirname(__DIR__, 5).'/_data/CN/5.19/cache'; // /var/www/clients/client4/web3/web/_data/CN/5.19/cache/ $path["root"]='/var/customers/webs/webmDSS/netsupport24.net/web-dev/CN'; $path["script"]=$path["root"].'/07_output-client/5.09'; } else{ die(""); } $limit=15; // speed: 1000/90sec $time_start = microtime(true); if (!isset($runtime)) $runtime = array(); $global = array( "debug" => TRUE, 'debug_allowed' => array(0,1), "FileNameLength" => 12, "allowed_format" => array("html","json","text", "none"), "format_default" => 'html', "CachePath" => $path['cache'], ); $location = array(); $tags = array(); $tag_ids = array(); $includes = array( $path["data"]."/5.19/config/config_database_external.inc.php", $path["root"]."/00_resources/inq.modules/6.01/global.inc.php", $path["root"]."/00_resources/inq.modules/6.01/array/array.inc.php", $path["root"]."/00_resources/inq.modules/6.01/cache/cache.inc.php", $path["root"]."/00_resources/inq.modules/6.01/database/mysql8.php", $path["root"]."/00_resources/inq.modules/6.01/file/func.file.php", $path["root"]."/00_resources/inq.modules/6.01/json/json.inc.php", ); // DO THE INLUDES foreach($includes as $inc){ if ( $runtime["debug"]===1 ) { // print "\n \$global".var_dump($global); print "\n ... load ".$inc; } if (!include_once($inc)) { print "
    ";
            if ( $runtime["debug"]===1 ) print "\n... load ".$inc;
            die("FATAL ERROR: could not load file: ".$inc);
        }
    }
    
    // correct some VARs
    $global["debug"]=TRUE; //--> overwritte the value from /global.inc.php
    $timestamp=time();
    
    
    notify_add($fn." started -------------------------------");
    
    // manage some incoming VARs
    ( isset($_REQUEST["location"]) && $_REQUEST["location"]!="" ) ? $location['in'] = $_REQUEST["location"] : die("FATAL ERROR: Missing incoming VAR") ;
    ( isset($_REQUEST["radius"]) && $_REQUEST["radius"]!="" && (int)$_REQUEST["radius"]>0 ) ? $radius = (int)$_REQUEST["radius"] : $radius=5;
    ( isset($_REQUEST["limit"]) && $_REQUEST["limit"]!="" && (int)$_REQUEST["limit"]>0 ) ? $limit = (int)$_REQUEST["limit"] : $limit=5;
    ( isset($_REQUEST["debug"]) && (int)$_REQUEST["debug"]===1 && $global["debug"]===TRUE ) ? $runtime["debug"]=1 : $runtime["debug"]=0;
    ( isset($_REQUEST["publisher_id"]) && (int)$_REQUEST["publisher_id"]>1  ) ? $q_add_publisher="AND publisher_id=".(int)$_REQUEST["publisher_id"]." " : $q_add_publisher = "";
    ( isset($_REQUEST["picture"]) && (int)$_REQUEST["picture"]>0  ) ? $q_add_picture=' AND story_thumb<>""': $q_add_picture = '';
    ( isset($_REQUEST["format"]) && in_array($_REQUEST["format"],$global["allowed_format"])  ) ? $runtime["format"]=$_REQUEST["format"] : $runtime["format"]=$global["format_default"];
    
    // Try to return recent cached value
    require_once __DIR__."/classes/InqCache.php";
    $cache = new InqCache();
    $cached = $cache->get(1800);
    if ($runtime['format'] == 'json') {
        if ($cached) {
            echo json_response($cached, 200);
            die();
        }
    } else {
        if ($cached) die($cached);
    }
    
    
        if ($runtime["debug"]===1){ notify_add($fn.' ... started'); }
    
    if ( createDBConnection() ) notify_add("Connected to database");
    else{
        if ( $runtime["debug"]===1){      }
        else{
            // version 2
            header($_SERVER["SERVER_PROTOCOL"]." 503 Service Temporarily Unavailable", true, 503);      //Service Temporarily Unavailable status code to the client.
            $retryAfterSeconds = 240;                                                                   //The number of seconds that the client should wait before retrying.
            header('Retry-After: ' . $retryAfterSeconds);                                               //Send a Retry-After header to the client.
            echo '

    503 Service Temporarily Unavailable

    '; //Send a message to the browser so that the user knows what is going on. echo '

    Our site is currently under maintenance. (db)

    '; exit; //Kill the PHP script. } // die("fatal error"); } // get location (lon/lat) for the given cityname $api_master = "https://api.geo.inquence.com/api/v1/location?q={KEYWORD}&country=DE"; $api_url = str_replace("{KEYWORD}", $location['in'], $api_master ); // $location['details'] = callJSONAPI($api_url,TRUE,84000); $location['details'] = callJSONAPI2($api_url,TRUE,10,2,1,"curl"); if ( $location['details']===FALSE ){ die(""); } if ($runtime["debug"]===1) { $msg = "JSON call to '".$api_url."' finished"; notify_add($fn.$msg); print "\n"; // notify_print(); // closeDBConnection(); // die($fn." die in line 124"); } // $location['details']['data']['lon'] // $location['details']['data']['lat'] if ( !isset($location['details']['data']['lon']) || $location['details']['data']['lon']=="" || !isset( $location['details']['data']['lat'] ) || $location['details']['data']['lat']=="" ){ if ($runtime["debug"]===1){ print "\nlon: ".$location['details']['data']['lon']; print "\nlat: ".$location['details']['data']['lat']."\n"; var_dump($location['details']); } closeDBConnection(); die(""); } // get all tags ids $limit_tags = 500; $query_master = 'SELECT tag_id, ( 3959 * acos ( cos ( radians({LAT}) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians({LON}) ) + sin ( radians({LAT}) ) * sin( radians( lat ) ) ) ) AS distance FROM dug_tags_location HAVING distance < {RADIUS} ORDER BY distance LIMIT 0 , '.$limit_tags.';'; $query = str_replace( array('{LON}','{LAT}','{RADIUS}', '{LIMIT}'), array( $location['details']['data']['lon'], $location['details']['data']['lat'], $radius, $limit_tags ), $query_master ); if ( $runtime["debug"]===1 ) { notify_add($fn.$query); } $tags = executeQuery($query); if ( !isset($tags) || !is_array($tags) || count($tags)<1 ){ closeDBConnection(); die(""); } if ($runtime["debug"]===1) { $msg = "... loaded tags from database"; notify_add($fn . $msg); } // find all articles (max. 5 days) for each tag-id foreach ($tags as $tag){ $tag_ids[] = $tag['tag_id']; } // $tag_time_max = $timestamp-(86400*3); // if ( $q_add_publisher!="" ) $tag_time_max = $timestamp-(86400*30); // $query = 'SELECT * FROM dug_stories_tags WHERE tag_id IN (' . implode(',',$tag_ids) . ') AND tag_time > '.$tag_time_max.' ORDER BY tag_time LIMIT 400;'; $query = 'SELECT * FROM dug_stories_tags WHERE tag_id IN (' . implode(',',$tag_ids) . ') /* ORDER BY tag_time LIMIT 200; */'; if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
    $story_ids = executeQuery($query);
    
    if ($runtime["debug"]===1) {     $msg = "... loaded story_ids from database";     notify_add($fn . $msg); }
    
    
    // load blacklist domains
    $path['config'] = str_replace('/cache', '/config', $path['cache']);
    $runtime['blacklist_source'] = $path['config'].'/LSRblacklist.txt';
    $runtime['blacklist_array'] = file($runtime['blacklist_source'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
    if ( isset($runtime['blacklist_array']) && is_array($runtime['blacklist_array']) && count($runtime['blacklist_array'])>0 ){
        $q_add_lsrdomain = ' AND domain NOT IN ("' . implode('", "', $runtime['blacklist_array']) . '")';
    } else{ $q_add_lsrdomain=''; }
    
    
    
    // load articles details
    $article_ids = array();
    $story_time_max = $timestamp-(86400*10);
    foreach( $story_ids as $story_id){ $article_ids[] = $story_id['story_id']; }
    // $query = 'SELECT * FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ')';
    $query = 'SELECT story_id, story_title, story_time, story_thumb, story_desc FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ') AND story_time>'.$story_time_max.'
    AND processing>79 '.$q_add_lsrdomain . $q_add_picture.' AND story_cat<>100 '.$q_add_publisher.' ORDER BY story_time DESC LIMIT 0,'.$limit;
        if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
    $news = executeQuery($query);
    
    // create a fallback for to less articles
    if ( !isset($news) || !is_array($news) || count($news)<$limit){
        $story_time_max = $timestamp-(86400*60);
        foreach( $story_ids as $story_id){ $article_ids[] = $story_id['story_id']; }
    // $query = 'SELECT * FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ')';
        $query = 'SELECT story_id, story_title, story_time, story_thumb, story_desc FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ') AND story_time>'.$story_time_max.'
    AND processing>79 '.$q_add_picture. $q_add_lsrdomain . ' AND story_cat<>100 '.$q_add_publisher.' ORDER BY story_time DESC LIMIT 0,'.$limit;
        if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
        $news = executeQuery($query);
    }
    
    
    
    // create output
    if ( !isset($news) || !is_array($news) || count($news)<1 ){
        if ( $runtime["format"]==='json' ){ http_response_code(500); closeDBConnection(); die();  }
        closeDBConnection();
        die(''); // no stories found
    }
    
    // deal with data
    $i = -1; $i_max=count($news)-1;
    while ( $i++<$i_max){
        if ( isset($q_add_publisher) && $q_add_publisher!="" ){ // special case "dpa"
            $news[$i]['story_url'] = 'https://www.hier-aktuell.de/artikel/'.$news[$i]['story_id'];
        }
    }
    
    
    
    $links=array(); $i=0;
    if ( $runtime["format"]=='json' ){
        $cache->set($news);
        echo json_response($news, 200);
        closeDBConnection();
        die();
    }
    
    
    // (B) HTML OUTPUT
    $template = file_get_contents('template_LatestNews.html'); // needs {HEADLINE} & {LINKS}
    // $links_master = '
  • {STORY_TITLE}
  • '; $links_master_internal = '
  • {STORY_TITLE}
  • '; $links_master_external = '
  • {STORY_TITLE}
  • '; if ($runtime["debug"]===1){ $links_master_internal = '
  • {STORY_TITLE}
  • '; } foreach( $news as $article ){ if ($i++>=$limit) continue; if ( isset($article['story_url']) && $article['story_url']!="" ) $links_master = $links_master_external; else { $article['story_url']=''; $links_master = $links_master_internal; } $links[] = str_replace( array('{STORY_ID}','{STORY_TITLE}','{STORY_THUMB}', '{STORY_URL}'), array( $article['story_id'], $article['story_title'], $article['story_thumb'], $article['story_url']), $links_master ); } if ( $radius <= 5){ $headline = 'Nachrichten aus '.$location['in']; } else{ $headline = $location['in'].' und Umgebung'; } $output = str_replace( array( '{HEADLINE}', '{LINKS}'), array( $headline, implode("\n", $links)), $template); if ( $runtime["debug"]===0 ){ $output = preg_replace('//Uis', '', $output); // remove all comments in public html } closeDBConnection(); if ($output) { $cache->set($output); die($output); } else { die($cache->get() ?: ''); } // merge & order this data // generate the output $output = array( 'status' => 'ok', 'content' => $data, ); // $output = json_encode($output, TRUE); $output = json_encode($output, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); header('Access-Control-Allow-Origin: *'); header("Content-type: application/json; charset=utf-8"); print $output; closeDBConnection(); die(); '; // {if $entry.newsflash.regional}{$entry.newsflash.local}{/if} $page["newsflash"]["regional"]=' https://dev5.netsupport24.net/CN/07_output-client/5.07/apiLatestNewsRadius.CN.php?location=Pirna&radius=5 */ if ( isset($_REQUEST["debug"]) && (int)$_REQUEST["debug"]===1){ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $runtime["debug"]=1; } else{ error_reporting(0); } // define some VARs $fn = 'apiLatestNewsRadius.CN'; $server_group_1 = array( "dev14.netsupport24.net", "beta14.netsupport24.net", "www14.netsupport24.net", "dev15.netsupport24.net", "beta15.netsupport24.net", "www15.netsupport24.net", "dev23.netsupport24.net", "beta23.netsupport24.net", "www23.netsupport24.net", "dev24.netsupport24.net", "beta24.netsupport24.net", "www24.netsupport24.net" ); $server_group_2 = array( "dev5.netsupport24.net", "beta5.netsupport24.net", "www5.netsupport24.net" ); if ( isset($_SERVER['SERVER_NAME']) && in_array($_SERVER['SERVER_NAME'], $server_group_1)){ $version = str_replace( dirname(__DIR__,1).'/', '', __DIR__); $path = array( 'root' => dirname(__DIR__, 2), 'data' => dirname(__DIR__, 5).'/_data/CN', 'cache' => dirname(__DIR__, 5).'/_data/CN/5.19/cache', // /var/www/clients/client4/web3/web/_data/CN/5.19/cache/ 'script' => __DIR__ ); } elseif ( isset($_SERVER['SERVER_NAME']) && in_array($_SERVER['SERVER_NAME'], $server_group_2)){ $path["data"]='/var/customers/webs/webmDSS/netsupport24.net/_data/CN'; // DOCUMENT_ROOT -> /var/customers/webs/webmDSS/netsupport24.net/web-dev/ $path['cache'] = dirname(__DIR__, 5).'/_data/CN/5.19/cache'; // /var/www/clients/client4/web3/web/_data/CN/5.19/cache/ $path["root"]='/var/customers/webs/webmDSS/netsupport24.net/web-dev/CN'; $path["script"]=$path["root"].'/07_output-client/5.09'; } else{ die(""); } $limit=15; // speed: 1000/90sec $time_start = microtime(true); if (!isset($runtime)) $runtime = array(); $global = array( "debug" => TRUE, 'debug_allowed' => array(0,1), "FileNameLength" => 12, "allowed_format" => array("html","json","text", "none"), "format_default" => 'html', "CachePath" => $path['cache'], ); $location = array(); $tags = array(); $tag_ids = array(); $includes = array( $path["data"]."/5.19/config/config_database_external.inc.php", $path["root"]."/00_resources/inq.modules/6.01/global.inc.php", $path["root"]."/00_resources/inq.modules/6.01/array/array.inc.php", $path["root"]."/00_resources/inq.modules/6.01/cache/cache.inc.php", $path["root"]."/00_resources/inq.modules/6.01/database/mysql8.php", $path["root"]."/00_resources/inq.modules/6.01/file/func.file.php", $path["root"]."/00_resources/inq.modules/6.01/json/json.inc.php", ); // DO THE INLUDES foreach($includes as $inc){ if ( $runtime["debug"]===1 ) { // print "\n \$global".var_dump($global); print "\n ... load ".$inc; } if (!include_once($inc)) { print "
    ";
            if ( $runtime["debug"]===1 ) print "\n... load ".$inc;
            die("FATAL ERROR: could not load file: ".$inc);
        }
    }
    
    // correct some VARs
    $global["debug"]=TRUE; //--> overwritte the value from /global.inc.php
    $timestamp=time();
    
    
    notify_add($fn." started -------------------------------");
    
    // manage some incoming VARs
    ( isset($_REQUEST["location"]) && $_REQUEST["location"]!="" ) ? $location['in'] = $_REQUEST["location"] : die("FATAL ERROR: Missing incoming VAR") ;
    ( isset($_REQUEST["radius"]) && $_REQUEST["radius"]!="" && (int)$_REQUEST["radius"]>0 ) ? $radius = (int)$_REQUEST["radius"] : $radius=5;
    ( isset($_REQUEST["limit"]) && $_REQUEST["limit"]!="" && (int)$_REQUEST["limit"]>0 ) ? $limit = (int)$_REQUEST["limit"] : $limit=5;
    ( isset($_REQUEST["debug"]) && (int)$_REQUEST["debug"]===1 && $global["debug"]===TRUE ) ? $runtime["debug"]=1 : $runtime["debug"]=0;
    ( isset($_REQUEST["publisher_id"]) && (int)$_REQUEST["publisher_id"]>1  ) ? $q_add_publisher="AND publisher_id=".(int)$_REQUEST["publisher_id"]." " : $q_add_publisher = "";
    ( isset($_REQUEST["picture"]) && (int)$_REQUEST["picture"]>0  ) ? $q_add_picture=' AND story_thumb<>""': $q_add_picture = '';
    ( isset($_REQUEST["format"]) && in_array($_REQUEST["format"],$global["allowed_format"])  ) ? $runtime["format"]=$_REQUEST["format"] : $runtime["format"]=$global["format_default"];
    
    // Try to return recent cached value
    require_once __DIR__."/classes/InqCache.php";
    $cache = new InqCache();
    $cached = $cache->get(1800);
    if ($runtime['format'] == 'json') {
        if ($cached) {
            echo json_response($cached, 200);
            die();
        }
    } else {
        if ($cached) die($cached);
    }
    
    
        if ($runtime["debug"]===1){ notify_add($fn.' ... started'); }
    
    if ( createDBConnection() ) notify_add("Connected to database");
    else{
        if ( $runtime["debug"]===1){      }
        else{
            // version 2
            header($_SERVER["SERVER_PROTOCOL"]." 503 Service Temporarily Unavailable", true, 503);      //Service Temporarily Unavailable status code to the client.
            $retryAfterSeconds = 240;                                                                   //The number of seconds that the client should wait before retrying.
            header('Retry-After: ' . $retryAfterSeconds);                                               //Send a Retry-After header to the client.
            echo '

    503 Service Temporarily Unavailable

    '; //Send a message to the browser so that the user knows what is going on. echo '

    Our site is currently under maintenance. (db)

    '; exit; //Kill the PHP script. } // die("fatal error"); } // get location (lon/lat) for the given cityname $api_master = "https://api.geo.inquence.com/api/v1/location?q={KEYWORD}&country=DE"; $api_url = str_replace("{KEYWORD}", $location['in'], $api_master ); // $location['details'] = callJSONAPI($api_url,TRUE,84000); $location['details'] = callJSONAPI2($api_url,TRUE,10,2,1,"curl"); if ( $location['details']===FALSE ){ die(""); } if ($runtime["debug"]===1) { $msg = "JSON call to '".$api_url."' finished"; notify_add($fn.$msg); print "\n"; // notify_print(); // closeDBConnection(); // die($fn." die in line 124"); } // $location['details']['data']['lon'] // $location['details']['data']['lat'] if ( !isset($location['details']['data']['lon']) || $location['details']['data']['lon']=="" || !isset( $location['details']['data']['lat'] ) || $location['details']['data']['lat']=="" ){ if ($runtime["debug"]===1){ print "\nlon: ".$location['details']['data']['lon']; print "\nlat: ".$location['details']['data']['lat']."\n"; var_dump($location['details']); } closeDBConnection(); die(""); } // get all tags ids $limit_tags = 500; $query_master = 'SELECT tag_id, ( 3959 * acos ( cos ( radians({LAT}) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians({LON}) ) + sin ( radians({LAT}) ) * sin( radians( lat ) ) ) ) AS distance FROM dug_tags_location HAVING distance < {RADIUS} ORDER BY distance LIMIT 0 , '.$limit_tags.';'; $query = str_replace( array('{LON}','{LAT}','{RADIUS}', '{LIMIT}'), array( $location['details']['data']['lon'], $location['details']['data']['lat'], $radius, $limit_tags ), $query_master ); if ( $runtime["debug"]===1 ) { notify_add($fn.$query); } $tags = executeQuery($query); if ( !isset($tags) || !is_array($tags) || count($tags)<1 ){ closeDBConnection(); die(""); } if ($runtime["debug"]===1) { $msg = "... loaded tags from database"; notify_add($fn . $msg); } // find all articles (max. 5 days) for each tag-id foreach ($tags as $tag){ $tag_ids[] = $tag['tag_id']; } // $tag_time_max = $timestamp-(86400*3); // if ( $q_add_publisher!="" ) $tag_time_max = $timestamp-(86400*30); // $query = 'SELECT * FROM dug_stories_tags WHERE tag_id IN (' . implode(',',$tag_ids) . ') AND tag_time > '.$tag_time_max.' ORDER BY tag_time LIMIT 400;'; $query = 'SELECT * FROM dug_stories_tags WHERE tag_id IN (' . implode(',',$tag_ids) . ') /* ORDER BY tag_time LIMIT 200; */'; if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
    $story_ids = executeQuery($query);
    
    if ($runtime["debug"]===1) {     $msg = "... loaded story_ids from database";     notify_add($fn . $msg); }
    
    
    // load blacklist domains
    $path['config'] = str_replace('/cache', '/config', $path['cache']);
    $runtime['blacklist_source'] = $path['config'].'/LSRblacklist.txt';
    $runtime['blacklist_array'] = file($runtime['blacklist_source'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
    if ( isset($runtime['blacklist_array']) && is_array($runtime['blacklist_array']) && count($runtime['blacklist_array'])>0 ){
        $q_add_lsrdomain = ' AND domain NOT IN ("' . implode('", "', $runtime['blacklist_array']) . '")';
    } else{ $q_add_lsrdomain=''; }
    
    
    
    // load articles details
    $article_ids = array();
    $story_time_max = $timestamp-(86400*10);
    foreach( $story_ids as $story_id){ $article_ids[] = $story_id['story_id']; }
    // $query = 'SELECT * FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ')';
    $query = 'SELECT story_id, story_title, story_time, story_thumb, story_desc FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ') AND story_time>'.$story_time_max.'
    AND processing>79 '.$q_add_lsrdomain . $q_add_picture.' AND story_cat<>100 '.$q_add_publisher.' ORDER BY story_time DESC LIMIT 0,'.$limit;
        if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
    $news = executeQuery($query);
    
    // create a fallback for to less articles
    if ( !isset($news) || !is_array($news) || count($news)<$limit){
        $story_time_max = $timestamp-(86400*60);
        foreach( $story_ids as $story_id){ $article_ids[] = $story_id['story_id']; }
    // $query = 'SELECT * FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ')';
        $query = 'SELECT story_id, story_title, story_time, story_thumb, story_desc FROM dug_stories WHERE story_id IN (' . implode(',',$article_ids) . ') AND story_time>'.$story_time_max.'
    AND processing>79 '.$q_add_picture. $q_add_lsrdomain . ' AND story_cat<>100 '.$q_add_publisher.' ORDER BY story_time DESC LIMIT 0,'.$limit;
        if ( $runtime["debug"]===1 ) { print "
    \n".$query; }
        $news = executeQuery($query);
    }
    
    
    
    // create output
    if ( !isset($news) || !is_array($news) || count($news)<1 ){
        if ( $runtime["format"]==='json' ){ http_response_code(500); closeDBConnection(); die();  }
        closeDBConnection();
        die(''); // no stories found
    }
    
    // deal with data
    $i = -1; $i_max=count($news)-1;
    while ( $i++<$i_max){
        if ( isset($q_add_publisher) && $q_add_publisher!="" ){ // special case "dpa"
            $news[$i]['story_url'] = 'https://www.hier-aktuell.de/artikel/'.$news[$i]['story_id'];
        }
    }
    
    
    
    $links=array(); $i=0;
    if ( $runtime["format"]=='json' ){
        $cache->set($news);
        echo json_response($news, 200);
        closeDBConnection();
        die();
    }
    
    
    // (B) HTML OUTPUT
    $template = file_get_contents('template_LatestNews.html'); // needs {HEADLINE} & {LINKS}
    // $links_master = '
  • {STORY_TITLE}
  • '; $links_master_internal = '
  • {STORY_TITLE}
  • '; $links_master_external = '
  • {STORY_TITLE}
  • '; if ($runtime["debug"]===1){ $links_master_internal = '
  • {STORY_TITLE}
  • '; } foreach( $news as $article ){ if ($i++>=$limit) continue; if ( isset($article['story_url']) && $article['story_url']!="" ) $links_master = $links_master_external; else { $article['story_url']=''; $links_master = $links_master_internal; } $links[] = str_replace( array('{STORY_ID}','{STORY_TITLE}','{STORY_THUMB}', '{STORY_URL}'), array( $article['story_id'], $article['story_title'], $article['story_thumb'], $article['story_url']), $links_master ); } if ( $radius <= 5){ $headline = 'Nachrichten aus '.$location['in']; } else{ $headline = $location['in'].' und Umgebung'; } $output = str_replace( array( '{HEADLINE}', '{LINKS}'), array( $headline, implode("\n", $links)), $template); if ( $runtime["debug"]===0 ){ $output = preg_replace('//Uis', '', $output); // remove all comments in public html } closeDBConnection(); if ($output) { $cache->set($output); die($output); } else { die($cache->get() ?: ''); } // merge & order this data // generate the output $output = array( 'status' => 'ok', 'content' => $data, ); // $output = json_encode($output, TRUE); $output = json_encode($output, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); header('Access-Control-Allow-Origin: *'); header("Content-type: application/json; charset=utf-8"); print $output; closeDBConnection(); die(); '; // {if $entry.newsflash.regional}{$entry.newsflash.regional}{/if} $page["newsflash"]["national"]='
    '; // {if $entry.newsflash.national}{$entry.newsflash.national}{/if} $page["newsflash"]["national"]=''; // {if $entry.newsflash.national}{$entry.newsflash.national}{/if} */ } // C:\_daten\_htdocs\netsupport24.net\web-dev\CN\08_output-master\5.18\plugin\2_whileSearch\dosearchES.php if (!include('./plugin/2_whileSearch/dosearchES.php')) notify_add("ERRRO: cannot load 'dosearchES'"); dosearchES_run(); if (!include('./plugin/3_afterSearch/addBanner.php')) notify_add("ERRRO: cannot load 'addBanner'"); addBanner_run(); if (!include('./plugin/3_afterSearch/addEventsHome.php')) notify_add("ERRRO: cannot load 'addEventsHome'"); addEventsHome_run(); if (!include('./plugin/3_afterSearch/addDPAPictures.php')) notify_add("ERRRO: cannot load 'addDPApictures'"); //addDPAPictures_run($ResultArray); if (!include('./plugin/3_afterSearch/addDefaultImg.php')) notify_add("ERRRO: cannot load 'addDefaultImg'"); if ( isset($page['stories'] ) ) $page['stories'] = addDefaultImg_run($page['stories']); if ( isset($ResultArray ) ) $ResultArray = addDefaultImg_run($ResultArray); //if ($runtime['debug']===1){print '
    '; var_dump($page['story']); die("dsdsdssdd3"); }
        //if ($runtime['debug']===1){print '
    '; var_dump($page['story']); die("dsdsdssdd3"); }
    if (!include('./plugin/3_afterSearch/addTracker.php')) notify_add("ERRRO: cannot load 'addTracker'");
    addTracker_run($ResultArray);
    
    if (!include('./plugin/3_afterSearch/addComments.php')) notify_add("ERRRO: cannot load 'addComments'");
    addComments_run($ResultArray);
    
    if (!include('./plugin/3_afterSearch/addContent.php')) notify_add("ERRRO: cannot load 'addContent'");
    addContent_run($ResultArray);
    
    
    if (!include('./plugin/3_afterSearch/addAdsense.php')) notify_add("ERRRO: cannot load 'addAdsense'");
    
    
    addAdsense_run($ResultArray);
    if (!include('./plugin/3_afterSearch/sitemapData.php')) notify_add("ERRRO: cannot load 'sitemapData'");
    sitemapData_run($ResultArray);
    if (!include('./plugin/3_afterSearch/addPlacesNearby.php')) notify_add("ERRRO: cannot load 'addPlacesNearby'");
    else addPlacesNearby_run();
    
    
    if ($runtime['debug']===1){
    // if (!include('./plugin/3_afterSearch/addPlacesNearby.php')) notify_add("ERRRO: cannot load 'addPlacesNearby'");
        //addPlacesNearby_run( 20, 5000, 1);
        //print '
    '; var_dump($page['places_nearby']); die();
    }
    
    
    if (@$runtime["displayMode"] == 'start') {
        if (!include('./plugin/3_afterSearch/addShortLocals.php')) notify_add("ERRRO: cannot load 'addShortLocals'");
        addShortLocals_run();
    }
    
    
    if (!include('./plugin/3_afterSearch/addDefaultCategoryImage.php')) notify_add("ERRRO: cannot load 'addDefaultCategoryImage'");
    else addDefaultCategoryImage_run();
    
    
    // if ($runtime['debug']===1) { print "
    "; var_dump($runtime);  var_dump($_GET['page']); /*var_dump(get_defined_vars()); */ notify_print(); die("debug-test:34567");}
    
    // create a fallback in case we have empty result for the local news
    if ( isset($runtime["displayMode"]) && !in_array($runtime["displayMode"], array(/*'Search',*/ 'static') )){
        //include('fallback_empty_local.php');
        include('fallback_empty_similar.php');
        $page = updateCleanArticles_run($page);
    
        notify_add("2");
    
    }
    
    unset($crawler);
    
    
    
    
    if ( $runtime["isProxyBackend"]===0 ){
        if ( isset($page["URL_PARAM"]) && $page["URL_PARAM"]!=""){
            $url = parse_url(substr($page["URL_PARAM"],5));     // url=http://grimma-lokal.de/static/cn_new_crawler_2018-07/css/dark-bottom.css
            $page["STATIC_URL"] = str_replace(
                array("url=http://dresdenlokal.de/static/", "/5.05/"),
                array('url='.$url["scheme"].'://'.$url["host"], '/'.VERSION.'/'),
                $page["STATIC_URL"]
            );
        }
        $page["STATIC_URL"]=FALSE;
        $page["URL_PARAM"] = FALSE;
        // $page["STATIC_URL"] = $page["STATIC_URL"].$url["scheme"].'://'.$url["host"];
    } else {
        if ( isset($_SERVER['HTTP_X_ORIG_HOST']) ){ $ur1 = 'https://'.$_SERVER['HTTP_X_ORIG_HOST'];    }
        else{
            if ( isset($page["URL_PARAM"]) ) $url = substr($page["URL_PARAM"],5);
        }
    
        if ( isset($url) && $url!=""){
            $url = parse_url($url1);
            $page["STATIC_URL"] = $url["scheme"].'://'.$url["host"];
            if ( isset($page["URL_PARAM"]) ) $page["STATIC_URL"] = $page["URL_PARAM"];
        }
        $page["STATIC_URL"]="";
        $page["URL_PARAM"] = FALSE;
    
    }
    
    // $page["URL_PARAM"] = FALSE;
    if ( !isset($page['companyLink'])) $page['companyLink']=''.$page['job']['companyName'].'';
    $page["job"]["slogan"] = str_replace( array("{CITY}"), array($page['job']['city']), $page['job']['slogan']);
    
    // set some value to "", since they are (may) used at the templates
    $min_key_page = array("category", "newsflash", "is_details_page", "URL_PARAM", "search_word", "template_debug", "is_details_page", "addLocalTitleCircle","page", "ad", "template_debug"  /*, , "loc_details", */ );
    foreach ($min_key_page as $mkp){
        if (!isset($page[$mkp])) $page[$mkp]="";
    }
    $page['displayMode'] = $runtime['displayMode'];
    
    //unset($page['similar']);
    
    
    
    if (!include('./plugin/3_afterSearch/addPinnedLocalContent.php')) notify_add("ERRRO: cannot load 'addPinnedLocalContent_run'");
    $ResultArray = addPinnedLocalContent_run($ResultArray);
    if (!include('./plugin/3_afterSearch/removeLSRContent.php')) notify_add("ERROR: cannot load 'removeLSRContent.php'");
    $ResultArray = removeLSRContent_run($ResultArray);   // remove all relative links from $output
    if (!include('./plugin/3_afterSearch/addTags.03.php')) notify_add("ERRRO: cannot load 'addTags'");
    addTags_run($ResultArray);
    if (!include('./plugin/3_afterSearch/update_ArticleDetail.php')) notify_add("ERRRO: cannot load 'update_ArticleDetail'");
    update_ArticleDetail_run($ResultArray);
    
    //if ($runtime['debug']===1){  print "
    ";    var_dump($page['similar']);die($fn."die insearch, line 356"); }
    
    
    if ( $runtime['debug']===1) {
        // This is a fallback function to clear the cache for developing, since smarty does have a strange behaviour.
        $temp_smarty_cache_path = $global["CachePath"] . '/templates_c';
        $exec = 'rm -r '.$temp_smarty_cache_path.'/*';
        exec($exec, $temp_smarty_delete_output);
            notify_add($fn . ' Deleted files from smarty-cache folder (' . $temp_smarty_cache_path . '): ');
            notify_add($temp_smarty_delete_output);
        unset($temp_smarty_cache_path, $exec, $temp_smarty_delete_output);
    
        $smarty->compile_check = true;
            notify_add($fn.'SMARTY --> compile_check');
        # Cleanup Smarty's compiled pages.
        //die("--1..");
        //$smarty->clear_compiled_tpl();
        //die("--2..");
        $smarty->force_compile = true;
            notify_add($fn.'SMARTY --> force_compile');
        //die("--3..");
    
    }
    
    
    if ( isset($_GET['var-dump']) && (int)$_GET['var-dump']>0 ){
        header("Content-Type: text/plain");
        echo "======== \$entity =============\n";
        print "search2.php, line 397\n";
        var_dump($page);
    
    
        echo "======== \$_SERVER =============\n";
        print "search2.php, line 402\n";
        var_dump($_SERVER);
        print "search2.php, line 404\n";
        echo "======== \$_GET =============\n";
        print "search2.php, line 406\n";
        var_dump($_GET);
        print "search2.php, line 408\n";
        echo "======== \$runtime ===========\n";
        var_dump($runtime);
        print "search2.php, line 411\n";
        echo "======== \$ResultArray ===========\n";
        var_dump($ResultArray);
        die($fn.'489');
    }
    
    
    
    /*
    if ($runtime['debug']===1){
        print '
    '; var_dump($runtime);
        die();
    } */
    
    $smarty->assign('entry', $page);
        notify_add($fn.'SMARTY --> assign VAR page to template');
    if ( isset($runtime['cache']) && ( $runtime['cache']===0 || $runtime['cache']===2 )){
        $smarty->setCacheLifetime(5);
            notify_add($fn."SMARTY --> set smarty->setCacheLifetime(5)");
        $smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
            notify_add($fn."SMARTY --> set smarty->setCaching");
        // notify_add($fn."SMARTY --> set smarty->clearAllCache");
    }
    if ( $runtime['debug']===1){
        $smarty->setCacheLifetime(0);
        /* TODO: $smarty->clearAllCache(); is very slow */
        // $smarty->clearAllCache(); // --> this is terrible slow (8sec or so)
        $smarty->setCaching(0);
    
    }
    
    
    // fill the job-array with need information for template
    $page['job']['template_details']['template_dir'] = $path['data'].'/template/page/'.$page['job']['template_details']['folder'] ?: "cn_new_crawler";
    $page['job']['template_details']['template_fullpath'] = $page['job']['template_details']['template_dir'].'/'.$page["job"]["template_details"]["templateName"]."HTML.tmpl";
    
    
    if ($runtime['debug']===1) {
        // $template_dir = $page['job']['template_details']['folder'] ?: "cn_new_crawler";
        notify_add("template: (global template path) " . $global["TemplatePath"] . " (size: " . (int)strlen(file_get_contents($page['job']['template_details']['template_fullpath']))/1000 . "kB)");
        //notify_add("template: (runtime template path) ". $runtime["TemplatePath"]);
        notify_add("template: " . $page['job']['template_details']['template_fullpath']);
        // $output = $smarty->fetch("page/$template_dir/".$page["job"]["template_details"]["templateName"]."HTML.tmpl");
    }
    
    
    if ( !isset($page['job']['template_details']['template_fullpath']) || $page['job']['template_details']['template_fullpath']=="" ){
        header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
        die("FATAL ERROR: No template defined.");
    }
    $output = $smarty->fetch( $page['job']['template_details']['template_fullpath'] );
        if ($runtime['debug']===1) {    notify_add('template: loaded (1)'); }
    if ( strlen($output)<1 && $runtime['debug']<1 ) {
        header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
        die("FATAL ERROR: Couldn´t load template.");
    }
        if ($runtime['debug']===1) {    notify_add('template: loaded'); }
    // some last minute frontend-mode-corrections
        if ( $runtime["isProxyBackend"]===0 ) {
            // FRONTEND
            if ($runtime['debug']===1) {    notify_add($fn.'load frontendUsage.php'); }
            if (!include('./plugin/3_afterSearch/frontendUsage.php')) notify_add("ERROR: cannot load 'frontendUsage'");
            if ($runtime['debug']===1) {    notify_add($fn.'end frontendUsage.php'); }
        } else{
            // BACKEND (default)
            if ($runtime['debug']===1) {    notify_add($fn.'start  backendUsage'); }
            $output = str_replace("http://api.thumbsniper.com/api_free.php?size=4&effect=1&url=", "https://aprc.it/api/320x240/", $output);
            $output = str_replace("http://", "https://", $output);
            $output = str_replace('src="&url=', 'src="', $output);
            $output = preg_replace('//Uis', '', $output); // remove all comments in public html
            // $output = str_replace( array("  ", "\n"), array(""), $output); // remove blanks and linebreak
                                                                              // possible problem with lazy-load?
            if ($runtime['debug']===1) {    notify_add($fn.'end  backendUsage'); }
        }
    
    
    
    if (!include('./plugin/3_afterSearch/removeUnwantedLinks.php')) notify_add("ERRRO: cannot load 'removeUnwantedLinks_run'");
    $output = removeUnwantedLinks_run($output);
    if (!include('./plugin/3_afterSearch/update_removeRelativeLinks.php')) notify_add("ERROR: cannot load 'update_removeRelativeLinks'");
    $ResultArray = update_removeRelativeLinks($ResultArray);   // remove all relative links from $output
    
    
    
    if ($runtime['debug']===1){
        switch ($runtime["format"]){
            case "json":
                print "here would follow a json output";
                break;
            case "none":
                print "no content is printed (format=none)";
                break;
            default:
                print $output;
                break;
        }
    
    }
    else{
        print $output;
    }
    
    notify_add( strlen($output).' kB for output');
    
    if ( isset($runtime["cache_id"]) ){
        cacheWrite($runtime["cache_id"], $output);
        notify_add($fn."write to cache OK");
    } else{
        notify_add($fn."CACHE not written! (Missing cache_id?)");
    }
    
    // save this session
    notify_add("search with ".count($ResultArray)." results finished :-)");
    notify_print();
    if (isset($global["LogFile"]) ) notify_write($global["LogFile"]);
    
    //$dbconnection->close();
    //closeDBConnection();