public function receive_new_comment($SubmittedForm)
 {
     $input = $SubmittedForm->data;
     if ($input['parentID']) {
         $data = array();
         $data['parentID'] = $input['parentID'];
         $data['commentDateTime'] = date('Y-m-d H:i:s');
         foreach ($this->static_fields as $field) {
             if (!isset($data[$field])) {
                 if (isset($input[$field]) && $input[$field] != '') {
                     $data[$field] = trim($input[$field]);
                 }
             }
         }
         // dynamic fields
         $dynamic_fields = array();
         foreach ($input as $field => $val) {
             if (!isset($data[$field])) {
                 $dynamic_fields[$field] = trim($val);
             }
         }
         $data['commentDynamicFields'] = PerchUtil::json_safe_encode($dynamic_fields);
         // Anti-spam
         $Settings = $this->api->get('Settings');
         $akismetAPIKey = $Settings->get('perch_comments_akismet_key')->val();
         $spam = false;
         $antispam = $SubmittedForm->get_antispam_values();
         $environment = $_SERVER;
         $spam_data = array();
         $spam_data['fields'] = $antispam;
         $spam_data['environment'] = $environment;
         $data['commentSpamData'] = PerchUtil::json_safe_encode($spam_data);
         $data['commentIP'] = ip2long($_SERVER['REMOTE_ADDR']);
         $spam = $this->_check_for_spam($antispam, $environment, $akismetAPIKey);
         if ($spam) {
             $data['commentStatus'] = 'SPAM';
         } else {
             $Users = new PerchUsers();
             $CurrentUser = $Users->get_current_user();
             if (is_object($CurrentUser) && $CurrentUser->logged_in()) {
                 $data['commentStatus'] = 'LIVE';
             } else {
                 $data['commentStatus'] = 'PENDING';
             }
         }
         foreach ($data as $key => $val) {
             switch ($key) {
                 case 'commentHTML':
                     if (!class_exists('\\Netcarver\\Textile\\Parser', false) && class_exists('Textile', true)) {
                         // sneaky autoloading hack
                     }
                     if (PERCH_HTML5) {
                         $Textile = new \Netcarver\Textile\Parser('html5');
                     } else {
                         $Textile = new \Netcarver\Textile\Parser();
                     }
                     if (PERCH_RWD) {
                         $val = $Textile->setDimensionlessImages(true)->textileRestricted($val);
                     } else {
                         $val = $Textile->textileRestricted($val);
                     }
                     if (defined('PERCH_XHTML_MARKUP') && PERCH_XHTML_MARKUP == false) {
                         $val = str_replace(' />', '>', $val);
                     }
                     break;
                 case 'commentURL':
                     if (!parse_url($val, PHP_URL_SCHEME)) {
                         $val = 'http://' . $val;
                     }
                     if (!parse_url($val, PHP_URL_SCHEME)) {
                         $val = '';
                     }
                     $val = strtolower($val);
                     break;
                 case 'commentEmail':
                     $val = strtolower($val);
                     break;
                 case 'parentTitle':
                     $val = html_entity_decode($val, ENT_QUOTES, 'UTF-8');
                     break;
             }
             $data[$key] = $val;
         }
         $r = $this->create($data);
         return $r;
     }
     PerchUtil::debug($SubmittedForm);
 }
Пример #2
0
 public function receive_new_listing($SubmittedForm)
 {
     $API = new PerchAPI(1.0, 'perch_members');
     $Session = PerchMembers_Session::fetch();
     $input = $SubmittedForm->data;
     $data = array();
     $data['listingDateTime'] = date('Y-m-d H:i:s');
     $data['memberID'] = $Session->get('memberID');
     $data['listingType'] = $input['listingType'];
     $data['listingTitle'] = $input['listingTitle'];
     $data['listingSlug'] = PerchUtil::urlify($input['listingTitle']);
     foreach ($this->static_fields as $field) {
         if (!isset($data[$field])) {
             if (isset($input[$field]) && $input[$field] != '') {
                 $data[$field] = trim($input[$field]);
             }
         }
     }
     // dynamic fields
     $dynamic_fields = array();
     foreach ($input as $field => $val) {
         if (!isset($data[$field])) {
             $dynamic_fields[$field] = trim($val);
         }
     }
     $data['listingDynamicFields'] = PerchUtil::json_safe_encode($dynamic_fields);
     foreach ($data as $key => $val) {
         switch ($key) {
             case 'listingHTML':
                 if (!class_exists('\\Netcarver\\Textile\\Parser', false) && class_exists('Textile', true)) {
                     // sneaky autoloading hack
                 }
                 if (PERCH_HTML5) {
                     $Textile = new \Netcarver\Textile\Parser('html5');
                 } else {
                     $Textile = new \Netcarver\Textile\Parser();
                 }
                 if (PERCH_RWD) {
                     $val = $Textile->setDimensionlessImages(true)->textileRestricted($val);
                 } else {
                     $val = $Textile->textileRestricted($val);
                 }
                 if (defined('PERCH_XHTML_MARKUP') && PERCH_XHTML_MARKUP == false) {
                     $val = str_replace(' />', '>', $val);
                 }
                 break;
         }
         $data[$key] = $val;
     }
     // print_r($data);
     // die();
     if (isset($data['listingID'])) {
         if ($this->check_title_exists($data['listingTitle'], $data['listingID'])) {
             $Listings = new Listings($API);
             $Listing = $Listings->find($data['listingID']);
             // Don't allow people to change their URL
             unset($data['listingSlug']);
             $r = $Listing->update($data);
         } else {
             $SubmittedForm->throw_error('duplicate', 'listingTitle');
             return false;
         }
     } else {
         if ($this->check_title_exists($data['listingTitle'])) {
             $r = $this->create($data);
         } else {
             $SubmittedForm->throw_error('duplicate', 'listingTitle');
             return false;
         }
     }
     return $r;
     PerchUtil::debug('this' . $SubmittedForm);
 }