function process()
 {
     //prep site
     $this->helper->ensure_type_is_on_site(id_of('publication_type'));
     $this->helper->ensure_type_is_on_site(id_of('group_type'));
     $this->helper->ensure_nobody_group_is_on_site();
     // gather core information
     $pub_type_id = id_of('publication_type');
     $name = trim(strip_tags($this->get_value('pub_name')));
     // populate values array
     $values['new'] = 0;
     $values['description'] = trim(get_safer_html($this->get_value('pub_description')));
     $values['unique_name'] = trim(strip_tags($this->get_value('pub_unique_name')));
     $values['state'] = 'Live';
     $values['hold_comments_for_review'] = 'no';
     $values['posts_per_page'] = turn_into_int($this->get_value('pub_posts_per_page'));
     $values['blog_feed_string'] = trim(strip_tags($this->get_value('pub_rss_feed_url')));
     $values['publication_type'] = 'Newsletter';
     $values['has_issues'] = 'no';
     $values['has_sections'] = 'no';
     $values['date_format'] = $this->get_value('date_format');
     // create the publication
     $pub_id = reason_create_entity($this->site_id, $pub_type_id, $this->user_id, $name, $values);
     // associate with nobody posting and commenting groups
     create_relationship($pub_id, id_of('nobody_group'), relationship_id_of('publication_to_authorized_posting_group'));
     create_relationship($pub_id, id_of('nobody_group'), relationship_id_of('publication_to_authorized_commenting_group'));
 }
