コード例 #1
0
 /**
  * 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();
 }
コード例 #2
0
ファイル: class.hooks.php プロジェクト: vanilla/community
 /**
  * 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');
 }