Example #1
0
 public static function getCloud(Module_Links $module)
 {
     //		$db = gdo_db();
     $back = array();
     if ($module->cfgShowPermitted()) {
         $conditions = '';
     } else {
         $conditions = $module->getPermQuery(GWF_Session::getUser());
     }
     $table = self::table('GWF_LinksTagMap');
     if (false === ($result = $table->select('lt_name, COUNT(*) lt_count, link_score', $conditions, 'lt_name ASC', array('ltm_lid', 'ltm_ltid'), -1, -1, 'lt_name'))) {
         return $back;
     }
     while (false !== ($row = $table->fetch($result, self::ARRAY_A))) {
         if ($row['lt_name'] !== NULL) {
             $back[] = new GWF_LinksTag($row);
         }
     }
     $table->free($result);
     //		$map = self::table(__CLASS__);#->getTableName();
     //		$tags = self::table('GWF_LinksTag')->getTableName();
     //		$links = self::table('GWF_Links')->getTableName();
     //		return $map
     //
     //		if (false !== ($result = $db->queryAll("SELECT lt_name, COUNT(*) lt_count, link_score FROM $map LEFT JOIN $tags ON lt_id=ltm_ltid LEFT JOIN $links ON link_id=ltm_lid WHERE $conditions GROUP BY ltm_ltid ORDER BY lt_name ASC ")))
     //		{
     //			foreach ($result as $row)
     //			{
     //				$back[] = new GWF_LinksTag($row);
     //			}
     //		}
     //		var_dump($back);
     return $back;
 }
Example #2
0
 public static function validate_tags(Module_Links $module, $arg)
 {
     $errors = array();
     $new = 0;
     $arg = explode(',', trim($arg));
     $taken = array();
     $minlen = 3;
     $maxlen = $module->cfgMaxTagLen();
     foreach ($arg as $tag) {
         $tag = trim($tag);
         if (strlen($tag) === 0) {
             continue;
         }
         if (false === GWF_LinksTag::getByName($tag)) {
             if (self::isValidTagName($tag, $minlen, $maxlen)) {
                 $taken[] = $tag;
                 $new++;
             } else {
                 $errors[] = $module->lang('err_tag', array(GWF_HTML::display($tag), $minlen, $maxlen));
             }
         } else {
             $taken[] = $tag;
         }
     }
     if (count($taken) === 0) {
         $errors[] = $module->lang('err_no_tag');
     }
     $_POST['link_tags'] = implode(',', $taken);
     if (count($errors) === 0) {
         return false;
     }
     return implode('<br/>', $errors);
 }
Example #3
0
 private static function checkLinksDown(Module_Links $module)
 {
     GWF_Module::loadModuleDB('Votes')->onInclude();
     $links = GDO::table('GWF_Links');
     $limit = $module->cfgCheckAmount();
     $cut = time() - $module->cfgCheckInterval();
     $dead = GWF_Links::DEAD;
     if (false === ($result = $links->selectObjects('*', "link_lastcheck<{$cut} AND link_options&{$dead}=0", 'link_lastcheck DESC', $limit))) {
         return self::error("Database error Links-1");
     }
     if (0 === ($left = count($result))) {
         return self::notice('No links to check.');
     }
     self::notice("Checking {$left} links.");
     foreach ($result as $link) {
         self::checkLinkDown($module, $link);
     }
 }
Example #4
0
function wcProfileOwnLinks(GWF_User $user, Module_Links $mod_links)
{
    $linksT = GDO::table('GWF_Links');
    $user_browsing = GWF_Session::getUser();
    $perm_query = $mod_links->cfgShowPermitted() ? '1' : $mod_links->getPermQuery($user_browsing);
    $mod_query = $linksT->getModQuery($user_browsing);
    $member_query = $linksT->getMemberQuery($user_browsing);
    $private_query = $linksT->getPrivateQuery($user_browsing);
    $aff_query = $linksT->getUnaffQuery($user_browsing);
    $conditions = "({$perm_query}) AND ({$mod_query}) AND ({$member_query}) AND ({$private_query}) AND ({$aff_query})";
    //	$mod_links->onInclude();
    //	$mod_links->onLoadLanguage();
    $links = $linksT->getTableName();
    $votes = GDO::table('GWF_VoteScore')->getTableName();
    $private = GWF_Links::ONLY_PRIVATE;
    $userid = $user->getID();
    $query = "SELECT {$links}.*, {$votes}.* FROM {$links} JOIN {$votes} ON vs_id=link_voteid WHERE link_user={$userid} AND {$conditions}";
    //	var_dump($query);
    $db = gdo_db();
    if (false === ($result = $db->queryRead($query))) {
        return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
    }
    $links = array();
    while (false !== ($row = $db->fetchAssoc($result))) {
        $links[] = new GWF_Links($row);
        # $linksT->createClass($row);
    }
    if (0 === ($count = count($links))) {
        return '';
    }
    return '<h2>' . WC_HTML::lang('own_links', array($user->displayUsername(), $count)) . '</h2>' . $mod_links->templateLinks($links, '', '', '', false, false, false, false);
}
Example #5
0
 /**
  * Check if we have permission to view that link. In case we do, return empty string. else return verbose permission text.
  * @param Module_Links $module
  * @param GWF_User $user
  * @return string
  */
 public function getPermissionText(Module_Links $module, $user)
 {
     static $text = NULL;
     if ($text === NULL) {
         $text = array($module->lang('permtext_in_mod'), $module->lang('permtext_score', array('%1%')), $module->lang('permtext_member'), $module->lang('permtext_group', array('%1%')));
     }
     if ($this->isInModeration()) {
         return $text[0];
     }
     $score = $user === false ? 0 : $user->getLevel();
     # Check score
     $need_score = $this->getVar('link_score');
     if ($score < $need_score) {
         return str_replace('%1%', $need_score, $text[1]);
     }
     # Check memberlink
     if ($user === false && $this->isMemberLink()) {
         return $text[2];
     }
     # Check group
     $need_gid = $this->getGroupID();
     if ($need_gid > 0) {
         if ($user === false || !$user->isInGroupID($need_gid)) {
             return str_replace('%1%', GWF_Group::getByID($need_gid)->displayName(), $text[3]);
         }
     }
     return '';
 }