function perch_forms_form_handler($SubmittedForm) { if ($SubmittedForm->validate()) { $API = new PerchAPI(1.0, 'perch_forms'); $Forms = new PerchForms_Forms($API); $formKey = $SubmittedForm->id; $Form = $Forms->find_by_key($formKey); if (!is_object($Form)) { $data = array(); $data['formKey'] = $formKey; $data['formTemplate'] = $SubmittedForm->templatePath; $data['formOptions'] = PerchUtil::json_safe_encode(array('store' => true)); $attrs = $SubmittedForm->get_form_attributes(); if ($attrs->label()) { $data['formTitle'] = $attrs->label(); } else { $data['formTitle'] = PerchUtil::filename($formKey, false); } $Form = $Forms->create($data); } if (is_object($Form)) { $Form->process_response($SubmittedForm); } } $Perch = Perch::fetch(); PerchUtil::debug($Perch->get_form_errors($SubmittedForm->formID)); }
public static function get_search_sql($key) { $db = PerchDB::fetch(); $encoded_key = str_replace('"', '', PerchUtil::json_safe_encode($key)); $opts = func_get_arg(1); $sql = ' \'' . __CLASS__ . '\' AS source, MATCH(ci.itemSearch) AGAINST(' . $db->pdb($key) . ') AS score, r.regionPage AS col1, ci.itemSearch AS col2, ci.itemJSON AS col3, r.regionOptions AS col4, p.pageNavText AS col5, p.pageTitle AS col6, regionTemplate AS col7, r.regionKey AS col8 FROM ' . PERCH_DB_PREFIX . 'content_regions r, ' . PERCH_DB_PREFIX . 'content_items ci, ' . PERCH_DB_PREFIX . 'pages p WHERE r.regionID=ci.regionID AND r.regionRev=ci.itemRev AND r.pageID=p.pageID AND r.regionPage!=\'*\' AND r.regionSearchable=1 AND (MATCH(ci.itemSearch) AGAINST(' . $db->pdb($key) . ') OR MATCH(ci.itemSearch) AGAINST(' . $db->pdb($encoded_key) . ') ) AND r.regionPage LIKE ' . $db->pdb($opts['from-path'] . '%') . ' '; return $sql; }
/** * Insert a new log into the database, filtering sensitive information * and encoding data for storage. * * @param array $data * @return JwActivityLog_Action */ public function create($data) { // Meta data $data['actionDateTime'] = date("Y-m-d H:i:s"); $data['resourceUrl'] = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']; // Remove sensitive information if (isset($data['userAccountData']['userPassword'])) { unset($data['userAccountData']['userPassword']); } if (isset($data['userAccountData']['userHash'])) { unset($data['userAccountData']['userHash']); } // Encode for storage $data['userAccountData'] = PerchUtil::json_safe_encode($data['userAccountData']); return parent::create($data); }
public function update_profile($SubmittedForm) { $data = $SubmittedForm->data; $out = array(); $properties = PerchUtil::json_safe_decode($this->memberProperties(), true); foreach ($data as $key => $val) { if (array_key_exists($key, $this->field_aliases)) { $out[$this->field_aliases[$key]] = $val; $key = $this->field_aliases[$key]; } if (!in_array($key, $this->static_fields)) { $properties[$key] = $val; } } if (isset($out['memberEmail'])) { if (!$this->check_email_unique($out['memberEmail'])) { unset($out['memberEmail']); } } $out['memberProperties'] = PerchUtil::json_safe_encode($properties); $this->update($out); }
public function register_with_form($SubmittedForm) { $key = $SubmittedForm->id . (isset($SubmittedForm->form_attributes['type']) ? '.' . $SubmittedForm->form_attributes['type'] : ''); $Forms = new PerchMembers_Forms($this->api); $Form = $Forms->find_or_create($key); $do_login = false; if (is_object($Form)) { $form_settings = PerchUtil::json_safe_decode($Form->formSettings(), true); $member = array('memberAuthType' => 'native', 'memberEmail' => '', 'memberPassword' => '', 'memberStatus' => 'pending', 'memberCreated' => date('Y-m-d H:i:s')); $data = $SubmittedForm->data; $properties = array(); foreach ($data as $key => $val) { if (array_key_exists($key, $this->field_aliases)) { $member[$this->field_aliases[$key]] = $val; $key = $this->field_aliases[$key]; } if (!in_array($key, $this->static_fields)) { $properties[$key] = $val; } } $member['memberProperties'] = PerchUtil::json_safe_encode($properties); // Password $clear_pwd = $member['memberPassword']; if (defined('PERCH_NONPORTABLE_HASHES') && PERCH_NONPORTABLE_HASHES) { $portable_hashes = false; } else { $portable_hashes = true; } $Hasher = new PasswordHash(8, $portable_hashes); $member['memberPassword'] = $Hasher->HashPassword($clear_pwd); $Member = $this->create($member); $member = array('memberAuthID' => $Member->memberID()); if (isset($form_settings['moderate']) && $form_settings['moderate'] == '1') { if (isset($form_settings['moderator_email'])) { $this->_email_moderator($form_settings['moderator_email'], $Member); } } else { $member['memberStatus'] = 'active'; $do_login = true; } $Member->update($member); if (isset($form_settings['default_tags']) && $form_settings['default_tags'] != '') { $tags = explode(',', $form_settings['default_tags']); if (PerchUtil::count($tags)) { foreach ($tags as $tagDisplay) { $expiry = false; if (strpos($tagDisplay, '|') > 0) { $parts = explode('|', $tagDisplay); $tagDisplay = $parts[0]; $expiry = $parts[1]; } $tagDisplay = trim($tagDisplay); $tag = PerchUtil::urlify($tagDisplay); $Member->add_tag($tag, $tagDisplay, $expiry); } } } if (is_object($Member) && $do_login) { $key = base64_encode('login:perch_members:login/login_form.html'); $data = array('email' => $Member->memberEmail(), 'password' => $clear_pwd, 'pos'); $files = array(); $Perch = Perch::fetch(); $Perch->dispatch_form($key, $data, $files); } if (is_object($Member) && $clear_pwd === '__auto__') { $Member->update(array('memberPassword' => null)); } } }
$assetID = $ids[0]; $Asset = $Assets->find($assetID); $Asset->reindex(); if (PerchUtil::count($ids)) { if (!PerchSession::is_set('resourceIDs')) { $logged_ids = array(); PerchSession::set('resourceIDs', $logged_ids); } else { $logged_ids = PerchSession::get('resourceIDs'); } foreach ($ids as $assetID) { if (!in_array($assetID, $logged_ids)) { $logged_ids[] = $assetID; } } PerchSession::set('resourceIDs', $logged_ids); } if ($is_image) { $result = $Assets->get_resize_profile($Asset->id(), $width, $height, $crop ? '1' : '0', false, $density); if ($result) { echo stripslashes(PerchUtil::json_safe_encode(array('filelink' => $result['web_path']))); } else { echo stripslashes(PerchUtil::json_safe_encode(array('filelink' => $Asset->web_path()))); } exit; } else { echo stripslashes(PerchUtil::json_safe_encode(array('filelink' => $Asset->web_path()))); exit; } } echo 'FAIL';
public function get_posted_content($Template, $Factory, $Item = false, $include_repeaters = true, $json_encode = true) { $data = array(); $prev = false; if ($Item) { $prev = $Item->to_array(); } $dynamic_fields = $this->receive_from_template_fields($Template, $prev, $Factory, $Item, true, false); $static_fields = array(); // fetch out static fields foreach ($Factory->static_fields as $field) { if (array_key_exists($field, $dynamic_fields)) { //($dynamic_fields[$field])) { if (is_array($dynamic_fields[$field])) { if (isset($dynamic_fields[$field]['_default'])) { $data[$field] = trim($dynamic_fields[$field]['_default']); } if (isset($dynamic_fields[$field]['processed'])) { $data[$field] = trim($dynamic_fields[$field]['processed']); } } if (!isset($data[$field])) { $data[$field] = $dynamic_fields[$field]; } unset($dynamic_fields[$field]); } else { if (isset($_POST[$field])) { if (!is_array($_POST[$field])) { $data[$field] = trim(PerchUtil::safe_stripslashes($_POST[$field])); } else { $data[$field] = $_POST[$field]; } } } } if (!$json_encode) { return $dynamic_fields; } $data[$Factory->dynamic_fields_column] = PerchUtil::json_safe_encode($dynamic_fields); return $data; }
/** * Set region options * * @param string $options * @return void * @author Drew McLellan */ public function set_options($options) { $existing = $this->get_options(); if (!is_array($existing)) { $existing = array(); } $opts = array_merge($existing, $options); $data = array(); $data['regionOptions'] = PerchUtil::json_safe_encode($opts); $this->update($data); // clear cache $this->options = false; }
$Template = $API->get('Template'); $Template->set('blog/section.html', 'blog'); $Form->handle_empty_block_generation($Template); $tags = $Template->find_all_tags_and_repeaters(); $Form->require_field('sectionTitle', 'Required'); $Form->set_required_fields_from_template($Template, $details); if ($Form->submitted()) { $postvars = array('sectionTitle'); $data = $Form->receive($postvars); $data['blogID'] = $Blog->id(); $prev = false; if (isset($details['sectionDynamicFields'])) { $prev = PerchUtil::json_safe_decode($details['sectionDynamicFields'], true); } $dynamic_fields = $Form->receive_from_template_fields($Template, $prev, $Sections, $Section); $data['sectionDynamicFields'] = PerchUtil::json_safe_encode($dynamic_fields); if (!is_object($Section)) { $data['sectionSlug'] = PerchUtil::urlify($data['sectionTitle']); $Section = $Sections->create($data); PerchUtil::redirect($API->app_path() . '/sections/edit/?id=' . $Section->id() . '&created=1'); } $Section->update($data); if (is_object($Section)) { $message = $HTML->success_message('Your section has been successfully edited. Return to %ssection listing%s', '<a href="' . $API->app_path() . '/sections">', '</a>'); } else { $message = $HTML->failure_message('Sorry, that section could not be edited.'); } // clear the caches PerchBlog_Cache::expire_all(); $details = $Section->to_array(); }
if (!$CurrentUser->has_priv('content.pages.attributes')) { PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/'); } // Page attributes $API = new PerchAPI(1.0, 'perch_pages'); $Page->api($API); $Template = $API->get('Template'); $status = $Template->set('pages/attributes/' . $Page->pageAttributeTemplate(), 'pages'); if ($status == 404) { $Alert->set('notice', PerchLang::get('The page attribute template (%s) could not be found.', '<code>templates/pages/attributes/' . $Page->pageAttributeTemplate() . '</code>')); } $details = $Page->to_array(); $Form = $API->get('Form'); $Form->handle_empty_block_generation($Template); $req = array(); $req['pageTitle'] = "Required"; $req['pageNavText'] = "Required"; $Form->set_required($req); $Form->set_required_fields_from_template($Template, $details, array('pageTitle', 'pageNavText')); if ($Form->posted() && $Form->validate()) { $postvars = array('pageTitle', 'pageNavText'); $data = $Form->receive($postvars); $existing = PerchUtil::json_safe_decode($Page->pageAttributes(), true); $dynamic_fields = $Form->receive_from_template_fields($Template, $existing, $Pages, $Page); $data['pageAttributes'] = PerchUtil::json_safe_encode($dynamic_fields); $Page->update($data); // log resources $Page->log_resources(); $Alert->set('success', PerchLang::get('Successfully updated')); $details = $Page->to_array(); }
$view = 'grid'; $filters = array(); if (isset($_GET['filter']) && $_GET['filter'] == 'new') { $filters['new'] = true; } if (isset($_GET['app']) && $_GET['app'] != '') { $filters['app'] = $_GET['app']; } if (isset($_GET['type']) && $_GET['type'] != '') { $filters['type'] = $_GET['type']; } if (isset($_GET['bucket']) && $_GET['bucket'] != '') { $filters['bucket'] = $_GET['bucket']; } if (isset($_GET['date']) && $_GET['date'] != '') { $filters['date'] = $_GET['date']; } if (isset($_GET['q']) && $_GET['q'] != '') { $term = $_GET['q']; $assets = $Assets->search($term, $filters); } else { $assets = $Assets->get_filtered_for_admin($Paging, $filters); } $out = array(); if (PerchUtil::count($assets)) { foreach ($assets as $Asset) { $out[] = $Asset->to_api_array(); } } echo PerchUtil::json_safe_encode(array('assets' => $out));
private function write_to_lang_file($items) { if (!is_array($this->translations)) { $this->translations = array('lang' => $this->lang); } $out = array_merge($this->translations, $items); $tidy_json = true; $json = PerchUtil::json_safe_encode($out, $tidy_json); if (is_writable($this->lang_file)) { file_put_contents($this->lang_file, $json); } }
<?php include __DIR__ . '/../inc/pre_config.php'; include __DIR__ . '/../../config/config.php'; include PERCH_CORE . '/inc/loader.php'; $Perch = PerchAdmin::fetch(); include PERCH_CORE . '/inc/auth_light.php'; header('Content-Type: application/javascript'); echo "Perch.Privs.init(\n\t"; echo PerchUtil::json_safe_encode($CurrentUser->get_privs()); echo ');';
} $Template = $API->get('Template'); $Template->set('events/category.html', 'events'); $Form->handle_empty_block_generation($Template); $tags = $Template->find_all_tags_and_repeaters(); $Form->require_field('categoryTitle', 'Required'); $Form->set_required_fields_from_template($Template, $details); if ($Form->submitted()) { $postvars = array('categoryTitle'); $data = $Form->receive($postvars); $prev = false; if (isset($details['categoryDynamicFields'])) { $prev = PerchUtil::json_safe_decode($details['categoryDynamicFields'], true); } $dynamic_fields = $Form->receive_from_template_fields($Template, $prev, $Categories, $Category); $data['categoryDynamicFields'] = PerchUtil::json_safe_encode($dynamic_fields); if (!is_object($Category)) { $data['categorySlug'] = PerchUtil::urlify($data['categoryTitle']); $Category = $Categories->create($data); PerchUtil::redirect($API->app_path() . '/categories/edit/?id=' . $Category->id() . '&created=1'); } $Category->update($data); if (is_object($Category)) { $message = $HTML->success_message('Your category has been successfully edited. Return to %scategory listing%s', '<a href="' . $API->app_path() . '/categories">', '</a>'); } else { $message = $HTML->failure_message('Sorry, that category could not be edited.'); } // clear the caches PerchEvents_Cache::expire_all(); $details = $Category->to_array(); }
public function import_from_wp($wordpress_file, $format = "textile", $callback = false, $sectionID = 1) { $out = array(); // LOAD XML $xml = simplexml_load_file(PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . $this->api->app_id . '/import_data/' . $wordpress_file)); // AUTHORS $Authors = new PerchBlog_Authors($this->api); foreach ($xml->channel->children('wp', true) as $tag) { if ($tag->getName() == 'author') { $data = array(); $data['authorEmail'] = (string) $tag->author_email; $data['authorSlug'] = PerchUtil::urlify((string) $tag->author_display_name); $data['authorGivenName'] = (string) $tag->author_first_name; $data['authorFamilyName'] = (string) $tag->author_last_name; $data['authorImportRef'] = (string) $tag->author_login; if ($data['authorGivenName'] == '') { $data['authorGivenName'] = (string) $tag->author_login; } $Author = $Authors->find_or_create_by_email((string) $tag->author_email, $data); if ($Author) { $out[] = array('type' => 'success', 'messages' => array('Author ' . (string) $tag->author_display_name, 'Successfully imported')); } } } // POSTS $Posts = new PerchBlog_Posts($this->api); $Template = $this->api->get('Template'); $Template->set('blog/post.html', 'blog'); foreach ($xml->channel->item as $item) { $post = array(); $post['postTitle'] = (string) $item->title; $post['postTags'] = ''; $post['postLegacyURL'] = parse_url((string) $item->link, PHP_URL_PATH); $post_type = false; foreach ($item->children('wp', true) as $tag) { $tagName = $tag->getName(); switch ($tagName) { case 'post_id': $post['postImportID'] = (string) $tag; break; case 'post_type': $post_type = (string) $tag; break; case 'post_date_gmt': $val = strtotime((string) $tag); if ($val) { $post['postDateTime'] = date('Y-m-d H:i:s', $val); } break; case 'post_date': $val = strtotime((string) $tag); if ($val) { $post['postDateTime'] = date('Y-m-d H:i:s', $val); } break; case 'comment_status': $val = (string) $tag; if ($val == 'open') { $post['postAllowComments'] = '1'; } else { $post['postAllowComments'] = '0'; } break; case 'post_name': $post['postSlug'] = (string) $tag; break; case 'status': $val = (string) $tag; $post['postStatus'] = 'Draft'; if ($val == 'publish') { $post['postStatus'] = 'Published'; } break; } } // if it's not of type 'post', skip. if ($post_type != 'post') { continue; } // At this point, check we don't already have the post (as we know have the postImportID to identify it) if (isset($post['postImportID'])) { $Post = $Posts->find_by_importID($post['postImportID']); if (is_object($Post)) { $out[] = array('type' => 'success', 'messages' => array('Post ' . $Post->postTitle(), 'Already imported')); continue; } } foreach ($item->children('dc', true) as $tag) { $tagName = $tag->getName(); switch ($tagName) { case 'creator': $val = (string) $tag; $Author = $Authors->get_one_by('authorImportRef', $val); if (is_object($Author)) { $post['authorID'] = $Author->id(); } break; } } foreach ($item->children('content', true) as $tag) { $tagName = $tag->getName(); switch ($tagName) { case 'encoded': $raw = (string) $tag; if ($format == 'textile') { $html = PerchUtil::text_to_html($raw); $post['postDescRaw'] = $raw; $post['postDescHTML'] = $html; } else { $post['postDescRaw'] = $raw; $post['postDescHTML'] = $raw; } break; } } foreach ($item->children('excerpt', true) as $tag) { $tagName = $tag->getName(); switch ($tagName) { case 'encoded': $raw = (string) $tag; $html = PerchUtil::text_to_html($raw); $fields = array(); $fields['excerpt'] = array(); if ($format == 'textile') { $fields['excerpt']['raw'] = $raw; $fields['excerpt']['processed'] = $html; } else { $fields['excerpt']['raw'] = $html; $fields['excerpt']['processed'] = $html; } $post['postDynamicFields'] = PerchUtil::json_safe_encode($fields); break; } } // Callbacks if ($callback) { $post = call_user_func($callback, $post, $Template); } // Section $post['sectionID'] = $sectionID; // Create the post $Post = $Posts->create($post, $Template); if (is_object($Post)) { $out[] = array('type' => 'success', 'messages' => array('Post ' . $Post->postTitle(), 'Successfully imported')); // CATEGORIES AND TAGS $Categories = new PerchCategories_Categories(); $Tags = new PerchBlog_Tags($this->api); $postTags = array(); $cat_ids = array(); foreach ($item->category as $category) { $attributes = $category->attributes(); $slug = (string) $attributes['nicename']; $label = (string) $category; switch ((string) $attributes['domain']) { case 'post_tag': $Tag = $Tags->find_or_create($slug, $label); if (is_object($Tag)) { $postTags[] = $Tag->tagSlug(); $out[] = array('type' => 'success', 'messages' => array('Tag ' . $Tag->tagSlug(), 'Successfully imported')); } break; case 'category': PerchUtil::debug("Find or create {$slug}", 'notice'); $Category = $Categories->find_or_create('blog/' . $slug . '/', $label); if (is_object($Category)) { $cat_ids[] = $Category->id(); $out[] = array('type' => 'success', 'messages' => array('Category ' . $label, 'Successfully imported')); } break; } } if (PerchUtil::count($postTags)) { $post['postTags'] = implode(', ', $postTags); } if (PerchUtil::count($cat_ids)) { $fields['categories'] = $cat_ids; $post['postDynamicFields'] = PerchUtil::json_safe_encode($fields); } $Post->Template = $Template; $Post->update($post); $Post->index($Template); // COMMENTS $Comments = new PerchBlog_Comments($this->api); foreach ($item->children('wp', true) as $tag) { $tagName = $tag->getName(); if ($tagName == 'comment') { if ((string) $tag->comment_type == 'pingback') { continue; // this is a pingback, so skip it. } $html = PerchUtil::text_to_html((string) $tag->comment_content); $comment = array(); $comment['postID'] = $Post->id(); $comment['commentName'] = (string) $tag->comment_author; $comment['commentEmail'] = (string) $tag->comment_author_email; $comment['commentURL'] = (string) $tag->comment_author_url; $comment['commentIP'] = ip2long((string) $tag->comment_author_IP); $comment['commentDateTime'] = date('Y-m-d H:i:s', strtotime((string) $tag->comment_date_gmt)); $comment['commentHTML'] = $html; $comment['commentSpamData'] = ''; $comment['commentDynamicFields'] = ''; if ((string) $tag->comment_approved == '1') { $comment['commentStatus'] = 'LIVE'; $Comment = $Comments->create($comment); $out[] = array('type' => 'success', 'messages' => array('Comment from ' . $comment['commentName'], 'Successfully imported')); } } } $Post->update_comment_count(); } } return $out; }
$ThisForm = $Forms->find($formID); $details = $ThisForm->to_array(); $settings = $ThisForm->get_settings(); } else { $message = $HTML->failure_message('Sorry, that form could not be updated.'); } $Form->require_field('formTitle', 'Required'); if ($Form->submitted()) { $postvars = array('formTitle'); $data = $Form->receive($postvars); $settingvars = array('store', 'fileLocation', 'email', 'emailAddress', 'adminEmailMessage', 'adminEmailTemplate', 'adminEmailSubject', 'adminEmailFromName', 'adminEmailFromAddress', 'akismet', 'akismetAPIKey', 'successURL', 'responseEmailSubject', 'responseEmailMessage', 'formEmailFieldID', 'sendAutoResponse', 'autoresponseTemplate'); $settingdata = $Form->receive($settingvars); if (isset($settingdata['successURL']) && trim($settingdata['successURL']) == '') { unset($settingdata['successURL']); } $data['formOptions'] = PerchUtil::json_safe_encode($settingdata); $ThisForm->update($data); if (is_object($ThisForm)) { $message = $HTML->success_message('Your form has been successfully edited. Return to %sform listing%s', '<a href="' . $API->app_path() . '">', '</a>'); } else { $message = $HTML->failure_message('Sorry, that form could not be edited.'); } if (isset($settingdata['akismet']) && $settingdata['akismet'] == '1' && isset($settingdata['akismetAPIKey']) && $settingdata['akismetAPIKey'] != '') { if (!PerchForms_Akismet::verify_key($settingdata['akismetAPIKey'])) { $message .= $HTML->failure_message('Sorry, Akismet API key does not appear to be correct.'); } } $details = $ThisForm->to_array(); $settings = $ThisForm->get_settings(); } $filter = 'options';
if (PerchUtil::count($items)) { foreach ($items as $Item) { $Item->clear_resources(); $id = $Item->itemID(); $form_vars = array(); $file_paths = array(); $search_text = ' '; $form_vars['_id'] = $id; $postitems = $Form->find_items('perch_' . $id . '_'); $subprefix = ''; list($form_vars, $search_text) = PerchContent_Util::read_items_from_post($Item, $tags, $subprefix, $form_vars, $postitems, $Form, $search_text, $options, $Resources, false, $Template); if (isset($form_vars['_blocks'])) { $form_vars['_blocks'] = PerchUtil::array_sort($form_vars['_blocks'], '_block_index'); } $data = array(); $data['itemJSON'] = PerchUtil::json_safe_encode($form_vars); $data['itemSearch'] = $search_text; //PerchUtil::debug($form_vars, 'success'); $Item->update($data); $edited_items[] = $id; } } } // Sort based on region options $Region->sort_items(); // Publish (or not if draft) if (isset($_POST['save_as_draft'])) { $Alert->set('success', PerchLang::get('Draft successfully updated')); } else { $Region->publish(); $Alert->set('success', PerchLang::get('Content successfully updated'));
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); }
if ($Form->submitted()) { $postvars = ['addressTitle', 'addressBuilding', 'addressStreet', 'addressTown', 'addressRegion', 'addressCountry', 'addressPostcode', 'force']; $data = $Form->receive($postvars); // Force? $force = false; if (isset($data['force'])) { $force = true; unset($data['force']); } // Dynamic fields $previous_values = false; if (isset($details['addressDynamicFields'])) { $previous_values = PerchUtil::json_safe_decode($details['addressDynamicFields'], true); } $dynamic_fields = $Form->receive_from_template_fields($Template, $previous_values, $Addresses, $Address); $data['addressDynamicFields'] = PerchUtil::json_safe_encode($dynamic_fields); // Save if (is_object($Address)) { $requeue = $Address->shouldQueue($data); if (!$force && $requeue) { $Tasks->add('address.geocode', $Address->id()); $data['addressLatitude'] = null; $data['addressLongitude'] = null; } $result = $Address->update($data, $force); $details = $Address->to_array(); $Address->index($Template); } else { $new_address = $Addresses->create($data); if ($new_address) { if ($force) {
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); }
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)); } }
/** * Add a new key to the regions table * * @param string $key * @param array $opts * @return void * @author Drew McLellan */ private function _register_new_key($key, $opts = array()) { if (!isset($this->registered[$key])) { $Perch = Perch::fetch(); $page = $Perch->get_page(); $data = array(); $data['regionKey'] = $key; $data['regionPage'] = $page; $data['regionHTML'] = '<!-- Undefined content: ' . PerchUtil::html($key) . ' -->'; $data['regionOptions'] = ''; if (is_array($opts) && count($opts)) { if ($opts['page']) { $data['regionPage'] = $opts['page']; // Creating for a different page, so make sure old pageID cache is cleared. $this->pageID = false; } if ($opts['shared']) { $data['regionPage'] = '*'; } if ($opts['template']) { $data['regionTemplate'] = $opts['template']; $data['regionNew'] = 0; } if ($opts['multiple']) { $data['regionMultiple'] = 1; } else { $data['regionMultiple'] = 0; } if ($opts['searchable']) { $data['regionSearchable'] = 1; } else { $data['regionSearchable'] = 0; } if ($opts['roles']) { $data['regionEditRoles'] = $opts['roles']; } $regionOptions = array(); if ($opts['sort']) { $regionOptions['sortField'] = $opts['sort']; } if ($opts['sort-order']) { $regionOptions['sortOrder'] = $opts['sort-order']; } if ($opts['edit-mode']) { $regionOptions['edit_mode'] = $opts['edit-mode']; } if ($opts['search-url']) { $regionOptions['searchURL'] = $opts['search-url']; } if ($opts['add-to-top']) { $regionOptions['addToTop'] = $opts['add-to-top']; } if ($opts['limit']) { $regionOptions['limit'] = $opts['limit']; } if ($opts['title-delimiter']) { $regionOptions['title_delimit'] = $opts['title-delimiter']; } if ($opts['columns']) { $regionOptions['column_ids'] = $opts['columns']; } $data['regionOptions'] = PerchUtil::json_safe_encode($regionOptions); } $data['pageID'] = $this->_find_or_create_page($data['regionPage']); if ($data['pageID']) { $db = PerchDB::fetch(); $cols = array(); $vals = array(); foreach ($data as $key => $value) { $cols[] = $key; $vals[] = $db->pdb($value) . ' AS ' . $key; } $sql = 'INSERT INTO ' . $this->table . '(' . implode(',', $cols) . ') SELECT ' . implode(',', $vals) . ' FROM (SELECT 1) AS dtable WHERE ( SELECT COUNT(*) FROM ' . $this->table . ' WHERE regionKey=' . $db->pdb($data['regionKey']) . ' AND (regionPage=' . $db->pdb($data['regionPage']) . ' OR regionPage=' . $db->pdb('*') . ') )=0 LIMIT 1'; $db->execute($sql); $this->registered[$key] = true; $this->new_keys_registered = true; } } }
<?php include realpath(__DIR__ . '/../../..') . '/inc/pre_config.php'; include realpath(__DIR__ . '/../../../..') . '/config/config.php'; include PERCH_CORE . '/inc/loader.php'; $Perch = PerchAdmin::fetch(); include PERCH_CORE . '/inc/auth_light.php'; include __DIR__ . '/../PerchAssets_Tags.class.php'; include __DIR__ . '/../PerchAssets_Tag.class.php'; $Tags = new PerchAssets_Tags(); $results = $Tags->async_search($_GET['term']); echo PerchUtil::json_safe_encode($results);
public function import_legacy_categories() { $sql = 'SELECT c.categoryCoreID AS newID FROM ' . PERCH_DB_PREFIX . 'blog_posts_to_categories p2c, ' . PERCH_DB_PREFIX . 'blog_categories c WHERE p2c.categoryID=c.categoryID AND p2c.postID=' . $this->db->pdb((int) $this->id()); $catIDs = $this->db->get_rows_flat($sql); if (PerchUtil::count($catIDs)) { $json = PerchUtil::json_safe_decode($this->postDynamicFields(), true); if ($json) { $json['categories'] = $catIDs; } else { $json = array('categories' => $catIDs); } $this->update(array('postDynamicFields' => PerchUtil::json_safe_encode($json)), false, false); } }
$Form->handle_empty_block_generation($Template); $tags = $Template->find_all_tags_and_repeaters(); $Form->set_required_fields_from_template($Template, $details); if ($Form->submitted()) { $postvars = array('perch_commentName', 'perch_commentEmail', 'perch_commentHTML', 'commentStatus', 'perch_commentDateTime', 'perch_commentURL'); $data = $Form->receive($postvars); if (PerchUtil::count($data)) { foreach ($data as $key => $val) { if (strpos($key, 'perch_') === 0) { $data[str_replace('perch_', '', $key)] = $val; unset($data[$key]); } } } $dynamic_fields = $Form->receive_from_template_fields($Template, $details, $Comments, $Comment); $data['commentDynamicFields'] = PerchUtil::json_safe_encode($dynamic_fields); if ($Comment->commentStatus() != $data['commentStatus']) { // status has changed // was the comment live? If so update the post's comment count. if ($Comment->commentStatus() == 'LIVE') { $Post = $Posts->find($Comment->postID()); if ($Post) { $Post->update_comment_count(); } } $Comment->set_status($data['commentStatus']); } PerchUtil::debug($data); $Comment->update($data); if (is_object($Comment)) { $message = $HTML->success_message('The comment has been successfully edited.');
} $Template = $API->get('Template'); $Template->set('blog/blog.html', 'blog'); $Form->handle_empty_block_generation($Template); $tags = $Template->find_all_tags_and_repeaters(); $Form->require_field('blogTitle', 'Required'); $Form->set_required_fields_from_template($Template, $details); if ($Form->submitted()) { $postvars = array('blogTitle', 'setSlug', 'postTemplate'); $data = $Form->receive($postvars); $prev = false; if (isset($details['blogDynamicFields'])) { $prev = PerchUtil::json_safe_decode($details['blogDynamicFields'], true); } $dynamic_fields = $Form->receive_from_template_fields($Template, $prev, $Blogs, $Blog); $data['blogDynamicFields'] = PerchUtil::json_safe_encode($dynamic_fields); if (!is_object($Blog)) { $data['blogSlug'] = PerchUtil::urlify($data['blogTitle']); $Blog = $Blogs->create($data); PerchUtil::redirect($API->app_path() . '/blogs/edit/?id=' . $Blog->id() . '&created=1'); } $Blog->update($data); if (is_object($Blog)) { $message = $HTML->success_message('Your blog has been successfully edited. Return to %sblog listing%s', '<a href="' . $API->app_path() . '/blogs">', '</a>'); } else { $message = $HTML->failure_message('Sorry, that blog could not be edited.'); } // clear the caches PerchBlog_Cache::expire_all(); $details = $Blog->to_array(); }
$message = false; $HTML = $API->get('HTML'); if (isset($_GET['id']) && $_GET['id'] != '') { $formID = (int) $_GET['id']; $MemberForm = $MemberForms->find($formID); $details = $MemberForm->to_array(); $settings = PerchUtil::json_safe_decode($MemberForm->formSettings(), true); $heading1 = 'Editing a Member Form'; } $heading2 = 'Form details'; $Form = $API->get('Form'); $Form->require_field('formTitle', 'Required'); if ($Form->submitted()) { $postvars = array('formTitle'); $data = $Form->receive($postvars); $result = false; if (is_object($MemberForm)) { $postvars = array('moderate', 'moderator_email', 'default_tags'); $settings_data = $Form->receive($postvars); if (!isset($settings_data['moderate'])) { $settings_data['moderate'] = '0'; } $data['formSettings'] = PerchUtil::json_safe_encode($settings_data); $result = $MemberForm->update($data); } $message = $HTML->success_message('The form has been successfully updated. Return to %sform listing%s', '<a href="' . $API->app_path() . '/forms/">', '</a>'); if (is_object($MemberForm)) { $details = $MemberForm->to_array(); $settings = PerchUtil::json_safe_decode($MemberForm->formSettings(), true); } }