123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
- define("HOSTNAME", "ceata.org");
- define("JOURNAL", "blog");
- define("EVENTS", "events");
- define("EVENTS2", "events2");
- define("NEWS", "news");
- $events2 = FALSE;
- error_reporting(-1);
- ini_set('display_errors', '1');
- // Define the path to the site root directory.
- $site_path = "./";
- require_once 'read-feed.php';
- // Update home page.
- update_home_page();
- function update_home_page()
- {
- global $site_path;
- // Read header template content.
- $template_content = read_template($site_path."templates/header.ro.tpl");
- // Read templates content.
- $template_content .= read_template($site_path."templates/index.ro.tpl");
- // Read the footer template content.
- $template_content .= read_template($site_path."templates/footer.ro.tpl");
- // Update the the site title.
- $template_content = str_replace("<!-- site-title -->", "Fundația Ceata — Ceata eliberează artele și tehnologiile actuale", $template_content);
- // Get Ceata events block content.
- $block_content = feed_list("events.ro.rss", 5, EVENTS, TRUE);
- // Verify if block content variable is not empty.
- if (!empty($block_content))
- {
- $events2 = FALSE;
- $pre = '<div id="events">';
- $pre .= '<a href="/events.ro.rss" class="flux"><img src="/files/images/feed.png" /></a>';
- $pre .= '<h2 class="block-title"><a href="/events.ro.html">Evenimente</a></h2>';
-
- $post = '<p class="toate">';
- $post .= '<a href="/events.ro.html">Vezi și evenimentele trecute >></a>';
- $post .= '</p></div>';
- $block_content = $pre.$block_content.$post;
- // Update journals block content.
- $template_content = str_replace(
- "<!-- Evenimente -->", $block_content, $template_content
- );
- }
- else
- $events2 = TRUE;
- // Get Ceata journals block content.
- $block_content = feed_list("blog.rss", 5, JOURNAL);
- // Verify if block content variable is not empty.
- if (!empty($block_content))
- {
- // Update journals block content.
- $template_content = str_replace(
- "<!-- Jurnal -->", $block_content, $template_content
- );
- }
- if ($events2)
- {
- // Get Ceata events block content.
- $block_content = feed_list("events.ro.rss", 5, EVENTS2);
- // Verify if block content variable is not empty.
- if (!empty($block_content))
- {
- $pre = '<div id="events">';
- $pre .= '<a href="/events.ro.rss" class="flux"><img src="/files/images/feed.png" /></a>';
- $pre .= '<h2 class="block-title"><a href="/events.ro.html">Evenimente</a></h2>';
-
- $post = '<p class="toate">';
- $post .= '<a href="/events.ro.html">Vezi toate evenimentele >></a>';
- $post .= '</p></div>';
- $block_content = $pre.$block_content.$post;
- // Update journals block content.
- $template_content = str_replace(
- "<!-- Evenimente2 -->", $block_content, $template_content
- );
- }
- }
- // Get Ceata news block content.
- $block_content = feed_list("news.ro.rss", 5);
- // Verify if block content variable is not empty.
- if (!empty($block_content))
- {
- // Update journals block content.
- $template_content = str_replace(
- "<!-- News -->", $block_content, $template_content
- );
- }
- // Create or update the home page.
- create_page($site_path."index.ro.html", $template_content);
- }
- function feed_list($feed_url, $number, $type=NEWS, $reverse=FALSE)
- {
- $feed_list = '';
- // Get Ceata journals feeds.
- $feeds = get_feed($feed_url);
- $feedset = array();
- foreach($feeds as $key => $feed)
- {
- if ($key > $number-1) break;
- if ($type == EVENTS && (strtotime($feed['date']) < (strtotime("now") - 24*3600)))
- break;
- array_push($feedset, $feed);
- }
- if ($reverse)
- $feedset = array_reverse($feedset, TRUE);
-
- if (!empty($feedset))
- {
- foreach($feedset as $key => $feed)
- {
- $description = $feed['description'];
- $append = '<a href="'.$feed['link'].'" target="_blank">[...]</a>';
- if ($type == JOURNAL)
- $description = truncate_text($feed['description'], 255, $append);
- $feed_list .= '<li>';
- if ($type == JOURNAL)
- $feed_list .= '<a href="'.$feed['link'].'" target="_blank" class="titlu">';
- else
- {
- $link = str_replace("http://".HOSTNAME."/", "", $feed['link']);
- $feed_list .= '<a href="/'.$link.'" class="titlu">';
- }
- $title = $feed['title'];
- if ($type == JOURNAL)
- {
- $pos = strpos($feed['title'], ":");
- $author = substr($feed['title'], 0, $pos);
- $title = substr($feed['title'], $pos+1);
- }
- $feed_list .= $title.'</a>';
- if ($type == JOURNAL)
- $feed_list .= '<br /><i>de '.$author.'</i>';
- // $feed_list .= '<span class="data">'.$feed['date'].'</span>';
- $feed_list .= '<div class="rezumat"><p>'.$description.'</p></div></li>';
- }
- if ($type == EVENTS && empty($feed_list))
- return $feed_list;
- $feed_list = '<ul class="listă-simplă">'.$feed_list.'</ul>';
- }
- return $feed_list;
- }
- /**
- * Read template function.
- *
- * Reads the content of a page template.
- *
- * @param $template_file
- * A string, template file name.
- */
- function read_template($template_file)
- {
- // Get template content.
- $template_content = file_get_contents($template_file);
- return $template_content;
- }
- /**
- * Create page function.
- *
- * Creates or update a HTML page.
- *
- * @param $page_name
- * A string, page file name.
- *
- * @param $content
- * A string, page content.
- */
- function create_page($page_name, $content)
- {
- // Open file for writing.
- $file = fopen($page_name,"w");
- // Write content to file.
- fwrite($file, $content);
- fclose($file);
- }
- /**
- * Truncate text function.
- *
- * Truncates a text.
- *
- * @param $text
- * Text to be truncated.
- * @param $max_text_length
- * The length of truncated text.
- * @param $append
- * String to append to the end of truncated text (such as '...').
- * @param $strip
- * Strip tags or not.
- *
- * @return
- * Truncated text or an empty string.
- */
- function truncate_text($text, $text_length, $append = "", $strip = TRUE)
- {
- // Verify text.
- if ( empty($text) ) return '';
- // Verify wether to strip tags.
- if ($strip)
- {
- // Strip tags.
- $text = strip_tags($text);
- }
- if (strlen($text) > $text_length)
- {
- $text_length += strpos(substr($text, $text_length), ".");
- $text = utf8_encode($text);
- // Get the the substring of legn $text_length.
- $text = mb_substr($text, 0, $text_length, "UTF-8");
- $text = utf8_decode($text).'.';
- // Add $append string.
- $text .= " ".$append;
- }
- return $text;
- }
- ?>
|