Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Modification of a parser (on first comment)

edited April 2009 in Vanilla 1.0 Help
Hello all,

first, love the software!
second, any PHP wiz who can help me out?
i'm using Make It Simple Text Formatter 1.12 ( http://lussumo.com/addons/index.php?PostBackAction=AddOn&AddOnID=399 ) and i'm trying to customize it so that it only parses at the 1st comment of each discussion.

I figure a simple:

if post = #1 ( parse )
else ( ignore )

would work?
here's the code:

if (in_array($Context->SelfUrl, array("comments.php", "post.php"))) { // An implementation of the string filter interface for plain text strings class ExtendedTextFormatter extends StringFormatter { function Parse ($String, $Object, $FormatPurpose) { $sReturn = $String; // Only format plain text strings if they are being displayed (save in database as is) if ($FormatPurpose == FORMAT_STRING_FOR_DISPLAY) if (stripos($sReturn, 'http://') !== false) $sReturn = $this->AutoLink($sReturn);; return $sReturn; } function AutoLink($String) { $String = str_replace(array(""","&"),array('"','&'),$String); $SplitLines = explode("<br />", $String); foreach ($SplitLines as &$Line) { $SplitWords = explode(" ", $Line); foreach ($SplitWords as &$Word) { if (strncasecmp($Word, 'http://', 7) == 0) if (strcasecmp(substr($Word, strlen($Word) - 4), '.jpg') == 0 || strcasecmp(substr($Word, strlen($Word) - 5), '.jpeg') == 0 || strcasecmp(substr($Word, strlen($Word) - 4), '.gif') == 0 || strcasecmp(substr($Word, strlen($Word) - 4), '.png') == 0) { $Word = '<img src="'.$Word.'" class="discImg" />'; } else if (stripos($Word, 'youtube.com/watch?v=')) { $Word = '<embed src="http://www.youtube.com/v/'.substr(stristr($Word, '='), 1).'" type="application/x-shockwave-flash" width="448" height="361"></embed>'; } else if (stripos($Word, 'dailymotion.com/video/')) { $IDStart = strpos($Word, 'video/') + 6; $IDLength = strpos($Word, '_') - $IDStart; $DailyMotionID = substr($Word, $IDStart, $IDLength); $Word = '<embed src="http://www.dailymotion.com/swf/'.$DailyMotionID.'" type="application/x-shockwave-flash" width="448" height="357" allowFullScreen="true" allowScriptAccess="always"></embed>'; } else if (stripos($Word, 'video.google.com/videoplay?docid=')) { $Word = '<embed id="VideoPlayback" style="width:448px;height:362px" allowFullScreen="true" src="http://video.google.com/googleplayer.swf?docid='.substr(stristr($Word, '='), 1).'" type="application/x-shockwave-flash"> </embed>'; } else if (stripos($Word, 'index.cfm?fuseaction=vids.individual&videoid')) { $Word = '<embed src="http://lads.myspace.com/videos/vplayer.swf" flashvars="m='.substr(stristr($Word, 'videoid='), 8).'&v=2&type=video" type="application/x-shockwave-flash" width="430" height="346" />'; } else if (stripos($Word, 'spike.com/video/')) { $Word = '<embed width="448" height="365" src="http://www.spike.com/efp" quality="high" bgcolor="000000" name="efp" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="flvbaseclip='.substr(strrchr($Word, '/'), 1).'" allowfullscreen="true"> </embed>'; } else if (stripos($Word, 'redlasso.com/ClipPlayer.aspx?id=')) { $Word = '<embed src="http://media.redlasso.com/xdrive/WEB/vidplayer_1b/redlasso_player_b1b_deploy.swf" flashvars="embedId='.substr(stristr($Word, '='), 1).'" width="390" height="320" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" name="Redlasso"></embed>'; } else if (stripos($Word, 'ceknito.sk/video/')) { $Word = '<embed src="http://www.ceknito.sk/style/vp.swf" type="application/x-shockwave-flash" width="440" height="365" flashvars="fid=000a/'.substr(stristr($Word, '/video/'), 7).'" allowFullScreen="true" />'; } else if (stripos($Word, 'vii.sk/video/')) { $Word = '<iframe src="http://www.vii.sk/embed/'.substr(stristr($Word, 'vii.sk/video/'), 13).'" width="448" height="336" frameborder="0"></iframe>'; } else if (stripos($Word, 'vimeo.com/')) { $Word = '<embed src="http://vimeo.com/moogaloop.swf?clip_id='.substr(stristr($Word, 'vimeo.com/'), 10).'&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="448" height="336"></embed>'; } else if (stripos($Word, 'videos.onsmash.com/v/')) { $Word = '<embed src="http://videos.onsmash.com/e/'.substr(stristr($Word, '/v/'), 3).'" type="application/x-shockwave-flash" allowFullScreen="true" width="448" height="374"></embed>'; } else { $Word = '<a href="'.$Word.'" target="_blank" rel="nofollow">'.$Word.'</a>'; }; } unset($Word); $Line = implode(" ", $SplitWords); } unset($Line); $String = implode("<br />", $SplitLines); return $String; } } $ExtendedTextFormatter = $Context->ObjectFactory->NewObject($Context, "ExtendedTextFormatter"); $Context->StringManipulator->Formatters[$Configuration["DEFAULT_FORMAT_TYPE"]]->AddChildFormatter($ExtendedTextFormatter); $Head->AddStyleSheet('extensions/MakeItSimpleTextFormatter/style.css'); }

thanks! ^^

Comments

  • Options
    ok so i've been digging up information on this..

    I've seen some previous attempts to try this, like changing the style for the first comment, but that was done inside the comments.php.

    I also found the $RowNumber variable. Could it be used inside this extension?
  • Options
    x00x00 MVP
    edited April 2009
    if (in_array($Context->SelfUrl, array("comments.php", "post.php"))) { ... $firstCommentID = 0; function Discussion_GetFirst(&$DataSet){ global $firstCommentID; $firstCommentID = $DataSet->FirstCommentID; } $Context->AddToDelegate("Discussion", "PostGetPropertiesFromDataSet", "Discussion_GetFirst"); ... class SomeFormatter extends StringFormatter { function Parse ($String, $Object, $FormatPurpose) { global $firstCommentID; if($firstCommentID && $Object->CommentID==$firstCommentID && $FormatPurpose == FORMAT_STRING_FOR_DISPLAY){ //Do your parsing } return $String; } ...

    grep is your friend.

  • Options
    edited April 2009
    wow thanks a lot!! I'm working on it atm
    thing is, what i really want is to have the parser work for images and videos for the 1st comment and for the other comments just parses the links normally without embedding images or videos.

    // edit: ok the code i pasted here was rubbish :-)

    so, any ideas how to implement it? ^^
  • Options
    x00x00 MVP
    edited April 2009
    class ExtendedTextFormatter extends StringFormatter {

    function Parse ($String, $Object, $FormatPurpose) {
    global $firstCommentID;
    if ($FormatPurpose == FORMAT_STRING_FOR_DISPLAY){
    if($firstCommentID && $Object->CommentID==$firstCommentID){
    $String = $this->AutoLink($sReturn,true);
    }else{
    $String = $this->AutoLink($sReturn,false);
    }
    }
    return $String;
    }

    function AutoLink($String, $First) {
    $String = str_replace(array(""","&"),array('"','&'),$String);

    $SplitLines = explode("
    ", $String); foreach ($SplitLines as &$Line) { $SplitWords = explode(" ", $Line); foreach ($SplitWords as &$Word) {

    grep is your friend.

  • Options
    if(strncasecmp($Word, 'http://', 7) == 0){
    if ($First){
    if (strcasecmp(substr($Word, strlen($Word) - 4), '.jpg') == 0 || strcasecmp(substr($Word, strlen($Word) - 5), '.jpeg') == 0 || strcasecmp(substr($Word, strlen($Word) - 4), '.gif') == 0 || strcasecmp(substr($Word, strlen($Word) - 4), '.png') == 0) {
    $Word = 'image';
    ...
    } else {
    $Word = '->link<-</a>';
    }
    }else{

    grep is your friend.

  • Options
    I'm not sure why it was giving me so much trouble posting that. It is all one thing

    grep is your friend.

  • Options
    thx \x00

    gonna try to implement :)
  • Options
    sorry replace $sReturn with $String, $sReturn shouldn't have been in the original it is erroneous

    grep is your friend.

  • Options
    thx a lot man, made my day! Fully working!! Here's the full code for anyone interested (modified by X00, with a bit of customization in display by me):


    <?php
    /*
    Extension Name: Make It Simple Text Formatter
    Extension Url: http://lussumo.com/addons/index.php?PostBackAction=AddOn&AddOnID=399
    Description: Extends the default text formatter to autolink urls and auto insert images and videos.
    Version: 1.12
    Author: Gambit
    Author Url: http://www.burrrn.net/

    Copyright 2008 Gambit
    This file is part of Lussumo's Software Library.
    Lussumo's Software Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    Lussumo's Software Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    The latest source code is available at www.lussumo.com
    */

    if (in_array($Context->SelfUrl, array("comments.php", "post.php"))) {

    $firstCommentID = 0;

    function Discussion_GetFirst(&$DataSet){
    global $firstCommentID;
    $firstCommentID = $DataSet->FirstCommentID;
    }

    $Context->AddToDelegate("Discussion", "PostGetPropertiesFromDataSet", "Discussion_GetFirst");



    // An implementation of the string filter interface for plain text strings

    class ExtendedTextFormatter extends StringFormatter {

    function Parse ($String, $Object, $FormatPurpose) {

    global $firstCommentID;

    if ($FormatPurpose == FORMAT_STRING_FOR_DISPLAY){

    if($firstCommentID && $Object->CommentID==$firstCommentID){ $String = $this->AutoLink($String,true); }

    else { $String = $this->AutoLink($String,false); }
    }

    return $String;

    }





    function AutoLink($String, $First) {

    $String = str_replace(array(""","&"),array('"','&'),$String);

    $SplitLines = explode("
    ", $String);

    foreach ($SplitLines as &$Line) {

    $SplitWords = explode(" ", $Line);

    foreach ($SplitWords as &$Word) {

    if(strncasecmp($Word, 'http://', 7) == 0) {
    if ($First){
    if (strcasecmp(substr($Word, strlen($Word) - 4), '.jpg') == 0 || strcasecmp(substr($Word, strlen($Word) - 5), '.jpeg') == 0 || strcasecmp(substr($Word, strlen($Word) - 4), '.gif') == 0 || strcasecmp(substr($Word, strlen($Word) - 4), '.png') == 0) {
    $Word = '

    image 500) {this.width = 500;}" class="discImg" />';
    } else if (stripos($Word, 'youtube.com/watch?v=')) {
    $Word = '';
    } else if (stripos($Word, 'dailymotion.com/video/')) {
    $IDStart = strpos($Word, 'video/') + 6;
    $IDLength = strpos($Word, '_') - $IDStart;
    $DailyMotionID = substr($Word, $IDStart, $IDLength);
    $Word = '';
    } else if (stripos($Word, 'video.google.com/videoplay?docid=')) {
    $Word = ' ';
    } else if (stripos($Word, 'index.cfm?fuseaction=vids.individual&videoid')) {
    $Word = '';
    } else if (stripos($Word, 'spike.com/video/')) {
    $Word = ' ';
    } else if (stripos($Word, 'redlasso.com/ClipPlayer.aspx?id=')) {
    $Word = '';
    } else if (stripos($Word, 'ceknito.sk/video/')) {
    $Word = '';
    } else if (stripos($Word, 'vii.sk/video/')) {
    $Word = '';
    } else if (stripos($Word, 'vimeo.com/')) {
    $Word = '';
    } else if (stripos($Word, 'videos.onsmash.com/v/')) {
    $Word = '';
    } else {
    $Word = ''.$Word.'';
    };


    } else { $Word = ''.$Word.''; }
    }
    }
    unset($Word);
    $Line = implode(" ", $SplitWords);
    }
    unset($Line);

    $String = implode("
    ", $SplitLines); return $String; } } $ExtendedTextFormatter = $Context->ObjectFactory->NewObject($Context, "ExtendedTextFormatter"); $Context->StringManipulator->Formatters[$Configuration["DEFAULT_FORMAT_TYPE"]]->AddChildFormatter($ExtendedTextFormatter); } ?>
  • Options
    no worries

    grep is your friend.

Sign In or Register to comment.