/**
  * Sets a comment date/time value
  *
  * @param string $datetime
  */
 function setDateTime($datetime)
 {
     if ($datetime) {
         $newtime = dateTimeConvert($datetime);
         if ($newtime === false) {
             return;
         }
         $this->set('date', $newtime);
     } else {
         $this->set('date', NULL);
     }
 }
Exemple #2
0
 /**
  * sets the expire date
  *
  */
 function setExpireDate($ed)
 {
     if ($ed) {
         $newtime = dateTimeConvert($ed);
         if ($newtime === false) {
             return;
         }
         $this->set('expiredate', $newtime);
     } else {
         $this->set('expiredate', NULL);
     }
 }
    if (!empty($albumlist)) {
        $albumids = ' AND (' . $albumids . ')';
        $albumidlist = ' AND (' . $albumidlist . ')';
    }
}
if (isset($_GET['propagate_unpublished'])) {
    foreach ($albumlist as $albumname) {
        $album = newAlbum($albumname);
        if (!$album->getShow()) {
            unpublishSubalbums($album);
        }
    }
    unset($_GET['propagate_unpublished']);
    $report = 'propagate';
}
$mtime = dateTimeConvert($requestdate, true);
$sql = "SELECT `folder`, `id` FROM " . prefix('albums') . ' WHERE `show`="0"' . $albumids;
$result = query_full_array($sql);
if (is_array($result)) {
    foreach ($result as $row) {
        $publish_albums_list[$row['folder']] = $row['id'];
    }
}
$sql = 'SELECT `filename`, ' . prefix('images') . '.id as id, folder FROM ' . prefix('images') . ',' . prefix('albums') . ' WHERE ' . prefix('images') . '.show="0" AND ' . prefix('images') . '.mtime < "' . $mtime . '" AND ' . prefix('albums') . '.id=' . prefix('images') . '.albumid' . $albumidlist;
$result = query_full_array($sql);
if (is_array($result)) {
    foreach ($result as $row) {
        $publish_images_list[$row['folder']][$row['filename']] = $row['id'];
    }
    ksort($publish_images_list, SORT_LOCALE_STRING);
}
Exemple #4
0
 /**
  * sets the publish date
  *
  */
 function setPublishDate($ed)
 {
     if ($ed) {
         $newtime = dateTimeConvert($ed);
         if ($newtime === false) {
             return;
         }
         $this->set('publishdate', $newtime);
     } else {
         $this->set('publishdate', NULL);
     }
 }
 /** For every album in the gallery, look for its file. Delete from the database
  * if the file does not exist. Do the same for images. Clean up comments that have
  * been left orphaned.
  *
  * Returns true if the operation was interrupted because it was taking too long
  *
  * @param bool $cascade garbage collect every image and album in the gallery.
  * @param bool $complete garbage collect every image and album in the *database* - completely cleans the database.
  * @param  int $restart Image ID to restart scan from
  * @return bool
  */
 function garbageCollect($cascade = true, $complete = false, $restart = '')
 {
     if (empty($restart)) {
         // Check for the existence of top-level albums (subalbums handled recursively).
         $result = query("SELECT * FROM " . prefix('albums'));
         $dead = array();
         $live = array('');
         // purge the root album if it exists
         $deadalbumthemes = array();
         // Load the albums from disk
         $albumfolder = getAlbumFolder();
         while ($row = mysql_fetch_assoc($result)) {
             if (!file_exists($albumfolder . UTF8ToFilesystem($row['folder'])) || in_array($row['folder'], $live)) {
                 $dead[] = $row['id'];
                 if ($row['album_theme'] !== '') {
                     // orphaned album theme options table
                     $deadalbumthemes[$row['id']] = $row['folder'];
                 }
             } else {
                 $live[] = $row['folder'];
             }
         }
         if (count($dead) > 0) {
             /* delete the dead albums from the DB */
             $first = array_pop($dead);
             $sql1 = "DELETE FROM " . prefix('albums') . " WHERE `id`='{$first}'";
             $sql2 = "DELETE FROM " . prefix('images') . " WHERE `albumid`='{$first}'";
             $sql3 = "DELETE FROM " . prefix('comments') . " WHERE `type`='albums' AND `ownerid`='{$first}'";
             $sql4 = "DELETE FROM " . prefix('obj_to_tag') . " WHERE `type`='albums' AND `objectid`='{$first}'";
             foreach ($dead as $albumid) {
                 $sql1 .= " OR `id` = '{$albumid}'";
                 $sql2 .= " OR `albumid` = '{$albumid}'";
                 $sql3 .= " OR `ownerid` = '{$albumid}'";
                 $sql4 .= " OR `objectid` = '{$albumid}'";
             }
             $n = query($sql1);
             if (!$complete && $n > 0 && $cascade) {
                 query($sql2);
                 query($sql3);
                 query($sql4);
             }
         }
         if (count($deadalbumthemes) > 0) {
             // delete the album theme options tables for dead albums
             foreach ($deadalbumthemes as $id => $deadtable) {
                 $sql = 'DELETE FROM ' . prefix('options') . ' WHERE `ownerid`=' . $id;
                 query($sql, true);
             }
         }
     }
     if ($complete) {
         if (empty($restart)) {
             /* refresh 'metadata' of dynamic albums */
             $albumfolder = getAlbumFolder();
             $albumids = query_full_array("SELECT `id`, `mtime`, `folder` FROM " . prefix('albums') . " WHERE `dynamic`='1'");
             foreach ($albumids as $album) {
                 if (($mtime = filemtime($albumfolder . UTF8ToFilesystem($album['folder']))) > $album['mtime']) {
                     // refresh
                     $data = file_get_contents($albumfolder . UTF8ToFilesystem($album['folder']));
                     while (!empty($data)) {
                         $data1 = trim(substr($data, 0, $i = strpos($data, "\n")));
                         if ($i === false) {
                             $data1 = $data;
                             $data = '';
                         } else {
                             $data = substr($data, $i + 1);
                         }
                         if (strpos($data1, 'WORDS=') !== false) {
                             $words = "words=" . urlencode(substr($data1, 6));
                         }
                         if (strpos($data1, 'THUMB=') !== false) {
                             $thumb = trim(substr($data1, 6));
                         }
                         if (strpos($data1, 'FIELDS=') !== false) {
                             $fields = "&searchfields=" . trim(substr($data1, 7));
                         }
                     }
                     if (!empty($words)) {
                         if (empty($fields)) {
                             $fields = '&searchfields=4';
                         }
                     }
                     $sql = "UPDATE " . prefix('albums') . "SET `search_params`=\"{$words}.{$fields}\", `thumb`=\"{$thumb}\", `mtime`=\"{$mtime}\" WHERE `id`=\"" . $album['id'] . "\"";
                     query($sql);
                 }
             }
             /* Delete all image entries that don't belong to an album at all. */
             $albumids = query_full_array("SELECT `id` FROM " . prefix('albums'));
             /* all the album IDs */
             $idsofalbums = array();
             foreach ($albumids as $row) {
                 $idsofalbums[] = $row['id'];
             }
             $imageAlbums = query_full_array("SELECT DISTINCT `albumid` FROM " . prefix('images'));
             /* albumids of all the images */
             $albumidsofimages = array();
             foreach ($imageAlbums as $row) {
                 $albumidsofimages[] = $row['albumid'];
             }
             $orphans = array_diff($albumidsofimages, $idsofalbums);
             /* albumids of images with no album */
             if (count($orphans) > 0) {
                 /* delete dead images from the DB */
                 $firstrow = array_pop($orphans);
                 $sql = "DELETE FROM " . prefix('images') . " WHERE `albumid`='" . $firstrow . "'";
                 foreach ($orphans as $id) {
                     $sql .= " OR `albumid`='" . $id . "'";
                 }
                 query($sql);
                 // Then go into existing albums recursively to clean them... very invasive.
                 foreach ($this->getAlbums(0) as $folder) {
                     $album = new Album($this, $folder);
                     if (!$album->isDynamic()) {
                         if (is_null($album->getDateTime())) {
                             // see if we can get one from an image
                             $image = $album->getImage(0);
                             if (is_object($image)) {
                                 $album->setDateTime($image->getDateTime());
                             }
                         }
                         $album->garbageCollect(true);
                         $album->preLoad();
                     }
                 }
             }
         }
         /* Look for image records where the file no longer exists. While at it, check for images with IPTC data to update the DB */
         $start = array_sum(explode(" ", microtime()));
         // protect against too much processing.
         if (!empty($restart)) {
             $restartwhere = ' WHERE `id`>' . $restart;
         } else {
             $restartwhere = '';
         }
         $sql = 'SELECT `id`, `albumid`, `filename`, `desc`, `title`, `date`, `mtime` FROM ' . prefix('images') . $restartwhere . ' ORDER BY `id`';
         $images = query_full_array($sql);
         foreach ($images as $image) {
             $sql = 'SELECT `folder` FROM ' . prefix('albums') . ' WHERE `id`="' . $image['albumid'] . '";';
             $row = query_single_row($sql);
             $imageName = UTF8ToFilesystem(getAlbumFolder() . $row['folder'] . '/' . $image['filename']);
             if (file_exists($imageName)) {
                 if ($image['mtime'] != filemtime($imageName)) {
                     // file has changed since we last saw it
                     /* check metadata */
                     $metadata = getImageMetadata($imageName);
                     $set = '';
                     /* title */
                     $defaultTitle = substr($image['filename'], 0, strrpos($image['filename'], '.'));
                     if (empty($defaultTitle)) {
                         $defaultTitle = $image['filename'];
                     }
                     if ($defaultTitle == $image['title']) {
                         /* default title */
                         if (isset($metadata['title'])) {
                             $set = ',`title`="' . mysql_real_escape_string($metadata['title']) . '"';
                         }
                     }
                     /* description */
                     if (!isset($row['desc'])) {
                         if (isset($metadata['desc'])) {
                             $set .= ', `desc`="' . mysql_real_escape_string($metadata['desc']) . '"';
                         }
                     }
                     /* tags */
                     if (isset($metadata['tags'])) {
                         $tags = $metadata['tags'];
                         storeTags($tags, $image['id'], 'images');
                     }
                     /* location, city, state, and country */
                     if (isset($metadata['location'])) {
                         $set .= ', `location`="' . mysql_real_escape_string($metadata['location']) . '"';
                     }
                     if (isset($metadata['city'])) {
                         $set .= ', `city`="' . mysql_real_escape_string($metadata['city']) . '"';
                     }
                     if (isset($metadata['state'])) {
                         $set .= ', `state`="' . mysql_real_escape_string($metadata['state']) . '"';
                     }
                     if (isset($metadata['country'])) {
                         $set .= ', `country`="' . mysql_real_escape_string($metadata['country']) . '"';
                     }
                     /* credit & copyright */
                     if (isset($metadata['credit'])) {
                         $set .= ', `credit`="' . escape($metadata['credit']) . '"';
                     }
                     if (isset($metadata['copyright'])) {
                         $set .= ', `copyright`="' . escape($metadata['copyright']) . '"';
                     }
                     /* date (for sorting) */
                     $newDate = strftime('%Y-%m-%d %T', filemtime($imageName));
                     if (isset($metadata['date'])) {
                         $dt = dateTimeConvert($metadata['date']);
                         if ($dt !== false) {
                             // flaw in exif/iptc data?
                             $newDate = $dt;
                         }
                     }
                     $set .= ', `date`="' . $newDate . '"';
                     /* update DB is necessary */
                     $sql = "UPDATE " . prefix('images') . " SET `EXIFValid`=0,`mtime`=" . filemtime($imageName) . $set . " WHERE `id`='" . $image['id'] . "'";
                     query($sql);
                 }
             } else {
                 $sql = 'DELETE FROM ' . prefix('images') . ' WHERE `id`="' . $image['id'] . '";';
                 $result = query($sql);
                 $sql = 'DELETE FROM ' . prefix('comments') . ' WHERE `type` IN (' . zp_image_types('"') . ') AND `ownerid` ="' . $image['id'] . '";';
                 $result = query($sql);
             }
             if (array_sum(explode(" ", microtime())) - $start >= 10) {
                 return $image['id'];
                 // avoide excessive processing
             }
         }
         /* clean the comments table */
         /* do the images */
         $imageids = query_full_array('SELECT `id` FROM ' . prefix('images'));
         /* all the image IDs */
         $idsofimages = array();
         foreach ($imageids as $row) {
             $idsofimages[] = $row['id'];
         }
         $commentImages = query_full_array("SELECT DISTINCT `ownerid` FROM " . prefix('comments') . 'WHERE `type` IN (' . zp_image_types('"') . ')');
         /* imageids of all the comments */
         $imageidsofcomments = array();
         foreach ($commentImages as $row) {
             $imageidsofcomments[] = $row['ownerid'];
         }
         $orphans = array_diff($imageidsofcomments, $idsofimages);
         /* image ids of comments with no image */
         if (count($orphans) > 0) {
             /* delete dead comments from the DB */
             $firstrow = array_pop($orphans);
             $sql = "DELETE FROM " . prefix('comments') . " WHERE `type` IN (" . zp_image_types("'") . ") AND `ownerid`='" . $firstrow . "'";
             foreach ($orphans as $id) {
                 $sql .= " OR `ownerid`='" . $id . "'";
             }
             query($sql);
         }
         /* do the same for album comments */
         $albumids = query_full_array('SELECT `id` FROM ' . prefix('albums'));
         /* all the album IDs */
         $idsofalbums = array();
         foreach ($albumids as $row) {
             $idsofalbums[] = $row['id'];
         }
         $commentAlbums = query_full_array("SELECT DISTINCT `ownerid` FROM " . prefix('comments') . 'WHERE `type`="albums"');
         /* album ids of all the comments */
         $albumidsofcomments = array();
         foreach ($commentAlbums as $row) {
             $albumidsofcomments[] = $row['ownerid'];
         }
         $orphans = array_diff($albumidsofcomments, $idsofalbums);
         /* album ids of comments with no album */
         if (count($orphans) > 0) {
             /* delete dead comments from the DB */
             $firstrow = array_pop($orphans);
             $sql = "DELETE FROM " . prefix('comments') . "WHERE `type`='albums' AND `ownerid`='" . $firstrow . "'";
             foreach ($orphans as $id) {
                 $sql .= " OR `ownerid`='" . $id . "'";
             }
             query($sql);
         }
         /* clean the tags table */
         /* do the images */
         $tagImages = query_full_array("SELECT DISTINCT `objectid` FROM " . prefix('obj_to_tag') . 'WHERE `type` IN (' . zp_image_types('"') . ')');
         /* imageids of all the comments */
         $imageidsoftags = array();
         foreach ($tagImages as $row) {
             $imageidsoftags[] = $row['objectid'];
         }
         $orphans = array_diff($imageidsoftags, $idsofimages);
         /* image ids of comments with no image */
         if (count($orphans) > 0) {
             /* delete dead tags from the DB */
             $firstrow = array_pop($orphans);
             $sql = "DELETE FROM " . prefix('obj_to_tag') . " WHERE `type` IN (" . zp_image_types('"') . ") AND (`objectid`='" . $firstrow . "'";
             foreach ($orphans as $id) {
                 $sql .= " OR `objectid`='" . $id . "'";
             }
             $sql .= ')';
             query($sql);
         }
         /* do the same for album tags */
         $tagAlbums = query_full_array("SELECT DISTINCT `objectid` FROM " . prefix('obj_to_tag') . 'WHERE `type`="albums"');
         /* album ids of all the comments */
         $albumidsoftags = array();
         foreach ($tagAlbums as $row) {
             $albumidsoftags[] = $row['objectid'];
         }
         $orphans = array_diff($albumidsoftags, $idsofalbums);
         /* album ids of comments with no album */
         if (count($orphans) > 0) {
             /* delete dead tags from the DB */
             $firstrow = array_pop($orphans);
             $sql = "DELETE FROM " . prefix('obj_to_tag') . "WHERE `type`='albums' AND `objectid`='" . $firstrow . "'";
             foreach ($orphans as $id) {
                 $sql .= " OR `objectid`='" . $id . "'";
             }
             query($sql);
         }
     }
     return false;
 }
