Автор: Marcel Werk
Наследование: extends DatabaseObject
Пример #1
0
 function recordInbound()
 {
     $strJson = file_get_contents("php://input");
     try {
         $arrResponse = Convert::json2array($strJson);
         if ($savedMessage = PostmarkMessage::get()->filter('MessageID', $arrResponse['MessageID'])->first()) {
             return;
         }
         $hash = $arrResponse['ToFull'][0]['MailboxHash'];
         $hashParts = explode('+', $hash);
         $lastMessage = PostmarkMessage::get()->filter(array('UserHash' => $hashParts[0], 'MessageHash' => $hashParts[1]))->first();
         $fromCustomer = PostmarkHelper::find_or_make_client($arrResponse['From']);
         $inboundSignature = null;
         if ($lastMessage) {
             $inboundSignature = $lastMessage->From();
         } else {
             if (!$lastMessage && isset($arrResponse['To'])) {
                 $inboundSignature = PostmarkSignature::get()->filter('Email', $arrResponse['To'])->first();
             }
         }
         if (!$inboundSignature) {
             $inboundSignature = PostmarkSignature::get()->filter('IsDefault', 1)->first();
         }
         $message = new PostmarkMessage(array('Subject' => $arrResponse['Subject'], 'Message' => $arrResponse['HtmlBody'], 'ToID' => 0, 'MessageID' => $arrResponse['MessageID'], 'InReplyToID' => $lastMessage ? $lastMessage->ID : 0, 'FromCustomerID' => $fromCustomer ? $fromCustomer->ID : 0, 'InboundToID' => $inboundSignature ? $inboundSignature->ID : 0));
         $message->write();
         if (isset($arrResponse['Attachments']) && count($arrResponse['Attachments'])) {
             foreach ($arrResponse['Attachments'] as $attachment) {
                 $attachmentObject = new Attachment(array('Content' => $attachment['Content'], 'FileName' => $attachment['Name'], 'ContentType' => $attachment['ContentType'], 'Length' => $attachment['ContentLength'], 'ContentID' => $attachment['ContentID'], 'PostmarkMessageID' => $message->ID));
                 $attachmentObject->write();
             }
         }
     } catch (Exception $e) {
     }
     return 'OK';
 }
 public function store($notebookId, $noteId, $versionId)
 {
     $note = self::getNote($notebookId, $noteId, $versionId);
     if ($note->pivot->umask < PaperworkHelpers::UMASK_READWRITE) {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('message' => 'Permission Error'));
     }
     if (Input::hasFile('file') && Input::file('file')->isValid() || Input::json() != null && Input::json() != "") {
         $fileUpload = null;
         $newAttachment = null;
         if (Input::hasFile('file')) {
             $fileUpload = Input::file('file');
             $newAttachment = new Attachment(array('filename' => $fileUpload->getClientOriginalName(), 'fileextension' => $fileUpload->getClientOriginalExtension(), 'mimetype' => $fileUpload->getMimeType(), 'filesize' => $fileUpload->getSize()));
         } else {
             $fileUploadJson = Input::json();
             $fileUpload = base64_decode($fileUploadJson->get('file'));
             $newAttachment = new Attachment(array('filename' => $fileUploadJson->get('clientOriginalName'), 'fileextension' => $fileUploadJson->get('clientOriginalExtension'), 'mimetype' => $fileUploadJson->get('mimeType'), 'filesize' => count($fileUpload)));
         }
         $newAttachment->save();
         // Move file to (default) /app/storage/attachments/$newAttachment->id/$newAttachment->filename
         $destinationFolder = Config::get('paperwork.attachmentsDirectory') . '/' . $newAttachment->id;
         if (!File::makeDirectory($destinationFolder, 0700)) {
             $newAttachment->delete();
             return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('message' => 'Internal Error'));
         }
         // Get Version with versionId
         //$note = self::getNote($notebookId, $noteId, $versionId);
         $tmp = $note ? $note->version()->first() : null;
         $version = null;
         if (is_null($tmp)) {
             $newAttachment->delete();
             File::deleteDirectory($destinationFolder);
             return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array('message' => 'version->first'));
         }
         while (!is_null($tmp)) {
             if ($tmp->id == $versionId || $versionId == 0) {
                 $version = $tmp;
                 break;
             }
             $tmp = $tmp->previous()->first();
         }
         if (is_null($version)) {
             $newAttachment->delete();
             File::deleteDirectory($destinationFolder);
             return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array('message' => 'version'));
         }
         if (Input::hasFile('file')) {
             $fileUpload->move($destinationFolder, $fileUpload->getClientOriginalName());
         } else {
             file_put_contents($destinationFolder . '/' . $fileUploadJson->get('clientOriginalName'), $fileUpload);
         }
         $version->attachments()->attach($newAttachment);
         // Let's push that parsing job, which analyzes the document, converts it if needed and parses the crap out of it.
         Queue::push('DocumentParserWorker', array('user_id' => Auth::user()->id, 'document_id' => $newAttachment->id));
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $newAttachment);
     } else {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('message' => 'Invalid input'));
     }
 }
