Example #1
0
	public function getSubscribers($catid, $topic, $subscriptions = false, $moderators = false, $admins = false, $excludeList = null) {
		$topic = KunenaForumTopicHelper::get($topic);
		if (!$topic->exists())
			return array();

		if ($subscriptions) {
			$subslist = $this->loadSubscribers($topic, (int)$subscriptions);
		}
		if ($moderators) {
			$modlist = array();
			if (!empty(self::$moderatorsByCatid[0])) $modlist += self::$moderatorsByCatid[0];
			if (!empty(self::$moderatorsByCatid[$catid])) $modlist += self::$moderatorsByCatid[$catid];

			// If category has no moderators, send email to admins instead
			if (empty($modlist)) $admins = true;
		}
		if ($admins) {
			$adminlist = array();
			if (!empty(self::$adminsByCatid[0])) $adminlist += self::$adminsByCatid[0];
			if (!empty(self::$adminsByCatid[$catid])) $adminlist += self::$adminsByCatid[$catid];
		}

		$query = new KunenaDatabaseQuery();
		$query->select('u.id, u.name, u.username, u.email');
		$query->from('#__users AS u');
		$query->where("u.block=0");
		$userlist = array();
		if (!empty($subslist)) {
			$userlist = $subslist;
			$subslist = implode(',', array_keys($subslist));
			$query->select("IF( u.id IN ({$subslist}), 1, 0 ) AS subscription");
		} else {
			$query->select("0 AS subscription");
		}
		if (!empty($modlist)) {
			$userlist += $modlist;
			$modlist = implode(',', array_keys($modlist));
			$query->select("IF( u.id IN ({$modlist}), 1, 0 ) AS moderator");
		} else {
			$query->select("0 AS moderator");
		}
		if (!empty($adminlist)) {
			$userlist += $adminlist;
			$adminlist = implode(',', array_keys($adminlist));
			$query->select("IF( u.id IN ({$adminlist}), 1, 0 ) AS admin");
		} else {
			$query->select("0 AS admin");
		}
		if (empty($excludeList)) {
			// false, null, '', 0 and array(): get all subscribers
			$excludeList = array();
		} elseif (is_array($excludeList)) {
			// array() needs to be flipped to get userids into keys
			$excludeList = array_flip($excludeList);
		} else {
			// Others: let's assume that we have comma separated list of values (string)
			$excludeList = array_flip(explode(',', (string) $excludeList));
		}
		$userlist = array_diff_key($userlist, $excludeList);
		$userids = array();
		if (!empty($userlist)) {
			$userlist = implode(',', array_keys($userlist));
			$query->where("u.id IN ({$userlist})");
			$db = JFactory::getDBO();
			$db->setQuery ( $query );
			$userids = (array) $db->loadObjectList ();
			KunenaError::checkDatabaseError();
		}
		return $userids;
	}
Example #2
0
 /**
  * @return KunenaDatabaseQuery
  */
 protected static function query_userTopicWrongCategory()
 {
     // Query to find user topic which wrong category information
     $query = new KunenaDatabaseQuery();
     $query->from("#__kunena_user_topics AS a")->innerJoin("#__kunena_topics AS t ON t.id=a.topic_id")->where("a.category_id!=t.category_id");
     return $query;
 }
