Changeset 1363
- Timestamp:
- 03/20/10 12:19:33 (3 years ago)
- Location:
- branches/1.2/content/plugins/autoreader
- Files:
-
- 5 edited
-
autoreader.php (modified) (11 diffs)
-
autoreader_settings.php (modified) (32 diffs)
-
templates/autoreader_add.php (modified) (15 diffs)
-
templates/autoreader_dashboard.php (modified) (2 diffs)
-
templates/autoreader_options.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.2/content/plugins/autoreader/autoreader.php
r1334 r1363 7 7 * class: Autoreader 8 8 * type: autoreader 9 * hooks: install_plugin, admin_ header_include, admin_plugin_settings, admin_sidebar_plugin_settings, admin_plugin_dropdown_menu, autoreader_runcron9 * hooks: install_plugin, admin_plugin_settings, admin_sidebar_plugin_settings, autoreader_runcron, admin_theme_index_top 10 10 * 11 11 * PHP version 5 … … 51 51 52 52 53 54 55 /** 56 * Install or Upgrade 57 */ 58 public function install_plugin($h) 59 { 60 // ************ 61 // PERMISSIONS 62 // ************ 63 64 // ************ 65 // SETTINGS 66 // ************ 67 // Get settings from database if they exist... 68 $autoreader_settings = $h->getSerializedSettings(); 69 if (!isset($autoreader_settings['wpo_log'])) { $autoreader_settings['wpo_log'] = true; } 70 if (!isset($autoreader_settings['wpo_log_stdout'])) { $autoreader_settings['wpo_log_stdout'] = false; } 71 if (!isset($autoreader_settings['wpo_unixcron'])) { $autoreader_settings['wpo_unixcron'] = false; } 72 if (!isset($autoreader_settings['wpo_cacheimage'])) { $autoreader_settings['wpo_cacheimage'] = 0; } 73 if (!isset($autoreader_settings['wpo_croncode'])) { $autoreader_settings['wpo_croncode'] = substr(md5(time()), 0, 8); } 74 if (!isset($autoreader_settings['wpo_cachepath'])) { $autoreader_settings['wpo_cachepath'] = 'cache'; } 75 if (!isset($autoreader_settings['wpo_help'])) { $autoreader_settings['wpo_help'] = false; } 76 if (!isset($autoreader_settings['wpo_premium'])) { $autoreader_settings['wpo_premium'] = false; } 77 78 $h->updateSetting('autoreader_settings', serialize($autoreader_settings)); 79 80 $this->activate($h); 81 } 82 83 84 /** 85 * Constructor for autoreader 86 */ 87 public function autoreader($h) 88 { 89 $autoreader_settings = $h->getSerializedSettings('autoreader'); 90 91 // Table names init 53 public function admin_theme_index_top($h) { 54 print "top"; 55 if ($h->cage->get->testAlnumLines('plugin') == 'autoreader') { 56 print "here"; 57 $h->vars['autoreader_settings'] = $h->getSerializedSettings('autoreader'); 58 print_r( $h->vars['autoreader_settings'] ); 59 60 // Table names init 92 61 $this->db = array( 93 62 'campaign' => DB_PREFIX . 'autoreader_campaign', … … 99 68 ); 100 69 101 $this->pluginpath = BASEURL . 'plugins/autoreader';102 // $this->cachepath = BASEURL . get_option('wpo_cachepath');70 $this->pluginpath = PLUGINS . '/autoreader/'; 71 $this->cachepath = $this->pluginpath . $h->vars['autoreader_settings']['wpo_cachepath']; 103 72 104 73 # Cron command / url 105 $this->cron_url = $this->pluginpath . '/cron.php?code=' . $ autoreader_settings['wpo_croncode'];74 $this->cron_url = $this->pluginpath . '/cron.php?code=' . $h->vars['autoreader_settings']['wpo_croncode']; 106 75 $this->cron_command = '*/20 * * * * '. $this->getCommand() . ' ' . $this->cron_url; 76 77 78 79 } 80 } 81 82 /** 83 * Install or Upgrade 84 */ 85 public function install_plugin($h) 86 { 87 // ************ 88 // PERMISSIONS 89 // ************ 90 91 // ************ 92 // SETTINGS 93 // ************ 94 // Get settings from database if they exist... 95 $autoreader_settings = $h->getSerializedSettings(); 96 if (!isset($autoreader_settings['wpo_log'])) { $autoreader_settings['wpo_log'] = true; } 97 if (!isset($autoreader_settings['wpo_log_stdout'])) { $autoreader_settings['wpo_log_stdout'] = false; } 98 if (!isset($autoreader_settings['wpo_unixcron'])) { $autoreader_settings['wpo_unixcron'] = false; } 99 if (!isset($autoreader_settings['wpo_cacheimages'])) { $autoreader_settings['wpo_cacheimages'] = 0; } 100 if (!isset($autoreader_settings['wpo_croncode'])) { $autoreader_settings['wpo_croncode'] = substr(md5(time()), 0, 8); } 101 if (!isset($autoreader_settings['wpo_cachepath'])) { $autoreader_settings['wpo_cachepath'] = 'cache'; } 102 if (!isset($autoreader_settings['wpo_help'])) { $autoreader_settings['wpo_help'] = false; } 103 if (!isset($autoreader_settings['wpo_premium'])) { $autoreader_settings['wpo_premium'] = false; } 104 105 $h->updateSetting('autoreader_settings', serialize($autoreader_settings)); 106 107 $this->activate($h); 107 108 } 109 108 110 109 111 … … 120 122 { 121 123 # autoreader_campaign 122 $exists = $h->db->table_exists( $this->db['campaign']);123 if (!$exists) { 124 $h->db->query ( "CREATE TABLE " . $this->db['campaign'] . " (124 $exists = $h->db->table_exists(str_replace(DB_PREFIX, "", $this->db['campaign'])); 125 if (!$exists) { 126 $h->db->query ( "CREATE TABLE " . $this->db['campaign'] . " ( 125 127 id int(11) unsigned NOT NULL auto_increment, 126 128 title varchar(255) NOT NULL default '', … … 147 149 148 150 # autoreader_campaign_category 149 $exists = $h->db->table_exists( $this->db['campaign_category']);151 $exists = $h->db->table_exists( str_replace(DB_PREFIX, "", $this->db['campaign_category'])); 150 152 if (!$exists) { 151 153 $h->db->query ( "CREATE TABLE " . $this->db['campaign_category'] . " ( … … 159 161 160 162 # autoreader_campaign_feed 161 $exists = $h->db->table_exists( $this->db['campaign_feed']);163 $exists = $h->db->table_exists(str_replace(DB_PREFIX, "", $this->db['campaign_feed'])); 162 164 if (!$exists) { 163 165 $h->db->query ( "CREATE TABLE " . $this->db['campaign_feed'] . " ( … … 178 180 179 181 # autoreader_campaign_post 180 $exists = $h->db->table_exists( $this->db['campaign_post']);182 $exists = $h->db->table_exists(str_replace(DB_PREFIX, "", $this->db['campaign_post'])); 181 183 if (!$exists) { 182 184 $h->db->query ( "CREATE TABLE " . $this->db['campaign_post'] . " ( … … 192 194 193 195 # autoreader_campaign_word 194 $exists = $h->db->table_exists( $this->db['campaign_word']);196 $exists = $h->db->table_exists(str_replace(DB_PREFIX, "", $this->db['campaign_word'])); 195 197 if (!$exists) { 196 198 $h->db->query ( "CREATE TABLE " . $this->db['campaign_word'] . " ( … … 208 210 209 211 # autoreader_log 210 $exists = $h->db->table_exists( $this->db['log']);212 $exists = $h->db->table_exists(str_replace(DB_PREFIX, "", $this->db['log'])); 211 213 if (!$exists) { 212 214 $h->db->query ( "CREATE TABLE " . $this->db['log'] . " ( … … 263 265 /** 264 266 * Checks that autoreader tables exist 265 * 267 * 266 268 * 267 269 */ … … 279 281 public function autoreader_runcron($h, $args) { 280 282 $cid = $args['id']; 281 //print_r ($args);282 283 283 284 $this->forcefetched = $this->processCampaign($h,$cid); 284 285 } 285 286 287 288 286 289 287 290 288 } -
branches/1.2/content/plugins/autoreader/autoreader_settings.php
r1334 r1363 90 90 */ 91 91 public function getOptionSettings($h, $options = null) 92 { 93 if ($h->cage->post->testAlpha('action') == "save" ) { 92 { 93 $autoreader_settings = $h->getSerializedSettings('autoreader'); 94 95 if ($h->cage->post->testAlpha('action') == "save" ) { 96 $autoreader_settings['wpo_log'] = $h->cage->post->keyExists('option_logging'); 97 $autoreader_settings['wpo_log_stdout'] = $h->cage->post->keyExists('option_log_stdout'); 98 $autoreader_settings['wpo_unixcron'] = $h->cage->post->keyExists('option_unixcron'); 99 $autoreader_settings['wpo_croncode'] = $h->cage->post->keyExists('option_croncode'); 100 $autoreader_settings['wpo_cacheimages'] = $h->cage->post->keyExists('option_caching'); 101 $autoreader_settings['wpo_cachepath'] = $h->cage->post->testPage('option_cachepath'); 102 103 $h->updateSetting('autoreader_settings', serialize($autoreader_settings),'autoreader'); 94 104 $array = array('saved' => 'true'); 95 $autoreader_settings['wpo_log'] = $h->cage->post->testAlnumLines('option_logging');96 $autoreader_settings['wpo_log_stdout'] = $h->cage->post->testAlnumLines('option_log_stdout');97 $autoreader_settings['wpo_unixcron'] = $h->cage->post->testAlnumLines('option_unixcron');98 $autoreader_settings['wpo_croncode'] = $h->cage->post->testAlnumLines('option_croncode');99 $autoreader_settings['wpo_cacheimage'] = $h->cage->post->testAlnumLines('option_cachimage');100 $autoreader_settings['wpo_cachepath'] = $h->cage->post->testAlnumLines('option_cachepath');101 102 $h->updateSetting('autoreader_settings', serialize($autoreader_settings));103 105 } 104 else { 105 $autoreader_settings = $h->getSerializedSettings('autoreader'); 106 else { 106 107 $array = $autoreader_settings; 107 108 } … … 310 311 311 312 // Reset count and lasactive 312 $ wpdb->query(WPOTools::updateQuery($this->db['campaign'], array(313 $h->db->query(WPOTools::updateQuery($this->db['campaign'], array( 313 314 'count' => 0, 314 315 'lastactive' => 0 … … 318 319 foreach($this->getCampaignFeeds($h, $id) as $feed) 319 320 { 320 $ wpdb->query(WPOTools::updateQuery($this->db['campaign_feed'], array(321 $h->db->query(WPOTools::updateQuery($this->db['campaign_feed'], array( 321 322 'count' => 0, 322 323 'lastactive' => 0, … … 325 326 } 326 327 327 // delete any cron jobs for this campaign ?328 //no need to delete cron jobs here 328 329 329 330 $arr = array('id'=> $id); … … 465 466 * @return integer Number of processed items 466 467 */ 467 function processCampaign($h, &$campaign)468 function processCampaign($h, $campaign) 468 469 { 469 470 @set_time_limit(0); … … 473 474 $campaign = is_numeric($campaign) ? $this->getCampaignById($h,$campaign) : $campaign; 474 475 475 // Log 476 $this->log($h, 'Processing campaign ' . $campaign->title . ' (ID: ' . $campaign->id . ')'); 477 478 // Get feeds 479 $count = 0; 480 $feeds = $this->getCampaignFeeds($h, $campaign->id); 481 482 foreach($feeds as $feed) 483 $count += $this->processFeed($h, $campaign, $feed); 484 485 $h->db->query(WPOTools::updateQuery($this->db['campaign'], array( 486 'count' => $campaign->count + $count, 487 'lastactive' => current_time('mysql', true) 488 ), "id = {$campaign->id}")); 489 490 return $count; 476 if ($campaign) { 477 478 // Log 479 $this->log($h, 'Processing campaign ' . $campaign->title . ' (ID: ' . $campaign->id . ')'); 480 481 // Get feeds 482 $count = 0; 483 $feeds = $this->getCampaignFeeds($h, $campaign->id); 484 485 foreach($feeds as $feed) 486 $count += $this->processFeed($h, $campaign, $feed); 487 488 $h->db->query(WPOTools::updateQuery($this->db['campaign'], array( 489 'count' => $campaign->count + $count, 490 'lastactive' => current_time('mysql', true) 491 ), "id = {$campaign->id}")); 492 493 return $count; 494 495 } 491 496 } 492 497 … … 592 597 $date = null;*/ 593 598 594 if($campaign->feeddate)599 if($campaign->feeddate) 595 600 $date = $item->get_date('U'); 596 601 else … … 604 609 $root=$_SERVER['HTTP_HOST']; 605 610 606 // $posturl=file_get_contents(" http://$root/wp-content/plugins/wp-o-matic/original_url.php?blog=$permalink");611 // $posturl=file_get_contents("/original_url.php?blog=$permalink"); 607 612 // $posturl = $this->get_sourceurl($permalink); 608 $posturl = $permalink;613 $posturl = $permalink; 609 614 610 615 … … 617 622 618 623 619 //tags624 //tags 620 625 $post_tags=$item->get_categories(); 621 626 … … 663 668 function isDuplicate($h, &$campaign, &$feed, &$item) 664 669 { 665 $hash = $this->getItemHash($item); 666 $row = $h->db->get_row("SELECT * FROM {$this->db['campaign_post']} " 667 . "WHERE campaign_id = {$campaign->id} AND feed_id = {$feed->id} AND hash = '$hash' "); 670 $row = $h->urlExists($item->get_permalink()); 671 //$hash = $this->getItemHash($item); 672 //$row = $h->db->get_row("SELECT * FROM {$this->db['campaign_post']} " 673 // . "WHERE campaign_id = {$campaign->id} AND feed_id = {$feed->id} AND hash = '$hash' "); 668 674 return !! $row; 669 675 } … … 671 677 672 678 /** 673 * Writes a post to blog679 * Submit a post to db 674 680 * 675 681 * … … 687 693 function insertPost($h, $title, $content, $timestamp = null, $category = null, $tags= null, $status = 'pending', $authorid = null, $allowpings = true, $comment_status = 'open', $meta = array()) 688 694 { 689 $date = ($timestamp) ? gmdate('Y-m-d H:i:s', $timestamp + (get_option('gmt_offset') * 3600)) : null; 695 $date = $timestamp; 696 //$date = ($timestamp) ? gmdate('Y-m-d H:i:s', $timestamp + (get_option('gmt_offset') * 3600)) : null; 690 697 691 698 $h->post = new Post(); … … 694 701 $h->post->url = make_url_friendly($title); 695 702 $h->post->content = $content; 703 $h->post->date = $date; 696 704 $h->post->type = 'news'; 697 $h->post->category = "";705 $h->post->category = $category[0]; 698 706 $h->post->tags = $tags; 699 $h->post->author = $h->currentUser->id; 707 $h->post->origUrl = $meta["wpo_sourcepermalink"]; 708 $h->post->domain = get_domain($meta["wpo_sourcepermalink"]); 709 $h->post->author = $authorid; 700 710 $h->post->status = $status; 701 711 … … 719 729 */ 720 730 $postid = $h->post->vars['last_insert_id']; 721 722 return $postid; 731 return $postid; 723 732 } 724 733 … … 737 746 738 747 739 740 741 742 743 744 745 746 747 748 749 750 748 /** 751 749 * Checks submitted campaign edit form for errors … … 755 753 */ 756 754 function adminCampaignRequest($h) 757 { 755 { 758 756 $data_active = $h->cage->post->testAlnumLines('campaign_active'); 759 757 $data_template = $h->cage->post->testAlnumLines('campaign_templatechk'); … … 767 765 $this->campaign_data = $this->campaign_structure; 768 766 $this->campaign_data['main'] = array( 769 'title' => $h->cage->post-> testAlnumLines('campaign_title'),770 'active' => (isset( $data_active)),767 'title' => $h->cage->post->getHtmLawed('campaign_title'), 768 'active' => $h->cage->post->keyExists('campaign_active'), 771 769 'slug' => $h->cage->post->testAlnumLines('campaign_slug'), 772 'template' => ( isset($data_template))770 'template' => ($h->cage->post->keyExists('campaign_template')) 773 771 ? $data = $h->cage->post->testAlnumLines('campaign_template') : null, 774 'frequency' => intval($h->cage->post->testInt('campaign_frequency_d')) * 86400775 + intval($h->cage->post->testInt('campaign_frequency_h'))* 3600776 + intval($h->cage->post->testInt('campaign_frequency_m')) * 60,777 'cacheimages' => (int) isset( $data_cacheimages),778 'feeddate' => (int) isset( $data_feeddate),772 'frequency' => $h->cage->post->testInt('campaign_frequency_d') * 86400 773 + $h->cage->post->testInt('campaign_frequency_h') //* 3600 774 + $h->cage->post->testInt('campaign_frequency_m') * 60, 775 'cacheimages' => $h->cage->post->keyExists( 'campaign_cacheimages'), 776 'feeddate' => $h->cage->post->keyExists( 'campaign_feeddate'), 779 777 'posttype' => $h->cage->post->testAlpha('campaign_posttype'), 780 778 'author' => $h->cage->post->testAlpha('campaign_author'), 781 'comment_status' => $h->cage->post->testAlpha('campaign_commentstatus'),782 'allowpings' => (int) isset($data_allowpings),783 'dopingbacks' => (int) isset( $data_dopingbacks),784 'max' => intval($h->cage->post->testInt('campaign_max')),785 'linktosource' => (int) isset($data_linktosource)779 'comment_status'=> $h->cage->post->testAlpha('campaign_commentstatus'), 780 'allowpings' => $h->cage->post->keyExists('campaign_allowpings'), 781 'dopingbacks' => $h->cage->post->keyExists('campaign_dopingbacks'), 782 'max' => $h->cage->post->testInt('campaign_max'), 783 'linktosource' => $h->cage->post->keyExists('campaign_linktosource') 786 784 ); 787 785 … … 793 791 { 794 792 $feed = trim($feed); 795 796 793 if(!empty($feed)) 797 794 { … … 804 801 805 802 // Existing feeds to delete 806 if( isset($data['campaign_feed']['delete']))807 { 803 if($h->cage->post->keyExists('/campaign_feed/delete')) 804 { 808 805 $this->campaign_data['feeds']['delete'] = array(); 809 810 foreach($data['campaign_feed']['delete'] as $feedid => $yes) 811 $this->campaign_data['feeds']['delete'][] = intval($feedid); 806 foreach($h->cage->post->getRaw('/campaign_feed/delete') as $feedid => $yes) 807 $this->campaign_data['feeds']['delete'][] = intval($feedid); 812 808 } 813 809 814 810 // Existing feeds. 815 if( isset($data['id']))811 if($h->cage->post->keyExists('campaign_edit')) 816 812 { 817 813 $this->campaign_data['feeds']['edit'] = array(); 818 foreach($this->getCampaignFeeds( intval($data['id'])) as $feed)814 foreach($this->getCampaignFeeds($h,intval($h->cage->post->testInt('campaign_edit'))) as $feed) 819 815 $this->campaign_data['feeds']['edit'][$feed->id] = $feed->url; 820 816 } 821 817 822 818 // Categories 823 if(isset($data['campaign_categories'])) 824 { 825 foreach($data['campaign_categories'] as $category) 826 { 827 $id = intval($category); 828 $this->campaign_data['categories'][] = $category; 829 } 819 if($h->cage->post->keyExists('campaign_categories') ) 820 { 821 foreach($h->cage->post->keyExists('campaign_categories') as $key => $value) { 822 $this->campaign_data['categories'][] = $value; 823 } 830 824 } 831 825 832 826 # New categories 833 if( isset($data['campaign_newcat']))834 { 835 foreach($ data['campaign_newcat']as $k => $on)836 { 837 $catname = $ data['campaign_newcatname'][$k];827 if($h->cage->post->keyExists('campaign_newcat') ) 828 { 829 foreach($h->cage->post->keyExists('campaign_newcat') as $k => $on) 830 { 831 $catname = $on; 838 832 if(!empty($catname)) 839 833 { … … 847 841 848 842 // Rewrites 849 if( isset($data['campaign_word_origin']))850 { 851 foreach($ data['campaign_word_origin']as $id => $origin_data)843 if($h->cage->post->keyExists('campaign_word_origin') ) 844 { 845 foreach($h->cage->post->keyExists('campaign_word_origin') as $id => $origin_data) 852 846 { 853 847 $rewrite = isset($data['campaign_word_option_rewrite']) … … 882 876 } 883 877 884 $errors = array(' basic' => array(), 'feeds' => array(), 'categories' => array(),878 $errors = array('errors'=>0, 'basic' => array(), 'feeds' => array(), 'categories' => array(), 885 879 'rewrite' => array(), 'options' => array()); 880 $this->errno = 0; 886 881 887 882 # Main … … 942 937 943 938 # Options 944 // if(! get_userdatabylogin($this->campaign_data['main']['author'])) 945 // { 946 // $errors['options'][] = __('Author username not found', 'wpomatic'); 947 // $this->errno++; 948 // } 939 //Allow blank username as code will allocate currentuser when writing to sql db 940 //if(! $h->getUserIdFromName($this->campaign_data['main']['author'])) 941 //{ 942 // $errors['options'][] = 'Author username not found'; 943 // $this->errno++; 944 //} 949 945 950 946 if(! $this->campaign_data['main']['frequency']) … … 960 956 } 961 957 962 if($this->campaign_data['main']['cacheimages'] && !is_writable($this->cachepath)) 963 { 964 $errors['options'][] = 'Cache path (in <a href="' . $this->adminurl . '&s=options">Options</a>) must be writable before enabling image caching.'; 958 //print "cacheimages: " . $this->campaign_data['main']['cacheimages']; 959 if($this->campaign_data['main']['cacheimages'] && !is_writable( $this->cachepath)) 960 { 961 $errors['options'][] = 'Cache path must be present and writable before enabling image caching.'; 965 962 $this->errno++; 966 963 } 967 964 965 $errors['errors'] = $this->errno; 968 966 $this->errors = $errors; 969 return $errors; 970 //print_r ( $this->errors); 967 968 return json_encode($errors); 969 971 970 //exit; 972 971 } … … 1015 1014 } 1016 1015 1017 # All 1016 # All 1018 1017 foreach($this->campaign_data['categories'] as $category) 1019 1018 { 1020 1019 // Insert 1021 $ wpdb->query(WPOTools::insertQuery($this->db['campaign_category'],1020 $h->db->query(WPOTools::insertQuery($this->db['campaign_category'], 1022 1021 array('category_id' => $category, 1023 1022 'campaign_id' => $id) … … 1037 1036 { 1038 1037 foreach($this->campaign_data['feeds']['delete'] as $feed) 1039 $ wpdb->query("DELETE FROM {$this->db['campaign_feed']} WHERE id = $feed ");1038 $h->db->query("DELETE FROM {$this->db['campaign_feed']} WHERE id = $feed "); 1040 1039 } 1041 1040 … … 1043 1042 foreach($this->campaign_data['rewrites'] as $rewrite) 1044 1043 { 1045 $wpdb->query(WPOTools::insertQuery($this->db['campaign_word'],1044 $h->db->query(WPOTools::insertQuery($this->db['campaign_word'], 1046 1045 array('word' => $rewrite['origin']['search'], 1047 1046 'regex' => $rewrite['origin']['regex'], … … 1056 1055 $main = $this->campaign_data['main']; 1057 1056 1058 // Fetch author id 1059 $main['authorid'] = $h->getUserIdFromName($this->campaign_data['main']['author']); 1057 //Test author name 1058 $authorname = $this->campaign_data['main']['author']; 1059 $userid = $h->getUserIdFromName($authorname); 1060 if ($userid) { $main['authorid'] =$userid; } else { $main['authorid'] = $h->currentUser->id; } 1060 1061 unset($main['author']); 1061 1062 … … 1064 1065 $h->db->query($query); 1065 1066 1066 //get data ready to pass to cron plugin 1067 $timestamp = time(); 1068 switch ($this->campaign_data['main']['frequency']) { 1069 case 43200 : $recurrence = "twicedaily"; break; 1070 case 86400 : $recurrence = "daily"; break; 1071 case 302400 : $recurrence = "weekly"; break; 1072 default : $recurrence = "hourly"; break; 1067 if ($this->campaign_data['main']['active']) { 1068 //get data ready to pass to cron plugin 1069 $timestamp = time(); 1070 switch ($this->campaign_data['main']['frequency']) { 1071 case 43200 : $recurrence = "twicedaily"; break; 1072 case 86400 : $recurrence = "daily"; break; 1073 case 302400 : $recurrence = "weekly"; break; 1074 default : $recurrence = "hourly"; break; 1075 } 1076 $hook = "autoreader_runcron"; 1077 $args = array('id'=> $id); 1078 $cron_data = array('timestamp'=>$timestamp, 'recurrence'=>$recurrence, 'hook'=>$hook, 'args'=>$args); 1079 $h->pluginHook('cron_update_job', 'cron', $cron_data); 1073 1080 } 1074 $hook = "autoreader_runcron"; 1075 $args = array('id'=> $id); 1076 $cron_data = array('timestamp'=>$timestamp, 'recurrence'=>$recurrence, 'hook'=>$hook, 'args'=>$args); 1077 $h->pluginHook('cron_update_job', 'cron', $cron_data); 1081 else 1082 { 1083 $hook = "autoreader_runcron"; 1084 $args = array('id'=> $id); 1085 $cron_data = array('hook'=>$hook, 'args'=>$args); 1086 $h->pluginHook('cron_delete_job', 'cron', $cron_data); 1087 } 1078 1088 1079 1089 // campaign_frequency_d … … 1162 1172 1163 1173 // Caching 1164 if ($ campaign->cacheimages) // set override here for all campaigns get_option('wpo_cacheimages')1174 if ($h->vars['autoreader_settings']['cacheimages'] || $campaign->cacheimages) // set override here for all campaigns get_option('wpo_cacheimages') 1165 1175 { 1166 1176 $images = WPOTools::parseImages($content); … … 1254 1264 { 1255 1265 file_put_contents($cachepath . '/' . $filename, $contents); 1256 return $this->pluginpath . '/' . get_option('wpo_cachepath'). '/' . $filename;1266 return $this->pluginpath . '/' . $h->vars['autoreader_settings']['wpo_cachepath'] . '/' . $filename; 1257 1267 } 1258 1268 … … 1323 1333 { 1324 1334 $campaign_data['main'] = array_merge($campaign_data['main'], $campaign); 1325 // $userdata = get_userdata($campaign_data['main']['authorid']);1326 // $campaign_data['main']['author'] = $userdata->user_login;1335 $userdata = $h->getUserNameFromId($campaign_data['main']['authorid']); 1336 $campaign_data['main']['author'] = $userdata; 1327 1337 } 1328 1338 … … 1332 1342 $categories = $h->db->get_results("SELECT * FROM {$this->db['campaign_category']} WHERE campaign_id = $id"); 1333 1343 if ($categories) { 1334 foreach($categories as $category) 1335 $campaign_data['categories'][] = $category->category_id; 1336 } else { 1337 } 1344 foreach($categories as $category) 1345 $campaign_data['categories'][] = $category->category_id; 1346 } 1338 1347 } 1339 1348 -
branches/1.2/content/plugins/autoreader/templates/autoreader_add.php
r1334 r1363 16 16 break; 17 17 case "save" : 18 $arSettings->adminCampaignRequest($h); 19 if ( $h->cage->post->keyExists('campaign_edit') ) { 20 $cid = $h->cage->post->getInt('campaign_edit'); 21 $arSettings->adminProcessEdit($h,$cid); 18 $errors = $arSettings->adminCampaignRequest($h); 19 print $errors; 20 $arr_errors = json_decode($errors); 21 if ($arr_errors->errors == 0) { 22 if ( $h->cage->post->keyExists('campaign_edit') ) { 23 $cid = $h->cage->post->getInt('campaign_edit'); 24 $arSettings->adminProcessEdit($h,$cid); 25 } 26 else { 27 $arSettings->adminProcessAdd($h); 28 } 22 29 } 23 else {24 $arSettings->adminProcessAdd($h);25 };26 30 exit; // this is an ajax return call, so we don't want any html echoing to the screen 31 case "tools_delete" : 32 $cid = $h->cage->post->getInt('id'); 33 print $cid; 34 //$errors = $arSettings->toolsdelete($h); 35 //print $errors; 36 exit; 27 37 case "test_feed" : 28 38 $data = $h->cage->post->testUri('url'); … … 62 72 <li><input type="submit" name="edit_submit" value="Submit" id="edit_submit" /></li> 63 73 </ul> 64 74 <div id="error_message"></div> 65 75 <div id="admin_plugin_tabs"> 66 76 <ul class="tabs"> … … 101 111 <!-- Feeds section --> 102 112 <div class="section" id="section_feeds"> 103 <p>Please fill in at least one feed. If you \'re not sure about the exact feed url, just type in the domain name, and the feed will be autodetected</p>113 <p>Please fill in at least one feed. If you are not sure about the exact feed url, just type in the domain name, and the feed will be autodetected</p> 104 114 105 115 <div id="edit_feed"> … … 137 147 <!-- Categories section --> 138 148 <div class="section" id="section_categories"> 139 <p>These are the categories where the posts will be created once they 're fetched from the feeds.</p>149 <p>These are the categories where the posts will be created once they are fetched from the feeds.</p> 140 150 <p>Please select one.</p> 141 151 142 152 <ul id="categories"> 143 153 <?php $arSettings->adminEditCategories($h, $data) ?> 154 155 <?php if(isset($data['categories']['new'])): ?> 156 <?php foreach($data['categories']['new'] as $i => $catname): ?> 157 <li> 158 <?php echo checkbox_tag('campaign_newcat[]', 1, true, 'id=campaign_newcat_' . $i) ?> 159 <?php echo input_tag('campaign_newcatname[]', $catname, 'class=input_text id=campaign_newcatname_' . $i) ?> 160 </li> 161 <?php endforeach ?> 162 <?php endif ?> 144 163 </ul> 145 164 165 146 166 <?php if ($autoreader_settings['wpo_premium']) { ?> 147 167 <a href="#quick_add" id="quick_add">Quick add</a> … … 151 171 <!-- Rewrite section --> 152 172 <div class="section" id="section_rewrite"> 173 <?php if ($autoreader_settings['wpo_help']) { ?> 153 174 <p>Want to transform a word into another? Or link a specific word to some website? 154 <?php // echo '<a href=' . $arSettings->helpurl . '" class="help_link">Read more</a>' ?></p>175 <?php // echo '<a href=' . $arSettings->helpurl . '" class="help_link">Read more</a>' ?></p> 155 176 156 177 <ul id="edit_words"> … … 203 224 </ul> 204 225 205 <?php if ($autoreader_settings['wpo_premium']) { ?>226 206 227 <a href="#add_word" id="add_word">Add more</a> 207 <?php } ?> 228 <?php } else { 229 echo "This section is being worked on and will be added in a future release of this plugin."; 230 }?> 231 208 232 </div> 209 233 … … 213 237 <div class="section_warn"> 214 238 <img src="<?php echo $arSettings->tplpath ?>/images/icon_alert.gif" alt="Warning" class="icon" /> 215 <h3> Remember that</h3>239 <h3>Note</h3> 216 240 <p>Changing these options only affects the creation of posts after the next time feeds are parsed.</p> 217 241 <p>If you need to edit existing posts, you can do so by using the options under the Tools tab</p> … … 263 287 <?php } ?> 264 288 265 <select name="campaign_frequency_h"> 266 <option value="1">hourly</option> 267 <option value="12">twice daily</option> 268 <option value="24">daily</option> 269 <option value="84">weekly</option> 270 </select> 271 272 <p class="note">How often should feeds be checked? </p> 273 </div> 274 275 <?php if ($autoreader_settings['wpo_premium']) { ?> 289 <?php echo select_tag('campaign_frequency_h', 290 options_for_select( 291 array('3600' => 'hourly', 292 '43200' => 'twice daily', 293 '86400' => 'daily', 294 '302400' => 'weekly' 295 ), _data_value($data['main'], 'frequency', '1'))) ?> 296 297 298 <p class="note">How often should this feed be checked? </p> 299 </div> 300 301 <?php if (!$autoreader_settings['wpo_premium']) { ?> 276 302 <div class="checkbox"> 277 303 <?php echo label_for('campaign_cacheimages', 'Cache images') ?> 278 304 <? // need to install timthumb folder to get the following working ?> 279 <?php echo checkbox_tag('campaign_cacheimages', 1, _data_value($data['main'], 'cacheimages', is_writable($a rSettings->cachepath))) ?>305 <?php echo checkbox_tag('campaign_cacheimages', 1, _data_value($data['main'], 'cacheimages', is_writable($autoreader_settings['wpo_cachepath']))) ?> 280 306 <p class="note">Images will be stored in your server, instead of hotlinking from the original site. 281 <a href="helpurl image_caching" class="help_link">More</a></p>282 </div> 283 <?php } ?>307 <?php if ($autoreader_settings['wpo_help']) { ?><a href="helpurl image_caching" class="help_link">More</a><?php } ?></p> 308 </div> 309 <?php } ?> 284 310 285 311 <div class="checkbox"> … … 309 335 <div class="text"> 310 336 <?php echo label_for('campaign_author', 'Author:') ?> 337 <?php echo input_tag('campaign_author', _data_value($data['main'], 'author')) ?> 311 338 <?php // echo select_tag('campaign_author', options_for_select($author_usernames, _data_value($data['main'], 'author', 'admin'))) ?> 312 <p class="note"> The created posts will be assigned to admin.</p>339 <p class="note">If blank, the created posts will be assigned to the current user.</p> 313 340 </div> 314 341 … … 319 346 </div> 320 347 321 <div class="checkbox"> 322 <?php echo label_for('campaign_linktosource', 'Post title links to source?') ?> 323 <?php echo checkbox_tag('campaign_linktosource', 1, _data_value($data['main'], 'linktosource', false)) ?> 324 </div> 348 <?php if ($autoreader_settings['wpo_premium']) { ?> 349 <div class="checkbox"> 350 <?php echo label_for('campaign_linktosource', 'Post title links to source?') ?> 351 <?php echo checkbox_tag('campaign_linktosource', 1, _data_value($data['main'], 'linktosource', false)) ?> 352 </div> 353 <?php } ?> 325 354 326 355 <?php if ($autoreader_settings['wpo_premium']) { ?> … … 341 370 </div> 342 371 343 <?php if ($autoreader_settings['wpo_premium']) { ?>344 <?php if($action == 'edit'): ?> 372 373 <?php if($action == 'edit'): ?> 345 374 <!-- Tools --> 346 375 <div class="section" id="section_tools"> 376 <?php if (!$autoreader_settings['wpo_premium']) { ?> 347 377 <div class="buttons"> 348 378 <h3>Posts action</h3> 349 379 <p class="note">The selected action applies to all the posts created by this campaign</p> 350 351 380 <ul> 352 381 <li> 382 <div class="text"> 383 Check hotaru Cron to confirm running of this campaign. <a href="/admin_index.php?page=plugin_settings&plugin=cron">check now</a> 384 </div> 385 </li> 386 <li> 387 388 <label class="main">Delete posts from database:</label> 353 389 <div class="btn"> 354 390 <input type="submit" name="tool_removeall" value="Remove all" /> 355 391 </div> 392 356 393 </li> 357 394 <li> 358 395 <div class="radio"> 359 396 <label class="main">Change status to:</label> 360 361 <input type="radio" name="campaign_tool_changetype" value="new" id="changetype_new" checked="checked" /> <label for="changetype_new">New</label> 362 <input type="radio" name="campaign_tool_changetype" value="private" id="changetype_private" /> <label for="changetype_private">Private</label> 363 <input type="radio" name="campaign_tool_changetype" value="draft" id="changetype_draft" /> <label for="changetype_draft">Draft</label> 364 <input type="submit" name="tool_changetype" value="Change" /> 397 <input type="radio" name="campaign_tool_changetype" value="new" id="changetype_new" checked="checked" /> <label for="changetype_new">Published (New)</label> 398 <input type="radio" name="campaign_tool_changetype" value="private" id="changetype_pending" /> <label for="changetype_pending">Pending</label> 399 <input type="submit" name="tool_changetype" value="Change" /> 365 400 </div> 366 401 </li> 367 402 <li> 368 403 <div class="text"> 369 <label for="campaign_tool_changeauthor">Change author username to:</label> 370 <?php echo select_tag('campaign_tool_changeauthor', options_for_select($author_usernames, _data_value($data['main'], 'author', 'admin'))) ?> 371 404 <?php echo label_for('campaign_tool_changeauthor', 'Change author username to:') ?> 405 <?php echo input_tag('campaign_tool_changeauthor', _data_value($data['main'], 'author')) ?> 372 406 <input type="submit" name="tool_changeauthor" value="Change" /> 407 <p class="note">If blank, the created posts will be assigned to the current user.</p> 373 408 </div> 374 </li> 409 </li> 375 410 </ul> 376 411 </div> … … 383 418 </div> 384 419 --> 420 <?php } ?> 385 421 </div> 386 422 <?php endif; ?> 387 <?php } ?>423 388 424 </div> 389 425 … … 439 475 data: formdata, 440 476 beforeSend: function () { 441 $('#e dit_buttons').append('<img src="' + BASEURL + "content/admin_themes/" + ADMIN_THEME + 'images/ajax-loader.gif' + '"/>');477 $('#error_message').html('<img src="' + BASEURL + "content/admin_themes/" + ADMIN_THEME + 'images/ajax-loader.gif' + '"/>'); 442 478 }, 443 479 error: function(XMLHttpRequest, textStatus, errorThrown) { 444 //widget.html('ERROR');480 $('#error_message').html('There was an error with the data'); 445 481 }, 446 482 success: function(data, textStatus) { // success means it returned some form of json code to us. may be code with custom error msg 447 if (data.error === true) { 483 $error_message = ""; 484 if (data.errors > 0) { 485 $error_mesage = 'There are a total of ' + data.errors + " problems to fix<br/>"; 486 if (data.basic.length > 0) { $error_message += 'Basic: ' + data.basic + "<br/>"; } 487 if (data.feeds.length > 0) { $error_message += 'Feeds ' + data.feeds + "<br/>"; } 488 if (data.categories.length >0) { $error_message += 'Categories: ' + data.categories + "<br/>"; } 489 if (data.rewrite.length > 0) { $error_message += 'Rewrite ' + data.rewrite + "<br/>"; } 490 if (data.options.length > 0) { $error_message += 'Options: ' + data.options + "<br/>"; } 448 491 } 449 492 else … … 453 496 if(data.enabled == 'true') { img_src = "active.png"; } else { img_src = "inactive.png"; } 454 497 $('#edit_buttons').html('<img src="' + BASEURL + "content/admin_themes/" + ADMIN_THEME + 'images/' + img_src + '"/>'); 498 $error_message += "Your changes have been saved." 455 499 } 500 $('#error_message').html($error_message); 456 501 //$('#return_message').html(data.message).addClass(data.color); 457 502 //$('#return_message').html(data.message).addClass('message'); … … 516 561 }; 517 562 feed.addClass('load input_text'); 518 }; 519 563 }; 564 565 $('#tool_removeall').click(function(){ 566 event.preventDefault(); 567 var answer = confirm('You are about to delete all the posts for this campaign from the database. This action can not be reversed. Delete ? '+jQuery(this).attr('title')); 568 if (answer) { 569 var campaign_id = ('#campaign_edit').val(); 570 alert(campaign_id); 571 var formdata = 'action=tools_delete&id=' + campaign_id; 572 var sendurl = BASEURL + 'admin_index.php?page=plugin_settings&plugin=autoreader&alt_template=autoreader_add'; 573 574 $.ajax( 575 { 576 type: 'post', 577 url: sendurl, 578 data: formdata, 579 error: function(XMLHttpRequest, textStatus, errorThrown) { 580 $('#error_message').html('There was an error with the data'); 581 }, 582 success: function(data, textStatus) { // success means it returned some form of json code to us. may be code with custom error msg 583 if (data.error === true) { 584 } 585 else 586 { 587 $('#error_message').html('___ records were deleted'); 588 } 589 }, 590 dataType: "json" 591 }); 592 } 593 return false; 594 }); 520 595 521 596 function update_feeds() { -
branches/1.2/content/plugins/autoreader/templates/autoreader_dashboard.php
r1334 r1363 76 76 <li> 77 77 <span class="details"><?php echo WPOTools::timezoneMysql('F j, g:i a', $campaign->lastactive) ?></span> 78 <a href=" <?php echo $this->adminurl ?>&s=list&id=<?php echo $campaign->id ?>"><?php echo $campaign->title ?></a></li>78 <a href="/admin_index.php?page=plugin_settings&plugin=autoreader"><?php echo $campaign->title ?></a></li> 79 79 <?php endforeach; ?> 80 80 </ol> … … 89 89 <li> 90 90 <span class="details"><?php echo $campaign->count ?></span> 91 <a href=" <?php echo $this->adminurl ?>&s=list&id=<?php echo $campaign->id ?>"><?php echo $campaign->title ?></a></li>91 <a href="/admin_index.php?page=plugin_settings&plugin=autoreader"><?php echo $campaign->title ?></a></li> 92 92 <?php endforeach; ?> 93 93 </ol> -
branches/1.2/content/plugins/autoreader/templates/autoreader_options.php
r1334 r1363 10 10 echo json_encode($autoreader_settings); 11 11 exit; 12 default : 13 $autoreader_settings = $arSettings->getOptionSettings($h); 12 case "flush": 13 $hook = "autoreader_runcron"; 14 $cron_data = array('hook'=>$hook); 15 $h->pluginHook('cron_flush_hook', 'cron', $cron_data); 16 exit; 17 default : 18 $autoreader_settings = $arSettings->getOptionSettings($h); 14 19 15 20 } … … 47 52 <?php } ?> 48 53 49 <p class="note"><?php echo 'Cron is set up to handle fetching.'; ?> <?php if ($autoreader_settings['wpo_help']) { ?><a href="<?php echo $arSettings->helpurl ?>cron" class="help_link"><?php echo 'More'; ?></a><?php } ?></p> 54 <p class="note"><?php echo 'Cron is set up to handle fetching if you are familiar with manually setting cron jobs on your server.'; ?> <?php if ($autoreader_settings['wpo_help']) { ?><a href="<?php echo $arSettings->helpurl ?>cron" class="help_link"><?php echo 'More'; ?></a><?php } ?></p> 55 <p class="note">For those not familiar with cron jobs or for shared servers where you cannot access them, you may install the "cron" plugin for hotaru which emulates the function of server cron jobs. This is recommended for most users.</p> 50 56 </li> 51 57 … … 64 70 <p class="note"><?php echo 'With this option enabled, Autoreader will attempt to show you logs creation in real time when manual fetching is used.'; ?> <a href="<?php echo $this->helpurl ?>logging" class="help_link"><?php echo 'More'; ?></a></p> 65 71 </li> 66 72 <?php } ?> 73 67 74 <li> 68 75 <?php echo label_for('option_caching','Cache images') ?> 69 <?php echo checkbox_tag('option_caching', 1,$autoreader_settings['wpo_cacheimage ']) ?>76 <?php echo checkbox_tag('option_caching', 1,$autoreader_settings['wpo_cacheimages']) ?> 70 77 71 <p class="note"><?php echo 'This option overrides a ll campaign-specific settings'; ?> <a href="<?php echo $this->helpurl ?>image_caching" class="help_link"><?php echo 'More'; ?></a></p>78 <p class="note"><?php echo 'This option overrides any campaign specific image settings'; ?> <?php if ($autoreader_settings['wpo_premium']) { ?><a href="<?php echo $this->helpurl ?>image_caching" class="help_link"><?php echo 'More'; ?></a><?php } ?></p> 72 79 </li> 73 80 … … 76 83 <?php echo input_tag('option_cachepath', $autoreader_settings['wpo_cachepath']) ?> 77 84 78 <p class="note"><?php echo 'The path <span id="cachepath">'. PLUGINS . ' Autoreader/<span id="cachepath_input">' . $autoreader_settings['wpo_cachepath'] . '</span></span> must exist, be writable by the server and accessible through browser.'; ?></p>85 <p class="note"><?php echo 'The path <span id="cachepath">'. PLUGINS . 'autoreader/<span id="cachepath_input">' . $autoreader_settings['wpo_cachepath'] . '</span></span> must exist, be writable by the server and accessible through browser.'; ?></p> 79 86 </li> 80 <?php } ?> 87 88 89 <li> 90 <a href='#' id="flush_cron">Clear</a> all cron jobs listed for "autoreader" in the hotaru "cron" plugin.<div id ="flush_cron_message"></div> 91 </li> 92 93 81 94 </ul> 82 95 … … 89 102 <script type='text/javascript'> 90 103 jQuery('document').ready(function($) { 104 105 $("#flush_cron").click(function() { 106 var answer = confirm('Are you sure you want to remove all current cron jobs for autoreader from cron plugin? Existing posts submitted will not be lost and campaign data will not be altered.'); 107 if (answer) { 108 var formdata = 'action=flush'; 109 var sendurl = BASEURL + 'admin_index.php?page=plugin_settings&plugin=autoreader&alt_template=autoreader_options'; 110 111 $.ajax( 112 { 113 type: 'post', 114 url: sendurl, 115 data: formdata, 116 beforeSend: function () { 117 $('#flush_cron_message').html('<img src="' + BASEURL + "content/admin_themes/" + ADMIN_THEME + 'images/ajax-loader.gif' + '"/>'); 118 }, 119 error: function(XMLHttpRequest, textStatus, errorThrown) { 120 $('#flush_cron_message').html('An error occured.'); 121 }, 122 success: function(data, textStatus) { // success means it returned some form of json code to us. may be code with custom error msg 123 if (data.error === true) { 124 } 125 else 126 { 127 $('#flush_cron_message').html(data.count + ' jobs flushed from the cron.'); 128 } 129 }, 130 dataType: "json" 131 }); 132 } 133 return false; 134 }); 135 91 136 92 137 $("#edit_submit").click(function(event) {
Note: See TracChangeset
for help on using the changeset viewer.