Esempio n. 1
0
 public function since(KDate $date)
 {
     $date->addHours(-2);
     $date = strtotime($date->getDate());
     $today = time();
     // array of time period chunks
     $chunks = array(60 * 60 * 24 * 365, 60 * 60 * 24 * 30, 60 * 60 * 24 * 7, 60 * 60 * 24, 60 * 60, 60, 1);
     $since = $today - $date;
     for ($i = 0, $j = count($chunks); $i < $j; $i++) {
         $seconds = $chunks[$i];
         if (0 != ($count = floor($since / $seconds))) {
             break;
         }
     }
     if ($count > 1) {
         $trans = array('YEARS', 'MONTHS', 'WEEKS', 'DAYS', 'HOURS', 'MINUTES', 'SECONDS');
     } else {
         $trans = array('YEAR', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE', 'SECOND');
     }
     $string = JText::sprintf(@$trans[@$i], $count);
     if ($string) {
         return JText::sprintf('POSTED_AGO', $string);
     } else {
         return JText::_('NOW');
     }
 }
Esempio n. 2
0
 /**
  * Prepare form layout
  * 
  * @return null
  */
 protected function _layoutForm()
 {
     if (!$this->expiresOn) {
         $expiresOn = new KDate();
         $expiresOn->addMonths(1);
         $this->set(array('expiresOn' => $expiresOn));
     }
 }
Esempio n. 3
0
 protected function _actionPost(KCommandContext $context)
 {
     $data = $context->data;
     $date = new KDate();
     $date->day((int) $data->expiresOnDay);
     $date->month((int) $data->expiresOnMonth);
     $date->year((int) $data->expiresOnYear);
     $data->expiresOn = $date;
     return parent::_actionPost($context);
 }
 protected function _formatDates($dates)
 {
     $result = array();
     $d = new KDate();
     foreach ($dates as $date) {
         $d->setDate($date);
         $result[] = $d->format('%b %e');
     }
     return $result;
 }
Esempio n. 5
0
 /**
  * Browse Service
  * 
  * @param KCommandContext $context
  */
 protected function _actionBrowse(KCommandContext $context)
 {
     if (!$context->query) {
         $context->query = $this->getRepository()->getQuery();
     }
     $query = $context->query;
     $query->select('COUNT(*) AS count')->join('RIGHT', 'anahita_edges AS edge', 'hashtag.id = edge.node_a_id')->order('count', 'DESC')->limit($this->limit, $this->start);
     if ($this->sort == 'trending') {
         $now = new KDate();
         $query->where('edge.created_on', '>', $now->addDays(-(int) $this->days)->getDate());
     }
     return $this->getState()->setList($query->toEntityset())->getList();
 }
Esempio n. 6
0
 /**
  * Browse Service.
  *
  * @param KCommandContext $context
  */
 protected function _actionBrowse(KCommandContext $context)
 {
     $entities = parent::_actionBrowse($context);
     if (in_array($this->sort, array('top', 'trending')) && $this->q == '') {
         $package = $this->getIdentifier()->package;
         $name = $this->getIdentifier()->name;
         $entities->select('COUNT(*) AS count')->join('RIGHT', 'edges AS edge', $name . '.id = edge.node_a_id')->where('edge.type', 'LIKE', '%com:' . $package . '.domain.entity.tag')->group($name . '.id')->order('count', 'DESC');
         if ($this->sort == 'trending') {
             $now = new KDate();
             $entities->where('edge.created_on', '>', $now->addDays(-(int) $this->days)->getDate());
         }
     }
     return $entities;
 }
Esempio n. 7
0
 public function getDates()
 {
     static $result;
     if (!isset($result)) {
         $year = $this->getState('year');
         $month = $this->getState('month');
         $days = KDate::getDaysInMonth($month, $year);
         $date = new KDate();
         $date->year($year);
         $date->month($month);
         $result = array();
         for ($day = 1; $day <= $days; $day++) {
             $date->day($day);
             $result[$date->format('%Y-%m-%d')] = 0;
         }
     }
     return $result;
 }
Esempio n. 8
0
 public static function months($selected, $name = 'filter_month', $attribs = array('class' => 'inputbox', 'size' => '1'), $idtag = null, $allowAll = false)
 {
     $list = array();
     if ($allowAll) {
         $list[] = self::option(0, JText::_('All'), 'id', 'title');
     }
     $months = KDate::getMonthNames();
     foreach ($months as $key => $month) {
         $list[] = self::option($key, $month, 'id', 'title');
     }
     return self::genericlist($list, $name, $attribs, 'id', 'title', $selected, $idtag);
 }
Esempio n. 9
0
<?php

if ($post->id) {
    ?>
	<div class="post" >
		
		<?php 
    $date = new KDate();
    $date->setDate($post->created_on);
    ?>
		<div class="date">
			<div class="day"><?php 
    echo $date->format('%d');
    ?>
</div>
			<div class="month"><?php 
    echo $date->format('%B');
    ?>
</div>
			<div class="year"><?php 
    echo $date->format('%Y');
    ?>
</div>
		</div>
		
		<h2>
			<b><?php 
    echo $post->title;
    ?>
</b>
		</h2>
Esempio n. 10
0
 /**
  * Set End Time action
  * 
  * sets correct end date value to be used for a subscription setting 
  *
  * @param KCommandContext $context Context parameter
  * 
  * @param void
  */
 public function setEndDate(KCommandContext $context)
 {
     $data = $context->data;
     if ($data->day || $data->month || $data->year) {
         $date = new KDate();
         $date->day((int) $data->day);
         $date->month((int) $data->month);
         $date->year((int) $data->year);
         $data->endDate = $date;
     }
 }
Esempio n. 11
0
<table class="u-stream" >
    <?php 
    $currentDay = null;
    ?>
    <?php 
    foreach (@$myactivities as $activity) {
        ?>
    
        <?php 
        if (!in_array($activity->parent_target_id, $array)) {
            continue;
        }
        ?>

	 	<?php 
        $date = new KDate();
        $offset = KFactory::get('lib.joomla.config')->getValue('config.offset') + 1;
        $date->setDate($activity->created_on)->addHours($offset);
        ?>
		<?php 
        if ($currentDay == $date->format('%d %B')) {
            ?>
     	    <tr> 
     	        <td class="empty">&nbsp;</td> 
     	<?php 
        } else {
            ?>
     	    <tr class="new-day"> 
     	        <td class="day"> 
     	            <span>
     	                <a><?php 
Esempio n. 12
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   KObjectConfig $config Configuration options
  * @return void
  */
 protected function _initialize(KObjectConfig $config)
 {
     $config->append(array('timezone' => 'UTC'));
     parent::_initialize($config);
 }
Esempio n. 13
0
 /**
  * Compare the reciever with another date. If receiver is the same date as the 
  * date it returns 0 if receiver is before the dat it returns 1 and if it's after the date
  * it returns -1
  *
  * @param KDate $date
  * @return int
  */
 public function compare(KDate $date)
 {
     $thisTimestamp = $this->getTimestamp();
     $dateTimestamp = $date->getTimestamp();
     return $thisTimestamp - $dateTimestamp;
 }
Esempio n. 14
0
" src='http://www.gravatar.com/avatar.php?gravatar_id=<?php 
    echo md5(strtolower($user->email));
    ?>
&size=50'>
						
					</div>
					<div class="comment-text">
						<?php 
    echo $comment->text;
    ?>
						<?php 
    echo $user->name;
    ?>
, 
						<?php 
    $date = new KDate();
    $offset = KFactory::get('lib.joomla.config')->getValue('config.offset') + 1;
    $date->setDate($comment->created_on)->addHours($offset);
    ?>
						<?php 
    KFactory::get('lib.joomla.language.language')->load('com_comments');
    ?>
						<?php 
    echo @text(KFactory::tmp('site::com.comments.helper.date')->since($date));
    ?>
			
		 			</div>
				</div>
			</div>
		</fieldset>
	<?php 
Esempio n. 15
0
 public function display()
 {
     $user = KFactory::tmp('lib.joomla.user', array(KRequest::get('get.userid', 'int')));
     if ($user->username == KRequest::get('get.username', 'string')) {
         $targets = KFactory::tmp('site::com.stream.model.targets')->getList()->getData();
         $thing = reset($targets);
         $string = substr($thing['title'], 3);
         $option = strtolower(substr($string, 0, stripos($string, 'controller')));
         $view = strtolower(substr($string, stripos($string, 'controller') + 10));
         $model = KInflector::pluralize($view);
         $list = KFactory::tmp('site::com.' . $option . '.model.' . $model)->userid($user->id)->getList()->getData();
         $array = array();
         foreach ($list as $item) {
             $array[] = $item['id'];
         }
         //Get the list of posts
         $activities = KFactory::get($this->getModel())->set('parent_target_id', KRequest::get('get.parent_target_id', 'int'))->getList();
         $doc =& JFactory::getDocument();
         foreach ($activities as $activity) {
             if (!in_array($activity->parent_target_id, $array)) {
                 continue;
             }
             $date = new KDate();
             $date->setDate($activity->created_on);
             $currentDay == $date->format('%d %B');
             $user = KFactory::tmp('lib.joomla.user', array('id' => $activity->created_by));
             $string = substr($activity->controller, 3);
             $option = strtolower(substr($string, 0, stripos($string, 'controller')));
             $view = strtolower(substr($string, stripos($string, 'controller') + 10));
             $link = '';
             if ($activity->action != 'delete') {
                 $link = KRequest::base() . '/index.php?option=com_' . $option . '&view=' . $view . '&id=' . $activity->target_id . '&project_id=' . $activity->parent_target_id . '&Itemid=2';
             }
             $description = '<i>' . JText::_($activity->controller . '-' . $activity->action) . '</i>';
             $description .= ' ' . $activity->target_title;
             //add the parent name in the description, if I'm not in a specialized view
             if (!KRequest::get('get.parent_target_id', 'int')) {
                 $targets = KFactory::tmp('site::com.stream.model.targets')->getList()->getData();
                 $thing = reset($targets);
                 $string = substr($thing['title'], 3);
                 $option = strtolower(substr($string, 0, stripos($string, 'controller')));
                 $view = strtolower(substr($string, stripos($string, 'controller') + 10));
                 $model = KInflector::pluralize($view);
                 $data = KFactory::tmp('site::com.' . $option . '.model.' . $model)->id($activity->parent_target_id)->getItem();
                 $description .= '<strong>' . $data->title . '</strong>';
             }
             $date = new KDate();
             $date->setDate($activity->created_on);
             $item = new JFeedItem();
             $item->title = $activity->target_title;
             $item->link = $link . '&param=' . $activity->created_on;
             $item->description = $description;
             $item->date = $date->format('%d %B %Y, %R');
             $item->category = '';
             $item->authorEmail = '';
             $item->author = '';
             $user = KFactory::tmp('lib.joomla.user', array('id' => $activity->created_by));
             if ($user->id) {
                 $item->authorEmail = $user->email;
                 $item->author = $user->name;
             }
             // loads item info into rss array
             $doc->addItem($item);
         }
         $doc->link = $this->createRoute('format=html&view=activities');
     }
 }
Esempio n. 16
0
 /**
  * Return a human friendly format of the date.
  *
  * @param KDate $date
  * @param array $config Optional array to pass format
  *
  * @return string
  */
 public function humanize($date, $config = array())
 {
     $config = new KConfig($config);
     $config->append(array('format' => '%B %d %Y', 'relative' => false, 'offset' => null));
     $format = $config->format;
     $diff = $this->_current_time->getDate(DATE_FORMAT_UNIXTIME) - $date->getDate(DATE_FORMAT_UNIXTIME);
     if ($config->relative) {
         $timeLeft = $diff < 0 ? '-FUTURE' : '';
         $diff = abs($diff);
         if ($diff < 1) {
             return sprintf(JText::_('LIB-AN-DATE-MOMENT'), $diff);
         }
         if ($diff < 60) {
             return $diff > 1 ? sprintf(JText::_('LIB-AN-DATE-SECONDS' . $timeLeft), $diff) : sprintf(JText::_('LIB-AN-DATE-SECOND' . $timeLeft), $diff);
         }
         $diff = round($diff / 60);
         if ($diff < 60) {
             return $diff > 1 ? sprintf(JText::_('LIB-AN-DATE-MINUTES' . $timeLeft), $diff) : sprintf(JText::_('LIB-AN-DATE-MINUTE' . $timeLeft), $diff);
         }
         $diff = round($diff / 60);
         if ($diff < 24) {
             return $diff > 1 ? sprintf(JText::_('LIB-AN-DATE-HOURS' . $timeLeft), $diff) : sprintf(JText::_('LIB-AN-DATE-HOUR' . $timeLeft), $diff);
         }
         $diff = round($diff / 24);
         if ($diff < 7) {
             return $diff > 1 ? sprintf(JText::_('LIB-AN-DATE-DAYS' . $timeLeft), $diff) : sprintf(JText::_('LIB-AN-DATE-DAY' . $timeLeft), $diff);
         }
         $diff = round($diff / 7);
         if ($diff < 4) {
             return $diff > 1 ? sprintf(JText::_('LIB-AN-DATE-WEEKS' . $timeLeft), $diff) : sprintf(JText::_('LIB-AN-DATE-WEEK' . $timeLeft), $diff);
         }
     } elseif ($config->offset) {
         $date->addHours($config->offset);
     }
     return $date->getDate($format);
 }