Beispiel #1
0
function safe_strftime($format, $time = '')
{
    if ($format == 'since') {
        $str = since($time);
        return $str;
    } else {
        $str = strftime($format, $time);
        return $str;
    }
}
Beispiel #2
0
function formatComments($darr)
{
    global $prefs, $txpcfg, $comments_disallow_images, $txpac;
    extract($prefs);
    $preview = gps('preview');
    $id = gps('id');
    $Form = fetch('Form', 'txp_form', 'name', 'comments');
    $out = '';
    foreach ($darr as $vars) {
        extract($vars);
        if ($preview) {
            include_once $txpcfg['txpath'] . '/lib/classTextile.php';
            $time = time();
            $discussid = 0;
            $textile = new Textile();
            $im = !empty($comments_disallow_images) ? 1 : '';
            $message = trim(nl2br($textile->TextileThis(strip_tags($message), 1, '', $im)));
        }
        if ($comments_dateformat == "since") {
            $comment_time = since($time + $timeoffset);
        } else {
            $comment_time = date($comments_dateformat, $time + $timeoffset);
        }
        $web = str_replace("http://", "", $web);
        if ($email && !$web && !$txpac['never_display_email']) {
            $name = '<a href="' . eE('mailto:' . $email) . '">' . $name . '</a>';
        }
        if ($web) {
            $name = '<a href="http://' . $web . '" title="' . $web . '">' . $name . '</a>';
        }
        $Section = fetch('Section', 'textpattern', 'ID', $parentid);
        if ($url_mode == 1) {
            $dlink = $path_from_root . $Section . '/' . $parentid . '/#c' . $discussid;
        } else {
            if ($url_mode == 0) {
                $dlink = $path_from_root . 'index.php?id=' . $parentid . '#c' . $discussid;
            }
        }
        $vals = array('comment_name' => $name, 'message' => $message, 'comment_time' => $comment_time);
        $temp = $Form;
        foreach ($vals as $a => $b) {
            $temp = str_replace('<txp:' . $a . ' />', $b, $temp);
        }
        $temp = preg_replace('/<(txp:comment_permlink)>(.*)<\\/\\1>/U', '<a href="' . $dlink . '">$2</a>', $temp);
        $out .= n . t . '<li id="c' . $discussid . '" style="margin-top:2em">' . $temp . '</li>';
    }
    return $out;
}
Beispiel #3
0
function safe_strftime($format, $time = '', $gmt = 0, $override_locale = '')
{
    global $locale;
    $old_locale = $locale;
    if (!$time) {
        $time = time();
    }
    # we could add some other formats here
    if ($format == 'iso8601' or $format == 'w3cdtf') {
        $format = '%Y-%m-%dT%H:%M:%SZ';
        $gmt = 1;
    } elseif ($format == 'rfc822') {
        $format = '%a, %d %b %Y %H:%M:%S GMT';
        $gmt = 1;
        $override_locale = 'en-gb';
    }
    if ($override_locale) {
        getlocale($override_locale);
    }
    if ($format == 'since') {
        $str = since($time);
    } elseif ($gmt) {
        $str = gmstrftime($format, $time);
    } else {
        $str = strftime($format, $time + tz_offset($time));
    }
    @(list($lang, $charset) = explode('.', $locale));
    if (empty($charset)) {
        $charset = 'ISO-8859-1';
    } elseif (IS_WIN and is_numeric($charset)) {
        // Score -1 for consistent naming conventions
        $charset = 'Windows-' . $charset;
    }
    if ($charset != 'UTF-8' and $format != 'since') {
        $new = '';
        if (is_callable('iconv')) {
            $new = @iconv($charset, 'UTF-8', $str);
        }
        if ($new) {
            $str = $new;
        } elseif (is_callable('utf8_encode')) {
            $str = utf8_encode($str);
        }
    }
    # revert to the old locale
    if ($override_locale) {
        $locale = setlocale(LC_ALL, $old_locale);
    }
    return $str;
}
Beispiel #4
0
 /**
  * helper function to wrap the added time stamp
  *
  * @return string
  * @author Craig Ulliott
  */
 public function getAgeString()
 {
     return since($this->get_added());
 }
