Exemplo n.º 1
0
 public function get_page_by_path($path)
 {
     if (isset($this->pages_cache[$path])) {
         return $this->pages_cache[$path];
     }
     $Pages = new PerchContent_Pages();
     $Page = $Pages->find_by_path($path);
     if (is_object($Page)) {
         $this->pages_cache[$path] = $Page;
     }
     return $this->pages_cache[$path];
 }
 public function process_response($SubmittedForm)
 {
     $opts = $this->_load_options();
     $data = array();
     $data['fields'] = array();
     $data['files'] = array();
     $data['page'] = $SubmittedForm->page;
     if (class_exists('PerchContent_Pages')) {
         $Pages = new PerchContent_Pages();
         $Page = $Pages->find_by_path($SubmittedForm->page);
         if ($Page) {
             $data['page'] = array('id' => $Page->pageID(), 'title' => $Page->pageTitle(), 'path' => $Page->pagePath(), 'navtext' => $Page->pageNavText());
         }
     }
     // Anti-spam
     $spam = false;
     $antispam = $SubmittedForm->get_antispam_values();
     $environment = $_SERVER;
     $akismetAPIKey = false;
     if (isset($opts->akismet) && $opts->akismet) {
         if (isset($opts->akismetAPIKey) && $opts->akismetAPIKey != '') {
             $akismetAPIKey = $opts->akismetAPIKey;
         }
     }
     $spam = $this->_check_for_spam($antispam, $environment, $akismetAPIKey);
     // Files
     if (!$spam && PerchUtil::count($SubmittedForm->files)) {
         if (isset($opts->fileLocation) && $opts->fileLocation != '') {
             foreach ($SubmittedForm->files as $key => &$details) {
                 if ($details['error'] == '0' && $details['size'] > 0) {
                     // no error, upload worked
                     $attrs = $SubmittedForm->get_template_attributes($key);
                     if (is_uploaded_file($details['tmp_name'])) {
                         $filename = $details['name'];
                         $dest = rtrim($opts->fileLocation, '\\/') . DIRECTORY_SEPARATOR;
                         if (file_exists($dest . $filename)) {
                             $filename = time() . $filename;
                         }
                         if (file_exists($dest . $filename)) {
                             $filename = time() . mt_rand() . $filename;
                         }
                         if (PerchUtil::move_uploaded_file($details['tmp_name'], $dest . $filename)) {
                             $details['new_path'] = $dest . $filename;
                             $details['new_filename'] = $filename;
                             $file = new stdClass();
                             $file->name = $filename;
                             $file->path = $dest . $filename;
                             $file->size = $details['size'];
                             $file->mime = '';
                             if (isset($SubmittedForm->mimetypes[$key])) {
                                 $file->mime = $SubmittedForm->mimetypes[$key];
                             }
                             $file->attributes = $attrs->get_attributes();
                             $data['files'][$key] = $file;
                         }
                     }
                 }
             }
         } else {
             PerchUtil::debug('Form ' . $SubmittedForm->id . ': File save location not set, files discarded.', 'error');
         }
     }
     // Fields
     if (PerchUtil::count($SubmittedForm->data)) {
         foreach ($SubmittedForm->data as $key => $value) {
             $attrs = $SubmittedForm->get_template_attributes($key);
             if ($attrs) {
                 $field = new stdClass();
                 $field->attributes = $attrs->get_attributes();
                 // skip submit fields
                 if (isset($field->attributes['type']) && $field->attributes['type'] == 'submit') {
                     // skip it.
                 } else {
                     // skip honeypot field
                     if (isset($field->attributes['antispam']) && $field->attributes['antispam'] == 'honeypot') {
                         // skip it
                     } else {
                         $field->value = $value;
                         $data['fields'][$attrs->id()] = $field;
                     }
                 }
             }
         }
     }
     if (!$spam && isset($opts->email) && $opts->email) {
         $this->_send_email($opts, $data);
     }
     if (isset($opts->store) && $opts->store) {
         $json = PerchUtil::json_safe_encode($data);
         $record = array();
         $record['responseJSON'] = $json;
         $record['formID'] = $this->id();
         $record['responseIP'] = $_SERVER['REMOTE_ADDR'];
         if ($spam) {
             $record['responseSpam'] = '1';
         }
         $spam_data = array();
         $spam_data['fields'] = $antispam;
         $spam_data['environment'] = $environment;
         $record['responseSpamData'] = PerchUtil::json_safe_encode($spam_data);
         $Responses = new PerchForms_Responses($this->api);
         $Response = $Responses->create($record);
     }
     if ($spam || !isset($opts->store) || !$opts->store) {
         // not storing, so drop files
         if (PerchUtil::count($data['files'])) {
             foreach ($data['files'] as $file) {
                 if (file_exists($file->path)) {
                     @unlink($file->path);
                 }
             }
         }
     }
     // Redirect?
     if (isset($opts->successURL) && $opts->successURL) {
         PerchUtil::redirect(trim($opts->successURL));
     }
 }
Exemplo n.º 3
0
function perch_members_check_page_access()
{
    $Session = PerchMembers_Session::fetch();
    if ($Session->logged_in) {
        $user_tags = $Session->get_tags();
    } else {
        $user_tags = array();
    }
    if (!is_array($user_tags)) {
        $user_tags = array();
    }
    $Page = PerchSystem::get_page_object();
    if (!$Page) {
        $Pages = new PerchContent_Pages();
        $Perch = Perch::fetch();
        $Page = $Pages->find_by_path($Perch->get_page());
        if ($Page instanceof PerchContent_Page) {
            PerchSystem::set_page_object($Page);
        }
    }
    if ($Page) {
        $page_tags = $Page->access_tags();
        if (!is_array($page_tags)) {
            $page_tags = array();
        }
        if (PerchUtil::count($page_tags)) {
            $intersection = array_intersect($user_tags, $page_tags);
            if (PerchUtil::count($intersection) === 0) {
                // no access!
                $API = new PerchAPI(1.0, 'perch_members');
                $Settings = $API->get('Settings');
                $redirect_url = $Settings->get('perch_members_login_page')->val();
                if ($redirect_url) {
                    $redirect_url = str_replace('{returnURL}', $Perch->get_page(), $redirect_url);
                    PerchUtil::redirect($redirect_url);
                } else {
                    die('Access denied.');
                }
            }
        }
    }
}
Exemplo n.º 4
0
function perch_pages_navigation_text($return = false)
{
    $attr_vars = PerchSystem::get_attr_vars();
    if (isset($attr_vars['pageNavText'])) {
        if ($return) {
            return $attr_vars['pageNavText'];
        }
        echo PerchUtil::html($attr_vars['pageNavText']);
        return;
    }
    $Page = PerchSystem::get_page_object();
    if (!$Page) {
        $Pages = new PerchContent_Pages();
        $Perch = Perch::fetch();
        $Page = $Pages->find_by_path($Perch->get_page());
        if ($Page instanceof PerchContent_Page) {
            PerchSystem::set_page_object($Page);
        }
    }
    $r = '';
    if (is_object($Page)) {
        $r = $Page->pageNavText();
    }
    if ($return) {
        return $r;
    }
    echo $r;
}