/**
  * get campaign data from the API and store it in our table
  */
 public function populate($api_key, $list_id, $echo_feedback = false)
 {
     $MailChimp = new MailChimp($api_key);
     if ($echo_feedback) {
         $API = new PerchAPI(1.0, 'perch_mailchimp');
         $Lang = $API->get('Lang');
     }
     $opts = array('apikey' => $api_key, 'filters' => array('list_id' => $list_id, 'status' => 'sent'));
     $result = $MailChimp->call('campaigns/list', $opts);
     if ($result && isset($result['total']) && $result['total'] > 0) {
         foreach ($result['data'] as $item) {
             $campaignID = $item['id'];
             //get the content
             $content_opts = array('apikey' => $api_key, 'cid' => $campaignID);
             $content = $MailChimp->call('campaigns/content', $content_opts);
             if (isset($content['html'])) {
                 $campaignHTML = $content['html'];
             }
             if (isset($content['text'])) {
                 $campaignText = $content['text'];
             }
             // array for insertion
             $campaign = array('campaignCID' => $campaignID, 'campaignWebID' => $item['web_id'], 'campaignTitle' => $item['title'], 'campaignCreateTime' => $item['create_time'], 'campaignSendTime' => $item['send_time'], 'campaignSent' => $item['emails_sent'], 'campaignSubject' => $item['subject'], 'campaignArchiveURL' => $item['archive_url'], 'campaignHTML' => $campaignHTML, 'campaignText' => $campaignText, 'campaignSlug' => PerchUtil::urlify(date('d M Y', strtotime($item['create_time'])) . ' ' . $item['subject']));
             //insert into our table
             $this->db->insert($this->table, $campaign);
             if ($echo_feedback) {
                 echo '<li class="icon success">';
                 echo $Lang->get('Importing campaign %s (%s)', $item['title'], $item['create_time']);
                 echo '</li>';
                 flush();
             }
         }
     }
 }
 public function update($data)
 {
     $PerchEvents_Events = new PerchEvents_Events();
     if (isset($data['eventDescRaw'])) {
         $data['eventDescHTML'] = $PerchEvents_Events->text_to_html($data['eventDescRaw']);
     } else {
         $data['eventDescHTML'] = false;
     }
     if (isset($data['eventTitle'])) {
         $data['eventSlug'] = PerchUtil::urlify(date('Y m d', strtotime($data['eventDateTime'])) . ' ' . $data['eventTitle']);
     }
     if (isset($data['cat_ids'])) {
         $catIDs = $data['cat_ids'];
         unset($data['cat_ids']);
     } else {
         $catIDs = false;
     }
     // Update the event itself
     parent::update($data);
     // Delete existing categories
     $this->db->delete(PERCH_DB_PREFIX . 'events_to_categories', $this->pk, $this->id());
     // Add new categories
     if (is_array($catIDs)) {
         for ($i = 0; $i < sizeOf($catIDs); $i++) {
             $tmp = array();
             $tmp['eventID'] = $this->id();
             $tmp['categoryID'] = $catIDs[$i];
             $this->db->insert(PERCH_DB_PREFIX . 'events_to_categories', $tmp);
         }
     }
     return true;
 }
 /**
  * Parse a string of entered tags (e.g. "this, that, the other") into an array of tags
  * @param  [type] $str [description]
  * @return [type]      [description]
  */
 public function parse_string($str)
 {
     $tags = explode(',', $str);
     $out = array();
     if (PerchUtil::count($tags)) {
         foreach ($tags as $tag) {
             $out[] = array('tag' => PerchUtil::urlify(trim($tag)), 'tagDisplay' => trim($tag));
         }
     }
     return $out;
 }
 public function parse_string_to_ids($tag_string)
 {
     $tags = $this->_tag_parse($tag_string);
     PerchUtil::debug($tags);
     $ids = array();
     if (PerchUtil::count($tags)) {
         foreach ($tags as $tag) {
             $Tag = $this->find_or_create(PerchUtil::urlify($tag), $tag);
             if ($Tag) {
                 $ids[] = $Tag->id();
             }
         }
     }
     return $ids;
 }
 /**
  * Find an author based on their email address. If not found, create a new one.
  * @param  Object $User Instance of a user object - usually CurrentUser.
  * @return Object       Instance of an author object
  */
 public function find_or_create($User)
 {
     $sql = 'SELECT * FROM ' . $this->table . ' WHERE authorEmail=' . $this->db->pdb($User->userEmail()) . ' LIMIT 1';
     $row = $this->db->get_row($sql);
     if (PerchUtil::count($row)) {
         return $this->return_instance($row);
     }
     // Author wasn't found, so create a new one and return it. (It? Him or her.)
     $data = array();
     $data['authorEmail'] = $User->userEmail();
     $data['authorGivenName'] = $User->userGivenName();
     $data['authorFamilyName'] = $User->userFamilyName();
     $data['authorSlug'] = PerchUtil::urlify($data['authorGivenName'] . ' ' . $data['authorFamilyName']);
     $Author = $this->create($data);
     return $Author;
 }