예제 #2
0
 /**
  *
  * @todo populate descriptions intelligently
  */
 function process()
 {
     // lets parse the uploaded file and create a job set - we cache the job set so that if the browser times out we can recover.
     $stack = new ReasonJobStack();
     // kill All
     $kill_all = $this->get_value('kill_all');
     if ($kill_all == "true") {
         $cleanup_job = new WordPressImportCleanup();
         $cleanup_job->site_id = $this->get_value('reason_site');
         $cleanup_job->user_id = $this->controller->reason_user_id;
         $stack->add_job($cleanup_job);
     } else {
         // create a job for alerts that we'll add to the end of the stack.
         $report_preformatted_job = new WordPressRewriteRuleReportPreformattedJob();
         // ensure the news type is on the site
         $job = new WordPressEnsureTypeIsOnSite();
         $job->site_id = $this->get_value('reason_site');
         $job->type_id = id_of('news');
         $stack->add_job($job);
         // ensure publication type is on the site
         $job = new WordPressEnsureTypeIsOnSite();
         $job->site_id = $this->get_value('reason_site');
         $job->type_id = id_of('publication_type');
         $stack->add_job($job);
         // ensure category type is on the site
         $job = new WordPressEnsureTypeIsOnSite();
         $job->site_id = $this->get_value('reason_site');
         $job->type_id = id_of('category_type');
         $stack->add_job($job);
         // create the publication entity
         $job = new WordPressEntityCreationJob();
         $job->site_id = $this->get_value('reason_site');
         $job->type_id = id_of('publication_type');
         $job->user_id = $this->controller->reason_user_id;
         $job->entity_info = array('name' => $this->xml_parser->document->channel[0]->title[0]->tagData, 'description' => $this->xml_parser->document->channel[0]->description[0]->tagData, 'publication_type' => 'blog', 'blog_feed_string' => 'blog', 'hold_posts_for_review' => 'no', 'has_issues' => 'no', 'has_sections' => 'no');
         $pub_import_guid = $stack->add_job($job);
         $nobody_group_job = new WordPressEnsureNobodyGroupIsOnSite();
         $nobody_group_job->site_id = $this->get_value('reason_site');
         $stack->add_job($nobody_group_job);
         // relate publication to nobody group for front end posting and commenting
         $post_group_job = new WordPressRelateItemsJob();
         $post_group_job->rel_id = relationship_id_of('publication_to_authorized_posting_group');
         $post_group_job->left_import_guid = $pub_import_guid;
         $post_group_job->right_id = id_of('nobody_group');
         $stack->add_job($post_group_job);
         $comment_group_job = new WordPressRelateItemsJob();
         $comment_group_job->rel_id = relationship_id_of('publication_to_authorized_commenting_group');
         $comment_group_job->left_import_guid = $pub_import_guid;
         $comment_group_job->right_id = id_of('nobody_group');
         $stack->add_job($comment_group_job);
         $make_pub_page_job = new WordPressMakePublicationPageJob();
         $make_pub_page_job->site_id = $this->get_value('reason_site');
         // if we want a new page - create a publication page.
         if ($new_pub_page = $this->get_value('blog_page_name')) {
             $pub_page_name = trim(strip_tags($new_pub_page));
             $pub_page_url_fragment = strtolower(str_replace(array("-", " "), "_", $pub_page_name));
             $create_pub_page_job = new WordPressEntityCreationJob();
             $create_pub_page_job->type_id = id_of('minisite_page');
             $create_pub_page_job->site_id = $this->get_value('reason_site');
             $create_pub_page_job->user_id = $this->controller->reason_user_id;
             $create_pub_page_job->entity_info = array('name' => $pub_page_name, 'link_name' => $pub_page_name, 'url_fragment' => $pub_page_url_fragment, 'state' => 'Live', 'custom_page' => 'publication', 'content' => '', 'nav_display' => 'Yes');
             $create_pub_page_guid = $stack->add_job($create_pub_page_job);
             // we need to make a parent relationship with the root page_id
             $page_parent_job = new WordPressRelateItemsJob();
             $page_parent_job->rel_id = relationship_id_of('minisite_page_parent');
             $page_parent_job->left_import_guid = $create_pub_page_guid;
             $page_parent_job->right_id = $this->get_site_root($this->get_value('reason_site'));
             $page_parent_job_guid = $stack->add_job($page_parent_job);
             $make_pub_page_job->page_id_guid = $create_pub_page_guid;
         } else {
             $make_pub_page_job->page_id = $this->get_site_root($this->get_value('reason_site'));
         }
         $make_pub_page_job->user_id = $this->controller->reason_user_id;
         $make_pub_page_job->pub_import_guid = $pub_import_guid;
         $pub_page_guid = $stack->add_job($make_pub_page_job);
         // CATEGORIES
         if (!empty($this->xml_parser->document->channel[0]->wp_category)) {
             foreach ($this->xml_parser->document->channel[0]->wp_category as $k => $cat) {
                 $the_category['wp_cat_name'] = $cat->wp_cat_name[0]->tagData;
                 $the_category['wp_category_nicename'] = $cat->wp_category_nicename[0]->tagData;
                 $the_category['wp_category_parent'] = $cat->wp_category_parent[0]->tagData;
                 if (!empty($the_category['wp_category_parent'])) {
                     $parent_cat[$the_category['wp_cat_name']] = $the_category['wp_category_parent'];
                 }
                 // STUFF FOR OUR IMPORT
                 $cat_import_job = new WordPressEntityCreationJob();
                 $cat_import_job->type_id = id_of('category_type');
                 $cat_import_job->site_id = $this->get_value('reason_site');
                 $cat_import_job->user_id = $this->controller->reason_user_id;
                 $cat_import_job->entity_info = array('name' => $the_category['wp_cat_name'], 'slug' => $the_category['wp_category_nicename']);
                 $cat_import_guid[$the_category['wp_cat_name']] = $stack->add_job($cat_import_job);
             }
         }
         // TAGS - we also make these into categories since Reason does not have a meaningful distinction
         if (!empty($this->xml_parser->document->channel[0]->wp_tag)) {
             foreach ($this->xml_parser->document->channel[0]->wp_tag as $k => $cat) {
                 $the_category['wp_tag_name'] = $cat->wp_tag_name[0]->tagData;
                 $the_category['wp_tag_slug'] = $cat->wp_tag_slug[0]->tagData;
                 // STUFF FOR OUR IMPORT
                 $cat_import_job = new WordPressEntityCreationJob();
                 $cat_import_job->type_id = id_of('category_type');
                 $cat_import_job->site_id = $this->get_value('reason_site');
                 $cat_import_job->user_id = $this->controller->reason_user_id;
                 $cat_import_job->entity_info = array('name' => $the_category['wp_tag_name'], 'slug' => $the_category['wp_tag_slug']);
                 $cat_import_guid[$the_category['wp_tag_name']] = $stack->add_job($cat_import_job);
             }
         }
         if (!empty($this->xml_parser->document->channel[0]->item)) {
             foreach ($this->xml_parser->document->channel[0]->item as $k => $item) {
                 $the_item = array();
                 // STRAIGHT OUT OF WORDPRESS
                 $the_item['title'] = $item->title[0]->tagData;
                 $the_item['link'] = $item->link[0]->tagData;
                 $the_item['pubDate'] = $item->pubdate[0]->tagData;
                 $the_item['dc_creator'] = $item->dc_creator[0]->tagData;
                 // categories - how to handle??
                 $the_item['guid'] = $item->guid[0]->tagData;
                 // attribute isPermaLink?? - do we care?
                 $the_item['guid_is_permalink'] = $item->guid[0]->tagAttrs['ispermalink'];
                 $the_item['description'] = tidy(strip_tags($item->description[0]->tagData));
                 $the_item['content_encoded'] = trim(tidy(get_safer_html($this->wpautop($item->content_encoded[0]->tagData))));
                 //$the_item['excerpt_encoded'] = trim(tidy($this->wpautop($item->excerpt_encoded[0]->tagData)));
                 $the_item['wp_post_id'] = $item->wp_post_id[0]->tagData;
                 $the_item['wp_post_date'] = $item->wp_post_date[0]->tagData;
                 $the_item['wp_post_date_gmt'] = $item->wp_post_date_gmt[0]->tagData;
                 $the_item['wp_comment_status'] = $item->wp_comment_status[0]->tagData;
                 $the_item['wp_ping_status'] = $item->wp_ping_status[0]->tagData;
                 $the_item['wp_post_name'] = $item->wp_post_name[0]->tagData;
                 $the_item['wp_status'] = $item->wp_status[0]->tagData;
                 $the_item['wp_post_parent'] = $item->wp_post_parent[0]->tagData;
                 $the_item['wp_menu_order'] = $item->wp_menu_order[0]->tagData;
                 $the_item['wp_post_type'] = $item->wp_post_type[0]->tagData;
                 $the_item['wp_post_password'] = $item->wp_post_password[0]->tagData;
                 $the_item['is_sticky'] = $item->wp_post_password[0]->tagData;
                 $the_item['guid'] = $item->guid[0]->tagData;
                 // IF WE ARE A PAGE
                 if (strtolower($the_item['wp_post_type']) == 'page') {
                     //$the_item['link'] is the old URL
                     //$the_item['guid'] is the non friendly URL
                     // our new url fragment should be the last segment of the old URL - if it is an SEO friendly URL
                     $url = parse_url($the_item['link']);
                     if (!empty($url['query'])) {
                         $new_url_fragment = strtolower(str_replace(" ", "_", $the_item['title']));
                     } else {
                         $new_url_fragment = strtolower(str_replace(" ", "_", $the_item['wp_post_name']));
                         $new_url_fragment = strtolower(str_replace("-", "_", $new_url_fragment));
                     }
                     // should we have a description of some type?
                     $page_import_job = new WordPressEntityCreationJob();
                     $page_import_job->type_id = id_of('minisite_page');
                     $page_import_job->site_id = $this->get_value('reason_site');
                     $page_import_job->user_id = $this->controller->reason_user_id;
                     $page_import_job->entity_info = array('name' => $the_item['title'], 'link_name' => $the_item['title'], 'url_fragment' => $new_url_fragment, 'state' => $the_item['wp_status'] == 'publish' ? 'Live' : 'Pending', 'datetime' => $the_item['wp_post_date'], 'author' => $the_item['dc_creator'], 'sort_order' => $the_item['wp_menu_order'], 'custom_page' => 'default', 'content' => tidy($the_item['content_encoded']), 'nav_display' => 'Yes');
                     $page_import_job->id(md5('page_guid_' . $the_item['wp_post_id']));
                     $stack->add_job($page_import_job);
                     //page_to_category - these rels we need to do
                     if (!empty($item->category)) {
                         foreach ($item->category as $k => $category) {
                             $page_cat = array();
                             $cat_name = $category->tagData;
                             $page_cat[] = $cat_name;
                             while (isset($parent_cat[$cat_name])) {
                                 $cat_name = $parent_cat[$cat_name];
                                 $page_cat[] = $cat_name;
                             }
                             foreach ($page_cat as $cat_name) {
                                 // add a job to relate the post to the category
                                 $page_to_cat_job = new WordPressRelateItemsJob();
                                 $page_to_cat_job->rel_id = relationship_id_of('page_to_category');
                                 $page_to_cat_job->left_import_guid = md5('page_guid_' . $the_item['wp_post_id']);
                                 $page_to_cat_job->right_import_guid = $cat_import_guid[$cat_name];
                                 if (!isset($page_to_cat_keys[$cat_import_guid[$cat_name]])) {
                                     $stack->add_job($page_to_cat_job);
                                     // we don't give this one a guid ... doesn't need one
                                 }
                                 $page_to_cat_keys[$cat_import_guid[$cat_name]] = true;
                             }
                         }
                     }
                     //minisite_page_parent - these rels we need to do
                     $page_parent_job = new WordPressRelateItemsJob();
                     $page_parent_job->rel_id = relationship_id_of('minisite_page_parent');
                     $page_parent_job->left_import_guid = md5('page_guid_' . $the_item['wp_post_id']);
                     if (empty($the_item['wp_post_parent'])) {
                         $page_parent_job->right_id = $this->get_site_root($this->get_value('reason_site'));
                     } else {
                         $page_parent_job->right_import_guid = md5('page_guid_' . $the_item['wp_post_parent']);
                     }
                     $page_parent_job_guid = $stack->add_job($page_parent_job);
                     $url_history_job = new WordPressURLHistoryJob();
                     if ($the_item['guid'] && $the_item['guid_is_permalink'] == "true") {
                         $url_history_job->wp_permalink = $the_item['guid'];
                     }
                     $url_history_job->wp_link = $the_item['link'];
                     $url_history_job->rel_guid = $page_parent_job_guid;
                     $url_history_job->entity_guid = md5('page_guid_' . $the_item['wp_post_id']);
                     $stack->add_job($url_history_job);
                     $this->rewrites_needed = true;
                 } elseif (strtolower($the_item['wp_post_type']) == 'post') {
                     if (!empty($the_item['excerpt_encoded'])) {
                         $reason_description = $the_item['excerpt_encoded'];
                     } elseif (!empty($the_item['description'])) {
                         $reason_description = $the_item['description'];
                     } else {
                         $words = explode(' ', $the_item['content_encoded'], 50);
                         unset($words[count($words) - 1]);
                         $reason_description = implode(' ', $words) . '…';
                         $reason_description = trim(tidy($reason_description));
                     }
                     /**
                      * its not clear to me what the various dates represent but in my sample xml file post_date seems to be the only item consistently populated
                      * and so we are going to use it for the dated.datetime value.
                      */
                     // CREATE THE IMPORT JOB AND SAVE IF IT IS NOT ALREADY CACHED
                     $post_import_job = new WordPressEntityCreationJob();
                     $post_import_job->type_id = id_of('news');
                     $post_import_job->site_id = $this->get_value('reason_site');
                     $post_import_job->user_id = $this->controller->reason_user_id;
                     $post_import_job->entity_info = array('name' => $the_item['title'], 'release_title' => $the_item['title'], 'description' => tidy($reason_description), 'content' => tidy($the_item['content_encoded']), 'status' => $the_item['wp_status'] == 'publish' ? 'published' : 'pending', 'show_hide' => $the_item['wp_status'] == 'publish' ? 'show' : 'hide', 'datetime' => $the_item['wp_post_date'], 'commenting_state' => $the_item['wp_comment_status'] == 'open' ? 'on' : 'off', 'author' => $the_item['dc_creator']);
                     $import_guid = $stack->add_job($post_import_job);
                     // now we want to add a job that relates the post to the publication - we have to do this using our import_guids
                     $relationship_job = new WordPressRelateItemsJob();
                     $relationship_job->rel_id = relationship_id_of('news_to_publication');
                     $relationship_job->left_import_guid = $import_guid;
                     $relationship_job->right_import_guid = $pub_import_guid;
                     $stack->add_job($relationship_job);
                     // we don't give this one a guid ... doesn't need one
                     $news_rewrite_alert_job = new WordPressNewsRewriteAlertJob();
                     $news_rewrite_alert_job->page_id_guid = $pub_page_guid;
                     $news_rewrite_alert_job->story_id_guid = $import_guid;
                     $news_rewrite_alert_job->original_url = $the_item['link'];
                     $news_rewrite_alert_job->report_preformatted_job = $report_preformatted_job;
                     $stack->add_job($news_rewrite_alert_job);
                     // lets do category rels and test the stack mechanism at the same time!
                     if (!empty($item->category)) {
                         foreach ($item->category as $k => $category) {
                             $news_cat = array();
                             $cat_name = $category->tagData;
                             $news_cat[] = $cat_name;
                             while (isset($parent_cat[$cat_name])) {
                                 $cat_name = $parent_cat[$cat_name];
                                 $news_cat[] = $cat_name;
                             }
                             foreach ($news_cat as $cat_name) {
                                 // add a job to relate the post to the category
                                 $news_to_cat_job = new WordPressRelateItemsJob();
                                 $news_to_cat_job->rel_id = relationship_id_of('news_to_category');
                                 $news_to_cat_job->left_import_guid = $import_guid;
                                 // the news item
                                 $news_to_cat_job->right_import_guid = $cat_import_guid[$cat_name];
                                 if (!isset($news_to_cat_keys[$cat_import_guid[$cat_name]])) {
                                     $stack->add_job($news_to_cat_job);
                                     // we don't give this one a guid ... doesn't need one
                                 }
                                 $news_to_cat_keys[$cat_import_guid[$cat_name]] = true;
                             }
                         }
                     }
                     if (!empty($item->wp_comment)) {
                         // ensure comment type is on the site
                         if (!isset($make_sure_comments_are_on_site)) {
                             $job = new WordPressEnsureTypeIsOnSite();
                             $job->site_id = $this->get_value('reason_site');
                             $job->type_id = id_of('comment_type');
                             $stack->add_job($job);
                             $make_sure_comments_are_on_site = true;
                         }
                         foreach ($item->wp_comment as $k => $comment) {
                             $the_comment = array();
                             // STRAIGHT OUT OF WORDPRESS
                             $the_comment['id'] = $comment->wp_comment_id[0]->tagData;
                             $the_comment['author'] = strip_tags($comment->wp_comment_author[0]->tagData);
                             $the_comment['author_email'] = $comment->wp_comment_author_email[0]->tagData;
                             $the_comment['author_url'] = $comment->wp_comment_author_url[0]->tagData;
                             $the_comment['author_IP'] = $comment->wp_comment_author_ip[0]->tagData;
                             $the_comment['date'] = $comment->wp_comment_date[0]->tagData;
                             $the_comment['content'] = trim(tidy($this->wpautop($comment->wp_comment_content[0]->tagData)));
                             $the_comment['approved'] = $comment->wp_comment_approved[0]->tagData;
                             $should_import = !$this->only_import_approved_comments || $the_comment['approved'] == '1';
                             // WE MAKE THIS ONE IF IT HAS CONTENT
                             if (!empty($the_comment['content']) && $should_import) {
                                 $words = explode(' ', strip_tags($the_comment['content']), 10);
                                 unset($words[count($words) - 1]);
                                 $name = trim(implode(' ', $words)) . '…';
                                 $comment_import_guid = md5('comment_id_' . $the_comment['id']);
                                 $comment_import_job = new WordPressEntityCreationJob();
                                 $comment_import_job->type_id = id_of('comment_type');
                                 $comment_import_job->site_id = $this->get_value('reason_site');
                                 $comment_import_job->user_id = $this->controller->reason_user_id;
                                 $comment_import_job->entity_info = array('name' => $name, 'content' => $the_comment['content'], 'author' => strip_tags($the_comment['author']), 'show_hide' => $the_comment['approved'] == '1' ? 'show' : 'hide', 'datetime' => $the_comment['date'], 'new' => 0);
                                 $stack->add_job($comment_import_job, $comment_import_guid);
                                 // now we want to add a job that relates the comment to the post - we use import guids
                                 $comment_relationship_job = new WordPressRelateItemsJob();
                                 $comment_relationship_job->rel_id = relationship_id_of('news_to_comment');
                                 $comment_relationship_job->left_import_guid = $import_guid;
                                 $comment_relationship_job->right_import_guid = $comment_import_guid;
                                 $stack->add_job($comment_relationship_job);
                                 // we don't give this one a guid ... doesn't need one
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($this->rewrites_needed) {
         $rewrite_job = new WordPressSiteRewritesJob();
         $rewrite_job->site_id = $this->get_value('reason_site');
         $stack->add_job($rewrite_job);
     }
     if (isset($report_preformatted_job)) {
         $stack->add_job($report_preformatted_job);
     }
     // lets save the stack in a cache with our $uid
     $cache = new ReasonObjectCache($this->uid);
     $cache->set($stack);
 }
예제 #3
0
 function process()
 {
     $site_id = $this->site_id;
     $counts = array();
     for ($i = 1; $i <= $this->max_upload_number; $i++) {
         $element = $this->get_element('upload_' . $i);
         if (!empty($element->tmp_full_path) and file_exists($element->tmp_full_path)) {
             $filename = $this->get_value('upload_' . $i . '_filename');
             if ($this->verify_image($element->tmp_full_path)) {
                 if (empty($counts[$filename])) {
                     $this->files[$filename] = $element->tmp_full_path;
                     $counts[$filename] = 1;
                 } else {
                     $counts[$filename]++;
                     $this->files[$filename . '.' . $counts[$filename]] = $element->tmp_full_path;
                 }
             } else {
                 $this->invalid_files[$filename] = $element->tmp_full_path;
             }
         }
     }
     if (count($this->files)) {
         $page_id = (int) $this->get_value('attach_to_page');
         $max_sort_order_value = 0;
         if ($page_id) {
             $max_sort_order_value = $this->_get_max_sort_order_value($page_id);
         }
         $sort_order_value = $max_sort_order_value;
         $tables = get_entity_tables_by_type(id_of('image'));
         $valid_file_html = '<ul>' . "\n";
         foreach ($this->files as $entry => $cur_name) {
             $sort_order_value++;
             $valid_file_html .= '<li><strong>' . $entry . ':</strong> processing ';
             $date = '';
             // get suffix
             $type = strtolower(substr($cur_name, strrpos($cur_name, '.') + 1));
             $ok_types = array('jpg');
             // get exif data
             if ($this->get_value('exif_override') && in_array($type, $ok_types) && function_exists('read_exif_data')) {
                 // read_exif_data() does not obey error supression
                 $exif_data = @read_exif_data($cur_name);
                 if ($exif_data) {
                     // some photos may have different fields filled in for dates - look through these until one is found
                     $valid_dt_fields = array('DateTimeOriginal', 'DateTime', 'DateTimeDigitized');
                     foreach ($valid_dt_fields as $field) {
                         // once we've found a valid date field, store that and break out of the loop
                         if (!empty($exif_data[$field])) {
                             $date = $exif_data[$field];
                             break;
                         }
                     }
                 }
             } else {
                 $date = $this->get_value('datetime');
             }
             $keywords = $entry;
             if ($this->get_value('keywords')) {
                 $keywords .= ', ' . $this->get_value('keywords');
             }
             // insert entry into DB with proper info
             $values = array('datetime' => $date, 'image_type' => $type, 'author' => $this->get_value('author'), 'state' => 'Pending', 'keywords' => $keywords, 'description' => $this->get_value('description'), 'name' => $this->get_value('name') ? $this->get_value('name') : $entry, 'content' => $this->get_value('content'), 'original_image_format' => $this->get_value('original_image_format'), 'new' => 0, 'no_share' => $this->get_value('no_share'));
             //tidy values
             $no_tidy = array('state', 'new');
             foreach ($values as $key => $val) {
                 if (!in_array($key, $no_tidy) && !empty($val)) {
                     $values[$key] = trim(get_safer_html(tidy($val)));
                 }
             }
             $id = reason_create_entity($site_id, id_of('image'), $this->user_id, $entry, $values);
             if ($id) {
                 //assign to categories
                 $categories = $this->get_value('assign_to_categories');
                 if (!empty($categories)) {
                     foreach ($categories as $category_id) {
                         create_relationship($id, $category_id, relationship_id_of('image_to_category'));
                     }
                 }
                 //assign to	gallery page
                 if ($page_id) {
                     create_relationship($page_id, $id, relationship_id_of('minisite_page_to_image'), array('rel_sort_order' => $sort_order_value));
                 }
                 // resize and move photos
                 $new_name = PHOTOSTOCK . $id . '.' . $type;
                 $orig_name = PHOTOSTOCK . $id . '_orig.' . $type;
                 $tn_name = PHOTOSTOCK . $id . '_tn.' . $type;
                 // Support for new fields; they should be set null by default, but will be
                 // changed below if a thumbnail/original image is created. This is very messy...
                 $thumbnail_image_type = null;
                 $original_image_type = null;
                 // atomic move the file if possible, copy if necessary
                 if (is_writable($cur_name)) {
                     rename($cur_name, $new_name);
                 } else {
                     copy($cur_name, $new_name);
                 }
                 // create a thumbnail if need be
                 list($width, $height, $type, $attr) = getimagesize($new_name);
                 if ($width > REASON_STANDARD_MAX_IMAGE_WIDTH || $height > REASON_STANDARD_MAX_IMAGE_HEIGHT) {
                     copy($new_name, $orig_name);
                     resize_image($new_name, REASON_STANDARD_MAX_IMAGE_WIDTH, REASON_STANDARD_MAX_IMAGE_HEIGHT);
                     $original_image_type = $this->image_types[$type];
                 }
                 $thumb_dimensions = get_reason_thumbnail_dimensions($site_id);
                 if ($width > $thumb_dimensions['width'] || $height > $thumb_dimensions['height']) {
                     copy($new_name, $tn_name);
                     resize_image($tn_name, $thumb_dimensions['width'], $thumb_dimensions['height']);
                     $thumbnail_image_type = $this->image_types[$type];
                 }
                 // real original
                 $my_orig_name = $this->add_name_suffix($cur_name, '-unscaled');
                 if (file_exists($my_orig_name)) {
                     // move the original image into the photostock directory
                     if (is_writable($my_orig_name)) {
                         rename($my_orig_name, $orig_name);
                     } else {
                         copy($my_orig_name, $orig_name);
                     }
                     $original_image_type = $this->image_types[$type];
                 }
                 $info = getimagesize($new_name);
                 $size = round(filesize($new_name) / 1024);
                 // now we have the size of the resized image.
                 $values = array('width' => $info[0], 'height' => $info[1], 'size' => $size, 'thumbnail_image_type' => $thumbnail_image_type, 'original_image_type' => $original_image_type);
                 // update with new info - don't archive since this is really just an extension of the creation of the item
                 // we needed that ID to do something
                 reason_update_entity($id, $this->user_id, $values, false);
                 $valid_file_html .= 'completed</li>';
             } else {
                 trigger_error('Unable to create image entity');
                 $valid_file_html .= '<li>Unable to import ' . $entry . '</li>';
             }
             sleep(1);
         }
         $valid_file_html .= '</ul>' . "\n";
         $num_image_string = count($this->files) == 1 ? '1 image has ' : count($this->files) . ' images have ';
         $valid_file_html .= '<p>' . $num_image_string . 'been successfully imported into Reason.</p>';
         $valid_file_html .= '<p>They are now pending.</p>';
         $next_steps[] = '<a href="?site_id=' . $site_id . '&amp;type_id=' . id_of('image') . '&amp;user_id=' . $this->user_id . '&amp;cur_module=Lister&amp;state=pending">review & approve imported images</a>';
     }
     if (isset($this->invalid_files)) {
         $invalid_files = array_keys($this->invalid_files);
         $invalid_file_html = '<p>The following could not be validated as image files and were not successfully imported.</p>';
         $invalid_file_html .= '<ul>';
         foreach ($invalid_files as $file) {
             $invalid_file_html .= '<li><strong>' . reason_htmlspecialchars($file) . '</strong></li>';
         }
         $invalid_file_html .= '</ul>';
     }
     $next_steps[] = '<a href="' . get_current_url() . '">Import another set of images</a>';
     if (!isset($this->invalid_files) && !isset($this->files)) {
         echo '<p>You did not select any files for upload</p>';
     }
     if (isset($valid_file_html)) {
         echo $valid_file_html;
     }
     if (isset($invalid_file_html)) {
         echo $invalid_file_html;
     }
     echo '<p>Next Steps:</p><ul><li>' . implode('</li><li>', $next_steps) . '</li></ul>';
     $this->show_form = false;
 }
예제 #4
0
	function process()
	{	
		$description = trim(tidy($this->get_value('description')));
		$content = trim(get_safer_html(tidy($this->get_value('post_content'))));
		if(carl_empty_html($description))
		{
			$words = explode(' ', $content, 31);
			unset($words[count($words)-1]);
			$description = implode(' ', $words).'…';
			$description = trim(tidy($description)); // we're tidying it twice so that if we chop off a closing tag tidy will stitch it back up again
		}
		
		if(!empty($this->user_netID))
		{
			$user_id = make_sure_username_is_user($this->user_netID, $this->site_info->id());
		}
		else
		{
			$user_id = $this->site_info->id();
		}
		
		if($this->hold_posts_for_review)
		{
			$status = 'pending';
		}
		else
		{
			$status = 'published';
		}

		$values = array (
			'status' => $status,
			'release_title' => trim(strip_tags($this->get_value('title'))),
			'author' => trim(strip_tags($this->get_value('author'))),
			'content' => $content,
			'description' => $description,
			'datetime' => date('Y-m-d H:i:s', time()),
			'keywords' => implode(', ', array(strip_tags($this->get_value('title')), date('Y'), date('F'))),
			'show_hide' => 'show',
			'new' => 0
		);
				
		$this->new_post_id = reason_create_entity( 
			$this->site_info->id(), 
			id_of('news'), 
			$user_id, 
			$values['release_title'], 
			$values
		);
		
		create_relationship(
			$this->new_post_id,
			$this->publication->id(),
			relationship_id_of('news_to_publication')
		);

		if ($this->successfully_submitted())
		{
			
			if($this->hold_posts_for_review)
			{
				echo '<p>Posts are being held for review on this publication. Please check back later to see if your post has been published.</p>';
				echo '<a href="?">Back to main page</a>';
			
			}
			else
			{
				echo '<p>Your post has been published.</p>';
				echo '<a href="'.carl_construct_redirect(array('story_id'=>$this->new_post_id)).'">View it.</a>';
			}
		}
		
		if($this->get_value('issue'))
		{
			create_relationship($this->new_post_id, $this->get_value('issue'), relationship_id_of('news_to_issue'));
		}
		
		if($this->get_value('section'))
		{
			create_relationship($this->new_post_id, $this->get_value('section'), relationship_id_of('news_to_news_section'));
		}
		
		if($this->get_value('categories'))
		{
			foreach($this->get_value('categories') as $category_id)
			{
				// Check to make sure ids posted actually belong to categories in the site
				if(array_key_exists($category_id, $this->categories))
				{
					create_relationship(
						$this->new_post_id,
						$category_id,
						relationship_id_of('news_to_category')
					);
				}
			}
		}
		
		$this->show_form = false;

		$this->do_notifications();
	}
예제 #5
0
	function process()
	{
		if(!empty($this->username))
		{
			$user_id = make_sure_username_is_user($this->username, $this->site_id);
		}
		else
		{
			$user_id = $this->site_info->id();
		}

		if($this->hold_comments_for_review)
		{
			$show_hide = 'hide';
		}
		else
		{
			$show_hide = 'show';
		}
		$flat_values = array (
			'state' => 'Live',
			'author' => trim(get_safer_html(strip_tags($this->get_value('author')))),
			'content' => trim(get_safer_html(strip_tags(tidy($this->get_value('comment_content')), '<p><em><strong><a><ol><ul><li><blockquote><acronym><abbr><br><cite><code><pre>'))),
			'datetime' => date('Y-m-d H:i:s'),
			'show_hide' => $show_hide,
			'new'=>'0',
		);

		$this->comment_id = reason_create_entity( 
			$this->site_id, 
			id_of('comment_type'), 
			$user_id, 
			trim(substr(strip_tags($flat_values['content']),0,40)),
			$flat_values,
			$testmode = false
		);
		
		create_relationship(
			$this->news_item->_id,
			$this->comment_id,
			relationship_id_of('news_to_comment')
		);
		$this->do_notifications();
	}