public function pluginController_quoteMention_create($sender, $discussionID, $commentID, $username)
 {
     $sender->deliveryMethod(DELIVERY_METHOD_JSON);
     $user = Gdn::userModel()->getByUsername($username);
     $discussionModel = new DiscussionModel();
     $discussion = $discussionModel->getID($discussionID);
     if (!$user || !$discussion) {
         throw notFoundException();
     }
     // Make sure this endpoint can't be used to snoop around.
     $sender->permission('Vanilla.Discussions.View', true, 'Category', $discussion->PermissionCategoryID);
     // Find the previous comment of the mentioned user in this discussion.
     $item = Gdn::sql()->getWhere('Comment', ['DiscussionID' => $discussion->DiscussionID, 'InsertUserID' => $user->UserID, 'CommentID <' => $commentID], 'CommentID', 'desc', 1)->firstRow();
     // The items ID in the DOM used for highlighting.
     if ($item) {
         $target = '#Comment_' . $item->CommentID;
         // The mentioned user might be the discussion creator.
     } elseif ($discussion->InsertUserID == $user->UserID) {
         $item = $discussion;
         $target = '#Discussion_' . $item->DiscussionID;
     }
     if (!$item) {
         // A success response code always means that a comment was found.
         $sender->statusCode(404);
     }
     $sender->renderData($item ? ['html' => nl2br(sliceString(Gdn_Format::plainText($item->Body, $item->Format), c('QuoteMention.MaxLength', 400))), 'target' => $target] : []);
 }
Example #2
0
    /**
     * Generates html output of $Content array
     *
     * @param array|object $Content
     * @param PromotedContentModule $Sender
     */
    function writePromotedContent($Content, $Sender)
    {
        static $UserPhotoFirst = NULL;
        if ($UserPhotoFirst === null) {
            $UserPhotoFirst = c('Vanilla.Comment.UserPhotoFirst', true);
        }
        $ContentType = val('RecordType', $Content);
        $ContentID = val("{$ContentType}ID", $Content);
        $Author = val('Author', $Content);
        $ContentURL = val('Url', $Content);
        $Sender->EventArguments['Content'] =& $Content;
        $Sender->EventArguments['ContentUrl'] =& $ContentURL;
        ?>
        <div id="<?php 
        echo "Promoted_{$ContentType}_{$ContentID}";
        ?>
" class="<?php 
        echo CssClass($Content);
        ?>
">
            <div class="AuthorWrap">
         <span class="Author">
            <?php 
        if ($UserPhotoFirst) {
            echo userPhoto($Author);
            echo userAnchor($Author, 'Username');
        } else {
            echo userAnchor($Author, 'Username');
            echo userPhoto($Author);
        }
        $Sender->fireEvent('AuthorPhoto');
        ?>
         </span>
         <span class="AuthorInfo">
            <?php 
        echo ' ' . WrapIf(htmlspecialchars(val('Title', $Author)), 'span', array('class' => 'MItem AuthorTitle'));
        echo ' ' . WrapIf(htmlspecialchars(val('Location', $Author)), 'span', array('class' => 'MItem AuthorLocation'));
        $Sender->fireEvent('AuthorInfo');
        ?>
         </span>
            </div>
            <div class="Meta CommentMeta CommentInfo">
         <span class="MItem DateCreated">
            <?php 
        echo anchor(Gdn_Format::date($Content['DateInserted'], 'html'), $ContentURL, 'Permalink', array('rel' => 'nofollow'));
        ?>
         </span>
                <?php 
        // Include source if one was set
        if ($Source = val('Source', $Content)) {
            echo wrap(sprintf(t('via %s'), t($Source . ' Source', $Source)), 'span', array('class' => 'MItem Source'));
        }
        $Sender->fireEvent('ContentInfo');
        ?>
            </div>
            <div
                class="Title"><?php 
        echo anchor(Gdn_Format::text(sliceString($Content['Name'], $Sender->TitleLimit), false), $ContentURL, 'DiscussionLink');
        ?>
</div>
            <div class="Body">
                <?php 
        echo anchor(htmlspecialchars(sliceString(Gdn_Format::plainText($Content['Body'], $Content['Format']), $Sender->BodyLimit)), $ContentURL, 'BodyLink');
        $Sender->fireEvent('AfterPromotedBody');
        // separate event to account for less space.
        ?>
            </div>
        </div>
    <?php 
    }
 function searchExcerpt($PlainText, $SearchTerms, $Length = 200, $Mark = true)
 {
     if (empty($SearchTerms)) {
         return substrWord($PlainText, 0, $Length);
     }
     if (is_string($SearchTerms)) {
         $SearchTerms = preg_split('`[\\s|-]+`i', $SearchTerms);
     }
     // Split the string into lines.
     $Lines = explode("\n", $PlainText);
     // Find the first line that includes a search term.
     foreach ($Lines as $i => &$Line) {
         $Line = trim($Line);
         if (!$Line) {
             continue;
         }
         foreach ($SearchTerms as $Term) {
             if (!$Term) {
                 continue;
             }
             if (($Pos = mb_stripos($Line, $Term)) !== false) {
                 $Line = substrWord($Line, $Term, $Length);
                 if ($Mark) {
                     return markString($SearchTerms, $Line);
                 } else {
                     return $Line;
                 }
             }
         }
     }
     // No line was found so return the first non-blank line.
     foreach ($Lines as $Line) {
         if ($Line) {
             return sliceString($Line, $Length);
         }
     }
     return '';
 }
