Example #1
0
 /**
  * Format input date string
  * @param  $time int same as returned from PHP time()
  * @return string formatted date according to saved options
  */
 public function formatDate($time)
 {
     // This method gets executed in a loop. Cache some variable to avoid
     // repeated get_option calls to the database
     if (CF7DBPlugin::$checkForCustomDateFormat) {
         if ($this->getOption('UseCustomDateTimeFormat', 'true') == 'true') {
             CF7DBPlugin::$customDateFormat = $this->getOption('SubmitDateTimeFormat', 'Y-m-d H:i:s P');
         } else {
             CF7DBPlugin::$dateFormat = get_option('date_format');
             CF7DBPlugin::$timeFormat = get_option('time_format');
         }
         $this->setTimezone();
         CF7DBPlugin::$checkForCustomDateFormat = false;
     }
     // Support Shamsi(Jalali) dates by looking for a plugin that can produce the correct text for the date
     if (!function_exists('is_plugin_active') && @file_exists(ABSPATH . 'wp-admin/includes/plugin.php')) {
         include_once ABSPATH . 'wp-admin/includes/plugin.php';
     }
     if (function_exists('is_plugin_active')) {
         // See if wp-parsidate is active and if so, have it convert the date
         // using its 'parsidate' function
         if (is_plugin_active('wp-parsidate/wp-parsidate.php')) {
             if (function_exists('parsidate')) {
                 if (CF7DBPlugin::$customDateFormat) {
                     return parsidate(CF7DBPlugin::$customDateFormat, $time);
                 } else {
                     return parsidate(CF7DBPlugin::$dateFormat . ' ' . CF7DBPlugin::$timeFormat, $time);
                 }
             }
         } else {
             if (is_plugin_active('wp-jalali/wp-jalali.php')) {
                 $jDateFile = WP_PLUGIN_DIR . '/wp-jalali/inc/jalali-core.php';
                 if (@file_exists($jDateFile)) {
                     include_once $jDateFile;
                     if (function_exists('jdate')) {
                         //return jdate('l, F j, Y');
                         if (CF7DBPlugin::$customDateFormat) {
                             return jdate(CF7DBPlugin::$customDateFormat, $time);
                         } else {
                             return jdate(CF7DBPlugin::$dateFormat . ' ' . CF7DBPlugin::$timeFormat, $time);
                         }
                     }
                 }
             }
         }
     }
     if (CF7DBPlugin::$customDateFormat) {
         return date(CF7DBPlugin::$customDateFormat, $time);
     } else {
         return date_i18n(CF7DBPlugin::$dateFormat . ' ' . CF7DBPlugin::$timeFormat, $time);
     }
 }
Example #2
0
function wp_get_parchives($args = '')
{
    global $wpdb, $wp_locale, $persian_month_names;
    $defaults = array('type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'echo' => 1, 'order' => 'DESC');
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    $archive_link_m = home_url("'?m='");
    $results = $wpdb->get_results("SELECT date( post_date )as date,count(ID)as count FROM {$wpdb->posts} WHERE post_date < NOW() AND post_type = 'post' AND post_status = 'publish' group by date ORDER BY post_date DESC");
    if (!empty($results)) {
        if ($type == 'yearly') {
            $old_date = parsidate('Y', $results[0]->date, 'eng');
            $count = $results[0]->count;
            $c = count($results);
            for ($i = 1; $i < $c; $i++) {
                $dt = $results[$i];
                $date = parsidate('Y', $dt->date, 'eng');
                if ($date == $old_date) {
                    $count += $dt->count;
                } else {
                    echo_yarchive($old_date, $format, $before, $count, $show_post_count);
                    $old_date = $date;
                    $count = $dt->count;
                }
            }
            echo_yarchive($old_date, $format, $before, $count, $show_post_count);
        } elseif ($type == 'monthly') {
            $old_date = parsidate('Ym', $results[0]->date, 'eng');
            $count = $results[0]->count;
            $c = count($results);
            for ($i = 1; $i < $c; $i++) {
                $dt = $results[$i];
                $date = parsidate('Ym', $dt->date, 'eng');
                if ($date == $old_date) {
                    $count += $dt->count;
                } else {
                    echo_marchive($old_date, $format, $before, $count, $show_post_count);
                    $old_date = $date;
                    $count = $dt->count;
                }
            }
            echo_marchive($old_date, $format, $before, $count, $show_post_count);
        } elseif ($type == 'daily') {
            foreach ($results as $row) {
                $date = parsidate('Y,m,d', $row->date, 'eng');
                $date = explode(',', $date);
                if ($show_post_count) {
                    $count = '&nbsp;(' . fixnumber($row->count) . ')';
                } else {
                    $count = '';
                }
                $text = fixnumber($date[2]) . ' ' . $persian_month_names[intval($date[1])] . ' ' . fixnumber($date[0]);
                echo get_archives_link(get_day_link($date[0], $date[1], $date[2]), $text, $format, $before, $count);
            }
        }
    }
}