Category Archives: My TECHings

14 Mar
2013

Sneaking a Javascript Web App Into A Drupal Module

drupal_js

When most people think of Drupal modules, the first words that generally come into mind are ‘hooks’, ‘form API’, ‘back end’ etc.. But what if you want to make a more front end oriented Drupal plugin? Drupal’s at least four steps ahead of you!

1. Drupal.behaviors

An excellent way to attach your javascript code to a Drupal module is to use Drupal.behaviors for two reasons. First, using jQuery’s $(function () trick to get your app to load is a very detached way of linking your code in. You have no way to control how your application interacts with Drupal events.

That bring’s me to reason #2 — attaching your app to Drupal.behaviors will allow Drupal to trigger a refresh of your app when Drupal core loads additional information using Ajax. This is incredibly useful for dealing with modules like Views that use Ajax pagers, or quick tabs.

Here’s a code snippet to get you started!

And there you go!

You may be wondering at this point how to connect this code to your module… Of course, Drupal doesn’t automatically detect new javascript files in your modules folder, and you need to set up your module in the first place. A guide on setting up a module is out of the scope of this tutorial, but I’ll give you the basic structure.

You need to create a new folder with the module name in the sites/all/modules directory path of your drupal installation. Once you have that folder make two files there — [module-name].info and [module-name].module. We’re mostly concerned with the .info file for now.

There you need to define the module name, its description, Drupal core and version. Here’s an example for you.

Oaky… but there’s still no reference to our awesome javascript file yet! Yeah, good point. Just add the following below the version number

You can add as many scripts here as you like. Sadly, as you might have noticed at this point, adding scripts this way will weigh down our site immensely with HTTP requests and loading all the code on pages that don’t use it would not be a good idea.

That’s why I propose an alternative. Include it in the module file instead! Let’s say you have a menu callback that loads up your module’s main page (you’ll see more about menus down below). “How do I do that?” you ask. Just a simple drupal_add_js will do the trick, but remember to include the path to the module:

2. Drupal.settings

Of course you can’t easily create a truely Drupal based module without getting help from Drupal settings or data from the database. Sure you can use Ajax to load in data, but what if you need some basic settings from Drupal, like administrative options set in a Drupal configuration menu? To add these settings, we’re gonna need to transition to the ‘.module’ file. We can add settings from a hook using the following pattern:

Need more context? Try this example out:

3. Menus

Yeah, maybe Menus aren’t really a javascript thing, but they are much cleaner for loading data via XML HTTP Requests than using standard, unclean GET data. The main reason to do this is so you can avoid using standalone PHP scripts that just float in your modules folder. If you haven’t worked with hook_menu yet, my advise is to think of it partially as a router. You set a path, arguments and then pass that data to a callback function that loads up data or a formatted drupal page or form. In our case, we just need our page to display raw JSON. Here’s another quick sample to give you the gist of what needs to happen:

4. #AHAH/#AJAX

Guess what? Drupal’s Form API has built in javascript tricks! You don’t need to create another js file just to call an ajaxy form submission. This is one of the trickiest things to do in Drupal, so — yeah, just be prepared for your first couple tries to fail. Here’s the basic syntax:

Of course there are tons of other options, which you should explore in Drupal’s documentation here: http://api.drupal.org/api/drupal/includes%21ajax.inc/group/ajax/7.

09 Feb
2013

Views and Paneled Pain

drupal-view-archive-sm

The relationship between Views, Panels, Mini Panels and Paneled Pages in Drupal is both robust and rife with potential pitfalls.

One of my first mistakes when dealing with views and panels was to get too caught up in “contexts.” Here was my first idea of how they should be used together:

 

  • Each section on a page should be its own node — that will make content easily targetable by content managers.
  • Since each page should have one focus, these nodes can be listed in a view and filtered by a taxonomy term created for that page.
  • To add additional content, such as sliders, feeds, etc. each page should be built using page manager as a panel containing the view for the current page.
  • The panel would pass on the taxonomy term of the page name to the view.

Unfortunately, it really doesn’t take long for this workflow to become extremely unmaintainable.

First, this requires the extra step of creating a taxonomy term for every new page you create — incredibly annoying and a huge barrier for any clients who will be taking over the site after you finish developing it.

Another redundant step in this process is having to add an “Edit” link to the view on each page. Not a huge deal, but if you forget to add it to a view, suddenly editing becomes a mess for the content manager(s).

panels-ipe-current

Finally, panels really don’t handle custom content well. To me, an ideal implementation of panels would allow users to edit content within the panel as they would edit a content node or view (we need a designated “edit” button outside of the little gear icon, but let’s forget that for now).

My point is, currently (in Drupal 7), there are too many different processes in place to edit different types of content. I’ll keep my fingers crossed for module developers to come up with some editing workflow standard in Drupal 8 or 9.

08 Feb
2013

Why Backbone is Sexier than jQuery

Screen Shot 2013-02-04 at 7.53.10 AM

jQuery is salt and sugar,

jQuery is a pullup bar,

jQuery is a menace and hero,

 

The library is essential to every web developers tool kit, but the framework scares the hell out of me — not because I don’t understand how to use it or fear its delicious transitions, but for the simple reason that it’s simplicity begs misuse. Here’s how I learned the hard way that Backbone.js, Ember.js and other full javascript frameworks are so much sexier than jQuery.

Call me superficial, but I place a great deal of importance on aesthetics when choosing a framework to work with. I don’t mean that I look for the awesome swishes and swoops, widgets and gadgets that the jQuery website teases us with. I mean that taunting, flirtatious design of the ember.js site (see right).

I won’t speak for everyone, but damn! I wanted to learn ember before I even scrolled down to see the code. I wasn’t let down.

Routers! Views! Models! Collections! Finally, programming made sense again. Okay, Model-View-Controller style coding is super hot right now and you can find it nearly anywhere from iOS objective-c development to similarly awesome PHP libraries like Cake. But the aspect of ember and backbone that I immediately fell in love with was the concept of using HTML5′s pushState together with beautifully organized front end data structures and views these frameworks seamlessly provide.

Imagine you’re hosting a website from an at home server or from a cheap host that’s super slow. Now, what if you could offload most of the processing to each user’s browser? Yeah! In backbone and ember, suddenly http requests aren’t necessarily needed to direct a user to another page with different content. As I mentioned earlier, the Backbone Router’s navigate method can use HTML5′s pushState feature to move a string up to the site’s url as if the user was navigating to a different page. The down side of this of course is that if you don’t have a backend that will direct the user to the correct page with the correct parameters when they revisit or refresh the page, the user will get a 404 error. You can avoid this issue by setting pushState to false in Backbone.history, but that’s the topic of another post.

Yeah jQuery will give you instant results to impress your clients and wow your friends, but if you plan on building a real, scalable, feature rich and deliciously visual web app, why not make things easier on yourself and feel like a badass learning Backbone or Ember? Google even has their own called angular (someday I’ll learn it… I swear!).

Continue reading

24 Mar
2012

Synergizing Salvation: Twitter Behavior and its Effect on Advertising

Anti-Government Protesters Clash With Pro-Mubarak Demonstrators

The mass of scattered voices eventually found their home together. The use of social media in the Egyptian Revolution signified a new kind of organization of socio-political ideas that were so far reaching that the cyber messages eventually gathered around the syntactical structures of a cohesive social networking revolution. The continuous power of the Occupy Wall Street movement indicates that the phenomenon of this sort of organization is not exclusive to the Middle East– a tool that began as a means to promote products and communicate with friends suddenly became an opportunity for creating a coherent message with a vast outreach. However, Twitter is not a non-profit, and as any other business, the company has found its niche market in advertisers and so called “influentials,” who help spread hype for various products.

My interest in this article is not in the usefulness of social networking platforms as tools for political dissidence. Instead, I will focus on the relationship of social and political discourse on Twitter to product marketing tactics that form around the organizational tools of of micro-blogging software. Tools such as hash tags and “mentions” on sites like Twitter together form a feature called trending topics, which seeks to direct users’ attention to the most discussed and relevant tweets at any given moment. Additionally, studies on the influence of top Twitter users demonstrates the utility of celebrities and political figures as carriers for advertising messages.[1] I argue that the structural apparatus of the Twitter platform (ie. hashtags, retweets, and mentions) inherently demand a coordination and uniformity in its use that exists almost exclusively in the marketing strategies of synergized conglomerates, and ultimately can only exist to promote a true democratic forum under a user base that has the organization and persistence of a large internet marketing campaign.

I will look first at the evolution of Twitter, from its early stages as a service made up of a seemingly arbitrary set of tools for linking and distributing posts, to the platforms takeover by advertisers, and finally to its more recent state as a utility for organizing movements for political reform. Next, I will examine the advertising models that developed, as well as the uses of features such as ‘hashtags,’ ‘mentions,’ and ‘retweets.’ To analyze the usefulness of these features in recent social movements such as the Arab Spring, I will examine the obstacles that protest organizers found in surpassing the proliferation of endorsed content on the site. My paper will conclude with an analysis of the most successful tactics of mass communication on Twiter, and the ways in which a new paradigm has emerged that allows for both users and advertisers to utilize the twitter marketing model.

In a sense, the idea for Twitter itself emerged from a kind of disintegration. Members on the board of a failing company called Odeo INC., based in San Francisco, Calfornia were faced with the task of reinventing their product, and one of the proposals revolved around a sort of social dispatch service over text messages. But possibly the most attractive aspect of the concept was its exclusion of large companies (with the exception of Google and a few others).[2] Also important to the course of Twitter’s evolution was its initial beta stage as a exclusively SMS based service.[3]

The two elements noted above are relevant to this paper for three reasons. First, the apparent focus on individual users rather than organized bodies through the infrastructure of an existing prolific and mobile network meant that the platform’s investment in advertisers was not considered in the development of the tool. Second, the service was initially intended to be entirely mobile and didn’t require a smart phone or other form of Internet device. Finally, as cell phones at the time commonly did not have QWERTY keyboards, one of the important structural features of the service was the 140-character limit put on messages. This put a strict limit on the complexity of ideas that could be shared, but as another twitter founder, Jack Dorsey, pointed out, “One could change the world with one hundred and forty characters.”[4] As I will discuss later, mobile tweeting played an enormous role in the organization of the various uprisings in the Arab Spring as Internet services rapidly became unavailable, and the three characteristics that I have outlined above paint a archetypical picture of both the audience and content of the tweets seen in contemporary socio-political dissent movements.

And in fact, the early stage of Twitter’s testing paralleled the platforms used in the Arab Spring. Dom Sagolla, one of twitters founders, identifies the software as the glue that held he and his colleagues together as the company that they worked for collapsed around them.[5] But as per usual in the evolution of the Internet from Web 1.0 to Web 2.0, structure and hyperlinking quickly became the force behind the Twitter evolution from a social networking project to a marketing instrument. In 2007, a new element of twitter emerged that formed the basis of creating a systematic organization of tweets based on their relevance to events, trending topics, or ideas. These were called ‘hashtags’, and were first used in the 2007 San Diego wildfires with the intention of making information about the disaster more accessible.[6]

However, this solution to aggregating related topics quickly became an answer to finding a cheap online advertising strategy for building product hype. Although hashtags are user created, and a variety of redundant hashtags often divide up tweets on any given topic, television broadcasters attempt to maintain uniformity in these categorizing tags’ use by creating ‘official’ hashtags, allowing buzz around shows to be easily accessible and to emphasize its popularity.[7] A variety of similar tools have formed over the years ranging from ‘mentions’, which allow users to publically or privately address or flag a friend, public figure, or company, and ‘retweets’, which allow users and organizations to spread information through ‘influentials’, or users with a vast array of followers. While these structural tools helped organize the mass of tweets rapidly growing on Twitter, they also dramatically changed the user base as well as the intentions of micro bloggers. But as I will argue in the remainder of this paper, Twitter’s aggregation apparatus isn’t only fitted to business promotion. Rather, it revolutionizes the concept of advertising, and allowed the political uprisings of 2011 to organize and generate hype for their cause using these new internet marketing strategies.

A great deal of research has been conducted on the habits of Twitter users, indicating avenues through which advertisers could endorse products in effective and far reaching ways. According to a study on the scope of user influence on Twitter, the most effective methods of spreading content revolve around a type of user known as an ‘influential.’ This group consists of celebrities, news organizations, and politicians—essentially users who maintain a high level of reverence from a large number of fan followers.[8] The study found that on average, users who tweeted about all of the three top trending topics of 2009 (the death of Michael Jackson, the outbreak of swine flu, and the Iranian presidential election) had on average 2,037 followers, reaching an audience of 16 million users.[9] This demonstrates the exponential value of a tweet from an influential user. The vast influence of celebrities and other influentials on Twitter suggests a new focus for advertisers. Rather than targeting users directly through company feeds, an advertising campaign can instead focus on using an influential as a surrogate for relaying the message to fans. This can be accomplished by one of two methods: seeking a  ‘retweet’, or a ‘mention’ from a top user. This follows what Henry Jenkins describes as a totemistic approach to appealing to consumers, which appeals to consumers desire for membership to what appears to be an exclusive brand.[10] By relaying an advertisement through an influential, a company not only reaches an enormous audience at little to no cost, but they create an image for their product consistent with the appeal of the influential.

While this discovery of the overwhelming power of celebrity and advertising agencies does not discount Twitter as a democratic platform in its self, it leads us to question the legitimacy of so called “trending topics,” which are intended to highlight the most discussed topics at any given moment. This feature is dangerous to the average twitter user for two reasons: as mentioned earlier, it privileges ‘official’ hashtags endorsed by large synergized conglomerates by ignoring any redundancies in hashtag creation and it privileges the corrupt advertising methods of what are called ‘spammers.’

In accordance with the study on celebrity influence on Twitter, spamming has emerged as a method of reaching the vast audience without forming an alliance with an influential. Through “brute force” attacks, hackers can ‘phish,’ or gain unauthorized access to a valuable twitter account and promote a product under the username of an influential. However, more dominant in forming the ethos of ‘trending topics’ is the proliferation of an advertisement through a variety of pseudonyms. A 2010 study found that 70% of scammers used identical hashtags in 52,000 tweets to make the spam to trending topic.[11] Possibly more frightening than Twitter’s inability to avoid these attacks, is the success the spam has. In fact, 0.13% of spam links on twitter are clicked, which signifies almost twice the success rate of email spam links.[12] If Twitter is to be propped up as a Democratic platform and to accurately represent the most discussed issues of the time, these issues must either be solved, or users must find a way to achieve the level of coordination and continuity present in these fishing scams and promoted content campaigns.

Through both ‘official’ hashtag creation and spamming, hegemony is enforced through the organization and coherent narrative of large conglomerates with the resources to proliferate their message throughout the twitter universe. In other words, by default, Twitter’s “trending topics” will almost always be congruent with capitalist ideals. But in the past year a trend has emerged that provides an answer to the media and capitalist dominance over the platform. The successes of the Arab spring, along with the Occupy Wall Street demonstrate a hope for battling the overwhelming presence of product placement as the default focus of Twitter’s user dialog. Some theorists argue that, “blogs and microblogs rise to prominence as news disseminators on occasions when access to mainstream news and/or other communication media is restricted or blocked.”[13] This was true in the Egyptian revolution. Neither the mainstream media nor big businesses could take credit for, or suppress the dominance of tweets from individuals inside the Egypt simply because social networking was essentially the lone source of information on the subject. In a sense, the advertising campaign models suddenly became relevant to forming continuity in the messages and news of the Egyptian revolution. International news agencies became the influentials through which tweets from within Egypt could be spread to a larger audience abroad.[14] In their article on the successes of Twitter in the Egyptian revolution, Zizi Papacharissi and Maria de Fatima Oliveira observe, “whereas feeds of news organizations and journalists are modeled after the news values and practices of the parent organizations, organically developed hashtag feeds deviate from the organizational logic of prominent news values to provide coherence by blending fact with opinion and objectivity with subjectivity.”[15] This highlights the element of the Arab spring that transcended the lack of organization plaguing other unrepresented discourse on Twitter. Through an nationwide social network based movement, all elements of discourse, from religious or class bias to reporting of atrocities, were combined under the single hashtag, #egypt,[16] and available to the world as a unified trending topic independent of the support of any corporate or government entity. The international demand for exclusive information on the events in Cairo matched the capitalist paradigm for creating brand loyalty and toetemism for celebrity endorsed products. The organization of events and planning of both the Occupy movement and the Arab spring required unification of ideas under one hashtag in order to occur at all.[17]

I would like to advance this idea of organization out of necessity by relating the methods of communication in these movements to concept of synergy in horizontally integrated conglomerates. Because large media organizations can increase revenue and visibility by incorporating smaller enterprises, promoting a variety of products across a broad spectrum of media becomes a basic element of maintaining unity. General Electric, News Corp, and Disney among other corporations commonly cross promote their products using their subsidiaries as platforms. The socio-political movements of 2011 took on a similar form of achieving unity through a kind of cross promotion. A prime example for this is in the organization of the Occupy Oakland protests. While a variety of media outlets spanning a wide spectrum of opinions existed as individual entities, a group of protestors set up a website that merged a variety of sources into one space.[18] This is significant in that it combined all thoughts and news related to the movement into one location, allowing users of the site to connect related hashtags and maximize the dialog emerging from initially fractured and disorganized elements.

In the past few years, twitter has facilitated a revolution of both Internet marketing and of political reform. While many features are so commonly misused that the platform risks losing its user base, I have argued in this paper that the unification of the socio-political revolutions that begin last year have given a new power to the average twitter user and ultimately offered hope for the legitimacy of ‘trending topics.’ I believe that if users acknowledge the necessity of organizing ideas through ‘official’ hashtags, Twitter will remain a relatively democratic platform for the years to come.

Works Cited

Cha, Meeyoung, Hamed Haddadi, Fabricio Benevenuto, and Krishna P. Gummadi. “Measuring User Influence in Twitter: The Million Follower Fallacy.” Proceedings of the Fourth International AAAI Conference on Weblogs and Social Media (2010): 10-17.

Cheng, Alex, Mark Evans, and Harshdeep Singh. “Inside Twitter: An In-Depth Look Inside the Twitter World.” Social Media Monitoring Tools for Business by Sysomos. Version Sysomos Inc.. Web. 15 Mar. 2012. <http://www.sysomos.com/insidetwitter/>.

Deller, Ruth. “Twittering on: Audience research and Participation Using Twitter.” Participations: Journal of Audience and Reception Studies  8.1 (2011): 216-245.

Grier, Chris, Kurt Thomas, Vern Paxson, and Michael Zhang. “@spam: The Underground on 140 Characters or Less.” 17th ACM Conference on Computer and Communications Security (2010): 27-37.

Jenkins, Henry. “Buying into American Idol.” Convergence Culture. New York: NYU Press, 2006. 217-229.

Sagolla, Dom. “How Twitter Was Born.” 140 Characters. N.p., 30 Jan. 2009. Web. 14 Mar. 2012. <www.140characters.com/2009/01/30/how-twitter-was-born/>.

Skinner, Julia. “Social Media and Revolution: The Arab Spring and the Occupy Movement as Seen through Three Information Studies Paradigms.” Sprouts: Working Papers on Information Systems 11.169 (2011): 1-26.

Starbird, Kate, and Jeannie Stamberger. “Tweak the Tweet: Leveraging Microblogging Proliferation with a Prescriptive Syntax to Support Citizen Reporting.” Proceedings of the 7th International ISCRAM Conference (2010): 1-5.

Papacharissi, Zizi, and Maria de Fatima Oliveira. “The Rhythms of News Storytelling on Twitter.” World Association for Public Opinion Research Conference, Amsterdam (2011): 1-30. University of Illinois, Chicago. Web. 14 Mar. 2012.


[1] Meeyoung Cha, Hamed Haddadi, Fabricio Benevenuto, and Krishna P. Gummadi. “Measuring User Influence in Twitter: The Million Follower Fallacy.” Proceedings of the Fourth International AAAI Conference on Weblogs and Social Media (2010): 10.

[2] Dom Sagolla, “”How Twitter Was Born.” 140 Characters., 30 Jan. 2009. <www.140characters.com/2009/01/30/how-twitter-was-born/>.

[3] Sagolla

[4] Sagolla

[5] Sagolla

[6] Kate Starbird and Jeannie Stamberger. “Tweak the Tweet: Leveraging Microblogging Proliferation with a Prescriptive Syntax to Support Citizen Reporting.” Proceedings of the 7th International ISCRAM Conference (2010): 2.

[7] Ruth Deller. “Twittering on: Audience Research and Participation Using Twitter.” Participations: Journal of Audience and Reception Studies  8.1 (2011): 226.

[8] Meeyoung Cha 13.

[9] Meeyoung Cha

[10] Henry Jenkins. “Buying into American Idol.” Convergence Culture. New York: NYU Press, 2006. 224.

 

[11] Chris Grier, Kurt Thomas, Vern Paxson, and Michael Zhang. “@spam: The Underground on 140 Characters or Less.” 17th ACM Conference on Computer and Communications Security (2010): 30.

[12] Chris Grier 27.

[13] Zizi Papacharissi, and Maria de Fatima Oliveira. “The Rhythms of News Storytelling on Twitter.” World Association for Public Opinion Research Conference, Amsterdam (2011): 2.

[14] Zizi Papacharissi 4.

[15] Zizi Papacharissi 5.

[16] Zizi Papacharissi 3.

[17] Julia Skinner. “Social Media and Revolution: The Arab Spring and the Occupy Movement as Seen through Three Information Studies Paradigms.” Sprouts: Working Papers on Information Systems 11.169 (2011): 5.

[18] Julia Skinner 6.

24 Jan
2012

Dotcom: Megacriminal, or a Waste of Time?

Why Me?

Kim Dotcom—cool name right? But Mr. Dotcom, founder of leading file hosting website Megaupload, is now facing some serious heat from the US feds after his arrest last Thursday. Well, I should be clearer; the American government doesn’t directly have beef with the web tycoon. In fact, Dotcom would probably still be sitting comfortably in his Coatesville New Zealand mansion if it weren’t with those meddling kids… err… American media superpowers behind the recently destroyed SOPA legislation.

But this guy wasn’t an international criminal guilty of pirating 500 million dollars of US owned media. In fact, as of recently he only owned a relatively small portion of his company’s shares and made few of the large decisions. It’s true that the business did engage in some shady dealings, but I can’t say Dotcom was an obvious candidate for the position of most wanted international media pirate. Actually, in my experience with pirated media (yes, I’ve run into such a thing on the mighty interwebs – shocker!), most copyrighted content online comes from film or computer geeks sitting at home, spreading their bootlegged copies through bittorrent under alieses like aXXo or SiNiStEr.

To be honest, I have no idea where this notion of media piracy as an international concern came from. Sure, if you hit the streets of any developing country you are sure to find a gazillion bootlegged DVDs of the latest Hollywood hits sprawled out on the ground, but who says American “pirates” are more moral than international “e-thieves?” Megaupload definitely turned a blind eye to illegally uploaded content on its servers, but I read in a recent article in the New York Times that I have a six hour window to watch copyright infringing movies on YouTube before the video is pulled. And YouTube isn’t the only offender. In fact, check out mediafire.com or Justin.tv and tell me that at any given instance you can’t find a wonderland of unauthorized copies of TV shows, music, and even movies.

So why is it that the media industry sees Megaupload as more of a threat than the aforementioned US based sites? Of course YouTube is owned Google – Google owns the world now right? – but it seems to me that SOPA and the Protect IP Act were centered around the idea that the American creativity was threatened by international terrorists. And in an age where one of the top discussions in the GOP debates is over illegal immigrants stealing American jobs, how is an advertisement that poses the threat of media piracy as an international issue not supposed to tug at the heart strings of proud Americans without jobs?

My only guess to why this Australian web tycoon suddenly became the first target of what is sure to become an ongoing US policy of attacking foreign web hosting services is that SOPA and PIPA have failed. The American entertainment industry has never had a lack of options in attacking those who’ve illegally made their content available to everyone. Most of us probably remember Napster. Most of us probably remember hearing stories of college students expelled from school for engaging in file sharing.

Ultimately, the answer to all this Internet mayhem isn’t to attack web-hosting sites. Media organizations should follow the routes of NBC, Disney and Fox in their joint venture, Hulu, which allows free access to top television shows through revenue gained from online advertisements. Digital media isn’t safe. Period. Top media production companies need to embrace free content. As the saying goes: if you can’t beet em, join em.