Пример #3
0
 public function deleteSelection($attachments)
 {
     $return = 1;
     foreach ($attachments as $id_attachment) {
         $attachment = new Attachment((int) $id_attachment);
         $return &= $attachment->delete();
     }
     return $return;
 }
Пример #4
0
 /**
  * We need a table for the attachments if it doesnt exist TBL_ATTACHMENT
  */
 function createTables()
 {
     $tables = array();
     if ($this->verifyTable('TBL_ATTACHMENT')) {
         $obj = new Attachment($this->db);
         $tables[] = $obj->generateCreateTables();
     }
     $tables = $this->addLinkTables($tables);
     $this->execute($tables);
 }
 public static function LoadAll()
 {
     $sql = sprintf("SELECT * FROM %s;", self::TABLE_NAME);
     $result = LoadDriver::query($sql);
     $coll = new BaseEntityCollection();
     while ($data = mysql_fetch_assoc($result)) {
         $tObj = new Attachment();
         $tObj->materilize($data);
         $coll->addItem($tObj);
     }
     return $coll;
 }
Пример #6
0
 /**
  * Get message data
  *
  * @return array
  */
 public function getData()
 {
     $res = ['recipient' => ['id' => $this->recipient]];
     $attachment = new Attachment(Attachment::TYPE_AUDIO);
     if (strpos($this->text, 'http://') === 0 || strpos($this->text, 'https://') === 0) {
         $attachment->setPayload(array('url' => $this->text));
     } else {
         $attachment->setFileData($this->getCurlValue($this->text, mime_content_type($this->text), basename($this->text)));
     }
     $res['message'] = $attachment->getData();
     return $res;
 }
Пример #7
0
 public function configure()
 {
     if ($category = $this->getObject()->getCategory()) {
         $this->embedForm('category', new CategoryForm($this->getObject()->getCategory()));
     }
     if ($this->getOption('with_attachment')) {
         $attachment = new Attachment();
         $attachment->setArticle($this->object);
         $attachmentForm = new AttachmentForm($attachment);
         unset($attachmentForm['article_id']);
         $this->embedForm('attachment', $attachmentForm);
     }
 }
Пример #8
0
 /**
  * Process db row
  * @param array $row
  * @return array
  */
 public function processRow(array $row)
 {
     global $ADMIN;
     // edit link
     $row['file_name'] = sprintf('<a href="/%s/media-archive/edit-attachment.php?f_attachment_id=%d">%s</a>', $ADMIN, $row['id'], $row['file_name']);
     // human readable size
     $row['size_in_bytes'] = parent::FormatFileSize($row['size_in_bytes']);
     // yes/no disposition
     $row['content_disposition'] = empty($row['content_disposition']) ? getGS('Yes') : getGS('No');
     // get in use info
     $object = new Attachment($row['id']);
     $row['InUse'] = (int) $object->inUse();
     return array_values($row);
 }
Пример #9
0
 public function main_delete_attachment()
 {
     if (!isset($_GET['id'])) {
         error(__("No ID Specified"), __("An ID is required to delete an attachment.", "attachments"));
     }
     $attachment = new Attachment($_GET['id']);
     if ($attachment->no_results) {
         error(__("Error"), __("Invalid attachment ID specified.", "attachments"));
     }
     if (!$attachment->deletable()) {
         show_403(__("Access Denied"), __("You do not have sufficient privileges to delete this attachment.", "attachments"));
     }
     Attachment::delete($attachment->id);
     Flash::notice(__("Attachment deleted.", "attachments"), $_SESSION['redirect_to']);
 }
