Example #1
0
 function convertImage(&$image)
 {
     $thumbUrlMap = $image->getThumbUrlMap();
     $image = array('id' => (string) $image->getIdNum(), 'ownerId' => null, 'createdDate' => null, 'modifiedDate' => null, 'title' => $image->getTitle(), 'keywordsArray' => $image->getTags(), 'hasKeywords' => count($image->getTags()) > 0, 'keywords' => implode(',', $image->getTags()), 'description' => $image->getDescription(), 'caption' => $image->getTitle(), 'captionLong' => $image->getDescription(), 'parentAlbumId' => $this->albumId, 'mediaHandler' => 'extapp', 'thumbnailId' => null, 'previewId' => null, 'originalId' => null, 'thumbnailRef' => (string) $image->getSmallThumb(), 'thumbnailMimeType' => 'image/jpeg', 'thumbnailWidth' => 72, 'thumbnailHeight' => 0, 'thumbnailBytes' => 0, 'previewRef' => (string) $image->getMediumThumb(), 'previewMimeType' => 'image/jpeg', 'previewWidth' => 400, 'previewHeight' => 0, 'previewBytes' => 0, 'originalRef' => (string) $image->getContent(), 'originalMimeType' => 'image/jpeg', 'originalWidth' => 0, 'originalHeight' => 0, 'originalBytes' => 0, 'originalIsImage' => true, 'ownerName' => null);
     mediashareAddKeywords($image);
     return $image;
 }
Example #2
0
/**
 * Lists
 */
