Skip to content

Instantly share code, notes, and snippets.

View LordZombi's full-sized avatar

Zombi LordZombi

View GitHub Profile
@LordZombi
LordZombi / wordpress
Created July 15, 2013 14:03
Wordpress get all post's editors.
function getPostAuthors() {
global $wpdb;
$authors = array();
$results = $wpdb->get_results( $wpdb->prepare("SELECT post_author FROM $wpdb->posts WHERE (post_type = '%s' AND ID = %d) OR (post_type = 'revision' AND post_parent = %d) GROUP BY post_author", get_post_type( get_the_ID() ), get_the_ID(), get_the_ID() ) );
foreach ($results as $row) {
if (isset($coma)) {
echo $coma;
} else {
$coma = ', ';
}
@LordZombi
LordZombi / Zend
Created July 15, 2013 14:14
If you want to select from one table but also join with another.
$select= $this->_getTable()->select()->setIntegrityCheck(false)
->from(array('BLG' => 'articles'), array('month' => new Zend_Db_Expr($m), 'count' => new Zend_Db_Expr('COUNT(BLG.id_articles)')))
->joinLeft(
array('LNG' => 'languages'),
'LNG.id_languages = BLG.id_languages',
array('lang' => 'code')
)
->where('LNG.code = ?', $lang)
;
@LordZombi
LordZombi / links
Created July 16, 2013 14:25
Links
@LordZombi
LordZombi / threedots
Created July 16, 2013 15:00
ThreeDots
JQUERY: //ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js
GITHUB: https://github.com/theproductguy/ThreeDots
<div class='text_here' style="width: 200px;">
<span class='ellipsis_text'>
TEXT
</span>
</div>
@LordZombi
LordZombi / numbers
Created July 24, 2013 08:18
Rounding numbers
NUMBER FORMAT:
return number_format((float)$number, 2, '.', '');
SPRINTF:
$padded = sprintf('%0.2f', $unpadded); // 520 -> 520.00
ROUND:
<?php
echo round(3.4); // 3
echo round(3.5); // 4
@LordZombi
LordZombi / paypal
Created July 24, 2013 14:08
PayPal IPN setup
<?php
// STEP 1: read POST data
// Reading POSTed data directly from $_POST causes serialization issues with array data in the POST.
// Instead, read raw POST data from the input stream.
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
@LordZombi
LordZombi / language
Created August 8, 2013 09:56
Set locale language
$translator = $this->view->getHelper('translate')->getTranslator();
$translator->setLocale($order->getLanguage()->code);
@LordZombi
LordZombi / redirects
Last active December 20, 2015 20:49
Routes, Forward, Redirect
$this->_helper->redirector->gotoRouteAndExit(array(), 'backend-module-controller');
$params = array();
$this->forward('denied', 'error', 'default', $params);
return;
@LordZombi
LordZombi / disable.php
Last active December 23, 2015 21:29
Disable Layout, Never Render
// in controller action
$this->_helper->viewRenderer->setNeverRender();
$this->_helper->layout()->disableLayout();
@LordZombi
LordZombi / curl
Created October 18, 2013 13:01
Curl
$server = $this->getRequest()->getServer();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 90); // times out after 90s
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params));