public static function mark(GWF_User $user, GWF_Links $link, $bool) { $userid = $user->getID(); $linkid = $link->getID(); $is_fav = self::table(__CLASS__)->getRow($userid, $linkid) !== false; if ($is_fav === $bool) { return true; } $row = new self(array('lf_uid' => $userid, 'lf_lid' => $linkid)); if ($bool) { if (!$row->replace()) { return false; } } else { if (!$row->delete()) { return false; } } if (false === $link->increase('link_favcount', $bool ? 1 : -1)) { return false; } if (false === $link->onCalcPopularity()) { return false; } return true; }
private function onApprove($lid, $approve) { if (false === ($link = GWF_Links::getByID($lid))) { return $this->module->error('err_link'); } if (!$link->isInModeration()) { return $this->module->error('err_approved'); } if ($link->getToken() !== Common::getGet('token')) { return $this->module->error('err_token'); } if ($approve) { if (false !== ($error = $link->insertTags($this->module))) { return $error; } if (false === $link->saveOption(GWF_Links::IN_MODERATION, false)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === $link->setVotesEnabled(true)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } } else { if (false !== ($error = $link->deleteLink($this->module))) { return $error; } } return $this->module->message($approve ? 'msg_approved' : 'msg_deleted'); }
private function onEdit() { $form = $this->getForm(); if (false !== ($error = $form->validate($this->module))) { return $error; } // var_dump($_POST); $this->link->removeTags(); $data = array('link_gid' => $form->getVar('link_gid'), 'link_score' => $form->getVar('link_score'), 'link_href' => $form->getVar('link_href'), 'link_descr' => $form->getVar('link_descr'), 'link_tags' => $form->getVar('link_tags')); if (false !== ($descr2 = $form->getVar('link_descr2'))) { $data['link_descr2'] = $descr2; } if (false === $this->link->saveVars($data)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $this->link->insertTags($this->module); $this->link->saveOption(GWF_Links::UNAFILIATE, isset($_POST['link_options&' . GWF_Links::UNAFILIATE])); $this->link->saveOption(GWF_Links::MEMBER_LINK, isset($_POST['link_options&' . GWF_Links::MEMBER_LINK])); $this->link->saveOption(GWF_Links::ONLY_PRIVATE, isset($_POST['link_options&' . GWF_Links::ONLY_PRIVATE])); if (GWF_User::isStaffS()) { $this->link->saveOption(GWF_Links::STICKY, isset($_POST['link_options&' . GWF_Links::STICKY])); if (false === $this->link->toggleModeration($this->module, isset($_POST['link_options&' . GWF_Links::IN_MODERATION]))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } } return $this->module->message('msg_edited'); }
public function execute() { if (false === ($link = GWF_Links::getByID(Common::getGet('lid')))) { return $this->module->error('err_link'); } if (!$link->mayView(GWF_Session::getUser())) { return $this->module->error('err_view_perm'); } if (false === $link->increase('link_clicks', 1)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === $link->onCalcPopularity()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } // $link->markRead(GWF_Session::getUser()); return $this->module->message('msg_counted_visit'); // header('Location: '.$link->getVar('link_href')); // return $this->module->message('msg_redirecting', array($link->display('link_href'))); }
public function execute() { if (false === ($link = GWF_Links::getByID(Common::getGet('lid')))) { return $this->module->error('err_link'); } if (!$link->mayView(GWF_Session::getUser())) { return $this->module->error('err_view_perm'); } if ('favorite' === Common::getGet('my')) { $fav = true; } elseif ('favorite' === Common::getGet('no')) { $fav = false; } else { return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__)); } if (false === GWF_LinksFavorite::mark(GWF_Session::getUser(), $link, $fav)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $msg = $fav ? 'msg_fav_yes' : 'msg_fav_no'; return $this->module->message($msg); }
private static function checkLinkDown(Module_Links $module, GWF_Links $link) { # Get HREF $href = $link->getVar('link_href'); if (strpos($href, '/') === 0) { $href = 'http://' . GWF_DOMAIN . GWF_WEB_ROOT . substr($href, 1); } if (GWF_HTTP::pageExists($href)) { self::notice("Checking {$href} ... UP"); $link->saveVar('link_downcount', 0); $link->saveOption(GWF_Links::DOWN | GWF_Links::DEAD, false); } else { self::notice("Checking {$href} ... DOWN"); $link->increase('link_downcount', 1); $bits = GWF_Links::DOWN; $count = $link->getVar('link_downcount'); if ($count > GWF_Links::DOWNCOUNT_DEAD) { $bits |= GWF_Links::DEAD; } $link->saveOption($bits, true); } $link->saveVar('link_lastcheck', time()); }
private function onMarkAllRead() { if (false === ($user = GWF_Session::getUser())) { return ''; } $table = GWF_Links::table('GWF_Links'); if (false === ($result = $table->select('*'))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } while (false !== ($link = $table->fetch($result, GDO::ARRAY_O))) { $link instanceof GWF_Links; if (false === $link->markRead($user)) { $table->free($result); return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } } $table->free($result); $data = $user->getUserData(); $data[Module_Links::USERDATA_MARK] = GWF_Time::getDate(GWF_Date::LEN_SECOND); if (false === $user->saveUserData($data)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return $this->module->message('msg_marked_all_read'); }
public static function mayAddTag(Module_Links $module, $user) { if (is_object($user)) { return GWF_Links::mayUserAddTag($module, $user); } else { return GWF_Links::mayGuestAddTag($module); } }
private function sendModMail(GWF_Links $link) { $link = GWF_Links::getByID($link->getID()); $mail = new GWF_Mail(); $mail->setSender(GWF_BOT_EMAIL); $mail->setReceiver(GWF_ADMIN_EMAIL); $mail->setSubject($this->module->lang('mail_subj')); $href = $link->getVar('link_href'); $descr = $link->display('link_descr'); $descr2 = $link->display('link_descr2'); $anchor = GWF_HTML::anchor($href, $href); $approve = Common::getAbsoluteURL($link->hrefModApprove()); $approve = GWF_HTML::anchor($approve, $approve); $delete = Common::getAbsoluteURL($link->hrefModDelete()); $delete = GWF_HTML::anchor($delete, $delete); $mail->setBody($this->module->lang('mail_body', array($descr, $descr2, $anchor, $approve, $delete))); $mail->sendAsHTML(GWF_STAFF_EMAILS); }
public function hookVoted(GWF_User $user, array $args) { $vsid = (int) $args[0]; $this->onInclude(); if (false !== ($link = GWF_Links::getByVSID($vsid))) { return $link->onCalcPopularity(); } return true; }