Example #4
0
    exit;
}
?>
<div class="Box BoxDrafts">
    <?php 
echo panelHeading(t('My Drafts'));
?>
    <ul class="PanelInfo PanelDiscussions">
        <?php 
foreach ($this->Data->result() as $Draft) {
    $EditUrl = !is_numeric($Draft->DiscussionID) || $Draft->DiscussionID <= 0 ? '/post/editdiscussion/0/' . $Draft->DraftID : '/post/editcomment/0/' . $Draft->DraftID;
    ?>
            <li>
                <strong><?php 
    echo anchor($Draft->Name, $EditUrl);
    ?>
</strong>
                <?php 
    echo anchor(sliceString(Gdn_Format::text($Draft->Body), 200), $EditUrl, 'DraftCommentLink');
    ?>
            </li>
        <?php 
}
?>
        <li class="ShowAll"><?php 
echo anchor(t('↳ Show All'), 'drafts');
?>
</li>
    </ul>
</div>
Example #5
0
File: all.php Project: R-J/vanilla
               <div class="ItemContent Category"><div class="Options">' . getOptions($Category, $this) . '</div>' . Gdn_Format::text($Category->Name) . '</div>
            </li>';
                $Alt = FALSE;
            } else {
                $LastComment = UserBuilder($Category, 'Last');
                $AltCss = $Alt ? ' Alt' : '';
                $Alt = !$Alt;
                $CatList .= '<li id="Category_' . $CategoryID . '" class="' . $CssClass . '">
               <div class="ItemContent Category">' . '<div class="Options">' . getOptions($Category, $this) . '</div>' . CategoryPhoto($Category) . '<div class="TitleWrap">' . anchor(Gdn_Format::text($Category->Name), CategoryUrl($Category), 'Title') . '</div>
                  <div class="CategoryDescription">' . $Category->Description . '</div>
                  <div class="Meta">
                     <span class="MItem RSS">' . anchor(img('applications/dashboard/design/images/rss.gif', array('alt' => T('RSS Feed'))), '/categories/' . $Category->UrlCode . '/feed.rss', '', array('title' => T('RSS Feed'))) . '</span>
                     <span class="MItem DiscussionCount">' . sprintf(PluralTranslate($Category->CountDiscussions, '%s discussion html', '%s discussions html', t('%s discussion'), t('%s discussions')), BigPlural($Category->CountDiscussions, '%s discussion')) . '</span>
                     <span class="MItem CommentCount">' . sprintf(PluralTranslate($Category->CountComments, '%s comment html', '%s comments html', t('%s comment'), t('%s comments')), BigPlural($Category->CountComments, '%s comment')) . '</span>';
                if ($Category->LastTitle != '') {
                    $CatList .= '<span class="MItem LastDiscussionTitle">' . sprintf(t('Most recent: %1$s by %2$s'), anchor(Gdn_Format::text(sliceString($Category->LastTitle, 40)), $Category->LastUrl), userAnchor($LastComment)) . '</span>' . '<span class="MItem LastCommentDate">' . Gdn_Format::date($Category->LastDateInserted) . '</span>';
                }
                // If this category is one level above the max display depth, and it
                // has children, add a replacement string for them.
                if ($MaxDisplayDepth > 0 && $Category->Depth == $MaxDisplayDepth - 1 && $Category->TreeRight - $Category->TreeLeft > 1) {
                    $CatList .= '{ChildCategories}';
                }
                $CatList .= '</div>
               </div>
            </li>';
            }
        }
    }
}
// If there are any remaining child categories that have been collected, do
// the replacement one last time.
Example #6
0
<?php

