/** * The code that needs to be called when the cron is running * * If $this->enableUserAndGroupSupport() returns TRUE then the run function * will be called for each $user. (The $user parameter will be given) * * If $this->enableUserAndGroupSupport() returns FALSE then the * $user parameter is null and the run function will be called only once. * * @param \GO\Base\Cron\CronJob $cronJob * @param \GO\Base\Model\User $user [OPTIONAL] */ public function run(\GO\Base\Cron\CronJob $cronJob, \GO\Base\Model\User $user = null) { \GO::session()->runAsRoot(); \GO::debug("Start updating public calendars."); $calendars = \GO\Calendar\Model\Calendar::model()->findByAttribute('public', true); foreach ($calendars as $calendar) { $file = new \GO\Base\Fs\File($calendar->getPublicIcsPath()); if (!$file->exists()) { \GO::debug("Creating " . $file->path() . "."); $file->touch(true); } $file->putContents($calendar->toVObject()); \GO::debug("Updating " . $calendar->name . " to " . $file->path() . "."); } \GO::debug("Finished updating public calendars."); }
protected function actionCreateFile($params) { $filename = \GO\Base\Fs\File::stripInvalidChars($params['filename']); if (empty($filename)) { throw new \Exception("Filename can not be empty"); } $template = \GO\Files\Model\Template::model()->findByPk($params['template_id']); $folder = \GO\Files\Model\Folder::model()->findByPk($params['folder_id']); $path = \GO::config()->file_storage_path . $folder->path . '/' . $filename; if (!empty($template->extension)) { $path .= '.' . $template->extension; } $fsFile = new \GO\Base\Fs\File($path); $fsFile->putContents($template->content); $fileModel = \GO\Files\Model\File::importFromFilesystem($fsFile); if (!$fileModel) { throw new Exception("Could not create file"); } return array('id' => $fileModel->id, 'success' => true); }
protected function afterSave($wasNew) { if ($wasNew && $this->group) { $stmt = $this->group->admins; foreach ($stmt as $user) { if ($user->user_id != $this->user_id) { //the owner has already been added automatically with manage permission $this->acl->addUser($user->user_id, \GO\Base\Model\Acl::DELETE_PERMISSION); } } } $file = new \GO\Base\Fs\File($this->getPublicIcsPath()); if (!$this->public) { if ($file->exists()) { $file->delete(); } } else { if (!$file->exists()) { $file->touch(true); } $file->putContents($this->toVObject()); } return parent::afterSave($wasNew); }
private function _getParts($structure, $part_number_prefix = '') { if (isset($structure->parts)) { $structure->ctype_primary = strtolower($structure->ctype_primary); $structure->ctype_secondary = strtolower($structure->ctype_secondary); //$part_number=0; foreach ($structure->parts as $part_number => $part) { $part->ctype_primary = strtolower($part->ctype_primary); $part->ctype_secondary = strtolower($part->ctype_secondary); //text part and no attachment so it must be the body if ($structure->ctype_primary == 'multipart' && $structure->ctype_secondary == 'alternative' && $part->ctype_primary == 'text' && $part->ctype_secondary == 'plain') { //check if html part is there if ($this->_hasHtmlPart($structure)) { continue; } } if ($part->ctype_primary == 'text' && ($part->ctype_secondary == 'plain' || $part->ctype_secondary == 'html') && (!isset($part->disposition) || $part->disposition != 'attachment') && empty($part->d_parameters['filename'])) { $charset = isset($part->ctype_parameters['charset']) ? $part->ctype_parameters['charset'] : 'UTF-8'; $body = \GO\Base\Util\String::clean_utf8($part->body, $charset); if (stripos($part->ctype_secondary, 'plain') !== false) { $body = nl2br($body); } else { $body = \GO\Base\Util\String::convertLinks($body); $body = \GO\Base\Util\String::sanitizeHtml($body); $body = $body; } $this->_loadedBody .= $body; } elseif ($part->ctype_primary == 'multipart') { } else { //attachment if (!empty($part->ctype_parameters['name'])) { $filename = $part->ctype_parameters['name']; } elseif (!empty($part->d_parameters['filename'])) { $filename = $part->d_parameters['filename']; } elseif (!empty($part->d_parameters['filename*'])) { $filename = $part->d_parameters['filename*']; } else { $filename = uniqid(time()); } $mime_type = $part->ctype_primary . '/' . $part->ctype_secondary; if (isset($part->headers['content-id'])) { $content_id = trim($part->headers['content-id']); if (strpos($content_id, '>')) { $content_id = substr($part->headers['content-id'], 1, strlen($part->headers['content-id']) - 2); } } else { $content_id = ''; } $f = new \GO\Base\Fs\File($filename); $a = new MessageAttachment(); $a->name = $filename; $a->number = $part_number_prefix . $part_number; $a->content_id = $content_id; $a->mime = $mime_type; $tmp_file = new \GO\Base\Fs\File($this->_getTempDir() . $filename); if (!empty($part->body)) { $tmp_file = new \GO\Base\Fs\File($this->_getTempDir() . $filename); if (!$tmp_file->exists()) { $tmp_file->putContents($part->body); } $a->setTempFile($tmp_file); } $a->index = count($this->attachments); $a->size = isset($part->body) ? strlen($part->body) : 0; $a->encoding = isset($part->headers['content-transfer-encoding']) ? $part->headers['content-transfer-encoding'] : ''; $a->disposition = isset($part->disposition) ? $part->disposition : ''; $this->addAttachment($a); } //$part_number++; if (isset($part->parts)) { $this->_getParts($part, $part_number_prefix . $part_number . '.'); } } } elseif (isset($structure->body)) { $charset = isset($structure->ctype_parameters['charset']) ? $structure->ctype_parameters['charset'] : 'UTF-8'; $text_part = \GO\Base\Util\String::clean_utf8($structure->body, $charset); //convert text to html if (stripos($structure->ctype_secondary, 'plain') !== false) { $this->extractUuencodedAttachments($text_part); $text_part = nl2br($text_part); } else { $text_part = \GO\Base\Util\String::convertLinks($text_part); $text_part = \GO\Base\Util\String::sanitizeHtml($text_part); } $this->_loadedBody .= $text_part; } }