Пример #10
0
 public function actionPickAtt()
 {
     $return_id = $_GET['return_id'];
     $rtype = $_GET['rtype'];
     $criteria = new CDbCriteria();
     if (isset($_GET['keyword'])) {
         $screen_name = trim($_GET['keyword']);
         $criteria->condition = 'screen_name like :screen_name';
         $criteria->params = array(':screen_name' => "%{$screen_name}%");
         $partial_tpl = '_att';
         //$atts = Attachment::model()->findAll($criteria);
         //$this->renderPartial('_att',array('return_id' => $return_id,'atts' => $atts,'rtype' => $rtype ),false,true);
     } else {
         $partial_tpl = 'pickatt';
         //$atts = Attachment::model()->findAll();
         //$this->renderPartial('pickatt',array('return_id' => $return_id,'atts' => $atts ,'rtype' => $rtype ),false,true);
     }
     $item_count = Attachment::model()->count($criteria);
     $page_size = 10;
     $pages = new CPagination($item_count);
     $pages->setPageSize($page_size);
     $pagination = new CLinkPager();
     $pagination->cssFile = false;
     $pagination->setPages($pages);
     $pagination->init();
     $criteria->limit = $page_size;
     $criteria->offset = $pages->offset;
     $select_pagination = new CListPager();
     $select_pagination->htmlOptions['onchange'] = "";
     $select_pagination->setPages($pages);
     $select_pagination->init();
     $atts = Attachment::model()->findAll($criteria);
     $this->renderPartial($partial_tpl, array('return_id' => $return_id, 'atts' => $atts, 'rtype' => $rtype, 'pagination' => $pagination, 'select_pagination' => $select_pagination), false, true);
 }
Пример #11
0
 private function handleTreeEditPost()
 {
     $request = Request::getInstance();
     $values = $request->getRequest(Request::POST);
     try {
         if (!$request->exists('tree_id')) {
             throw new Exception('Node ontbreekt.');
         }
         if (!$request->exists('tag')) {
             throw new Exception('Tag ontbreekt.');
         }
         $tree_id = intval($request->getValue('tree_id'));
         $tag = $request->getValue('tag');
         $key = array('tree_id' => $tree_id, 'tag' => $tag);
         if ($this->exists($key)) {
             $this->update($key, $values);
         } else {
             $this->insert($values);
         }
         $treeRef = new AttachmentTreeRef();
         $treeRef->delete($key);
         foreach ($values['ref_tree_id'] as $ref_tree_id) {
             $key['ref_tree_id'] = $ref_tree_id;
             $treeRef->insert($key);
         }
         viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW);
         $this->plugin->getReferer()->handleHttpGetRequest();
     } catch (Exception $e) {
         $template = new TemplateEngine();
         $template->setVariable('errorMessage', $e->getMessage(), false);
         $this->handleTreeEditGet(false);
     }
 }
