Пример #1
0
 public function execute()
 {
     if ('' === ($filename = Common::getGetString('filename'))) {
         return GWF_Error::err('ERR_NO_PERMISSION');
     }
     $path = $this->module->getContentPath();
     $filename = $path . '/' . $filename;
     if (!Common::isFile($filename)) {
         return GWF_Error::err404($filename);
     }
     GWF_Upload::outputFile($filename);
 }
Пример #2
0
 private static function insertTag($tag, $pid, $langid)
 {
     # Insert tagname
     $etag = GDO::escape($tag);
     $langid = (int) $langid;
     if (false === ($tid = GDO::table(__CLASS__)->selectVar('ptag_tid', "ptag_tag='{$etag}' AND ptag_lang={$langid}"))) {
         $newtag = new self(array('ptag_tid' => '0', 'ptag_lang' => $langid, 'ptag_tag' => $tag, 'ptag_count' => '1'));
         if (false === $newtag->insert()) {
             return GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         if (0 == ($tid = $newtag->getID())) {
             return GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     # Insert into map
     $data = array('ptm_pid' => $pid, 'ptm_tid' => $tid);
     if (false === GDO::table('GWF_PageTagMap')->insertAssoc($data, true)) {
         return GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return true;
 }
Пример #3
0
 /**
  * Return a single html select for languages. 
  * @param int $bitmask
  * @param string $name param name
  * @param mixed $selected 
  * @param string $text
  */
 public static function single($bitmask = 0, $name = 'language', $selected = true, $text = true)
 {
     $db = gdo_db();
     $table = GDO::table('GWF_Language');
     $bitmask = (int) $bitmask;
     if (false === ($result = $table->select('lang_id, lang_name', "lang_options&{$bitmask}={$bitmask}"))) {
         GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
         return '';
     }
     if ($selected === true) {
         $selected = Common::getPostString($name, '0');
     }
     if ($text === true) {
         $text = GWF_HTML::lang('sel_language');
     }
     $data = array(array('0', $text));
     while (false !== ($row = $db->fetchRow($result))) {
         $data[] = $row;
     }
     $db->free($result);
     return GWF_Select::display($name, $data, Common::getPostString($name, $selected));
 }
Пример #4
0
 private function onTranslate(GWF_Page $page)
 {
     $form = $this->formTranslate($page);
     if (false !== ($error = $form->validate($this->module))) {
         return $error;
     }
     $options = 0;
     $options |= GWF_Page::ENABLED;
     $options |= GWF_Page::TRANSLATION;
     $options |= $page->isLoginRequired() ? GWF_Page::LOGIN_REQUIRED : 0;
     $options |= $this->locked_mode ? GWF_Page::LOCKED : 0;
     $options |= $page->getMode();
     $options |= $page->getShowFlags();
     $gstring = $page->getVar('page_groups');
     $tags = ',' . trim(trim($form->getVar('tags')), ',') . ',';
     $author = GWF_User::getStaticOrGuest();
     $time = time();
     $date = GWF_Time::getDate(GWF_Time::LEN_SECOND, $time);
     $newpage = new GWF_Page(array('page_id' => '0', 'page_otherid' => $page->getID(), 'page_lang' => $form->getVar('lang'), 'page_author' => $author->getID(), 'page_author_name' => $author->getVar('user_name'), 'page_groups' => $gstring, 'page_create_date' => $date, 'page_date' => $date, 'page_time' => $time, 'page_url' => $form->getVar('url'), 'page_title' => $form->getVar('title'), 'page_cat' => '0', 'page_meta_tags' => $tags, 'page_meta_desc' => $form->getVar('descr'), 'page_content' => $form->getVar('content'), 'page_views' => '0', 'page_options' => $options, 'page_inline_css' => $page->getVar('page_inline_css')));
     if (false === $newpage->insert()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     // 		if (false === GWF_PageGID::updateGIDs($newpage, $gstring))
     // 		{
     // 			return GWF_HTML::err('ERR_DATABASE', array(__FILE__,__LINE__));
     // 		}
     if (false === GWF_PageTags::updateTags($newpage, $tags, $form->getVar('lang'))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === $this->module->writeHTA()) {
         return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__));
     }
     if ($this->locked_mode) {
         $this->module->sendModMails();
         return $this->module->message('msg_added_locked');
     }
     if (false === GWF_PageHistory::push($newpage)) {
         GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return $this->module->message('msg_trans');
 }
Пример #5
0
 public static function getIP($type = self::INT_32, $ip = false)
 {
     $ip = is_bool($ip) ? self::remoteAddress() : $ip;
     $is6 = self::isV6($ip);
     $is4 = self::isV4($ip);
     if ($is6 && $is4) {
         $ip = self::ip6toIP4($ip);
     }
     switch ($type) {
         case self::INT_32:
             return $is4 ? self::ip4ToInt32($ip) : 0;
         case self::UINT_32:
             return $is4 ? self::ip4ToUInt32($ip) : 0;
         case self::HASH_32_1:
             return $is4 ? self::ip4ToInt32($ip) : self::ip6ToInt32($ip);
         case self::HASH_32_2:
             return $is4 ? self::ip4ToInt32Hash($ip, true) : self::ip6ToInt32Hash($ip, true);
         case self::HASH_32_3:
             return $is4 ? self::ip4ToInt32Hash($ip, false) : self::ip6ToInt32Hash($ip, false);
         case self::HASH_64:
             return $is4 ? self::ip4ToInt64Hash($ip) : self::ip6ToInt64Hash($ip);
         case self::HEX_32_128:
             return $is4 ? self::ip4ToHex128($ip, true) : self::ip6ToHex128($ip, true);
         case self::HEX_128:
             return $is4 ? self::ip4ToHex128($ip, false) : self::ip6ToHex128($ip, false);
         case self::BIN_32_128:
             return $is4 ? self::ip4ToBlob128($ip, true) : self::ip6ToBlob128($ip, true);
         case self::BIN_128:
             return $is4 ? self::ip4ToBlob128($ip, false) : self::ip6ToBlob128($ip, false);
         case self::AS_IS:
             return $is4 ? $ip : self::ip6AsIs($ip);
         case self::PACK_1:
         case self::PACK_2:
         default:
             GWF_Error::err('ERR_PARAMETER', array(__FILE__, __LINE__, 'type'));
             //return false;
             die(htmlspecialchars($type));
     }
 }
Пример #6
0
function merge_users(GDO_Database $db_from, GDO_Database $db_to, array &$db_offsets, $prefix, $prevar)
{
    $db_offsets['user_name'] = array();
    GDO::setCurrentDB($db_from);
    $users = GDO::table('GWF_User');
    if (false === ($result = $users->select('*', '', 'user_id ASC'))) {
        echo GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
        return false;
    }
    GDO::setCurrentDB($db_to);
    $to_users = GDO::table('GWF_User');
    $off = $db_offsets['GWF_User'];
    while (false !== ($user = $users->fetch($result, GDO::ARRAY_A))) {
        $oldname = $user['user_name'];
        $newname = merge_user_name($user['user_name'], $to_users, $prefix, $prevar);
        $user['user_name'] = $newname;
        if ($oldname !== $newname) {
            $db_offsets['user_name'][$oldname] = $newname;
        }
        $user['user_id'] += $off;
        $to_users->insertAssoc($user);
        GWF_Cronjob::log('Added user ' . $user['user_name'] . ' with id ' . $user['user_id']);
    }
    $users->free($result);
    return true;
}
Пример #7
0
 /**
  * Send moderation mail for a fresh page.
  * @param GWF_Page $page
  */
 public function sendModMails(GWF_Page $page)
 {
     if (false === ($method = $this->getMethod('Moderate'))) {
         GWF_Error::err('ERR_METHOD_MISSING', array('Moderate', 'PageBuilder'));
     }
     $method instanceof PageBuilder_Moderate;
     $method->sendModMails($page);
 }
Пример #8
0
 public function onDelete(GWF_Page $page, $do_cleanup = true)
 {
     # History is per page basis, and can be deleted easily.
     if (false === GWF_PageHistory::onDelete($page)) {
         return GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     #
     if (false === GWF_PageTagMap::onDelete($page)) {
         return GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     # Last of them?
     $num_trans = $page->selectVar('COUNT(*)', "page_otherid={$oid}");
     if ($num_trans === 1) {
         if (false === GWF_PageGID::onDelete($page)) {
             return GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     } elseif ($page->isRoot()) {
         if (!$this->newRoot($page)) {
             return GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     if (false === $page->delete()) {
         return GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if ($do_cleanup) {
         if (false === $this->onDeleteCleanup()) {
             return GWF_Error::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     GWF_Website::addDefaultOutput($this->module->message('msg_deleted'));
     return true;
 }