Example #1
0
 protected function _category()
 {
     $cid = Utils::pg("cid", 0);
     $cat = new Category($cid);
     $this->_smarty->assign('category_tree', $cat->getSubTree(true));
     if ($cid > 0) {
         $this->_smarty->assign('page_title', $cat->_dbo->category_name);
         $this->_smarty->assign('category_name', $cat->_dbo->category_name);
         if (!$this->_session->requireLogin(false)) {
             if (!$cat->checkSubscription($this->_session->_uid)) {
                 $this->_smarty->assign('subscribe_url', url('subscribe', array('cid' => $cid, 'ref' => Utils::selfURL())));
             } elseif ($cat->checkSubscription($this->_session->_uid, false)) {
                 $this->_smarty->assign('unsubscribe_url', url('unsubscribe', array('cid' => $cid, 'ref' => Utils::selfURL())));
             }
         }
     } else {
         $this->_smarty->assign('page_title', "Wszystkie kategorie");
         $this->_smarty->assign('category_name', "Wszystkie kategorie");
     }
     $pids = $cat->getPhotos();
     if (!empty($pids)) {
         $in_s = implode(", ", $pids);
         $q = $this->_db->prepare("SELECT photo_id FROM phph_photos WHERE photo_id IN ({$in_s}) AND photo_approved IS NOT NULL ORDER BY photo_added DESC LIMIT ?, ?");
         $res = $this->_db->execute($q, array(intval($this->_page) * $this->_count, intval($this->_count)));
         $photos = array();
         while ($row = $res->fetchRow()) {
             $photos[] = get_photo($row['photo_id'], $cid);
         }
         $this->_smarty->assign('photos', $photos);
         $this->_pages = pager(url('category', array('cid' => $cid)), count(array_unique($pids)));
         $this->_smarty->assign('pager', $this->_pages);
     }
 }
 function checkSubscription($uid, $cp = true)
 {
     global $db;
     $q = $db->prepare("SELECT * FROM phph_subscriptions WHERE user_id = ? AND category_id = ?");
     $res = $db->execute($q, array($uid, $this->_cid));
     if ($res->numRows() > 0) {
         return true;
     }
     if (empty($this->_dbo->category_parent) || !$cp) {
         return false;
     }
     $parent = new Category($this->_dbo->category_parent);
     return $parent->checkSubscription($uid);
 }