function link_post($post_id)
 {
     if (count($_POST) != 0 && isset($_POST['_wp_http_referer'])) {
         $linked = get_post_meta($post_id, "CanvasLinked", true);
         if ($linked == 1) {
             $this->post = $post_id;
             $post = get_post($this->post);
             $this->content = $post->post_content;
             $this->change_src();
             $this->change_links();
             $strip = explode("body>", $this->content);
             $this->content = substr($strip[1], 0, strlen($strip[1]) - 2);
             $styles = $this->stylesheets($post);
             require_once dirname(__FILE__) . "/../lib/emogrifier.php";
             foreach ($styles as $style) {
                 if (strpos($style, network_site_url()) !== FALSE) {
                     $dir = wp_upload_dir();
                     $style = str_replace(network_site_url() . "/wp-content/", str_replace("uploads", "", $dir['basedir']), $style);
                     $style = explode("?", $style);
                     $style = $style[0];
                 }
                 $css = preg_replace("/\\/[\\*]*[^\\*]*\\*\\//", "", file_get_contents($styles[1]));
                 $emogrifier = new emogrifier($this->content, $css);
                 $this->content = $emogrifier->emogrify();
             }
             $canvas_id = get_post_meta($post_id, "postCanvasID", true);
             $course_id = get_post_meta($post_id, "CanvasCourse", true);
             global $wpdb;
             $course_post = $wpdb->get_results("select post_id from " . $wpdb->prefix . "postmeta where meta_key='CourseID' and meta_value = '" . $course_id . "'");
             $course_post = get_post($course_post[0]->post_id);
             require_once __DIR__ . "/../../API/Psr4AutoloaderClass.php";
             $loader = new Psr4AutoloaderClass();
             $loader->register();
             $loader->addNamespace('InstructureCanvasAPI', __DIR__ . "/../../API/InstructureCanvasAPI/src");
             $API = new InstructureCanvasAPI\InstructureCanvasAPI(array("site" => get_post_meta($course_post->ID, "courseURL", true), "token" => get_post_meta($course_post->ID, "courseToken", true), "webService" => "CURL"));
             $pages = new InstructureCanvasAPI\Courses\Pages\Pages();
             $pages->setAPI($API);
             $pages->setCourseID(get_post_meta($course_post->ID, "courseID", true));
             $post = get_post($post_id);
             $publish = 1;
             if ($post->post_status != "publish") {
                 $publish = 0;
             }
             $data = $pages->updatePage($post->post_title, array("wiki_page[body]" => stripslashes(str_replace(" ", " ", $this->content)), "wiki_page[title]" => $post->post_title, "wiki_page[published]" => $publish));
         }
     }
 }
Ejemplo n.º 2
0
 }
 if (count($_REQUEST['pbem']) > 0) {
     global $host;
     if ($host == 'localhost') {
         echo '<h1>E-mail not available on localhost</h1>';
     } else {
         if ($_REQUEST['reps'] > 1 or $_REQUEST['battle'] !== 'Run') {
             echo "<em>E-mail not available when swapping or evaluating units or running battle more than once.</em><br />";
         } else {
             //use emogrifier to convert CSS styles in results($out) to in-line styles so colors are preserved in the email
             $cssstr = file_get_contents("aa.css");
             //gets the CSS and puts it's contents into a string
             $converttoinline = new emogrifier($out, $cssstr);
             //instantiates the emogrifier class
             //need to use @ operator to suppress PHP warnings when loading HTML into DOM object
             @($body = $converttoinline->emogrify());
             //converted results with in line styles instead of CSS classes
             $addresses = implode(', ', $_REQUEST['pbem']);
             //NO NEED FOR GAMEID ANYMORE?
             $subject = " Battle results";
             echo "<em>Results e-mailed to {$addresses}.</em><br /> ";
             $headers = 'From: aacalc@frood.net' . "\n" . 'MIME-Version: 1.0' . "\n" . 'Content-type: text/html; charset=iso-8859-1' . "\n";
             mail($addresses, $subject, $body, $headers);
             //release class object
             unset($converttoinline);
         }
     }
     /*NO LONGER NEEDED?
     		//The magic: add results to Game Record if requested
     		if ($_REQUEST['gameid']!=='' && file_exists('makegame/games/'.$_REQUEST['gameid'].'.php')) { //Game ID already validated in getformdata
     			if ($_REQUEST ['battle']== 'Run') {