if (!defined('APPLICATION')) {
    exit;
}
foreach ($this->DraftData->resultArray() as $Draft) {
    $Offset = val('CountComments', $Draft, 0);
    if ($Offset > c('Vanilla.Comments.PerPage', 30)) {
        $Offset -= c('Vanilla.Comments.PerPage', 30);
    } else {
        $Offset = 0;
    }
    $draftID = val('DraftID', $Draft);
    $discussionID = val('DiscussionID', $Draft);
    $excerpt = sliceString(Gdn_Format::text(val('Body', $Draft)), 200);
    $isDiscussion = !is_numeric($discussionID) || $discussionID <= 0;
    $orphaned = !val('DiscussionExists', $Draft);
    $editUrl = $isDiscussion || $orphaned ? '/post/editdiscussion/0/' . $draftID : '/discussion/' . $discussionID . '/' . $Offset . '/#Form_Comment';
    $deleteUrl = 'vanilla/drafts/delete/' . $draftID . '/' . Gdn::session()->transientKey() . '?Target=' . urlencode($this->SelfUrl);
    ?>
    <li class="Item Draft">
        <div
            class="Options"><?php 
    echo anchor(t('Draft.Delete', 'Delete'), $deleteUrl, 'Delete');
    ?>
</div>
        <div class="ItemContent">
            <?php 
    echo anchor(Gdn_Format::text(val('Name', $Draft), false), $editUrl, 'Title DraftLink');
    ?>
            <?php 
Example #7
0
    while (strlen($string) > $maxCharacters) {
        $temp = substr($string, 0, $maxCharacters);
        $pos = strrpos($temp, "+");
        $strings[$i] = substr($string, 0, $pos);
        $string = substr($string, $pos);
        $i++;
    }
    $strings[$i] = $string;
    return $strings;
}
if ($argc != 3) {
    die("Wrong parameter count. Please provice the language as first and the string to say as second parameter. E. g.: GoogleTTS.php de \"Hello World\"");
}
$language = $argv[1];
$path = "/var/lib/homegear/tmp/sonos/";
if (!file_exists($path)) {
    if (!mkdir($path, 0777, true)) {
        die("Could not create directory {$path}");
    }
}
$words = urlencode($argv[2]);
$filename = $path . md5($words) . "-" . $language . ".mp3";
if (!file_exists($filename)) {
    $words = sliceString($words, 100);
    $data = array();
    for ($i = 0; $i < count($words); $i++) {
        $data[$i] = file_get_contents('http://translate.google.com/translate_tts?q=' . $words[$i] . '&tl=' . $language . '&ie=UTF-8');
    }
    file_put_contents($filename, $data);
}
echo $filename;
Example #8
0
                $LastPhoto = userPhoto($User);
                if ($LastPhoto) {
                    break;
                }
            } elseif (!$LastPhoto) {
                $LastPhoto = userPhoto($User);
            }
        }
    }
    $CssClass = 'Item';
    $CssClass .= $Alt ? ' Alt' : '';
    $CssClass .= $Conversation->CountNewMessages > 0 ? ' New' : '';
    $CssClass .= $LastPhoto != '' ? ' HasPhoto' : '';
    $CssClass .= ' ' . ($Conversation->CountNewMessages <= 0 ? 'Read' : 'Unread');
    $JumpToItem = $Conversation->CountMessages - $Conversation->CountNewMessages;
    $Message = sliceString(Gdn_Format::plainText($Conversation->LastBody, $Conversation->LastFormat), 100);
    if (stringIsNullOrEmpty(trim($Message))) {
        $Message = t('Blank Message');
    }
    $this->EventArguments['Conversation'] = $Conversation;
    ?>
    <li class="<?php 
    echo $CssClass;
    ?>
