Advertisement
richardevans123

Page for Badges

Mar 29th, 2015
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. <?php
  2.  
  3. // do now load for guests
  4. if (!Zend_Auth::getInstance()->hasIdentity()) {
  5. Application_Plugin_Alerts::error(Zend_Registry::get('Zend_Translate')->translate('Please sign in first'), 'on');
  6. Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl('/');
  7. return;
  8. }
  9.  
  10.  
  11. $newbadge = $model = new Application_Model_Addons();
  12.  
  13. $sql = "
  14. SELECT badge
  15. FROM codes
  16. ";
  17.  
  18. require_once 'MainClass.php';
  19. require_once 'BadgeForm.php';
  20.  
  21. $Getpurchasedbadge = new Addon_Getpurchasedbadge_Main();
  22.  
  23. if ($Getpurchasedbadge->hasBadge($newbadge)) {
  24. ?>
  25. <h3>Get your "Convention" badge</h3>
  26. <hr/><br />
  27.  
  28. <div class="row">
  29.  
  30. <div class="col-md-6 col-md-offset-3" style="text-align: center">
  31. <h4>You already have this badge!</h4>
  32. </div>
  33.  
  34. </div> <!-- end row -->
  35.  
  36. <br /><br />
  37. <?php
  38. return;
  39. }
  40.  
  41. $form = new Addon_Form_Getpurchasedbadge();
  42. $translator = Zend_Registry::get('Zend_Translate');
  43.  
  44. // form is submitted and valid?
  45. if(isset($_POST['identifier']) && $_POST['identifier'] == 'GetPurchasedBadge')
  46. {
  47. if($form->isValid($_POST))
  48. {
  49. $license_to_check = $model = new Application_Model_Addons();
  50.  
  51. $sql = "
  52. SELECT code
  53. FROM codes
  54. ";
  55.  
  56. $license_to_check = preg_replace('/[^a-zA-Z0-9_ -]/s', '', $license_to_check);
  57.  
  58. if(!empty($license_to_check)){
  59.  
  60. //Initialize curl
  61. $url = 'http://example.com?code='.$license_to_check;
  62. $ch = curl_init();
  63. curl_setopt($ch, CURLOPT_URL, $url);
  64. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  65. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  66. curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
  67. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 4_3_2 like Mac OD X; en-us) AppleWebKit/535.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5");
  68. $ch_data = curl_exec($ch);
  69. curl_close($ch);
  70.  
  71. if(!empty($ch_data))
  72. {
  73. $json_data = json_decode($ch_data, true);
  74.  
  75. // check response
  76. if(isset($json_data['is_valid']) && $json_data['is_valid'] == true){
  77.  
  78. if ($Getpurchasedbadge->assignBadge($newbadge, $license_to_check)) {
  79. Application_Plugin_Alerts::success(Zend_Registry::get('Zend_Translate')->translate('You got yourself a badge!'), 'on');
  80. } else {
  81. Application_Plugin_Alerts::error(Zend_Registry::get('Zend_Translate')->translate('You already have this badge!'), 'on');
  82. }
  83.  
  84. // flush
  85. Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl('/');
  86. return;
  87. }
  88.  
  89. }
  90.  
  91. }
  92. }
  93.  
  94. $form->getElement('itemcode')->setValue('')->setErrors(array(Zend_Registry::get('Zend_Translate')->translate('Please check if your item purchase code is valid.')));
  95.  
  96. }
  97.  
  98.  
  99. ?>
  100.  
  101.  
  102.  
  103. <h3><img height="45" src="<?php echo Application_Plugin_Common::getFullBaseUrl().'/addons/'.basename(__DIR__).'/badge.png'?>"> Get a "Purchased" badge</h3>
  104. <hr/><br />
  105.  
  106. <div class="row">
  107.  
  108. <div class="col-md-6 col-md-offset-3">
  109. <p>If you have purchased SocialStrap script and you want people to know this fact then you've come to the right place. Fill up the form below and get yourself a badge.</p>
  110. <br />
  111.  
  112. <?php echo $form->render()?>
  113.  
  114. </div>
  115.  
  116. </div> <!-- end row -->
  117.  
  118. <br /><br />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement