Cinema
-
Show Links Menu w/Active Class <nav> <?php $args=array( 'sort_order' => 'ASC', 'sort_column' => 'post_date', 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => '', 'child_of' => 0, 'parent' => -1, 'exclude_tree' => '', 'number' => '', 'offset' => 0, 'post_type' => 'page', 'post_status' => 'publish' ); $pages = get_pages($args); $current_id = get_the_ID(); if( $pages ){ echo( "<ul>\n" ); foreach( $pages as $page){ $link_page_id = ($page->ID); if( $current_id==$link_page_id ) echo( "<li class=\"active\">" ); else echo( "<li>" ); echo( "<a href=\"".get_page_link($page->ID)."\">".$page->post_title."</a>" ); echo( "</li>\n" ); } echo( "</ul>\n\n" ); } ?> </nav> Show Categories List <?php echo( "<div id=\"topics\">\n" ); echo( "<h3>Topics</h3>\n" ); echo( "<ul>\n" ); $categories_obj = get_ca... Code Various WP snippets Template Coding Wordpress
-
<?php $host = "127.0.0.1:10389"; $ldap = ldap_connect($host); ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); $username = "uid=admin,ou=system"; $password = "secret"; if( $bind = ldap_bind($ldap, $username, $password) ) echo( "logged into ".$host." as ".$username ); else echo( "Fail" ); ?>... Code LDAP Connect and Bind Test Template Coding PHP
-
contenttypetest.info name = Contenttype test description = Test - how can I create a new content type with hook form? core = 7.x files[] = contenttypetest.module; files[] = contenttypetest.install; contenttypetest.module <?php // hook_form implementation function contenttypetest_form($node, &$form_state) { $form = array(); $form['contenttypetest_pass'] = array( '#type' => 'password', '#title' => t('Type a password'), '#description' => t('You can type anything you like.'), ); $form['contenttypetest_veld'] = array( '#type' => 'file', '#description' => 'You might wanna upload a file!', '#title' => 'Bestand', ); return $form; } // hook_node_info() implementation function contenttypetest_node_info() { return array( 'contenttypetest' => array( 'name' => t('Content type test node'), 'base' => 'contenttypetest', 'module' => 'contenttype... Code Create custom content type Template Coding Drupal
-
<?php function HOOK_menu_link( array $variables ){ $element = $variables['element']; $sub_menu = ''; $name_id = strtolower(strip_tags($element['#title'])); // remove colons and anything past colons if (strpos($name_id, ':')) $name_id = substr ($name_id, 0, strpos($name_id, ':')); //Preserve alphanumerics, everything else goes away $pattern = '/[^a-z]+/ '; $name_id = preg_replace($pattern, '', $name_id); $element['#attributes']['id'][] = 'menu-' . $element['#original_link']['mlid'] . ' '.$name_id; if( $element['#below'] ) $sub_menu = drupal_render($element['#below']); $output = l($element['#title'], $element['#href'], $element['#localized_options']); return '' . $output . $sub_menu . "\n"; } ?>... Code Add unique IDs to menu items Template Coding Drupal
-
function obtain_entities_by_type($entity_type,$bundle,$limit=10,$offset=0,$subject_nid=FALSE){ $query=new EntityFieldQuery(); $query->entityCondition('entity_type', $entity_type) ->entityCondition('bundle', $bundle) ->propertyCondition('status', 1) ->range($offset, $limit); if($subject_nid) $query->fieldCondition('field_subject','nid',$subject_nid); $results=$query->execute(); if(array_key_exists('node',$results)) return entity_load($entity_type,array_keys($results[$entity_type])); } Useage obtain_entities_by_type('node','page',10,0,432); Or <?php $sql="SELECT node.nid AS nid, node.title AS node_title, node.created AS node_created, node_data_field_weight.field_weight_value AS node_data_field_weight_field_weight_value FROM node node LEFT JOIN content_field_weight node_data_field_weight ON node.vid = node_data_field_weight.vid WHERE (node.status <> 0) ORDER BY node_data_field_weight_field_weight_value DESC"; $db_query=db_query($sql); $items=array(); while($row=db_fetch_array(... Code Obtain matching entities Template Coding Drupal
-
function HOOK_form_alter( &$form, &$form_state, $form_id ){ if( $form_id == "user_register_form" || $form_id == "user_profile_form" ) { // Shows OTHER text field when 'Other' is selected as their specialty $form["field_specialty_other"]["#states"] = array( "visible" => array( ':input[name="field_specialty[und]"]' => array("value"=>"Other"), ) ); } }... Code Show field when a different selection is made on the same form JavaScript Template Coding Drupal
-
<?php function HOOK_user_insert( &$edit, &$account, $category = NULL ){ // Don't create a new username if one is already set if( strpos($account->name, 'temporary_') !== 0) return; // Otherwise, replace username with email address field db_update("users") ->fields(array("name" => $edit["mail"])) ->condition("uid", $account->uid) ->execute(); $edit["name"] = $edit["mail"]; $account->name = $edit["mail"]; return; } function HOOK_user_register_form_alter( &$form, &$form_state, $form_id ){ $form["account"]["name"]["#value"] = "temporary_".user_password(); $form["account"]["name"]["#access"] = FALSE; }?>... Code Insert email as username at registration Template Coding Drupal
-
.box img{ filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'> <filter id=\'grayscale\'> <feColorMatrix type=\'saturate\' values=\'0.5\'/> </filter> </svg>#grayscale"); filter: gray alpha(opacity=50); -webkit-filter: grayscale(50%); -webkit-transform: translateZ(0); } .box img:hover{ filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'> <filter id=\'grayscale\'> <feColorMatrix type=\'saturate\' values=\'1\'/> </filter> </svg>#grayscale"); -webkit-filter: grayscale(0%); }... Code Image Desaturation Effect Stylesheet Coding
-
HTML <div id="photos_rotator"> <ul> <li> <a href="/node/15"> <span class="title">003</span> </a> <div class="rotator_full"><img src="003_0.jpg" alt=""/></div> </li> <li> <a href="/node/14"> <span class="title">002</span> </a> <div class="rotator_full"><img src="002_0.jpg" alt=""/></div> </li> <li> <a href="/node/13"> <span class="title">001</span> </a> <div class="rotator_full"><img src="001_0.jpg" alt=""/></div> </li> </ul> </div> JavaScript jQuery(function($){ function processSlideshow( nextElem ){ currentElem = $("#photos_rotator ul li.selected"); if( !nextElem ){ currentElemIndex = $("#photos_rotator ul li").index(currentElem); nextElem = $('#photos_rotator ul li').get(currentElemIndex+1); if( !nextElem ) nextElem = $("#photos_rotator ul li").get(0); } //... Code Slideshow JavaScript Stylesheet Coding JQuery
-
HTML <img src="http://orgnsm.org/camoff.jpg" alt="Webcam" id="webcamImage"/></div> JavaScript function refreshCam(id, file) { var today = new Date(); var h = today.getHours(); var m = today.getMinutes(); var s = today.getSeconds(); document.getElementById(id).src = file + "?time="+h+m+s; setTimeout('refreshCam("webcamImage","'+file+'")',10000); } window.onload = function(){ if( document.getElementById("webcamImage") ) refreshCam( "webcamImage","http://orgnsm.org/webcam.jpg" ); }... Code Webcam Image Refresher JavaScript
-
w/JavaScript //the callback function run after loading JSONp below function test_results_loaded(data){ //post data to a service via ajax var xhr = new XMLHttpRequest(); xhr.open("POST", "https://orgnsm@orgnsm.org:lkAGWUE01H@orgnsm.testrail.com//index.php?/api/v2/add_result/1", true); xhr.setRequestHeader('Content-Type', 'application/json;'); xhr.setRequestHeader('Accept', 'application/json;'); // send the collected data as JSON xhr.send(JSON.stringify({"status_id":"1"})); xhr.onloadend = function () { alert("Wrote test data"); }; } window.onload = function(){ //add event to a button that loads remote JSONp document.getElementById('loaderButton').onclick = function(){ var script = document.createElement('script'); script.src = 'http://shellfiche.anoml.net/test.php5?callback=test_results_loaded'; document.getElementsByTagName('head')[0].appendChild(script); } } w/JQuery $(document).ready(function(){ $("#loaderButton").click(function(){ $.ajax({ url: 'http://shellfiche.anoml.net/test.php5', dataType: "jsonp", jsonpCall... Code AJAX Remote Read, Local Write JavaScript JQuery
-
w/JavaScript window.onload = function(){ //create new button var btn = document.createElement("a"); btn.setAttribute("id", "addedbutton"); var btntxt = document.createTextNode("Run Me"); btn.appendChild(btntxt); //inject new button document.getElementById("sidebar").appendChild(btn); //add event to new button document.getElementById('addedbutton').onclick = function(){ alert("Success"); } } w/JQuery $(document).ready(function(){ var test = $("<a href='#'>Run Me</a>").click(function(){ alert("Success"); return false; }); $("body").append(test); });... Code DOM Inject and Add Event JavaScript JQuery
-
<?php $items = array( 0 => array( "item 1", "2013-09-13", "1" ), 1 => array( "item 2", "2013-09-14", "2" ), 2 => array( "item 3", "2013-09-15", "3" ), ); ######## CALCULATIONS ######### # set per-page var if (isset($_GET["perpage"])) $perpage = $_GET["perpage"]; else $perpage = 10; # calc numb of pages $pages = ceil(count($items) / $perpage); # which page are we on? if( isset($_GET["page"]) && round($_GET["page"]) <= $pages && round($_GET["page"]) > 0 ) $page = round($_GET["page"]); else $page = 1; # calc start and end item $startItem = (($page - 1) * $perpage); $endItem = $startItem + ($perpage - 1); if( $endItem > $items ) $endItem = $endItem - ($endItem % $items); ######## PRINT ITEMS ######### echo( "<div>\n" ); echo( " <ul>\n"); for( $i=$startItem; $i<=$endItem; $i++ ){ echo( " <li>\n"); echo( " <a href=\"/node/".$items[$i][2]."\">\n"); echo( " <span class=\"title\">" . $items[$i][0] . "</span>\n" ); echo( " </a>\n" ); echo( " </li>\n" ); } echo( " </ul&... Code Pagination Logic Template Coding PHP View this Site
-
HTML <meta name="viewport" content="width=device-width, initial-scale=1.0;"/> CSS @media (max-width: 480px){ } @media (max-width: 767px){ #container{ padding: 0 25px; } nav ul li a{ font-size: 100%; padding: 15px 0; border-radius: 30px; } nav ul li a svg{ width: 60px; height: 60px; } } @media (min-width: 768px) and (max-width: 979px){ #container{ padding: 0 35px; } nav ul li a{ font-size: 120%; padding: 20px 0; border-radius: 40px; } nav ul li a svg{ width: 80px; height: 80px; } } @media (max-width: 979px){ } @media (min-width: 980px){ /* default rules */ } @media (min-width: 1200px){ #container{ padding: 0 75px; } nav ul li a{ font-size: 170%; padding: 30px 0; border-radius: 60px; } nav ul li a svg{ width: 133px; height: 133px; } }... Code Device-Responsive Layout Stylesheet Coding View this Site
-
The JavaScript jQuery(function($){ $("#contact").submit(function(){ //grab form values before blowing it out of the DOM in the next line values=$(this).serialize(); $("#contact").html( "<p>Sending message...</p>\n" ); //send the values to the PHP handler $.ajax({ type: "POST", url: $("#contact").attr('action'), data: values, success: function(re){ $("#contact").html(re); } }); return false; }); }); PHP <?php if( $_SERVER["REQUEST_METHOD"] == "POST" ){ $to = "orgnsm@orgnsm.org"; $subject = "Contact through website"; $message = "Message: ".$_POST["message"]."\r\rFrom: ".$_POST["nombre"]."\r\rEmail: ".$_POST["email"]; $from = $_POST["email"]; $headers = "From:" . $from; mail($to,$subject,$message,$headers); echo( "<p>Your message has been sent. Thank you</p>\n" ); } ?> HTML <form action="/sites/all/themes/visionarysports/contact.php" method="POST" id="contact"> <div>&... Code Dynamic Form Submission JavaScript PHP JQuery View this Site
-
<?php function getRSS( $url ){ $cobj = curl_init( $url ); curl_setopt( $cobj, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $cobj, CURLOPT_CONNECTTIMEOUT, 0 );//0 = no timeout $tumblr_raw = curl_exec( $cobj ); curl_close( $cobj ); if( $tumblr_raw ){ $tumblr_xml = new DOMDocument(); $tumblr_xml->loadXML( $tumblr_raw ); //echo( "<pre>".$tumblr_xml->saveHTML()."</pre>" ); if( $tumblr_xml->getElementsByTagName("item") instanceof DOMNodeList && $tumblr_xml->getElementsByTagName("item")->item(0) instanceof DOMElement && $tumblr_xml->getElementsByTagName("item")->item(0)->hasChildNodes() ){ foreach( $tumblr_xml->getElementsByTagName("item") as $tweet ){ foreach( $tweet->childNodes as $deetz ){ if( $deetz->nodeType == 1 && $deetz->nodeName == "title" ) $tweet_title = $deetz->textContent; elseif( $deetz->nodeType == 1 && $deetz->nodeName == "pubDate" ) $tweet_date = $deetz->textContent; elseif( $deetz->nodeType == 1 && $deetz->nodeName == "guid" ) $tweet_url = $dee... Code Read and Process RSS Template Coding
-
Style Links HTML <link rel="alternate stylesheet" type="text/css" href="/theme/KATALOG/style.css" title="KATALOG"/> <link rel="alternate stylesheet" type="text/css" href="/theme/SCREEN/style.css" title="SCREEN"/> <link rel="alternate stylesheet" type="text/css" href="/theme/spaecial/style.css" title="spaecial"/> <link rel="alternate stylesheet" type="text/css" href="/theme/touchpanel/style.css" title="touchpanel"/> <link rel="stylesheet" type="text/css" href="/theme/blawk/style.css" title="blawk"/> Style Switch Links HTML <div id="style_chooser"> <a href="#" onclick="setActiveStyleSheet('KATALOG');this.blur();return false;">KATALOG</a> <a href="#" onclick="setActiveStyleSheet('SCREEN');this.blur();return false;">SCREEN</a> <a href="#" onclick="setActiveStyleSheet('touchpanel');this.blur();return false;">(touchpanel)</a> <a href="#" onclick="setActiveStyleSheet('spaecial');this.blur();return false;">spæcial</a>... Code Stylesheet Switcher JavaScript