function set_cover_photo($pid, $cid, $myaccount = false)
 {
     global $db, $userquery, $cbphoto;
     if (!$this->collection_exists($cid)) {
         e(lang('collection_not_exists'));
         return false;
     }
     if (!$this->object_exists($pid)) {
         e(lang(sprintf('%s does not exist', $this->objType)));
         return false;
     }
     if (!$this->object_in_collection($pid, $cid)) {
         e(sprintf(lang("object_not_in_collect"), $this->objName));
         return false;
     }
     if (!$this->is_collection_owner($cid) || userid() != $cbphoto->get_photo_owner($pid)) {
         e(lang('cant_perform_action_collect'));
         return false;
     }
     $fields = tbl_fields(array('p' => get_photo_fields(), 'c' => get_collection_fields()));
     $query = ' SELECT ' . $fields . ' FROM ' . tbl('collections') . ' as c';
     $query .= " LEFT JOIN " . tbl('photos') . " as p ON c.collection_id = p.collection_id ";
     start_where();
     add_where(" c.collection_id = '{$cid}' ");
     add_where(" p.photo_id = '{$pid}' ");
     if (get_where()) {
         $query .= ' WHERE ' . get_where();
     }
     end_where();
     $result = db_select($query);
     if ($myaccount) {
         if ($result['is_avatar'] == 'yes' || $result['is_avatar_collection'] == 'yes') {
             return false;
         }
     }
     $cover_photo = json_decode($result['cover_photo'], true);
     if ($pid == $cover_photo['photo_id']) {
         $update = true;
     } else {
         //Create array so we can reduce one query per collection YOSH !!!
         $result = $result[0];
         $cover_photo['photo_id'] = $result['photo_id'];
         $cover_photo['photo_key'] = $result['photo_key'];
         $cover_photo['filename'] = $result['filename'];
         $cover_photo['ext'] = $result['ext'];
         $cover_photo['is_collection_cover'] = true;
         // This flag will help us make a query to get is_mature for cover photo while displaying
         $jecp = json_encode($cover_photo);
         $field = array('cover_photo' => $jecp);
         $update = db_update(tbl('collections'), $field, " collection_id = '" . $result['collection_id'] . "' ");
     }
     if ($update) {
         return $cover_photo;
     } else {
         return false;
     }
 }
