Example #1
0
 /**
  * Returns all media from the specified month.
  *
  * @param string $month The name of the month.
  * @param int $year The year.
  * @return array A status array, where the 'status' index is the
  *               status code of the operation, and the 'response' index
  *               is an array of Media objects on STATUS_OK or an error string otherwise.
  */
 public static function get_from_month($month, $year)
 {
     $result = Database::SELECT('id FROM ' . IMAGE_TABLE . ' ' . 'WHERE MONTHNAME(uploaded) = ? AND YEAR(uploaded) = ?' . 'ORDER BY id DESC, uploaded DESC', array($month, $year));
     if ($result['status'] == STATUS_OK) {
         $media = array();
         foreach ($result['response'] as $column) {
             $media[] = new Media($column['id']);
         }
         return array('status' => STATUS_OK, 'response' => $media);
     }
     return $result;
 }
Example #2
0
/**
 * Returns all months that have media.
 *
 * @return array A status array, where the 'status' index is
 *               the status code of the operation, and the 'response'
 *               index is an array in the format year=>array(months)
 *               on STATUS_OK or an error string otherwise.
 */
function get_media_months()
{
    $result = Database::SELECT('MONTHNAME(uploaded) as month, YEAR(uploaded) as year ' . 'FROM ' . IMAGE_TABLE . ' ' . 'GROUP BY MONTH(uploaded), YEAR(uploaded) ' . 'ORDER BY uploaded DESC');
    if ($result['status'] == STATUS_OK) {
        $months = array();
        foreach ($result['response'] as $column) {
            if (!isset($months[$column['year']])) {
                $months[$column['year']] = array();
            }
            $months[$column['year']][] = $column['month'];
        }
        return array('status' => STATUS_OK, 'response' => $months);
    }
    return $result;
}
Example #3
0
 /**
  * Returns an array of all tag names in alphabetical order.
  *
  * @return array An array of all tag names, or null on a database error.
  */
 public static function get_all_tags()
 {
     $result = Database::SELECT('name FROM ' . TAGS_TABLE);
     if ($result['status'] == STATUS_OK) {
         # Instead of Array ( [0] => Array ( [name] => tagname ) ...
         # return an array like Array ( [0] => tagname ...
         $tags = array();
         foreach ($result['response'] as $tag) {
             $tags[] = $tag['name'];
         }
         // Alphabetize
         sort($tags);
         return $tags;
     }
     return null;
 }
Example #4
0
 /**
  * Compares the histogram against all histograms in the database.
  * If a near match is found, the id of that image is returned.
  *
  * @return int The id of a matching image, or null if none matched.
  */
 public function compare_against_database()
 {
     $result = Database::SELECT('id, histograms FROM ' . IMAGE_TABLE);
     if ($result['status'] == STATUS_OK) {
         $lowest_value = self::$match_threshold;
         $id = null;
         foreach ($result['response'] as $column) {
             $value = $this->compare_against(new Histogram($column['histograms']));
             if ($value < $lowest_value && $value < self::$match_threshold) {
                 $id = intval($column['id']);
                 $lowest_value = $value;
             }
         }
         return $id;
     }
     return null;
 }
Example #5
0
 /**
  * Creates an object with information for the revision of the given id.
  *
  * @param int $id The id of the revision.
  * @return Revision The revision object.
  */
 public function __construct($id)
 {
     $this->id = intval($id);
     $cols = 'image_id,uploader,uploaded,filename,type';
     $result = Database::SELECT("{$cols} FROM " . REVISIONS_TABLE . ' WHERE id=?', array($this->id));
     $this->status = $result['status'];
     if ($this->status == STATUS_OK && count($result['response']) > 0) {
         $media_data = $result['response'][0];
         $this->filename = $media_data['filename'];
         $this->extension = $media_data['type'];
         $media_fn = MEDIA_DIR . $this->filename;
         $ext = $this->extension;
         $this->full_src = $media_fn . ".{$ext}";
         $this->src = $media_fn . WEB_SRC_SUFFIX . ".{$ext}";
         $this->thumb_src = $media_fn . THUMB_SRC_SUFFIX . ".{$ext}";
         $upload_date = new DateTime($media_data['uploaded']);
         $this->uploader = $media_data['uploader'];
         $this->upload_date = $media_data['uploaded'];
         $this->human_upload_date = $upload_date->format('F j, Y');
     }
 }
Example #6
0
 /**
  * Returns all revisions for the media.
  *
  * @return array An array of Revision objects, or null on database error.
  */
 public function get_revisions()
 {
     $result = Database::SELECT('id FROM ' . REVISIONS_TABLE . ' WHERE image_id = ?', array($this->id));
     if ($result['status'] != STATUS_OK) {
         return null;
     }
     $revisions = array();
     foreach ($result['response'] as $column) {
         $revisions[] = new Revision($column['id']);
     }
     return $revisions;
 }