<?php

include_once 'gc-config.php';
include_once 'gc-function.php';
/* 範例資料 */
$data_set = array();
array_push($data_set, eventDesc("first", "Taipei", "event1", dateTimeConvert("2014-12-25", "14:00:00"), dateTimeConvert("2014-12-25", "16:00:00")));
array_push($data_set, eventDesc("second", "Taipei", "event2", dateTimeConvert("2014-12-26", "14:00:00"), dateTimeConvert("2014-12-26", "16:00:00")));
foreach ($data_set as $data) {
    // 檢查 calendar 上 event 是否已存在,若 event 不存在則寫入事件
    $exist_check = false;
    # 先假設不存在
    // 若 title, 起始時間, 結束時間相等,則判斷 event 存在
    foreach ($cal_current_events as $event) {
        if ($event["title"] == $data["title"] && $event["start"] == $data["start"] && $event["end"] == $data["end"]) {
            $exist_check = true;
            # 判斷成立
            break;
        }
    }
    // 若 event 已存在的話,跳過進行下一個迴圈
    if ($exist_check) {
        echo $data["title"] . "事件已存在<br>\n";
        continue;
    }
    // 將 event 寫入 calendar 內
    $event = new Google_Service_Calendar_Event();
    $event->setSummary($data["title"]);
    // 事件標題
    $event->setLocation($data["where"]);
    // 事件地點
     $i = 0;
     foreach ($albumIDs as $ID) {
         if ($i > 0) {
             $albumidlist .= ' OR ';
             $albumids .= ' OR ';
         }
         $albumidlist .= prefix('images') . '.albumid=' . $ID;
         $albumids .= '`id`=' . $ID;
         $i++;
     }
     if (!empty($albumlist)) {
         $albumids = ' AND (' . $albumids . ')';
         $albumidlist = ' AND (' . $albumidlist . ')';
     }
 }
 $mtime = dateTimeConvert(sanitize($requestdate), true);
 $sql = "SELECT `folder`, `id` FROM " . prefix('albums') . ' WHERE `show`="0"' . $albumids;
 $result = query_full_array($sql);
 if (is_array($result)) {
     foreach ($result as $row) {
         $publish_albums_list[$row['folder']] = $row['id'];
     }
 }
 $sql = 'SELECT `filename`, ' . prefix('images') . '.id as id, folder FROM ' . prefix('images') . ',' . prefix('albums') . ' WHERE ' . prefix('images') . '.show="0" AND ' . prefix('images') . '.mtime < "' . $mtime . '" AND ' . prefix('albums') . '.id=' . prefix('images') . '.albumid' . $albumidlist;
 $result = query_full_array($sql);
 if (is_array($result)) {
     foreach ($result as $row) {
         $publish_images_list[$row['folder']][$row['filename']] = $row['id'];
     }
 }
 if ($_zp_loggedin & ADMIN_RIGHTS) {
<?php

session_start();
include_once 'gc-config.php';
include_once 'gc-function.php';
/* 範例資料 */
$data_set = array();
array_push($data_set, eventDesc($_POST["id"], $_POST["location"], $_POST["things"], dateTimeConvert($_POST["startdate"], $_POST["starttime"]), dateTimeConvert($_POST["enddate"], $_POST["endtime"])));
foreach ($data_set as $data) {
    // 檢查 calendar 上 event 是否已存在,若 event 不存在則寫入事件
    $exist_check = false;
    # 先假設不存在
    // 若 title, 起始時間, 結束時間相等,則判斷 event 存在
    foreach ($cal_current_events as $event) {
        if ($event["title"] == $data["title"] && $event["start"] == $data["start"] && $event["end"] == $data["end"]) {
            $exist_check = true;
            # 判斷成立
            break;
        }
    }
    // 若 event 已存在的話,跳過進行下一個迴圈
    if ($exist_check) {
        echo $data["title"] . "事件已存在<br>\n";
        continue;
    }
    // 將 event 寫入 calendar 內
    $event = new Google_Service_Calendar_Event();
    $data["title"] = "(" . $_SESSION['username'] . ")" . $data["title"];
    $event->setSummary($data["title"]);
    // 事件標題
    $event->setLocation($data["where"]);
Exemple #9
0
 /**
  *
  * sets the last change date
  */
 function setLastchange($d)
 {
     if ($d) {
         $newtime = dateTimeConvert($d);
         if ($newtime === false) {
             return;
         }
         $this->set('lastchange', $newtime);
     } else {
         $this->set('lastchange', NULL);
     }
 }