Exemple #2
0
 /**
  * Get Photos 
  */
 function get_photos($p)
 {
     global $db, $cb_columns;
     $tables = "photos,users";
     $order = $p['order'];
     $limit = $p['limit'];
     $cond = "";
     if (!has_access('admin_access', TRUE)) {
         $cond = " " . 'photos.broadcast' . " = 'public' AND " . 'photos.active' . " = 'yes'";
     } else {
         if ($p['active']) {
             $cond .= " " . 'photos.active' . " = '" . $p['active'] . "'";
         }
         if ($p['broadcast']) {
             if ($cond != "") {
                 $cond .= " AND ";
             }
             $cond .= " " . 'photos.broadcast' . " = '" . $p['broadcast'] . "'";
         }
     }
     if ($p['pid']) {
         if ($cond != "") {
             $cond .= " AND ";
         }
         $cond .= $this->constructMultipleQuery(array("ids" => $p['pid'], "sign" => "=", "operator" => "OR"));
     }
     if ($p['key']) {
         if ($cond != "") {
             $cond .= " AND ";
         }
         $cond .= " " . 'photos.photo_key' . " = '" . $p['key'] . "'";
     }
     if ($p['filename']) {
         if ($cond != "") {
             $cond .= " AND ";
         }
         $cond .= " " . 'photos.filename' . " = '" . $p['filename'] . "'";
     }
     if ($p['extension']) {
         foreach ($this->exts as $ext) {
             if (in_array($ext, $this->exts)) {
                 if ($cond != "") {
                     $cond .= " AND ";
                 }
                 $cond .= " " . 'photos.ext' . " = '" . $p['extension'] . "'";
             }
         }
     }
     if ($p['date_span']) {
         if ($cond != "") {
             $cond .= " AND ";
         }
         $cond .= " " . cbsearch::date_margin("photos.date_added", $p['date_span']);
     }
     if ($p['featured']) {
         if ($cond != "") {
             $cond .= " AND ";
         }
         $cond .= " " . 'photos.featured' . " = '" . $p['featured'] . "'";
     }
     if ($p['user']) {
         if ($cond != "") {
             $cond .= " AND ";
         }
         $cond .= $this->constructMultipleQuery(array("ids" => $p['user'], "sign" => "=", "operator" => "AND", "column" => "userid"));
     }
     if ($p['exclude']) {
         if ($cond != "") {
             $cond .= " AND ";
         }
         $cond .= $this->constructMultipleQuery(array("ids" => $p['exclude'], "sign" => "<>"));
     }
     $title_tag = '';
     if ($p['title']) {
         $title_tag = " " . 'photos.photo_title' . " LIKE '%" . $p['title'] . "%'";
     }
     if ($p['tags']) {
         $tags = explode(",", $p['tags']);
         if (count($tags) > 0) {
             if ($title_tag != '') {
                 $title_tag .= " OR ";
             }
             $total = count($tags);
             $loop = 1;
             foreach ($tags as $tag) {
                 $title_tag .= " " . 'photos.photo_tags' . " LIKE '%{$tag}%'";
                 if ($loop < $total) {
                     $title_tag .= " OR ";
                 }
                 $loop++;
             }
         } else {
             if ($title_tag != '') {
                 $title_tag .= " OR ";
             }
             $title_tag .= " " . 'photos.photo_tags' . " LIKE '%" . $p['tags'] . "%'";
         }
     }
     if ($title_tag != "") {
         if ($cond != '') {
             $cond .= " AND ";
         }
         $cond .= " ({$title_tag}) ";
     }
     if ($p['ex_user']) {
         if ($cond != "") {
             $cond .= " AND ";
         }
         $cond .= $this->constructMultipleQuery(array("ids" => $p['ex_user'], "sign" => "<>", "operator" => "AND", "column" => "userid"));
     }
     if ($p['extra_cond']) {
         if ($cond != "") {
             $cond .= " AND ";
         }
         $cond .= $p['extra_cond'];
     }
     if ($p['get_orphans']) {
         $p['collection'] = (string) "0";
     }
     if ($p['collection'] || $p['get_orphans']) {
         if ($cond != "") {
             $cond .= " AND ";
         }
         $cond .= $this->constructMultipleQuery(array("ids" => $p['collection'], "sign" => "=", "operator" => "OR", "column" => "collection_id"));
     } else {
         if ($cond != "") {
             $cond .= " AND ";
         }
         $cond .= " " . 'photos.collection_id' . " <> '0'";
     }
     $fields = array('photos' => get_photo_fields(), 'users' => get_user_fields(), 'collections' => array('collection_name', 'type', 'category', 'views as collection_views', 'date_added as collection_added'));
     $string = tbl_fields($fields);
     $main_query = "SELECT {$string} FROM " . table('photos');
     $main_query .= " LEFT JOIN " . table('collections') . " ON photos.collection_id = collections.collection_id";
     $main_query .= " LEFT JOIN " . table('users') . " ON collections.userid = users.userid";
     $order = $order ? " ORDER BY " . $order : false;
     $limit = $limit ? " LIMIT " . $limit : false;
     if (!$p['count_only'] && !$p['show_related']) {
         $query = $main_query;
         if ($cond) {
             $query .= " WHERE " . $cond;
         }
         $query .= $order;
         $query .= $limit;
         $result = select($query);
     }
     if ($p['show_related']) {
         $query = $main_query;
         $cond = "MATCH(" . 'photos.photo_title,photos.photo_tags' . ")";
         $cond .= " AGAINST ('" . cbsearch::set_the_key($p['title']) . "' IN BOOLEAN MODE)";
         if ($p['exclude']) {
             if ($cond != "") {
                 $cond .= " AND ";
             }
             $cond .= $this->constructMultipleQuery(array("ids" => $p['exclude'], "sign" => "<>"));
         }
         if ($p['collection']) {
             if ($cond != "") {
                 $cond .= " AND ";
             }
             $cond .= $this->constructMultipleQuery(array("ids" => $p['collection'], "sign" => "<>", "column" => "collection_id"));
         }
         if ($p['extra_cond']) {
             if ($cond != "") {
                 $cond .= " AND ";
             }
             $cond .= $p['extra_cond'];
         }
         $where = " WHERE " . $cond . " AND photos.collection_id <> 0";
         $query .= $where;
         $query .= $order;
         $query .= $limit;
         $result = select($query);
         // We found nothing from TITLE of Photos, let's try TAGS
         if ($db->num_rows == 0) {
             $query = $main_query;
             $tags = cbsearch::set_the_key($p['tags']);
             $tags = str_replace('+', '', $tags);
             $cond = "MATCH(" . 'photos.photo_title,photos.photo_tags' . ")";
             $cond .= " AGAINST ('" . $tags . "' IN BOOLEAN MODE)";
             if ($p['exclude']) {
                 if ($cond != "") {
                     $cond .= " AND ";
                 }
                 $cond .= $this->constructMultipleQuery(array("ids" => $p['exclude'], "sign" => "<>"));
             }
             if ($p['collection']) {
                 if ($cond != "") {
                     $cond .= " AND ";
                 }
                 $cond .= $this->constructMultipleQuery(array("ids" => $p['collection'], "sign" => "<>", "column" => "collection_id"));
             }
             if ($p['extra_cond']) {
                 if ($cond != "") {
                     $cond .= " AND ";
                 }
                 $cond .= $p['extra_cond'];
             }
             $where = " WHERE " . $cond . " AND photos.collection_id <> 0";
             $query .= $where;
             $query .= $order;
             $query .= $limit;
             $result = select($query);
         }
     }
     if ($p['count_only']) {
         if ($p['extra_cond']) {
             if ($cond != "") {
                 $cond .= " AND ";
             }
             $cond .= $p['extra_cond'];
         }
         $result = $db->count(table("photos"), "photo_id", $cond);
     }
     ##pr( $query, true );
     if ($p['assign']) {
         assign($p['assign'], $result);
     } else {
         return $result;
     }
 }
/**
 * This function get photo details, setups an array for content.
 * This also serves as an example on how to use custom callback
 * for subscription type
 * 
 * @author Fawaz Tahir <*****@*****.**>
 * @param type $id
 * @return array|boolean
 */
function get_subscription_photo($id)
{
    global $cbphoto, $userquery;
    $photo = $cbphoto->get_photo($id, true);
    if ($photo) {
        $fields = array('photo_description', 'photo_tags', 'collection_id', 'collection_name', 'views', 'file_directory', 'server_url', 'broadcast', 'date_added');
        $fields = get_photo_fields($fields);
        foreach ($fields as $field) {
            if ($field == 'photo_details') {
                continue;
            }
            $details[$field] = $photo[$field];
        }
        $details['title'] = $photo['photo_title'];
        $details['description'] = $photo['photo_descritpion'];
        $details['tags'] = tags($photo['photo_tags'], "photos");
        $details['heading'] = sprintf(lang('<a href="%s">%s</a> added a new photo in <a href="%s">%s</a>'), $userquery->profile_link($photo), name($photo), collection_links($photo), $photo['collection_name']);
        $details['link'] = view_photo_link($photo);
        $details['thumb'] = get_image_url($photo, 'm');
        return $details;
    }
    return false;
}