Пример #12
0
 /**
  * Create Attachment instance and move file to attachmentsDirectory
  *
  * @param $data
  * @param $fileName
  * @param string $mime
  * @return \Attachment
  * @throws \Exception
  */
 protected function createAttachment($data, $fileName, $mime = '')
 {
     if (empty($mime)) {
         $f = finfo_open();
         $mime = finfo_buffer($f, $data, FILEINFO_MIME_TYPE);
     }
     $newAttachment = new \Attachment(array('filename' => $fileName, 'fileextension' => pathinfo($fileName, PATHINFO_EXTENSION), 'mimetype' => $mime, 'filesize' => strlen($data)));
     $newAttachment->save();
     $destinationFolder = \Config::get('paperwork.attachmentsDirectory') . '/' . $newAttachment->id;
     if (!\File::makeDirectory($destinationFolder, 0700)) {
         $newAttachment->delete();
         throw new \Exception('Error creating directory');
     }
     file_put_contents($destinationFolder . '/' . $fileName, $data);
     return $newAttachment;
 }
 public function mutateAttribute($key, $value)
 {
     preg_match('/(.*)_(image|file)(_la)?$/', $key, $matches);
     if (count($matches) > 0) {
         list($match_data, $field_name_prefix, $field_type) = $matches;
         $la_mode = count($matches) == 4;
         $field_name = "{$field_name_prefix}_{$field_type}_id";
         if (!$this->{$field_name}) {
             return null;
         }
         switch ($field_type) {
             case 'image':
                 $obj = Image::find($this->{$field_name});
                 break;
             case 'file':
                 $obj = Attachment::find($this->{$field_name});
                 break;
             default:
                 throw new \Exception("Unrecognized attachment type {$field_type}");
         }
         if (!$obj) {
             return null;
         }
         if ($la_mode) {
             // Recover image if missing from Laravel Admin
             $la_fpath = config('laravel-stapler.images.la_path') . "/{$obj->att_file_name}";
             if (!file_exists($la_fpath)) {
                 copy($obj->path('admin'), $la_fpath);
             }
             return $obj->att_file_name;
         }
         return $obj->att;
     }
     return parent::mutateAttribute($key, $value);
 }
Пример #14
0
 /**
  * handle tree edit
  */
 private function handleTreeEditGet($retrieveFields = true)
 {
     $template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
     $request = Request::getInstance();
     $view = ViewManager::getInstance();
     $view->setType(ViewManager::TREE_EDIT);
     if (!$request->exists('id')) {
         throw new Exception('Bestand ontbreekt.');
     }
     $id = intval($request->getValue('id'));
     $template->setVariable('id', $id, false);
     $key = array('id' => $id);
     if ($retrieveFields) {
         $fields = $this->getDetail($key);
         $fields['online'] = $fields['online'] ? strftime('%Y-%m-%d', $fields['online']) : '';
         $fields['offline'] = $fields['offline'] ? strftime('%Y-%m-%d', $fields['offline']) : '';
     } else {
         $fields = $this->getFields(SqlParser::MOD_UPDATE);
         $detail = $this->getDetail($key);
         $fields['file'] = $detail['file'];
     }
     $this->setFields($fields);
     // get path to file
     if ($fields['file']) {
         $template->setVariable('file_url', $this->plugin->getFileUrl($id), false);
     }
     $template->setVariable($fields, NULL, false);
     $this->handleTreeSettings($template);
     $datefields = array();
     $datefields[] = array('dateField' => 'online', 'triggerElement' => 'online');
     $datefields[] = array('dateField' => 'offline', 'triggerElement' => 'offline');
     Utils::getDatePicker($this->director->theme, $datefields);
     $this->template[$this->director->theme->getConfig()->main_tag] = $template;
 }
Пример #15
0
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Attachment::create([]);
     }
 }
Пример #16
0
 /**
  * handle tree edit
  */
 private function handleTreeEditGet($retrieveFields = true)
 {
     $template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
     $request = Request::getInstance();
     $view = ViewManager::getInstance();
     $view->setType(NewsLetter::VIEW_FILE_EDIT);
     $tree_id = intval($request->getValue('tree_id'));
     $tag = $request->getValue('tag');
     $template->setVariable('tree_id', $tree_id, false);
     $template->setVariable('tag', $tag, false);
     if (!$request->exists('id')) {
         throw new Exception('Bestand ontbreekt.');
     }
     $id = intval($request->getValue('id'));
     $template->setVariable('id', $id, false);
     $key = array('id' => $id);
     if ($retrieveFields) {
         $fields = $this->getDetail($key);
     } else {
         $fields = $this->getFields(SqlParser::MOD_UPDATE);
         $detail = $this->getDetail($key);
         $fields['file'] = $detail['file'];
     }
     $this->setFields($fields);
     // get path to file
     if ($fields['file']) {
         $template->setVariable('file_url', $this->plugin->getFileUrl($id), false);
     }
     $template->setVariable($fields, NULL, false);
     $this->handleTreeSettings($template);
     $this->template[$this->director->theme->getConfig()->main_tag] = $template;
 }
