Example #1
0
 /**
  * Create a new reminder
  *
  * @param string $name The text that will appear in the reminder
  * @param int $time Unix timestamp
  * @param string $model_name Optional model name and model id so that the reminder links to the dialog.
  * @param int $model_id
  * @param int $vtime The time that will be displayed in the reminder
  * 
  * @return Reminder 
  */
 public static function newInstance($name, $time, $model_name = '', $model_id = 0, $vtime = null)
 {
     $r = new Reminder();
     $r->name = \GO\Base\Util\String::cut_string($name, 100);
     $r->time = $time;
     $r->vtime = $vtime;
     $r->model_type_id = \GO::getModel($model_name)->modelTypeId();
     $r->model_id = $model_id;
     $r->save();
     return $r;
 }
Example #2
0
 public function getExcerpt($maxLength = 100)
 {
     return $this->getEncrypted() ? GO::t('encryptedContent', 'notes') : GO\Base\Util\String::cut_string($this->content, $maxLength);
 }
Example #3
0
 /**
  * Get a short text from this contentitem
  * 
  * @param int $length
  * @param boolean $cutwords
  * @param string $append
  * @return string
  */
 public function getShortText($length = 100, $cutwords = false, $append = '...')
 {
     //		 $text = \GO\Base\Util\String::html_to_text($this->content);
     $text = \GO\Base\Util\String::cut_string($this->content, $length, !$cutwords, $append);
     $html = MarkdownExtra::defaultTransform($text);
     return strip_tags($html);
 }
Example #4
0
 public function getResponseData()
 {
     $dayString = \GO::t('full_days');
     $response = $this->_event->getAttributes('html');
     if ($this->isAllDay()) {
         $response['time'] = $this->getFormattedTime();
     } else {
         if (date(\GO::user()->date_format, $this->getAlternateStartTime()) != date(\GO::user()->date_format, $this->getAlternateEndTime())) {
             $response['time'] = $this->getFormattedTime();
         } else {
             $response['time'] = $this->getFormattedTime();
         }
     }
     //		$response['time_of_day'] = $this->getTimeOfDay();
     $response['status'] = $this->_event->status;
     $response['username'] = $this->_event->user ? $this->_event->user->getName() : \GO::t('unknown') . ' ' . \GO::t('user');
     $response['musername'] = !empty($this->_event->mUser) ? $this->_event->mUser->getName() : '';
     //		if($this->_event->status==Event::STATUS_CANCELLED){
     //			$response['name'] .= ' ('.$this->_event->localizedStatus.')';
     //		}
     //
     if ($this->_isMerged) {
         $response['name'] = $response['name'] . ' (' . implode(',', $this->_initials) . ')';
         $response['calendar_name'] = implode('; ', $this->_calendarNames);
         unset($response['status']);
         // unset this, it is not relevant to show this in merge view
         unset($response['username']);
         // unset this, it is not relevant to show this in merge view.
     } else {
         $response['calendar_name'] = $this->_calendarNames[0];
     }
     $response['id'] = $this->_event->id . ':' . $this->getAlternateStartTime();
     // a unique id for the data store. Is not really used.
     $response['background'] = $this->_backgroundColor;
     $response['start_time'] = date('Y-m-d H:i', $this->getAlternateStartTime());
     $response['end_time'] = date('Y-m-d H:i', $this->getAlternateEndTime());
     $response['ctime'] = date('Y-m-d H:i', $this->_event->ctime);
     $response['mtime'] = date('Y-m-d H:i', $this->_event->mtime);
     $response['event_id'] = $this->_event->id;
     $response['description'] = nl2br(htmlspecialchars(\GO\Base\Util\String::cut_string($this->_event->description, 800), ENT_COMPAT, 'UTF-8'));
     $response['private'] = $this->isPrivate();
     $response['private_enabled'] = $this->_event->private;
     $response['resources'] = array();
     if ($response['private']) {
         $response['name'] = \GO::t('private', 'calendar');
         $response['description'] = "";
         $response['location'] = "";
         $response['repeats'] = false;
         $response['has_reminder'] = false;
         $response['link_count'] = false;
         $response['status_color'] = false;
         $response['status'] = false;
     } else {
         $response['repeats'] = $this->isRepeating();
         $response['has_reminder'] = $response['reminder'] > 0 ? 1 : 0;
         $response['link_count'] = $this->getLinkCount();
         $response['status_color'] = $this->_event->getStatusColor();
         if ($this->_event->resources) {
             foreach ($this->_event->resources as $resourceModel) {
                 $response['resources'][$resourceModel->id] = $resourceModel->calendar->name;
             }
         }
     }
     $response['permission_level'] = $this->_event->permissionLevel;
     $response['all_day_event'] = $this->isAllDay();
     $response['day'] = $dayString[date('w', $this->getAlternateStartTime())] . ' ' . \GO\Base\Util\Date::get_timestamp($this->getAlternateStartTime(), false);
     // date(implode(\GO::user()->date_separator,str_split(\GO::user()->date_format,1)), ($eventModel->start_time));
     $response['read_only'] = $this->isReadOnly();
     $response['model_name'] = $this->_event->className();
     $response['partstatus'] = "none";
     if (isset($response['status']) && $response['status'] == Event::STATUS_CANCELLED) {
         //hack to make it transparent on cancelled status too in the view.
         $response['partstatus'] = Participant::STATUS_DECLINED;
     } else {
         if ($participant = $this->_event->getParticipantOfCalendar()) {
             $response['partstatus'] = $participant->status;
         }
     }
     $duration = $this->getDurationInMinutes();
     if ($duration >= 60) {
         $durationHours = floor($duration / 60);
         $durationRestMinutes = $duration % 60;
         $response['duration'] = $durationHours . ' ' . \GO::t('hours') . ', ' . $durationRestMinutes . ' ' . \GO::t('mins');
     } else {
         $response['duration'] = $duration . 'm';
     }
     return $response;
 }
