From: Steve Sutton Date: Mon, 28 Sep 2015 13:51:09 +0000 (-0400) Subject: Update for images X-Git-Tag: v0.0.2^2~4 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=8b23d43dd442d1027fc5114da8df69e83edf0dca;p=WP-Plugins%2Fglm-wp-importer.git Update for images uncomment actions --- diff --git a/controllers/EventImageImport.php b/controllers/EventImageImport.php index 4ffce76..402747b 100644 --- a/controllers/EventImageImport.php +++ b/controllers/EventImageImport.php @@ -223,141 +223,6 @@ return $filename; } - private function _getPageTitleById($id) - { - $this->_connect(); - if ($this->_options['toolbox_page_table'] == 'pages') { - $sql = " - SELECT navigation_name - FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']} - WHERE id = :id"; - } else { - $sql = " - SELECT category as navigation_name - FROM {$this->_options['toolbox_schema']}.{$this->_options['toolbox_page_table']} - WHERE id = :id"; - } - $stmt = $this->_dbh->prepare($sql); - $stmt->bindParam(':id', $id, PDO::PARAM_INT); - $stmt->execute(); - return $stmt->fetchColumn(); - } - - private function _updateFilesHref() - { - global $wpdb; - $currentPostArray = get_option(GLM_WP_IMPORT_POST_OPTION, array()); - $files = get_option(GLM_WP_IMPORT_FILES_OPTION, array()); - echo '
' . print_r($files, true) . '
'; - //$images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array()); - //$media = array_merge($images, $files); - //echo '
' . print_r($media, true) . '
'; - $sql = " - SELECT * - FROM {$wpdb->prefix}posts - WHERE post_content LIKE '%http://is0.gaslightmedia.com%' - AND post_type = 'page'"; - $sql .= " AND ID IN (" . implode(',', $currentPostArray) . ")"; - $results = $wpdb->get_results($sql, OBJECT); - if (count($results) > 0) { - foreach ($results as $post) { - $content = $post->post_content; - echo '
'; - $urlPattern = '%]*)" ?[^>]*>([^>]+)%s'; - if (preg_match_all($urlPattern, $content, $isMatch)) { - $isMatchCount = count($isMatch[0]); - echo '

Matches is0 ' . $isMatchCount . '

'; - for ($index = 0; $index < $isMatchCount; ++$index) { - echo '
'.htmlspecialchars($isMatch[1][$index]).'
'; - //echo '
'.htmlspecialchars(basename($isMatch[1][$index])).'
'; - //echo '
'.print_r(pathinfo($isMatch[1][$index]), true).'
'; - $fileInfo = pathinfo($isMatch[1][$index]); - $fileName = $fileInfo['filename']; - echo '
File Name: ' . print_r($fileName, true)  . '
'; - echo '
File Name: ' . print_r($fileInfo, true)  . '
'; - $fileTitle = $isMatch[2][$index]; - echo '
File Title: ' . print_r($fileTitle, true)  . '
'; - $key = $this->_getAttachmentByName($fileName); - echo '
Key: ' . print_r($key, true)  . '
'; - // check on format of filename - if (!$key && ($fileName && $fileTitle)) { - $key = $this->_handleMediaFile( - $fileName, - $fileTitle, - '', - $post->ID, - $this->_options['site_url'] . '/uploads/' - ); - } - if ($key !== false) { - var_dump($key); - $newSrc = wp_get_attachment_url($key); - $content = str_replace($isMatch[1][$index], $newSrc, $content); - } - } - $updatePost = array( - 'ID' => $post->ID, - 'post_content' => $content - ); - wp_update_post($updatePost); - } - echo '
'.htmlspecialchars($content).'
'; - echo '
'; - } - } - } - - private function replaceIsoUrls() - { - global $wpdb; - $this->_connect(); - echo '

Replace IS0 url\'s

'; - $searchUrl = 'http://is0.gaslightmedia.com'; - // find all pages with links to site pages - $sql = " - SELECT * - FROM {$wpdb->prefix}posts - WHERE post_content LIKE '%{$searchUrl}%' - AND post_type = 'page'"; - echo '
'.$sql.'
'; - $results = $wpdb->get_results($sql, OBJECT); - if (count($results) > 0) { - //echo '
' . print_r($results, true) . '
'; - $pattern = ';(http://is0.gaslightmedia.com/[^"]+);si'; - foreach ($results as $post) { - $content = $post->post_content; - preg_match_all($pattern, $post->post_content, $matches); - $matches = array_unique($matches[0]); - echo '
' . print_r($post->ID, true) . '
'; - echo '
' . print_r($matches, true) . '
'; - foreach ($matches as $match) { - // process the file as media library - $parsed = parse_url($match); - $filename = basename($parsed['path']); - $rootUrl = str_replace('/' . $filename, '', $match); - echo '
' . print_r($parsed, true) . '
'; - echo '
' . print_r($filename, true) . '
'; - echo '
' . print_r($rootUrl, true) . '
'; - $img_id = $this->_handleMediaFile( - $filename, - '', - $post->ID, - $rootUrl . '/' - ); - echo '
' . print_r($img_id, true) . '
'; - $replaceUrl = wp_get_attachment_url($img_id); - echo '
' . print_r($image, true) . '
'; - $content = str_replace($match, $replaceUrl, $content); - } - $updatePost = array( - 'ID' => $post->ID, - 'post_content' => $content - ); - wp_update_post($updatePost); - } - } - } - private function _fetchAllEventImages() { global $wpdb; @@ -373,31 +238,31 @@ while( $event = $stmt->fetch() ) { //echo '
' . print_r($event, true) . '
'; $images[] = $event['img']; - //$sql = " - //SELECT * - //FROM {$wpdb->prefix}ai1ec_events - //WHERE ical_uid = '{$event['id']}@emmetcounty.org'"; - //$results = $wpdb->get_results($sql, ARRAY_A); - //echo '
Results: ' . print_r($results, true)  . '
'; - //if ($results) { - //$ePost = get_post($results[0]['post_id'], ARRAY_A); - //$img_id = $this->_handleMediaFile( - //$event['img'], - //'', - //'', - //$results[0]['post_id'], - //$this->_options['toolbox_image_url'] . '/CKImage' - //); - //echo '
Image Id: ' . print_r($img_id, true) . '
'; - //echo '
Results: ' . print_r($ePost['ID'], true)  . '
'; - //if ($img_id) { - //update_post_meta( - //$results[0]['post_id'], - //'_thumbnail_id', - //$img_id - //); - //} - //} + $sql = " + SELECT * + FROM {$wpdb->prefix}ai1ec_events + WHERE ical_uid = '{$event['id']}@emmetcounty.org'"; + $results = $wpdb->get_results($sql, ARRAY_A); + echo '
Results: ' . print_r($results, true)  . '
'; + if ($results) { + $ePost = get_post($results[0]['post_id'], ARRAY_A); + $img_id = $this->_handleMediaFile( + $event['img'], + '', + '', + $results[0]['post_id'], + $this->_options['toolbox_image_url'] . '/CKImage' + ); + echo '
Image Id: ' . print_r($img_id, true) . '
'; + echo '
Results: ' . print_r($ePost['ID'], true)  . '
'; + if ($img_id) { + update_post_meta( + $results[0]['post_id'], + '_thumbnail_id', + $img_id + ); + } + } } sort($images, SORT_NATURAL); $imgUnique = array_unique($images); @@ -420,7 +285,6 @@ echo '

Import Images

'; break; case 1: - //echo '

Weeee!!!!

'; $this->_fetchAllEventImages(); break; }