Example #3
0
	/**
	 * JXtended: Grabs all groups mapped to an ARO.
	 *
	 * A root group value can be specified for looking at sub-tree
	 * (results include the root group)
	 *
	 * @param	string	The section value or the ARO or AXO
	 * @param	string	The value of the ARO or AXO
	 * @param	integer	The value of the group to start at (optional)
	 * @param	string	The type of group, either ARO or AXO (optional)
	 */
	protected function acl_get_groups($sectionValue, $value, $rootGroupValue=NULL, $type='ARO') {
		static $cache = null;

		$db		= JFactory::getDbo();
		$type	= strtolower($type);

		if ($type != 'aro' && $type != 'axo') {
			return array();
		}
		if (($sectionValue === '' || $sectionValue === null) && ($value === '' || $value === null)) {
			return array();
		}

		// Simple cache
		if ($cache === null) {
			$cache = array();
		}

		// Generate unique cache id.
		$cacheId = 'acl_get_groups_'.$sectionValue.'-'.$value.'-'.$rootGroupValue.'-'.$type;

		if (!isset($cache[$cacheId]))
		{
			$query = new KunenaDatabaseQuery();

			// Make sure we get the groups
			$query->select('DISTINCT g2.id');
			$query->from('#__core_acl_'.$type.' AS o');
			$query->join('INNER', '#__core_acl_groups_'.$type.'_map AS gm ON gm.'. $type .'_id=o.id');
			$query->join('INNER', '#__core_acl_'.$type.'_groups AS g1 ON g1.id = gm.group_id');

			$query->where('(o.section_value='. $db->quote($sectionValue) .' AND o.value='. $db->quote($value) .')');

			/*
			 * If root group value is specified, we have to narrow this query down
			 * to just groups deeper in the tree then what is specified.
			 * This essentially creates a virtual "subtree" and ignores all outside groups.
			 * Useful for sites like sourceforge where you may seperate groups by "project".
			 */
			if ( $rootGroupValue != '') {
				$query->join('INNER', '#__core_acl_'.$type.'_groups AS g3 ON g3.value='. $db->quote($rootGroupValue));
				$query->join('INNER', '#__core_acl_'.$type.'_groups AS g2 ON ((g2.lft BETWEEN g3.lft AND g1.lft) AND (g2.rgt BETWEEN g1.rgt AND g3.rgt))');
			}
			else {
				$query->join('INNER', '#__core_acl_'.$type.'_groups AS g2 ON (g2.lft <= g1.lft AND g2.rgt >= g1.rgt)');
			}

			$db->setQuery($query);
			$cache[$cacheId] = $db->loadResultArray();
		}

		return $cache[$cacheId];
	}
Example #4
0
 /**
  * @param int  $catid
  * @param mixed $topic
  * @param mixed $type
  * @param bool $moderators
  * @param bool $admins
  * @param mixed $excludeList
  *
  * @return array
  */
 public function getSubscribers($catid, $topic, $type = false, $moderators = false, $admins = false, $excludeList = null)
 {
     $topic = KunenaForumTopicHelper::get($topic);
     $category = $topic->getCategory();
     if (!$topic->exists()) {
         return array();
     }
     $modlist = array();
     if (!empty($this->moderatorsByCatid[0])) {
         $modlist += $this->moderatorsByCatid[0];
     }
     if (!empty($this->moderatorsByCatid[$catid])) {
         $modlist += $this->moderatorsByCatid[$catid];
     }
     $adminlist = array();
     if (!empty($this->adminsByCatid[0])) {
         $adminlist += $this->adminsByCatid[0];
     }
     if (!empty($this->adminsByCatid[$catid])) {
         $adminlist += $this->adminsByCatid[$catid];
     }
     if ($type) {
         $subscribers = $this->loadSubscribers($topic, $type);
         $allow = $deny = array();
         if (!empty($subscribers)) {
             /** @var KunenaAccess $access */
             foreach ($this->accesstypes[$category->accesstype] as $access) {
                 if (method_exists($access, 'authoriseUsers')) {
                     list($a, $d) = $access->authoriseUsers($topic, $subscribers);
                     if (!empty($a)) {
                         $allow += array_combine($a, $a);
                     }
                     if (!empty($d)) {
                         $deny += array_combine($d, $d);
                     }
                 }
             }
         }
         $subslist = array_diff($allow, $deny);
         // Category administrators and moderators override ACL
         $subslist += array_intersect_key($adminlist, array_flip($subscribers));
         $subslist += array_intersect_key($modlist, array_flip($subscribers));
     }
     if (!$moderators) {
         $modlist = array();
     } else {
         // If category has no moderators, send email to admins instead
         if (empty($modlist)) {
             $admins = true;
         }
     }
     if (!$admins) {
         $adminlist = array();
     }
     $query = new KunenaDatabaseQuery();
     $query->select('u.id, u.name, u.username, u.email');
     $query->from('#__users AS u');
     $query->where("u.block=0");
     $userlist = array();
     if (!empty($subslist)) {
         $userlist += $subslist;
         $subslist = implode(',', array_keys($subslist));
         $query->select("IF( u.id IN ({$subslist}), 1, 0 ) AS subscription");
     } else {
         $query->select("0 AS subscription");
     }
     if (!empty($modlist)) {
         $userlist += $modlist;
         $modlist = implode(',', array_keys($modlist));
         $query->select("IF( u.id IN ({$modlist}), 1, 0 ) AS moderator");
     } else {
         $query->select("0 AS moderator");
     }
     if (!empty($adminlist)) {
         $userlist += $adminlist;
         $adminlist = implode(',', array_keys($adminlist));
         $query->select("IF( u.id IN ({$adminlist}), 1, 0 ) AS admin");
     } else {
         $query->select("0 AS admin");
     }
     if (empty($excludeList)) {
         // false, null, '', 0 and array(): get all subscribers
         $excludeList = array();
     } elseif (is_array($excludeList)) {
         // array() needs to be flipped to get userids into keys
         $excludeList = array_flip($excludeList);
     } else {
         // Others: let's assume that we have comma separated list of values (string)
         $excludeList = array_flip(explode(',', (string) $excludeList));
     }
     $userlist = array_diff_key($userlist, $excludeList);
     $userids = array();
     if (!empty($userlist)) {
         $userlist = implode(',', array_keys($userlist));
         $query->where("u.id IN ({$userlist})");
         $db = JFactory::getDBO();
         $db->setQuery($query);
         $userids = (array) $db->loadObjectList();
         KunenaError::checkDatabaseError();
     }
     return $userids;
 }
