Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(@txpinterface == 'admin') {
- add_privs('gva_sammelpost','1,2');
- register_tab('extensions', 'gva_sammelpost', "Sammelpost");
- register_callback('gva_sammelpost_page', 'gva_sammelpost');
- global $gva_sammelpost;
- }
- // Prepare tweets and auto-detect hyperlinks, hashtags and usernames
- function preparetweet($ret) {
- $ret = preg_replace_callback('#(?<=[\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#$%&~/\-=?@\[\](+]|[.,;:](?![\s<])|(?(1)\)(?![\s<])|\)))+)#is', 'clickable_url', $ret);
- $ret = preg_replace_callback('|(#[a-zA-Z0-9_äöüÄÖÜß]*)|is', 'clickable_hashtag', $ret);
- $ret = preg_replace_callback('|(@[a-zA-Z0-9_äöüÄÖÜß]*)|is', 'clickable_username', $ret);
- return trim($ret);
- }
- function clickable_hashtag($matches) {
- $origin = trim($matches[0]);
- return '<a target="_blank" class="hashtag" href="http://search.twitter.com/search?q=&tag='.substr($origin, 1).'">'.$origin.'</a>';
- }
- function clickable_username($matches) {
- $origin = trim($matches[0]);
- return '<a target="_blank" class="username" href="http://twitter.com/'.substr($origin, 1).'">'.$origin.'</a>';
- }
- function clickable_url($matches) {
- $url = $matches[2];
- if ( empty($url) )
- return $matches[0];
- return $matches[1] . "<a class='link' href=\"$url\">$url</a>";
- }
- // Turn date to relative string
- function reldate($input, $now = false) {
- if (!$now) { $now = time(); }
- $diff = $now - $input;
- if ($diff < 3600) {
- $value = floor($diff / 60);
- $unit = "Minute";
- $unit2 = "Minuten";
- } elseif ($diff < 86400) {
- $value = floor($diff / 3600);
- $unit = "Stunde";
- $unit2 = "Stunden";
- } else {
- $value = floor($diff / 86400);
- $unit = "Tag";
- $unit2 = "Tagen";
- }
- if ($value == 1) {
- return "vor ".$value." ".$unit;
- } else {
- return "vor ".$value." ".$unit2;
- }
- }
- function gva_sammelpost() {
- global $prefs;
- $thismonday = getmonday(time());
- $lastmonday = getmonday(time()-604800);
- if ($thismonday > $prefs['gva_last_monday']) {
- safe_update("txp_prefs", "val = '".$thismonday."'", "name = 'gva_last_monday' and prefs_id = 1" );
- if ($postdata = build_sammelpost($thismonday, $lastmonday)) {
- extract($postdata);
- safe_insert("textpattern",
- "Title = '$title',
- Body = '$text',
- Body_html = '$text',
- Status = '4',
- Posted = '$posted',
- LastMod = '$posted',
- AuthorID = 'Turbo-G',
- Section = 'weblog',
- Category1 = 'sammelpost',
- textile_body = '$text',
- url_title = '$urltitle',
- Annotate = '1',
- AnnotateInvite = 'Kommentare',
- uid = '".md5(uniqid(rand(),true))."',
- feed_time = '$posted'");
- }
- }
- return '<!-- Sammelpost wurde ausgefuehrt -->';
- }
- function build_sammelpost($thismonday, $lastmonday) {
- global $prefs;
- require_once ($prefs['file_base_path'].'/simplepie.inc');
- $feed = new SimplePie("http://pipes.yahoo.com/pipes/pipe.run?_id=4415799d9a31a393138dcbc5a197ff2e&_render=rss", $prefs['file_base_path'].'/cache/',60);
- $feed->handle_content_type();
- $posttext = "";
- foreach ($feed->get_items() as $item) {
- $itemtime = strtotime($item->get_date());
- if ($itemtime >= $lastmonday && $itemtime < $thismonday) {
- // twitterkram
- if (substr($item->get_permalink(),0,18) == "http://twitter.com") {
- $posttext .= '<li>'.preparetweet($item->get_title()).'<br>(<a href="'.$item->get_permalink().'">'.reldate(strtotime($item->get_date()))."</a>)</li>\n";
- // non-twitterkram
- } else {
- $posttext .= '<li><a href="'.$item->get_permalink().'">'.$item->get_title()."</a><br />\n";
- if ($item->get_description() != $item->get_title()) {
- $summary = substr(strip_tags($item->get_description()), 0, 140);
- if ($summary != $item->get_description()) {
- $posttext .= $summary."…</li>\n";
- } else {
- $posttext .= $summary."</li>\n";
- }
- }
- }
- }
- }
- $postdata = array();
- if (!empty($posttext)) {
- $posttext = '<p>Netzfundstücke vom '.date("d.m.", $lastmonday).' bis zum '.date("d.m.", $thismonday).':</p><ul class="sammelpost">'.$posttext."</ul>";
- $postdata['title'] = 'Wochenlinks';
- $postdata['posted'] = date("Y-m-d H:i:s", $thismonday+(60*60));
- $postdata['urltitle'] = 'wochenlinks-'.date("Y-m-d", $thismonday);
- $postdata['text'] = str_replace("'", "\'", $posttext);
- return $postdata;
- } else {
- return false;
- }
- }
- function gva_sammelpost_page() {
- global $step;
- require_privs('gva_sammelpost');
- pagetop('Sammelpost');
- var_dump(build_sammelpost(getmonday(time()+500000), getmonday(time()-604800)));
- }
- function getmonday($timestamp) {
- $dayoffset = (int) date('w', $timestamp) - 1;
- if ($dayoffset == -1) $dayoffset = 6; // Sonntag ist 0, ganz doof
- $houroffset = (int) date('H', $timestamp);
- $minoffset = (int) date('i', $timestamp);
- $secoffset = (int) date('s', $timestamp);
- return ($timestamp - ($dayoffset*24*60*60) - ($houroffset*60*60) - ($minoffset*60) - $secoffset);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement