Ejemplo n.º 1
0
 private function set($key, $value)
 {
     $this->data[$key] = $value;
     //update cache
     mpp_add_gallery_to_cache($this);
 }
Ejemplo n.º 2
0
/**
 * Retrieves gallery data given a gallery id or gallery object.
 *
 * @param int|object $gallery gallery id or gallery object. Optional, default is the current gallery from the loop.
 * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N.
 * @param string $filter Optional, default is raw.
 * 
 * @return MPP_Gallery|null MPP_Gallery on success or null on failure
 */
function mpp_get_gallery($gallery = null, $output = OBJECT)
{
    $_gallery = null;
    $needs_caching = false;
    //if gallery is not given, but we do have current_gallery setup
    if (empty($gallery) && mediapress()->current_gallery) {
        $gallery = mediapress()->current_gallery;
    }
    if (!$gallery) {
        return null;
    }
    //if already an instance of gallery object
    if (is_a($gallery, 'MPP_Gallery')) {
        $_gallery = $gallery;
    } elseif (is_numeric($gallery)) {
        $_gallery = mpp_get_gallery_from_cache($gallery);
        if (!$_gallery) {
            $_gallery = new MPP_Gallery($gallery);
            $needs_caching = true;
        }
    } elseif (is_object($gallery)) {
        $_gallery = new MPP_Gallery($gallery);
        $needs_caching = true;
    }
    //save to cache if not already in cache
    if ($needs_caching && !empty($_gallery) && $_gallery->id) {
        mpp_add_gallery_to_cache($_gallery);
    }
    if (!$_gallery) {
        return null;
    }
    //if the gallery has no id set
    if (!$_gallery->id) {
        return null;
    }
    if ($output == ARRAY_A) {
        return $_gallery->to_array();
    } elseif ($output == ARRAY_N) {
        return array_values($_gallery->to_array());
    }
    return $_gallery;
}