Example #5
0
 protected static function pollUsersOrphaned()
 {
     // Query to find messages which do not belong in any existing topic
     $query = new KunenaDatabaseQuery();
     $query->from("#__kunena_polls_users AS a")->leftJoin("#__kunena_polls AS p ON p.id=a.pollid")->where("p.id IS NULL");
     return $query;
 }
Example #6
0
 protected function _get_user_groups($userid)
 {
     static $cache = array();
     $userid = intval($userid);
     if (!$userid) {
         return array(29);
     }
     if (!isset($cache[$userid])) {
         $db = JFactory::getDbo();
         $query = new KunenaDatabaseQuery();
         $query->select('g.id');
         $query->from('#__core_acl_aro AS o');
         $query->join('INNER', '#__core_acl_groups_aro_map AS gm ON gm.aro_id=o.id');
         $query->join('INNER', '#__core_acl_aro_groups AS g ON g.id = gm.group_id');
         $query->where("(o.section_value='users' AND o.value=" . $db->quote($userid) . ')');
         $db->setQuery($query);
         $cache[$userid] = $db->loadResultArray();
     }
     return $cache[$userid];
 }
Example #7
0
	/**
	 * Method to delete a row from the database table by primary key value.
	 *
	 * @param   mixed    $keys  An optional primary key value to delete.  If not set the
	 *                          instance property value is used.
	 *
	 * @return  boolean  True on success.
	 *
	 * @link	http://docs.joomla.org/JTable/delete
	 * @since   Joomla 11.1
	 */
	public function delete($keys = null)
	{
		// Initialise variables.
		if (empty($keys)) {
			// If empty, use the value of the current key
			if (!is_array($this->_tbl_key)) {
				$keyName = $this->_tbl_key;
				$keyValue = $this->$keyName;

				// If null primary key there's is no need to delete
				if(is_null($keyValue)) {
					$e = new JException(JText::_('JLIB_DATABASE_ERROR_NULL_PRIMARY_KEY'));
					$this->setError($e);
					return false;
				}
				$keys = array($keyName => $keyValue);
			} else {
				$keys = array();
				foreach ($this->_tbl_key as $keyName) {
					$keyValue = $this->$keyName;
					$keys[$keyName] = $keyValue;

					// If null primary key there's is no need to delete
					if(is_null($keyValue)) {
						$e = new JException(JText::_('JLIB_DATABASE_ERROR_NULL_PRIMARY_KEY'));
						$this->setError($e);
						return false;
					}
				}
			}
		} elseif (!is_array($keys)) {
			// Delete by primary key.
			$keys = array($this->_tbl_key => $keys);
		}

		// Delete the row by primary key.
		$query	= new KunenaDatabaseQuery();
		$query->delete();
		$query->from($this->_tbl);
		foreach ($keys as $key=>$value) {
			$query->where("{$this->_db->nameQuote($key)} = {$this->_db->quote($value)}");
		}
		$this->_db->setQuery($query);

		// Check for a database error.
		if (!$this->_db->query()) {
			$e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this), $this->_db->getErrorMsg()));
			$this->setError($e);
			return false;
		}

		return true;
	}
