コード例 #1
0
ファイル: Database.php プロジェクト: mined-gatech/framework
 /**
  * Dump the database
  *
  * @museDescription  Dumps the current site database into a file in the users home directory
  *
  * @return  void
  **/
 public function dump()
 {
     $tables = App::get('db')->getTableList();
     $prefix = App::get('db')->getPrefix();
     $excludes = [];
     $now = new Date();
     $exclude = '';
     $includes = (array) $this->arguments->getOpt('include-table', []);
     if (!$this->arguments->getOpt('all-tables')) {
         $this->output->addLine('Dumping database with all prefixed tables included');
         foreach ($tables as $table) {
             if (strpos($table, $prefix) !== 0 && !in_array(str_replace('#__', $prefix, $table), $includes)) {
                 $excludes[] = Config::get('db') . '.' . $table;
             } elseif (in_array(str_replace('#__', $prefix, $table), $includes)) {
                 $this->output->addLine('Also including `' . $table . '`');
             }
         }
         // Build exclude list string
         $exclude = '--ignore-table=' . implode(' --ignore-table=', $excludes);
     } else {
         $this->output->addLine('Dumping database with all tables included');
     }
     // Add save location option
     $home = getenv('HOME');
     $hostname = gethostname();
     $filename = tempnam($home, "{$hostname}.mysql.dump." . $now->format('Y.m.d') . ".sql.");
     // Build command
     $cmd = "mysqldump -u " . Config::get('user') . " -p'" . Config::get('password') . "' " . Config::get('db') . " --routines {$exclude} > {$filename}";
     exec($cmd);
     // Print out location of file
     $this->output->addLine('File saved to: ' . $filename, 'success');
 }
コード例 #2
0
ファイル: search.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Process the index queue
  *
  * @museDescription  Processes the index queue
  *
  * @return  void
  **/
 public function processQueue()
 {
     require_once PATH_CORE . DS . 'components' . DS . 'com_search' . DS . 'models' . DS . 'indexqueue.php';
     require_once PATH_CORE . DS . 'components' . DS . 'com_search' . DS . 'models' . DS . 'blacklist.php';
     // Get the type needed to be indexed;
     $items = \Components\Search\Models\QueueDB::all()->where('status', '=', 0)->limit(100)->rows();
     // Refresh indexed material if no work to do
     if ($items->count() <= 0) {
         $items = \Components\Search\Models\QueueDB::all()->where('status', '=', 1)->where('action', '=', 'index')->order('modified', 'ASC')->limit(100)->rows();
     }
     // Get the blacklist
     $sql = "SELECT doc_id FROM #__search_blacklist;";
     $db = App::get('db');
     $db->setQuery($sql);
     $blacklist = $db->query()->loadColumn();
     foreach ($items as $item) {
         $format = Event::trigger('search.onIndex', array($item->type, $item->type_id, true));
         if (isset($format[0])) {
             $this->processRows($format[0], $item->action, $blacklist);
             $timestamp = \Hubzero\Utility\Date::of()->toSql();
             $item->set('modified', $timestamp);
             $item->set('status', 1);
         } else {
             $item->set('status', '2');
         }
         $item->save();
     }
 }