Пример #17
0
 public function actionRepairUpload()
 {
     $index = $this->request->getParam("selectedIndex");
     $pre_id = $this->request->getParam("upload_save_to_db_id");
     $inputFileName = "repair_attached_file" . $index;
     $attach = CUploadedFile::getInstanceByName($inputFileName);
     $retValue = "";
     if ($attach == null) {
         $retValue = "提示:不能上传空文件。";
     } else {
         if ($attach->size > 2000000) {
             $retValue = "提示:文件大小不能超过2M。";
         } else {
             $retValue = '恭喜,上传成功!';
             if ($pre_id == 0) {
                 $f = file_get_contents($attach->tempName);
                 $a = new Attachment();
                 $a->ref_type = "failParts";
                 $a->data = $f;
                 $a->file_path = $attach->name;
                 $a->save();
                 $cur_id = $a->id;
             } else {
                 $trans = Yii::app()->db->beginTransaction();
                 try {
                     $f = file_get_contents($attach->tempName);
                     $a = new Attachment();
                     $a->ref_type = "failParts";
                     $a->data = $f;
                     $a->file_path = $attach->name;
                     $a->save();
                     $cur_id = $a->id;
                     $pre = Attachment::model()->findByPk($pre_id);
                     $pre->delete();
                     $trans->commit();
                 } catch (Exception $e) {
                     $retValue = $e->getMessage();
                     $cur_id = 0;
                     $trans->rollback();
                 }
             }
             echo "<script type='text/javascript'>window.top.window.successUpload('{$retValue}',{$cur_id},{$index})</script>";
             exit;
         }
     }
     echo "<script type='text/javascript'>window.top.window.stopUpload('{$retValue}',{$index})</script>";
 }
 private function loadAttachment($attachmentId)
 {
     $attachment = Attachment::find($attachmentId);
     if (is_null($attachment)) {
         throw new Exception('Document parsing job #' . $this->job->getJobId() . ' contains an invalid document_id. Aborting.');
     }
     return $attachment;
 }
Пример #19
0
 public static function fromResponse($data)
 {
     $array = [];
     foreach ($data as $update) {
         $array[] = Attachment::fromResponse($update);
     }
     return $array;
 }
Пример #20
0
 public function a()
 {
     $id = $this->request->param('ID');
     $attachment = Attachment::get()->filterAny(array('ID' => $id, 'ContentID' => $id))->first();
     if ($attachment) {
         return $attachment->returnToBrowser();
     }
     return $this->httpError(404);
 }
Пример #21
0
 /**
  * @param string $uri
  * @param int         $linkType
  * @param null        $mediaType
  * @param int         $length
  *
  * @throws InvalidURIException
  */
 public function __construct($uri, $linkType, $mediaType = null, $length = 0)
 {
     parent::__construct($mediaType, $length);
     $uri = filter_var($uri, FILTER_VALIDATE_URL);
     if ($uri === false) {
         throw new InvalidURIException();
     }
     $this->uri = $uri;
     $this->linkType = $linkType;
 }
Пример #22
0
 public function pdfMergeAttachmentAction()
 {
     //this function is primarily used by other controllers so parameters here are not permitted from _GET and _POST do to possible injection into the xmlData arg which would be very hard to filter
     $request = $this->getRequest();
     $request->setParamSources(array());
     $attachmentReferenceId = preg_replace('/[^a-zA-Z0-9-]/', '', $this->_getParam('attachmentReferenceId'));
     $xmlData = $this->_getParam('xmlData');
     $attachment = new Attachment();
     $attachment->attachmentReferenceId = $attachmentReferenceId;
     //'ff560b50-75d0-11de-8a39-0800200c9a66' uuid for prescription pdf
     $attachment->populateWithAttachmentReferenceId();
     $db = Zend_Registry::get('dbAdapter');
     $sql = "select data from attachmentBlobs where attachmentId = " . $attachment->attachmentId;
     $stmt = $db->query($sql);
     $row = $stmt->fetch();
     $this->view->pdfBase64 = base64_encode($row['data']);
     $stmt->closeCursor();
     $this->view->xmlData = $xmlData;
     header('Content-type: application/vnd.adobe.xfdf');
 }