Beispiel #5
0
function comment_time($atts)
{
    global $thiscomment, $comments_dateformat;
    if ($comments_dateformat == "since") {
        $comment_time = since($thiscomment['time'] + tz_offset());
    } else {
        $comment_time = safe_strftime($comments_dateformat, $thiscomment['time']);
    }
    return $comment_time;
}
Beispiel #6
0
/**
 * Formats a time.
 *
 * Respects the locale and local timezone, and makes sure the
 * output string is encoded in UTF-8.
 *
 * @param   string $format          The date format
 * @param   int    $time            UNIX timestamp. Defaults to time()
 * @param   bool   $gmt             Return GMT time
 * @param   string $override_locale Override the locale
 * @return  string Formatted date
 * @package DateTime
 * @example
 * echo safe_strftime('w3cdtf');
 */
function safe_strftime($format, $time = '', $gmt = false, $override_locale = '')
{
    global $locale;
    if (!$time) {
        $time = time();
    }
    // We could add some other formats here.
    if ($format == 'iso8601' or $format == 'w3cdtf') {
        $format = '%Y-%m-%dT%H:%M:%SZ';
        $gmt = true;
    } elseif ($format == 'rfc822') {
        $format = '%a, %d %b %Y %H:%M:%S GMT';
        $gmt = true;
        $override_locale = 'en-gb';
    }
    if ($override_locale) {
        $oldLocale = Txp::get('Textpattern_L10n_Locale')->getLocale(LC_TIME);
        Txp::get('Textpattern_L10n_Locale')->setLocale(LC_TIME, $override_locale);
    }
    if ($format == 'since') {
        $str = since($time);
    } elseif ($gmt) {
        $str = gmstrftime($format, $time);
    } else {
        $str = strftime($format, $time + tz_offset($time));
    }
    @(list($lang, $charset) = explode('.', $locale));
    if (empty($charset)) {
        $charset = 'ISO-8859-1';
    } elseif (IS_WIN and is_numeric($charset)) {
        $charset = 'Windows-' . $charset;
    }
    if ($charset != 'UTF-8' and $format != 'since') {
        $new = '';
        if (is_callable('iconv')) {
            $new = @iconv($charset, 'UTF-8', $str);
        }
        if ($new) {
            $str = $new;
        } elseif (is_callable('utf8_encode')) {
            $str = utf8_encode($str);
        }
    }
    // Revert to the old locale.
    if ($override_locale && $oldLocale) {
        Txp::get('Textpattern_L10n_Locale')->setLocale(LC_TIME, $oldLocale);
    }
    return $str;
}
Beispiel #7
0
        echo $comments;
        if (false) {
            foreach ($comments as $comment) {
                if ($this->request->api('me') != 'anonymous') {
                    $like[] = 'm_like' . $comment['msg_id'];
                }
                if ($comment['user'] == NULL) {
                    $comment['user'] = '******';
                }
                if (strlen($comment['body']) > 50) {
                    $reply = substr_replace($comment['body'] . "", '...', 70);
                } else {
                    $reply = $comment['body'];
                }
                $timestamp = strtotime($comment['date']);
                $replace = array("%form_action%" => '%appurl%rmpost/', "%msg_id%" => $comment['msg_id'], "%likes%" => $comment['likes'], "%body%" => $comment['body'], "%since%" => since($timestamp), "%device%" => $comment['device'], '%x%' => '');
                if ($thread['owner_id'] == $this->request->api('getuid') || $comment['sender_id'] == $this->request->api('getuid')) {
                    $replace['%x%'] = '<a href="%appurl%rmpost/' . $comment['msg_id'] . '/" method="post" class="removepost hrefapi">X</a>';
                }
                $replace['%sender_id%'] = $comment['user'];
                $reg_http = '/http:\\/\\/[a-zA-Z0-9\\-]+\\.[a-zA-Z0-9\\-\\.?=_\\/]+/';
                preg_match_all($reg_http, $comment['body'], $matches);
                for ($i = 0; $i < count($matches[0]); $i++) {
                    $comment['body'] = str_replace($matches[0][$i], '<a href="' . $matches[0][$i] . '">' . $matches[0][$i] . '</a>', $comment['body']);
                }
                echo str_replace(array_keys($replace), array_values($replace), $skin_reply);
                $options .= '
					<option value="' . $comment['msg_id'] . '">
						Reply to ' . $comment['user'] . ' - ' . $reply . '
					</options>
				';
Beispiel #8
0
						<p><?php 
        $Parsedown = new Parsedown();
        echo $Parsedown->text($post['content']);
        ?>
</p>
						<br style="clear:both;" />
						<span class="date">
							<a href="%appurl%<?php 
        echo $id . '-' . $url_title;
        ?>
">Permalink</a> | 
							Posted by <?php 
        echo $post['user'];
        ?>
 <?php 
        echo since(strtotime($post['date']));
        ?>
						</span>			
					</div>
				</div>
				<?php 
    }
    ?>
			</div>
			<?php 
} else {
    ?>
			<p>No threads to show</p>
			<?php 
}
?>
Beispiel #9
0
function posted($atts)
{
    global $dateformat, $archive_dateformat, $timeoffset, $pg, $c, $thisarticle, $id, $txpcfg;
    $date_offset = $thisarticle['posted'] + $timeoffset;
    if (is_array($atts)) {
        extract($atts);
    }
    if (!empty($format)) {
        if ($format == 'since') {
            $date_out = since($thisarticle['posted']);
        } else {
            $date_out = date($format, $date_offset);
        }
    } else {
        if ($pg or $id or $c) {
            $dateformat = $archive_dateformat;
        }
        if ($dateformat == "since") {
            $date_out = since($thisarticle['posted']);
        } else {
            $date_out = date($dateformat, $date_offset);
        }
    }
    if (!empty($lang)) {
        if (empty($GLOBALS['date_lang'])) {
            $date_lang = load_lang($lang . '_dates');
        } else {
            global $date_lang;
        }
        if ($date_lang) {
            foreach ($date_lang as $k => $v) {
                $date_out = str_replace($k, $v, $date_out);
            }
        }
    }
    if (!empty($wraptag)) {
        $date_out = tag($date_out, $wraptag);
    }
    return $date_out;
}
/**
 * modifier.date_format.php - smarty modifier to format a timestamp
 *
 * @param unknown $date
 * @param unknown $format (optional)
 * @return unknown
 */