예제 #6
0
        $campaign_id = $_POST['data']['id'];
        if ($status == 'sent') {
            $log = array('logEvent' => 'Campaign sent: ' . $campaign_id, 'logDate' => date('Y-m-d H:i:s'));
            $api_key = $Settings->get('perch_mailchimp_api_key')->settingValue();
            $list_id = $Settings->get('perch_mailchimp_list_id')->settingValue();
            $MailChimp = new MailChimp($api_key);
            $opts = array('apikey' => $api_key, 'filters' => array('campaign_id' => $campaign_id));
            $new_campaign = $MailChimp->call('campaigns/list', $opts);
            if ($new_campaign) {
                //get the content
                $content_opts = array('apikey' => $api_key, 'cid' => $campaign_id);
                $content = $MailChimp->call('campaigns/content', $content_opts);
                if (isset($content['html'])) {
                    $campaignHTML = $content['html'];
                }
                if (isset($content['text'])) {
                    $campaignText = $content['text'];
                }
                $campaign = array('campaignCID' => $campaign_id, 'campaignWebID' => $new_campaign['data'][0]['web_id'], 'campaignTitle' => $new_campaign['data'][0]['title'], 'campaignCreateTime' => $new_campaign['data'][0]['create_time'], 'campaignSendTime' => $new_campaign['data'][0]['send_time'], 'campaignSent' => $new_campaign['data'][0]['emails_sent'], 'campaignSubject' => $new_campaign['data'][0]['subject'], 'campaignArchiveURL' => $new_campaign['data'][0]['archive_url'], 'campaignHTML' => $campaignHTML, 'campaignText' => $campaignText, 'campaignSlug' => PerchUtil::urlify(date('d M Y', strtotime($new_campaign['data'][0]['create_time'])) . ' ' . $new_campaign['data'][0]['subject']));
                //insert into our table
                if ($db->insert(PERCH_DB_PREFIX . 'mailchimp_campaigns', $campaign)) {
                    $log['logType'] = 'success';
                } else {
                    $log['logType'] = 'failure';
                }
                //add to log
                $db->insert(PERCH_DB_PREFIX . 'mailchimp_log', $log);
            }
        }
    }
}
 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));
         }
     }
 }
 private function map_fields($campaign)
 {
     return ['campaignMailChimpID' => $campaign['id'], 'campaignSendTime' => $campaign['send_time'] ? date('Y-m-d H:i:s', strtotime($campaign['send_time'])) : null, 'campaignArchiveURL' => $campaign['archive_url'], 'campaignStatus' => $campaign['status'], 'campaignEmailsSent' => $campaign['emails_sent'], 'campaignSubject' => $campaign['settings']['subject_line'], 'campaignTitle' => $campaign['settings']['title'] ? $campaign['settings']['title'] : $campaign['settings']['subject_line'], 'campaignSlug' => PerchUtil::urlify($campaign['settings']['subject_line']), 'campaignCreated' => $campaign['create_time'] ? date('Y-m-d H:i:s', strtotime($campaign['create_time'])) : null];
 }
 /**
  * overwriting create to add URL slug creation.
  * @see PerchFactory::create()
  * @param array $data
  * @return album object
  */
 public function create($data)
 {
     if (isset($data['imageAlt'])) {
         $data['imageSlug'] = PerchUtil::urlify($data['imageAlt']);
         $data['imageSlug'] = $this->check_slug_unique($data['imageSlug']);
     }
     if (!isset($data['imageOrder']) && isset($data['albumID'])) {
         $sql = 'SELECT COUNT(*) FROM ' . $this->table . ' WHERE albumID=' . $this->db->pdb($data['albumID']);
         $count = $this->db->get_value($sql);
         $data['imageOrder'] = $count + 1;
     }
     if ($imageID = $this->db->insert($this->table, $data)) {
         return $this->find($imageID);
     }
     return false;
 }
