Jump to content

Harmster

Members
  • Posts

    137
  • Joined

  • Last visited

Everything posted by Harmster

  1. Hey, I've searched for this and I couldn't find it, what i want to do is check if a page (object) already is in a PageArray field? Ofcourse i can go through it with a loop but if theres already a method to do this then i dont want to re invent the wheel.
  2. You can try to use JQuery? Though its not really a pw answer removeAttr
  3. Sorry Soma, one more question it seems now i removed autoload= 'true' i can't use my methods in the templates anymore, how do i accomplish to get that back w/o using autoload?
  4. Thank you soma, i finnaly got the tab as they should be, although it doesn't matter which menu tab is active, this is a js thing right? EDIT: I get it now Awesome, i might write a tutorial about this agian since now i got it and for later reference for myselfs and maybe others it might be helpfull. Thanks!
  5. Okay, its quite a mess right now but here we go... <?php include('MCAPI.class.php'); class Mailchimp extends Process implements Module, ConfigurableModule { static $apiKey = ""; static $list_id = ""; static $optin = 0; const PAGE_NAME = 'mailchimp'; const PERMISSION_NAME = 'mc-view'; public static function getModuleInfo() { return array( 'title' => 'Mailchimp', 'version' => 001, 'summary' => 'Module that connects to the Mailchimp API (ALPHA)', 'href' => 'https://www.yourhosting.nl/website-maken/', 'singular' => true, 'autoload' => true, ); } public function init() { $this->fuel->set("mailchimp", $this); $this->apiKey = $this->get("apiKey"); $this->list_id = $this->get("list_id"); $this->optin = $this->get("opt-in"); parent::init(); if(!$this->isPost) $this->modules->get('JqueryWireTabs'); } public function get_apikey() { return $this->apiKey; } public function get_listid() { return $this->list_id; } public function get_optin() { return $this->optin; } public function get_optin_value($optin) { if($optin == "1") { return "true"; } else { return "false"; } } private function list_members($apikey) { $api = new MCAPI($this->apiKey); $retval = $api->listMembers($this->list_id, 'subscribed', null, 0, 5000 ); if ($api->errorCode){ return array('errorcode' => $api->errorCode, 'errormessage' => $api->errorMessage, 'apikey' => $this->apiKey); } else { return $retval; } } public function get_mc_lists($apikey) { $api = new MCAPI($apikey); $retval = $api->lists(); if ($api->errorCode) { return array('errorcode' => $api->errorCode, 'errormessage' => $api->errorMessage); } else { return $retval; } } public function subscribe_user($email, $fname="", $lname="") { $api = new MCAPI($this->apiKey); $merge_vars = array('FNAME'=>$fname, 'LNAME' => $lname); $api->listSubscribe($this->get_listid(), $email, $merge_vars, 'html', $this->get_optin_value($this->get_optin())); if ($api->errorCode){ return array('errorcode' => $api->errorCode, 'errormessage' => $api->errorMessage); //return array('errorcode' => $api->errorCode, 'errormessage' => $api->errorMessage); } else { return true; } } public function unsubscribe_user($email) { $api = new MCAPI($this->apiKey); $retval = $api->listUnsubscribe($this->get_listid(), $email); if ($api->errorCode) { return array('errorcode' => $api->errorCode, 'errormessage' => $api->errorMessage); } else { return "Subscriber added"; } } static public function getModuleConfigInputfields(array $data) { $modules = Wire::getFuel('modules'); $fields = new InputfieldWrapper(); $field = $modules->get("InputfieldText"); $field->attr('name+id', 'apiKey'); $field->attr('value', $data['apiKey']); $field->label = "API Key (Developer Key)"; $field->description = 'Enter the API key'; $fields->append($field); $field = $modules->get("InputfieldSelect"); $field->attr('name+id', 'list_id'); $field->attr('value', $data['list_id']); $mailing_lists = self::get_mc_lists($data['apiKey']); foreach($mailing_lists['data'] as $list) { $field->addOption($list['id'], $list['name']); } $field->label = "Mailing list"; $field->description = 'Choose a mailing list'; $fields->append($field); $field = $modules->get("InputfieldCheckbox"); $field->attr('name+id', 'opt-in'); $field->attr('value', $data['opt-in']); $field->label = "Double opt-in"; $field->description = 'Enable or disable double opt-in'; $fields->append($field); return $fields; } public function ___install() { $page = $this->pages->get('template=admin,name='.self::PAGE_NAME); if (!$page->id) { $page = new Page(); $page->template = $this->templates->get('admin'); $page->parent = $this->pages->get($this->config->adminRootPageID); $page->title = 'MailChimp'; $page->name = self::PAGE_NAME; $page->process = $this; $page->save(); } $permission = $this->permissions->get(self::PERMISSION_NAME); if (!$permission->id) { $p = new Permission(); $p->name = self::PERMISSION_NAME; $p->title = $this->_('View MailChimp Page statistics and synchronize pages with lists'); $p->save(); } } /* Uninstall module * Delete the page 'newsletter-mailchimp' and Permission 'mc-view' */ public function ___uninstall() { $permission = $this->permissions->get(self::PERMISSION_NAME); if ($permission->id) { $permission->delete(); } $page = $this->pages->get('template=admin, name='.self::PAGE_NAME); if ($page->id) { $page->delete(); } } public function ___execute() { return $this->_renderInterface(); } public function ___executeDelete() { return $this->_renderDelete(); } private function _renderInterface() { $this->setFuel('processHeadline', 'MailChimp synchronize tool'); $form = $this->modules->get('InputfieldForm'); $form->attr('id','ga_form'); $wrapper_members = new InputfieldWrapper(); $wrapper_members->attr('id','membersWrapper'); $wrapper_members->attr('title',$this->_('Members')); $wrapper_statistics = new InputfieldWrapper(); $wrapper_statistics->attr('title',$this->_('Statisitcs')); $wrapper_statistics->attr('id','statisticsWrapper'); $html = "<div id='Mailchimp-tabs'>"; $html .= "<div class='ga_header_links'>"; $members = $this->list_members($this->get_apikey()); foreach($members['data'] as $member) { $html .= "<tr><td>" . $member['email'] . "</td><td>" . $member['timestamp'] . "</td><td> <a href='./delete?email=" . $member['email'] . "'>DELETE</a></td></tr>"; } $html .= "</div>"; $html .= "<div id='members_wrapper' class='load'></div>"; $field = $this->modules->get("InputfieldMarkup"); $field->label = $this->_("Gebruikers"); $field->columnWidth = 100; $field->attr('value',$html); $wrapper_members->append($field); $html .= "<div id='statistics_wrapper' class='load'></div>"; $field = $this->modules->get("InputfieldMarkup"); $field->label = $this->_("Gebruikers"); $field->columnWidth = 100; $members = $this->list_members($this->get_apikey()); foreach($members['data'] as $member) { $html .= "<tr><td>" . $member['email'] . "</td><td>" . $member['timestamp'] . "</td><td> <a href='./delete?email=" . $member['email'] . "'>DELETE</a></td></tr>"; } $html .= "</div>"; $field->attr('value',$html); $wrapper_statistics->append($field); $form->append($wrapper_members); $form->append($wrapper_statistics); return $form->render(); } private function _renderDelete() { $this->setFuel('processHeadline', 'MailChimp fdgvzxcgadfg tool'); $form = $this->modules->get('InputfieldForm'); $form->attr('id','ga_form'); $email = $_GET['email']; $wrapper_audience = new InputfieldWrapper(); $field = $this->modules->get("InputfieldMarkup"); $field->label = $this->_("Gebruikers"); $field->columnWidth = 100; $members = $this->list_members($this->get_apikey()); if(isset($_GET['sure']) == 'yes') { $this->unsubscribe_user($_GET['email']); $html = $_GET['email'] . " is verwijdert uit de lijst.<br /><a href=''>Klik hier om terug te gaan</a>"; } else { $html = __("Do you really want to delete " . $email . "<br />"); $html .= "<a href='./delete?email=" . $_GET['email'] . "&sure=yes'>" . __("Yes") . "</a>/<a href='./'>" . __("No") . "</a>"; } $field->attr('value',$html); $wrapper_audience->append($field); $form->append($wrapper_audience); return $form->render(); } }
  6. Okay, so I get the js to load now, but now it says: Uncaught ReferenceError: jQuery is not defined I thought JQuery was included by default or isn't it? I starting feel really noob D:
  7. As a student on a internship I've got a task to make a website in a CMS called Processwire. Had no idea what it was and so I went to look into the api and videos Ryan provided us with. At first i was confused I couldnt really see what it was maybe because i havent had much experience with other CMS before PW. Anyways it took me a while to find out what pages actually were and what you could do with it, when i found out i was amazed and i really wanted to code more and more in pw. I am also using PW now as my main cms/cmf and i love it more everytime i use it. Thanks Ryan for you great work and especially for your great support
  8. Sorry for asking but my .js doesn't seem to load I am creating a Mailchimp.module in the folder Mailchimp with the js Mailchimp.js Which module is the best example, i've been searching for quite a while and all i've tried so far failed epicly...
  9. Hey, I am trying to get tabs in my existing module, I am quite new to modules and stuff and PW in general and I try looking at already existing Modules like the Google Analytics Module and some of the core modules but lack of documentation made me post the question on the PW forums. Now I want to create tabs in my module using the JqueryWireTabs js, because I want to to be like the menu of Google analytics. (see below) But instead of audience, content traffic sources and options i want to have members and statistics... I've tried to create inputfieldwrappers and appending them with content like this: private function _renderInterface() { $this->setFuel('processHeadline', 'MailChimp synchronize tool'); $form = $this->modules->get('InputfieldForm'); $form->attr('id','ga_form'); $wrapper_members = new InputfieldWrapper(); $wrapper_members->attr('id','membersWrapper'); $wrapper_members->attr('title',$this->_('Members')); $wrapper_statistics = new InputfieldWrapper(); $wrapper_statistics->attr('title',$this->_('Statisitcs')); $wrapper_statistics->attr('id','statisticsWrapper'); $html = "<div class='ga_header_links'>"; $members = $this->list_members($this->get_apikey()); foreach($members['data'] as $member) { $html .= "<tr><td>" . $member['email'] . "</td><td>" . $member['timestamp'] . "</td><td> <a href='./delete?email=" . $member['email'] . "'>DELETE</a></td></tr>"; } $html .= "</div>"; $html .= "<div id='members_wrapper' class='load'></div>"; $field = $this->modules->get("InputfieldMarkup"); $field->label = $this->_("Gebruikers"); $field->columnWidth = 100; $field->attr('value',$html); $wrapper_members->append($field); $html = "<div id='statistics_wrapper' class='load'></div>"; $field = $this->modules->get("InputfieldMarkup"); $field->label = $this->_("Gebruikers"); $field->columnWidth = 100; $members = $this->list_members($this->get_apikey()); foreach($members['data'] as $member) { $html .= "<tr><td>" . $member['email'] . "</td><td>" . $member['timestamp'] . "</td><td> <a href='./delete?email=" . $member['email'] . "'>DELETE</a></td></tr>"; } $field->attr('value',$html); $wrapper_statistics->append($field); $form->append($wrapper_members); $form->append($wrapper_statistics); return $form->render(); } Yes yes i know its 2 times the same but in different wrappers, its just to test... Anyways, how do i accomplish this? (Also i tried adding $this->modules->get('JqueryWireTabs'); To my init method but then other modules like fields stop working so i didnt think that was the solution. Many thanks in advance
  10. Ok that did work for some reason... Thanks Soma
  11. And what is the code you used to display the matches?
  12. U scared me Soma D:< Ehm, no not really i think... It seems okay... if i just put 1 team in there it works... But multiple doesnt...
  13. Thats... Dissapointing... I kinda really wanted that because i also want to order it by datetime... How can i acchieve something?
  14. Both examples do not work, Maybe I should of told that the teams is a pagearray field aswell but it contains more pages...
  15. Hey i am trying to perform an OR selector on my Match template My match template contains 2 fields (pagefields, single) to teams called team_1 and team_2 Now I have the following selector: $matches = $pages->find("template=match, team_1|team_2=$teams, sort=match_time"); I retrieve the teams as following: foreach($user->teams as $team) { $teams .= $team."|"; } Above the selector ofcourse. if i echo $teams i get And if i run the code i get: Error Exception: Not unique table/alias: 'field_team_1' (in C:\xampp\htdocs\harmsterproject\wire\core\Database.php line 118) #0 C:\xampp\htdocs\harmsterproject\wire\core\DatabaseQuery.php(84): Database->query(Object(DatabaseQuerySelect)) #1 C:\xampp\htdocs\harmsterproject\wire\core\PageFinder.php(145): DatabaseQuery->execute() #2 C:\xampp\htdocs\harmsterproject\wire\core\Pages.php(144): PageFinder->find(Object(Selectors), Array) #3 [internal function]: Pages->___find('template=match,...') #4 C:\xampp\htdocs\harmsterproject\wire\core\Wire.php(271): call_user_func_array(Array, Array) #5 C:\xampp\htdocs\harmsterproject\wire\core\Wire.php(229): Wire->runHooks('find', Array) #6 C:\xampp\htdocs\harmsterproject\site\templates\dashboard.php(9): Wire->__call('find', Array) #7 C:\xampp\htdocs\harmsterproject\site\templates\dashboard.php(9): Pages->find('template=match,...') #8 C:\xampp\htdocs\harmsterproject\site\templates\home.php(3): require_once('C:\xampp\htdocs...') #9 C:\xampp\htdocs\harmsterproject\wire\core\TemplateF This error message was shown because you are logged in as a Superuser. Error has been logged. What is wrong here?
  16. Lol, agian D: ARGH sorry... thought this was a pw thing...
  17. Yes, i am allowing that, when i echo the field i get 1014|1011|1441 ...
  18. Hey, I have a tournament page that requires teams competing in that tournament, this can be more then 2 it can be 100+ so I thought i get a page array but how do i use it in the template? i tried: foreach($page->teams as $team); { echo $team->title; } But then I'd only get the last team... how do i get this right?
  19. Yeah, but which of the options? I dont see any drop down as in page field or something...
  20. Hey, How do i put a image field to a single image upload... I've been searching for the last hour and im getting pretty fed up. Thanks.
  21. Hey, I need to select some pages that have a datetime between 2 user input datetimes. Now I use the datetime from pw and in the selector i try to select it with $r = $pages->find("template=transaction, datetime>=$start_date, datetime<=$end_date); Now my $start_date and $end_date are formatted by 31-12-2012 but also tried 2012-12-31 And when i try to select a page with a datetime of 03-12-2012 with <=04-12-2012 i get nothing and if 07-12-2012 i get all the pages... What am I doing wrong? Thanks in advance, sorry for the weird explaination, its friday. So i figured out what the problem was, it was something in the code later on... I am stupid D:
  22. Hey PW, I am only a starting developer and I am still in school and my experience with processwire is quite small but recently I've created my own module for Processwire and I kind of had to ask and copy a lot from other sources, now I want to create a small walk through tutorial for people with the same lack of knowledge as me And as a guide for myselfs in the future 1) Setting up the file. Okay, so we start of by making a new document in the Module root folder and call it Harmster.module for this example, we dont need to add the .php extension. Now every module in Processwire needs to extends the classes and methods from Processwire itselfs so we start off by typing class Harmster extends Process{ } You can also extend WireData, I don't really understand the difference but both work for me A module contains 2 standart classes, init() and getModuleInfo() init() This is kind of, or the same as a __construct() method, this always executes and is executed almost at creation. getModuleInfo() This is a method that is used to show the information in the Processwire CMS. We both need to add these to our fresh class like following: class Harmster extends WireData { public static function getModuleInfo() { return array( 'title' => 'Harmster', 'version' => 100, 'summary' => 'Harmster module' 'singular' => true, ); } public function init() { $this->setFuel("harmster", $this); } This is where I, as a starting developer, get really excited about this little code in the init() method $this->setFuel("harmster", $this); Basically creates your class in every template you are going to use and it is callable by $harmster Woah! awesome right! Now this is where I got stuck on, I the user to configure some options in the module :\ hmm... Well I just went asking on the forums and the super nice community of PW came to help me, Wanze in this case (no emoticon because its not allowed) (Check it for yourselfs, http://processwire.c...lds-for-module/) And basically you need to implement some methods from an another object, you should replace this, class Harmster extends WireData implements Module with class Harmster extends Process implements Module, ConfigurableModule But when you add that and try to use your module you'll see you get an error, we need to add one more method to the class called getModuleConfigInputfields add static public function getModuleConfigInputfields(array $data) { } 2) Adding a configurable and usable textbox But now you want to add some input fields, now this is pretty hmm complicated For a simple textbox you put this inside the method you just made: $modules = Wire::getFuel('modules'); $fields = new InputfieldWrapper(); $field = $modules->get("InputfieldText"); $field->attr('name+id', ''some_text_field_saved_name''); $field->attr('value', $data['some_text_field_saved_name']); $field->label = "Hamsters rule!"; $field->description = 'Enter a nice sentance here if you like hamsters'; $fields->append($field); Now you've created a input field and you can use it with $this->get(''some_text_field_saved_name''); in all your methods in this class (no emoticon because its not allowed) If you're lazy Now what you've created is a configurable module, heres a I am lazy and i want to pastey (no emoticon because its not allowed) class Harmster extends Process implements Module, ConfigurableModule { public static function getModuleInfo() { return array( 'title' => 'Harmster', 'version' => 001, 'summary' => '', 'href' => '', 'singular' => true, 'autoload' => true, ); } public function init() { $this->fuel->set("harmster", $this); } static public function getModuleConfigInputfields(array $data) { } } Now if you want to add a overview page, much like the setup, pages, acces and module tab in Processwire CMS default you can easily do this by adding 2 new methods in your class, install and uninstall 3) Creating your install and uninstall So you want to get a nice overview for your module now eh? Well we can do that because Processwire is awesome like that I did this for my module Now, we need to add 2 methods to our class, ___install and ___uninstall (yes, 3 underscores) So add this to your class: public function ___install() { } public function ___uninstall() { } I think that these are kind of self explaing, the one method gets executed when the user installs the module and the other one gets executed when the user deinstalls the module. Now we want to add a page to PW CMS, but how (no emoticon because its not allowed) Thats actually really easy, $page = $this->pages->get('template=admin,name='.self::PAGE_NAME); if (!$page->id) { $page = new Page(); $page->template = $this->templates->get('admin'); $page->parent = $this->pages->get($this->config->adminRootPageID); $page->title = 'MailChimp'; $page->name = self::PAGE_NAME; $page->process = $this; $page->save(); } This is how you install a page, notice that we name the page to self::PAGE_NAME therefor you want to add const PAGE_NAME = 'harmster-module'; with the name of your module BUT BUT now everyone can look in to this module D:< i dont want that! Ofcourse you dont want that. Clients are famous for breaking everything where they put their hands on, so we need to create permissions! Now the way you make permissions is just genius and so easy, you just add this to your ___install method, $permission = $this->permissions->get(self::PERMISSION_NAME); if (!$permission->id) { $p = new Permission(); $p->name = self::PERMISSION_NAME; $p->title = $this->_('View Harmster Page statistics and synchronize pages with lists'); $p->save(); } And you create a permission constant just like PAGE_NAME like this const PERMISSION_NAME = 'hr-view'; And of course you can create more permissions, just genius! Now what our install method should look like is this: public function ___install() { $page = $this->pages->get('template=admin,name='.self::PAGE_NAME); if (!$page->id) { $page = new Page(); $page->template = $this->templates->get('admin'); $page->parent = $this->pages->get($this->config->adminRootPageID); $page->title = 'Harmster'; $page->name = self::PAGE_NAME; $page->process = $this; $page->save(); } $permission = $this->permissions->get(self::PERMISSION_NAME); if (!$permission->id) { $p = new Permission(); $p->name = self::PERMISSION_NAME; $p->title = $this->_('View Harmster Page statistics and synchronize pages with lists'); $p->save(); } } This will set a module page up for you And we create an uninstall method, this basicly reverts your installed permissions and pages. public function ___uninstall() { $permission = $this->permissions->get(self::PERMISSION_NAME); if ($permission->id) { $permission->delete(); } $page = $this->pages->get('template=admin, name='.self::PAGE_NAME); if ($page->id) { $page->delete(); } } Now you are might be wondering, how do i get to display content in my page :S Well, I kinda stole this from other modules and it does work, but I am open for suggestions. the method ___execute gets executed when you click on your page in the PWCMS. What i wrote in there is public function ___execute() { return $this->_renderInterface(); } and in renderInterface() i put the next code: private function _renderInterface() { $this->setFuel('processHeadline', 'MailChimp synchronize tool'); $form = $this->modules->get('InputfieldForm'); $form->attr('id','ga_form'); $wrapper_audience = new InputfieldWrapper(); $field = $this->modules->get("InputfieldMarkup"); $field->label = $this->_("Gebruikers"); $field->columnWidth = 100; $members = $this->list_members($this->get_apikey()); $html = "<table class='AdminDataTable AdminDataList AdminDataTableSortable'>"; foreach($members['data'] as $member) { $html .= "<tr><td>" . $member['email'] . "</td><td>" . $member['timestamp'] . "</td></tr>"; } $html .= "</table>"; $field->attr('value',$html); $wrapper_audience->append($field); $form->append($wrapper_audience); return $form->render(); } Bascily you create a form and you render the form and that displays it for you, just play around with it for a bit and you'll get into it, as i am still getting into it. I am lazy, here a copy, pastey (no emoticon because its not allowed) <?php class Harmster extends Process implements Module, ConfigurableModule { const PAGE_NAME = 'harmster-module'; const PERMISSION_NAME = 'hr-view'; public static function getModuleInfo() { return array( 'title' => 'Harmster', 'version' => 001, 'summary' => '', 'href' => '', 'singular' => true, 'autoload' => true, ); } public function init() { $this->fuel->set("harmster", $this); } static public function getModuleConfigInputfields(array $data) { } public function ___install() { $page = $this->pages->get('template=admin,name='.self::PAGE_NAME); if (!$page->id) { $page = new Page(); $page->template = $this->templates->get('admin'); $page->parent = $this->pages->get($this->config->adminRootPageID); $page->title = 'Harmster'; $page->name = self::PAGE_NAME; $page->process = $this; $page->save(); } $permission = $this->permissions->get(self::PERMISSION_NAME); if (!$permission->id) { $p = new Permission(); $p->name = self::PERMISSION_NAME; $p->title = $this->_('View Harmster Page statistics and synchronize pages with lists'); $p->save(); } } public function ___uninstall() { $permission = $this->permissions->get(self::PERMISSION_NAME); if ($permission->id) { $permission->delete(); } $page = $this->pages->get('template=admin, name='.self::PAGE_NAME); if ($page->id) { $page->delete(); } } public function ___execute() { return $this->_renderInterface(); } private function _renderInterface() { $this->setFuel('processHeadline', 'MailChimp synchronize tool'); $form = $this->modules->get('InputfieldForm'); $form->attr('id','ga_form'); $wrapper_audience = new InputfieldWrapper(); $field = $this->modules->get("InputfieldMarkup"); $field->label = $this->_("Gebruikers"); $field->columnWidth = 100; $members = $this->list_members($this->get_apikey()); $html = "<table class='AdminDataTable AdminDataList AdminDataTableSortable'>"; foreach($members['data'] as $member) { $html .= "<tr><td>" . $member['email'] . "</td><td>" . $member['timestamp'] . "</td></tr>"; } $html .= "</table>"; $field->attr('value',$html); $wrapper_audience->append($field); $form->append($wrapper_audience); return $form->render(); } } I'll update this tutorial in the near future as i am still working my way up (no emoticon because its not allowed) Aww, i get an error when i save it, thats not nice. Thanks for reading (no emoticon because its not allowed)EDIT Updating this tutorial very soon, its horrible and incorrect
  23. I found out why i did not work, it was a PHP problem with the static class... Thanks all
  24. I tried reinstalling and i got this error: Error Using $this when not in object context (line 96 of /home/harm/NetBeansProjects/phpScriptjes/mailchimp/wire/core/Data.php)
  25. Thank you Wanze, it worked. However for some reason it seems that I can't use the methods from my class in the website. I've set autoload to true and i've set a fuel like this public static function getModuleInfo() { return array( 'title' => 'Mailchimp', 'version' => 101, 'summary' => 'An example module used for demonstration purposes. See the /site/modules/Helloworld.module file for details.', 'singular' => true, 'autoload' => true, ); } public function init() { $this->setFuel("mailchimp", $this); } public function get_apikey(){ return $apiKey = $this->get('apiKey'); } But when i try to use it like this: $api_key = $mailchimp->get_apikey(); echo $api_key; With the error: Any thoughts? EDIT: Also when i try to use $this in any context within the class i get errors like these: Error Using $this when not in object context (line 34 of /home/harm/NetBeansProjects/phpScriptjes/mailchimp/site/modules/Mailchimp.module)
×
×
  • Create New...