コード例 #1
0
ファイル: SchemaFront.php プロジェクト: kanei/vantuch.cz
 /**
  * hunch_schema_add is called to lookup schema.org or add default markup 
  */
 public function hunch_schema_add()
 {
     global $post;
     $DisableMarkup = is_singular() ? get_post_meta($post->ID, '_HunchSchemaDisableMarkup', true) : false;
     if (!$DisableMarkup) {
         $server = new SchemaServer();
         $jsonLd = $server->getResource();
         if ($jsonLd === "") {
             $postType = get_post_type();
             $schemaObj = HunchSchema_Thing::factory($postType);
             if (isset($schemaObj)) {
                 $jsonLd = $schemaObj->getResource();
             }
         }
         if ($jsonLd !== "") {
             echo "<script type='application/ld+json'>" . $jsonLd . "</script>";
         }
     }
 }
コード例 #2
0
ファイル: SchemaSettings.php プロジェクト: kanei/vantuch.cz
 /**
  * Activate license listener, activation process
  */
 public function hunch_schema_activate_license()
 {
     // listen for our activate button to be clicked
     if (isset($_POST['schema_license_activate'])) {
         // run a quick security check
         if (!check_admin_referer('schema_sample_nonce', 'schema_sample_nonce')) {
             return;
         }
         // get out if we didn't click the Activate button
         // retrieve the license from the database
         $license = trim($_POST['schema_option_name_license']['schema_license_wc']);
         // data to send in our API request
         $api_params = array('license' => $license, 'item_name' => urlencode(self::SCHEMA_ITEM_NAME), 'url' => home_url());
         $server = new SchemaServer();
         $licenseData = $server->activateLicense($api_params);
         // Check for no activation errors
         if ($licenseData[0] == true) {
             //Alter the options appropriately, should be part of the schema_option_name_license array
             update_option('schema_license_wc_status', 'Active');
             add_settings_error('schema_wc_activation_err', esc_attr('settings_updated'), $licenseData[1], 'updated');
         } else {
             // Report the errors
             update_option('schema_license_wc_status', 'Inactive');
             add_settings_error('schema_wc_activation_err', esc_attr('settings_updated'), $licenseData[1] . ". Visit <a target='_blank' href='http://app.schemaapp.com/licenses'>Schema App Licenses</a> for more information", 'error');
         }
     }
 }
コード例 #3
0
ファイル: SchemaEditor.php プロジェクト: kanei/vantuch.cz
    /**
     * Render Meta Box content.
     *
     * @param WP_Post $post The post object.
     */
    public function render_meta_box_content($post)
    {
        $PostType = get_post_type();
        $DisableMarkup = get_post_meta($post->ID, '_HunchSchemaDisableMarkup', true);
        $MarkupType = get_post_meta($post->ID, '_HunchSchemaType', true);
        // Add an nonce field so we can check for it later.
        wp_nonce_field('schema_inner_custom_box', 'schema_inner_custom_box_nonce');
        $server = new SchemaServer();
        // Use get_post_meta to retrieve an existing value from the database.
        $jsonLd = $server->getResource(get_permalink($post->ID), true);
        if (empty($jsonLd)) {
            $schemaObj = HunchSchema_Thing::factory($PostType);
            $jsonLd = $schemaObj->getResource(TRUE);
            $replacelink = $server->createLink();
        } else {
            $editlink = $server->updateLink();
        }
        $testlink = "https://developers.google.com/structured-data/testing-tool?url=" . urlencode(get_permalink($post->ID));
        // Display the form, using the current value.
        ?>
        <style>
        #schemapostlinks {
            display: inline;
            float: right;
        }
        #schemapostlinks button {
            margin: 0 1em;
        }
        </style>
        <label for="schema_new_field"><span class="inside"><?php 
        echo _e('Post JSON-LD', 'schema_textdomain');
        ?>
</span>
            <div id="schemapostlinks">
                <?php 
        if (empty($replacelink)) {
            echo '<button><a target="_blank" href="' . $editlink . '">Edit</a></button>';
        } else {
            ?>
                    <button><a target="_blank" href="<?php 
            echo $replacelink;
            ?>
">Use Different Schema.org Type</a></button>
                    <button id="extendSchema" value="Extend Markup"><a target="_blank" href="#">Add to <?php 
            echo $schemaObj->schemaType;
            ?>
 Default Markup</a></button>
                    <input type="hidden" id="resourceURI" value="<?php 
            echo get_permalink($post->ID);
            ?>
"/>
                    <textarea id="resourceData" style="display:none"><?php 
            echo esc_attr($jsonLd);
            ?>
</textarea> 
                    <?php 
        }
        ?>
                <button><a class="" target="_blank" href="<?php 
        echo $testlink;
        ?>
">Test with Google</a></button>
            </div>
        </label> 
        <p>
            <textarea disabled="" class="large-text metadesc" rows="6" id="schema_new_field" name="schema_new_field"><?php 
        echo esc_attr($jsonLd);
        ?>
</textarea>
            <?php 
        if (isset($schemaObj)) {
            ?>
                <br/><strong>Note: </strong><span style="color: grey"><em>This is default markup. Extend this with Schema App Creator using Update linked above.</em></span>
            <?php 
        }
        ?>
        </p>
        <h4>Markup Options</h4>
        <p>
            <label><input type="checkbox" name="HunchSchemaDisableMarkup" value="1" <?php 
        $this->CheckSelected(1, $DisableMarkup, 'checkbox');
        ?>
> <?php 
        _e('Disable Schema markup', 'schema_textdomain');
        ?>
</label>
        </p>
        <?php 
        if ($PostType == 'page') {
            ?>
            <p>
                <label>Select Type</label> 
                <select name="HunchSchemaType">
                    <option value="">Article</option>
                    <option value="BlogPosting" <?php 
            $this->CheckSelected('BlogPosting', $MarkupType);
            ?>
>Blog Posting</option>
                    <option value="LiveBlogPosting" <?php 
            $this->CheckSelected('LiveBlogPosting', $MarkupType);
            ?>
>&nbsp; Live Blog Posting</option>
                    <option value="NewsArticle" <?php 
            $this->CheckSelected('NewsArticle', $MarkupType);
            ?>
>News Article</option>
                    <option value="Report" <?php 
            $this->CheckSelected('Report', $MarkupType);
            ?>
>Report</option>
                    <option value="ScholarlyArticle" <?php 
            $this->CheckSelected('ScholarlyArticle', $MarkupType);
            ?>
>Scholarly Article</option>
                    <option value="MedicalScholarlyArticle" <?php 
            $this->CheckSelected('MedicalScholarlyArticle', $MarkupType);
            ?>
>&nbsp; Medical Scholarly Article</option>
                    <option value="SocialMediaPosting" <?php 
            $this->CheckSelected('SocialMediaPosting', $MarkupType);
            ?>
>Social Media Posting</option>
                    <option value="DiscussionForumPosting" <?php 
            $this->CheckSelected('DiscussionForumPosting', $MarkupType);
            ?>
>&nbsp; Discussion Forum Posting</option>
                    <option value="TechArticle" <?php 
            $this->CheckSelected('TechArticle', $MarkupType);
            ?>
>Tech Article</option>
                    <option value="APIReference" <?php 
            $this->CheckSelected('APIReference', $MarkupType);
            ?>
>&nbsp; API Reference</option>
                </select>
            </p>
        <?php 
        }
    }