예제 #10
0
$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 (isset($_GET['created']) && !$message) {
    $message = $HTML->success_message('Your section has been successfully created. Return to %ssection listing%s', '<a href="' . $API->app_path() . '/sections">', '</a>');
 /**
  * takes the event data and inserts it as a new row in the database.
  */
 public function create($data)
 {
     if (isset($data['eventDescRaw'])) {
         $data['eventDescHTML'] = $this->text_to_html($data['eventDescRaw']);
     } else {
         $data['eventDescHTML'] = false;
     }
     if (isset($data['eventTitle'])) {
         $data['eventSlug'] = PerchUtil::urlify(date('Y m d', strtotime($data['eventDateTime'])) . ' ' . $data['eventTitle']);
     }
     if (isset($data['cat_ids']) && is_array($data['cat_ids'])) {
         $cat_ids = $data['cat_ids'];
     } else {
         $cat_ids = false;
     }
     unset($data['cat_ids']);
     $eventID = $this->db->insert($this->table, $data);
     if ($eventID) {
         if (is_array($cat_ids)) {
             for ($i = 0; $i < sizeOf($cat_ids); $i++) {
                 $tmp = array();
                 $tmp['eventID'] = $eventID;
                 $tmp['categoryID'] = $cat_ids[$i];
                 $this->db->insert(PERCH_DB_PREFIX . 'events_to_categories', $tmp);
             }
         }
         return $this->find($eventID);
     }
     return false;
 }
예제 #12
0
} else {
    $groupID = false;
    $NavGroup = false;
}
$Form = new PerchForm('editpage');
$req = array();
$req['groupTitle'] = "Required";
$Form->set_required($req);
if ($Form->posted() && $Form->validate()) {
    $postvars = array('groupTitle');
    $data = $Form->receive($postvars);
    if (is_object($NavGroup)) {
        $NavGroup->update($data);
        $Alert->set('success', PerchLang::get('Your navigation group has been successfully updated.'));
    } else {
        $data['groupSlug'] = PerchUtil::urlify($data['groupTitle']);
        $NavGroup = $NavGroups->create($data);
        if (is_object($NavGroup)) {
            PerchUtil::redirect(PERCH_LOGINPATH . '/core/apps/content/navigation/edit/?id=' . $NavGroup->id() . '&created=1');
        } else {
            $Alert->set('failure', PerchLang::get('There was a problem creating the navigation group.'));
        }
    }
}
if (isset($_GET['created'])) {
    $Alert->set('success', PerchLang::get('Your navigation group has been successfully created.'));
}
if (is_object($NavGroup)) {
    $details = $NavGroup->to_array();
} else {
    $details = array();
예제 #13
0
 public static function check_title_exists($listingTitle, $listingID = false)
 {
     $API = new PerchAPI(1.0, 'listing');
     $db = $API->get('DB');
     $sql = 'SELECT COUNT(*) FROM ' . PERCH_DB_PREFIX . 'listings WHERE listingSlug=' . $db->pdb(PerchUtil::urlify($listingTitle)) . ' AND listingID!=' . $db->pdb($listingID);
     $count = $db->get_count($sql);
     PerchUtil::debug($sql);
     if ($count) {
         return false;
     }
     return true;
 }
 public function get_raw($post = false, $Item = false)
 {
     $value = false;
     if ($post === false) {
         $post = $_POST;
     }
     $id = $this->Tag->id();
     if (isset($post[$id])) {
         $this->raw_item = trim(PerchUtil::safe_stripslashes($post[$id]));
         $value = $this->raw_item;
     }
     // Indelible?
     if ($this->Tag->indelible()) {
         // if it's indelible, just return the previous value.
         $prev_value = false;
         if (is_object($Item)) {
             $json = PerchUtil::json_safe_decode($Item->itemJSON(), true);
             if (PerchUtil::count($json) && isset($json[$this->Tag->id()])) {
                 $prev_value = $json[$this->Tag->id()];
             }
         } elseif (is_array($Item)) {
             $json = $Item;
             if (PerchUtil::count($json) && isset($json[$this->Tag->id()])) {
                 $prev_value = $json[$this->Tag->id()];
             }
         }
         if ($prev_value) {
             return $prev_value;
         }
     }
     // Editable + value?
     if ($this->Tag->editable() && $value) {
         // return the user's value
         return $value;
     }
     if ($this->Tag->for()) {
         $parts = $this->break_for_string($this->Tag->for());
         if (PerchUtil::count($parts)) {
             $str = array();
             foreach ($parts as $part) {
                 if (isset($post[$part])) {
                     $str[] = trim(PerchUtil::safe_stripslashes($post[$part]));
                 }
             }
             return PerchUtil::urlify(implode(' ', $str));
         }
         if (isset($post[$this->Tag->for()])) {
             return PerchUtil::urlify(trim(PerchUtil::safe_stripslashes($post[$this->Tag->for()])));
         }
     }
     return '';
 }
예제 #15
0
<?php

include '../runtime/runtime.php';
$s = filter_input(INPUT_GET, 's', FILTER_SANITIZE_STRING);
if ($s) {
    echo PerchUtil::urlify($s);
}
예제 #16
0
 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;
 }
 /**
  * Create a new page, either from an existing page, or just as a nav link
  *
  * @param string $data
  * @return void
  * @author Drew McLellan
  */
 public function create_without_file($data)
 {
     $create_folder = false;
     if (isset($data['create_folder'])) {
         $create_folder = $data['create_folder'];
         unset($data['create_folder']);
     }
     $link_only = false;
     // is this a URL or just local file?
     if (isset($data['file_name'])) {
         $url = parse_url($data['file_name']);
         if ($url && is_array($url) && isset($url['scheme']) && $url['scheme'] != '') {
             $link_only = true;
             $url = $data['file_name'];
             unset($data['file_name']);
         }
     }
     // Find the parent page
     $ParentPage = $this->find($data['pageParentID']);
     if ($link_only) {
         $data['pagePath'] = $url;
         $data['pageNavOnly'] = '1';
         // Insert into the DB
         $Page = $this->create($data);
         // Set its position in the tree
         if (is_object($Page)) {
             if (is_object($ParentPage)) {
                 $Page->update_tree_position($ParentPage->id());
             }
             return $Page;
         }
     } else {
         // use the file name given (if stated) or create from the title. Sans extension.
         if (isset($data['file_name'])) {
             $file_name = $data['file_name'];
             unset($data['file_name']);
         } else {
             $file_name = PerchUtil::urlify($data['pageTitle']);
         }
         $this->find_site_path();
         // Find the parent page
         $ParentPage = $this->find($data['pageParentID']);
         if (is_object($ParentPage)) {
             if (PERCH_RUNWAY) {
                 $pageSection = $ParentPage->pageSortPath();
             } else {
                 if ($ParentPage->pageSubpagePath()) {
                     $pageSection = $ParentPage->pageSubpagePath();
                 } else {
                     $pageSection = PerchUtil::strip_file_name($ParentPage->pagePath());
                 }
             }
             // Copy subpage info
             $data['pageSubpageRoles'] = $ParentPage->pageSubpageRoles();
             $data['pageSubpageTemplates'] = $ParentPage->pageSubpageTemplates();
             $parentPageID = $ParentPage->id();
             $data['pageDepth'] = $ParentPage->pageDepth() + 1;
         } else {
             $pageSection = '/';
             $parentPageID = 0;
             $data['pageParentID'] = '0';
             $data['pageDepth'] = '1';
         }
         if (!isset($data['templateID']) || $data['templateID'] == '') {
             $data['templateID'] = 0;
         }
         $dir = PERCH_SITEPATH . str_replace('/', DIRECTORY_SEPARATOR, $pageSection);
         // Get the new file path
         $new_url = $pageSection . '/' . str_replace($dir, '', $file_name);
         $r = str_replace(DIRECTORY_SEPARATOR, '/', $new_url);
         while (strpos($r, '//') !== false) {
             $r = str_replace('//', '/', $r);
         }
         $data['pagePath'] = $r;
         // Insert into the DB
         $Page = $this->create($data);
         // Set its position in the tree
         if (is_object($Page)) {
             $Page->update_tree_position($parentPageID);
             if (PERCH_RUNWAY) {
                 // Grab the template this page uses
                 $Templates = new PerchContent_PageTemplates();
                 $Template = $Templates->find($Page->templateID());
                 if (is_object($Template)) {
                     // Add to nav groups
                     if ($Template->templateNavGroups() != '') {
                         $Page->update_navgroups(explode(',', $Template->templateNavGroups()));
                     }
                     // Copy page options?
                     if ($Template->optionsPageID() != '0') {
                         $CopyPage = $this->find($Template->optionsPageID());
                         if (is_object($CopyPage)) {
                             $sql = 'INSERT INTO ' . PERCH_DB_PREFIX . 'content_regions (
                                     pageID,
                                     regionKey,
                                     regionPage,
                                     regionHTML,
                                     regionNew,
                                     regionOrder,
                                     regionTemplate,
                                     regionMultiple,
                                     regionOptions,
                                     regionSearchable,
                                     regionEditRoles
                                 )
                                 SELECT
                                     ' . $this->db->pdb($Page->id()) . ' AS pageID,
                                     regionKey,
                                     ' . $this->db->pdb($r) . ' AS regionPage,
                                     "<!-- Undefined content -->" AS regionHTML,
                                     regionNew,
                                     regionOrder,
                                     regionTemplate,
                                     regionMultiple,
                                     regionOptions,
                                     regionSearchable,
                                     regionEditRoles
                                 FROM ' . PERCH_DB_PREFIX . 'content_regions
                                 WHERE regionPage!=' . $this->db->pdb('*') . ' AND pageID=' . $this->db->pdb((int) $CopyPage->id());
                             $this->db->execute($sql);
                         }
                     }
                 }
             }
             return $Page;
         }
     }
     return false;
 }
 /**
  * takes the post data and inserts it as a new row in the database.
  */
 public function create($data, $Template = false)
 {
     if (!isset($data['postDateTime'])) {
         $data['postDateTime'] = date('Y-m-d H:i:s');
     }
     if (isset($data['postTitle'])) {
         $data['postSlug'] = PerchUtil::urlify(date('Y m d', strtotime($data['postDateTime'])) . ' ' . $data['postTitle']);
     }
     if (isset($data['cat_ids']) && is_array($data['cat_ids'])) {
         $cat_ids = $data['cat_ids'];
     } else {
         $cat_ids = false;
     }
     unset($data['cat_ids']);
     $postID = $this->db->insert($this->table, $data);
     if ($postID) {
         // if(is_array($cat_ids)) {
         // 	for($i=0; $i<sizeOf($cat_ids); $i++) {
         // 	    $tmp = array();
         // 	    $tmp['postID'] = $postID;
         // 	    $tmp['categoryID'] = $cat_ids[$i];
         // 	    $this->db->insert(PERCH_DB_PREFIX.'blog_posts_to_categories', $tmp);
         // 	}
         // }
         // Split tag string into array
         if ($data['postTags'] != '') {
             $a = explode(',', $data['postTags']);
             if (is_array($a)) {
                 for ($i = 0; $i < sizeOf($a); $i++) {
                     $tmp = array();
                     $tmp['postID'] = $postID;
                     $tag_str = trim($a[$i]);
                     //does this tag exist
                     $sql = 'SELECT tagID, tagTitle FROM ' . PERCH_DB_PREFIX . 'blog_tags WHERE tagTitle = ' . $this->db->pdb($tag_str) . ' LIMIT 1';
                     $row = $this->db->get_row($sql);
                     if (is_array($row)) {
                         $tmp['tagID'] = $row['tagID'];
                     } else {
                         $tag = array();
                         $tag['tagTitle'] = $tag_str;
                         $tag['tagSlug'] = PerchUtil::urlify($tag_str);
                         $tmp['tagID'] = $this->db->insert(PERCH_DB_PREFIX . 'blog_tags', $tag);
                     }
                     $this->db->insert(PERCH_DB_PREFIX . 'blog_posts_to_tags', $tmp);
                 }
             }
         }
         return $this->find($postID, true);
     }
     return false;
 }
