Пример #1
0
 function getPermissions($type = "category", $id = null)
 {
     global $xoopsUser;
     static $permissions;
     if (!isset($permissions[$type]) || $id != null && !isset($permissions[$type][$id])) {
         $smartModule =& sf_getModuleInfo();
         //Get group permissions handler
         $gperm_handler =& xoops_gethandler('groupperm');
         //Get user's groups
         $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
         switch ($type) {
             case "category":
                 $gperm_name = "category_read";
                 break;
             case "item":
                 $gperm_name = "item_read";
                 break;
             case "moderation":
                 $gperm_name = "category_moderation";
                 $groups = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
         }
         //Get all allowed item ids in this module and for this user's groups
         $userpermissions =& $gperm_handler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid'));
         $permissions[$type] = $userpermissions;
     }
     //Return the permission array
     return isset($permissions[$type]) ? $permissions[$type] : array();
 }
Пример #2
0
function b_faqs_recent_show($options)
{
    include_once XOOPS_ROOT_PATH . "/modules/smartfaq/include/functions.php";
    $myts =& MyTextSanitizer::getInstance();
    $smartModule =& sf_getModuleInfo();
    $smartModuleConfig =& sf_getModuleConfig();
    $block = array();
    if ($options[0] == 0) {
        $categoryid = -1;
    } else {
        $categoryid = $options[0];
    }
    $sort = $options[1];
    $limit = $options[2];
    $maxQuestionLength = $options[3];
    // Creating the faq handler object
    $faq_handler =& sf_gethandler('faq');
    // Creating the category handler object
    $category_handler =& sf_gethandler('category');
    // Creating the last FAQs
    $faqsObj = $faq_handler->getAllPublished($limit, 0, $categoryid, $sort);
    $allcategories = $category_handler->getObjects(null, true);
    if ($faqsObj) {
        $userids = array();
        foreach ($faqsObj as $key => $thisfaq) {
            $faqids[] = $thisfaq->getVar('faqid');
            $userids[$thisfaq->uid()] = 1;
        }
        $answer_handler =& sf_gethandler('answer');
        $allanswers = $answer_handler->getLastPublishedByFaq($faqids);
        foreach ($allanswers as $key => $thisanswer) {
            $userids[$thisanswer->uid()] = 1;
        }
        $member_handler =& xoops_gethandler('member');
        $users = $member_handler->getUsers(new Criteria('uid', "(" . implode(',', array_keys($userids)) . ")", "IN"), true);
        for ($i = 0; $i < count($faqsObj); $i++) {
            $faqs['categoryid'] = $faqsObj[$i]->categoryid();
            $faqs['question'] = $faqsObj[$i]->question($maxQuestionLength);
            $faqs['faqid'] = $faqsObj[$i]->faqid();
            $faqs['categoryname'] = $allcategories[$faqsObj[$i]->categoryid()]->getVar('name');
            // Creating the answer object
            $answerObj =& $allanswers[$faqsObj[$i]->faqid()];
            $faqs['date'] = $faqsObj[$i]->datesub();
            $faqs['poster'] = sf_getLinkedUnameFromId($answerObj->uid(), $smartModuleConfig['userealname'], $users);
            $block['faqs'][] = $faqs;
        }
        $block['lang_question'] = _MB_SF_FAQS;
        $block['lang_category'] = _MB_SF_CATEGORY;
        $block['lang_poster'] = _MB_SF_ANSWEREDBY;
        $block['lang_date'] = _MB_SF_DATE;
        $modulename = $myts->htmlSpecialChars($smartModule->getVar('name'));
        $block['lang_visitfaq'] = _MB_SF_VISITFAQ . " " . $modulename;
    }
    return $block;
}
Пример #3
0
function b_marquee_smartfaq($limit, $dateformat, $itemssize)
{
    include_once XOOPS_ROOT_PATH . "/modules/smartfaq/include/functions.php";
    $block = array();
    $smartModule =& sf_getModuleInfo();
    $smartModuleConfig =& sf_getModuleConfig();
    $categoryid = -1;
    $sort = 'datesub';
    if ($itemssize > 0) {
        $maxQuestionLength = $itemssize;
    } else {
        $maxQuestionLength = 99999;
    }
    // Creating the faq handler object
    $faq_handler =& sf_gethandler('faq');
    // Creating the category handler object
    $category_handler =& sf_gethandler('category');
    // Creating the last FAQs
    $faqsObj = $faq_handler->getAllPublished($limit, 0, $categoryid, $sort);
    $allcategories = $category_handler->getObjects(null, true);
    if ($faqsObj) {
        $userids = array();
        foreach ($faqsObj as $key => $thisfaq) {
            $faqids[] = $thisfaq->getVar('faqid');
            $userids[$thisfaq->uid()] = 1;
        }
        $answer_handler =& sf_gethandler('answer');
        $allanswers = $answer_handler->getLastPublishedByFaq($faqids);
        foreach ($allanswers as $key => $thisanswer) {
            $userids[$thisanswer->uid()] = 1;
        }
        $member_handler =& xoops_gethandler('member');
        $users = $member_handler->getUsers(new Criteria('uid', "(" . implode(',', array_keys($userids)) . ")", "IN"), true);
        for ($i = 0; $i < count($faqsObj); $i++) {
            $answerObj =& $allanswers[$faqsObj[$i]->faqid()];
            $title = $faqsObj[$i]->question($maxQuestionLength);
            $block[] = array('date' => $faqsObj[$i]->datesub(), 'category' => $allcategories[$faqsObj[$i]->categoryid()]->getVar('name'), 'author' => sf_getLinkedUnameFromId($answerObj->uid(), $smartModuleConfig['userealname'], $users), 'title' => $title, 'link' => "<a href='" . XOOPS_URL . '/modules/smartfaq/faq.php?faqid=' . $faqsObj[$i]->faqid() . "'>" . $title . '</a>');
        }
    }
    return $block;
}
Пример #4
0
 /**
  * delete a category from the database
  *
  * @param object $category reference to the category to delete
  * @param bool $force
  * @return bool FALSE if failed.
  */
 function delete(&$category, $force = false)
 {
     if (strtolower(get_class($category)) != 'sfcategory') {
         return false;
     }
     // Deleting the FAQs
     $faq_handler = new sfFaqHandler($this->db);
     if (!$faq_handler->deleteAll(new Criteria('categoryid', $category->categoryid()))) {
         return false;
     }
     // Deleteing the sub categories
     $subcats =& $this->getCategories(0, 0, $category->categoryid());
     foreach ($subcats as $subcat) {
         $this->delete($subcat);
     }
     $sql = sprintf("DELETE FROM %s WHERE categoryid = %u", $this->db->prefix("smartfaq_categories"), $category->getVar('categoryid'));
     $smartModule =& sf_getModuleInfo();
     $module_id = $smartModule->getVar('mid');
     if (false != $force) {
         $result = $this->db->queryF($sql);
     } else {
         $result = $this->db->query($sql);
     }
     xoops_groupperm_deletebymoditem($module_id, "category_read", $category->categoryid());
     //xoops_groupperm_deletebymoditem ($module_id, "category_admin", $categoryObj->categoryid());
     if (!$result) {
         return false;
     }
     return true;
 }