">
        <?php 
    $Names = ConversationModel::participantTitle($Conversation, false);
    ?>
        <div class="ItemContent Conversation">
            <?php 
    $Url = '/messages/' . $Conversation->ConversationID . '/#Item_' . $JumpToItem;
Example #9
0
 /**
  * Hook into the rendering of each discussion link
  *
  * How did we find this event? We know we're trying to display a line of text when each discussion is rendered
  * on the /discussions/ page. That page corresponds to the DiscussionsController::Index() method. This method,
  * by default, renders the views/discussions/index.php view. That view contains this line:
  *     <?php include($this->FetchViewLocation('discussions')); ?>
  *
  * So we look inside views/discussions/discussions.php. We find a loop that calls WriteDiscussion() for each
  * discussion in the list. WriteDiscussion() fires several events each time it is called. One of those events
  * is called "AfterDiscussionTitle". Since we know that the parent controller context is "DiscussionsController",
  * and that the event's name is "AfterDiscussionTitle", it is easy to see that our handler method should be called
  *
  *      discussionsController_afterDiscussionTitle_handler()
  */
 public function discussionsController_afterDiscussionTitle_handler($sender)
 {
     /*
     echo "<pre>";
     print_r($sender->EventArguments['Discussion']);
     echo "</pre>";
     */
     /*
      * The 'c' function allows plugins to access the config file. In this call, we're looking for a specific setting
      * called 'Plugin.Example.TrimSize', but defaulting to a value of '100' if the setting cannot be found.
      */
     $trimSize = c('Plugin.Example.TrimSize', 100);
     /*
      * We're using this setting to allow conditional display of the excerpts. We have 3 settings: 'all', 'announcements',
      * 'discussions'. They do what you'd expect!
      */
     $renderCondition = c('Plugin.Example.RenderCondition', 'all');
     $type = val('Announce', $sender->EventArguments['Discussion']) == '1' ? "announcement" : "discussion";
     $compareType = $type . 's';
     if ($renderCondition == "all" || $compareType == $renderCondition) {
         /*
          * Here, we remove any HTML from the Discussion Body, trim it down to a pre-defined length, re-encode htmlentities
          * and then output it to discussions list inside a div with a class of 'ExampleDescription'
          */
         $discussionBody = htmlentities(sliceString(html_entity_decode(strip_tags($sender->EventArguments['Discussion']->Body)), $trimSize));
         echo wrap($discussionBody, 'div', array('class' => "ExampleDescription"));
     }
 }
Example #10
0
        ?>
            <li class="Item" rel="<?php 
        echo url("/messages/{$Row['ConversationID']}#Message_{$Row['LastMessageID']}");
        ?>
">
                <div class="Author Photo"><?php 
        echo userPhoto($PhotoUser);
        ?>
</div>
                <div class="ItemContent">
                    <b class="Subject"><?php 
        echo anchor($Subject, "/messages/{$Row['ConversationID']}#Message_{$Row['LastMessageID']}");
        ?>
</b>
                    <?php 
        $Excerpt = sliceString(Gdn_Format::plainText($Row['LastBody'], $Row['LastFormat']), 80);
        echo wrap(nl2br(htmlspecialchars($Excerpt)), 'div', array('class' => 'Excerpt'));
        ?>
                    <div class="Meta">
                        <?php 
        echo ' <span class="MItem">' . plural($Row['CountMessages'], '%s message', '%s messages') . '</span> ';
        if ($Row['CountNewMessages'] > 0) {
            echo ' <strong class="HasNew"> ' . plural($Row['CountNewMessages'], '%s new', '%s new') . '</strong> ';
        }
        echo ' <span class="MItem">' . Gdn_Format::date($Row['LastDateInserted']) . '</span> ';
        ?>
                    </div>
                </div>
            </li>
        <?php 
    }