Пример #23
0
function mdt_add_attachment($id)
{
    try {
        require_once "Attachment.php";
        require_once "Image.php";
        require_once "Upload.php";
        $u = new Upload(FTP_CDN_HOST, FTP_CDN_USER, FTP_CDN_PASWD);
        $a = new Attachment($id);
        $i = new Image();
        $upload_dir = wp_upload_dir();
        $upload_dir = $upload_dir['baseurl'];
        $a->select();
        $u->sourceDir = UPLOAD_PATH . $a->year . '/' . $a->month;
        $u->destinyDir = '';
        $destiny = $u->setFtpDir($a->year, $a->month);
        //die(print_r(array($u->sourceDir.'/'.$a->guid['name'], $destiny.'/'.$a->guid['name'])));
        $u->put($u->sourceDir . '/' . $a->guid['name'], $destiny . '/' . $a->guid['name']);
        //die("end");
        foreach ($i->sizes as $k => $size) {
            $source = $u->sourceDir . '/' . $a->guid['name'];
            $file = $u->sourceDir . '/' . $a->guid['name'];
            if (in_array($k, array('medium', 'large'))) {
                $name = $i->defineImageName($source, $file, $size[0], $size[1], true);
            } else {
                list($width, $height) = $i->defineProportionalSize($source, $size[0], $size[1]);
                $name = $i->defineImageName($source, $file, $size[0], $size[1], false);
            }
            $file = $u->sourceDir . '/' . $name;
            if (!file_exists($file)) {
                $i->resize($source, $file, $size[0], $size[1], null, $k);
            }
            $u->put($file, $destiny . '/' . $name);
            //unlink($file);
        }
        //unlink($u->sourceDir.'/'.$a->guid['name']);
    } catch (Exception $e) {
        echo '<div class="error"><p>' . $e->getMessage() . '</p></div>';
    }
}
Пример #24
0
 public function insertAttachment($attachmentIds)
 {
     if (!is_array($attachmentIds)) {
         return false;
     }
     $attachmentIds = array_unique($attachmentIds);
     foreach ($attachmentIds as $v) {
         $model = Attachment::find()->andWhere(['cid' => $v])->one();
         if (!$model || $model->parent != 0) {
             continue;
         }
         $model->parent = $this->cid;
         $model->update(false);
     }
     return true;
 }
Пример #25
0
 public function fetchAllBodyIdByKeywordFromAttach($keyword, $whereAdd = "1", $queryArchiveId = 0)
 {
     $kwBodyIds = array();
     $queryParam = "uid = " . Ibos::app()->user->uid;
     $kwAttachments = Attachment::model()->fetchAllByKeywordFileName($keyword, $queryParam);
     if (!empty($kwAttachments)) {
         $kwAids = array_keys($kwAttachments);
         $emailData = $this->fetchAllByArchiveIds("e.*,eb.*,", "{$whereAdd} AND attachmentid!=''", $queryArchiveId);
         foreach ($emailData as $email) {
             if (array_intersect($kwAids, explode(",", $email["attachmentid"]))) {
                 $kwBodyIds[] = $email["bodyid"];
             }
         }
     }
     return $kwBodyIds;
 }
 public function viewAttachmentAction()
 {
     $attachmentId = (int) $this->_getParam('attachmentId');
     $attachment = new Attachment();
     $attachment->attachmentId = $attachmentId;
     $attachment->populate();
     $db = Zend_Registry::get('dbAdapter');
     $sql = "select data from attachmentBlobs where attachmentId = " . $attachmentId;
     $stmt = $db->query($sql);
     $row = $stmt->fetch();
     $this->view->content = $row['data'];
     $stmt->closeCursor();
     $this->getResponse()->setHeader('Content-Type', 'application/binary');
     $this->getResponse()->setHeader('Content-Disposition', 'attachment; filename="' . $attachment->name . '"');
     $this->render();
 }