function smarty_modifier_date_format($date, $format = "%F %j, %Y, %g:%i %a")
{
    if ($date < 1) {
        return '';
    }
    // locale should be defined in a config file, not case by case
    define('C_LOCALE', 'en_GB');
    setlocale(LC_TIME, C_LOCALE);
    switch ($format) {
        case "full":
            return strftime("%A, %d. %B %Y, %H:%M", $date);
            break;
        case "date":
            return strftime("%A, %d. %B %Y", $date);
            break;
        case "europe":
            return strftime("%d.%m.%Y", $date);
            break;
        case "shortdate":
            return strftime("%x", $date);
            break;
        case "month":
            return strftime("%B", $date);
            break;
        case "year":
            return strftime("%Y", $date);
            break;
        case "monthyear":
            return strftime("%B %Y", $date);
            break;
        case "time":
            return strftime("%H:%M", $date);
            break;
        case "s1":
            return date("F j, Y, g:i a", $date);
            break;
        case "s2":
            return date("F j, Y", $date);
            break;
        case "atom":
            return date('Y-m-d\\TH:i:s\\Z', $date);
            break;
        case "rss20":
            return strftime("%a, %d %b %Y %H:%M:%S %Z", $date);
            break;
        case "rss92":
            return strftime("%a, %d %b %Y %H:%M:%S %Z", $date);
            break;
        case "suffix":
            return date("S", $date);
            break;
            // a clever little hack to make date() return a ISO 8601 standard date string for use in RSS 1.0
        // a clever little hack to make date() return a ISO 8601 standard date string for use in RSS 1.0
        case "rss10":
            return substr(date("Y-m-d\\Th:i:sO", $date), 0, 22) . ":" . substr(date("O", $date), 3);
            break;
            // called Jim in reference to RevJim ( revjim.net ) who first used this format ( afict )
        // called Jim in reference to RevJim ( revjim.net ) who first used this format ( afict )
        case "jim":
            return since($date) . " on " . date("F j, Y", $date);
            break;
        case "since":
            return since($date);
            break;
        default:
            //default should behave like the original smarty date_format
            //see if there is at least one % in the date. then we go for new format
            if (substr_count("{$format}", '%') > 0) {
                return strftime($format, $date);
            } else {
                return date($format, $date);
            }
            break;
    }
    //switch
}
Beispiel #11
0
function formatDate($uPosted, $pg = '')
{
    global $dateformat, $archive_dateformat, $timeoffset, $c, $id;
    if ($pg or $id or $c) {
        $dateformat = $archive_dateformat;
    }
    if ($dateformat == "since") {
        $date = since($uPosted);
    } else {
        $date = date("{$dateformat}", $uPosted + $timeoffset);
    }
    return $date;
}
Beispiel #12
0
function comment_time($atts)
{
    global $thiscomment, $comments_dateformat;
    extract(lAtts(array('format' => $comments_dateformat), $atts));
    if ($format == 'since') {
        $comment_time = since($thiscomment['time'] + tz_offset());
    } else {
        $comment_time = safe_strftime($format, $thiscomment['time']);
    }
    return $comment_time;
}