Thread: Miscellaneous Hacks - tDigg - Digg like system for threads
View Single Post
  #135  
Old 08-05-2008, 01:45 AM
derekivey derekivey is offline
 
Join Date: Apr 2005
Location: Pennsylvania, USA
Posts: 1,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello,

To fix the security token problem, use this modified code for the tDigg - Template Edits plugin:

PHP Code:
if ($vbulletin->options['tDigg_enabled']) {
            
$vbulletin->templatecache['SHOWTHREAD'] = preg_replace('#</head>#i''
            ".((!in_array($forum[forumid], explode(",", "' 
$vbulletin->options['tDigg_forums'] . '", -1))) ? ("") : ("
            <script type=\"text/javascript\" language=\"javascript\">
   var tdigg_request = false;
   var threadnum = null;
   function maketdiggRequest(url, parameters) {
      tdigg_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         tdigg_request = new XMLHttpRequest();
         if (tdigg_request.overrideMimeType) {
             // set type accordingly to anticipated content type
            //tdigg_request.overrideMimeType(\'text/xml\');
            tdigg_request.overrideMimeType(\'text/html\');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            tdigg_request = new ActiveXObject(\"Msxml2.XMLHTTP\");
         } catch (e) {
            try {
               tdigg_request = new ActiveXObject(\"Microsoft.XMLHTTP\");
            } catch (e) {}
         }
      }
      if (!tdigg_request) {
         alert(\'Cannot create XMLHTTP instance\');
         return false;
      }
      
      tdigg_request.onreadystatechange = alerttdiggContents;
      tdigg_request.open(\'POST\', url, true);
      tdigg_request.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded\");
      tdigg_request.setRequestHeader(\"Content-length\", parameters.length);
      tdigg_request.setRequestHeader(\"Connection\", \"close\");
      tdigg_request.send(parameters);
   }

   function alerttdiggContents() { 
      if (tdigg_request.readyState == 4) {
         if (tdigg_request.status == 200) {
            document.getElementById(\'votecount_\' + threadnum).innerHTML = tdigg_request.responseText;
         } else {
            alert(\'There was a problem with the request.\');
         }
      }
   }
   
function vote(ID,type) {
    var threadid = document.getElementById(\'qr_threadid\').value;
    threadnum = ID;
    if (type == \'give\'){
            var poststr = \"threadid=\" + encodeURI( threadid ) +
            \"&action=give&securitytoken=\" + SECURITYTOKEN;
            document.getElementById(\'votecount_\' + ID).innerHTML = \'<img src=\"$stylevar[imgdir_misc]/13x13progress.gif\">\';
            maketdiggRequest( \'ajax.php?do=tdigg\', poststr);
    } else if (type == \'take\') {
            var poststr = \"threadid=\" + encodeURI( threadid ) +
            \"&action=take&securitytoken=\" + SECURITYTOKEN;
            document.getElementById(\'votecount_\' + ID).innerHTML = \'<img src=\"$stylevar[imgdir_misc]/13x13progress.gif\">\';
            maketdiggRequest( \'ajax.php?do=tdigg\', poststr);
    }
}
</script>
<style type=\"text/css\"> <!--
.topicv {
    position:relative;
    height: 18px;
}
.countbg {    
    position:relative;
    top: -5px;
    text-align: center;
    color: #000000;
    font-weight:bold
}
.news-tDigg {
    position: relative;
    top: 0.8em;
    text-align: center;
    font-size: 85%;
    margin: 0;
    padding: 0;
    list-style: none;
    background: url($stylevar[imgdir_misc]/t-shade.gif) no-repeat;
}
.news-tDigg li {
    margin: 0;
    padding: 0;
}
.tDigg-count a , .tDigg-count span, .tDigg-count-s a, .tDigg-count-s span {
    display: block;
    position: relative;
    padding: 6px 0 4px 0;
    text-decoration: none;
    width: 50px;
    min-height: 20px;
    color: #93883F;
    text-align: center;
    font: 13px arial, sans-serif;
}
.news-summary .tDigg-count strong, .news-full .tDigg-count strong, .news-summary .tDigg-count-s strong, .news-full .tDigg-count-s strong {
    font-size: 160%;
    font-weight: normal;
    letter-spacing: -1px;
    line-height: 1;
    display: block;
    position: relative;
    color: #736926;
}
.news-summary .tDigg-count-s strong, .news-full .tDigg-count-s strong {
    font-size: 160%;
}
.tDigg-count img, .tDigg-count-s img {
    position: relative;
    top: 0;
    left: 0;
    border: none;
}
.tDigg-count a:hover, .tDigg-count-s a:hover, .tDigg-count a:hover strong, .tDigg-count-s a:hover strong {
    color: #998D43;
}
--></style>
")) . "
</head>'
$vbulletin->templatecache['SHOWTHREAD']);
$vbulletin->templatecache['threadbit'] = preg_replace('#\"\.\(\(\$show\[\'moderated\'\] OR #i','
".((!in_array($thread[forumid], explode(",", "' 
$vbulletin->options['tDigg_forums'] . '", -1))) ? ("") : ("
<span style=\'float: right;\' ><b><span id=\'votecount_$threadnum\' style=\'position: relative; top: -5px;\'>$thread[tdiggs]</span></b> " . (($thread[\'tdiggs\'] >= 0) ? ("<img src=\"$stylevar[imgdir_misc]/t-us.png\" width=\"18px\" height=\"18px\">") : ("<img src=\"$stylevar[imgdir_misc]/t-ds.png\" width=\"18px\" height=\"18px\">")) . "</span>")) . "
".(($show[\'moderated\'] OR '
$vbulletin->templatecache['threadbit']);
if (
$vbulletin->options['legacypostbit']) {
    
$vbulletin->templatecache['postbit_legacy'] = preg_replace('#<div id=\\\"post_message_\$post\[postid\]\\\" 
class=\\\"vb_postbit\\\">\$post\[message\]</div>#i'
,'
".((!in_array($forum[forumid], explode(",", "' 
$vbulletin->options['tDigg_forums'] . '", -1))) ? ("") : ("
            ".(($post[postcount] == 1) ? ("
            <div style=\'position: relative; display: inline; float: right; padding: 0px 10px 0px 0px;\'>
                <div class=\"news-summary\">
                    <ul class=\"news-tDigg\">
                        <li class=\"tDigg-count\">
                            <a><strong id=\"votecount_$thread[threadid]\">$thread[tdiggs]</strong></a>
                        </li>
                        '
.(($vbulletin->userinfo['usergroupid'] != 1) ? ('<li><img src=\"$stylevar[imgdir_misc]/t-dg.png\" onmouseover=\"this.src=\'$stylevar[imgdir_misc]/t-d.png\'\" onmouseout=\"this.src=\'$stylevar[imgdir_misc]/t-dg.png\'\" onclick=\"javascript: vote($thread[threadid],\'take\');\" width=\"25px\" height=\"18px\"><img src=\"$stylevar[imgdir_misc]/t-ug.png\" onmouseover=\"this.src=\'$stylevar[imgdir_misc]/t-u.png\'\" onmouseout=\"this.src=\'$stylevar[imgdir_misc]/t-ug.png\'\" onclick=\"javascript: vote($thread[threadid],\'give\');\" width=\"25px\" height=\"18px\"></li>') : ('')).'
                    </ul>
                </div>
            </div>") : ("")) . "")) . "
        <div id=\"post_message_$post[postid]\">$post[message]</div>
        <div style=\"display: block; clear: both;\">&nbsp;</div>'
$vbulletin->templatecache['postbit_legacy']);
} else {
    
$vbulletin->templatecache['postbit'] = preg_replace('#<div id=\\\"post_message_\$post\[postid\]\\\">\$post\[message\]</div>#i','
".((!in_array($forum[forumid], explode(",", "' 
$vbulletin->options['tDigg_forums'] . '", -1))) ? ("") : ("
            ".(($post[postcount] == 1) ? ("
            <div style=\'position: relative; display: inline; float: right; padding: 0px 10px 0px 0px;\'>
                <div class=\"news-summary\">
                    <ul class=\"news-tDigg\">
                        <li class=\"tDigg-count\">
                            <a><strong id=\"votecount_$thread[threadid]\">$thread[tdiggs]</strong></a>
                        </li>
                        '
.(($vbulletin->userinfo['usergroupid'] != 1) ? ('<li><img src=\"$stylevar[imgdir_misc]/t-dg.png\" onmouseover=\"this.src=\'$stylevar[imgdir_misc]/t-d.png\'\" onmouseout=\"this.src=\'$stylevar[imgdir_misc]/t-dg.png\'\" onclick=\"javascript: vote($thread[threadid],\'take\');\" width=\"25px\" height=\"18px\"><img src=\"$stylevar[imgdir_misc]/t-ug.png\" onmouseover=\"this.src=\'$stylevar[imgdir_misc]/t-u.png\'\" onmouseout=\"this.src=\'$stylevar[imgdir_misc]/t-ug.png\'\" onclick=\"javascript: vote($thread[threadid],\'give\');\" width=\"25px\" height=\"18px\"></li>') : ('')).'
                    </ul>
                </div>
            </div>") : ("")) . "")) . "
        <div id=\"post_message_$post[postid]\">$post[message]</div>
        <div style=\"display: block; clear: both;\">&nbsp;</div>'
$vbulletin->templatecache['postbit']);
}

I had to help someone get this working, so I thought I'd share the modified code.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01263 seconds
  • Memory Usage 1,860KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete