/**
  * Set the icon for an addon.
  *
  * @param int $AddonID Specified addon id.
  * @throws Exception Addon not found.
  */
 public function icon($AddonID = '')
 {
     $Session = Gdn::session();
     if (!$Session->isValid()) {
         $this->Form->addError('You must be authenticated in order to use this form.');
     }
     $Addon = $this->AddonModel->getID($AddonID);
     if (!$Addon) {
         throw notFoundException('Addon');
     }
     if ($Session->UserID != $Addon['InsertUserID']) {
         $this->permission('Addons.Addon.Manage');
     }
     $this->addModule('AddonHelpModule', 'Panel');
     $this->Form->setModel($this->AddonModel);
     $this->Form->addHidden('AddonID', $AddonID);
     if ($this->Form->authenticatedPostBack()) {
         $UploadImage = new Gdn_UploadImage();
         try {
             // Validate the upload
             $imageLocation = $UploadImage->validateUpload('Icon');
             $TargetImage = $this->saveIcon($imageLocation);
         } catch (Exception $ex) {
             $this->Form->addError($ex);
         }
         // If there were no errors, remove the old picture and insert the picture
         if ($this->Form->errorCount() == 0) {
             if ($Addon['Icon']) {
                 $UploadImage->delete($Addon['Icon']);
             }
             $this->AddonModel->save(array('AddonID' => $AddonID, 'Icon' => $TargetImage));
         }
         // If there were no problems, redirect back to the addon
         if ($this->Form->errorCount() == 0) {
             $this->RedirectUrl = Url('/addon/' . AddonModel::slug($Addon));
         }
     }
     $this->render();
 }
Example #2
0
 /**
  * Provide notification when someone talks about your addon.
  *
  * @param DiscussionModel $Sender
  * @param array $Args
  */
 public function discussionModel_beforeNotification_handler($Sender, $Args)
 {
     $Discussion = $Args['Discussion'];
     $Activity = $Args['Activity'];
     if (!val('AddonID', $Discussion)) {
         return;
     }
     $AddonModel = new AddonModel();
     $Addon = $AddonModel->getID($Discussion['AddonID'], DATASET_TYPE_ARRAY);
     if (val('InsertUserID', $Addon) == Gdn::session()->UserID) {
         return;
     }
     $ActivityModel = $Args['ActivityModel'];
     $Activity['NotifyUserID'] = $Addon['InsertUserID'];
     $Activity['HeadlineFormat'] = '{ActivityUserID,user} asked a <a href="{Url,html}">question</a> about the <a href="{Data.AddonUrl,exurl}">{Data.AddonName,html}</a> addon.';
     $Activity['Data']['AddonName'] = $Addon['Name'];
     $Activity['Data']['AddonUrl'] = '/addon/' . urlencode(AddonModel::slug($Addon, false));
     $ActivityModel->queue($Activity, 'AddonComment');
 }
Example #3
0
 /**
  * Get an addon based on its slug in the following form:
  *  - AddonID[-AddonName]
  *  - AddonType-AddonKey[-Version]
  *
  * @param string|int $Slug The slug to lookup
  * @param bool $GetVersions Whether or not to add an array of versions to the result.
  * @return array
  */
 public function getSlug($slug, $getVersions = false)
 {
     if (is_numeric($slug)) {
         $addon = $this->getID($slug, false, ['GetVersions' => $getVersions]);
     } else {
         // This is a string identifier for the addon.
         $parts = explode('-', $slug, 3);
         $key = val(0, $parts);
         if (is_numeric($key)) {
             $addon = $this->getID($key, false, ['GetVersions' => $getVersions]);
         } else {
             $type = strtolower(val(1, $parts));
             $typeID = val($type, self::$Types, 0);
             $version = val(2, $parts);
             $addon = $this->getID(array($key, $typeID, $version), false, ['GetVersions' => $getVersions]);
         }
     }
     if (!$addon) {
         return false;
     }
     $addon['Releases'] = [];
     $addon['Prereleases'] = [];
     if ($getVersions) {
         $maxVersion = valr('Versions.0', $addon);
         $foundMax = false;
         $viewingVersion = false;
         if (is_array(val('Versions', $addon))) {
             foreach ($addon['Versions'] as $version) {
                 // Find the version we are looking at.
                 $versionSlug = AddonModel::slug($addon, $version);
                 if ($versionSlug == $slug && $viewingVersion === false) {
                     $viewingVersion = $version;
                 }
                 // Separate releases & prereleases.
                 if (AddonModel::isReleaseVersion($version['Version'])) {
                     $addon['Releases'][] = $version;
                     // Find the latest stable version.
                     if (!$foundMax) {
                         $maxVersion = $version;
                         $foundMax = true;
                     }
                 } elseif ($foundMax === false) {
                     // Only list prereleases new than the current stable.
                     $addon['Prereleases'][] = $version;
                 }
             }
         }
         if ($viewingVersion === false) {
             $viewingVersion = $maxVersion;
         }
         $addon['CurrentAddonVersionID'] = $maxVersion['AddonVersionID'];
         $addon = array_merge($addon, (array) $viewingVersion);
         $addon['Slug'] = AddonModel::slug($addon, $viewingVersion);
     }
     return $addon;
 }
Example #4
0
$Access = $this->data('Slug') ? urlencode($this->data('Slug')) : $AddonID;
?>
    <description><?php 
echo Gdn_Format::text($this->Head->title());
?>
</description>
    <language><?php 
echo c('Garden.Locale', 'en-US');
?>
</language>
    <atom:link href="<?php 
echo url('/addon/' . $Access . '/follow.rss');
?>
" rel="self" type="application/rss+xml" />
<?php 
$SlugBase = AddonModel::slug($this->Data, FALSE);
foreach ($this->data('Versions') as $Version) {
    $VersionSlug = urlencode($SlugBase . '-' . $Version['Version']);
    ?>
    <item>
        <title><?php 
    echo Gdn_Format::text($this->data('Name') . ' ' . $Version['Version']);
    ?>
</title>
        <link><?php 
    echo url('/addon/' . $VersionSlug, TRUE);
    ?>
</link>
        <pubDate><?php 
    echo date(DATE_RSS, Gdn_Format::toTimeStamp($Version['DateInserted']));
    ?>
Example #5
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 #6
0
    if (count($versions) > 0) {
        ?>
            <div class="Box AddonBox VersionsBox">
                <h3><?php 
        echo t('Prerelease (unstable)');
        ?>
</h3>
                <table class="VersionsTable">
                <?php 
        $i = 1;
        foreach ($versions as $version) {
            if ($i > 3) {
                break;
            }
            $i++;
            $url = url('/addon/' . AddonModel::slug($this->Data, false) . '-' . $version['Version']);
            $deleteOption = '';
            if (checkPermission('Addons.Addon.Manage')) {
                $deleteOption = ' ' . anchor('x', '/addon/deleteversion/' . $version['AddonVersionID'], 'Popup Alert DeleteVersion');
            }
            echo '<tr>' . '<td>' . anchor(htmlspecialchars($version['Version']), $url) . '</td>' . '<td class="DateColumn">' . anchor(htmlspecialchars(Gdn_Format::date($version['DateInserted'])), $url) . $deleteOption . '</td>' . '</tr>';
        }
        ?>
                </table>
            </div>
            <?php 
    }
    if ($session->isValid()) {
        echo anchor('Ask a Question', 'post/discussion?AddonID=' . $addonID, 'Button BigButton');
    }
    ?>