예제 #19
0
    $id = (int) $_GET['id'];
    $Role = $Roles->find($id);
} else {
    $id = false;
    $Role = false;
}
$Form = new PerchForm('role', false);
$req = array();
$req['roleTitle'] = "Required";
$Form->set_required($req);
if ($Form->posted() && $Form->validate()) {
    PerchUtil::debug($_POST);
    $data = array();
    $postvars = array('roleTitle');
    $data = $Form->receive($postvars);
    $data['roleSlug'] = PerchUtil::urlify($data['roleTitle']);
    if (is_object($Role)) {
        $Role->update($data);
    } else {
        $Role = $Roles->create($data);
    }
    $privs = $Form->find_items('privs-');
    $new_privs = array();
    if (PerchUtil::count($privs)) {
        foreach ($privs as $category) {
            if (PerchUtil::count($category)) {
                foreach ($category as $item) {
                    $new_privs[] = $item;
                }
            }
        }
예제 #20
0
 private function substitute_slug_vars($matches)
 {
     $url_vars = $this->tmp_slug_vars;
     if (isset($url_vars[$matches[1]])) {
         return PerchUtil::urlify($url_vars[$matches[1]]);
     }
 }
예제 #21
0
 public function replace_content_tags($namespace, $content_vars, $contents)
 {
     if (is_array($content_vars)) {
         // Find all matching tags
         $s = '#<perch:' . $namespace . '[^>]*/>#';
         $count = preg_match_all($s, $contents, $matches, PREG_SET_ORDER);
         if ($count) {
             foreach ($matches as $match) {
                 $match = $match[0];
                 $tag = new PerchXMLTag($match);
                 if ($tag->suppress) {
                     $contents = str_replace($match, '', $contents);
                 } else {
                     if (isset($content_vars[$tag->id])) {
                         $value = $content_vars[$tag->id];
                     } else {
                         $replacement = '';
                         if ($tag->else()) {
                             $replacement = $tag->else();
                         }
                         $contents = str_replace($match, $replacement, $contents);
                         continue;
                     }
                     $field_is_markup = false;
                     if ($tag->type) {
                         $FieldType = PerchFieldTypes::get($tag->type, false, $tag);
                         $modified_value = $FieldType->get_processed($value);
                         $field_is_markup = $FieldType->processed_output_is_markup;
                     } else {
                         $modified_value = $value;
                     }
                     // check for 'rewrite' attribute
                     if ($tag->rewrite) {
                         $modified_value = $this->_rewrite($tag, $modified_value);
                     }
                     // check for 'format' attribute
                     if ($tag->format) {
                         $modified_value = $this->_format($tag, $modified_value);
                     }
                     // check for 'replace' strings
                     if ($tag->replace) {
                         $pairs = explode(',', $tag->replace);
                         if (PerchUtil::count($pairs)) {
                             foreach ($pairs as $pair) {
                                 $pairparts = explode('|', $pair);
                                 if (isset($pairparts[0]) && isset($pairparts[1])) {
                                     $modified_value = str_replace(trim($pairparts[0]), trim($pairparts[1]), $modified_value);
                                 }
                             }
                         }
                     }
                     // Urlify
                     if ($tag->urlify) {
                         $modified_value = PerchUtil::urlify($modified_value);
                     }
                     // Trim by chars
                     if ($tag->chars) {
                         if (strlen($modified_value) > (int) $tag->chars) {
                             $modified_value = PerchUtil::excerpt_char($modified_value, (int) $tag->chars, false, true, $tag->append);
                         }
                     }
                     // Trim by words
                     if ($tag->words) {
                         $modified_value = PerchUtil::excerpt($modified_value, (int) $tag->words, false, true, $tag->append);
                     }
                     // Hash
                     if ($tag->hash == 'md5') {
                         $modified_value = md5($modified_value);
                     }
                     // check that what we've got isn't an array. If it is, try your best to get a good string.
                     if (is_array($modified_value)) {
                         if (isset($modified_value['_default'])) {
                             $modified_value = (string) $modified_value['_default'];
                         } else {
                             if (isset($modified_value['processed'])) {
                                 $modified_value = (string) $modified_value['processed'];
                             } else {
                                 $modified_value = (string) array_shift($modified_value);
                             }
                         }
                     }
                     // Strip tags
                     if ($tag->striptags) {
                         $modified_value = strip_tags($modified_value);
                     }
                     // Append
                     if (!$tag->words && !$tag->chars && $tag->append) {
                         $modified_value .= $tag->append;
                     }
                     // URL Encode
                     if ($tag->urlencode) {
                         $modified_value = rawurlencode($modified_value);
                     }
                     // Escape quotes
                     if ($tag->escape) {
                         $modified_value = PerchUtil::html($modified_value, true, false);
                         $field_is_markup = true;
                     }
                     // check encoding
                     if ($this->autoencode && !$field_is_markup) {
                         if (!$tag->textile && !$tag->markdown) {
                             if ((!$tag->is_set('encode') || $tag->encode == true) && (!$tag->is_set('html') || $tag->html == false)) {
                                 $modified_value = PerchUtil::html($modified_value);
                             }
                         }
                     }
                     // JSON encoding
                     if ($tag->jsonencode) {
                         $modified_value = json_encode($modified_value);
                     }
                     $contents = str_replace($match, $modified_value, $contents);
                 }
             }
         }
     }
     return $contents;
 }
    public function search($term, $filters)
    {
        $term = trim($term);
        $tag = PerchUtil::urlify($term);
        $Tags = new PerchAssets_Tags();
        $Tag = $Tags->get_one_by('tagSlug', $tag);
        $sql = 'SELECT * FROM (';
        $filter_sql = '';
        if (PerchUtil::count($filters)) {
            foreach ($filters as $filter => $filter_value) {
                switch ($filter) {
                    case 'bucket':
                        $filter_sql .= ' AND r.resourceBucket=' . $this->db->pdb($filter_value) . ' ';
                        break;
                    case 'app':
                        $filter_sql .= ' AND r.resourceApp=' . $this->db->pdb($filter_value) . ' ';
                        break;
                    case 'type':
                        $type_map = PerchAssets_Asset::get_type_map();
                        if (array_key_exists($filter_value, $type_map)) {
                            $filter_sql .= ' AND r.resourceType IN (' . $this->db->implode_for_sql_in($type_map[$filter_value]['exts']) . ') ';
                        } else {
                            $filter_sql .= ' AND r.resourceType=' . $this->db->pdb($filter_value) . ' ';
                        }
                        break;
                    case 'date':
                        $ts = strtotime($filter_value);
                        $filter_sql .= ' AND r.resourceCreated BETWEEN ' . $this->db->pdb(date('Y-m-d 00:00:00', $ts)) . ' AND ' . $this->db->pdb(date('Y-m-d 25:59:59', $ts)) . ' ';
                        break;
                }
            }
        }
        if ($Tag) {
            $sql .= 'SELECT r.*, 0.5 AS score, r2.resourceFile AS thumb, r2.resourceWidth AS thumbWidth, r2.resourceHeight AS thumbHeight, r2.resourceDensity AS thumbDensity 
                    FROM ' . PERCH_DB_PREFIX . 'resources r LEFT OUTER JOIN ' . PERCH_DB_PREFIX . 'resources r2 ON r2.resourceParentID=r.resourceID AND r2.resourceKey=\'thumb\'
                    AND r2.resourceAWOL!=1 JOIN ' . PERCH_DB_PREFIX . 'resources_to_tags r2t ON r.resourceID=r2t.resourceID AND r2t.tagID=' . $Tag->id() . '
                    WHERE  r.resourceAWOL=0 AND r.resourceKey=\'orig\' ' . $filter_sql . '
                    UNION ALL ';
        }
        $sql .= 'SELECT r.*, MATCH(r.resourceTitle) AGAINST(' . $this->db->pdb($term) . ') AS score, r2.resourceFile AS thumb, r2.resourceWidth AS thumbWidth, r2.resourceHeight AS thumbHeight, r2.resourceDensity AS thumbDensity 
                FROM ' . PERCH_DB_PREFIX . 'resources r LEFT OUTER JOIN ' . PERCH_DB_PREFIX . 'resources r2 ON r2.resourceParentID=r.resourceID AND r2.resourceKey=\'thumb\'
                AND r2.resourceAWOL!=1
                WHERE MATCH(r.resourceTitle) AGAINST(' . $this->db->pdb($term) . ') AND r.resourceKey=\'orig\' ' . $filter_sql . '

                ORDER BY score DESC, resourceUpdated DESC';
        $sql .= ') AS t GROUP BY resourceID';
        return $this->return_instances($this->db->get_rows($sql));
    }
예제 #23
0
 /**
  * overwriting create to add URL slug creation.
  * @see PerchFactory::create()
  * @param array $data
  * @return album object
  */
 public function create($data)
 {
     if (isset($data['albumTitle'])) {
         $data['albumSlug'] = PerchUtil::urlify($data['albumTitle']);
         $data['albumSlug'] = $this->check_slug_unique($data['albumSlug']);
     }
     if (!isset($data['albumOrder']) || $data['albumOrder'] == '') {
         $sql = 'SELECT COUNT(*) FROM ' . $this->table;
         $count = $this->db->get_value($sql);
         $data['albumOrder'] = $count + 1;
     }
     if ($albumID = $this->db->insert($this->table, $data)) {
         return $this->find($albumID);
     }
     return false;
 }
예제 #24
0
$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();
}
if (isset($_GET['created']) && !$message) {
    $message = $HTML->success_message('Your blog has been successfully created. Return to %sblog listing%s', '<a href="' . $API->app_path() . '/blogs">', '</a>');
예제 #25
0
$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();
}
if (isset($_GET['created']) && !$message) {
    $message = $HTML->success_message('Your category has been successfully created. Return to %scategory listing%s', '<a href="' . $API->app_path() . '/categories">', '</a>');