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 '<pre>' . print_r($files, true) . '</pre>';
- //$images = get_option(GLM_WP_IMPORT_IMAGES_OPTION, array());
- //$media = array_merge($images, $files);
- //echo '<pre>' . print_r($media, true) . '</pre>';
- $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 '<div style="border: 1px solid green; padding: 9px; margin: 10px;">';
- $urlPattern = '%<a href="(' . $this->_options['toolbox_image_url'] . '/[^">]*)" ?[^>]*>([^>]+)</a>%s';
- if (preg_match_all($urlPattern, $content, $isMatch)) {
- $isMatchCount = count($isMatch[0]);
- echo '<p>Matches is0 ' . $isMatchCount . '</p>';
- for ($index = 0; $index < $isMatchCount; ++$index) {
- echo '<pre>'.htmlspecialchars($isMatch[1][$index]).'</pre>';
- //echo '<pre>'.htmlspecialchars(basename($isMatch[1][$index])).'</pre>';
- //echo '<pre>'.print_r(pathinfo($isMatch[1][$index]), true).'</pre>';
- $fileInfo = pathinfo($isMatch[1][$index]);
- $fileName = $fileInfo['filename'];
- echo '<pre>File Name: ' . print_r($fileName, true) . '</pre>';
- echo '<pre>File Name: ' . print_r($fileInfo, true) . '</pre>';
- $fileTitle = $isMatch[2][$index];
- echo '<pre>File Title: ' . print_r($fileTitle, true) . '</pre>';
- $key = $this->_getAttachmentByName($fileName);
- echo '<pre>Key: ' . print_r($key, true) . '</pre>';
- // 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 '<pre>'.htmlspecialchars($content).'</pre>';
- echo '</div>';
- }
- }
- }
-
- private function replaceIsoUrls()
- {
- global $wpdb;
- $this->_connect();
- echo '<p>Replace IS0 url\'s</p>';
- $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 '<pre>'.$sql.'</pre>';
- $results = $wpdb->get_results($sql, OBJECT);
- if (count($results) > 0) {
- //echo '<pre>' . print_r($results, true) . '</pre>';
- $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 '<pre>' . print_r($post->ID, true) . '</pre>';
- echo '<pre>' . print_r($matches, true) . '</pre>';
- foreach ($matches as $match) {
- // process the file as media library
- $parsed = parse_url($match);
- $filename = basename($parsed['path']);
- $rootUrl = str_replace('/' . $filename, '', $match);
- echo '<pre>' . print_r($parsed, true) . '</pre>';
- echo '<pre>' . print_r($filename, true) . '</pre>';
- echo '<pre>' . print_r($rootUrl, true) . '</pre>';
- $img_id = $this->_handleMediaFile(
- $filename,
- '',
- $post->ID,
- $rootUrl . '/'
- );
- echo '<pre>' . print_r($img_id, true) . '</pre>';
- $replaceUrl = wp_get_attachment_url($img_id);
- echo '<pre>' . print_r($image, true) . '</pre>';
- $content = str_replace($match, $replaceUrl, $content);
- }
- $updatePost = array(
- 'ID' => $post->ID,
- 'post_content' => $content
- );
- wp_update_post($updatePost);
- }
- }
- }
-
private function _fetchAllEventImages()
{
global $wpdb;
while( $event = $stmt->fetch() ) {
//echo '<pre>' . print_r($event, true) . '</pre>';
$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 '<pre>Results: ' . print_r($results, true) . '</pre>';
- //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 '<pre>Image Id: ' . print_r($img_id, true) . '</pre>';
- //echo '<pre>Results: ' . print_r($ePost['ID'], true) . '</pre>';
- //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 '<pre>Results: ' . print_r($results, true) . '</pre>';
+ 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 '<pre>Image Id: ' . print_r($img_id, true) . '</pre>';
+ echo '<pre>Results: ' . print_r($ePost['ID'], true) . '</pre>';
+ if ($img_id) {
+ update_post_meta(
+ $results[0]['post_id'],
+ '_thumbnail_id',
+ $img_id
+ );
+ }
+ }
}
sort($images, SORT_NATURAL);
$imgUnique = array_unique($images);
echo '<p><a href="admin.php?import=eventimages&step=1">Import Images</a></p>';
break;
case 1:
- //echo '<p>Weeee!!!!</p>';
$this->_fetchAllEventImages();
break;
}