public function render($field) { // Load the image that is associated with this field $imagedata = Wi3::inst()->model->factory("site_data")->setref($field)->setname("image")->load(); $width = $field->options["stylearray"]["width"]; if (empty($width)) { // No hard value for width means that we can fallback to our stored value $width = Wi3::inst()->model->factory("site_data")->setref($field)->setname("width")->load()->data; if (empty($width)) { $width = "200"; } } else { // Hard value is set. Save to fallback if (strpos($width, "px") !== false) { $width = substr($width, 0, -2); } $widthobj = Wi3::inst()->model->factory("site_data")->setref($field)->setname("width")->load(); $widthobj->data = $width; $widthobj->updateorcreate(); } $description = ""; // TODO: store with image? $addition = ""; if (strlen($description) > 0) { $addition = "<span>" . $description . "</span>"; } if (empty($imagedata->data)) { return "<img src='" . Wi3::inst()->urlof->pagefillerfiles . "components/image/static/images/noimage.png'>" . $addition; } else { // fetch image-id and render the image $fileid = $imagedata->data; $file = Wi3::inst()->model->factory("site_file")->set("id", $fileid)->load(); return "<img src='" . Wi3::inst()->urlof->sitefiles . "data/uploads/" . $width . "/" . $file->filename . "'>" . $addition; } }
public function saveEditableBlockContent($editableblock, $blockname, $content) { $data = Wi3::inst()->model->factory("site_data")->setref($this)->set("name", $blockname)->load(); $data->data = $content; // Save the data $data->updateorcreate(); }
public function action_rssfeed() { // Feed always includes 20 latest items $amount = 20; // TODO: load information from field-instance using an id $dataobject = array(); $articles = array(); // TODO: Rework this or at least implement caching. Right now it is completely inefficient // 1. Fetch the latest [$amount] fields with type simpleblogarticle $fields = Wi3::inst()->model->factory("site_field")->values(array("type" => "simpleblogarticle"))->load(DB::select()->order_by("id"), $amount); // 2. Grab their data foreach ($fields as $blogfield) { // Get page where this field is situated on and include its URL $page = Wi3::inst()->model->factory("site_page")->values(array("id" => $blogfield->_refid))->load(); $pageurl = Wi3::inst()->urlof->page($page); // Load data $data = $this->fielddata($blogfield); $data->pageurl = $pageurl; $image = Wi3::inst()->model->factory("site_file")->values(array("id" => $data->image))->load(); $imageurl = Wi3::inst()->urlof->image($image, 300); $data->imageurl = $imageurl; $articles[] = $data; } // Newest on top $articles = array_reverse($articles); // Generate! $this->template = $this->view("rssfeed")->set("data", $dataobject)->set("articles", $articles)->render(); Request::current()->headers["Content-Type"] = "application/rss+xml"; // Send as file? Request::current()->send_file(true,"rssfeed.xml"); }
public function action_create_superadmin() { try { $m = Wi3::inst()->model->factory("user"); $m->username = "******"; $m->email = "*****@*****.**"; $m->load(); foreach ($m->roles as $role) { $role->delete(); } $m->delete(); // TODO: make sure Sprig understands that the columns with $_in_db == FALSE should NOT be added to the delete() clause // Then, place the following line before the $m->password = "******" above $m->password = "******"; $m->password_confirm = "superadmin"; $m->create(); // Now create roles $role = Wi3::inst()->model->factory("role"); $role->name = "superadmin"; $role->description = "superadmin role"; $role->users = $m->id; $role->create(); $role = Wi3::inst()->model->factory("role"); $role->name = "login"; $role->description = "login role"; $role->users = $m->id; $role->create(); } catch (Exception $e) { echo Kohana::debug($e); return; } echo "<p>Superadminuser has been recreated.</p>"; echo "<p>Back to <a href='..'>setup</a></p>"; }
public function render() { $id = Wi3::inst()->date_now(); $ret = "<label for='" . $this->attributes->name . "'/><input id='input_" . $id . "' name='" . $this->attributes->name . "' "; if (isset($this->attributes->value)) { $ret .= "value='" . $this->attributes->value . "' "; } $ret .= "></input>"; $ret .= ' <script> //datePickers on input with class componentInput_datepicker $(document).ready(function() { $.datepicker.setDefaults({ dateFormat: "dd-mm-yy", changeMonth: true, changeYear: true }); //"#"+prefix+"_add input.componentInput_datepicker, #"+prefix+"_edit input.componentInput_datepicker" $("#input_' . $id . '").each(function() { //give ID if none is attached yet //if ($(this).attr("id").length < 1) { // counter++; // $(this).attr("id", "input_" + wi3.dateNow() + counter); //} $(this).datepicker(); }); }); </script> '; return $ret; }
public function update() { $this->loadarraydata(); // Make sure that existing arraydata is loaded foreach ($this->_updatedarray as $key => $val) { // If $val is an Array, serialize it if (is_array($val)) { $val = serialize($val); } // Search for an existing arraydata with this key, if it exists if (isset($this->_originalarray[$key])) { $arraydata = Wi3::inst()->model->factory("site_arraydata")->set("array", $this)->set("key", $key)->load(); $arraydata->val = $val; $arraydata->update(); } else { // Create new arraydata and fill it $arraydata = Wi3::inst()->model->factory("site_arraydata"); $arraydata->key = $key; $arraydata->val = $val; $arraydata->array = $this; $arraydata->create(); // Add it to the _related list $this->add("_arraydatas", $arraydata); // Now, the array has this arraydata as 'original' $this->_originalarray[$key] = $val; } } return $this; }
public function render($field) { // Load the articles, and create a basic article if there are none $articles = Wi3::inst()->model->factory("site_array")->setref($field)->setname("articles")->load(); if (!$articles->loaded()) { $articles->create(); } if (count($articles) == 0) { // Create an article $articleid = Wi3::inst()->date_now(); //$articles-> } // Load the image that is associated with this field $imagedata = Wi3::inst()->model->factory("site_data")->setref($field)->setname("image")->load(); // If data does not exist, create it if (!$imagedata->loaded()) { $imagedata->create(); } if (empty($imagedata->data)) { return "<img src='" . Wi3::inst()->urlof->pagefillerfiles . "components/image/static/images/noimage.png'> <cms type='editableblock' name='description'>Beschrijving van afbeelding</cms>"; } else { // fetch image-id and render the image $fileid = $imagedata->data; $file = Wi3::inst()->model->factory("site_file")->set("id", $fileid)->load(); return "<img src='" . Wi3::inst()->urlof->sitefiles . "data/uploads/200/" . $file->filename . "'> <cms type='editableblock' name='description'>Beschrijving van afbeelding</cms>"; } }
public function action_order() { // Load field and check if user is allowed to access data of that field $field = $this->field($_POST["fieldid"]); // Load pre-set emailaddress $address = Wi3::inst()->model->factory("site_data")->setref($field)->setname("emailaddress")->load()->data; if (empty($address)) { echo json_encode(array("scriptsbefore" => array("0" => "\$(wi3.popup.getDOM()).fadeOut(100,function() { \$(this).html('Bestelling kon <strong>niet</strong> geplaatst worden! Stel de eigenaar van de site hiervan op de hoogte.').fadeIn(); } );"))); } else { // Send an email to client and to the pre-set emailaddress $presetemailaddress = $address; // Set folder to $_POST to store $folderid = Wi3::inst()->model->factory("site_data")->setref($field)->setname("folder")->load()->data; $_POST["folderid"] = $folderid; // Store order $orders = Wi3::inst()->model->factory("site_data")->setref($field)->setname("orders")->load(); if (!$orders->loaded()) { $orders->create(); } $ordersdata = unserialize($orders->data); $ordersdata[] = $_POST; $orders->data = serialize($ordersdata); $orders->update(); // Create mail $message = $this->view("mail")->set("post", $_POST)->render(); $clientmessage = $this->view("clientmail")->set("post", $_POST)->render(); $subject = "Bestelling foto's"; // Send mail to 'us' and to client mail($presetemailaddress, $subject, $message); mail($_POST["emailaddress"], $subject, $clientmessage); echo json_encode(array("scriptsbefore" => array("0" => "\$(wi3.popup.getDOM()).fadeOut(100,function() { \$(this).html('Bestelling succesvol geplaatst!').fadeIn(); } );"))); } }
function getall() { if ($this->allpages == NULL) { // The , FALSE parameter sets no limit to the amount of records loaded $this->allpages = Wi3::inst()->model->factory("site_page")->load(NULL, FALSE); } return $this->allpages; }
public static function pagefiller($pagefiller) { if (empty($pagefiller)) { return Wi3::inst()->pathof->pagefiller; } else { return APPPATH . "pagefillers/" . $pagefiller . "/"; } }
public function render($field) { // Load the data that is associated with this field $data = Wi3::inst()->model->factory("site_array")->setref($field)->setname("data")->load(); // Mark the field as a block-element $field->options["stylearray"]["display"] = "block"; // Return rendered view return $this->view("render")->set("code", $data->code)->set("fieldid", $field->id)->render(); }
function thumbnail($file) { $ret = ""; $ret .= "<div class='smallmargin thumbnail hoverable smallpadding'>"; $ret .= "<div class='imagecontainer'><img src='" . Wi3::inst()->urlof->sitefiles . "data/uploads/50/" . $file->filename . "' fullSRC='" . Wi3::inst()->urlof->sitefiles . "data/uploads/" . $file->filename . "'></img></div>"; $ret .= "<div class='productbuttons'><button class='smallpadding paddingmarginwithinbox' data-buttontype='addtocart' data-productid='" . $file->id . "'>+</button></div>"; $ret .= "</div>"; return $ret; }
public function css($name) { if (is_array($name)) { foreach ($name as $n) { Wi3::inst()->css->add($this->_params["css_url"] . $n, "view"); } } else { Wi3::inst()->css->add($this->_params["css_url"] . $name, "view"); } }
public static function renderPage($pageOrPagename, $renderedInAdminArea) { // Create a page from pagename. Wi3 will automatically distinguish between id-urls (/_number) and slug-urls (/string) and fetch the correct page Wi3::inst()->sitearea->setpage($pageOrPagename); // Render page // TODO: we should have one siteare per Request::Instance() (i.e. true HMVC) since the current structure is quite inflexible // and dependency injecting everything into everywhere is also quite unfeasable // We should set sitearea etc on the current Request and be able to fire new requests with different URLs etc easily return Wi3::inst()->sitearea->page->render($renderedInAdminArea); }
public function render($field) { $dataobject = $this->fielddata($field); if (!isset($dataobject->image)) { $dataobject->image = "notset"; $dataobject->update(); } $image = Wi3::inst()->model->factory("site_file")->values(array("id" => $dataobject->image))->load(); $imageurl = Wi3::inst()->urlof->image($image, 300); return $this->view("render")->set("data", $dataobject)->set("field", $field)->set("imageurl", $imageurl)->render(); }
public function action_editpagetemplatesettings($pageid) { $page = Wi3::inst()->model->factory("Site_Page")->set("id", $pageid)->load(); Wi3::inst()->sitearea->page = $page; // Now notify other entities that use this->page that the page has been loaded Event::instance("wi3.init.sitearea.page.loaded")->execute(); // Save the template for this page $templatename = $_POST["pagefiller_templatename"]; $page->templatename = $templatename; $page->update(); echo json_encode(array("alert" => "template is geupdate")); }
private function prepareForViewing($pagename) { // Load the requested page Wi3::inst()->sitearea->setpage($pagename); // Will also execute the "wi3.init.sitearea.page.loaded" event // Now check the rights for this page // Pages can only be viewed if the page has not set any 'viewright' or if the user that requests the page is logged in and has that required viewright $page = Wi3::inst()->sitearea->page; // TODO: rewrite with ACL, see adminarea if (!empty($page->viewright)) { // Check for required role $requiredrole = $page->viewright; $hasrequiredrole = false; // Check if there is a logged-in user for this site at all $user = Wi3::inst()->sitearea->auth->user; if (is_object($user)) { // Check user rights $roles = $user->roles; foreach ($roles as $role) { if (strtolower($role->name) === strtolower($requiredrole) or $role->name === strtolower("admin")) { $hasrequiredrole = true; break; } } } // Check if (!$hasrequiredrole) { // Redirect to the loginpage of the site (if known, that is) $site = Wi3::inst()->sitearea->site; if (strlen($site->loginpage) > 0) { Request::instance()->redirect(Wi3::inst()->urlof->page($site->loginpage)); } else { throw new ACL_Exception_403(); // Permission denied exit; } } } // Caching is per user Wi3::inst()->cache->requireCacheParameter("user"); $user = Wi3::inst()->sitearea->auth->user; if (is_object($user)) { $userid = $user->id; } else { $userid = ""; } //Wi3::inst()->cache->doRemoveCacheWhenAllRequiredCacheParametersAreFilled(); Wi3::inst()->cache->fillCacheParameter("user", $userid); // By default, don't cache pages // This can be overridden in the user template, if desired Wi3::inst()->cache->doNotCache(); }
public function action_remove() { $fieldid = $_POST["fieldid"]; $field = Wi3::inst()->model->factory("site_field")->set("id", $fieldid)->load(); $dataobject = $this->fielddata($field); // Find reference index $elements = $dataobject->elements; $index = $_POST["index"]; $arrayIndex = array_search($index, $elements); // Remove element at that index unset($elements[$arrayIndex]); $this->fielddata($field, "elements", $elements); }
public function action_edit() { // Load field $fieldid = $_POST["fieldid"]; $field = Wi3::inst()->model->factory("site_field")->set("id", $fieldid)->load(); // Load data array $data = Wi3::inst()->model->factory("site_array")->setref($field)->setname("data")->load(); // Update array if (isset(Wi3::inst()->originalpost["code"])) { $data->code = Wi3::inst()->originalpost["code"]; } $data->update(); echo json_encode(array("scriptsbefore" => array("0" => "window.wi3.livejavascript_examples['livejavascript_input_" . $field->id . "'].setCode(wi3.pagefillers.default.edittoolbar.fromBase64('" . base64_encode($data->code) . "'));", "1" => "window.wi3.livejavascript_examples['livejavascript_input_" . $field->id . "'].run();", "2" => "wi3.pagefillers.default.edittoolbar.hidePopup();"))); }
public function action_edit() { // Load field, and the image-date field that connects to it $fieldid = $_POST["fieldid"]; $field = Wi3::inst()->model->factory("site_field")->set("id", $fieldid)->load(); // Update data field with image-id $data = Wi3::inst()->model->factory("site_array")->setref($field)->setname("data")->load(); if (isset($_POST["url"])) { $data->url = $_POST["url"]; $data->destinationtype = "url"; } else { if (isset($_POST["fileid"])) { $data->fileid = $_POST["fileid"]; $data->destinationtype = "file"; } else { if (isset($_POST["pageid"])) { $data->pageid = $_POST["pageid"]; $data->destinationtype = "page"; } } } $data->update(); $url = ""; $destinationtype = $data->destinationtype; // get proper URL if ($destinationtype == "url") { $url = $data->url; } else { if ($destinationtype == "file") { $fileid = $data->fileid; $file = Wi3::inst()->model->factory("site_file")->set("id", $fileid)->load(); if ($file->loaded()) { $url = Wi3::inst()->urlof->file($file); } else { $url = ""; } } else { if ($destinationtype == "page") { $pageid = $data->pageid; $page = Wi3::inst()->model->factory("site_page")->set("id", $pageid)->load(); if ($page->loaded()) { $url = Wi3::inst()->urlof->page($page->slug); } else { $url = ""; } } } } echo json_encode(array("scriptsbefore" => array("0" => "\$('[type=field][fieldid=" . $fieldid . "] [type=fieldcontent] > a').attr('href', '" . $url . "');", "1" => "wi3.pagefillers.default.edittoolbar.hidePopup();"))); }
public function fieldevent($eventtype, $field) { if ($eventtype == "create") { // Set the inserttype // TODO: think about this. It doesn't feel right. Controller_Pagefiller_Default_Edittoolbar_Ajax::$responseoptions["inserttype"] = "replace"; // Create the data that is associated with this field $data = Wi3::inst()->model->factory("site_array")->setref($field)->setname("data")->create(); $this->fielddata($field, "entertimestamp", time()); } else { if ($eventtype == "delete") { Wi3::inst()->model->factory("site_array")->setref($field)->setname("data")->delete(); } } }
public function __GET($type) { // Check whether this particular config instance has already been created if (isset($this->configinstances[$type])) { return $this->configinstances[$type]; } // Create a new instance of a config loader if ($type == "site") { $this->configinstances[$type] = new Wi3_Config(array("configdir" => Wi3::inst()->pathof->site . "config/")); return $this->configinstances[$type]; } else { if ($type == "wi3" or $type == "app") { $this->configinstances[$type] = new Wi3_Config(array("configdir" => Wi3::inst()->pathof->wi3 . "config/")); return $this->configinstances[$type]; } } }
public function action_edit() { // Load field, and the image-date field that connects to it $fieldid = $_POST["fieldid"]; $field = Wi3::inst()->model->factory("site_field")->set("id", $fieldid)->load(); $data = Wi3::inst()->model->factory("site_data")->setref($field)->setname("image")->load(); // If data does not exist, create it if (!$data->loaded()) { $data->create(); } // Update data field with image-id $fileid = $_POST["image"]; $data->data = $fileid; $data->update(); $file = Wi3::inst()->model->factory("site_file")->set("id", $fileid)->load(); echo json_encode(array("scriptsbefore" => array("0" => "\$('[type=field][fieldid=" . $fieldid . "] [type=fieldcontent] > img').attr('src', '" . Wi3::inst()->urlof->sitefiles . "data/uploads/200/" . $file->filename . "');"))); }
public function render($field) { // Load the image that is associated with this field $imagedata = Wi3::inst()->model->factory("site_data")->setref($field)->setname("folder")->load(); if (empty($imagedata->data)) { return "Geen afbeeldingsmap ingesteld."; } else { // fetch image-id and render the image $fileid = $imagedata->data; $folder = Wi3::inst()->model->factory("site_file")->set("id", $fileid)->load(); // Load all images for this folder $query = DB::select()->where($folder->left_column, ">", $folder->{$folder->left_column})->and_where($folder->right_column, "<", $folder->{$folder->right_column})->order_by($folder->left_column); $files = $folder->load($query, NULL); // NULL for no limit return $this->view("view")->set("files", $files)->render(); } }
public function renderContent() { // Set pagepositions if (is_object(Wi3::inst()->sitearea->page->pageposition)) { $pageposition = Wi3::inst()->sitearea->page->pageposition->load(); } else { $pageposition = Wi3::inst()->model->factory("site_pageposition")->set("id", Wi3::inst()->sitearea->page->pageposition)->load(); } if ($pageposition->{$pageposition->level_column} == 0) { // Lowest level, there is no parent, and all level 0 are siblings $pagepositions = Wi3::inst()->model->factory("site_pageposition")->set($pageposition->level_column, "0")->load(NULL, FALSE); // False for no limit } else { $pagepositions = $pageposition->parent()->children(); } $this->pagePositions($pagepositions); return parent::renderContent(); }
public function loadPages() { if (!isset($this->pages)) { $pages = array(); if ($this->pagePositions() == null) { $this->pagePositions(Wi3::inst()->sitearea->pagepositions->getall()); } $pagepositions = $this->pagePositions(); foreach ($pagepositions as $pageposition) { $pagepositionpages = $pageposition->pages; $page = $pagepositionpages[0]; // Simply get first page $pages[] = $page; } $this->pages = $pages; } return $this->pages; }
public function javascript($file, $category = "wi3") { ///find the directory of this plugin $filename = strtolower(str_replace("_", "/", get_class($this))); $location = Wi3::inst()->unixpath(Kohana::find_file("classes", $filename)); //extract the 'base' directory $directory = substr($location, 0, strrpos($location, "/classes/")) . "/"; //now remove the first part of the dir, so that the remaining dir works from the wi3 base dir $directory = substr($directory, strlen(Wi3::inst()->pathof->wi3)); //at last, create an URL to the wi3 base dir and add the remaining dir $url = Wi3::inst()->urlof->wi3files . $directory; if (is_array($file)) { foreach ($file as $f) { Wi3::inst()->javascript->add($url . "static/javascript/" . $f, $category); } } else { Wi3::inst()->javascript->add($url . "static/javascript/" . $file, $category); } }
public function getpage($pagename) { // Empty pagename should be turned into NULL, or otherwise the Sprig will still load a page successfully (the last added page, to be exact) if (empty($pagename)) { $pagename = -1; } // Check whether we deal with a pagename that is meant to identify a numerical id (in the form of domain.com/[something]/_numericid) if (substr($pagename, 0, 1) == "_" and is_numeric(substr($pagename, 1))) { $page = Wi3::inst()->model->factory("site_page")->set('id', substr($pagename, 1))->load(); } else { $page = Wi3::inst()->model->factory("site_page")->set('slug', $pagename)->load(); } // Check whether the load was succesfull if (!$page->loaded()) { // Load landingpage. This is always an ID, not a slug $pageid = !empty(Wi3::inst()->sitearea->site->landingpage) ? Wi3::inst()->sitearea->site->landingpage : Wi3::inst()->sitearea->site->notfoundpage; if (empty($pageid)) { $pageid = -1; } $page = Wi3::inst()->model->factory("site_page")->set('id', $pageid)->load(); // Check if that worked, else load notfoundpage if (!$page->loaded()) { // Load notfoundpage $pageid = Wi3::inst()->sitearea->site->notfoundpage; if (empty($pageid)) { // If empty, then load first page $pageposition = Wi3::inst()->model->factory("site_pageposition")->load(NULL, 1); // limit to 1 $page = Wi3::inst()->sitearea->page = $pageposition->pages[0]; } else { $page = Wi3::inst()->model->factory("site_page")->set('slug', $pageid)->load(); // If loading notfoundpage did not work, then load first page if (!$page->loaded()) { $pageposition = Wi3::inst()->model->factory("site_pageposition")->load(NULL, 1); // limit to 1 $page = Wi3::inst()->sitearea->page = $pageposition->pages[0]; } } } } return $page; }
public function __construct() { // Note: it is not recommended to call Auth_Sprig::instance() for both global and siteauth, since that will return a singleton everytime, and this will get conflicts between globalauth and siteauth, if they are used at the same time // Manually loading the config and creating a new Auth_Sprig like // $conf = Kohana::config("auth"); // $inst = new Auth_Sprig($conf); // Does also not work, since this will (assumably) call the new Auth() twice, // where somewhere the salt_pattern gets rewritten to an array, causing an error the next time the Auth() is generated $this->_auth = Auth_Sprig::instance(); $this->_auth->user_model($this->_user_model); $this->_auth->token_model($this->_token_model); $this->session = Session::instance(); if ($this->_auth->logged_in() or $this->_auth->auto_login() == TRUE) { // Logged in $this->user = $this->_auth->get_user(); // Set cache-addendum // TODO: Wi3::$cache->page_addendums["wi3_login_userid"] = $this->user->id; $this->session->set("userid", $this->user->id); $this->session->set("sitefolder", Wi3::inst()->pathof->site); //set this for use by for example the Tinymce advimage plugin } }
public function render() { $id = Wi3::date_now(); $val = $this->val(); if (isset($this->attributes->label)) { echo "<label for='" . $this->attributes->name . "'></label>"; } echo "<input type='hidden' name='" . $this->attributes->name . "' id='input_" . $id . "' value='" . $val . "' />"; echo "<div style='padding: 10px;'>"; if (isset($this->settings->extensions)) { $files = Wi3::inst()->sitearea->files->find(array("extensions" => $this->settings->extensions)); } else { $files = Wi3::inst()->sitearea->files->find(array()); } $counter = 0; foreach ($files as $file) { $level = $file->{$file->level_column}; $counter++; echo "<div style='padding-left: " . $level * 10 . "px; "; if ($file->id != $val) { echo "opacity: 0.6; "; } echo "margin: 5px;' id='file_" . $id . "_" . $counter . "' class='file_" . $id . "'>"; echo "<a href='javascript:void(0)' style='text-decoration: none;' onClick='\$(\"#input_" . $id . "\").val(\"" . $file->id . "\").has(\"xyz\").add(\"#file_" . $id . "_" . $counter . "\").fadeTo(50,1).has(\"xyz\").add(\".file_" . $id . "\").not(\"#file_" . $id . "_" . $counter . "\").fadeTo(50,0.40);'>"; echo "<div style='margin: 5px;'>"; // Add small thumbnail if file is an image if ($file->isImage()) { echo "<img src='" . Wi3::inst()->urlof->site . "_uploads/30/" . $file->filename . "'/> "; } echo $file->filename; echo "</div>"; echo "</a>"; echo "</div>"; } echo "<div style='font-size: 1px; visibility: hidden; clear:both;'>.</div>"; echo "</div>"; }