function mediashare_userapi_getList($args)
{
    $dom = ZLanguage::getModuleDomain('mediashare');
    $keyword = isset($args['keyword']) ? $args['keyword'] : null;
    $uname = isset($args['uname']) ? $args['uname'] : null;
    $albumId = isset($args['albumId']) ? $args['albumId'] : null;
    $order = isset($args['order']) ? $args['order'] : null;
    $orderDir = isset($args['orderDir']) ? $args['orderDir'] : 'asc';
    $recordPos = isset($args['recordPos']) ? (int) $args['recordPos'] : 0;
    $pageSize = isset($args['pageSize']) ? (int) $args['pageSize'] : 5;
    pnModDBInfoLoad('User');
    // Ensure DB table info is available
    $pntable = pnDBGetTables();
    $mediaTable = $pntable['mediashare_media'];
    $mediaColumn = $pntable['mediashare_media_column'];
    $keywordsTable = $pntable['mediashare_keywords'];
    $keywordsColumn = $pntable['mediashare_keywords_column'];
    $albumsTable = $pntable['mediashare_albums'];
    $albumsColumn = $pntable['mediashare_albums_column'];
    $storageTable = $pntable['mediashare_mediastore'];
    $storageColumn = $pntable['mediashare_mediastore_column'];
    $usersTable = $pntable['users'];
    $usersColumn = $pntable['users_column'];
    // Find accessible albums
    $accessibleAlbumSql = pnModAPIFunc('mediashare', 'user', 'getAccessibleAlbumsSql', array('access' => mediashareAccessRequirementViewSomething, 'field' => "media.{$mediaColumn['parentAlbumId']}"));
    if (!$accessibleAlbumSql) {
        return false;
    }
    // Build simple restriction
    $restriction = array();
    $join = array();
    if (!empty($uname)) {
        $restriction[] = "users.{$usersColumn['uname']} = '" . DataUtil::formatForStore($uname) . "'";
        $join[] = "INNER JOIN {$usersTable} users\r\n                           ON users.{$usersColumn['uid']} = media.{$mediaColumn['ownerId']}";
    }
    if (!empty($albumId)) {
        $restriction[] = "album.{$albumsColumn['id']} = '" . (int) $albumId . "'";
    }
    $orderKey = 'title';
    if (in_array($order, array('uname', 'created', 'modified'))) {
        $orderKey = $order;
    }
    $orderDir = strtolower($orderDir) == 'desc' ? 'DESC' : 'ASC';
    $restrictionSql = count($restriction) > 0 ? ' AND ' . implode(' AND ', $restriction) : '';
    $joinSql = count($join) > 0 ? implode(' ', $join) : '';
    if (!empty($keyword)) {
        $sql = "\r\n                   SELECT album.{$albumsColumn['id']},\r\n                          album.{$albumsColumn['title']},\r\n                          album.{$albumsColumn['keywords']},\r\n                          media.{$mediaColumn['id']},\r\n                          media.{$mediaColumn['ownerId']},\r\n                          media.{$mediaColumn['createdDate']} AS created,\r\n                          media.{$mediaColumn['modifiedDate']} AS modified,\r\n                          media.{$mediaColumn['title']} AS title,\r\n                          media.{$mediaColumn['keywords']},\r\n                          media.{$mediaColumn['description']},\r\n                          media.{$mediaColumn['mediaHandler']},\r\n                          media.{$mediaColumn['position']} AS position,\r\n                          thumbnail.{$storageColumn['fileRef']},\r\n                          preview.{$storageColumn['fileRef']},\r\n                          preview.{$storageColumn['mimeType']},\r\n                          preview.{$storageColumn['width']},\r\n                          preview.{$storageColumn['height']},\r\n                          preview.{$storageColumn['bytes']},\r\n                          original.{$storageColumn['fileRef']},\r\n                          original.{$storageColumn['mimeType']},\r\n                          original.{$storageColumn['width']},\r\n                          original.{$storageColumn['height']},\r\n                          original.{$storageColumn['bytes']}\r\n                     FROM {$keywordsTable} keyword\r\n               INNER JOIN {$mediaTable} media\r\n                       ON media.{$mediaColumn['id']} = keyword.{$keywordsColumn['itemId']}\r\n                      AND keyword.{$keywordsColumn['type']} = 'media'\r\n               INNER JOIN {$albumsTable} album\r\n                       ON album.{$albumsColumn['id']} = media.{$mediaColumn['parentAlbumId']}\r\n                LEFT JOIN {$storageTable} thumbnail\r\n                       ON thumbnail.{$storageColumn['id']} = {$mediaColumn['thumbnailId']}\r\n                LEFT JOIN {$storageTable} preview\r\n                       ON preview.{$storageColumn['id']} = {$mediaColumn['previewId']}\r\n                LEFT JOIN {$storageTable} original\r\n                       ON original.{$storageColumn['id']} = {$mediaColumn['originalId']}\r\n                          {$joinSql}\r\n                    WHERE ({$accessibleAlbumSql})\r\n                      AND keyword.{$keywordsColumn['keyword']} = '" . DataUtil::formatForStore($keyword) . "'\r\n                          {$restrictionSql}\r\n\r\n              UNION\r\n\r\n              (\r\n                   SELECT album.{$albumsColumn['id']},\r\n                          album.{$albumsColumn['title']},\r\n                          album.{$albumsColumn['keywords']},\r\n                          media.{$mediaColumn['id']},\r\n                          media.{$mediaColumn['ownerId']},\r\n                          media.{$mediaColumn['createdDate']},\r\n                          media.{$mediaColumn['modifiedDate']},\r\n                          media.{$mediaColumn['title']},\r\n                          media.{$mediaColumn['keywords']},\r\n                          media.{$mediaColumn['description']},\r\n                          media.{$mediaColumn['mediaHandler']},\r\n                          media.{$mediaColumn['position']},\r\n                          thumbnail.{$storageColumn['fileRef']},\r\n                          preview.{$storageColumn['fileRef']},\r\n                          preview.{$storageColumn['mimeType']},\r\n                          preview.{$storageColumn['width']},\r\n                          preview.{$storageColumn['height']},\r\n                          preview.{$storageColumn['bytes']},\r\n                          original.{$storageColumn['fileRef']},\r\n                          original.{$storageColumn['mimeType']},\r\n                          original.{$storageColumn['width']},\r\n                          original.{$storageColumn['height']},\r\n                          original.{$storageColumn['bytes']}\r\n                     FROM {$keywordsTable} keyword\r\n               INNER JOIN {$albumsTable} album\r\n                       ON album.{$albumsColumn['id']} = keyword.{$keywordsColumn['itemId']}\r\n                      AND keyword.{$keywordsColumn['type']} = 'album'\r\n               INNER JOIN {$mediaTable} media\r\n                       ON media.{$mediaColumn['id']} = album.{$albumsColumn['mainMediaId']}\r\n                LEFT JOIN {$storageTable} thumbnail\r\n                       ON thumbnail.{$storageColumn['id']} = {$mediaColumn['thumbnailId']}\r\n                LEFT JOIN {$storageTable} preview\r\n                       ON preview.{$storageColumn['id']} = {$mediaColumn['previewId']}\r\n                LEFT JOIN {$storageTable} original\r\n                       ON original.{$storageColumn['id']} = {$mediaColumn['originalId']}\r\n                          {$joinSql}\r\n                    WHERE ({$accessibleAlbumSql})\r\n                      AND keyword.{$keywordsColumn['keyword']} = '" . DataUtil::formatForStore($keyword) . "'\r\n                          {$restrictionSql}\r\n               )\r\n               ORDER BY {$orderKey} {$orderDir}";
    } else {
        $sql = "   SELECT album.{$albumsColumn['id']},\r\n                          album.{$albumsColumn['title']},\r\n                          album.{$albumsColumn['keywords']},\r\n                          media.{$mediaColumn['id']},\r\n                          media.{$mediaColumn['ownerId']},\r\n                          media.{$mediaColumn['createdDate']} AS created,\r\n                          media.{$mediaColumn['modifiedDate']} AS modified,\r\n                          media.{$mediaColumn['title']} AS title,\r\n                          media.{$mediaColumn['keywords']},\r\n                          media.{$mediaColumn['description']},\r\n                          media.{$mediaColumn['mediaHandler']},\r\n                          media.{$mediaColumn['position']} AS position,\r\n                          thumbnail.{$storageColumn['fileRef']},\r\n                          preview.{$storageColumn['fileRef']},\r\n                          preview.{$storageColumn['mimeType']},\r\n                          preview.{$storageColumn['width']},\r\n                          preview.{$storageColumn['height']},\r\n                          preview.{$storageColumn['bytes']},\r\n                          original.{$storageColumn['fileRef']},\r\n                          original.{$storageColumn['mimeType']},\r\n                          original.{$storageColumn['width']},\r\n                          original.{$storageColumn['height']},\r\n                          original.{$storageColumn['bytes']}\r\n                     FROM {$mediaTable} media\r\n               INNER JOIN {$albumsTable} album\r\n                       ON album.{$albumsColumn['id']} = media.{$mediaColumn['parentAlbumId']}\r\n                LEFT JOIN {$storageTable} thumbnail\r\n                       ON thumbnail.{$storageColumn['id']} = {$mediaColumn['thumbnailId']}\r\n                LEFT JOIN {$storageTable} preview\r\n                       ON preview.{$storageColumn['id']} = {$mediaColumn['previewId']}\r\n                LEFT JOIN {$storageTable} original\r\n                       ON original.{$storageColumn['id']} = {$mediaColumn['originalId']}\r\n                          {$joinSql}\r\n                    WHERE ({$accessibleAlbumSql})\r\n                          {$restrictionSql}\r\n                 ORDER BY {$orderKey} {$orderDir}";
    }
    $result = DBUtil::executeSQL($sql, $recordPos, $pageSize);
    if ($result === false) {
        return LogUtil::registerError(__f('Error in %1$s: %2$s.', array('userapi.getList', 'Could not retrieve the media list.'), $dom));
    }
    $colArray = array('albumId', 'albumTitle', 'albumKeywords', 'id', 'ownerId', 'createdDate', 'modifiedDate', 'title', 'keywords', 'description', 'mediaHandler', 'position', 'thumbnailRef', 'previewRef', 'previewMimeType', 'previewWidth', 'previewHeight', 'previewBytes', 'originalRef', 'originalMimeType', 'originalWidth', 'originalHeight', 'originalBytes');
    $media = DBUtil::marshallObjects($result, $colArray);
    $result = array();
    foreach (array_keys($media) as $k) {
        // build the album
        $album = array('id' => $media[$k]['albumId'], 'title' => $media[$k]['albumTitle'], 'keywords' => $media[$k]['albumKeywords']);
        mediashareAddKeywords($album);
        // remove the album data
        unset($media[$k]['albumId']);
        unset($media[$k]['albumTitle']);
        unset($media[$k]['albumKeywords']);
        // media data post process
        unset($media[$k]['position']);
        $media[$k]['caption'] = empty($media[$k]['title']) ? $media[$k]['description'] : $media[$k]['title'];
        $media[$k]['captionLong'] = empty($media[$k]['description']) ? $media[$k]['title'] : $media[$k]['description'];
        $media[$k]['originalIsImage'] = substr($media[$k]['originalMimeType'], 0, 6) == 'image/';
        mediashareAddKeywords($media[$k]);
        $result[] = array('album' => $album, 'media' => $media[$k]);
    }
    return $result;
}