Plugin Directory

Changeset 1971883


Ignore:
Timestamp:
11/09/2018 11:55:40 PM (7 years ago)
Author:
navigationnorth
Message:

updates for v0.6.5

Location:
wp-oer/trunk
Files:
485 added
14 edited

Legend:

Unmodified
Added
Removed
  • wp-oer/trunk/classes/class-wp-session.php

    r1714161 r1971883  
    103103        $this->read_data();
    104104
    105         $this->set_cookie();
     105        add_action( 'init', array( $this, 'set_cookie' ) );
    106106
    107107    }
     
    133133     * Set the session cookie
    134134     */
    135     protected function set_cookie() {
     135    public function set_cookie() {
    136136        @setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN );
    137137    }
     
    331331    }
    332332}
     333
     334$oer_session = OER_WP_Session::get_instance();
  • wp-oer/trunk/css/back_styles.css

    r1714161 r1971883  
    221221.oer-plugin-row .oer-row-left, .oer-import-row .row-left { width:63%; float:left; }
    222222.oer-plugin-row .oer-row-right, .oer-import-row .row-right { width:35%; float:right; }
     223.oer-import-row .row2-left { width:85%; float:left; }
     224.oer-import-row .row2-right { width:13%; float:right; }
    223225.oer-plugin-row fieldset, .oer-import-row fieldset { margin-bottom:15px; }
    224226.oer-plugin-row .form-table th { width:0; display:none; }
     
    274276.loader .loader-img { display: table; overflow: hidden; height:100%; width:100%; }
    275277.loader .loader-img div { display:table-cell; top:30%; position:relative; }
     278p.submit { margin-top:0; padding: 15px; }
     279.oer_settings_form .plugin-row-first{ padding-top:0px; }
     280.loader-notice { font-size:18px; color: #fbe0e0;text-align:center;margin:10px auto;display:block !important;font-weight:bold; }
  • wp-oer/trunk/css/front_styles.css

    r1776251 r1971883  
    442442.search-results .type-resource .entry-header h5.post-meta { margin-bottom:1.05em; }
    443443.search-results .type-resource .entry-header h5.post-meta .post-meta-box { margin-right:15px; }
     444.oer-standards #content, .standards-template #content,
     445.substandards-template #content, .notation-template #content { width:100%; }
     446.oer-pdf-viewer { /*min-height:1250px;*/min-height:500px; height:100%; }
     447.oer-standards #content ul.oer-standards li,
     448.standards-template #content ul.oer-standards li,
     449.substandards-template #content ul.oer-substandards li{ list-style-type:none;  }
     450.oer-standards #content ul.oer-standards,
     451.standards-template #content ul.oer-standards{ padding-left:0; margin-top:10px;}
     452#content ul.oer-substandards,
     453#content ul.oer-standard { margin-top:10px; padding-left:20px; }
     454#content ul.oer-hsubstandards { padding-left:20px; }
     455#content ul.oer-notations { padding-left:20px; }
     456#content ul.oer-substandards li,
     457#content ul.oer-standard li,
     458#content ul.oer-notations li{ list-style-type:none; }
     459#content ul.oer-notations li h4 { margin-top:5px; }
     460.oer_standard_resources h4 { margin-bottom:10px; }
     461.oer_standard_resources ul.oer-resources { padding-left:20px; }
     462.oer_standard_resources li { list-style-type:none; }
     463.oer-backlink { margin-bottom:10px; }
     464#content ul.oer-substandards { margin-top:0; }
     465.oer_blgpst .rght-sd-cntnr-blg h4 { margin-top:0; }
    444466@media screen and (max-width: 600px) {
    445467    .oer_blgpst .oer-feature-image { width:100%; float:none; margin-bottom:10px; }
  • wp-oer/trunk/css/resource-category-style.css

    r1823963 r1971883  
    5656.oer-allftrdpst { float: left; margin: 0 0 25px 0; padding: 10px 0; width: 100%; overflow:hidden; }
    5757.oer-allftrdrsrc .oer-snglrsrchdng { width: 100%; float: left; margin: 0px; padding: 5px 0 10px; font-size: 25px; line-height: 25px; }
    58 .oer-allftrdrsrc .oer-allftrdrsrccntr { float: left; margin: 0px; padding: 0 5px 0 0; overflow: auto; height: 540px; border-top: 1px solid #c8c8c8; border-bottom: 1px solid #c8c8c8; width:100%; }
     58.oer-allftrdrsrc .oer-allftrdrsrccntr,
     59.oer-allftrdrsrc .oer-allftrdrsrccntr-notation{ float: left; margin: 0px; padding: 0 5px 0 0; overflow: auto; height: 540px; border-top: 1px solid #c8c8c8; border-bottom: 1px solid #c8c8c8; width:100%; }
    5960.oer-allftrdrsrc .oer-snglrsrc:first-child { border-top: none !important; margin: 8px 0 2px !important; }
    6061.oer-allftrdrsrc .oer-snglrsrc { float: left; padding: 5px 0; width: 100%; border-top: 1px solid #ddd !important; }
  • wp-oer/trunk/css/resource-style.css

    r1776251 r1971883  
    77.oer_sngl_resource_wrapper { width: 100%; margin-bottom: 10px; overflow:hidden; }
    88.oer-rsrclftcntr-img { float: left; width: 42%; /*margin-right: 35px;*/ }
     9.oer-rsrclftcntr-video { padding-right:0; overflow:hidden; }
     10.oer-rsrclftcntr-video .videoWrapper { padding-top:0; }
     11.oer-rsrccntr-details { margin-top:15px; }
     12.oer-rsrclftcntr .oer-sngl-rsrc-dscrptn h2 { margin-top:0; }
     13.oer-rsrclftcntr .oer-sngl-rsrc-dscrptn { padding-bottom:0; }
    914.oer-rsrcrghtcntr { float: left; width: 54%; padding: 0 0 0 15px; box-sizing: border-box; }
    1015.oer-sngl-rsrc-url { float: left; font-size: 26px; padding: 0 0 10px 0; line-height: 28px; text-align: left; width: 100%; }
  • wp-oer/trunk/includes/import.php

    r1714161 r1971883  
    77$message = isset($_GET['message'])?urldecode($_GET['message']):null;
    88$type = isset($_GET['type'])?urldecode($_GET['type']):null;
     9
     10if ($type=="lr"){
     11    if ($message=="0")
     12        $message = "No record was imported.";
     13    elseif ($message=="1")
     14        $message .= " record imported.";
     15    else
     16        $message .= " records imported.";
     17   
     18    $type="success";
     19}
    920
    1021if (!current_user_can('manage_options')) {
     
    3546                ?>
    3647            </div>
     48            <!--<div class="oer-import-row">-->
     49                <?php
     50                //include_once(OER_PATH.'includes/lr-importer.php');
     51                ?>
     52            <!--</div>-->
    3753            <div class="oer-import-row">
    3854                <?php
  • wp-oer/trunk/includes/init.php

    r1823963 r1971883  
    168168add_action( 'init' , 'oer_postcreation' );
    169169function oer_postcreation(){
     170    global $_use_gutenberg;
    170171    $labels = array(
    171172        'name'               => _x( 'Resource', 'post type general name' ),
     
    198199    'register_meta_box_cb' => 'oer_resources_custom_metaboxes'
    199200    );
    200     register_post_type( 'resource', $args);
     201   
     202    if ($_use_gutenberg=="on" or $_use_gutenberg=="1")
     203    $args['show_in_rest'] = true;
     204   
     205    register_post_type( 'resource', $args);
    201206}
    202207
     
    215220add_action( 'init', 'oer_create_resource_taxonomies', 0 );
    216221function oer_create_resource_taxonomies() {
    217     $labels = array(
    218         'name'              => _x( 'Subject Area', 'taxonomy general name' ),
    219         'singular_name'     => _x( 'Subject Area', 'taxonomy singular name' ),
    220         'search_items'      => __( 'Search Subject Areas' ),
    221         'all_items'         => __( 'All Subject Areas' ),
    222         'parent_item'       => __( 'Parent Subject Area' ),
    223         'parent_item_colon' => __( 'Parent Subject Area:' ),
    224         'edit_item'         => __( 'Edit Subject Area' ),
    225         'update_item'       => __( 'Update Subject Area' ),
    226         'add_new_item'      => __( 'Add New Subject Area' ),
    227         'new_item_name'     => __( 'New Genre Subject Area' ),
    228         'menu_name'         => __( 'Subject Areas' ),
    229     );
    230    
    231     $args = array(
    232         'hierarchical'      => true,
    233         'labels'            => $labels,
    234         'show_ui'           => true,
    235         'show_admin_column' => true,
    236         'query_var'         => true,
    237         'rewrite'           => array( 'slug' => 'resource-subject-area' ),
    238     );
    239     register_taxonomy( 'resource-subject-area', array( 'resource' ), $args );
     222    global $_use_gutenberg;
     223   
     224    $labels = array(
     225        'name'              => _x( 'Subject Area', 'taxonomy general name' ),
     226        'singular_name'     => _x( 'Subject Area', 'taxonomy singular name' ),
     227        'search_items'      => __( 'Search Subject Areas' ),
     228        'all_items'         => __( 'All Subject Areas' ),
     229        'parent_item'       => __( 'Parent Subject Area' ),
     230        'parent_item_colon' => __( 'Parent Subject Area:' ),
     231        'edit_item'         => __( 'Edit Subject Area' ),
     232        'update_item'       => __( 'Update Subject Area' ),
     233        'add_new_item'      => __( 'Add New Subject Area' ),
     234        'new_item_name'     => __( 'New Genre Subject Area' ),
     235        'menu_name'         => __( 'Subject Areas' ),
     236    );
     237   
     238    $args = array(
     239        'hierarchical'      => true,
     240        'labels'            => $labels,
     241        'show_ui'           => true,
     242        'show_admin_column' => true,
     243        'query_var'         => true,
     244        'rewrite'           => array( 'slug' => 'resource-subject-area' ),
     245    );
     246   
     247    if ($_use_gutenberg=="on" or $_use_gutenberg=="1")
     248    $args['show_in_rest'] = true;
     249   
     250    register_taxonomy( 'resource-subject-area', array( 'resource' ), $args );
    240251}
    241252//register cutsom category
     
    691702}
    692703
     704add_action("admin_action_import_lr_resources","process_import_lr_resources");
     705function process_import_lr_resources(){
     706    $message = null;
     707    $type = null;
     708
     709    if (!current_user_can('manage_options')) {
     710        wp_die( "You don't have permission to access this page!" );
     711    }
     712   
     713    //Resource Import
     714    if(isset($_POST['lr_resrc_imprt'])){
     715    check_admin_referer('oer_lr_nonce_field');
     716   
     717    $resources = oer_importLRResources();
     718   
     719    if ($resources){
     720        $cnt = 0;
     721        foreach($resources as $resource) {
     722        if (!resource_exists($resource)){
     723            oer_add_resource($resource);
     724            $cnt++;
     725        }
     726        }
     727        $message = $cnt;
     728        $type = "lr";
     729    }
     730   
     731    }
     732    wp_safe_redirect( admin_url("edit.php?post_type=resource&page=oer_import&message=$message&type=$type"));
     733    exit;
     734}
     735
    693736/**
    694737 * Process Import Subject Areas
  • wp-oer/trunk/includes/oer-functions.php

    r1823963 r1971883  
    14801480}
    14811481
     1482// Import LR Resources
     1483function oer_importLRResources(){
     1484    $lr_url = $_POST['lr_import'];
     1485   
     1486    $resources = null;
     1487    $lr_resources = array();
     1488    $schema = array(
     1489            "LRMI",
     1490            "JSON-LD",
     1491            "json",
     1492            "schema.org"
     1493        );
     1494   
     1495    if ($lr_url){
     1496        if( ini_get('allow_url_fopen') ) {
     1497            $resources = file_get_contents($lr_url);
     1498        } else {
     1499            $resources = curlResources($lr_url);
     1500        }
     1501        $resources = json_decode($resources);
     1502    }
     1503   
     1504    $index = 0;
     1505   
     1506    if(strpos($lr_url,"slice") === false) {
     1507        // Getting LR Imports through Obtain
     1508        foreach($resources->documents as $document){
     1509            $lr_resource = array();
     1510           
     1511            foreach ($document as $doc) {
     1512                if ($doc[0]->doc_type=="resource_data"){
     1513                    $exists = custom_array_intersect($schema, $doc[0]->payload_schema);
     1514                   
     1515                    if (!empty($exists)){
     1516                        if ($doc[0]->resource_data->items){
     1517                            foreach($doc[0]->resource_data as $resource){
     1518                                $lr_resource['resource_url'] = trim($resource[0]->properties->url[0]);
     1519                                if (strtolower($resource[0]->properties->educationalAlignment[0]->properties->alignmentType[0])=="educationlevel"){
     1520                                    if (strpos($resource[0]->properties->educationalAlignment[0]->properties->targetName[0],"Fourth")>=0){
     1521                                        $lr_resource['grade'] = "4";
     1522                                    }
     1523                                }
     1524                                if (strpos($resource[0]->properties->author[0]->type[0],"Person")){
     1525                                    $lr_resource['author_type'] = "person";
     1526                                } else {
     1527                                    $lr_resource['author_type'] = "organization";
     1528                                }
     1529                                $lr_resource['author_url'] = $resource[0]->properties->author[0]->properties->url[0][0];
     1530                                if (!is_array($resource[0]->properties->author[0]->properties->name[0]))
     1531                                    $lr_resource['author_name'] = $resource[0]->properties->author[0]->properties->name[0];
     1532                                else
     1533                                    $lr_resource['author_name'] = $resource[0]->properties->author[0]->properties->name[0][0];
     1534                                $lr_resource['author_email'] = $resource[0]->properties->author[0]->properties->email[0][0];
     1535                                if (strpos($resource[0]->properties->publisher[0]->type[0],"Organization")){
     1536                                    $lr_resource['publisher_name'] = $resource[0]->properties->publisher[0]->properties->name[0];
     1537                                    $lr_resource['publisher_url'] = $resource[0]->properties->publisher[0]->properties->url[0];
     1538                                }
     1539                                $lr_resource['interactivity'] = $resource[0]->properties->interactivityType[0];
     1540                                $lr_resource['title'] = $resource[0]->properties->name[0];
     1541                                $lr_resource['media_type'] = strtolower($resource[0]->properties->mediaType[0]);
     1542                                $lr_resource['date_created'] = $resource[0]->properties->dateCreated[0];
     1543                                $lr_resource['lr_type'] = strtolower($resource[0]->properties->learningResourceType[0]);
     1544                                $lr_resource['description'] = $resource[0]->properties->description[0];
     1545                                $lr_resource['tags'] = $resource[0]->properties->keywords[0];
     1546                                $lr_resources[] = $lr_resource;
     1547                            }
     1548                        } else {
     1549                            $resource = $doc[0]->resource_data;
     1550                            if (!is_object($resource)){
     1551                                $resource = json_decode($resource);
     1552                                $lr_resource['resource_url'] = trim($resource->url);
     1553                                $lr_resource['description'] = $resource->description;
     1554                                $lr_resource['title'] = $resource->name;
     1555                                $lr_resource['publisher_name'] = $resource->publisher->name;
     1556                                $lr_resource['author_name'] = $resource->author->name;
     1557                                $lr_resource['date_created'] = $resource->dateCreated;
     1558                                $lr_resource['tags'] = $resource->keywords;
     1559                            } else {
     1560                                $lr_resource['resource_url'] = trim($resource->url);
     1561                                $lr_resource['description'] = $resource->description[0];
     1562                                $lr_resource['title'] = $resource->name[0];
     1563                                $lr_resource['publisher_name'] = $resource->publisher[0]->name;
     1564                                $lr_resource['author_name'] = $resource->author[0]->name;
     1565                                $lr_resource['based_on_url'] = $resource->isBasedOnURL[0];
     1566                                $lr_resource['date_created'] = $resource->dateCreated[0];
     1567                                $lr_resource['subject_areas'] = $resource->about;
     1568                            }
     1569                            $lr_resources[] = $lr_resource;
     1570                        }
     1571                    }
     1572                }
     1573               
     1574            }
     1575            $index++;
     1576        }
     1577    } else {
     1578        $lr_resources = get_sliceLRResources($lr_url);
     1579    }
     1580    return $lr_resources;
     1581}
     1582
     1583// Import LR Resources with slice and resumption token
     1584function get_sliceLRResources($lr_url){
     1585    $lr_resources = array();
     1586   
     1587    $lrUrl = $lr_url;
     1588   
     1589    do {
     1590        // Get LR Resources based on initial slice URL
     1591        if( ini_get('allow_url_fopen') ) {
     1592            $resources = file_get_contents($lrUrl);
     1593        } else {
     1594            $resources = curlResources($lrUrl);
     1595        }
     1596        $resources = json_decode($resources);
     1597       
     1598        // Exit loop if no resources returned
     1599        if (empty($resources->documents))
     1600            break;
     1601       
     1602        // Getting LR Imports through Slice
     1603        foreach($resources->documents as $document){
     1604            $lr_resource = array();
     1605           
     1606            if($document->resource_data_description->doc_type=="resource_data"){
     1607                $resource = $document->resource_data_description;
     1608                $resource_data = json_decode($resource->resource_data);
     1609               
     1610                $lr_resource['resource_url'] = $resource->resource_locator;
     1611                $lr_resource['title'] = $resource_data->name;
     1612                $lr_resource['description'] = $resource_data->description;
     1613                $lr_resource['date_created'] = $resource_data->dateCreated;
     1614                $lr_resource['lr_type'] = $resource_data->learningResourceType;
     1615                $lr_resource['thumbnail_url'] = $resource_data->thumbnailUrl;
     1616               
     1617                if($resource_data->author->{'@type'}=="Organization")
     1618                    $lr_resource['author_type'] = "organization";
     1619                else
     1620                    $lr_resource['author_type'] = "person";
     1621                   
     1622                $lr_resource['author_name'] = $resource_data->author->name;
     1623                $lr_resource['publisher_name'] = $resource_data->publisher->name;
     1624                $lr_resource['publisher_url'] = $resource_data->publisher->url;
     1625                $lr_resource['subject_areas'] = $resource_data->keywords;
     1626               
     1627                $lr_resources[] = $lr_resource;
     1628            }
     1629        }
     1630       
     1631        // get resumption token for next batch of resources
     1632        $resume_token = $resources->resumption_token;
     1633        $lrUrl = $lr_url."&resumption_token=".$resume_token;
     1634       
     1635    } while(!empty($resources->resumption_token));
     1636   
     1637    return $lr_resources;
     1638}
     1639
     1640function curlResources($url){
     1641    if (!function_exists('curl_init')){
     1642        die('CURL is not installed!');
     1643    }
     1644    $ch = curl_init();
     1645    curl_setopt($ch, CURLOPT_URL, $url);
     1646    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     1647    $response = curl_exec($ch);
     1648    curl_close($ch);
     1649    return $response;
     1650}
     1651
     1652function custom_array_intersect($firstArray, $secondArray){
     1653  $intersection = [];
     1654  foreach ($firstArray as $a){
     1655      $A = strtolower($a);
     1656      foreach ($secondArray as $b) {
     1657      $B = strtolower($b);
     1658      if ($A === $B) {
     1659          $intersection[] = array($a,$b);
     1660          break;
     1661      }
     1662      }
     1663  }
     1664  return $intersection;
     1665}
     1666
    14821667//Import Subject Areas
    14831668function oer_importSubjectAreas($default=false) {
     
    20212206}
    20222207
     2208function oer_is_sll_resource($url) {
     2209    $match = false;
     2210   
     2211    //$pattern = '/^(http(s)?:\/\/)?((w){3}.)?learninglab.si?(\.edu)?\/.+/';
     2212    $pattern = '/^(http(s)?:\/\/)?((w){3}.)?learninglab.si?(\.edu)?\/resource(s)\/view\/.+/';
     2213    $pattern_match = preg_match($pattern, $url, $matches);
     2214   
     2215    if ($pattern_match == 1)
     2216        $match = true;
     2217       
     2218    return $match;
     2219}
     2220
     2221function oer_is_sll_collection($url) {
     2222    $match = false;
     2223   
     2224    //$pattern = '/^(http(s)?:\/\/)?((w){3}.)?learninglab.si?(\.edu)?\/.+/';
     2225    $pattern = '/^(http(s)?:\/\/)?((w){3}.)?learninglab.si?(\.edu)?\/(collection(s)|q)\/.+/';
     2226    $pattern_match = preg_match($pattern, $url, $matches);
     2227   
     2228    if ($pattern_match == 1)
     2229        $match = true;
     2230       
     2231    return $match;
     2232}
     2233
    20232234//Generate youtube embed code
    20242235function oer_generate_youtube_embed_code($url) {
     
    20612272   
    20622273    return $thumbnail_file;
     2274}
     2275
     2276function oer_generate_sll_resource_embed_code($url){
     2277    $embed_code = "";
     2278   
     2279    $sll_resource_id = oer_get_ssl_resource_id($url);
     2280   
     2281    //Generate embed code
     2282    if ($sll_resource_id) {
     2283        $embed_code = '<script type="text/javascript" src="https://learninglab.si.edu/embed/widget/q/r/'.$sll_resource_id.'/embed.js"></script><div class="sll-embed" data-widget-type="r" data-widget-key="'.$sll_resource_id.'"></div>';
     2284    }
     2285    return $embed_code;
     2286}
     2287
     2288function oer_get_ssl_resource_id($url){
     2289    $resource_id = null;
     2290   
     2291    if (preg_match('/learninglab\.si\.edu\/resources\/view\/([^\&\?\/]+)/', $url, $id)) {
     2292        $resource_id = $id[1];
     2293    }
     2294   
     2295    return $resource_id;
     2296}
     2297
     2298function oer_generate_sll_collection_embed_code($url){
     2299    $embed_code = "";
     2300   
     2301    $sll_collection_id = oer_get_ssl_collection_id($url);
     2302   
     2303    //Generate embed code
     2304    if ($sll_collection_id) {
     2305        $embed_code = '<script type="text/javascript" src="https://learninglab.si.edu/embed/widget/q/c/'.$sll_collection_id.'/embed.js"></script><div class="sll-embed" data-widget-type="c" data-widget-key="'.$sll_collection_id.'"></div>';
     2306    }
     2307    return $embed_code;
     2308}
     2309
     2310function oer_get_ssl_collection_id($url){
     2311    $collection_id = null;
     2312   
     2313    if (preg_match('/learninglab\.si\.edu\/collections\/[A-Za-z0-9\_\@\.\/\#\&\+\-]*\/([^\&\?\/]+)/', $url, $id)) {
     2314        $collection_id = $id[1];
     2315    }elseif (preg_match('/learninglab\.si\.edu\/q\/[A-Za-z0-9\_\@\.\/\#\&\+\-]*\/([^\&\?\/]+)/', $url, $id)) {
     2316        $collection_id = $id[1];
     2317    }
     2318   
     2319    if (substr($collection_id,-2)=="#r"){
     2320        $collection_id = substr($collection_id,0,strrpos($collection_id,"#r"));
     2321    }
     2322   
     2323    return $collection_id;
    20632324}
    20642325
     
    21042365}
    21052366
     2367//Replace PDF Url to embedded PDF
     2368//add_filter( 'the_content' , 'replace_pdf_to_embed' );
     2369function replace_pdf_to_embed($content){
     2370    $pattern = '/(http|https):\/\/.*?\.pdf\b/i';
     2371
     2372    $matches = array();
     2373
     2374    preg_match_all($pattern, $content, $matches);
     2375   
     2376    foreach ($matches[0] as $match) {
     2377    $match_url = strip_tags($match);
     2378    if(shortcode_exists('wonderplugin_pdf')) {
     2379        $embed_code = "[wonderplugin_pdf src='".$match_url."' width='100%']";
     2380    } elseif(shortcode_exists('pdf-embedder')){
     2381        $embed_code = "[pdf-embedder url='".$match_url."' width='100%']";
     2382    } elseif(shortcode_exists('pdfviewer')){
     2383        $embed_code = "[pdfviewer width='100%']".$match_url."[/pdfviewer]";
     2384    } else {
     2385        $pdf_url = OER_URL."pdfjs/web/viewer.html?file=".urlencode($match_url);
     2386        $embed_code = '<iframe class="oer-pdf-viewer" width="100%" src="'.$pdf_url.'"></iframe>';
     2387    }
     2388    if ($embed_code)
     2389        $content = str_replace($match, $embed_code, $content);
     2390    }
     2391    return $content;
     2392}
     2393
     2394function is_pdf_resource($url) {
     2395    $is_pdf = false;
     2396   
     2397    if (preg_match('/(http|https):\/\/.*?\.pdf\b/i', $url, $id))
     2398        $is_pdf = true;
     2399
     2400    return $is_pdf;
     2401}
     2402
     2403function is_external_url($url) {
     2404    $is_external = false;
     2405   
     2406    $base_host = parse_url(home_url(), PHP_URL_HOST);
     2407    $url_host = parse_url($url, PHP_URL_HOST);
     2408   
     2409    if ($base_host !== $url_host)
     2410        $is_external = true;
     2411   
     2412    return $is_external;
     2413}
     2414
     2415/**
     2416 * Get Standards Count
     2417 **/
     2418function get_standards_count(){
     2419    global $wpdb;
     2420    $cnt = 0;
     2421   
     2422    $query = "SELECT count(*) FROM {$wpdb->prefix}oer_core_standards";
     2423
     2424    $cnt = $wpdb->get_var($query);
     2425   
     2426    return $cnt;
     2427}
     2428
     2429/**
     2430 * Get Standards
     2431 **/
     2432function get_standards(){
     2433    global $wpdb;
     2434   
     2435    $query = "SELECT * FROM {$wpdb->prefix}oer_core_standards";
     2436   
     2437    $standards = $wpdb->get_results($query);
     2438   
     2439    return $standards;
     2440}
     2441
     2442/**
     2443 * Get Standard By Slug
     2444 **/
     2445function get_standard_by_slug($slug){
     2446    global $wpdb;
     2447   
     2448    $std = null;
     2449   
     2450    $query = "SELECT * FROM {$wpdb->prefix}oer_core_standards";
     2451   
     2452    $standards = $wpdb->get_results($query);
     2453   
     2454    foreach($standards as $standard){
     2455        if (sanitize_title($standard->standard_name)===$slug)
     2456            $std = $standard;
     2457    }
     2458   
     2459    return $std;
     2460}
     2461
     2462/**
     2463 * Get Standard By Id
     2464 **/
     2465function get_standard_by_id($id){
     2466    global $wpdb;
     2467   
     2468    $std = null;
     2469   
     2470    $query = "SELECT * FROM {$wpdb->prefix}oer_core_standards WHERE id = %d";
     2471   
     2472    $standards = $wpdb->get_results($wpdb->prepare($query,$id));
     2473   
     2474    foreach($standards as $standard){
     2475            $std = $standard;
     2476    }
     2477   
     2478    return $std;
     2479}
     2480
     2481/**
     2482 * Get SubStandard By Slug
     2483 **/
     2484function get_substandard_by_slug($slug){
     2485    global $wpdb;
     2486   
     2487    $std = null;
     2488   
     2489    $query = "SELECT * FROM {$wpdb->prefix}oer_sub_standards";
     2490   
     2491    $substandards = $wpdb->get_results($query);
     2492   
     2493    foreach($substandards as $substandard){
     2494        if (sanitize_title($substandard->standard_title)===$slug)
     2495            $std = $substandard;
     2496    }
     2497   
     2498    return $std;
     2499}
     2500
     2501/**
     2502 * Get child standards of a core standard
     2503 **/
     2504function get_substandards($standard_id, $core=true){
     2505    global $wpdb;
     2506   
     2507    if ($core)
     2508        $std_id = "core_standards-".$standard_id;
     2509    else
     2510        $std_id = "sub_standards-".$standard_id;
     2511   
     2512    $substandards = array();
     2513   
     2514    $query = "SELECT * FROM {$wpdb->prefix}oer_sub_standards where parent_id='%s'";
     2515   
     2516    $substandards = $wpdb->get_results($wpdb->prepare($query, $std_id));
     2517   
     2518    return $substandards;
     2519}
     2520
     2521/**
     2522 * Get Standard Notations under a Sub Standard
     2523 **/
     2524function get_standard_notations($standard_id){
     2525    global $wpdb;
     2526   
     2527    $std_id = "sub_standards-".$standard_id;
     2528   
     2529    $notations = array();
     2530   
     2531    $query = "SELECT * FROM {$wpdb->prefix}oer_standard_notation where parent_id='%s'";
     2532   
     2533    $result = $wpdb->get_results($wpdb->prepare($query, $std_id));
     2534   
     2535    foreach ($result as $row){
     2536        $notations[] = $row;
     2537    }
     2538   
     2539    return $notations;
     2540}
     2541
     2542/**
     2543 * Get Parent Sub Standard by Notation
     2544 **/
     2545function get_substandard_by_notation($notation) {
     2546    global $wpdb;
     2547   
     2548    $std = null;
     2549   
     2550    $query = "SELECT * FROM {$wpdb->prefix}oer_standard_notation WHERE standard_notation = '%s'";
     2551   
     2552    $substandards = $wpdb->get_results($wpdb->prepare($query, $notation));
     2553   
     2554    foreach($substandards as $substandard){
     2555        $std = $substandard;
     2556    }
     2557   
     2558    return $std;
     2559}
     2560
     2561/**
     2562 * Get Core Standard by Notation
     2563 **/
     2564function get_standard_by_notation($notation){
     2565    global $wpdb;
     2566   
     2567    $std = null;
     2568   
     2569    $query = "SELECT * FROM {$wpdb->prefix}oer_standard_notation WHERE standard_notation = '%s'";
     2570   
     2571    $standard_notation = $wpdb->get_results($wpdb->prepare($query, $notation));
     2572   
     2573    if ($standard_notation){
     2574        $substandard_id = $standard_notation[0]->parent_id;
     2575        $substandard = oer_get_parent_standard($substandard_id);
     2576       
     2577        if (strpos($substandard[0]['parent_id'],"core_standards")!==false){
     2578            $pIds = explode("-",$substandard[0]['parent_id']);
     2579           
     2580            if (count($pIds)>1){
     2581                $parent_id=(int)$pIds[1];
     2582                $std = get_standard_by_id($parent_id);
     2583            }
     2584        }
     2585    }
     2586   
     2587    return $std;
     2588}
     2589
     2590/**
     2591 * Get Substandard(s) by Notation
     2592 **/
     2593function get_substandards_by_notation($notation){
     2594    global $wpdb;
     2595   
     2596    $std = null;
     2597   
     2598    $query = "SELECT * FROM {$wpdb->prefix}oer_standard_notation WHERE standard_notation = '%s'";
     2599   
     2600    $standard_notation = $wpdb->get_results($wpdb->prepare($query, $notation));
     2601   
     2602    if ($standard_notation){
     2603        $substandard_id = $standard_notation[0]->parent_id;
     2604        $std = get_hierarchical_substandards($substandard_id);
     2605    }
     2606   
     2607    return $std;
     2608}
     2609
     2610/**
     2611 * Get hierarchical substandards by substandard id
     2612 **/
     2613function get_hierarchical_substandards($substandard_id) {
     2614   
     2615    $stds = null;
     2616   
     2617    $substandard = oer_get_parent_standard($substandard_id);
     2618   
     2619    foreach($substandard as $std){
     2620        $stds[] = $std;
     2621    }
     2622   
     2623    if (strpos($substandard[0]['parent_id'],"sub_standards")!==false){
     2624        $stds[] = get_hierarchical_substandards($substandard[0]['parent_id']);
     2625    }
     2626   
     2627    return $stds;
     2628}
     2629
     2630/**
     2631 * Get Resources by notation
     2632 **/
     2633function get_resources_by_notation($notation_id) {
     2634   
     2635    $notation = "standard_notation-".$notation_id;
     2636   
     2637    //later in the request
     2638    $args = array(
     2639        'post_type'  => 'resource', //or a post type of your choosing
     2640        'posts_per_page' => -1,
     2641        'meta_query' => array(
     2642            array(
     2643            'key' => 'oer_standard',
     2644            'value' => $notation,
     2645            'compare' => 'like'
     2646            )
     2647        )
     2648    );
     2649   
     2650    $query = new WP_Query($args);
     2651   
     2652    return $query->posts;
     2653}
     2654
     2655function get_child_notations($notation_id){
     2656    global $wpdb;
     2657   
     2658    $notation = "standard_notation-".$notation_id;
     2659   
     2660    $query = "SELECT * FROM {$wpdb->prefix}oer_standard_notation WHERE parent_id = '%s'";
     2661   
     2662    $standard_notations = $wpdb->get_results($wpdb->prepare($query, $notation));
     2663   
     2664    return $standard_notations;
     2665}
     2666
     2667/**
     2668 * Get Resource Count By Notation
     2669 **/
     2670function get_resource_count_by_notation($notation_id){
     2671    $cnt = 0;
     2672   
     2673    $notation = "standard_notation-".$notation_id;
     2674   
     2675    //later in the request
     2676    $args = array(
     2677        'post_type'  => 'resource', //or a post type of your choosing
     2678        'posts_per_page' => -1,
     2679        'meta_query' => array(
     2680            array(
     2681            'key' => 'oer_standard',
     2682            'value' => $notation,
     2683            'compare' => 'like'
     2684            )
     2685        )
     2686    );
     2687   
     2688    $query = new WP_Query($args);
     2689   
     2690    $cnt += count($query->posts);
     2691   
     2692    $child_notations = get_child_notations($notation_id);
     2693   
     2694    if ($child_notations){
     2695        foreach ($child_notations as $child_notation){
     2696            $cnt += get_resource_count_by_notation($child_notation->id);
     2697        }
     2698    }
     2699   
     2700    return $cnt;
     2701}
     2702
     2703/**
     2704 * Get Resource Count By Sub-Standard
     2705 **/
     2706function get_resource_count_by_substandard($substandard_id){
     2707    $cnt = 0;
     2708   
     2709    $child_substandards = get_substandards($substandard_id, false);
     2710   
     2711    if(count($child_substandards)>0){
     2712        foreach($child_substandards as $child_substandard){
     2713            $cnt += get_resource_count_by_substandard($child_substandard->id, false);
     2714        }
     2715    }
     2716    $notations = get_standard_notations($substandard_id);
     2717   
     2718    if ($notations){
     2719        foreach($notations as $notation){
     2720            $cnt += get_resource_count_by_notation($notation->id);
     2721        }
     2722    }
     2723    return $cnt;
     2724}
     2725
     2726/**
     2727 * Get Resource Count By Standard
     2728 **/
     2729function get_resource_count_by_standard($standard_id){
     2730   
     2731    $cnt = 0;
     2732   
     2733    $substandards = get_substandards($standard_id);
     2734   
     2735    if(count($substandards)>0){
     2736        foreach($substandards as $substandard){
     2737            $cnt += get_resource_count_by_substandard($substandard->id);
     2738        }
     2739    }
     2740    $notations = get_standard_notations($standard_id);
     2741   
     2742    if ($notations){
     2743        foreach($notations as $notation){
     2744            $cnt += get_resource_count_by_notation($notation->id);
     2745        }
     2746    }
     2747    return $cnt;
     2748}
     2749
     2750/**
     2751 * Get Core Standard by standard or substandard ID
     2752 **/
     2753function get_corestandard_by_standard($parent_id){
     2754    global $wpdb;
     2755   
     2756    $standard = null;
     2757    $parent = explode("-",$parent_id);
     2758    if ($parent[0]=="sub_standards") {
     2759        $query = "SELECT * FROM {$wpdb->prefix}oer_sub_standards WHERE id = '%s'";
     2760        $substandards = $wpdb->get_results($wpdb->prepare($query, $parent[1]));
     2761       
     2762        foreach($substandards as $substandard){
     2763            $standard = get_corestandard_by_standard($substandard->parent_id);
     2764        }
     2765    } else {
     2766        $query = "SELECT * FROM {$wpdb->prefix}oer_core_standards WHERE id = '%s'";
     2767        $standards = $wpdb->get_results($wpdb->prepare($query, $parent[1]));
     2768        foreach($standards as $std){
     2769            $standard = $std;
     2770        }
     2771    }
     2772   
     2773    return $standard;
     2774}
     2775
     2776/**
     2777 * Add OER Resource
     2778 **/
     2779function oer_add_resource($resource) {
     2780    $post_name = "";
     2781    $oer_resourceurl = "";
     2782    $file = "";
     2783    $post_id = null;
     2784    $category_id = array();
     2785    $oer_kywrd = null;
     2786   
     2787    if (!empty($resource['tags'])){
     2788        $oer_kywrd = $resource['tags'];
     2789    }
     2790   
     2791    // Save Subject Areas
     2792    if(!empty($resource['subject_areas'])){
     2793        $oer_categories = $resource['subject_areas'];
     2794        if (is_array($oer_categories)) {
     2795            $categories = array();
     2796            foreach($oer_categories as $cat)
     2797            {
     2798                if (strpos($cat,"--")){
     2799                    $cats = explode(" -- ", $cat);
     2800                    $categories = array_merge($categories, $cats);
     2801                } else {
     2802                    $categories[] = $cat;   
     2803                }
     2804            }
     2805            $categories = array_unique($categories);
     2806            if(!empty($categories)){
     2807                foreach($categories as $category){
     2808                    $cat = get_term_by( 'name', trim($category), 'resource-subject-area' );
     2809                    if($cat){
     2810                        $category_id[$i] = $cat->term_id;
     2811                    }
     2812                    else{
     2813                        // Categories are not found then assign as keyword
     2814                        $oer_kywrd[] = $category;
     2815                    }
     2816                }
     2817            }
     2818        }
     2819    }
     2820   
     2821    //Check if resource title is set
     2822    if ( isset( $resource['title'] ) ){
     2823        $post_name = strtolower($resource['title']);
     2824        $post_name = str_replace(' ','_', $post_name);
     2825    }
     2826
     2827    // Save resource title
     2828    if(!empty($resource['title']) && !empty($resource['resource_url']))
     2829    {
     2830        /** Get Current WP User **/
     2831        $user_id = get_current_user_id();
     2832        /** Get Current Timestamp for post_date **/
     2833        $cs_date = current_time('mysql');
     2834
     2835        $post = array('post_content' => $resource['description'], 'post_name' => $post_name, 'post_title' => $resource['title'], 'post_status' => 'publish', 'post_type' => 'resource', 'post_author' => $user_id , 'post_date' => $cs_date, 'post_date_gmt'  => $cs_date, 'comment_status' => 'open');
     2836        /** Set $wp_error to false to return 0 when error occurs **/
     2837        $post_id = wp_insert_post( $post, false );
     2838       
     2839        //Set Category of Resources
     2840        $tax_ids = wp_set_object_terms( $post_id, $category_id, 'resource-subject-area', true );
     2841
     2842        // Set Tags
     2843        if (!is_array($oer_kywrd))
     2844            $oer_kywrd = explode(",", $oer_kywrd);
     2845       
     2846        wp_set_post_tags(  $post_id, $oer_kywrd , true );
     2847    }
     2848   
     2849    // Save Resource URL and Create Screenshot
     2850    if( !empty($resource['resource_url']) )
     2851    {
     2852        if ( preg_match('/http/',$resource['resource_url']) )
     2853        {
     2854            $oer_resourceurl = $resource['resource_url'];
     2855        }
     2856        else
     2857        {
     2858            $oer_resourceurl = 'http://'.$resource['resource_url'];
     2859        }
     2860        update_post_meta( $post_id , 'oer_resourceurl' , esc_url_raw($oer_resourceurl));
     2861       
     2862        //Create Screenshot
     2863        //--------------------------------------
     2864        $url = esc_url_raw($oer_resourceurl);
     2865        $upload_dir = wp_upload_dir();
     2866
     2867        //if screenshot is enabled
     2868        $screenshot_enabled = get_option( 'oer_enable_screenshot' );
     2869        //if external service screenshot is enabled
     2870        $external_screenshot = get_option( 'oer_external_screenshots' );
     2871
     2872        if(!has_post_thumbnail( $post_id ))
     2873        {
     2874            if ($screenshot_enabled) {
     2875                $file = oer_getScreenshotFile($url);
     2876            } elseif ( $external_screenshot ) {
     2877                // if external screenshot utility enabled
     2878                $file = oer_getImageFromExternalURL($url);
     2879            }
     2880        }
     2881       
     2882        if(file_exists($file))
     2883        {
     2884            $filetype = wp_check_filetype( basename( $file ), null );
     2885            $wp_upload_dir = wp_upload_dir();
     2886           
     2887            $guid = $wp_upload_dir['url'] . '/' . basename( $file );
     2888
     2889            $attachment = array(
     2890                'guid'           => $guid,
     2891                'post_mime_type' => $filetype['type'],
     2892                'post_title'     => preg_replace( '/\.[^.]+$/', '', basename( $file ) ),
     2893                'post_content'   => '',
     2894                'post_status'    => 'inherit'
     2895            );
     2896           
     2897            $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
     2898            update_post_meta($post_id, "_thumbnail_id", $attach_id);
     2899
     2900            // Generate the metadata for the attachment, and update the database record.
     2901            $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
     2902            wp_update_attachment_metadata( $attach_id, $attach_data );
     2903        }
     2904        //--------------------------------------
     2905    }
     2906   
     2907    // Save Date Created
     2908    if(!empty($resource['date_created'])){
     2909        update_post_meta( $post_id , 'oer_datecreated' , $resource['date_created']);
     2910    }
     2911   
     2912    // Save Author Type
     2913    if(!empty($resource['author_type'])){
     2914        update_post_meta( $post_id , 'oer_authortype' , sanitize_text_field($resource['author_type']));
     2915    }
     2916   
     2917    // Save Author Name
     2918    if(!empty($resource['author_name'])){
     2919        update_post_meta( $post_id , 'oer_authorname' , sanitize_text_field($resource['author_name']));
     2920    }
     2921   
     2922    // Save Author Url
     2923    if(!empty($resource['author_url'])){
     2924        $oer_authorurl = $resource['author_url'];
     2925        if ( preg_match('/http/',$oer_authorurl) ){
     2926            $oer_authorurl = $oer_authorurl;
     2927        }
     2928        else{
     2929            $oer_authorurl = 'http://'.$oer_authorurl;
     2930        }
     2931        update_post_meta( $post_id , 'oer_authorurl' , esc_url_raw($oer_authorurl));
     2932    }
     2933   
     2934    // Save Publisher name
     2935    if(isset($resource['publisher_name'])){
     2936        update_post_meta( $post_id , 'oer_publishername' , sanitize_text_field($resource['publisher_name']));
     2937    }
     2938
     2939    // Save publisher url
     2940    if(isset($resource['publisher_url']))
     2941    {
     2942        $oer_publisherurl = $resource['publisher_url'];
     2943        if( !empty($resource['publisher_url']) )
     2944        {
     2945            if ( preg_match('/http/',$oer_publisherurl) )
     2946            {
     2947                $oer_publisherurl = $resource['publisher_url'];
     2948            }
     2949            else
     2950            {
     2951                $oer_publisherurl = 'http://'.$resource['publisher_url'];
     2952            }
     2953        }
     2954        update_post_meta( $post_id , 'oer_publisherurl' , esc_url_raw($oer_publisherurl));
     2955    }
     2956   
     2957    // Save media type
     2958    if(!empty($resource['media_type'])){
     2959        update_post_meta( $post_id , 'oer_mediatype' , sanitize_text_field($resource['media_type']));
     2960    }
     2961   
     2962    // Save Learning Resource Type
     2963    if(!empty($resource['lr_type'])){
     2964        update_post_meta( $post_id , 'oer_lrtype' , sanitize_text_field($resource['media_type']));
     2965    }
     2966   
     2967    // Save Interactivity
     2968    if(!empty($resource['interactivity'])){
     2969        update_post_meta( $post_id , 'oer_interactivity' , sanitize_text_field($resource['interactivity']));
     2970    }
     2971   
     2972    // Save Based On URL
     2973    if(!empty($resource['based_on_url'])){
     2974        update_post_meta( $post_id , 'oer_isbasedonurl' , sanitize_text_field($resource['based_on_url']));
     2975    }
     2976   
     2977}
     2978
     2979// Checks if resource exists
     2980function resource_exists($resource){
     2981    $exists = false;
     2982   
     2983    $args = array(
     2984        'fields' => 'ids',
     2985        'post_type'  => 'resource',
     2986        'meta_query' => array(
     2987            array(
     2988                'key' => 'oer_resourceurl',
     2989                'value' => $resource['resource_url']
     2990            )
     2991        )
     2992    );
     2993   
     2994    $my_query = new WP_Query( $args );
     2995   
     2996    if( $my_query->post_count>0 ) {
     2997        $exists = true;
     2998    }
     2999    return $exists;
     3000}
     3001
     3002// Get Hierarchical Notations
     3003function get_hierarchical_notations($notation_id){
     3004    $notation=null;
     3005    $notations = array();
     3006    $hierarchy = "";
     3007    $ids = explode("-",$notation_id);
     3008    if (strpos($notation_id,"standard_notation")!==false) {
     3009        do {
     3010            $notation = get_notation_details($ids[1]);
     3011            $ids = explode("-", $notation[0]['parent_id']);
     3012            $notations[] = $notation;
     3013        } while(strpos($notation[0]['parent_id'],"standard_notation")!==false);
     3014    }
     3015    return $notations;
     3016}
     3017
     3018// Get Notation Details
     3019function get_notation_details($notation_id){
     3020    global $wpdb;
     3021    $notations = null;
     3022    $results = $wpdb->get_results( $wpdb->prepare( "SELECT * from " . $wpdb->prefix. "oer_standard_notation where id = %s" , $notation_id  ) , ARRAY_A);
     3023    foreach ($results as $row){
     3024        $notations = $row;
     3025    }
     3026    return $notations;
     3027}
     3028
     3029// Get Hierarchical Substandards
     3030function oer_get_hierarchical_substandards($substandard_id){
     3031    $substandard=null;
     3032    $substandards = null;
     3033    $hierarchy = "";
     3034    $ids = explode("-",$substandard_id);
     3035    if (strpos($substandard_id,"sub_standards")!==false) {
     3036        do {
     3037           
     3038            $substandard = oer_get_substandard_details($ids[1]);
     3039            $ids = explode("-", $substandard['parent_id']);
     3040            $substandards[] = $substandard;
     3041           
     3042        } while(strpos($substandard['parent_id'],"sub_standards")!==false);
     3043    }
     3044   
     3045    return $substandards;
     3046}
     3047
     3048// Get Substandard Details
     3049function oer_get_substandard_details($substandard_id){
     3050    global $wpdb;
     3051    $substandards = null;
     3052    $results = $wpdb->get_results( $wpdb->prepare( "SELECT * from " . $wpdb->prefix. "oer_sub_standards where id = %s" , $substandard_id  ) , ARRAY_A);
     3053    foreach ($results as $row){
     3054        $substandards = $row;
     3055    }
     3056    return $substandards;
     3057}
    21063058?>
  • wp-oer/trunk/includes/settings.php

    r1714161 r1971883  
    192192        </div>
    193193    </div>
    194     <div class="oer-plugin-row">
    195         <form method="post" class="oer_settings_form" action="options.php"  onsubmit="return processInitialSettings(this)">
     194    <form method="post" class="oer_settings_form" action="options.php"  onsubmit="return processInitialSettings(this)">
     195        <?php settings_fields("oer_general_settings"); ?>
     196        <div class="oer-plugin-row plugin-row-first">
     197            <fieldset>
     198                <legend><div class="oer_hdng"><?php _e("PDF Embeds", OER_SLUG); ?></div></legend>
     199                <?php do_settings_sections("embed_settings"); ?>
     200            </fieldset>
     201        </div>
     202        <div class="oer-plugin-row">
    196203            <fieldset>
    197204                <legend><div class="oer_hdng"><?php _e("Screenshot Utility", OER_SLUG); ?></div></legend>
    198                 <?php settings_fields("oer_general_settings"); ?>
    199205                <?php do_settings_sections("oer_settings"); ?>
    200                 <?php submit_button(); ?>
    201206            </fieldset>
    202         </form>
    203     </div>
     207        </div>
     208        <?php submit_button(); ?>
     209    </form>
    204210</div>
    205211
  • wp-oer/trunk/js/back_scripts.js

    r1823963 r1971883  
    200200}
    201201
     202//Import LR Resources
     203function processLRImport(btn, input) {
     204    var max_time = jQuery(btn).attr('data-max-time');
     205   
     206    if ( document.getElementById(input).value === "" ) {
     207        return false;
     208    }
     209    if (jQuery('.notice-red').length>0) {
     210        jQuery('.notice-red').remove();
     211    }
     212   
     213    jQuery(btn).prop('value','Processing...');
     214   
     215    setTimeout(function() {
     216        var Top = document.documentElement.scrollTop || document.body.scrollTop;
     217        jQuery('.loader .loader-img').css({'padding-top':Top + 'px'});
     218        jQuery('.loader .loader-img > div').append("<div class='loader-notice'>LR Import Execution Timeout: " + max_time + " seconds</div>");
     219        jQuery('.loader').show();
     220        } ,1000);
     221    jQuery('.oer_imprtrwpr .oer-import-row input[type=submit]').prop('disabled',true);
     222    return(true);
     223}
     224
    202225//Import Standards
    203226function importStandards(frm,btn) {
  • wp-oer/trunk/oer_template/single-resource.php

    r1823963 r1971883  
    2525
    2626$youtube = oer_is_youtube_url($url);
     27$isSSLResource = oer_is_sll_resource($url);
     28$isSLLCollection = oer_is_sll_collection($url);
     29$isPDF = is_pdf_resource($url);
     30$isExternal = is_external_url($url);
    2731
    2832$hide_title = get_option('oer_hide_resource_title');
     
    6872        $subject_areas = array_merge($subject_areas,$subjects);
    6973}
    70 
     74$embed_disabled = false;
    7175?>
    7276<!--<div id="primary" class="content-area">-->
     
    7579    <article id="oer-resource-<?php the_ID(); ?>" class="oer_sngl_resource_wrapper post-content">
    7680        <div id="sngl-resource" class="entry-content oer-cntnr post-content oer_sngl_resource_wrapper row">
    77         <?php if (!$hide_title): ?>
     81    <?php if (!$hide_title): ?>
    7882        <header class="entry-header">
    7983            <h1 class="entry-title"><?php echo $post->post_title;?></h1>
    8084        </header>
    8185    <?php endif; ?>
    82             <div class="oer-rsrclftcntr-img col-md-5 col-sm-12 col-xs-12">
    83                 <!--Resource Image-->
    84                 <div class="oer-sngl-rsrc-img">
    85             <?php if ($youtube) {
    86                 $embed = oer_generate_youtube_embed_code($url);
    87                 echo $embed;
    88              } else { ?>
    89              <a class="oer-featureimg" href="<?php echo esc_url(get_post_meta($post->ID, "oer_resourceurl", true)) ?>" target="_blank" >
    90                 <?php
    91                     $img_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) , "full" );
    92                     $img_path = $new_img_path = parse_url($img_url[0]);
    93                     $img_path = $_SERVER['DOCUMENT_ROOT'] . $img_path['path'];
    94                     $new_image_url = OER_URL.'images/default-icon-528x455.png';
    95                 $img_width = oer_get_image_width('large');
    96                 $img_height = oer_get_image_height('large');
    97                
    98             if(!empty($img_url))
    99                 {
    100                 if ( is_wp_error($img_url) ) {
    101                     debug_log("Can't get Image editor to resize Resource screenshot.");
    102                 } else {
    103                     $new_image_url = oer_resize_image($img_url[0], $img_width, $img_height, true);
    104                 }
    105             }
    106            
    107                     echo '<img src="'.esc_url($new_image_url).'" alt="'.esc_attr(get_the_title()).'"/>';
     86       
     87    <?php
     88    if ($youtube || $isSSLResource || $isSLLCollection)
     89        include(OER_PATH.'oer_template/single-resource-youtube.php');
     90    else
     91        include(OER_PATH.'oer_template/single-resource-standard.php');
     92    ?>
    10893
    109                     ?>
    110                     </a>
    111             <?php } ?>
    112                 </div>
    113             </div>
    114 
    115             <div class="oer-rsrcrghtcntr col-md-7 col-sm-12 col-xs-12">
    116             <div class="oer-rsrcctgries tagcloud">
    117                     <?php
    118             /** Resource Subject Areas **/
    119             $subjects = array_unique($subject_areas, SORT_REGULAR);
    120            
    121                 if(!empty($subjects))
    122                 {
    123                     foreach($subjects as $subject)
    124                     {
    125                         echo '<span><a href="'.esc_url(site_url().'/'.$subject->taxonomy.'/'.$subject->slug).'" class="button">'.ucwords ($subject->name).'</a></span>';
    126                     }
    127                 }
    128                 ?>
    129                         </div>
    130 
    131                         <!--Resource Description-->
    132             <?php if(!empty($post->post_content)) {?>
    133                 <div class="oer-sngl-rsrc-dscrptn">
    134                     <h2><?php _e("Description", OER_SLUG) ?></h2>
    135                     <?php echo $content = apply_filters ("the_content", $post->post_content); ?>
    136                 </div>
    137             <?php } ?>
    138            
    139             <?php if ($youtube) { ?>
    140                 <div class="oer-rsrcurl oer-cbxl"><h4><strong>Original Resource:</strong> <a href="<?php echo esc_url(get_post_meta($post->ID, "oer_resourceurl", true)); ?>" target="_blank" ><?php echo esc_url(get_post_meta($post->ID, "oer_resourceurl", true)); ?></a></h4></div>
    141             <?php } else { ?>
    142                 <div class="oer-rsrcurl oer-cbxl"><h4><strong>Original Resource:</strong> <a href="<?php echo esc_url(get_post_meta($post->ID, "oer_resourceurl", true)); ?>" target="_blank" ><?php echo $url_domain; ?></a></h4></div>
    143             <?php } ?>
    144 
    145                         <div id="" class="oer-authorName oer-cbxl">
    146                             <?php
    147                                 $oer_authorname = get_post_meta($post->ID, "oer_authorname", true);
    148                                 $oer_authorurl = get_post_meta($post->ID, "oer_authorurl", true);
    149 
    150                                 if(!empty($oer_authorname) && !empty($oer_authorurl))
    151                                 {
    152                                 ?>
    153                                     <h4><strong><?php _e("Creator:", OER_SLUG) ?></strong>
    154                                     <span><a href="<?php echo esc_url($oer_authorurl); ?>" target="_blank"><?php echo $oer_authorname; ?></a></span></h4>
    155                                 <?php } ?>
    156                         </div>
    157                             <?php
    158                 $oer_publishername = get_post_meta($post->ID, "oer_publishername", true);
    159                 $oer_publisherurl = get_post_meta($post->ID, "oer_publisherurl", true);
    160 
    161                 if(!empty($oer_publishername) && !empty($oer_publisherurl))
    162                 {
    163                 ?>
    164                 <div id="" class="oer-publisherName oer-cbxl">
    165                     <h4><strong><?php _e("Publisher:", OER_SLUG) ?></strong>
    166                     <span><a href="<?php echo esc_url($oer_publisherurl); ?>" target="_blank"><?php echo $oer_publishername; ?></a></span></h4>
    167                 </div>
    168                 <?php } ?>
    169                         <div id="" class="oer-mediaType oer-cbxl">
    170                             <?php
    171                                 $oer_mediatype = get_post_meta($post->ID, "oer_mediatype", true);
    172                                 if(!empty($oer_mediatype))
    173                                 { ?>
    174                                     <h4><strong><?php _e("Type:", OER_SLUG) ?></strong>
    175                                     <span><?php echo ucwords($oer_mediatype); ?></span></h4>
    176                             <?php } ?>
    177                         </div>
    178                         <?php
    179                             $grades =  trim(get_post_meta($post->ID, "oer_grade", true),",");
    180                             $grades = explode(",",$grades);
    181                        
    182                             if(is_array($grades) && !empty($grades) && array_filter($grades))
    183                             {
    184                         ?>
    185                             <div class="oer-rsrcgrd oer-cbxl">
    186                                 <h4><strong><?php
    187                             if (count($grades)>1)
    188                                 _e("Grades:", OER_SLUG);
    189                             else
    190                                 _e("Grade:", OER_SLUG)
    191                             ?></strong>
    192                                 <span>
    193                         <?php
    194                                         sort($grades);
    195 
    196                                         for($x=0; $x < count($grades); $x++)
    197                                         {
    198                                           $grades[$x];
    199                                         }
    200                                         $fltrarr = array_filter($grades, 'strlen');
    201                                         $flag = array();
    202                                         $elmnt = $fltrarr[min(array_keys($fltrarr))];
    203                                         for($i =0; $i < count($fltrarr); $i++)
    204                                         {
    205                                             if($elmnt == $fltrarr[$i] || "k" == strtolower($fltrarr[$i]))
    206                                             {
    207                                                 $flag[] = 1;
    208                                             }
    209                                             else
    210                                             {
    211                                                 $flag[] = 0;
    212                                             }
    213                                             $elmnt++;
    214                                         }
    215 
    216                                         if(in_array('0',$flag))
    217                                         {
    218                                             echo implode(",",array_unique($fltrarr));
    219                                         }
    220                                         else
    221                                         {
    222                                             $arr_flt = array_keys($fltrarr);
    223                                             $end_filter = end($arr_flt);
    224                                         if (count($fltrarr)>1) {
    225                                             if (strtolower($fltrarr[$end_filter])=="k") {
    226                                                 $last_index = count($fltrarr)-2;
    227                                                 echo $fltrarr[$end_filter]."-".$fltrarr[$last_index];
    228                                             }
    229                                             else
    230                                                 echo $fltrarr[0]."-".$fltrarr[$end_filter];
    231                                         }
    232                                         else
    233                                             echo $fltrarr[0];
    234                                         }
    235                                 ?>
    236                             </span></h4>
    237                         </div>
    238                         <?php }?>
    239 
    240                         <?php
    241                             $oer_datecreated = get_post_meta($post->ID, "oer_datecreated", true);
    242                             if(!empty($oer_datecreated))
    243                             {
    244                             ?>
    245                     <div class="oer-created oer-cbxl">
    246                         <h4><strong>Created:</strong>
    247                         <span><?php echo $oer_datecreated; ?></span></h4>
    248                     </div>
    249                         <?php } ?>
    250 
    251                         <?php
    252                             $keywords = wp_get_post_tags($post->ID);
    253                             if(!empty($keywords))
    254                             {
    255                         ?>
    256                                 <div class="oer-rsrckeyword">
    257                                     <h4><strong><?php _e("Keywords:", OER_SLUG) ?></strong></h4>
    258                                     <div class="oer_meta_container tagcloud">
    259                                    <?php
    260                                         foreach($keywords as $keyword)
    261                                         {
    262                                             echo "<span><a href='".esc_url(get_tag_link($keyword->term_id))."' class='button'>".ucwords($keyword->name)."</a></span>";
    263                                         }
    264                                     ?>
    265                                     </div>
    266                                 </div>
    267                         <?php } ?>
    268 
    269 
    270                         <!--Resource Meta Data-->
    271                         <div class="oer-sngl-rsrc-meta">
    272                             <!-- Meta Data Navigation Tab-->
    273                             <!--<div class="tabNavigator">
    274                              <a href="javascript:" data-id="tags" title="Metadata Tags" onclick="rsrc_tabs(this);">1</a>
    275                              <a href="javascript:" data-id="alignedStandards" title="Aligned Standards" onclick="rsrc_tabs(this);"><?php //echo count($stnd_arr);?></a>
    276                              <a href="javascript:" data-id="keyword" title="Keywords" onclick="rsrc_tabs(this);"><?php //echo count($keywords); ?></a>
    277                              <a href="javascript:" data-id="moreLikeThis" title="More Like This" onclick="rsrc_tabs(this);"><?php //echo $count; ?></a>
    278                            </div>-->
    279 
    280                            <!-- Meta Data Navigation Tab Related Post-->
    281                            <!--<div class="moreLikeThis" style="display: none;" >
    282                                 <h3>More Like This</h3>
    283                                 <div class="oer_meta_container">
    284                                 <?php
    285 
    286                                     /*$tags = wp_get_post_tags($post->ID);
    287                                     if ($tags)
    288                                     {
    289                                           $tag_ids = array();
    290                                           foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
    291 
    292                                           $args=array(
    293                                             'tag__in'       => $tag_ids,
    294                                             'post__not_in'  => array($post->ID),
    295                                             'showposts'     => -1,
    296                                             'post_type'     => 'resource',
    297                                             'ignore_sticky_posts'   => 1
    298                                            );
    299 
    300                                           $my_query = new WP_Query($args);
    301 
    302                                           if( $my_query->have_posts() )
    303                                           {
    304                                             while ($my_query->have_posts()) : $my_query->the_post(); */?>
    305                                                 <div class="sngl-rltd-rsrc">
    306                                                     <div class="sngl-rltd-rsrc-title">
    307                                                         <a href="<?php //the_permalink() ?>" rel="bookmark" title="<?php //the_title_attribute(); ?>"><?php //the_title(); ?></a>
    308                                                     </div>
    309                                                     <div class="sngl-rltd-rsrc-description">
    310                                                         <?php //echo the_content(); ?>
    311                                                     </div>
    312                                                     <div class="sngl-rltd-rsrc-img">
    313                                                         <?php //$img_url = wp_get_attachment_url(get_post_meta( //$post->ID, "_thumbnail_id" , true)); ?>
    314                                                         <img src="<?php //echo $img_url;?>" alt="<?php //the_title();?>"/>
    315                                                     </div>
    316                                                 </div>
    317                                               <?php
    318                                             /*endwhile;
    319                                           }
    320                                           else
    321                                           {
    322                                             echo "No Resource Found Like This!!";
    323                                           }
    324                                     }
    325                                     else
    326                                     {
    327                                         echo "No Resource Found Like This!!";
    328                                     }*/
    329                                 ?>
    330                                 </div>
    331                            </div>-->
    332                         </div>
    333                     </div> <!--Description & Resource Info at Right-->
    334 
    335                     <!-- Standards Alignment -->
    336                     <div class="oer-rsrclftcntr col-md-12">
    337 
    338                         <?php
    339 
    340                             $stdrd_id = get_post_meta($post->ID, 'oer_standard_alignment', true);
    341                             $oer_standard = get_post_meta($post->ID, 'oer_standard', true);
    342                        
    343                         $standards = explode(",", $oer_standard);
    344                         $oer_standards = array();
    345                        
    346                         foreach ($standards as $standard) {
    347                             if ($standard!=""){
    348                                 $stds = oer_get_parent_standard($standard);
    349                                 foreach($stds as $std){
    350                                     $core_std = oer_get_core_standard($std['parent_id']);
    351                                     $oer_standards[] = array(
    352                                                 'id' => $standard,
    353                                                 'core_id' => $core_std[0]['id'],
    354                                                 'core_title' => $core_std[0]['standard_name']
    355                                                  );
    356                                 }
    357                             }
    358                         }
    359                        
    360                         foreach ($oer_standards as $key => $row) {
    361                             $core[$key]  = $row['core_id'];
    362                         }
    363                        
    364                         if (!empty($oer_standards))
    365                             array_multisort($core, SORT_ASC, $oer_standards);
    366                        
    367                             if(!empty($stdrd_id) || !empty($oer_standards))
    368                             {
    369                         ?>
    370                             <div class="alignedStandards">
    371                                 <h2><?php _e("Standards Alignment", OER_SLUG) ?></h2>
    372                                 <div class="oer_meta_container">
    373                                     <!--<div class="oer_stndrd_align">-->
    374                                     <?php
    375                                         if(!empty($stdrd_id))
    376                                         {
    377                                     ?>
    378                                            <!--<h3><?php _e("Standard Alignment", OER_SLUG) ?></h3>-->
    379                                            <?php
    380                                              //$res = $wpdb->get_row( $wpdb->prepare( "select standard_name from ".$wpdb->prefix."oer_core_standards where id=%d" , $stdrd_id ), ARRAY_A);
    381                                              //echo "<div class='stndrd_ttl'>".$res['standard_name']."</div>";
    382                                         }
    383                                     ?>
    384 
    385                                     <!--</div>-->
    386 
    387                                     <div class="oer_stndrds_notn">
    388                                     <?php
    389                                         if(!empty($oer_standards))
    390                                         {
    391                         ?>
    392                         <?php
    393                         $displayed_core_standards = array();
    394                         foreach($oer_standards as $o_standard) {
    395                            
    396                             if (!in_array($o_standard['core_id'],$displayed_core_standards)){
    397                                 echo "<div class='oer-core-title'><h4><strong>".$o_standard['core_title']."</strong></h4></div>";
    398                                 $displayed_core_standards[] = $o_standard['core_id'];
    399                             }
    400                            
    401                             $oer_standard =$o_standard['id'];
    402                             $stnd_arr = explode(",", $oer_standard);
    403                            
    404                             for($i=0; $i< count($stnd_arr); $i++)
    405                             {
    406                                 $table = explode("-",$stnd_arr[$i]);
    407                                
    408                                 $table_name = $wpdb->prefix.$_oer_prefix.$table[0];
    409                                
    410                                 $id = $table[1];
    411                                
    412                                 $res = $wpdb->get_row( $wpdb->prepare("select * from $table_name where id=%d" , $id ), ARRAY_A);
    413                                
    414                                 echo "<div class='oer_sngl_stndrd'>";
    415                                 if (strpos($table_name,"sub_standards")>0) {
    416                                     echo "<span class='oer_sngl_description'>".$res['standard_title']."</span>";
    417                                 } else {
    418                                     echo "<span class='oer_sngl_notation'>".$res['standard_notation']."</span>";
    419                                     echo "<span class='oer_sngl_description'>".$res['description']."</span>";
    420                                 }
    421                                 echo "</div>";
    422                             }
    423                         }
    424                                         }
    425                                     ?>
    426                                     </div>
    427 
    428                                 </div>
    429                            </div>
    430                         <?php } ?>
    431                     </div> <!--Thumbnail & Standards Info at Left-->
    432 
    433 
    434             </div><!-- .single resource wrapper -->
     94        </div><!-- .single resource wrapper -->
    43595
    43696    </article>
     
    443103}
    444104
     105function display_default_thumbnail($post){
     106    $html = '<a class="oer-featureimg" href="'.esc_url(get_post_meta($post->ID, "oer_resourceurl", true)).'" target="_blank" >';
     107        $img_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) , "full" );
     108        $img_path = $new_img_path = parse_url($img_url[0]);
     109        $img_path = $_SERVER['DOCUMENT_ROOT'] . $img_path['path'];
     110        $new_image_url = OER_URL.'images/default-icon-528x455.png';
     111        $img_width = oer_get_image_width('large');
     112        $img_height = oer_get_image_height('large');
     113       
     114    if(!empty($img_url))
     115    {
     116        if ( is_wp_error($img_url) ) {
     117            debug_log("Can't get Image editor to resize Resource screenshot.");
     118        } else {
     119            $new_image_url = oer_resize_image($img_url[0], $img_width, $img_height, true);
     120        }
     121    }
     122   
     123    $html .= '<img src="'.esc_url($new_image_url).'" alt="'.esc_attr(get_the_title()).'"/>';
     124
     125    $html .= '</a>';
     126    return $html;
     127}
     128function get_embed_code($url){
     129    $embed_code = '<iframe class="oer-pdf-viewer" width="100%" src="'.$url.'"></iframe>';
     130    return $embed_code;
     131}
     132
    445133get_footer();
    446134?>
  • wp-oer/trunk/oer_template/tag-resource.php

    r1714161 r1971883  
    3939                        endif; ?>
    4040                        </div>
    41                     <?php }?>
     41                    <?php } else {
     42                        $new_image_url = OER_URL . 'images/default-icon-220x180.png';
     43                        echo '<div class="oer-feature-image col-md-3"><a href="'.esc_url(get_permalink($post->ID)).'"><img src="'.esc_url($new_image_url).'"></a></div>';
     44                    }?>
    4245                   
    4346                    <div class="rght-sd-cntnr-blg col-md-9">
  • wp-oer/trunk/open-educational-resources.php

    r1823963 r1971883  
    44 Plugin URI:   https://www.wp-oer.com
    55 Description:  Open Educational Resource management and curation, metadata publishing, and alignment to Common Core State Standards.
    6  Version:      0.6.1
     6 Version:      0.6.5
    77 Author:       Navigation North
    88 Author URI:   https://www.navigationnorth.com
     
    3737define( 'OER_PLUGIN_NAME', 'WP OER Plugin' );
    3838define( 'OER_ADMIN_PLUGIN_NAME', 'WP OER Plugin');
    39 define( 'OER_VERSION', '0.6.1' );
     39define( 'OER_VERSION', '0.6.5' );
    4040
    4141include_once(OER_PATH.'includes/oer-functions.php');
     42include_once(OER_PATH.'includes/template-functions.php');
    4243include_once(OER_PATH.'includes/init.php');
    4344include_once(OER_PATH.'includes/shortcode.php');
     
    4546
    4647//define global variable $debug_mode and get value from settings
    47 global $_debug, $_bootstrap, $_css, $_subjectarea, $_search_post_ids, $_w_bootstrap, $_oer_prefix, $oer_session;
     48global $_debug, $_bootstrap, $_css, $_subjectarea, $_search_post_ids, $_w_bootstrap, $_oer_prefix, $oer_session, $_gutenberg, $_use_gutenberg;
    4849
    4950if( ! defined( 'WP_SESSION_COOKIE' ) )
     
    6263$_debug = get_option('oer_debug_mode');
    6364$_bootstrap = get_option('oer_use_bootstrap');
     65$_use_gutenberg = get_option('oer_use_gutenberg');
    6466$_css = get_option('oer_additional_css');
    6567$_subjectarea = get_option('oer_display_subject_area');
     
    134136
    135137   update_option('setup_notify', true);
     138   update_option( "oer_rewrite_rules", false );
    136139
    137140   //Trigger CPT and Taxonomy creation
     
    139142   oer_create_resource_taxonomies();
    140143
     144   oer_add_rewrites();
    141145   //Trigger permalink reset
    142146   flush_rewrite_rules();
     
    515519add_action( 'admin_init' , 'oer_settings_page' );
    516520function oer_settings_page() {
     521    //Create Embed Section
     522    add_settings_section(
     523        'oer_embed_settings',
     524        '',
     525        'oer_embed_settings_callback',
     526        'embed_settings'
     527    );
     528
     529    //Add Settings field for Local PDF Resources Viewer
     530    add_settings_field(
     531        'oer_local_pdf_viewer',
     532        '',
     533        'oer_setup_settings_field',
     534        'embed_settings',
     535        'oer_embed_settings',
     536        array(
     537            'uid' => 'oer_local_pdf_viewer',
     538            'type' => 'select',
     539            'class' => 'local_pdf_viewer',
     540            'name' =>  __('Local PDF Resources', OER_SLUG),
     541            'options' =>  array(
     542                        "0" => "embed disabled(download only)",
     543                        "1" => "Google Viewer",
     544                        "2" => "Mozilla PDFJS",
     545                        "3" => "Wonderplugin PDF Embed",
     546                        "4" => "PDF Embedder",
     547                        "5" => "PDF Viewer"
     548                        ),
     549            'default' => '1'
     550        )
     551    );
     552
     553    //Add Settings field for External PDF Resources Viewer
     554    add_settings_field(
     555        'oer_external_pdf_viewer',
     556        '',
     557        'oer_setup_settings_field',
     558        'embed_settings',
     559        'oer_embed_settings',
     560        array(
     561            'uid' => 'oer_external_pdf_viewer',
     562            'type' => 'select',
     563            'class' => 'external_pdf_viewer',
     564            'name' =>  __('External PDF Resources', OER_SLUG),
     565            'options' => array(
     566                    "0" => "embed disabled (download only)",
     567                    "1" => "Google Viewer"
     568                    ),
     569            'default' => '1'
     570        )
     571    );
     572
     573    register_setting( 'oer_general_settings' , 'oer_local_pdf_viewer' );
     574    register_setting( 'oer_general_settings' , 'oer_external_pdf_viewer' );
     575
    517576    //Create General Section
    518577    add_settings_section(
     
    646705}
    647706
    648 
     707function oer_embed_settings_callback(){
     708
     709}
    649710
    650711//Initialize Style Settings Tab
     
    754815add_action( 'admin_init' , 'oer_setup_settings' );
    755816function oer_setup_settings(){
    756     global $_w_bootstrap;
     817    global $_w_bootstrap, $_gutenberg;
    757818
    758819    if ((isset($_REQUEST['post_type']) && $_REQUEST['post_type']=="resource") && (isset($_REQUEST['page']) && $_REQUEST['page']=="oer_settings")){
     
    822883        )
    823884    );
    824 
    825     /*if ($_w_bootstrap) {
    826         $bootstrap_disabled = true;
    827         $load_bootstrap = false;
    828     }*/
    829885
    830886    //Add Settings field for Importing Bootstrap CSS & JS Libraries
     
    846902    );
    847903
     904    if ( function_exists( 'register_block_type' ) ) {
     905        $_gutenberg = true;
     906    }
     907
     908    if ($_gutenberg)
     909        //Add Settings field to Enabled Gutenberg editor
     910        add_settings_field(
     911            'oer_use_gutenberg',
     912            '',
     913            'oer_setup_settings_field',
     914            'setup_settings_section',
     915            'oer_setup_settings',
     916            array(
     917                'uid' => 'oer_use_gutenberg',
     918                'type' => 'checkbox',
     919                'value' => '1',
     920                'default' => true,
     921                'name' =>  __('Use Gutenberg Editor', OER_SLUG)
     922            )
     923        );
     924
    848925    register_setting( 'oer_setup_settings' , 'oer_import_sample_resources' );
    849926    register_setting( 'oer_setup_settings' , 'oer_import_default_subject_areas' );
    850927    register_setting( 'oer_setup_settings' , 'oer_import_ccss' );
    851928    register_setting( 'oer_setup_settings' , 'oer_setup_bootstrap' );
     929    if ($_gutenberg)
     930        register_setting( 'oer_setup_settings' , 'oer_use_gutenberg' );
    852931}
    853932
     
    10811160
    10821161            echo '<input name="'.$arguments['uid'].'" id="'.$arguments['uid'].'" '.$class.' type="'.$arguments['type'].'" ' . $display_value . ' ' . $size . ' ' .  $selected . ' ' . $disabled . '  /><label for="'.$arguments['uid'].'"><strong>'.$arguments['name'].'</strong></label>';
     1162            break;
     1163        case "select":
     1164            if (isset($arguments['name']))
     1165                $title = $arguments['name'];
     1166            echo '<label for="'.$arguments['uid'].'"><strong>'.$title.'</strong></label>';
     1167            echo '<select name="'.$arguments['uid'].'" id="'.$arguments['uid'].'">';
     1168
     1169            if (isset($arguments['options']))
     1170                $options = $arguments['options'];
     1171
     1172            foreach($options as $key=>$desc){
     1173                $selected = "";
     1174                if ($value===false){
     1175                    if ($key==$arguments['default'])
     1176                        $selected = " selected";
     1177                } else {
     1178                    if ($key==$value)
     1179                        $selected = " selected";
     1180                }
     1181                $disabled = "";
     1182                switch ($key){
     1183                    case 3:
     1184                        if(!shortcode_exists('wonderplugin_pdf'))
     1185                            $disabled = " disabled";
     1186                        break;
     1187                    case 4:
     1188                        if (!shortcode_exists('pdf-embedder'))
     1189                            $disabled = " disabled";
     1190                        break;
     1191                    case 5:
     1192                        if(!shortcode_exists('pdfviewer'))
     1193                            $disabled = " disabled";
     1194                        break;
     1195                    default:
     1196                        break;
     1197                }
     1198                echo '<option value="'.$key.'"'.$selected.''.$disabled.'>'.$desc.'</option>';
     1199            }
     1200
     1201            echo '<select>';
    10831202            break;
    10841203        case "textarea":
     
    19712090}
    19722091add_filter('template_include','oer_custom_search_template');
    1973 ?>
     2092
     2093function assign_standard_template($template) {
     2094    global $wp_query;
     2095
     2096    $url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/');
     2097
     2098    status_header(200);
     2099    //if ( $url_path === 'openk12xchange/resource/standards' ){
     2100//  if ( $url_path === 'resource/standards' ) {
     2101    if ( strpos( $url_path,'resource/standards' ) !== false && !get_query_var('standard') && !get_query_var('substandard') && !get_query_var('notation') ) {
     2102        // load the file if exists
     2103        $wp_query->is_404 = false;
     2104        $template = locate_template('oer_template/standards.php', true);
     2105        if (!$template) {
     2106            $template = dirname(__FILE__) . '/oer_template/standards.php';
     2107        }
     2108    } elseif (get_query_var('standard') && !get_query_var('substandard') && !get_query_var('notation')){
     2109        $wp_query->is_404 = false;
     2110        $template = locate_template('oer_template/template-standard.php', true);
     2111        if (!$template) {
     2112            $template = dirname(__FILE__) . '/oer_template/template-standard.php';
     2113        }
     2114    } elseif (get_query_var('standard') && get_query_var('substandard') && !get_query_var('notation')){
     2115        $wp_query->is_404 = false;
     2116        $template = locate_template('oer_template/template-substandard.php', true);
     2117        if (!$template) {
     2118            $template = dirname(__FILE__) . '/oer_template/template-substandard.php';
     2119        }
     2120    } elseif (get_query_var('standard') && get_query_var('substandard') && get_query_var('notation')){
     2121        $wp_query->is_404 = false;
     2122        $template = locate_template('oer_template/template-notation.php', true);
     2123        if (!$template) {
     2124            $template = dirname(__FILE__) . '/oer_template/template-notation.php';
     2125        }
     2126    }
     2127    return $template;
     2128}
     2129add_action( 'template_include' , 'assign_standard_template' );
     2130
     2131// Assign template
     2132function oer_template_redirect(){
     2133    global $wp, $wp_query;
     2134
     2135    $template = $wp->query_vars;
     2136
     2137    if ( array_key_exists( 'resource', $template ) && 'standards' == $template['name'] ) {
     2138        $wp_query->is_404 = false;
     2139        status_header(200);
     2140        include( dirname(__FILE__) . '/oer_template/standards.php' );
     2141        exit;
     2142    }
     2143}
     2144//add_action( 'template_redirect' , 'oer_template_redirect' );
     2145
     2146// Add rewrite rule for substandards
     2147function oer_add_rewrites()
     2148{
     2149    global $wp_rewrite;
     2150    add_rewrite_tag( '%standard%', '([^/]*)' );
     2151    add_rewrite_tag( '%substandard%' , '([^&]+)' );
     2152    add_rewrite_tag( '%notation%' , '([^&]+)' );
     2153    add_rewrite_rule( '^resource/standards/([^/]*)/?$', 'index.php?pagename=standards&standard=$matches[1]', 'top' );
     2154    add_rewrite_rule( '^resource/standards/([^/]*)/([^/]*)/?$', 'index.php?pagename=standards&standard=$matches[1]&substandard=$matches[2]', 'top' );
     2155    add_rewrite_rule( '^resource/standards/([^/]*)/([^/]*)/([^/]*)/?$', 'index.php?pagename=standards&standard=$matches[1]&substandard=$matches[2]&notation=$matches[3]', 'top' );
     2156    add_rewrite_endpoint( 'standard', EP_PERMALINK | EP_PAGES );
     2157    add_rewrite_endpoint( 'substandard', EP_PERMALINK | EP_PAGES );
     2158    add_rewrite_endpoint( 'notation', EP_PERMALINK | EP_PAGES );
     2159
     2160    $flush_rewrite = get_option('oer_rewrite_rules');
     2161    if ($flush_rewrite==false) {
     2162        $wp_rewrite->init();
     2163        $wp_rewrite->flush_rules();
     2164        update_option('oer_rewrite_rules', true);
     2165    }
     2166}
     2167add_action( 'init', 'oer_add_rewrites', 10, 0 );
     2168
     2169function oer_add_query_vars( $vars ){
     2170    $vars[] = "standard";
     2171    $vars[] = "substandard";
     2172    $vars[] = "notation";
     2173    return $vars;
     2174}
     2175add_filter( 'query_vars', 'oer_add_query_vars' );
     2176
     2177// Quick fix for the headers already sent error after submitting setup tab on the settings page
     2178add_action( 'init', function () {
     2179    if (isset($_REQUEST['tab']) && $_REQUEST['tab']=="setup") {
     2180        ob_start();
     2181    }
     2182} );
  • wp-oer/trunk/readme.txt

    r1824761 r1971883  
    11=== WP OER ===
    2 Contributors: navigationnorth, joehobson, arobotnamedchris, johnpaulbalagolan
     2Contributors: navigationnorth, joehobson, johnpaulbalagolan, tomozaidem, arobotnamedchris
    33Tags: OER, Open Educational Resources, Education, Learning
    44Requires at least: WordPress. 4.4
    5 Tested up to: WordPress 4.9.4
    6 Stable tag: 0.6.1
     5Tested up to: WordPress 4.9.8
     6Stable tag: 0.6.5
    77License: GPLv3
    88License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    4141
    4242== Changelog ==
     43
     44= 0.6.5 =
     45* options for PDF display on resource view
     46* pages to browse by Standard
     47* preliminary support for Gutenberg editor
     48
    4349
    4450= 0.6.1 =
Note: See TracChangeset for help on using the changeset viewer.