Пример #27
0
 /**
  * Manages form output rendering
  * @param string Smarty template object
  * @see GuiProvider::renderForm
  */
 public function renderForm($theme)
 {
     $view = ViewManager::getInstance();
     $template = $theme->getTemplate();
     $template->setVariable($view->getUrlId(), $view->getName(), false);
     // parse rpc javascript to set variables
     $rpcfile_src = $this->plugin->getHtdocsPath(true) . "js/rpc.js.in";
     $theme->addJavascript($theme->fetchFile($rpcfile_src));
     $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/jsxmlrpc/lib/xmlrpc_lib.js"></script>');
     $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/jsxmlrpc/lib/xmlrpc_wrappers.js"></script>');
     $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/prototype.js"></script>');
     $theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/scriptaculous.js"></script>');
     $theme->addJavascript(file_get_contents($this->plugin->getHtdocsPath(true) . 'js/fade.js'));
     foreach ($this->template as $key => $value) {
         $template->setVariable($key, $value, false);
     }
 }
Пример #28
0
 /**
  * Delete a comment and its attachments
  *
  * @param int    $comment
  * @return bool
  */
 public static function delete_comment($comment)
 {
     \User\Activity::where('action_id', '=', $comment)->delete();
     $comment = static::find($comment);
     if (!$comment) {
         return false;
     }
     $issue = \Project\Issue::find($comment->issue_id);
     /* Delete attachments and files */
     $path = \Config::get('application.upload_path') . $issue->project_id;
     foreach ($comment->attachments()->get() as $row) {
         Attachment::delete_file($path . '/' . $row->upload_token, $row->filename);
         $row->delete();
     }
     $comment->delete();
     return true;
 }
Пример #29
0
 protected function body()
 {
     $inputs = array('lecture' => 'isIndex', 'name' => array('isName', 'isNotEmpty'), 'type' => array('isEnum' => array('text', 'code', 'image')));
     if (!$this->isInputValid($inputs)) {
         return false;
     }
     $lectureId = $this->getParams('lecture');
     /** @var \Lecture $lecture */
     $lecture = Repositories::findEntity(Repositories::Lecture, $lectureId);
     $name = $this->getParams('name');
     $type = $this->getParams('type');
     $id = $this->getParams('id');
     $isIdSet = $id !== null && $id !== '';
     $originalName = $this->getUploadedFileName('file');
     if (!$originalName) {
         return false;
     }
     $extensionStart = strrpos($originalName, '.');
     $extension = $extensionStart === false ? '' : substr($originalName, strrpos($originalName, '.'));
     $attachmentFolder = Config::get('paths', 'attachments');
     $filename = $id . '_' . $name . $extension;
     if (!$this->checkTestGenerationPrivileges($lecture)) {
         return $this->death(StringID::InsufficientPrivileges);
     }
     /**
      * @var $attachment \Attachment
      */
     $attachment = null;
     if (!$this->saveUploadedFile('file', $attachmentFolder . $filename)) {
         return $this->death(StringID::InsufficientPrivileges);
     }
     /** @var \Attachment[] $attachmentsWithThisName */
     $attachmentsWithThisName = Repositories::getRepository(Repositories::Attachment)->findBy(['lecture' => $lectureId, 'name' => $name]);
     if ($isIdSet) {
         $attachment = Repositories::findEntity(Repositories::Attachment, $id);
         if (count($attachmentsWithThisName) > 0) {
             if ($attachmentsWithThisName[0]->getId() !== $attachment->getId()) {
                 return $this->death(StringID::AttachmentExists);
             }
         }
     } else {
         if (count($attachmentsWithThisName) > 0) {
             return $this->death(StringID::AttachmentExists);
         }
         $attachment = new \Attachment();
     }
     $attachment->setType($type);
     $attachment->setLecture($lecture);
     $attachment->setName($name);
     $attachment->setFile($filename);
     Repositories::persistAndFlush($attachment);
     return true;
 }
Пример #30
0
 /**
  * @param Attachment $attachment
  * @return $this
  */
 public function attach(Attachment $attachment)
 {
     $mailAttachment = \Swift_Attachment::fromPath($attachment->getFile());
     if ($attachment->getFilename() !== null) {
         $mailAttachment->setFilename($attachment->getFilename());
     }
     if ($attachment->getMimeType() !== null) {
         $mailAttachment->setContentType($attachment->getMimeType());
     }
     $this->message->attach($mailAttachment);
     return $this;
 }