Example #8
0
	public function load($keys = null, $reset = true) {
		if (empty($keys)) {
			// If empty, use the value of the current key
			if (!is_array($this->_tbl_key)) {
				$keyName = $this->_tbl_key;
				$keyValue = $this->$keyName;

				// If empty primary key there's is no need to load anything
				if(empty($keyValue)) return false;
				$keys = array($keyName => $keyValue);
			} else {
				$keys = array();
				foreach ($this->_tbl_key as $keyName) {
					$keyValue = $this->$keyName;
					$keys[$keyName] = $keyValue;

					// If null primary key there's is no need to load anything
					if($keyValue === null) return false;
				}
			}
		} elseif (!is_array($keys)) {
			// Load by primary key.
			$keys = array($keys);
		}

		if ($reset) $this->reset();

		// Initialise the query.
		$query	= new KunenaDatabaseQuery();
		$query->select('*');
		$query->from($this->_tbl);
		$fields = array_keys($this->getProperties());

		if (is_array($this->_tbl_key)) reset($this->_tbl_key);
		foreach ($keys as $field => $value) {
			if (is_numeric($field)) {
				if (!is_array($this->_tbl_key)) {
					$field = $this->_tbl_key;
				} else {
					list($i,$field) = each($this->_tbl_key);
				}
				$this->$field = $value;
			}
			// Check that $field is in the table.
			if (!in_array($field, $fields)) {
				$e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_CLASS_IS_MISSING_FIELD', get_class($this), $field));
				$this->setError($e);
				return false;
			}
			// Add the search tuple to the query.
			$query->where($this->_db->nameQuote($field).' = '.$this->_db->quote($value));
		}

		$this->_db->setQuery($query);
		$row = $this->_db->loadAssoc();

		// Check for a database error.
		if ($this->_db->getErrorNum()) {
			$e = new JException($this->_db->getErrorMsg());
			$this->setError($e);
			return false;
		}

		// Check that we have a result.
		if (empty($row)) {
			$e = new JException(JText::_('JLIB_DATABASE_ERROR_EMPTY_ROW_RETURNED'));
			$this->setError($e);
			return false;
		}

		// Bind the object with the row and return.
		return $this->_exists = $this->bind($row);
	}
Example #9
0
 protected function checkSubscribers($category, &$userids)
 {
     $userlist = implode(',', $userids);
     $db = JFactory::getDBO();
     $query = new KunenaDatabaseQuery();
     $query->select('u.id');
     $query->from('#__users AS u');
     $query->where("u.block=0");
     $query->where("u.id IN ({$userlist})");
     if ($category->accesstype == 'joomla') {
         // Check against Joomla access level
         if ($category->access > 1) {
             // Special users = not in registered group
             $query->where("u.gid!=18");
         }
     } elseif ($category->accesstype == 'none') {
         // Check against Joomla user groups
         $public = $this->_get_groups($category->pub_access, $category->pub_recurse);
         $admin = $category->pub_access > 0 ? $this->_get_groups($category->admin_access, $category->admin_recurse) : array();
         $groups = implode(',', array_unique(array_merge($public, $admin)));
         if ($groups) {
             $query->join('LEFT', "#__noixacl_multigroups AS g ON g.id_user=u.id");
             $query->where("(u.gid IN ({$groups}) OR g.id_group IN ({$groups}))");
         }
     } else {
         return array();
     }
     $db->setQuery($query);
     $userids = (array) $db->loadResultArray();
     KunenaError::checkDatabaseError();
 }