add('name', PLUGIN_DISQUS_TITLE); $propbag->add('description', PLUGIN_DISQUS_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Garvin Hicking, Grischa Brockhaus'); $propbag->add('requirements', array( 'serendipity' => '0.7', 'smarty' => '2.6.7', 'php' => '4.1.0' )); $propbag->add('version', '0.4'); $propbag->add('groups', array('FRONTEND_VIEWS')); $propbag->add('event_hooks', array( 'frontend_display:html:per_entry' => true, 'entries_footer' => true, 'entry_display' => true )); $propbag->add('configuration', array('shortname', 'enable_since','template_hide_css','footer_comment_link')); $propbag->add('legal', array( 'services' => array( 'disqus' => array( 'url' => 'https://www.disqus.com', 'desc' => 'Embeds a javascript widget from disqus to display comment badges, which allows Disqus to receive visitor metadata (IP, browser, referrer).' ), ), 'frontend' => array( 'Embeds a javascript widget from disqus to display comment badges, which allows Disqus to receive visitor metadata (IP, browser, referrer).', 'Comments will be stored in Disqus and are subject to their terms; all comment data will be handled on disqus servers.' ), 'backend' => array( ), 'cookies' => array( ), 'stores_user_input' => false, 'stores_ip' => false, 'uses_ip' => true, 'transmits_user_input' => true )); } function introspect_config_item($name, &$propbag) { global $serendipity; switch($name) { case 'enable_since': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DISQUS_ENABLE_SINCE); $propbag->add('description', PLUGIN_DISQUS_ENABLE_SINCE_DESC); $propbag->add('default', date('Y-m-d')); break; case 'shortname': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DISQUS_SHORTNAME); $propbag->add('description', PLUGIN_DISQUS_SHORTNAME_DESC); $propbag->add('default', ''); break; case 'template_hide_css': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_DISQUS_HIDE_COMMENTCSS); $propbag->add('description', PLUGIN_DISQUS_HIDE_COMMENTCSS_DESC); $propbag->add('default', 'serendipity_section_comments,serendipity_section_commentform'); break; case 'footer_comment_link': $propbag->add('type', 'boolean'); $propbag->add('name', PLUGIN_DISQUS_FOOTERCOMMENTLINK); $propbag->add('description', PLUGIN_DISQUS_FOOTERCOMMENTLINK_DESC); $propbag->add('default', 'false'); break; } return true; } function generate_content(&$title) { $title = PLUGIN_DISQUS_TITLE; } function example() { return nl2br(PLUGIN_DISQUS_DESC2); } function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { switch($event) { case 'entries_footer': $putFooterLink = $this->get_config('footer_comment_link', false); // If we don't have a DISQUSfied footer, the JS is of no sense. if (!$putFooterLink) return true; ?> get_config('enable_since')); $ts = mktime(0, 0, 0, $_ts[1], $_ts[2], $_ts[0]); if ($eventData['timestamp'] < $ts) { return true; } $putFooterLink = $this->get_config('footer_comment_link', false); $eventData['has_disqus'] = true; // This is problematic, because some templates (like 2k11) expect text only here! if ($putFooterLink) { $eventData['comments'] = 'DISQUS'; } else { $eventData['comments'] = COMMENTS; } return true; case 'entry_display': $singleArticle = $addData['extended']; if (!$singleArticle) return true; $_ts = explode('-', $this->get_config('enable_since')); $ts = mktime(0, 0, 0, $_ts[1], $_ts[2], $_ts[0]); if (isset($eventData) && is_array($eventData)) { foreach($eventData as $event) { if ($event['timestamp'] < $ts) { continue; } $i = 0; $disqus = $this->produce_disqus_output($event); $event[$i]['display_dat'] .= $disqus; $eventData[$i]['disqus'] .= $disqus; $eventData[$i]['has_disqus'] = true; $eventData[$i]['commentform'] = true; $eventData[$i]['add_footer'] .= $disqus; $i++; } } return true; default: return false; } } else { return false; } } function produce_disqus_output(&$eventData) { $hidecss = $this->get_config('template_hide_css','serendipity_section_comments,serendipity_section_commentform'); if (empty($hidecss)) return ''; $csslist = explode(',', $hidecss); $hide = ''; $count = count($csslist); $index = 0; foreach ($csslist as $css) { $hide .= '.' . $css; $index ++; if ($index<$count) $hide .= ','; } return '
'; } function generate_article_url( $entry ) { global $serendipity; $urlparts = @parse_url($serendipity['baseURL']); $server = $urlparts['scheme'] . '://' . $urlparts['host']; if (!empty($urlparts['port'])) $server = $server . ':' . $urlparts['port']; $relurl = serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp'])); return $server . $relurl; } }