Example #5
0
 protected function actionDescription($params)
 {
     $response = array();
     $response['title'] = '';
     $response['description'] = '';
     if (function_exists('curl_init')) {
         try {
             $c = new \GO\Base\Util\HttpClient();
             $c->setCurlOption(CURLOPT_CONNECTTIMEOUT, 2);
             $c->setCurlOption(CURLOPT_TIMEOUT, 5);
             $c->setCurlOption(CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
             $html = $c->request($params['url']);
             //go_debug($html);
             $html = str_replace("\r", '', $html);
             $html = str_replace("\n", ' ', $html);
             $html = preg_replace("'</[\\s]*([\\w]*)[\\s]*>'", "</\$1>", $html);
             preg_match('/<head>(.*)<\\/head>/i', $html, $match);
             if (isset($match[1])) {
                 $html = $match[1];
                 //go_debug($html);
                 preg_match('/charset=([^"\'>]*)/i', $c->getContentType(), $match);
                 if (isset($match[1])) {
                     $charset = strtolower(trim($match[1]));
                     if ($charset != 'utf-8') {
                         $html = \GO\Base\Util\String::to_utf8($html, $charset);
                     }
                 }
                 preg_match_all('/<meta[^>]*>/i', $html, $matches);
                 $description = '';
                 foreach ($matches[0] as $match) {
                     if (stripos($match, 'description')) {
                         $name_pos = stripos($match, 'content');
                         if ($name_pos) {
                             $description = substr($match, $name_pos + 7, -1);
                             $description = trim($description, '="\'/ ');
                             break;
                         }
                     }
                 }
                 //replace double spaces
                 $response['description'] = preg_replace('/\\s+/', ' ', $description);
                 preg_match('/<title>(.*)<\\/title>/i', $html, $match);
                 $response['title'] = $match ? preg_replace('/\\s+/', ' ', trim($match[1])) : '';
             }
         } catch (\Exception $e) {
         }
         try {
             $contents = $c->request($params['url'] . '/favicon.ico');
             if (!empty($contents) && $c->getHttpCode() != 404) {
                 $relpath = 'public/bookmarks/';
                 $path = \GO::config()->file_storage_path . $relpath;
                 if (!is_dir($path)) {
                     mkdir($path, 0755, true);
                 }
                 $filename = str_replace('.', '_', preg_replace('/^https?:\\/\\//', '', $_POST['url'])) . '.ico';
                 $filename = rtrim(str_replace('/', '_', $filename), '_ ');
                 //var_dump($filename);
                 file_put_contents($path . $filename, $contents);
                 $response['logo'] = $relpath . $filename;
             }
         } catch (\Exception $e) {
             $response['logo'] = '';
         }
     }
     $response['title'] = \GO\Base\Util\String::cut_string($response['title'], 64, true, "");
     $response['description'] = \GO\Base\Util\String::cut_string($response['description'], 255, true, "");
     return $response;
 }