Beispiel #1
0
 public static function getInstance()
 {
     if (NULL === self::$static) {
         self::$static = new self();
     }
     return self::$static;
 }
Beispiel #2
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);
 }
Beispiel #3
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;
 }
Beispiel #4
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));
 }
Beispiel #5
0
 public static function wizard_message($key, $param = NULL)
 {
     return GWF_Error::message(self::$gwfil->lang('wizard'), self::$gwfil->lang($key, $param), false, true) . PHP_EOL;
 }
Beispiel #6
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');
 }
Beispiel #7
0
 public static function getHTMLHead()
 {
     $tVars = array('page_title' => self::displayPageTitle(), 'language' => GWF_Language::getCurrentISO(), 'meta' => self::displayMeta(), 'js' => self::displayJavascripts(), 'head_links' => self::displayLink());
     # Errors and messages from GWF_Error
     GWF_Error::displayAll();
     return GWF_Doctype::getDoctype(GWF_DEFAULT_DOCTYPE) . GWF_Template::templateMain('html_head.tpl', $tVars) . PHP_EOL;
 }
Beispiel #8
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));
     }
 }
Beispiel #9
0
 private function onEdit()
 {
     $form = $this->formEdit();
     if (false !== ($error = $form->validate($this->module))) {
         return $error;
     }
     $page = $this->page;
     $gstring = $this->buildGroupString();
     $tags = ',' . trim(trim($form->getVar('tags')), ',') . ',';
     $data = array();
     if ($page->getVar('page_url') !== ($url = $form->getVar('url'))) {
         $data['page_url'] = $url;
     }
     if ($page->getVar('page_title') !== ($title = $form->getVar('title'))) {
         $data['page_title'] = $title;
     }
     if ($page->getVar('page_meta_tags') !== $tags) {
         $data['page_meta_tags'] = $tags;
     }
     if ($page->getVar('page_meta_desc') !== ($descr = $form->getVar('descr'))) {
         $data['page_meta_desc'] = $descr;
     }
     if ($page->getVar('page_content') !== ($content = $form->getVar('content'))) {
         $data['page_content'] = $content;
     }
     if ($this->is_author) {
         if ($page->getVar('page_inline_css') !== ($css = $form->getVar('inline_css'))) {
             $data['page_inline_css'] = $css;
         }
     }
     $content_changed = count($data) > 0;
     if ($content_changed) {
         $time = time();
         $data['page_time'] = $time;
         $data['page_date'] = GWF_Time::getDate(GWF_Time::LEN_SECOND, $time);
         if (false === $page->saveVars($data)) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     if (isset($_POST['home_page']) && $this->is_author) {
         $this->module->setHomePage($page->getOtherID());
     }
     if ($this->is_author) {
         if (false === $this->setAuthorOptions($page)) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     if ($this->is_oowner) {
         if (false === $this->setRootOptions($page, $gstring)) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         if ($gstring !== $page->getVar('page_groups')) {
             if (false === GWF_PageGID::updateGIDs($page, $gstring)) {
                 return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
             }
         }
     }
     if ($this->is_owner) {
         if (false === $this->setOwnerOptions($page)) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     if (false === GWF_PageTags::updateTags($page, $tags, $page->getVar('page_lang'))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === $this->module->writeHTA()) {
         return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__));
     }
     # No content change
     if (!$content_changed) {
         return $this->module->message('msg_edited', array(GWF_WEB_ROOT . $page->display('page_url'), $page->display('page_title')));
     }
     # Content changed!
     echo GWF_Error::message('PageBuilder', 'Content changed!');
     # If author mode we directly push
     if ($this->is_author) {
         if (false === GWF_PageHistory::push($page)) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         return $this->module->message('msg_edited', array(GWF_WEB_ROOT . $page->getVar('page_url'), $page->getVar('page_title')));
     }
     # Else we gonna send moderation mails
     if (false === $page->saveOption(GWF_Page::LOCKED, true)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     $this->module->sendModMails($page);
     return $this->module->message('msg_edit_locked');
 }
Beispiel #10
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;
}
Beispiel #11
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);
 }
Beispiel #12
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;
 }