Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Need a PHP programmer who knows TextPattern well and can edit/change TXP Plugins

  1. #1

    Need a PHP programmer who knows TextPattern well and can edit/change TXP Plugins

    I've got my site: www.kentuckygolfing.com

    If you click on either of the golf course's names (in the "recent posts") area, you can see that I've got a rating script for each course. It's seemingly a pretty simple plugin (I'm not a programmer so I don't know) it just tracks ratings according to a users IP address and wont let the same user vote twice for the same article or page. Then in the textpattern interface you have an extra tab that allows you to monitor each person that voted by their IP and you can delete all the ratings if you want to start over.

    Anyway, the reason I need someone is because the plugin obviously has a bug. What happens when you view my site is if an article has not been rated yet, it tells you that "this article hasn't been rated" under the stars and then for some reason it tells you "this article hasn't been rated" in the top of the page above the logo and even if you view the source the text "this article hasn't been rated" shows up before the DOCTYPE declaration. This shouldn't be happening. Once an article has a rating, everything works as it should, the mystery text goes away. I need someone willing to take a look at the code for this plugin out of the goodness of their heart and see if they can tell what is going on. I've posted at the txp forums and even emailed the author of the plugin with no response.

    thanks

  2. #2
    Is Still Alive! Johnny Gulag's Avatar
    Join Date
    Feb 2006
    Location
    North Texas
    Posts
    242
    Hello

    Post the code and I will look at it, but no guarantees.

  3. #3
    Hey Ben. Thanks for taking a look at the code! No big deal if you can't figure it out, but I do appreciate you trying

    There is also a JavaScript snippet that is called into the page (may also be the culprit?). The JavaScript is called into the page by using this tag: <txp:tcm_rating_js_tag /> in the head of your document. The actual code that is output by that tag is found here: http://www.kentuckygolfing.com/ratingjs

    The only thing I don't know is how to edit that JavaScript code if in fact it is the reason behind this bug? Because all I do with the plugin is put the textpattern tag in where I want the star rating to show up at and then paste the textpattern tag in the the head of the documet for the javascript and then the backend php code does the rest, so maybe the javascript is actually embedded in that php code somewhere (if that's even possible?)


    I've got to break the php code up into a couple different posts as it's to long for me to post in one single post. They will follow this message.

    Thanks again!

    EDIT: Damn, sorry I didn't realize there was that much code. It's all in sequencial (sp?) order though. If you want, I can just put it in notepad or something and upoad the file so you can download it.
    Last edited by deronsizemore; 09-03-2006 at 10:07 AM.

  4. #4
    PHP Code:
    if (@txpinterface == 'public') {
        
    register_callback("tcm_rating_pt"'pretext');
        
    register_callback("tcm_rating_js"'pretext');
    }

    if (@
    txpinterface == 'admin') {
        
    $myevent 'rating';
        
    $mytab 'ratings';
        
    add_privs($myevent'1,2,3,4,5');
        
    register_tab("extensions"$myevent$mytab);
        
    register_callback("tcm_rating_admin"$myevent);
    }
    function 
    tcm_rating_admin($event$step)
    {
        if (!
    $step or !in_array($step, array('tcm_rating_install_db''tcm_rating_uninstall_db''tcm_rating_install_form''showcss''append_css'))) {
            
    list_queue();
        } else 
    $step();
    }

    function 
    tcm_rating_install_form($message '')
    {
        
    tcm_rating_install_db();
        
    pagetop("Rating Admin");
        echo 
    "<div align=\"center\" style=\"margin-top:3em\">" sLink('rating''list_queue''List''navlink') . "</div>";
        echo 
    "<div align=\"center\" style=\"margin-top:3em\">";
        echo 
    form(
            
    tag("SQL""h3") .
            
    graf("Drop DB Tables: " .
                
    fInput("submit""uninstall""Uninstall""publish") .
                
    eInput("rating") . sInput("tcm_rating_uninstall_db") , " style=\"text-align:center\""));
        echo 
    "</div>";

        
    $styleslist safe_column("name""txp_css""1=1");
        echo 
    "<div align=\"center\" style=\"margin-top:3em\">";
        echo 
    form(
            
    tag("CSS""h3") .
            
    graf("Append CSS to " selectInput('css'$styleslist) .br.
                    
    "Image Path: "fInput('text','image_path','','edit').br.
                
    fInput("submit""append""Append""publish") .
                
    '<a target="_blank" href="?event=rating&step=showcss"
                onclick="window.open(this.href, \'popupwindow\',\'width=600, height=600,scrollbars,resizable\'); return false;">View CSS</a>'
                
    eInput("rating") . sInput("append_css") , " style=\"text-align:center\"")
                );
        echo 
    "</div>";
    }

    function 
    append_css()
    {
        
    $name gps('css');
        
    $image_path gps('image_path');
        
    $thecss base64_decode(fetch("css"'txp_css''name'$name));
        
    $append_css return_css($image_path);
        
    $newcss base64_encode($thecss $append_css);
        
    $rs safe_update("txp_css""css = '" $newcss "'""name = '$name'");
        if (
    $rs) {
            
    tcm_rating_install_form("CSS Append successful");
        } else {
            
    tcm_rating_install_form("CSS Append failed");
        }
    }

    function 
    showcss()
    {
        
    $image_path = (gps('image_path')) ? gps('image_path') : "";
        echo <<< HEADSECTION
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Textpattern: Rating CSS View</title>
    </head>
    <body>
    HEADSECTION;
        echo 
    form(
                
    "Image Path: "fInput('text','image_path','','edit').
                
    fInput("submit""showcss""Show CSS""publish")
                . 
    eInput("rating") . sInput("showcss") , " style=\"text-align:center\"");
        echo 
    tcm_textarea('500''550'htmlentities(return_css($image_path)), 'css');
        exit;
    }
    function 
    tcm_textarea($h$w$content$name)
    {
        return 
    '<textarea name="' $name '" style="height:' $h 'px;width:' $w 'px;font-family:monaco,courier,courier new;font-size:10px;margin-top:6px" rows="1" cols="1">' htmlspecialchars($content) . '</textarea>';
    }

    function 
    tcm_rating_install_db()
    {
        
    $sql "CREATE TABLE IF NOT EXISTS `" PFX "txp_tcm_rqueue` (
      `parent_id` int(11) NOT NULL default '0',
      `id` int(11) NOT NULL auto_increment,
      `ip` varchar(30) NOT NULL default '',
      `rating` int(11) NOT NULL default '0',
      `posted` datetime NOT NULL default '0000-00-00 00:00:00',
      PRIMARY KEY  (`id`),
      KEY `ip` (`ip`),
      KEY `posted` (`posted`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;"
    ;
        
    $rs safe_query($sql);
        
    $sql2 "CREATE TABLE IF NOT EXISTS `" PFX "txp_tcm_rsum` (
      `id` int(10) NOT NULL auto_increment,
      `parent_id` int(10) unsigned NOT NULL default '0',
      `ratings` int(11) NOT NULL default '0',
      `sum` int(11) NOT NULL default '0',
      `average` float NOT NULL default '0',
      PRIMARY KEY  (`id`),
      KEY `parent_id` (`parent_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;"
    ;
        
    $rs2 safe_query($sql2);
        if (
    $rs && $rs2) {
            
    //echo pagetop("Install Rating System", "installation successful");
            
    safe_delete("txp_tcm_rqueue""posted < date_sub(now(),interval 1 day)");
        } else {
            
    //echo pagetop("Install Rating System", "installation failed");
        
    }
    }

    function 
    tcm_rating_uninstall_db()
    {
        
    $rs safe_query("DROP TABLE IF EXISTS `txp_tcm_rqueue`;");
        
    $rs2 safe_query("DROP TABLE IF EXISTS `txp_tcm_rsum`;");
        if (
    $rs && $rs2) {
            
    tcm_rating_install_form("uninstallation successful");
        } else {
            
    tcm_rating_install_form("uninstallation failed");
        }
    }

    function 
    list_queue($message '')
    {
            
    tcm_rating_install_db();
            if (isset(
    $message)) {
                
    pagetop("View Rating Queue"$message);
            } else {
                
    pagetop("View Rating Queue");
            }
            
    $page gps('page');
            
    $total getCount('txp_tcm_rqueue'"1");
            
    $limit 40;
            
    $numPages ceil($total $limit);
            
    $page = (!$page) ? $page;
            
    $offset = ($page 1) * $limit;
            
    $nav[] = ($page 1)
            ? 
    PrevNextLink("rating"$page-1gTxt('prev'), 'prev') : '';

            
    $nav[] = sp small($page '/' $numPages) . sp;

            
    $nav[] = ($page != $numPages)
            ? 
    PrevNextLink("rating"$page 1gTxt('next'), 'next') : '';
    /*
            $rs = safe_rows_start("*, unix_timestamp(posted) as stamp",
                "txp_tcm_rqueue",
                "1 order by posted desc limit $offset, $limit"
                );
                */
             
    $rs safe_rows_start_joined("*, unix_timestamp(".PFX."txp_tcm_rqueue.posted) as stamp", Array('textpattern''txp_tcm_rqueue'),
             
    PFX."txp_tcm_rqueue.parent_id = ".PFX."textpattern.ID ".' order by '.PFX."txp_tcm_rqueue.posted desc limit $offset$limit");
            if (
    $rs) {
                echo 
    tag("Rating Queue""h3"" style='text-align: center'");
                echo 
    startTable('list'),
                
    assHead('time''host''article''rating'),
                
    tr(tdcs(sLink('rating''tcm_rating_install_form''Install &amp; Admin''navlink'), '4'));
                while (
    $a nextRow($rs)) {
                    
    extract($a);
                    
    $fstamp date("n/j g:i a", ($stamp tz_offset()));
                    
    //
                    
    echo tr(
                        
    td($fstamp) .
                        
    td(tag($ip'a'' href="http://www.dnsstuff.com/tools/city.ch?ip='.$ip.'" ')) .
                        
    td(tag($Title'a'' href="'.tcm_permlinkurl($a).'"')) .
                        
    td(rating_dots($rating)));
                    unset(
    $fstamp$ip$parent_id$rating);
                }
                echo 
    '<tr><td colspan="4" align="right" style="padding:10px">',
                
    join(''$nav),
                
    "</td></tr>";
                echo 
    endTable();
            }
    }


    // -------------------------------------------------------------
        
    function tcm_permlinkurl($article_array)
        {
            global 
    $permlink_mode$prefs;

            if (isset(
    $prefs['custom_url_func']) and is_callable($prefs['custom_url_func']))
                return 
    call_user_func($prefs['custom_url_func'], $article_array);

            if (empty(
    $article_array)) return;

            
    extract($article_array);

            if (!isset(
    $title)) $title $Title;
            if (empty(
    $url_title)) $url_title stripSpace($title);
            if (empty(
    $section)) $section $Section// lame, huh?
            
    if (empty($posted)) $posted $Posted;
            if (empty(
    $thisid)) $thisid $ID;

            switch(
    $permlink_mode) {
                case 
    'section_id_title':
                    if (
    $prefs['attach_titles_to_permalinks'])
                    {
                        return 
    hu."$section/$thisid/$url_title";
                    }else{
                        return 
    hu."$section/$thisid/";
                    }
                case 
    'year_month_day_title':
                    list(
    $y,$m,$d) = explode("-",date("Y-m-d",$posted));
                    return 
    hu."$y/$m/$d/$url_title";
                case 
    'id_title':
                    if (
    $prefs['attach_titles_to_permalinks'])
                    {
                        return 
    hu."$thisid/$url_title";
                    }else{
                        return 
    hu."$thisid/";
                    }
                case 
    'section_title':
                    return 
    hu."$section/$url_title";
                case 
    'title_only':
                    return 
    hu."$url_title";
                case 
    'messy':
                    return 
    hu."index.php?id=$thisid";
            }
        } 

  5. #5
    PHP Code:
    function rating_dots($rating)
    {
       
    $out "";
       for(
    $i 0;$i $rating;$i++)
       {
          
    $out .= "&mdash;";
       }
       return 
    $out;
    }

    function 
    tcm_rating_js()
    {
        global 
    $prefs;
        
    extract($prefs);

        
    $page['req'] = tcm_clean_request();
        
    $page['path'] = tcm_clean_chop(@$page['req'][0]);
        if (!empty(
    $page['path'][0])) {
            if (
    $page['path'][0] == 'ratingjs') {
               echo 
    return_js();
               die;
            }
        }
    }

    function 
    tcm_rating_pt()
    {
        global 
    $prefs;
        
    extract($prefs);

        
    $page['req'] = tcm_clean_request();
        
    $page['path'] = tcm_clean_chop(@$page['req'][0]);
        if (!empty(
    $page['path'][0])) {
            if (
    $page['path'][0] == 'rate') {
                if (
    is_numeric($page['path'][1])) {
                    
    $article safe_row("*""textpattern""ID='" intval($page['path'][1]) . "' and Status in (4,5)");
                    
    $aid $page['path'][1];
                    if (!empty(
    $article)) {
                        
    // NOTE: checking rating
                        
    if (isset($page['path'][2])) {
                            if (
    is_numeric($page['path'][2]) && ($page['path'][2] < 6) && ($page['path'][2] > 0)) {
                                
    $ip serverSet('REMOTE_ADDR');
                                
    $precedent safe_rows("*""txp_tcm_rqueue""parent_id=" intval($page['path'][1]) . " and ip='" $ip "' and posted > date_sub(now(),interval 1 day)");
                                
    // print_r($precedent);
                                
    if (empty($precedent)) {
                                    
    safe_insert("txp_tcm_rqueue""parent_id='" intval($page['path'][1]) . "', ip='" $ip "', rating=" $page['path'][2] . ", posted=now()");
                                    
    $sum_precedent safe_row("ratings, sum, average""txp_tcm_rsum""parent_id='" intval($page['path'][1]) . "'");
                                    
    $ratings $sum $average 0;
                                    if (!empty(
    $sum_precedent)) {
                                        
    $ratings $sum_precedent["ratings"];
                                        
    $sum $sum_precedent["sum"];
                                        
    $average $sum_precedent["average"];
                                    }
                                    
    $ratings++;
                                    
    $sum += $page['path'][2];
                                    
    $average round($sum $ratings1);
                                    
    // echo $average;
                                    // NOTE: safe_upsert doesn't work here.
                                    // txp_tcm_rsum", "parent_id='".$page['path'][1]."', ratings=".$ratings.", sum=".$sum.", average=".$average, "parent_id='".$page['path'][1]."'"
                                    
    $r safe_update("txp_tcm_rsum""ratings=" $ratings ", sum=" $sum ", average=" $average"parent_id='" $page['path'][1] . "'");
                                    if (
    $r and mysql_affected_rows()) {
                                        echo 
    tcm_rating_form(Array('internal' => true'id' => $aid));
                                        exit;
                                    } else {
                                        
    $ins safe_insert("txp_tcm_rsum""parent_id='" $page['path'][1] . "', ratings=" $ratings ", sum=" $sum ", average=" $average);

                                        echo 
    tcm_rating_form(Array('internal' => true'id' => $aid));
                                        exit;
                                    }
                                } else {
                                    echo 
    tcm_rating_form(Array('internal' => true'id' => $aid'error' => "You've already rated this course."));
                                    exit;
                                }
                            } else {
                                echo 
    tcm_rating_form(Array('internal' => true'id' => $aid'error' => "Sorry, that bit of input didn't agree with the tcm_rating system."));
                                exit;
                            }
                        } else {
                            echo 
    tcm_rating_form(Array('internal' => true'id' => $aid'error' => "Sorry, you need to enter a numerical rating for the article"));
                            exit;
                        }
                    } else {
                        
    // NOTE: error: invalid article
                        
    echo tcm_rating_form(Array('internal' => true'id' => $aid'error' => "Sorry, that article is invalid."));
                        exit;
                    }
                } else {
                    
    // NOTE: error: invalid ID
                    
    echo tcm_rating_form(Array('internal' => true'error' => "Sorry, that article is invalid."));
                    exit;
                }
            }
        }
    }
    // TODO: credit ajw_clean_feed_request
    function tcm_clean_request()
    {
        
    $subpath preg_quote(preg_replace("/http:\/\/.*(\/.*)/Ui""$1"hu), "/");
        
    $req preg_replace("/^$subpath/i""/"$_SERVER['REQUEST_URI']);
        
    $req explode('?'$req);
        return 
    $req;
    }
    // TODO: credit ajw_clean_feed_chop
    function tcm_clean_chop($req '')
    {
        
    $req urldecode(strtolower($req));
        
    // strip off query_string, if present
        
    $qs strpos($req'?');
        if (
    $qs$req substr($req0$qs);
        
    $req preg_replace('/index\.php$/'''$req);
        
    $req array_values(array_filter(explode('/'$req)));
        return 
    $req;
    }
    function 
    tcm_rating_form($atts)
    {
        if (
    safe_query("describe " PFX "txp_tcm_rqueue") && safe_query("describe " PFX "txp_tcm_rsum")) {
            global 
    $pretext$thisarticle;
            
    $id gAtt($atts'id'gps('id'));
            
    extract(lAtts(array('error' => '',
                        
    'internal' => false
                        
    ), $atts));
            if (@
    $thisarticle['thisid']) $id $thisarticle['thisid'];
            if (!
    $id && @$pretext['id']) $id $pretext['id'];
            
    $precedent safe_row("ratings, average""txp_tcm_rsum""parent_id='" $id "'");
            if (!empty(
    $precedent)) {
                
    // print_r($precedent);
                
    $width $precedent["average"] * 25;
                
    $average $precedent["average"];
                
    $current_rating "<li class='current-rating' style='width:" $width "px;'>Currently " $precedent["average"] . "/5 Stars.</li>";
                
    $rating_desc "<span class=\"ratingdesc\">Currently $average/5 Stars.</span>";
            } else {
                
    $current_rating $average $width $rating_desc "";
                
    $error "This hasn't been rated yet.";
            } 

  6. #6
    PHP Code:
     if (!empty($error)) {
                
    $errorspan "<span class='ratingerror'>" $error "</span>";
            } else {
                
    $errorspan "";
            }
            if (!
    $internal) {
                
    $div_open "<div id='tcm_rating_input'>";
                
    $div_close "</div>";
            } else {
                
    $div_open $div_close "";
            }
            return <<< RATINGFORM
    $div_open
    <ul class="star-rating">
    $current_rating
      <li><a href='#' title='Rate this 1 star out of 5' onclick='tcm_rate(
    $id, 1, this);' class='one-stars'>1</a></li>
      <li><a href='#' title='Rate this 2 stars out of 5' onclick='tcm_rate(
    $id, 2, this);' class='two-stars'>2</a></li>
      <li><a href='#' title='Rate this 3 stars out of 5' onclick='tcm_rate(
    $id, 3, this);' class='three-stars'>3</a></li>
      <li><a href='#' title='Rate this 4 stars out of 5' onclick='tcm_rate(
    $id, 4, this);' class='four-stars'>4</a></li>
      <li><a href='#' title='Rate this 5 stars out of 5' onclick='tcm_rate(
    $id, 5, this);' class='five-stars'>5</a></li>
    </ul>
    $rating_desc
    $errorspan
    $div_close
    RATINGFORM;
        } else {
            return 
    "<span class='ratingerror'>error: rating database doesn't exist.</span>";
        }
    }


    function 
    tcm_rating_num($atts)
    {
        global 
    $thisarticle;
        
    extract(lAtts(array('noratings' => 'This article hasn\'t been rated',
                
    'hasbeen' => 'This course has been rated %r (time/times)',
                
    'alpha' => false
                
    ), $atts));
        
    // NOTE: avoid extra sql if we are already using a tcm_rating_article tag.
        
    if (isset($thisarticle["ratings"]))
        {
            
    $precedent $thisarticle["ratings"];
        }
        elseif (
    safe_query("describe " PFX "txp_tcm_rqueue") && safe_query("describe " PFX "txp_tcm_rsum")) {
            
    $id gAtt($atts'id'gps('id'));
            if (@
    $thisarticle['thisid']) $id $thisarticle['thisid'];
            if (!
    $id && @$pretext['id']) $id $pretext['id'];
            
    $precedent safe_field("ratings""txp_tcm_rsum""parent_id='" $id "'");
        }
        else {
            return 
    "<span class='ratingerror'>error: rating database doesn't exist.</span>";
        }
            if (!empty(
    $precedent)) {
                if(
    $precedent 0)
                {
                    if(
    $precedent == 1)
                    {
                        
    //echo $hasbeen;
                        
    $reg'#\(([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)\)#';
                        
    $rep'$1';
                        
    $replaced preg_replace($reg,$rep,$hasbeen);
                        
    $replaced = ($alpha) ?
                         
    str_replace("%r"int_to_words(intval($precedent)), $replaced) :
                         
    str_replace("%r"intval($precedent), $replaced);
                         return 
    $replaced;
                    }
                    else
                    {
                        
    $reg'#\(([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)\)#';
                        
    $rep'$2';
                        
    $replaced preg_replace($reg,$rep,$hasbeen);
                        
    $replaced = ($alpha) ?
                         
    str_replace("%r"int_to_words(intval($precedent)), $replaced) :
                         
    str_replace("%r"intval($precedent), $replaced);
                         return 
    $replaced;
                    }
                }
            } else {
                echo 
    $noratings;
            }
        }

    function 
    int_to_words($x)
    {
       
    $nwords = array("zero""one""two""three""four""five""six""seven",
                        
    "eight""nine""ten""eleven""twelve""thirteen",
                        
    "fourteen""fifteen""sixteen""seventeen""eighteen",
                        
    "nineteen""twenty"30 => "thirty"40 => "forty",
                        
    50 => "fifty"60 => "sixty"70 => "seventy"80 => "eighty",
                        
    90 => "ninety");
        if(!
    is_numeric($x))
        {
            
    $w '#';
        }else if(
    fmod($x1) != 0)
        {
            
    $w '#';
        }else{
            if(
    $x 0)
            {
                
    $w 'minus ';
                
    $x = -$x;
            }else{
                
    $w '';
            }
            if(
    $x 21)
            {
                
    $w .= $nwords[$x];
            }else if(
    $x 100)
            {
                
    $w .= $nwords[10 floor($x/10)];
                
    $r fmod($x10);
                if(
    $r 0)
                {
                    
    $w .= '-'$nwords[$r];
                }
            } else if(
    $x 1000)
            {
                
    $w .= $nwords[floor($x/100)] .' hundred';
                
    $r fmod($x100);
                if(
    $r 0)
                {
                    
    $w .= ' and 'int_to_words($r);
                }
            } else if(
    $x 1000000)
            {
                
    $w .= int_to_words(floor($x/1000)) .' thousand';
                
    $r fmod($x1000);
                if(
    $r 0)
                {
                    
    $w .= ' ';
                    if(
    $r 100)
                    {
                        
    $w .= 'and ';
                    }
                    
    $w .= int_to_words($r);
                }
            } else {
                
    $w .= int_to_words(floor($x/1000000)) .' million';
                
    $r fmod($x1000000);
                if(
    $r 0)
                {
                    
    $w .= ' ';
                    if(
    $r 100)
                    {
                        
    $word .= 'and ';
                    }
                    
    $w .= int_to_words($r);
                }
            }
        }
        return 
    $w;
    }

    function 
    return_js()
    {
       
    $js = <<< THEJS

     function createXMLHttpRequest() {
       try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
       try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
       try { return new XMLHttpRequest(); } catch(e) {}
       alert("XMLHttpRequest not supported");
       return null;
     }
     function tcm_rate(id, rating, element) {
        var xhReq = createXMLHttpRequest();
        restURL = "[HU_TEMP]rate/"+id+"/"+rating;
        //alert(restURL);
        xhReq.open("GET", restURL, true);
        xhReq.onreadystatechange = function() {
          if (xhReq.readyState != 4)  { return; }
          //rating_input = \$('tcm_rating_input');
          outerdiv = element.parentNode.parentNode.parentNode;
          var serverResponse = xhReq.responseText;
          outerdiv.innerHTML = serverResponse;
        };
        xhReq.send(null);
        return false;
     } 

  7. #7
    PHP Code:
    function \$() {
      var 
    elements = new Array();

      for (var 
    0arguments.lengthi++) {
        var 
    element arguments[i];
        if (
    typeof element == 'string')
          
    element document.getElementById(element);

        if (
    arguments.length == 1)
          return 
    element;

        
    elements.push(element);
      }

      return 
    elements;
    }
    THEJS;

        
    $js str_replace("[HU_TEMP]"hu$js);
        return 
    $js;
    }


    function 
    return_css($image_path)
    {
        
    $css = <<< THECSS

                 /*             styles for the star rater                */
        .star-rating{
            list-style:none;
            margin: 0px;
            padding:0px;
            width: 125px;
            height: 25px;
            position: relative;
            background: url([IMAGE_PATH]) top left repeat-x;
        }
        .star-rating li{
            padding:0px;
            margin:0px;
            /*\*/
            float: left;
            /* */
        }
        .star-rating li a{
    border: 0;
            display:block;
            width:25px;
            height: 25px;
            text-decoration: none;
            text-indent: -9000px;
            z-index: 20;
            position: absolute;
            padding: 0px;
        }
        .star-rating li a:hover{
            background: url([IMAGE_PATH]) left bottom;
            z-index: 2;
            left: 0px;
        }
        .star-rating a.one-star{
            left: 0px;
        }
        .star-rating a.one-star:hover{
            width:25px;
        }
        .star-rating a.two-stars{
            left:25px;
        }
        .star-rating a.two-stars:hover{
            width: 50px;
        }
        .star-rating a.three-stars{
            left: 50px;
        }
        .star-rating a.three-stars:hover{
            width: 75px;
        }
        .star-rating a.four-stars{
            left: 75px;
        }
        .star-rating a.four-stars:hover{
            width: 100px;
        }
        .star-rating a.five-stars{
            left: 100px;
        }
        .star-rating a.five-stars:hover{
            width: 125px;
        }
        .star-rating li.current-rating{
            background: url([IMAGE_PATH]) left center;
            position: absolute;
            height: 25px;
            display: block;
            text-indent: -9000px;
            z-index: 1;
        }
    .ratingerror {
    color: red;
    }
    THECSS;
        
    $css str_replace("[IMAGE_PATH]"$image_path$css);
        return 
    $css;
    }

    function 
    tcm_rating_js_tag()
    {
       return 
    "<script type=\"text/javascript\" src=\"".hu."ratingjs\"></script>";
    }


    // -------------------------------------------------------------
        
    function tcm_rating_articles($atts$iscustom)
        {
            global 
    $pretext$prefs$txpcfg;
            if (
    safe_query("describe " PFX "txp_tcm_rqueue") && safe_query("describe " PFX "txp_tcm_rsum")) {
            
    extract($pretext);
            
    extract($prefs);
            
    //getting attributes
            
    $theAtts lAtts(array(
                
    'form'      => 'default',
                
    'limit'     => 10,
                
    'pageby'    => '',
                
    'category'  => '',
                
    'section'   => '',
                
    'excerpted' => '',
                
    'author'    => '',
                
    'sortby'    => '',
                
    'sortdir'   => 'desc',
                
    'month'     => '',
                
    'keywords'  => '',
                
    'frontpage' => '',
                
    'id'        => '',
                
    'time'      => 'past',
                
    'status'    => '4',
                
    'pgonly'    => 0,
                
    'searchall' => 1,
                
    'searchsticky' => 0,
                
    'allowoverride' => (!$q and !$iscustom),
                
    'offset'    => 0,
            ),
    $atts);

            
    // if an article ID is specified, treat it as a custom list
            
    $iscustom = (!empty($theAtts['id'])) ? true $iscustom;

            
    //for the txp:article tag, some attributes are taken from globals;
            //override them before extract

            
    if (!$iscustom)
            {
                
    //$theAtts['category'] = ($c)? $c : '';
                //$theAtts['section'] = ($s && $s!='default')? $s : '';
                
    $theAtts['author'] = (!empty($author)? $author'');
                
    $theAtts['month'] = (!empty($month)? $month'');
                
    //$theAtts['frontpage'] = ($s && $s=='default')? true: false;
                //$theAtts['excerpted'] = '';
            
    }
            
    extract($theAtts);

            
    $pageby = (empty($pageby) ? $limit $pageby);

            
    // treat sticky articles differently wrt search filtering, etc
            
    if (!is_numeric($status))
                
    $status getStatusNum($status);
            
    $issticky = ($status == 5);

            
    $match $search '';
            if (!
    $sortby$sortbyPFX.'txp_tcm_rsum.average';

            
    //Building query parts
            
    $frontpage = ($frontpage and !$q) ? filterFrontPage() : '';
            
    $category  = (!$category)  ? '' " and ((Category1='".doslash($category)."') or (Category2='".doSlash($category)."')) ";
            
    $section   = (!$section)   ? '' " and Section = '".doslash($section)."'";
            
    $excerpted = ($excerpted=='y')  ? " and Excerpt !=''" '';
            
    $author    = (!$author)    ? '' " and AuthorID = '".doslash($author)."'";
            
    $month     = (!$month)     ? '' " and Posted like '".doSlash($month)."%'";
            
    $id        = (!$id)        ? '' " and ID = '".intval($id)."'";
            switch (
    $time) {
                case 
    'any':
                    
    $time ""; break;
                case 
    'future':
                    
    $time " and Posted > now()"; break;
                default:
                    
    $time " and Posted < now()";
            }
            if (!
    is_numeric($status))
                
    $status getStatusNum($status);

            
    $custom '';

            
    // trying custom fields here
            
    $customFields getCustomFields();

            if (
    $customFields) {
                foreach(
    $customFields as $cField) {
                    if (isset(
    $atts[$cField]))
                        
    $customPairs[$cField] = $atts[$cField];
                }
                if(!empty(
    $customPairs)) {
                    
    $custom =  buildCustomSql($customFields,$customPairs);
                } else 
    $custom '';
            }

            
    //Allow keywords for no-custom articles. That tagging mode, you know
            
    if ($keywords) {
                
    $keys split(',',$keywords);
                foreach (
    $keys as $key) {
                    
    $keyparts[] = " Keywords like '%".doSlash(trim($key))."%'";
                }
                
    $keywords " and (" join(' or ',$keyparts) . ")";
            }

            if (
    $q and $searchsticky)
                
    $statusq " and Status >= '4'";
            elseif (
    $id)
                
    $statusq " and Status >= '4'";
            else
                
    $statusq " and Status='".doSlash($status)."'";

            
    $where "1" $statusq$time.
                
    $search $id $category $section $excerpted $month $author $keywords $custom $frontpage;

            
    //do not paginate if we are on a custom list
            
    if (!$iscustom and !$issticky)
            {
                
    $total safe_count('textpattern',$where) - $offset;
                
    $numPages ceil($total/$pageby);
                
    $pg = (!$pg) ? $pg;
                
    $pgoffset $offset + (($pg 1) * $pageby).', ';
                
    // send paging info to txp:newer and txp:older
                
    $pageout['pg']       = $pg;
                
    $pageout['numPages'] = $numPages;
                
    $pageout['s']        = $s;
                
    $pageout['c']        = $c;
                
    $pageout['total']    = $total;

                global 
    $thispage;
                
    $thispage $pageout;
                if (
    $pgonly)
                    return;
            }else{
                
    $pgoffset $offset ', ';
            }
            
    $where .= " and ".PFX."txp_tcm_rsum.parent_id = ".PFX."textpattern.ID";
            
    $rs safe_rows_start_joined("*, txp_tcm_rsum.ratings, txp_tcm_rsum.average, unix_timestamp(Posted) as uPosted".$match, Array('textpattern''txp_tcm_rsum'),
            
    $where' order by ' doslash($sortby) . ' ' doSlash($sortdir) . ' limit ' doSlash($pgoffset.$limit));
            
    // alternative form override for search or list
            
    if ($q and !$iscustom and !$issticky)
                
    $form gAtt($atts'searchform''search_results');
            else
                
    $form gAtt($atts'listform'$form);
            
    // might be a form preview, otherwise grab it from the db
            
    $form = (isset($_POST['Form']))
            ?    
    gps('Form')
            :    
    fetch_form($form);

            if (
    $rs) {
                
    $count 0;

                
    $articles = array();
                while(
    $a nextRow($rs)) {
                    ++
    $count;
                    
    populateArticleDataRatings($a);
                    global 
    $thisarticle$uPosted$limit;
                    
    $thisarticle['is_first'] = ($count == 1);
                    
    $thisarticle['is_last'] = ($count == numRows($rs));
                    
    // define the article form
                    
    $article = ($allowoverride and $a['override_form'])
                    ?    
    fetch_form($a['override_form'])
                    :    
    $form;

                    
    $articles[] = parse($article);

                    
    // sending these to paging_link(); Required?
                    
    $uPosted $a['uPosted'];
                    
    $limit $limit;

                    unset(
    $GLOBALS['thisarticle']);
                    unset(
    $GLOBALS['theseatts']);//Required?
                
    }

                return 
    join('',$articles);
            }
            }
        }
        function 
    safe_rows_start_joined($things$tables$where$debug='')
        {
            
    array_walk($tables'table_slash');
            
    $table join(","$tables);
            
    $q "select $things from $table where $where";
            return 
    startRows($q,$debug);
        }
        function 
    table_slash(&$item1$key)
        {
           
    $item1 "`".PFX.$item1."`";
        }

        function 
    populateArticleDataRatings($rs)
        {
            
    //print_r($rs);
            
    extract($rs);

            
    trace_add("[".gTxt('Article').$ID]");
            
    $out['thisid']          = $ID;
            
    $out['posted']          = $uPosted;
            
    $out['annotate']        = $Annotate;
            
    $out['comments_invite'] = $AnnotateInvite;
            
    $out['authorid']        = $AuthorID;
            
    $out['title']           = $Title;
            
    $out['url_title']       = $url_title;
            
    $out['category1']       = $Category1;
            
    $out['ratings']       = $ratings;
            
    $out['average']       = $average;
            
    $out['category2']       = $Category2;
            
    $out['section']         = $Section;
            
    $out['keywords']        = $Keywords;
            
    $out['article_image']   = $Image;
            
    $out['comments_count']  = $comments_count;


            
    $custom getCustomFields();
            if (
    $custom) {
                foreach (
    $custom as $i => $name)
                    
    $out[$name] = $rs['custom_' $i];
            }

            global 
    $thisarticle$is_article_body;
            
    $thisarticle $out;
            
    $is_article_body 1;
            
    $thisarticle['body'] = parse($Body_html);
            
    $thisarticle['excerpt'] = parse($Excerpt_html);
            
    $is_article_body 0;

        } 

  8. #8
    Is Still Alive! Johnny Gulag's Avatar
    Join Date
    Feb 2006
    Location
    North Texas
    Posts
    242
    Hello

    Wow that is alot of code, to be honest I do not think I am gonna be much help afterall :-( I messed around looking through it for awhile but have no answers to give.

    Have you tried asking the creator of the plug in? Do they have TXP support forums, that might be your best bet.

    Sorry for my lack of assistance.

  9. #9
    Ah, it's cool. I appreciate the effort anyway. I didn't even realize myself that the plugin had that much code.

    Yeah I've asked in the txp forums and only responses I've got back are a couple people having similar issues. I've even emailed the author with no response (it's been around a week). Usually at the txp forums, each plugin has it's own forum thread and you can post bugs/problems there and the author with actually help you, but it's been almost a month since his last post. So I don't know.

    Thanks again.

  10. #10
    Junior Registered
    Join Date
    Sep 2006
    Posts
    1
    Quote Originally Posted by deronsizemore
    I've got my site: www.kentuckygolfing.com

    If you click on either of the golf course's names (in the "recent posts") area, you can see that I've got a rating script for each course. It's seemingly a pretty simple plugin (I'm not a programmer so I don't know) it just tracks ratings according to a users IP address and wont let the same user vote twice for the same article or page. Then in the textpattern interface you have an extra tab that allows you to monitor each person that voted by their IP and you can delete all the ratings if you want to start over.

    Anyway, the reason I need someone is because the plugin obviously has a bug. What happens when you view my site is if an article has not been rated yet, it tells you that "this article hasn't been rated" under the stars and then for some reason it tells you "this article hasn't been rated" in the top of the page above the logo and even if you view the source the text "this article hasn't been rated" shows up before the DOCTYPE declaration. This shouldn't be happening. Once an article has a rating, everything works as it should, the mystery text goes away. I need someone willing to take a look at the code for this plugin out of the goodness of their heart and see if they can tell what is going on. I've posted at the txp forums and even emailed the author of the plugin with no response.

    thanks
    this site: www.makecancer.com

  11. #11
    yeah thanks for that

  12. #12
    Not that blue at all Blue Cat Buxton's Avatar
    Join Date
    May 2004
    Location
    UK
    Posts
    932
    Just a thought, have you tried taking out the text "This hasn't been rated yet." in the code and replace it with "", ie so the error just outputs a blank. I see this text in the last line of the second block you posted, but it could be elsewhere as well.

    I know this is a cheat, but it might solve the problem!

  13. #13
    No, I've not tried that just becuase I know no PHP and didn't want to break something more than it already was. lol. I'll try it though, maybe it will work. Thanks

  14. #14
    Well I tried your suggestion and it worked...only at first it took the wrong text out. The text you suggested took the wrong error message out. The text it took out was directly below the stars telling people that it had no ratings and said "this hasn't been rated yet." The text I needed to delete was at the top of the page and said "this article hasn't been rated." So I just searched for the text that I needed and did what you said and it seems to be working now as it should. I just hope I wont run into some other problems later...

    Thanks I appreciate it.

  15. #15
    Is Still Alive! Johnny Gulag's Avatar
    Join Date
    Feb 2006
    Location
    North Texas
    Posts
    242
    Quote Originally Posted by Blue Cat Buxton
    Just a thought, have you tried taking out the text "This hasn't been rated yet." in the code and replace it with "", ie so the error just outputs a blank. I see this text in the last line of the second block you posted, but it could be elsewhere as well.

    I know this is a cheat, but it might solve the problem!
    Thats what I was gonna do, but for whatever reason the find/replace on my editor did not locate that text in the file, maybe I forgot to cop one of those code examples above.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •