Exemplo n.º 1
0
define('PRODUCTION_DIR', 'settoriali');
define('START_REP', '<!-- #REPETITIVE_PART_START# -->');
define('END_REP', '<!-- #REPETITIVE_PART_END# -->');
define('DESCR_MAX_LENGTH', 300);
define('LOGO_STORE', "http://adv.networkagenti.it/images/idem/007351/");
define('LOGO_DEFAULT', "attesalogo.jpg");
define('SINGLE_SECTOR_TEMPLATE', '<a href="#SECTOR_URL#" style="text-decoration:underline; color:#0000FF;font-size: 11pt; font-family: Arial, sans-serif; font-style: normal; font-weight: normal;" target="_blank" title="vedi le aziende del settore #SECTOR_TEXT#">#SECTOR_TEXT#</a>');
$dbConfig = ['dsn' => 'mysql:host=localhost;dbname=forum_agenti;charset=utf8', 'userName' => 'readonly', 'pswd' => 'D7ehjC9WydUdmHeY', 'tableName' => 'companies'];
$replacements = ['macro_settore' => '#PLACEHOLDER1#', 'thumb' => '#PLACEHOLDER2#', 'company' => '#PLACEHOLDER3#', 'companydescr' => '#PLACEHOLDER4#'];
$reader = new DBReader($dbConfig);
// info about company without sectors (only macrosectors)
$data = $reader->retreiveFields($dbConfig['tableName'], array_keys($replacements));
unset($reader);
$reader = new DBReader($dbConfig);
// info about company only with sectors and corresponding adv links
$sectorsData = $reader->retreiveFields($dbConfig['tableName'], ['company', 'settori', 'adv_link']);
unset($reader);
// elaborate retreived data:
// 1. eliminate tags;
// 2. shorten description
// 3. if the logo does not exist, use default one
$dataLen = count($data);
$descrKey = 'companydescr';
$logoKey = 'thumb';
// stores the result of controls whether an url corresponds to a resource that exists
// It serves to avoid multiple requests to the same url
$urlExists = [];
$parser0 = new DataParser();
for ($i = 0; $i < $dataLen; $i++) {
    $text = strip_tags($data[$i][$descrKey]);
    if (strlen($text) > DESCR_MAX_LENGTH) {