Пример #5
0
/**
* Saves permissions for the selected category
*
*   sf_saveModerators()
*
* @param array $moderators : moderators uids
* @param integer $categoryid : categoryid on which we are setting permissions
* @return boolean : TRUE if the no errors occured
*/
function sf_saveModerators($moderators, $categoryid)
{
    $result = true;
    $smartModule =& sf_getModuleInfo();
    $module_id = $smartModule->getVar('mid');
    $gperm_handler =& xoops_gethandler('groupperm');
    // First, if the permissions are already there, delete them
    $gperm_handler->deleteByModule($module_id, 'category_moderation', $categoryid);
    // Save the new permissions
    if (count($moderators) > 0) {
        foreach ($moderators as $uid) {
            $gperm_handler->addRight('category_moderation', $categoryid, $uid, $module_id);
        }
    }
    return $result;
}
Пример #6
0
 function sendNotifications($notifications = array())
 {
     $smartModule =& sf_getModuleInfo();
     $myts =& MyTextSanitizer::getInstance();
     $notification_handler =& xoops_gethandler('notification');
     $faqObj = new sfFaq($this->faqid());
     $tags = array();
     $tags['MODULE_NAME'] = $myts->displayTarea($smartModule->getVar('name'));
     $tags['FAQ_NAME'] = $faqObj->question();
     $tags['FAQ_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/faq.php?faqid=' . $faqObj->faqid();
     $tags['CATEGORY_NAME'] = $faqObj->getCategoryName();
     $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/category.php?categoryid=' . $faqObj->categoryid();
     $tags['FAQ_QUESTION'] = $faqObj->question();
     // TODO : Not sure about the 'formpreview' ...
     $tags['FAQ_ANSWER'] = $this->answer('formpreview');
     $tags['DATESUB'] = $this->datesub();
     foreach ($notifications as $notification) {
         switch ($notification) {
             case _SF_NOT_ANSWER_APPROVED:
                 // This notification is not working for PM, but is for email... and I don't understand why???
                 $notification_handler->triggerEvent('faq', $this->answerid(), 'answer_approved', $tags);
                 break;
             case -1:
             default:
                 break;
         }
     }
 }
Пример #7
0
 function getFaqsAdminSide($limit = 0, $start = 0, $status = '', $categoryid = -1, $sort = 'datesub', $order = 'DESC', $asobject = true, $otherCriteria = null)
 {
     include_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php';
     $smartModule =& sf_getModuleInfo();
     $ret = array();
     if (isset($categoryid) && $categoryid != -1) {
         $criteriaCategory = new criteria('faq.categoryid', $categoryid);
     }
     if (!empty($status) && is_array($status)) {
         $criteriaStatus = new CriteriaCompo();
         foreach ($status as $v) {
             $criteriaStatus->add(new Criteria('faq.status', $v), 'OR');
         }
     } elseif (!empty($status) && $status != -1) {
         $criteriaStatus = new CriteriaCompo();
         $criteriaStatus->add(new Criteria('faq.status', $status), 'OR');
     }
     $criteria = new CriteriaCompo();
     if (!empty($criteriaCategory)) {
         $criteria->add($criteriaCategory);
     }
     if (!empty($criteriaStatus)) {
         $criteria->add($criteriaStatus);
     }
     if (!empty($otherCriteria)) {
         $criteria->add($otherCriteria);
     }
     $criteria->setLimit($limit);
     $criteria->setStart($start);
     $criteria->setSort($sort);
     $criteria->setOrder($order);
     $ret =& $this->getObjectsAdminSide($criteria, false);
     return $ret;
 }