Example #11
0
/**
 *
 *
 * @param $Addon
 * @param $Alt
 */
function writeAddon($Addon, $Alt)
{
    $Url = '/addon/' . AddonModel::slug($Addon, FALSE);
    ?>
    <li class="Item AddonRow<?php 
    echo $Alt;
    ?>
">
        <?php 
    if ($Addon->Icon != '') {
        echo '<a class="Icon" href="' . url($Url) . '"><div class="IconWrap"><img src="' . Gdn_Upload::url($Addon->Icon) . '" /></div></a>';
    }
    ?>
        <div class="ItemContent">
            <?php 
    echo anchor(htmlspecialchars($Addon->Name), $Url, 'Title');
    echo '<div class="Description">', anchor(htmlspecialchars(sliceString(Gdn_Format::text($Addon->Description), 300)), $Url), '</div>';
    ?>
            <div class="Meta">
                <span class="TypeTag"><?php 
    echo $Addon->Type;
    ?>
</span>
                <?php 
    if ($Addon->Type === 'Locale') {
        ?>
                    <?php 
        if (!is_null($Addon->EnName)) {
            ?>
                <span class="EnName">
                    Name (en)
                    <span><?php 
            echo htmlspecialchars($Addon->EnName);
            ?>
</span>
                </span>
                    <?php 
        }
        ?>
                    <?php 
        if (!is_null($Addon->PercentComplete)) {
            ?>
                <span class="PercentComplete">
                    Translated
                    <span><?php 
            echo (int) $Addon->PercentComplete . '%';
            ?>
</span>
                </span>
                    <?php 
        }
        ?>
                <?php 
    } else {
        ?>
                <span class="Version">
                    Version
                    <span><?php 
        echo htmlspecialchars($Addon->Version);
        ?>
</span>
                </span>
                <?php 
    }
    ?>
                <span class="Author">
                    Author
                    <span><?php 
    echo val('Official', $Addon) ? t('Vanilla Staff') : htmlspecialchars($Addon->InsertName);
    ?>
</span>
                </span>
                <span class="Downloads">
                    Downloads
                    <span><?php 
    echo number_format($Addon->CountDownloads);
    ?>
</span>
                </span>
                <span class="Updated">
                    Updated
                    <span><?php 
    echo Gdn_Format::date($Addon->DateUpdated, 'html');
    ?>
</span>
                </span>
            </div>
        </div>
    </li>
<?php 
}
Example #12
0
            <?php 
    foreach ($this->data('Conversations') as $Row) {
        ?>
                <li id="Conversation_<?php 
        echo $Row['ConversationID'];
        ?>
" class="Item">
                    <?php 
        $JumpToItem = $Row['CountMessages'] - $Row['CountNewMessages'];
        $Url = "/messages/{$Row['ConversationID']}/#Item_{$JumpToItem}";
        if ($SubjectsVisible && $Row['Subject']) {
            $Message = htmlspecialchars($Row['Title']);
        } elseif ($Row['Format'] == 'Text') {
            $Message = sliceString(Gdn_Format::to($Row['LastMessage'], $Conversation['Format']), 100);
        } else {
            $Message = sliceString(Gdn_Format::text(Gdn_Format::to($Row['LastMessage'], $Row['Format']), false), 100);
        }
        if (stringIsNullOrEmpty(trim($Message))) {
            $Message = t('Blank Message');
        }
        echo anchor($Message, $Url, 'ConversationLink');
        ?>
                    <div class="Meta">
            <span class="MItem Participants">
               <?php 
        $First = TRUE;
        foreach ($Row['Participants'] as $User) {
            if ($First) {
                $First = FALSE;
            } else {
                echo ', ';