コード例 #3
0
ファイル: ticketsv1_0.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Create a new ticket
  *
  * @apiMethod POST
  * @apiUri    /support
  * @apiParameter {
  * 		"name":        "scope",
  * 		"description": "Scope type (group, member, etc.)",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "scope_id",
  * 		"description": "Scope object ID",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "title",
  * 		"description": "Entry title",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "alias",
  * 		"description": "Entry alias",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @return     void
  */
 public function createTask()
 {
     //get the userid and attempt to load user profile
     $userid = User::get('id');
     $result = User::getInstance($userid);
     //make sure we have a user
     if (!$result || !$result->get('id')) {
         throw new Exception(Lang::txt('User not found.'), 500);
     }
     // Initiate class and bind data to database fields
     $ticket = new \Components\Support\Models\Ticket();
     // Set the created date
     $ticket->set('created', Date::toSql());
     // Incoming
     $ticket->set('report', Request::getVar('report', '', 'post', 'none', 2));
     if (!$ticket->get('report')) {
         throw new Exception(Lang::txt('Error: Report contains no text.'), 500);
     }
     $ticket->set('os', Request::getVar('os', 'unknown', 'post'));
     $ticket->set('browser', Request::getVar('browser', 'unknown', 'post'));
     $ticket->set('severity', Request::getVar('severity', 'normal', 'post'));
     // Cut suggestion at 70 characters
     $summary = substr($ticket->get('report'), 0, 70);
     if (strlen($summary) >= 70) {
         $summary .= '...';
     }
     $ticket->set('summary', $summary);
     // Get user data
     $ticket->set('name', $result->get('name'));
     $ticket->set('email', $result->get('email'));
     $ticket->set('login', $result->get('username'));
     // Set some helpful info
     $ticket->set('instances', 1);
     $ticket->set('section', 1);
     $ticket->set('open', 1);
     $ticket->set('status', 0);
     $ticket->set('ip', Request::ip());
     $ticket->set('hostname', gethostbyaddr(Request::getVar('REMOTE_ADDR', '', 'server')));
     // Save the data
     if (!$ticket->store()) {
         throw new Exception($ticket->getErrors(), 500);
     }
     // Any tags?
     if ($tags = trim(Request::getVar('tags', '', 'post'))) {
         $ticket->tag($tags, $result->get('id'));
     }
     // Set the response
     $msg = new stdClass();
     $msg->submitted = $ticket->get('created');
     $msg->ticket = $ticket->get('id');
     $this->send($msg);
 }
コード例 #4
0
ファイル: Recipient.php プロジェクト: hubzero/framework
 /**
  * Mark entry as having been viewed
  *
  * @return  boolean
  */
 public function markAsViewed()
 {
     $dt = new Date('now');
     $this->set('viewed', $dt->toSql());
     return $this->save();
 }
コード例 #5
0
 /**
  * Create a new comment
  *
  * @apiMethod POST
  * @apiUri    /support/comments
  * @apiParameter {
  * 		"name":        "ticket",
  * 		"description": "Id of the ticket to make a comment on",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":		 null
  * }
  * @apiParameter {
  * 		"name":        "comment",
  * 		"description": "Comment text",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":		 null
  * }
  * @apiParameter {
  * 		"name":        "group",
  * 		"description": "Group to assign the ticket to (by alias)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":		 null
  * }
  * @apiParameter {
  * 		"name":        "owner",
  * 		"description": "Id of the owner to assign ticket to",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":		 null
  * }
  * @apiParameter {
  * 		"name":        "severity",
  * 		"description": "Severity of the ticket",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":		 null
  *		"allowed_values":	"minor, normal, major, critical"
  * }
  * @apiParameter {
  * 		"name":        "status",
  * 		"description": "Status of the ticket",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":		 null
  * }
  * @apiParameter {
  * 		"name":        "target_date",
  * 		"description": "Target date for completion of ticket (YYYY-MM-DD hh:mm:ss)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":		 null
  * }
  * @apiParameter {
  * 		"name":        "cc",
  * 		"description": "Comma seperated list of email addresses to email updates to",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":		 submitter,owner
  * }
  * @apiParameter {
  * 		"name":        "private",
  * 		"description": "Should the comment be flagged as private",
  * 		"type":        "boolean",
  * 		"required":    false,
  * 		"default":		 false
  * }
  * @apiParameter {
  * 		"name":        "email_submitter",
  * 		"description": "Should the submitter be emailed about this comment",
  * 		"type":        "boolean",
  * 		"required":    false,
  * 		"default":		 false
  * }
  * @apiParameter {
  * 		"name":        "email_owner",
  * 		"description": "Should the ticket owner be emailed about this comment",
  * 		"type":        "boolean",
  * 		"required":    false,
  * 		"default":		 false
  * }
  * @return     void
  */
 public function createTask()
 {
     $this->requiresAuthentication();
     if (!$this->acl->check('create', 'comments')) {
         throw new Exception(Lang::txt('Not authorized'), 403);
     }
     $ticket_id = Request::getInt('ticket', null);
     if (!isset($ticket_id)) {
         throw new Exception(Lang::txt('Bad request - ticket ID required'), 400);
     }
     $comment_text = Request::getString('comment', '');
     if ($comment_text == '') {
         throw new Exception(Lang::txt('Bad request - comment required'), 400);
     }
     $ticket = \Components\Support\Models\Orm\Ticket::oneOrFail($ticket_id);
     $comment = new \Components\Support\Models\Orm\Comment();
     $changelog = new stdClass();
     $comment->set('ticket', Request::get('ticket', ''));
     $comment->set('comment', nl2br(Request::get('comment')));
     $comment->set('created_by', User::get('id'));
     $comment->set('access', Request::get('private', false) == 'true' ? 1 : 0);
     $changes = array();
     foreach (['group', 'owner', 'severity', 'status', 'target_date', 'category'] as $index) {
         if (Request::get($index, null)) {
             if (Request::get($index) != $ticket->get($index)) {
                 $temp = new stdClass();
                 $temp->field = $index;
                 $temp->before = $ticket->get($index);
                 $temp->after = Request::get($index);
                 if ($index == 'status') {
                     if ($ticket->get('status') == 0) {
                         $status_model = new \Components\Support\Models\Orm\Status();
                         $status_model->set('title', 'Closed');
                         $status_model->set('open', 0);
                     } else {
                         $status_model = \Components\Support\Models\Orm\Status::oneOrFail(Request::get('status'));
                     }
                     if ($ticket->get('status') == 0) {
                         $old_status = new \Components\Support\Models\Orm\Status();
                         $old_status->set('title', 'Closed');
                         $old_status->set('open', 0);
                     } else {
                         $old_status = \Components\Support\Models\Orm\Status::oneOrFail($ticket->get('status'));
                     }
                     $temp->before = $old_status->get('title');
                     $temp->after = $status_model->get('title');
                     $ticket->set('open', $status_model->get('open'));
                     if ($status_model->get('get') == 'open' && $ticket->get('status', null) == 'closed') {
                         $tiket->set('closed', '0000-00-00 00:00:00');
                     }
                     if ($status_model->get('get') == 'closed' && $ticket->get('status', null) == 'open') {
                         $ticket->set('closed', Date::toSql());
                     }
                 }
                 if ($index == 'owner') {
                     $old_owner = User::getInstance($ticket->get('owner'));
                     $new_owner = User::getInstance(Request::get('owner'));
                     $temp->before = $old_owner->get('username');
                     $temp->after = $new_owner->get('username');
                 }
                 $ticket->set($index, Request::get($index));
                 $changes[] = $temp;
             }
         }
     }
     $changelog->changes = $changes;
     if ($comment->get('comment')) {
         // If a comment was posted by the ticket submitter to a "waiting user response" ticket, change status.
         $user = User::getInstance(User::get('id'));
         if ($ticket->get('status') == 2 && $user->get('username') == $ticket->get('login')) {
             $ticket->set('status', 0);
         }
     }
     $comment->set('changelog', json_encode($changelog));
     if (!$comment->save()) {
         throw new Exception(print_r($comment->getErrors(), 1), 500);
     }
     if (!$ticket->save()) {
         throw new Exception(print_r($ticket->getErrors(), 1), 500);
     }
     // There's now a ticket and a comment, lets add attachments
     \Components\Support\Helpers\Utilities::addAttachments($ticket->get('id'), $comment->get('id'));
     $msg = new stdClass();
     $msg->id = $comment->get('id');
     $msg->notified = $comment->get('changelog');
     $this->send($msg, 200, 'OK');
     /*
     		$changlog->notifications = array();
     		if (Request::get('email_owner'))
     		{
     			$comment->addTo(array(
     				'role'  => Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_OWNER'),
     				'name'  => $ticket->get_owner->get('name'),
     				'email' => $ticket->get_owner->get('email'),
     				'id'    => $ticket->get_owner->get('id')
     			));
     			$changelog->notifications[] = json_encode(array('role'=>'Ticket owner', 'address'=>$ticket->get_owner()->get('email'), 'name'=>$ticket->get_owner()->get('name')));
     		}
     
     		// Add any CCs to the e-mail list
     		$cc = Request::get('cc', null);
     		if ($cc)
     		{
     			$cc = explode(',', $cc);
     			foreach ($cc)
     			{
     				$comment->addTo($cc, Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_CC'));
     			}
     			$changelog->cc = json_encode($cc);
     		}
     
     		// Check if the notify list has eny entries
     		if (count($comment->to()))
     		{
     			include_once(PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'helpers' . DS . 'utilities.php');
     
     			$allowEmailResponses = $ticket->config('email_processing');
     			if ($allowEmailResponses)
     			{
     				try
     				{
     					$encryptor = new \Hubzero\Mail\Token();
     				}
     				catch (Exception $e)
     				{
     					$allowEmailResponses = false;
     				}
     			}
     
     			$subject = Lang::txt('COM_SUPPORT_EMAIL_SUBJECT_TICKET_COMMENT', $ticket->get('id'));
     
     			$from = array(
     				'name'      => Lang::txt('COM_SUPPORT_EMAIL_FROM', Config::get('sitename')),
     				'email'     => Config::get('mailfrom'),
     				'multipart' => md5(date('U'))
     			);
     
     			$message = array();
     
     			// Plain text email
     			$eview = new \Hubzero\Mail\View(array(
     				'base_path' => PATH_CORE . '/components/com_support/site',
     				'name'      => 'emails',
     				'layout'    => 'comment_plain'
     			));
     			$eview->option     = 'com_support';
     			$eview->controller = 'tickets';
     			$eview->comment    = $comment;
     			$eview->ticket     = $ticket;
     			$eview->delimiter  = ($allowEmailResponses ? '~!~!~!~!~!~!~!~!~!~!' : '');
     
     			$message['plaintext'] = $eview->loadTemplate(false);
     			$message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
     
     			// HTML email
     			$eview->setLayout('comment_html');
     			$message['multipart'] = $eview->loadTemplate();
     
     			// Send e-mail to admin?
     			foreach ($comment->to('ids') as $to)
     			{
     				if ($allowEmailResponses)
     				{
     					// The reply-to address contains the token
     					$token = $encryptor->buildEmailToken(1, 1, $to['id'], $ticket->get('id'));
     					$from['replytoemail'] = 'htc-' . $token . strstr(Config::get('mailfrom'), '@');
     				}
     
     				// Get the user's email address
     				if (!Event::trigger('xmessage.onSendMessage', array('support_reply_submitted', $subject, $message, $from, array($to['id']), 'com_support')))
     				{
     					$this->setError(Lang::txt('COM_SUPPORT_ERROR_FAILED_TO_MESSAGE', $to['name'] . '(' . $to['role'] . ')'));
     				}
     				$comment->changelog()->notified(
     					$to['role'],
     					$to['name'],
     					$to['email']
     				);
     			}
     
     			foreach ($comment->to('emails') as $to)
     			{
     				if ($allowEmailResponses)
     				{
     					$token = $encryptor->buildEmailToken(1, 1, -9999, $ticket->get('id'));
     
     					$email = array(
     						$to['email'],
     						'htc-' . $token . strstr(Config::get('mailfrom'), '@')
     					);
     
     					// In this case each item in email in an array, 1- To, 2:reply to address
     					\Components\Support\Helpers\Utilities::sendEmail($email[0], $subject, $message, $from, $email[1]);
     				}
     				else
     				{
     					// email is just a plain 'ol string
     					\Components\Support\Helpers\Utilities::sendEmail($to['email'], $subject, $message, $from);
     				}
     
     				$comment->changelog()->notified(
     					$to['role'],
     					$to['name'],
     					$to['email']
     				);
     			}
     		}
     		$comment->set('changelog', json_encode($changelog));
     		$comment->save();
     		$ticket->save();
     
     		$msg = new stdClass;
     		$msg->id  = $comment->get('id');
     		$msg->notified = $comment->get('changelog');
     
     		$this->send($msg, 200, 'OK');
     */
 }
コード例 #6
0
ファイル: accesstoken.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Return a formatted timestamp
  *
  * @param   string  $as  What format to return
  * @return  string
  */
 public function expires($as = '')
 {
     $as = strtolower($as);
     if ($as == 'date') {
         return Date::of($this->get('expires'))->toLocal(Lang::txt('DATE_FORMAT_HZ1'));
     }
     if ($as == 'time') {
         return Date::of($this->get('expires'))->toLocal(Lang::txt('TIME_FORMAT_HZ1'));
     }
     if ($as) {
         return Date::of($this->get('expires'))->toLocal($as);
     }
     return $this->get('expires');
 }
コード例 #7
0
ファイル: Recipient.php プロジェクト: kevinwojo/framework
 /**
  * Mark a message as being read by the recipient
  *
  * @return  boolean  True on success
  */
 public function markAsRead()
 {
     if (!$this->get('id')) {
         $this->addError('Recipient record not found');
         return false;
     }
     $xseen = Seen::oneByMessageAndUser($this->get('mid'), $this->get('uid'));
     if ($xseen->get('whenseen') == '' || $xseen->get('whenseen') == '0000-00-00 00:00:00' || $xseen->get('whenseen') == null) {
         $dt = new Date('now');
         $xseen->set('mid', $this->get('mid'));
         $xseen->set('uid', $this->get('uid'));
         $xseen->set('whenseen', $dt->toSql());
         if (!$xseen->save()) {
             $this->addError($xseen->getError());
             return false;
         }
     }
     return true;
 }
コード例 #8
0
 /**
  * Method to invoke new tools session
  *
  * @apiMethod GET
  * @apiUri    /tools/{tool}/invoke
  * @return    void
  */
 public function invokeTask()
 {
     //get the userid and attempt to load user profile
     $userid = App::get('authn')['user_id'];
     $result = User::getInstance($userid);
     //make sure we have a user
     if (!$result->get('id')) {
         throw new Exception(Lang::txt('Unable to find user.'), 404);
     }
     //get request vars
     $tool_name = Request::getVar('app', '');
     $tool_version = Request::getVar('version', 'default');
     //build application object
     $app = new stdClass();
     $app->name = trim(str_replace(':', '-', $tool_name));
     $app->version = $tool_version;
     $app->ip = $_SERVER["REMOTE_ADDR"];
     //check to make sure we have an app to invoke
     if (!$app->name) {
         $this->errorMessage(400, 'You Must Supply a Valid Tool Name to Invoke.');
         return;
     }
     //include needed tool libraries
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'version.php';
     require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'session.php';
     require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'viewperm.php';
     //create database object
     $database = \App::get('db');
     //load the tool version
     $tv = new \Components\Tools\Tables\Version($database);
     switch ($app->version) {
         case 1:
         case 'default':
             $app->name = $tv->getCurrentVersionProperty($app->name, 'instance');
             break;
         case 'test':
         case 'dev':
             $app->name .= '_dev';
             break;
         default:
             $app->name .= '_r' . $app->version;
             break;
     }
     $app->toolname = $app->name;
     if ($parent = $tv->getToolname($app->name)) {
         $app->toolname = $parent;
     }
     // Check of the toolname has a revision indicator
     $r = substr(strrchr($app->name, '_'), 1);
     if (substr($r, 0, 1) != 'r' && substr($r, 0, 3) != 'dev') {
         $r = '';
     }
     // No version passed and no revision
     if ((!$app->version || $app->version == 'default') && !$r) {
         // Get the latest version
         $app->version = $tv->getCurrentVersionProperty($app->toolname, 'revision');
         $app->name = $app->toolname . '_r' . $app->version;
     }
     // Get the caption/session title
     $tv->loadFromInstance($app->name);
     $app->caption = stripslashes($tv->title);
     $app->title = stripslashes($tv->title);
     //make sure we have a valid tool
     if ($app->title == '' || $app->toolname == '') {
         throw new Exception(Lang::txt('The tool "%s" does not exist on the HUB.', $tool_name), 400);
     }
     //get tool access
     $toolAccess = \Components\Tools\Helpers\Utils::getToolAccess($app->name, $result->get('username'));
     //do we have access
     if ($toolAccess->valid != 1) {
         throw new Exception($toolAccess->error->message, 400);
     }
     // Log the launch attempt
     \Components\Tools\Helpers\Utils::recordToolUsage($app->toolname, $result->get('id'));
     // Get the middleware database
     $mwdb = \Components\Tools\Helpers\Utils::getMWDBO();
     // Find out how many sessions the user is running.
     $ms = new \Components\Tools\Models\Middleware\Session($mwdb);
     $jobs = $ms->getCount($result->get('username'));
     // Find out how many sessions the user is ALLOWED to run.
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'preferences.php';
     $preferences = new \Components\Tools\Tables\Preferences($database);
     $preferences->loadByUser($result->get('uidNumber'));
     if (!$preferences || !$preferences->id) {
         include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'sessionclass.php';
         $scls = new \Components\Tools\Tables\SessionClass($this->database);
         $default = $scls->find('one', array('alias' => 'default'));
         $preferences->user_id = $result->get('uidNumber');
         $preferences->class_id = $default->id;
         $preferences->jobs = $default->jobs ? $default->jobs : 3;
         $preferences->store();
     }
     $remain = $preferences->jobs - $jobs;
     //can we open another session
     if ($remain <= 0) {
         throw new Exception(Lang::txt('You are using all (%s) your available job slots.', $jobs), 401);
     }
     // Get plugins
     Plugin::import('mw', $app->name);
     // Trigger any events that need to be called before session invoke
     Event::trigger('mw.onBeforeSessionInvoke', array($app->toolname, $app->version));
     // We've passed all checks so let's actually start the session
     $status = \Components\Tools\Helpers\Utils::middleware("start user="******" ip=" . $app->ip . " app=" . $app->name . " version=" . $app->version, $output);
     //make sure we got a valid session back from the middleware
     if (!isset($output->session)) {
         throw new Exception(Lang::txt('There was a issue while trying to start the tool session. Please try again later.'), 500);
     }
     //set session output
     $app->sess = $output->session;
     // Trigger any events that need to be called after session invoke
     Event::trigger('mw.onAfterSessionInvoke', array($app->toolname, $app->version));
     // Get a count of the number of sessions of this specific tool
     $appcount = $ms->getCount($result->get('username'), $app->name);
     // Do we have more than one session of this tool?
     if ($appcount > 1) {
         // We do, so let's append a timestamp
         $app->caption .= ' (' . Date::format("g:i a") . ')';
     }
     // Save the changed caption
     $ms->load($app->sess);
     $ms->sessname = $app->caption;
     if (!$ms->store()) {
         throw new Exception(Lang::txt('There was a issue while trying to start the tool session. Please try again later.'), 500);
     }
     //add tool title to output
     //add session title to ouput
     $output->tool = $app->title;
     $output->session_title = $app->caption;
     $output->owner = 1;
     $output->readonly = 0;
     //return result
     if ($status) {
         $this->send($output);
     }
 }
コード例 #9
0
ファイル: Calendar.php プロジェクト: kevinwojo/framework
 /**
  * Method to get the field input markup.
  *
  * @return  string  The field input markup.
  */
 protected function getInput()
 {
     // Initialize some field attributes.
     $format = $this->element['format'] ? (string) $this->element['format'] : '%Y-%m-%d';
     // Build the attributes array.
     $attributes = array();
     if ($this->element['size']) {
         $attributes['size'] = (int) $this->element['size'];
     }
     if ($this->element['maxlength']) {
         $attributes['maxlength'] = (int) $this->element['maxlength'];
     }
     if ($this->element['class']) {
         $attributes['class'] = (string) $this->element['class'];
     }
     if ((string) $this->element['readonly'] == 'true') {
         $attributes['readonly'] = 'readonly';
     }
     if ((string) $this->element['disabled'] == 'true') {
         $attributes['disabled'] = 'disabled';
     }
     if ($this->element['onchange']) {
         $attributes['onchange'] = (string) $this->element['onchange'];
     }
     // Handle the special case for "now".
     if (strtoupper($this->value) == 'NOW') {
         $this->value = strftime($format);
     }
     // If a known filter is given use it.
     switch (strtoupper((string) $this->element['filter'])) {
         case 'SERVER_UTC':
             // Convert a date to UTC based on the server timezone.
             if (intval($this->value)) {
                 // Get a date object based on the correct timezone.
                 $date = new Date($this->value, 'UTC');
                 $date->setTimezone(new DateTimeZone(App::get('config')->get('offset')));
                 // Transform the date string.
                 $this->value = $date->format('Y-m-d H:i:s', true, false);
             }
             break;
         case 'USER_UTC':
             // Convert a date to UTC based on the user timezone.
             if (intval($this->value)) {
                 // Get a date object based on the correct timezone.
                 $date = new Date($this->value, 'UTC');
                 $date->setTimezone(new DateTimeZone(App::get('user')->getParam('timezone', App::get('config')->get('offset'))));
                 // Transform the date string.
                 $this->value = $date->format('Y-m-d H:i:s', true, false);
             }
             break;
     }
     return Input::calendar($this->value, $this->name, $this->id, $format, $attributes);
 }
コード例 #10
0
ファイル: Atom.php プロジェクト: mined-gatech/framework
 /**
  * Render the feed.
  *
  * @param   string  $name     The name of the element to render
  * @param   array   $params   Array of values
  * @param   string  $content  Override the output of the renderer
  * @return  string  The output of the script
  */
 public function render($name = '', $params = null, $content = null)
 {
     $now = new Date('now');
     $data = $this->doc;
     $uri = App::get('request')->root();
     $syndicationURL = App::get('router')->url('&format=feed&type=atom');
     if (App::get('config')->get('sitename_pagetitles', 0) == 1) {
         $data->title = App::get('language')->txt('JPAGETITLE', App::get('config')->get('sitename'), $data->title);
     } elseif (App::get('config')->get('sitename_pagetitles', 0) == 2) {
         $data->title = App::get('language')->txt('JPAGETITLE', $data->title, App::get('config')->get('sitename'));
     }
     $feed_title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
     $feed = "<feed xmlns=\"http://www.w3.org/2005/Atom\" ";
     if ($data->language != "") {
         $feed .= " xml:lang=\"" . $data->language . "\"";
     }
     $feed .= ">\n";
     $feed .= "\t<title type=\"text\">" . $feed_title . "</title>\n";
     $feed .= "\t<subtitle type=\"text\">" . htmlspecialchars($data->description, ENT_COMPAT, 'UTF-8') . "</subtitle>\n";
     if (empty($data->category) === false) {
         if (is_array($data->category)) {
             foreach ($data->category as $cat) {
                 $feed .= "\t<category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n";
             }
         } else {
             $feed .= "\t<category term=\"" . htmlspecialchars($data->category, ENT_COMPAT, 'UTF-8') . "\" />\n";
         }
     }
     $feed .= "\t<link rel=\"alternate\" type=\"text/html\" href=\"" . $url . "\"/>\n";
     $feed .= "\t<id>" . str_replace(' ', '%20', $data->getBase()) . "</id>\n";
     $feed .= "\t<updated>" . htmlspecialchars($now->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n";
     if ($data->editor != "") {
         $feed .= "\t<author>\n";
         $feed .= "\t\t<name>" . $data->editor . "</name>\n";
         if ($data->editorEmail != "") {
             $feed .= "\t\t<email>" . htmlspecialchars($data->editorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n";
         }
         $feed .= "\t</author>\n";
     }
     $feed .= "\t<generator uri=\"http://hubzero.org\" version=\"2.5\">" . $data->getGenerator() . "</generator>\n";
     $feed .= '	<link rel="self" type="application/atom+xml" href="' . str_replace(' ', '%20', $url . $syndicationURL) . "\"/>\n";
     for ($i = 0, $count = count($data->items); $i < $count; $i++) {
         $feed .= "\t<entry>\n";
         $feed .= "\t\t<title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n";
         $feed .= '		<link rel="alternate" type="text/html" href="' . $url . $data->items[$i]->link . "\"/>\n";
         if ($data->items[$i]->date == "") {
             $data->items[$i]->date = $now->toUnix();
         }
         $itemDate = new Date($data->items[$i]->date);
         $itemDate->setTimeZone($tz);
         $feed .= "\t\t<published>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</published>\n";
         $feed .= "\t\t<updated>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n";
         if (empty($data->items[$i]->guid) === true) {
             $feed .= "\t\t<id>" . str_replace(' ', '%20', $url . $data->items[$i]->link) . "</id>\n";
         } else {
             $feed .= "\t\t<id>" . htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8') . "</id>\n";
         }
         if ($data->items[$i]->author != "") {
             $feed .= "\t\t<author>\n";
             $feed .= "\t\t\t<name>" . htmlspecialchars($data->items[$i]->author, ENT_COMPAT, 'UTF-8') . "</name>\n";
             if ($data->items[$i]->authorEmail != "") {
                 $feed .= "\t\t\t<email>" . htmlspecialchars($data->items[$i]->authorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n";
             }
             $feed .= "\t\t</author>\n";
         }
         if ($data->items[$i]->description != "") {
             $feed .= "\t\t<summary type=\"html\">" . htmlspecialchars($data->items[$i]->description, ENT_COMPAT, 'UTF-8') . "</summary>\n";
             $feed .= "\t\t<content type=\"html\">" . htmlspecialchars($data->items[$i]->description, ENT_COMPAT, 'UTF-8') . "</content>\n";
         }
         if (empty($data->items[$i]->category) === false) {
             if (is_array($data->items[$i]->category)) {
                 foreach ($data->items[$i]->category as $cat) {
                     $feed .= "\t\t<category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n";
                 }
             } else {
                 $feed .= "\t\t<category term=\"" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8') . "\" />\n";
             }
         }
         if ($data->items[$i]->enclosure != null) {
             $feed .= "\t\t<link rel=\"enclosure\" href=\"" . $data->items[$i]->enclosure->url . "\" type=\"" . $data->items[$i]->enclosure->type . "\"  length=\"" . $data->items[$i]->enclosure->length . "\" />\n";
         }
         $feed .= "\t</entry>\n";
     }
     $feed .= "</feed>\n";
     return $feed;
 }
コード例 #11
0
ファイル: Recipient.php プロジェクト: kevinwojo/framework
 /**
  * Mark entry as having been viewed
  *
  * @return  boolean
  */
 public function markAsViewed()
 {
     $dt = new Date('now');
     $this->set('viewed', $dt->toSql());
     if (!$this->save()) {
         return false;
     }
     return true;
 }
コード例 #12
0
 /**
  * Build Query to get Announcements
  *
  * @param   array   $filters
  * @return  string
  */
 private function _buildQuery($filters = array())
 {
     //array to hold where statements
     $where = array();
     //start query
     $query = " FROM {$this->_tbl} AS a";
     //apply filters based on filters passed in
     if (isset($filters['scope']) && $filters['scope']) {
         $where[] = "a.`scope` = " . $this->_db->quote($filters['scope']);
     }
     if (isset($filters['scope_id']) && $filters['scope_id']) {
         $where[] = "a.`scope_id` = " . $this->_db->quote(intval($filters['scope_id']));
     }
     if (isset($filters['state']) && $filters['state']) {
         $where[] = "a.`state` = " . $this->_db->quote(intval($filters['state']));
     }
     if (isset($filters['created_by']) && $filters['created_by']) {
         $where[] = "a.`created_by` = " . $this->_db->quote(intval($filters['created_by']));
     }
     if (isset($filters['priority']) && $filters['priority']) {
         $where[] = "a.`priority` = " . $this->_db->quote(intval($filters['priority']));
     }
     if (isset($filters['sticky']) && in_array($filters['sticky'], array(0, 1))) {
         $where[] = "a.`sticky` = " . $this->_db->quote(intval($filters['sticky']));
     }
     if (isset($filters['email']) && in_array($filters['email'], array(0, 1))) {
         $where[] = "a.`email` = " . $this->_db->quote(intval($filters['email']));
     }
     if (isset($filters['sent']) && in_array($filters['sent'], array(0, 1))) {
         $where[] = "a.`sent` = " . $this->_db->quote(intval($filters['sent']));
     }
     //published
     if (isset($filters['published'])) {
         $now = new Date('now');
         $where[] = "(a.`publish_up` = '0000-00-00 00:00:00' OR a.`publish_up` <= " . $this->_db->quote($now->toSql()) . ")";
         $where[] = "(a.`publish_down` = '0000-00-00 00:00:00' OR a.`publish_down` >= " . $this->_db->quote($now->toSql()) . ")";
     }
     //search
     if (isset($filters['search']) && $filters['search']) {
         if (is_numeric($filters['search'])) {
             $where[] = "a.`id`=" . $this->_db->quote(intval($filters['search']));
         } else {
             $where[] = "(LOWER(a.content) LIKE " . $this->_db->quote('%' . strtolower($filters['search']) . '%') . ")";
         }
     }
     //if we have an wheres append them
     if (count($where) > 0) {
         $query .= " WHERE " . implode(' AND ', $where);
     }
     return $query;
 }
コード例 #13
0
 /**
  * Create a new comment
  *
  * @apiMethod POST
  * @apiUri    /support/{ticket}/comments
  * @apiParameter {
  * 		"name":        "scope",
  * 		"description": "Scope type (group, member, etc.)",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "scope_id",
  * 		"description": "Scope object ID",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "title",
  * 		"description": "Entry title",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "alias",
  * 		"description": "Entry alias",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @return     void
  */
 public function createTask()
 {
     $this->requiresAuthentication();
     if (!$this->acl->check('create', 'comments')) {
         throw new Exception(Lang::txt('Not authorized'), 403);
     }
     $ticket_id = Request::getInt('ticket', 0, 'post');
     // Load the old ticket so we can compare for the changelog
     $old = new \Components\Support\Models\Ticket($ticket_id);
     $old->set('tags', $old->tags('string'));
     if (!$old->exists()) {
         $this->errorMessage(500, Lang::txt('Ticket "%s" does not exist.', $ticket_id));
         return;
     }
     // Initiate class and bind posted items to database fields
     $ticket = new \Components\Support\Models\Ticket($ticket_id);
     $ticket->set('status', Request::getInt('status', $ticket->get('status'), 'post'));
     $ticket->set('open', Request::getInt('open', $ticket->get('open'), 'post'));
     $ticket->set('category', Request::getInt('category', $ticket->get('category'), 'post'));
     $ticket->set('severity', Request::getVar('severity', $ticket->get('severity'), 'post'));
     $ticket->set('owner', Request::getVar('owner', $ticket->get('owner'), 'post'));
     $ticket->set('group', Request::getVar('group', $ticket->get('group'), 'post'));
     // If an existing ticket AND closed AND previously open
     if ($ticket_id && !$ticket->get('open') && $ticket->get('open') != $old->get('open')) {
         // Record the closing time
         $ticket->set('closed', Date::toSql());
     }
     // Any tags?
     if ($tags = trim(Request::getVar('tags', '', 'post'))) {
         $ticket->tag($tags, $user->get('uidNumber'));
         $ticket->set('tags', $ticket->tags('string'));
     }
     // Store new content
     if (!$ticket->store()) {
         $this->errorMessage(500, $ticket->getError());
         return;
     }
     // Create a new comment
     $comment = new \Components\Support\Models\Comment();
     $comment->set('ticket', $ticket->get('id'));
     $comment->set('comment', nl2br(Request::getVar('comment', '', 'post', 'none', 2)));
     if ($comment->get('comment')) {
         // If a comment was posted by the ticket submitter to a "waiting user response" ticket, change status.
         if ($ticket->isWaiting() && $user->get('username') == $ticket->get('login')) {
             $ticket->open();
         }
     }
     $comment->set('created', Date::toSql());
     $comment->set('created_by', $user->get('uidNumber'));
     $comment->set('access', Request::getInt('access', 0, 'post'));
     // Compare fields to find out what has changed for this ticket and build a changelog
     $comment->changelog()->diff($old, $ticket);
     $comment->changelog()->cced(Request::getVar('cc', '', 'post'));
     // Store new content
     if (!$comment->store()) {
         $this->errorMessage(500, $comment->getError());
         return;
     }
     if ($ticket->get('owner')) {
         $comment->addTo(array('role' => Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_OWNER'), 'name' => $ticket->owner('name'), 'email' => $ticket->owner('email'), 'id' => $ticket->owner('id')));
     }
     // Add any CCs to the e-mail list
     foreach ($comment->changelog()->get('cc') as $cc) {
         $comment->addTo($cc, Lang::txt('COM_SUPPORT_COMMENT_SEND_EMAIL_CC'));
     }
     // Check if the notify list has eny entries
     if (count($comment->to())) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'helpers' . DS . 'utilities.php';
         $allowEmailResponses = $ticket->config('email_processing');
         if ($allowEmailResponses) {
             try {
                 $encryptor = new \Hubzero\Mail\Token();
             } catch (Exception $e) {
                 $allowEmailResponses = false;
             }
         }
         $subject = Lang::txt('COM_SUPPORT_EMAIL_SUBJECT_TICKET_COMMENT', $ticket->get('id'));
         $from = array('name' => Lang::txt('COM_SUPPORT_EMAIL_FROM', Config::get('sitename')), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U')));
         $message = array();
         // Plain text email
         $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . '/components/com_support/site', 'name' => 'emails', 'layout' => 'comment_plain'));
         $eview->option = 'com_support';
         $eview->controller = 'tickets';
         $eview->comment = $comment;
         $eview->ticket = $ticket;
         $eview->delimiter = $allowEmailResponses ? '~!~!~!~!~!~!~!~!~!~!' : '';
         $message['plaintext'] = $eview->loadTemplate(false);
         $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
         // HTML email
         $eview->setLayout('comment_html');
         $message['multipart'] = $eview->loadTemplate();
         // Send e-mail to admin?
         foreach ($comment->to('ids') as $to) {
             if ($allowEmailResponses) {
                 // The reply-to address contains the token
                 $token = $encryptor->buildEmailToken(1, 1, $to['id'], $ticket->get('id'));
                 $from['replytoemail'] = 'htc-' . $token . strstr(Config::get('mailfrom'), '@');
             }
             // Get the user's email address
             if (!Event::trigger('xmessage.onSendMessage', array('support_reply_submitted', $subject, $message, $from, array($to['id']), 'com_support'))) {
                 $this->setError(Lang::txt('COM_SUPPORT_ERROR_FAILED_TO_MESSAGE', $to['name'] . '(' . $to['role'] . ')'));
             }
             $comment->changelog()->notified($to['role'], $to['name'], $to['email']);
         }
         foreach ($comment->to('emails') as $to) {
             if ($allowEmailResponses) {
                 $token = $encryptor->buildEmailToken(1, 1, -9999, $ticket->get('id'));
                 $email = array($to['email'], 'htc-' . $token . strstr(Config::get('mailfrom'), '@'));
                 // In this case each item in email in an array, 1- To, 2:reply to address
                 \Components\Support\Helpers\Utilities::sendEmail($email[0], $subject, $message, $from, $email[1]);
             } else {
                 // email is just a plain 'ol string
                 \Components\Support\Helpers\Utilities::sendEmail($to['email'], $subject, $message, $from);
             }
             $comment->changelog()->notified($to['role'], $to['name'], $to['email']);
         }
     }
     // Were there any changes?
     if (count($comment->changelog()->get('notifications')) > 0 || count($comment->changelog()->get('cc')) > 0 || count($comment->changelog()->get('changes')) > 0) {
         // Save the data
         if (!$comment->store()) {
             $this->errorMessage(500, $comment->getError());
             return;
         }
     }
     $msg = new stdClass();
     $msg->ticket = $ticket->get('id');
     $msg->comment = $comment->get('id');
     $msg->notified = $comment->changelog()->get('notifications');
     $this->setMessageType(Request::getVar('format', 'json'));
     $this->send($msg, 200, 'OK');
 }
コード例 #14
0
ファイル: User.php プロジェクト: kevinwojo/framework
 /**
  * Pass through method to the table for setting the last visit date
  *
  * @param   integer  $timestamp  The timestamp, defaults to 'now'.
  * @return  boolean  True on success.
  * @since   2.1.0
  */
 public function setLastVisit($timestamp = 'now')
 {
     $timestamp = new Date($timestamp);
     $query = $this->getQuery()->update($this->getTableName())->set(array('lastvisitDate' => $timestamp->toSql()))->whereEquals('id', $this->get('id'));
     return $query->execute();
 }
コード例 #15
0
 /**
  * Month 
  * 
  * @param string $date 
  * @param mixed $row 
  * @access private
  * @return void
  */
 private function Month($date = '', $row)
 {
     $date = $row->{$date};
     $month = Date::of(strtotime($date))->toLocal('m');
     return $month;
 }
コード例 #16
0
ファイル: Rss.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Render the feed.
  *
  * @param   string  $name     The name of the element to render
  * @param   array   $params   Array of values
  * @param   string  $content  Override the output of the renderer
  * @return  string  The output of the script
  */
 public function render($name = NULL, $params = NULL, $content = NULL)
 {
     $now = new Date('now');
     $data = $this->doc;
     $url = \App::get('request')->root();
     if (\App::get('config')->get('sitename_pagetitles', 0) == 1) {
         $data->title = \App::get('language')->txt('JPAGETITLE', \App::get('config')->get('sitename'), $data->title);
     } elseif (\App::get('config')->get('sitename_pagetitles', 0) == 2) {
         $data->title = \App::get('language')->txt('JPAGETITLE', $data->title, \App::get('config')->get('sitename'));
     }
     $feed = '<rss version="2.0" xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd">' . "\n";
     //$feed  = "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
     $feed .= '	<channel>' . "\n";
     $feed .= '		<title>' . $data->title . '</title>' . "\n";
     $feed .= '		<description><![CDATA[' . $data->description . ']]></description>' . "\n";
     $feed .= '		<link>' . str_replace(' ', '%20', $url . $data->link) . '</link>' . "\n";
     $feed .= '		<lastBuildDate>' . $this->escape($now->toRFC822()) . '</lastBuildDate>' . "\n";
     $feed .= '		<generator>' . $data->getGenerator() . '</generator>' . "\n";
     // iTunes specific tags
     if ($data->itunes_summary != '') {
         $feed .= '		<itunes:summary>' . $this->escape($data->itunes_summary) . '</itunes:summary>' . "\n";
     }
     if ($data->itunes_category != '') {
         $feed .= '		<itunes:category text="' . $this->escape($data->itunes_category) . '">' . "\n";
         if ($data->itunes_subcategories != null) {
             $cats = $data->itunes_subcategories;
             foreach ($cats as $cat) {
                 $feed .= '			<itunes:category text="' . $this->escape($cat) . '" />' . "\n";
             }
         }
         $feed .= '		</itunes:category>' . "\n";
     }
     if ($data->itunes_owner != null) {
         $feed .= '		<itunes:owner>' . "\n";
         $feed .= '			<itunes:name>' . $this->escape($data->itunes_owner->name) . '</itunes:name>' . "\n";
         $feed .= '			<itunes:email>' . $data->itunes_owner->email . '</itunes:email>' . "\n";
         $feed .= '		</itunes:owner>' . "\n";
     }
     if ($data->itunes_explicit != '') {
         $feed .= '		<itunes:explicit>' . $data->itunes_explicit . '</itunes:explicit>' . "\n";
     }
     if ($data->itunes_keywords != '') {
         $feed .= '		<itunes:keywords>' . $this->escape($data->itunes_keywords) . '</itunes:keywords>' . "\n";
     }
     if ($data->itunes_author != '') {
         $feed .= '		<itunes:author>' . $this->escape($data->itunes_author) . '</itunes:author>' . "\n";
     }
     if ($data->itunes_image != null) {
         $feed .= '		<itunes:image href="' . $data->itunes_image->url . '" />' . "\n";
     }
     // end iTunes specific tags
     if ($data->image != null) {
         $feed .= '		<image>' . "\n";
         $feed .= '			<url>' . $data->image->url . '</url>' . "\n";
         $feed .= '			<title>' . $this->escape($data->image->title) . '</title>' . "\n";
         $feed .= '			<link>' . str_replace(' ', '%20', $data->image->link) . '</link>' . "\n";
         if ($data->image->width != "") {
             $feed .= '			<width>' . $data->image->width . '</width>' . "\n";
         }
         if ($data->image->height != '') {
             $feed .= '			<height>' . $data->image->height . '</height>' . "\n";
         }
         if ($data->image->description != '') {
             $feed .= '			<description><![CDATA[' . $data->image->description . ']]></description>' . "\n";
         }
         $feed .= '		</image>' . "\n";
     }
     if ($data->language != '') {
         $feed .= "\t\t<language>" . $data->language . "</language>\n";
     }
     if ($data->copyright != '') {
         $feed .= "\t\t<copyright>" . $this->escape($data->copyright) . "</copyright>\n";
     }
     if ($data->editor != '') {
         $feed .= "\t\t<managingEditor>" . $this->escape($data->editor) . "</managingEditor>\n";
     }
     if ($data->webmaster != '') {
         $feed .= "\t\t<webMaster>" . $this->escape($data->webmaster) . "</webMaster>\n";
     }
     if ($data->pubDate != '') {
         $pubDate = new Date($data->pubDate);
         $feed .= "\t\t<pubDate>" . $this->escape($pubDate->toRFC822()) . "</pubDate>\n";
     }
     if ($data->category) {
         if (!is_array($data->category)) {
             $data->category = array($data->category);
         }
         foreach ($data->category as $category) {
             $feed .= "\t\t<category>" . $this->escape($category) . "</category>\n";
         }
     }
     if ($data->docs != '') {
         $feed .= "\t\t<docs>" . $this->escape($data->docs) . "</docs>\n";
     }
     if ($data->ttl != '') {
         $feed .= "\t\t<ttl>" . $this->escape($data->ttl) . "</ttl>\n";
     }
     if ($data->rating != '') {
         $feed .= "\t\t<rating>" . $this->escape($data->rating) . "</rating>\n";
     }
     if ($data->skipHours != '') {
         $feed .= "\t\t<skipHours>" . $this->escape($data->skipHours) . "</skipHours>\n";
     }
     if ($data->skipDays != '') {
         $feed .= "\t\t<skipDays>" . $this->escape($data->skipDays) . "</skipDays>\n";
     }
     for ($i = 0; $i < count($data->items); $i++) {
         if (strpos($data->items[$i]->link, 'http://') === false and strpos($data->items[$i]->link, 'https://') === false) {
             $data->items[$i]->link = str_replace(' ', '%20', $url . $data->items[$i]->link);
         }
         $feed .= "\t\t<item>\n";
         $feed .= "\t\t\t<title>" . $this->escape(strip_tags($data->items[$i]->title)) . "</title>\n";
         $feed .= "\t\t\t<link>" . str_replace(' ', '%20', $data->items[$i]->link) . "</link>\n";
         $feed .= "\t\t\t<description>" . $this->_relToAbs($data->items[$i]->description) . "</description>\n";
         if (empty($data->items[$i]->guid) === true) {
             $feed .= "\t\t\t<guid isPermaLink=\"true\">" . str_replace(' ', '%20', $data->items[$i]->link) . "</guid>\n";
         } else {
             $feed .= "\t\t\t<guid isPermaLink=\"false\">" . $this->escape($data->items[$i]->guid) . "</guid>\n";
         }
         // iTunes specific tags
         if ($data->items[$i]->itunes_summary != '') {
             $feed .= "\t\t\t<itunes:summary>" . $this->escape($data->items[$i]->itunes_summary) . "</itunes:summary>\n";
         }
         if ($data->items[$i]->itunes_duration != '') {
             $feed .= "\t\t\t<itunes:duration>" . $this->escape($data->items[$i]->itunes_duration) . "</itunes:duration>\n";
         }
         if ($data->items[$i]->itunes_explicit != '') {
             $feed .= "\t\t\t<itunes:explicit>" . $data->items[$i]->itunes_explicit . "</itunes:explicit>\n";
         }
         if ($data->items[$i]->itunes_keywords != '') {
             $feed .= "\t\t\t<itunes:keywords>" . $this->escape($data->items[$i]->itunes_keywords) . "</itunes:keywords>\n";
         }
         if ($data->items[$i]->itunes_author != '') {
             $feed .= "\t\t\t<itunes:author>" . $this->escape($data->items[$i]->itunes_author) . "</itunes:author>\n";
         }
         if ($data->items[$i]->itunes_category != '') {
             $feed .= "\t\t\t<itunes:category text=\"" . $this->escape($data->items[$i]->itunes_category) . "\">\n";
             if ($data->items[$i]->itunes_subcategories != '') {
                 $icats = $data->items[$i]->itunes_subcategories;
                 foreach ($icats as $icat) {
                     $feed .= "\t\t\t\t<itunes:category text=\"" . $this->escape($icat) . "\">\n";
                 }
             }
             $feed .= "\t\t\t</itunes:category>\n";
         }
         if ($data->items[$i]->itunes_image != null) {
             $feed .= "\t\t\t<itunes:image>\n";
             $feed .= "\t\t\t\t<url>" . $data->items[$i]->itunes_image->url . "</url>\n";
             $feed .= "\t\t\t\t<title>" . $this->escape($data->items[$i]->itunes_image->title) . "</title>\n";
             $feed .= "\t\t\t\t<link>" . $data->items[$i]->itunes_image->link . "</link>\n";
             if ($data->items[$i]->itunes_image->width != '') {
                 $feed .= "\t\t\t<width>" . $data->items[$i]->itunes_image->width . "</width>\n";
             }
             if ($data->items[$i]->itunes_image->height != '') {
                 $feed .= "\t\t\t<height>" . $data->items[$i]->itunes_image->height . "</height>\n";
             }
             if ($data->items[$i]->itunes_image->description != '') {
                 $feed .= "\t\t\t<description><![CDATA[" . $data->items[$i]->itunes_image->description . "]]></description>\n";
             }
             $feed .= "\t\t\t</itunes:image>\n";
         }
         // end iTunes specific tags
         if ($data->items[$i]->author != '') {
             $feed .= "\t\t\t<author>" . $this->escape($data->items[$i]->author) . "</author>\n";
         }
         if ($data->items[$i]->category) {
             if (!is_array($data->items[$i]->category)) {
                 $data->items[$i]->category = array($data->items[$i]->category);
             }
             foreach ($data->items[$i]->category as $category) {
                 $feed .= "\t\t\t<category>" . $this->escape($category) . "</category>\n";
             }
         }
         if ($data->items[$i]->comments != '') {
             $feed .= "\t\t\t<comments>" . $this->escape($data->items[$i]->comments) . "</comments>\n";
         }
         if ($data->items[$i]->date != '') {
             $itemDate = new Date($data->items[$i]->date);
             $feed .= "\t\t\t<pubDate>" . $this->escape($itemDate->toRFC822()) . "</pubDate>\n";
         }
         if ($data->items[$i]->guid != '') {
             $feed .= "\t\t\t<guid>" . $this->escape($data->items[$i]->guid) . "</guid>\n";
         }
         if ($data->items[$i]->enclosure != NULL) {
             $feed .= '			<enclosure url="' . $data->items[$i]->enclosure->url . '" length="' . $data->items[$i]->enclosure->length . '" type="' . $data->items[$i]->enclosure->type . '"/>' . "\n";
         }
         $feed .= "\t\t</item>\n";
     }
     $feed .= "\t</channel>\n";
     $feed .= "</rss>\n";
     return $feed;
 }
コード例 #17
0
ファイル: Run.php プロジェクト: kevinwojo/framework
 /**
  * Generates automatic created field value
  *
  * @return  string
  * @since   2.0.0
  **/
 public function automaticRanAt()
 {
     $dt = new Date('now');
     return $dt->toSql();
 }