Plugin Directory

Changeset 994136


Ignore:
Timestamp:
09/21/2014 08:54:05 AM (12 years ago)
Author:
freshlabs
Message:

Implemented post specific functions from other classes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-simile-timeline/trunk/inc/WPSimileTimelinePost.class.php

    r994131 r994136  
    109109    }
    110110   
    111     /*
     111    /**
    112112     * Save start and end dates of an event(post) to the database
    113113     */
     
    120120        }
    121121    }
     122   
     123    /**
     124     * Get the minimum or maximum date of wpdb->posts.$column in $categories
     125     */
     126    function queryEventDate($minmax, $column, $categories) {
     127        global $wpdb;
     128
     129        $relation = "SELECT object_id FROM $wpdb->term_relationships " .
     130                    "INNER JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id IN ($categories) )";
     131
     132        $query = "SELECT $minmax($wpdb->posts.$column) from $wpdb->posts INNER JOIN ($relation) t1 ON (t1.object_id=$wpdb->posts.ID) " .
     133                 "WHERE $column != '0000-00-00 00:00:00' AND post_status='publish' AND post_type='post'";
     134
     135        return $wpdb->get_var($query);
     136    }
     137   
     138    /**
     139     * Get the date of the very first or last post dependant from the start date
     140     * @param type $minmax
     141     * @param type $type
     142     * @param type $format
     143     * @param type $categories
     144     * @return type
     145     */
     146    function getMinMaxEventDate($minmax, $type, $format = 'r', $categories) {
     147        global $wpdb;
     148
     149        $column = 'stl_timeline_event_' . $type;
     150
     151        // try to get the extreme post date from stl-columns
     152        $date = self::queryEventDate($minmax, $column, $categories);
     153
     154        if (empty($date)) {
     155            $column = 'post_date';
     156            // get usual post date when start or end date isn't set
     157            $date = self::queryEventDate($minmax, $column, $categories);
     158        }
     159        if ($format != null) {
     160            $date = adodb_date2($format, $date);
     161        }
     162        return $date;
     163    }
     164
    122165}
     166
    123167?>
Note: See TracChangeset for help on using the changeset viewer.