/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. * We have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality; * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderForm(S $objFormToRender, A $objFormArray = NULL) { // Make them defaults ... if ($objFormArray == NULL) { $objFormArray = new A(); } // Do a switch ... switch ($objFormToRender) { case 'propertyCreate': // Set the URL to go back; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { if ($this->checkPOST(self::$objProductsPropertyTableFKey)->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsPropertyTableFKey, new S(PRODUCTS_PROPERTY_CANNOT_BE_EMPTY)); } if ($this->checkPOST(self::$objProductsPropertyTableFVar)->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsPropertyTableFVar, new S(PRODUCTS_VALUE_CANNOT_BE_EMPTY)); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(PRODUCTS_ADD_PROPERTY))->setSQLAction(new S('update'))->setTableName(self::$objProductsPropertyTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objProductsPropertyTableFId)->setExtraUpdateData(self::$objProductsPropertyTableFPId, $_GET[ADMIN_ACTION_ID])->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setValue(new S(PRODUCTS_ADD_PROPERTY))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsPropertyTableFKey)->setLabel(new S(PRODUCTS_PROPERTY))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objProductsPropertyTableFVar)->setLabel(new S(PRODUCTS_VALUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'propertyEdit': // Set the URL to go back; $objURLToGoBack = URL::rewriteURL(new A(array(PRODUCTS_ACTION_PROPERTY, PRODUCTS_ID_PROPERTY))); // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { if ($this->checkPOST(self::$objProductsPropertyTableFKey)->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsPropertyTableFKey, new S(PRODUCTS_PROPERTY_CANNOT_BE_EMPTY)); } if ($this->checkPOST(self::$objProductsPropertyTableFVar)->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsPropertyTableFVar, new S(PRODUCTS_VALUE_CANNOT_BE_EMPTY)); } } $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(PRODUCTS_EDIT_PROPERTY))->setSQLAction(new S('update'))->setTableName(self::$objProductsPropertyTable)->setUpdateId($_GET[PRODUCTS_ID_PROPERTY])->setUpdateField(self::$objProductsPropertyTableFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setValue(new S(PRODUCTS_EDIT_PROPERTY))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsPropertyTableFKey)->setLabel(new S(PRODUCTS_PROPERTY))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objProductsPropertyTableFVar)->setLabel(new S(PRODUCTS_VALUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'propertyErase': // Set the URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(PRODUCTS_ACTION_PROPERTY, PRODUCTS_ID_PROPERTY))); // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objProductsPropertyTable)->doToken('%condition', new S('%objProductsPropertyTableFId = "%Id"'))->doToken('%Id', $_GET[PRODUCTS_ID_PROPERTY])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'imageCreate': // Set the URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST(self::$objProductsIMGTableFTitle)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsIMGTableFTitle)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsIMGTableFTitle, new S(PRODUCTS_IMAGE_TITLE_CANNOT_BE_EMPTY)); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(PRODUCTS_ADD_IMAGE))->setSQLAction(new S('update'))->setTableName(self::$objProductsIMGTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objProductsIMGTableFId)->setUploadDirectory(new S('products/images/' . $_GET[ADMIN_ACTION_ID]))->setUploadImageResize(new A(array(60 => 60, 100 => 100, 128 => 128, 320 => 240, 640 => 480, 800 => 600)))->setExtraUpdateData(self::$objProductsIMGTableFProdId, $_GET[ADMIN_ACTION_ID])->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setInputInfoMessage($this->getHELP($objFormToRender))->setValue(new S(PRODUCTS_ADD_IMAGE))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsIMGTableFTitle)->setLabel(new S(PRODUCTS_IMAGE_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setName(self::$objProductsIMGTableFURL)->setLabel(new S(PRODUCTS_IMAGE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objProductsIMGTableFCaption)->setLabel(new S(PRODUCTS_CAPTION))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'imageEdit': // Set the URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(PRODUCTS_ACTION_IMAGE, PRODUCTS_ID_IMAGE))); // Do the form, make it happen; if ($this->checkPOST(self::$objProductsIMGTableFTitle)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsIMGTableFTitle)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsIMGTableFTitle, new S(PRODUCTS_IMAGE_TITLE_CANNOT_BE_EMPTY)); } } $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(PRODUCTS_EDIT_IMAGE))->setSQLAction(new S('update'))->setTableName(self::$objProductsIMGTable)->setUpdateId($_GET[PRODUCTS_ID_IMAGE])->setUpdateField(self::$objProductsIMGTableFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE))->setUploadDirectory(new S('products/images/' . $_GET[ADMIN_ACTION_ID]))->setUploadImageResize(new A(array(60 => 60, 100 => 100, 128 => 128, 320 => 240, 640 => 480, 800 => 600)))->setInputType(new S('submit'))->setValue(new S(PRODUCTS_EDIT_IMAGE))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsIMGTableFTitle)->setLabel(new S(PRODUCTS_IMAGE_TITLE))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setName(self::$objProductsIMGTableFURL)->setLabel(new S(PRODUCTS_IMAGE))->setFileController(new B(TRUE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objProductsIMGTableFCaption)->setLabel(new S(PRODUCTS_CAPTION))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'imageErase': // Set the URL to back too; $objURLToGoBack = URL::rewriteURL(new A(array(PRODUCTS_ACTION_IMAGE, PRODUCTS_ID_IMAGE))); // First, delete existing images; $objProductImages = $this->_Q(_QS('doSELECT')->doToken('%what', self::$objProductsIMGTableFURL)->doToken('%table', self::$objProductsIMGTable)->doToken('%condition', new S('WHERE %objProductsIMGTableFId = "%Id"'))->doToken('%Id', $_GET[PRODUCTS_ID_IMAGE])); // Knowing the images, delete THEM; foreach ($objProductImages as $k => $v) { UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . '60_60_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . '100_100_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . '128_128_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . '320_240_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . '640_480_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images/' . $_GET[ADMIN_ACTION_ID] . _S . '800_600_' . $v['url']); } // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objProductsIMGTable)->doToken('%condition', new S('%objProductsIMGTableFId = "%Id"'))->doToken('%Id', $_GET[PRODUCTS_ID_IMAGE])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'productCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work; if ($this->checkPOST(self::$objProductsTableFCode)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFCode)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFCode, new S(PRODUCTS_CODE_MUST_BE_ENTERED)); } else { if ($this->checkCodeIsUnique($this->getPOST(self::$objProductsTableFCode))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsTableFCode, new S(PRODUCTS_CODE_MUST_BE_UNIQUE)); } } } if ($this->checkPOST(self::$objProductsTableFName)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFName)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFName, new S(PRODUCTS_NAME_MUST_BE_ENTERED)); } else { if ($this->checkProductNameIsUnique($this->getPOST(self::$objProductsTableFName))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsTableFName, new S(PRODUCTS_NAME_MUST_BE_UNIQUE)); } } } if ($this->checkPOST(self::$objProductsTableFName)->toBoolean() == TRUE) { if ($this->checkProductURLIsUnique(URL::getURLFromString($this->getPOST(self::$objProductsTableFName)))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsTableFName, new S(PRODUCTS_URL_MUST_BE_UNIQUE)); } } if ($this->checkPOST(self::$objProductsTableFStoc)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFStoc)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFStoc, new S(PRODUCTS_STOCK_MUST_BE_ENTERED)); } else { // Get some requirements; $objStock = new I((int) $this->getPOST(self::$objProductsTableFStoc)->toString()); // Do some MORE validation; if ($objStock->toInt() < 0) { $this->setErrorOnInput(self::$objProductsTableFStoc, new S(PRODUCTS_STOCK_CANNOT_BE_NEGATIVE)); } } } if ($this->checkPOST(self::$objProductsTableFPrice)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFPrice)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFPrice, new S(PRODUCTS_PRICE_MUST_BE_ENTERED)); } else { // Get some requirements; $objPrice = new I((int) $this->getPOST(self::$objProductsTableFPrice)->toString()); // Do some MORE validation; if ($objPrice->toInt() < 0) { $this->setErrorOnInput(self::$objProductsTableFPrice, new S(PRODUCTS_PRICE_CANNOT_BE_NEGATIVE)); } } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(PRODUCTS_ADD_PRODUCT))->setSQLAction(new S('update'))->setTableName(self::$objProductsTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objProductsTableFId)->setUploadDirectory(new S('products/pdf'))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE)); // Set some EXTRA data; if ($this->checkPOST(self::$objProductsTableFName)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objProductsTableFSEO, URL::getURLFromString($this->getPOST(self::$objProductsTableFName))); } // Continue; $this->setInputType(new S('submit'))->setValue(new S(PRODUCTS_ADD_PRODUCT))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objProductsTableFCategoryId)->setLabel(new S(PRODUCTS_CATEGORY)); // Category parent or brother of this one ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue; $this->setInputType(new S('text'))->setName(self::$objProductsTableFCode)->setLabel(new S(PRODUCTS_CODE))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFName)->setLabel(new S(PRODUCTS_NAME))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFURL)->setLabel(new S(PRODUCTS_URL))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFStoc)->setLabel(new S(PRODUCTS_STOCK))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFPrice)->setLabel(new S(PRODUCTS_PRICE))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setName(self::$objProductsTableFPDF)->setLabel(new S(PRODUCTS_PDF))->setFileController(new B(TRUE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objProductsTableFDescription)->setLabel(new S(PRODUCTS_DECRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'productEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Do some work; if ($this->checkPOST(self::$objProductsTableFCode)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFCode)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFCode, new S(PRODUCTS_CODE_MUST_BE_ENTERED)); } else { if ($this->getPOST(self::$objProductsTableFCode) != $this->getProductInfoById($_GET[ADMIN_ACTION_ID], self::$objProductsTableFCode)) { if ($this->checkCodeIsUnique($this->getPOST(self::$objProductsTableFCode))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsTableFCode, new S(PRODUCTS_CODE_MUST_BE_UNIQUE)); } } } } if ($this->checkPOST(self::$objProductsTableFName)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFName)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFName, new S(PRODUCTS_NAME_MUST_BE_ENTERED)); } else { if ($this->getPOST(self::$objProductsTableFName) != $this->getProductInfoById($_GET[ADMIN_ACTION_ID], self::$objProductsTableFName)) { if ($this->checkProductNameIsUnique($this->getPOST(self::$objProductsTableFName))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsTableFName, new S(PRODUCTS_NAME_MUST_BE_UNIQUE)); } if ($this->checkPOST(self::$objProductsTableFName)->toBoolean() == TRUE) { if ($this->checkProductURLIsUnique(URL::getURLFromString($this->getPOST(self::$objProductsTableFName)))->toBoolean() == FALSE) { $this->setErrorOnInput(self::$objProductsTableFName, new S(PRODUCTS_URL_MUST_BE_UNIQUE)); } } } } } if ($this->checkPOST(self::$objProductsTableFStoc)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFStoc)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFStoc, new S(PRODUCTS_STOCK_MUST_BE_ENTERED)); } else { // Get some requirements; $objStock = new I((int) $this->getPOST(self::$objProductsTableFStoc)->toString()); // Do some MORE validation; if ($objStock->toInt() < 0) { $this->setErrorOnInput(self::$objProductsTableFStoc, new S(PRODUCTS_STOCK_CANNOT_BE_NEGATIVE)); } } } if ($this->checkPOST(self::$objProductsTableFPrice)->toBoolean() == TRUE) { if ($this->getPOST(self::$objProductsTableFPrice)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objProductsTableFPrice, new S(PRODUCTS_PRICE_MUST_BE_ENTERED)); } else { // Get some requirements; $objPrice = new I((int) $this->getPOST(self::$objProductsTableFPrice)->toString()); // Do some MORE validation; if ($objPrice->toInt() < 0) { $this->setErrorOnInput(self::$objProductsTableFPrice, new S(PRODUCTS_PRICE_CANNOT_BE_NEGATIVE)); } } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setEnctype(new S('multipart/form-data'))->setFieldset(new S(PRODUCTS_EDIT_PRODUCT))->setSQLAction(new S('update'))->setTableName(self::$objProductsTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objProductsTableFId)->setName($objFormToRender)->setRedirect($objURLToGoBack)->setAJAXEnabledForm(new B(FALSE)); // Set some EXTRA data; if ($this->checkPOST(self::$objProductsTableFName)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objProductsTableFSEO, URL::getURLFromString($this->getPOST(self::$objProductsTableFName))); } // Continue; $this->setInputType(new S('submit'))->setValue(new S(PRODUCTS_EDIT_PRODUCT))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(self::$objProductsTableFCategoryId)->setLabel(new S(PRODUCTS_CATEGORY)); // Category parent or brother of this one ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue; $this->setInputType(new S('text'))->setName(self::$objProductsTableFCode)->setLabel(new S(PRODUCTS_CODE))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFName)->setLabel(new S(PRODUCTS_NAME))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFURL)->setLabel(new S(PRODUCTS_URL))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFStoc)->setLabel(new S(PRODUCTS_STOCK))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objProductsTableFPrice)->setLabel(new S(PRODUCTS_PRICE))->setContainerDiv(new B(TRUE))->setInputType(new S('file'))->setName(self::$objProductsTableFPDF)->setLabel(new S(PRODUCTS_PDF))->setFileController(new B(TRUE))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objProductsTableFDescription)->setLabel(new S(PRODUCTS_DECRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'productErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // First, delete existing images; $objProductImages = $this->_Q(_QS('doSELECT')->doToken('%what', self::$objProductsIMGTableFURL)->doToken('%table', self::$objProductsIMGTable)->doToken('%condition', new S('WHERE %objProductsIMGTableFProdId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Knowing the images, delete THEM; foreach ($objProductImages as $k => $v) { UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . '60_60_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . '100_100_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . '128_128_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . '320_240_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . '640_480_' . $v['url']); UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/images' . _S . '800_600_' . $v['url']); } // Do erase associated images; $this->_Q(_QS('doDELETE')->doToken('%table', self::$objProductsIMGTable)->doToken('%condition', new S('%objProductsIMGTableFProdId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do erase associated properties ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objProductsPropertyTable)->doToken('%condition', new S('%objProductsPropertyTableFPId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do erase associated PDF file; $objPDF = $this->getProductInfoById($_GET[ADMIN_ACTION_ID], self::$objProductsTableFPDF); if ($objPDF->toLength()->toInt() != 0) { UNLINK(DOCUMENT_ROOT . UPLOAD_DIR . _S . 'products/pdf' . _S . $objPDF); } // Do erase it ... $this->_Q(_QS('doDELETE')->doToken('%table', self::$objProductsTable)->doToken('%condition', new S('%objProductsTableFId = "%Id"'))->doToken('%Id', $_GET[ADMIN_ACTION_ID])); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); break; case 'categoryCreate': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(); // Do some work ... if ($this->checkPOST(new S('categories_show_all'))->toBoolean() == TRUE) { // Redirect to proper ... $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_SHOW_ALL)), new A(array('1'))), new S('Location')); } if ($this->checkPOST(new S('add_category_submit'))->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); $objToCheck = MPTT::mpttAddUnique($this->getPOST(new S('add_category')), new S((string) $_SERVER['REQUEST_TIME'])); if ($objToCheck->toLength()->toInt() == 0) { $this->setErrorOnInput(new S('add_category'), new S(CATEGORY_NAME_CANNOT_BE_EMPTY)); // Set the memory; $objFormHappened->switchType(); } else { if (self::$objMPTT->mpttCheckIfNodeExists($objToCheck)->toBoolean() == TRUE) { // Check to see if the group exists, and tell the user the group exists; $this->setErrorOnInput(new S('add_category'), new S(CATEGORY_ALREADY_EXISTS)); // Set the memory; $objFormHappened->switchType(); } if ($this->checkCategoryURLIsUnique(URL::getURLFromString($objToCheck))->toBoolean() == FALSE) { $this->setErrorOnInput(new S('add_category'), new S(PRODUCTS_CATEGORY_URL_MUST_BE_UNIQUE)); } } // Get AJAX; $this->getAjaxErrors(); if ($objFormHappened->toBoolean() == FALSE) { // Remember if we should add it as a brother or child; $objAddNodeAS = NULL; switch ($this->getPOST(new S('add_category_as_what'))) { case PRODUCTS_CATEGORY_CHILD: $objAddNodeAS = new S((string) MPTT::FIRST_CHILD); break; case PRODUCTS_CATEGORY_LAST_CHILD: $objAddNodeAS = new S((string) MPTT::LAST_CHILD); break; case PRODUCTS_CATEGORY_BROTHER: $objAddNodeAS = new S((string) MPTT::PREVIOUS_BROTHER); break; case PRODUCTS_CATEGORY_NEXT_BROTHER: $objAddNodeAS = new S((string) MPTT::NEXT_BROTHER); break; } // Add the node; self::$objMPTT->mpttAddNode($objToCheck, $this->getPOST(new S('add_category_parent_or_bro')), $objAddNodeAS); } } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(PRODUCTS_ADD_CATEGORY))->setName($objFormToRender); if ($this->checkPOST(new S('add_category_submit'))->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } $this->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setName(new S('categories_show_all'))->setValue(new S(PRODUCTS_SHOW_ALL_CATEGORIES))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('submit'))->setName(new S('add_category_submit'))->setValue(new S(PRODUCTS_ADD_CATEGORY))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setContainerDiv(new B(TRUE))->setName(new S('add_category'))->setLabel(new S(PRODUCTS_CATEGORY_NAME_LABEL))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_as_what'))->setLabel(new S(PRODUCTS_AS_A))->setInputType(new S('option'))->setName(new S('as_first_child'))->setLabel(new S(PRODUCTS_CATEGORY_CHILD))->setInputType(new S('option'))->setName(new S('as_last_child'))->setLabel(new S(PRODUCTS_CATEGORY_LAST_CHILD))->setInputType(new S('option'))->setName(new S('as_previous_brother'))->setLabel(new S(PRODUCTS_CATEGORY_BROTHER))->setInputType(new S('option'))->setName(new S('as_next_brother'))->setLabel(new S(PRODUCTS_CATEGORY_NEXT_BROTHER))->setInputType(new S('select'))->setContainerDiv(new B(TRUE))->setName(new S('add_category_parent_or_bro'))->setLabel(new S(PRODUCTS_OF_CATEGORY)); // Category parent or brother of this one ... foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objNameOfNode])->setValue($v[self::$objMPTT->objNameOfNode])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique(clone $v[self::$objMPTT->objNameOfNode]))); } // Continue, execute the form ... $this->setFormEndAndExecute(new B(TRUE)); break; case 'categoryEdit': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); $objFormHappened = new B(FALSE); // Do validation and error on it if something goes wrong; if ($this->checkPOST()->toBoolean() == TRUE) { // Set some requirements; $objFormHappened = new B(FALSE); $objToCheck = MPTT::mpttAddUnique($this->getPOST(self::$objCategoryTableFName), $this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFDate)); if ($objToCheck->toLength()->toInt() == 0) { // Check for empty group name, and error on it. We don't allow empty group names; $this->setErrorOnInput(self::$objCategoryTableFName, new S(PRODUCTS_CATEGORY_NAME_EMPTY)); // Set the memory; $objFormHappened->switchType(); } else { if ($this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName) != $objToCheck) { if (self::$objMPTT->mpttCheckIfNodeExists($objToCheck)->toBoolean() == TRUE) { // Check to see if the group exists; $this->setErrorOnInput(self::$objCategoryTableFName, new S(PRODUCTS_CATEGORY_ALREADY_EXISTS)); // Set the memory; $objFormHappened->switchType(); } } } // Get AJAX; $this->getAjaxErrors(); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setSQLAction(new S('update'))->setTableName(self::$objCategoryTable)->setUpdateId($_GET[ADMIN_ACTION_ID])->setUpdateField(self::$objCategoryTableFId)->setFieldset(new S(PRODUCTS_EDIT_CATEGORY)); if ($this->checkPOST(self::$objCategoryTableFName)->toBoolean() == TRUE) { $this->setExtraUpdateData(self::$objCategoryTableFSEO, URL::getURLFromString($this->getPOST(self::$objCategoryTableFName))); } if ($objFormHappened->toBoolean() == FALSE && $this->checkPOST()->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } $this->setName($objFormToRender)->setAJAXEnabledForm(new B(FALSE))->setInputType(new S('submit'))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setName(new S('edit_category_submit'))->setValue(new S(PRODUCTS_EDIT_CATEGORY))->setInputType(new S('text'))->setName(self::$objCategoryTableFName)->setMPTTRemoveUnique(new B(TRUE))->setLabel(new S(PRODUCTS_NAME))->setJSRegExpReplace(new S('[^a-zA-Z0-9 -]'))->setContainerDiv(new B(TRUE))->setInputType(new S('textarea'))->setName(self::$objCategoryTableFDescription)->setLabel(new S(PRODUCTS_DECRIPTION))->setTinyMCETextarea(new B(TRUE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; case 'categoryErase': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_ID))); // Memorize if it has kids ... $objNodeHasKids = new B(FALSE); // Check if the category has articles; if ($this->getProductCount(_S('WHERE %objProductsTableFCategoryId = "%Id"')->doToken('%Id', $_GET[ADMIN_ACTION_ID]))->toInt() != 0) { // Set an error message; self::$objAdministration->setErrorMessage(new S(PRODUCTS_CANNOT_DELETE_CATEGORY), $objURLToGoBack); } else { // Do erase the group node from the table; self::$objMPTT->mpttRemoveNode($this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName)); // Do a redirect, and get the user back where he belongs; $this->setHeaderKey($objURLToGoBack, new S('Location')); } // Break out ... break; case 'categoryMove': // Set some predefines; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION, ADMIN_ACTION_TO, ADMIN_ACTION_TYPE))); // Get names, as they are unique; $objThatIsMoved = $this->getCategoryInfoById($_GET[ADMIN_ACTION_ID], self::$objCategoryTableFName); $objWhereToMove = $this->getCategoryInfoById($_GET[ADMIN_ACTION_TO], self::$objCategoryTableFName); // Get the node subtree, that's move, make sure the node we move to ain't a child; $objMovedNodeSubTree = self::$objMPTT->mpttGetTree($objThatIsMoved); // Memorize; $objIsChild = new B(FALSE); foreach ($objMovedNodeSubTree as $k => $v) { if ($v[self::$objMPTT->objNameOfNode] == $objWhereToMove) { $objIsChild->switchType(); } } // Check if it's a child or not; if ($objIsChild->toBoolean() == TRUE) { // Set an error message; self::$objAdministration->setErrorMessage(new S(PRODUCTS_CATEGORY_CANNOT_BE_MOVED), $objURLToGoBack); } else { // Move nodes; self::$objMPTT->mpttMoveNode($objThatIsMoved, $objWhereToMove, $_GET[ADMIN_ACTION_TYPE]); $this->setHeaderKey($objURLToGoBack, new S('Location')); } // Break out ... break; case 'categoryMoveOperation': // The URL to go back too; $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_SUBPAGE)), new A(array(MANAGE_PRODUCTS))); // Do some work; $this->checkPOST()->toBoolean() == TRUE ? $objOLDCategoryId = $this->getPOST(new S('old_category_id')) : ($objOLDCategoryId = new S('0')); // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(PRODUCTS_MOVE_PRODUCTS))->setSQLAction(new S('update'))->setTableName(self::$objProductsTable)->setUpdateField(self::$objProductsTableFId)->setUpdateWhere($this->doModuleToken(_S('%objProductsTableFCategoryId = "%Id"')->doToken('%Id', $objOLDCategoryId)))->setName($objFormToRender)->setRedirect($objURLToGoBack)->setInputType(new S('submit'))->setValue(new S(PRODUCTS_MOVE_PRODUCTS))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('old_category_id'))->setLabel(new S(PRODUCTS_OLD_CATEGORY))->setContainerDiv(new B(TRUE)); // Cateories; foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Categories; $this->setInputType(new S('select'))->setName(self::$objProductsTableFCategoryId)->setLabel(new S(PRODUCTS_NEW_CATEGORY))->setContainerDiv(new B(TRUE)); foreach ($this->getCategories() as $k => $v) { $this->setInputType(new S('option'))->setName($v[self::$objMPTT->objIdField])->setValue($v[self::$objMPTT->objIdField])->setLabel(new S(str_repeat('--' . _SP, (int) $v['depth']->toString()) . MPTT::mpttRemoveUnique($v[self::$objMPTT->objNameOfNode]))); } // Continue; $this->setFormEndAndExecute(new B(TRUE)); break; case 'configurationEdit': // Do some work; if ($this->checkPOST()->toBoolean() == TRUE) { $objURLToGoBack = URL::rewriteURL(new A(array(ADMIN_ACTION)), new A(array($this->getPOST(new S('what'))))); } // Do the form, make it happen; $this->setMethod(new S('POST'))->setFieldset(new S(PRODUCTS_MANAGE_CONFIGURATION))->setName($objFormToRender); // Set redirect; if ($this->checkPOST()->toBoolean() == TRUE) { $this->setRedirect($objURLToGoBack); } // Continue; $this->setInputType(new S('submit'))->setValue(new S(ADMIN_ACTION))->setInputInfoMessage($this->getHELP($objFormToRender))->setContainerDiv(new B(TRUE))->setInputType(new S('select'))->setName(new S('what'))->setLabel(new S(PRODUCTS_CONFIG_CHOOSE))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; } }
/** * Will parse the URL into an associative array. This method will get the current URL string and parse it in an associative array * that we can then insert in the _GET superglobal to work with. It's an internal private method not used by non-core developers. * * @param I $segmentNumber The number of the segment to get from; * @return A The associative array, parsed from the URL, as key/var pairs; * @author Elena Ramona <*****@*****.**> * @copyright Under the terms of the GNU General Public License v3 * @version $Id: 09_URL.php 313 2009-10-09 13:27:52Z catalin.zamfir $ * @since Version 1.0 * @access private * @static * @final */ private static final function associativeFromURL(I $segmentNumber) { $getURLSegments = new A(array_slice(self::$objGETURLSegment->toArray(), $segmentNumber->toInt() - 1)); $i = new I(0); $lastURLVar = new S(_NONE); $returnedArray = new A(); foreach ($getURLSegments as $v) { if ($i->toInt() % 2) { $returnedArray[$lastURLVar->toString()] = $v; } else { $returnedArray[$v] = new B(FALSE); $lastURLVar->setString($v); } // Increment; $i->doInc(); } // Do return ... return $returnedArray; }
/** * Will return a string containing three lines from the PHP file that was in a debug_backtrace, by parsing the previous, current and * next line from the debugged file. It's an easy way to get the content of a file in many circumstances. Also, for EVAL'ed code, * where we actually don't have a file, we issue a default NULL string back to the calling method so execution can go on; * * @param S $codeFile The path to the file to be GeSHi'ed * @param S $codeLine The number of line (+/-1) that should be GeSHi'ed * @author Catalin Z. Alexandru <*****@*****.**> * @copyright Under the terms of the GNU General Public License v3 * @version $Id: 08_ERR.php 313 2009-10-09 13:27:52Z catalin.zamfir $ * @since Version 1.0 * @access private * @static */ private static function getDebugCodeLine(S $codeFile, I $codeLine) { // S make; $theString = new S(); // Get the file array from the passed argument; if (WIN == TRUE) { // Get the contents; if (file_exists($codeFile)) { // PHP Code: FILE; $theFileArray = file($codeFile->doToken(DOCUMENT_ROOT, _NONE)->toString(), FILE_SKIP_EMPTY_LINES); } else { // PHP Code: EVAL; return new S(_NONE); } } else { // Get the contents; if (file_exists($codeFile)) { // PHP Code: FILE; $theFileArray = file($codeFile->toString(), FILE_SKIP_EMPTY_LINES); } else { // PHP Code: EVAL; return new S(_NONE); } } // Files that are bellow 3 LINES have problems, so here's the fix; if (count($theFileArray) >= 3) { if (isset($theFileArray[$codeLine->toInt() - 2])) { $theString->setString($theFileArray[$codeLine->toInt() - 2] . $theFileArray[$codeLine->toInt() - 1] . $theFileArray[$codeLine->toInt()]); } } else { if (count($theFileArray) == 1) { $theString->setString($theFileArray[$codeLine->toInt() - 1]); } else { if (count($theFileArray) == 2) { $theString->setString($theFileArray[$codeLine->toInt() - 1] . $theFileArray[$codeLine->toInt()]); } } } // We should empty theFileArray straight away, and return the string; unset($theFileArray); return $theString; }
/** * Will render a requested widget; * * This method is used to render a widget that usually is used in the frontend part of any website done with the help of this * platform. What are widgets you ask?! Well, it's quite simple. They are pieces of PHP code, usually tied to some * configuration options that control the way the widget functions or showns; * * Usually, configured widgets have enough power to be used in any way you want or need. For most of the times, the widgets * are called in the proper section of the frontend, but this method must permit the use of widgets, independent of the place * the developer needs them; * * @param $objW The widget to render; * @return mixed Depends on the widget; */ public function renderWidget(S $objW, A $objWA = NULL) { // Make an empty array if NULL ... if ($objWA == NULL) { $objWA = new A(); } // XML & RSS: Do a switch ... switch ($objW) { case 'widgetXML': // Yo man ... woohoooooo ... foreach ($this->getApprovedAudioFiles(new S('ORDER BY %objAudioTableFUploadedDate DESC')) as $k => $v) { // Set some requirements ... $objDTE = date('Y-m-d', (int) $v[self::$objAudioTableFUploadedDate]->toString()); $objLOC = URL::staticURL(new A(array(AUDIO_ITEM_URL, FRONTEND_SECTION_URL)), new A(array($v[self::$objAudioTableFSEO], FRONTEND_AUDIO_URL))); // Get the (INNER) CHILD of every young SEO freak ... $objURL = $objWA['objXML']->addCHILD(Frontend::XML_URL); // Set the XML Sitemap kids ... $objURL->addCHILD(Frontend::XML_LOCATION, $objLOC); $objURL->addCHILD(Frontend::XML_LAST_MOD, $objDTE); $objURL->addCHILD(Frontend::XML_CHANGE_FREQ, self::XML_SITEMAP_FREQUENCY); $objURL->addCHILD(Frontend::XML_PRIORITY, self::XML_SITEMAP_PRIORITY); } // BK; break; case 'widgetRSS': // Yo man ... woohoooooo ... if ($_GET[FRONTEND_FEED_URL] == __CLASS__) { // Get'em 30 ... foreach ($this->getApprovedAudioFiles(new S('ORDER BY %objAudioTableFUploadedDate DESC LIMIT 0, 30')) as $k => $v) { // Set some requirements ... $objDTE = date(DATE_RFC822, (int) $v[self::$objAudioTableFUploadedDate]->toString()); $objLOC = URL::staticURL(new A(array(AUDIO_ITEM_URL, FRONTEND_SECTION_URL)), new A(array($v[self::$objAudioTableFSEO], FRONTEND_AUDIO_URL))); $objTTL = $v[self::$objAudioTableFTitle]->appendString(_DCSP)->appendString($v[self::$objAudioTableFArtist])->appendString(_DCSP)->appendString($v[self::$objAudioTableFAlbum]); $objDSC = $v[self::$objAudioTableFDescription]->entityEncode(ENT_QUOTES)->entityDecode(ENT_QUOTES)->stripTags(); // Get the (INNER) CHILD of every young SEO freak ... $objURL = $objWA['objXML']->addCHILD(Frontend::RSS_ITEM); // Set the RSS kids ... $objURL->addCHILD(Frontend::RSS_TITLE, $objTTL); $objURL->addCHILD(Frontend::RSS_LINK, $objLOC); $objURL->addCHILD(Frontend::RSS_GUID, $objLOC); $objURL->addCHILD(Frontend::RSS_PUBLISHED_DATE, $objDTE); $objURL->addCHILD(Frontend::RSS_DESCRIPTION, $objDSC); } } // BK; break; } // HTML: Do a switch ... switch ($objW) { case 'widgetCategoryList': // Set some requirements ... if (isset($objWA['cache_file'])) { // Take the input; $objCacheFile = $objWA['cache_file']; } else { // Do cache me ... $objCacheFile = new B(TRUE); } if (isset($objWA['cache_time'])) { // Get the cache time from me; $objCacheTime = $objWA['cache_time']; } else { // Do a cache for: 6 hours; $objCacheTime = new I(60 * 60 * 6); } // Set the template file ... if ($cId = TPL::tpIni($tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . TPL_EXTENSION), $objCacheTime, $objCacheFile)) { // Get the category to start from ... if (isset($objWA['start_from_category'])) { // Get the category LIST; $objCategoryList = $this->getCategories(NULL, $objWA['start_from_category']); } else { // Get the category LIST; $objCategoryList = $this->getCategories(NULL, NULL); } // Set the template file ... TPL::tpSet($objCategoryList, new S('objCategoryList'), $tpF); TPL::tpSet($objWA, new S('objWidgetArray'), $tpF); TPL::tpSet($this, new S('AUD'), $tpF); TPL::tpExe($tpF); TPL::tpEnd($cId); } // BK; break; case 'widgetList': // Check some needed requirements ... if ($_GET[FRONTEND_SECTION_URL] == FRONTEND_AUDIO_URL) { // Set some requirements ... $objPag = isset($_GET[AUDIO_PAGE_URL]) ? $_GET[AUDIO_PAGE_URL] : new S((string) 1); $objPag = new I((int) $objPag->toString()); // Fixes for a bugged user ... if ($objPag->toInt() == 0) { // Make the proper header, at first ... $this->setHeaderStr(new S(HDR::HEADER_404_NOT_FOUND)); // Give me back my free hardcore, Quoth the server, '404' ... $this->setHeaderKey(URL::staticURL(new A(array(FRONTEND_ERROR_URL)), new A(array('404'))), new S('Location')); } else { // Make it a string again ... $objPag = new S((string) $objPag->toInt()); } // Get your switches on ... if (isset($_GET[AUDIO_ITEM_URL])) { // Check that the article exists, before doing anything stupid ... if ($this->checkAudioFileURLIsUnique($objURL = $_GET[AUDIO_ITEM_URL])->toBoolean() == TRUE) { // Make the proper header, at first ... $this->setHeaderStr(new S(HDR::HEADER_404_NOT_FOUND)); // Give me back my free hardcore, Quoth the server, '404' ... $this->setHeaderKey(URL::staticURL(new A(array(FRONTEND_ERROR_URL)), new A(array('404'))), new S('Location')); } else { // Make me SEO ... yah! TPL::manageTTL($objTTL = $this->getAudioFileInfoByURL($objURL, self::$objAudioTableFTitle)); TPL::manageTTL($objART = $this->getAudioFileInfoByURL($objURL, self::$objAudioTableFArtist)); TPL::manageTTL($objALB = $this->getAudioFileInfoByURL($objURL, self::$objAudioTableFAlbum)); // SEO my category, little one ... TPL::manageTTL($objCAT = MPTT::mpttRemoveUnique($this->getCategoryInfoById($this->getAudioFileInfoByURL($objURL, self::$objAudioTableFCategoryId), self::$objCategoryTableFName))); // Get the published date ... we need it; $objPBL = new S(date(self::$objFrontend->STG->getConfigKey(new S('settings_default_date_format')), (int) $this->getAudioFileInfoByURL($objURL, self::$objAudioTableFUploadedDate)->toString())); // Get the keywords ... $objKEY = $this->getAudioFileInfoByURL($objURL, self::$objAudioTableFDescription)->entityDecode(ENT_QUOTES)->stripTags(); // Get the description ... $objDSC = $this->getAudioFileInfoByURL($objURL, self::$objAudioTableFDescription)->entityDecode(ENT_QUOTES)->stripTags(); // Cut it down to size ... if ($objDSC->toLength()->toInt() > META_DESCRIPTION_MAX) { $objDSC->doSubStr(0, META_DESCRIPTION_MAX)->appendString(_SP)->appendString(_DTE); } if ($objKEY->toLength()->toInt() > META_DESCRIPTION_MAX) { $objKEY->doSubStr(0, META_DESCRIPTION_MAX)->appendString(_SP)->appendString(_DTE); } // Only description if it's bigger ... if ($objDSC->toLength()->toInt() != 0) { $objDSC = $objDSC->prependString($objWA['audio_description'])->prependString(', '); } // Get the description ... but prepend it with the Title, Artist, Album ... $objDSC->prependString($objPBL)->prependString($objWA['audio_uploaded_at'])->prependString(', ')->prependString($objCAT)->prependString($objWA['audio_genre'])->prependString(', ')->prependString($objALB)->prependString($objWA['audio_album'])->prependString(', ')->prependString($objART)->prependString($objWA['audio_artist'])->prependString(', ')->prependString($objTTL)->prependString($objWA['audio_title']); // Add them LYRICS ... if ($this->getAudioFileInfoByURL($objURL, self::$objAudioTableFLyrics)->toLength()->toInt() != 0) { // Yes ... $objHasLrc = new S('Da'); } else { // Nop ... $objHasLrc = new S('Nu'); } // Add them DESCRIPTIONS ... if ($this->getAudioFileInfoByURL($objURL, self::$objAudioTableFDescription)->toLength()->toInt() != 0) { // Yes ... $objHasDsc = new S('Da'); } else { // Nop ... $objHasDsc = new S('Nu'); } // Modify the DESCRIPTION ... $objDSC->appendString(', ')->appendString($objWA['audio_lyrics'])->appendString($objHasLrc); $objDSC->appendString(', ')->appendString($objWA['audio_description'])->appendString($objHasDsc); // Add the TAG, as we have description ... TPL::manageTAG(new S('description'), $objDSC->entityEncode(ENT_QUOTES)); // Add the TAG, as we have keywords ... if ($objKEY->toLength()->toInt() != 0) { TPL::manageTAG(new S('keywords'), $objKEY->eregReplace('[^a-zA-Z0-9 -]', _NONE)->eregReplace(_SP, ', ')->eregReplace(', ,', ',')->entityEncode(ENT_QUOTES)); } // Set some requirements ... $objPathToItem = self::$objMPTT->mpttGetSinglePath($this->getCategoryInfoById($this->getAudioFileInfoByURL($objURL, self::$objAudioTableFCategoryId), self::$objCategoryTableFName)); // Update them views ... $this->_Q(_QS('doUPDATE')->doToken('%table', self::$objAudioTable)->doToken('%condition', new S('%objAudioTableFViews = %objAudioTableFViews + 1 WHERE %objAudioTableFSEO = "%Id"'))->doToken('%Id', $objURL)); // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . '-Item' . TPL_EXTENSION); TPL::tpSet($objPathToItem, new S('objPathToItem'), $tpF); TPL::tpSet($objWA, new S('objWidgetArray'), $tpF); TPL::tpSet($objURL, new S('objURL'), $tpF); TPL::tpSet($this->ATH, new S('ATH'), $tpF); TPL::tpSet($this->STG, new S('STG'), $tpF); TPL::tpSet($this, new S('AUD'), $tpF); TPL::tpExe($tpF); } } else { if (isset($_GET[AUDIO_CATEGORY_URL])) { // Check that the category exists, before doing anything stupid ... if ($this->checkCategoryURLIsUnique($objCat = $_GET[AUDIO_CATEGORY_URL])->toBoolean() == TRUE) { // Make the proper header, at first ... $this->setHeaderStr(new S(HDR::HEADER_404_NOT_FOUND)); // Give me back my free hardcore, Quoth the server, '404' ... $this->setHeaderKey(URL::staticURL(new A(array(FRONTEND_ERROR_URL)), new A(array('404'))), new S('Location')); } else { // Do me SEO, yah baby! ... TPL::manageTTL(MPTT::mpttRemoveUnique($this->getCategoryInfoByURL($objCat, self::$objCategoryTableFName))); // Make a condition to avoid dup. title tags on different pages ... if ((int) $objPag->toString() >= 1 && isset($_GET[AUDIO_PAGE_URL])) { TPL::manageTTL(_S(AUDIO_PAGE_URL)->appendString(_SP)->appendString($objPag)); } // Set some requirements ... $objCnt = $this->getApprovedAudioFileCountForCategoryURL($objCat); $objArt = $this->getApprovedAudioFilesByCategoryURLAndPage($objCat, $objPag); } } else { if (isset($_GET[AUDIO_SEARCH_URL])) { // Get audio by page ... $objCnt = $this->getApprovedAudioFileCountForSearch($_GET[AUDIO_SEARCH_URL]); $objArt = $this->getApprovedAudioFilesByPageAndSearch($objPag, $_GET[AUDIO_SEARCH_URL]); } else { // Do me SEO, yah baby! ... TPL::manageTTL(_S(FRONTEND_AUDIO_URL)); // Make a condition to avoid dup. title tags on different pages ... if ((int) $objPag->toString() >= 1 && isset($_GET[AUDIO_PAGE_URL])) { TPL::manageTTL(_S(AUDIO_PAGE_URL)->appendString(_SP)->appendString($objPag)); } // Set some requirements ... $objArt = $this->getApprovedAudioFilesByPage($objPag); $objCnt = $this->getApprovedAudioFileCount(); } } // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . TPL_EXTENSION); TPL::tpSet($objWA, new S('objWidgetArray'), $tpF); TPL::tpSet($objArt, new S('objAr'), $tpF); TPL::tpExe($tpF); // Set them paginations ... if ($objCnt->toInt() > (int) self::$objItemsPerPage->toString()) { self::$objFrontend->setPagination($objCnt, new I((int) self::$objItemsPerPage->toString())); } } } else { // Do the biggest error on the PLANET ... self::renderScreenOfDeath(new S(__CLASS__), new S(AUDIO_NEED_PROPER_SECTION), new S(AUDIO_NEED_PROPER_SECTION_FIX)); } // BK; break; case 'widgetComments': // Check if we have the proper URL enabled ... if (isset($_GET[AUDIO_ITEM_URL])) { // Check if the comments are enabled ... if ($this->getAudioFileInfoByURL($objURL = $_GET[AUDIO_ITEM_URL], self::$objAudioTableFCanComment) == 'Y') { // Set some requirements ... $objCommentIsOk = new S(); $objComments = $this->getApprovedCommentsByAudioFileURL($_GET[AUDIO_ITEM_URL], new S('ORDER BY %objCommentsTableFDate DESC')); // Check for status ... if (isset($_GET[AUDIO_STATUS_URL])) { if ($_GET[AUDIO_STATUS_URL] == AUDIO_STATUS_OK_URL) { $objCommentIsOk = new S($objWA['comment_has_been_added']); } } // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . TPL_EXTENSION); TPL::tpSet($objCommentIsOk, new S('objCommentIsOk'), $tpF); TPL::tpSet($objComments, new S('objComments'), $tpF); TPL::tpSet($this->STG, new S('STG'), $tpF); TPL::tpSet($this->ATH, new S('ATH'), $tpF); TPL::tpExe($tpF); // Set some requirements ... $objShowFrm = new B(TRUE); // Check if we're allowed to show the comment form ... if ($this->getConfigKey(new S('audio_settings_audio_auth_to_comment')) == 'Y') { if ($this->ATH->checkIfUserIsLoggedIn()->toBoolean() == TRUE) { // To show ... or not ... $objShowFrm = new B(TRUE); } else { // to show ... or not ... $objShowFrm = new B(FALSE); } } // Do some work ... if ($objShowFrm->toBoolean() == TRUE) { if ($this->checkPOST(self::$objCommentsTableFComment)->toBoolean() == TRUE) { if ($this->getPOST(self::$objCommentsTableFComment)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objCommentsTableFComment, new S($objWA['error_no_comment'])); } } if ($this->checkPOST(self::$objCommentsTableFName)->toBoolean() == TRUE) { if ($this->getPOST(self::$objCommentsTableFName)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objCommentsTableFName, new S($objWA['error_no_name'])); } } if ($this->checkPOST(self::$objCommentsTableFEML)->toBoolean() == TRUE) { if ($this->getPOST(self::$objCommentsTableFEML)->toLength()->toInt() == 0) { $this->setErrorOnInput(self::$objCommentsTableFEML, new S($objWA['error_no_email'])); } } // Make the form ... (ya, outside the box ...); $this->setMethod(new S('POST'))->setFieldset(new S($objWA['comment_add']))->setSQLAction(new S('update'))->setTableName(self::$objCommentsTable)->setUpdateId(new S('#nextTableAutoIncrement'))->setUpdateField(self::$objCommentsTableFId); if ($this->checkPOST(self::$objCommentsTableFComment)->toBoolean() == TRUE) { $this->setRedirect(URL::rewriteURL(new A(array(AUDIO_STATUS_URL)), new A(array(AUDIO_STATUS_OK_URL)))); } $this->setName(new S('commentForm'))->setExtraUpdateData(self::$objCommentsTableFDate, new S((string) time()))->setExtraUpdateData(self::$objCommentsTableFAudioFileId, $this->getAudioFileInfoByURL($_GET[AUDIO_ITEM_URL], self::$objAudioTableFId))->setInputType(new S('submit'))->setValue(new S($objWA['comment_submit']))->setName(new S('submit'))->setContainerDiv(new B(TRUE)); // Check if the user is authenticated ... if ($this->ATH->checkIfUserIsLoggedIn()->toBoolean() == TRUE) { // Set the RUId; $this->setExtraUpdateData(self::$objCommentsTableFRUId, $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFId)); } else { // Set the other infos; $this->setInputType(new S('text'))->setName(self::$objCommentsTableFName)->setLabel(new S($objWA['comment_name']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objCommentsTableFEML)->setLabel(new S($objWA['comment_email']))->setContainerDiv(new B(TRUE))->setInputType(new S('text'))->setName(self::$objCommentsTableFURL)->setLabel(new S($objWA['comment_website']))->setContainerDiv(new B(TRUE)); } // Continue ... $this->setInputType(new S('textarea'))->setName(self::$objCommentsTableFComment)->setLabel(new S($objWA['comment_message']))->setRows(new S('10'))->setTinyMCETextarea(new B(TRUE))->setClass(new S('tinyMCESimple'))->setContainerDiv(new B(TRUE)); // Notify ... if ($this->checkFormHasErrors()->toBoolean() == FALSE && $this->checkPOST(self::$objCommentsTableFComment)->toBoolean() == TRUE) { if ($this->ATH->checkIfUserIsLoggedIn()->toBoolean() == TRUE) { // Query the authentication ... $objUSR = $this->ATH->getCurrentUserInfoById(Authentication::$objAuthUsersTableFUName); } else { // Or trust the FORM ... $objUSR = $this->getPOST(self::$objCommentsTableFName); } // Go and SP ... MAIL me ... $objMAIL = new MAIL(); $objMAIL->doMAIL($this->STG->getConfigKey(new S('settings_website_notification_email')), new S(AUDIO_COMMENT_HAS_BEEN_POSTED), $this->getHELP(new S('widgetCommentsCommentPosted'))->doToken('%t', $this->getAudioFileInfoByURL($objURL, self::$objAudioTableFTitle))->doToken('%a', $this->getAudioFileInfoByURL($objURL, self::$objAudioTableFArtist))->doToken('%b', $this->getAudioFileInfoByURL($objURL, self::$objAudioTableFAlbum))->doToken('%u', $objUSR)); // Go deeper and notify them users ... $objCommentsForItem = $this->getCommentsByAudioFileURL($objURL); foreach ($objCommentsForItem as $k => $v) { $objMAIL = new MAIL(); $objMAIL->doMAIL($this->ATH->getUserInfoById($v[self::$objCommentsTableFRUId], Authentication::$objAuthUsersTableFEML), new S(AUDIO_COMMENT_HAS_BEEN_POSTED), $this->getHELP(new S('widgetCommentsCommentPostedFrontend'))->doToken('%t', $this->getAudioFileInfoByURL($objURL, self::$objAudioTableFTitle))->doToken('%a', $this->getAudioFileInfoByURL($objURL, self::$objAudioTableFArtist))->doToken('%b', $this->getAudioFileInfoByURL($objURL, self::$objAudioTableFAlbum))->doToken('%u', $objUSR)->doToken('%k', URL::rewriteURL())); } } // End form and execute ... $this->setFormEndAndExecute(new B(TRUE)); } } } // BK; break; case 'widgetUploadForm': // Ya, checking the STATUS ... if (isset($_GET[AUDIO_STATUS_URL])) { // Get me going my dear one ... $objConfKey = new S('audio_settings_audio_form_page_status_ok'); $objShowFrm = new B(FALSE); } else { // Get me going my dear one ... $objConfKey = new S('audio_settings_audio_form_page'); $objShowFrm = new B(TRUE); } // If we're NOT authenticated ... bang, you're DEAD ... if ($this->ATH->checkIfUserIsLoggedIn()->toBoolean() == FALSE) { // Get me going my dear one ... $objConfKey = new S('audio_settings_audio_form_not_authenticated'); $objShowFrm = new B(FALSE); } // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . TPL_EXTENSION); TPL::tpSet($this->getConfigKey($objConfKey), new S('objContent'), $tpF); TPL::tpSet($objWA, new S('objWidgetArray'), $tpF); TPL::tpSet($objShowFrm, new S('objShowForm'), $tpF); TPL::tpSet($this, new S('AUD'), $tpF); TPL::tpExe($tpF); break; case 'widgetLastN': // Do CACHE ... if ($cId = TPL::tpIni($tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . TPL_EXTENSION), new I(180))) { // Set the template file ... TPL::tpSet($this->getApprovedAudioFiles(_S('ORDER BY %objAudioTableFUploadedDate DESC LIMIT 0, %UpperLimit')->doToken('%UpperLimit', $objWA['audio_n_count'])), new S('objLastN'), $tpF); TPL::tpSet($objWA, new S('objWidgetArray'), $tpF); TPL::tpSet($this, new S('AUD'), $tpF); TPL::tpExe($tpF); TPL::tpEnd($cId); } // BK; break; case 'widgetRandomN': // Do CACHE ... if ($cId = TPL::tpIni($tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . TPL_EXTENSION), new I(180))) { // Set the template file ... TPL::tpSet($this->getApprovedAudioFiles(_S('ORDER BY RAND() LIMIT 0, %UpperLimit')->doToken('%UpperLimit', $objWA['audio_n_count'])), new S('objRandomN'), $tpF); TPL::tpSet($objWA, new S('objWidgetArray'), $tpF); TPL::tpSet($this, new S('AUD'), $tpF); TPL::tpExe($tpF); TPL::tpEnd($cId); } // BK; break; case 'widgetRelatedN': // Do CACHE ... if ($cId = TPL::tpIni($tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . TPL_EXTENSION), new I(180))) { // Set the template file ... TPL::tpSet($this->getApprovedAudioFiles(_S('AND %objAudioTableFArtist LIKE "%Id" LIMIT 0, %UpperLimit')->doToken('%Id', $this->getAudioFileInfoByURL($objWA['audio_song_item'], self::$objAudioTableFArtist))->doToken('%UpperLimit', $objWA['audio_n_count'])), new S('objRandomN'), $tpF); TPL::tpSet($objWA, new S('objWidgetArray'), $tpF); TPL::tpSet($this, new S('AUD'), $tpF); TPL::tpExe($tpF); TPL::tpEnd($cId); } // BK; break; case 'widgetTopN': // Do CACHE ... if ($cId = TPL::tpIni($tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . TPL_EXTENSION), new I(180))) { // Set the template file ... TPL::tpSet($this->getApprovedAudioFiles(_S('ORDER BY %objAudioTableFViews DESC LIMIT 0, %UpperLimit')->doToken('%UpperLimit', $objWA['audio_n_count'])), new S('objRandomN'), $tpF); TPL::tpSet($objWA, new S('objWidgetArray'), $tpF); TPL::tpSet($this, new S('AUD'), $tpF); TPL::tpExe($tpF); TPL::tpEnd($cId); } // BK; break; case 'widgetRandomItem': // Do some work ... if ($this->checkPOST(new S('search_random_item'))->toBoolean() == TRUE) { // Get me there ... quick ... $this->setHeaderKey(URL::staticURL(new A(array(AUDIO_ITEM_URL, FRONTEND_SECTION_URL)), new A(array($this->getApprovedAudioFiles(_S('ORDER BY RAND() LIMIT 1'))->offsetGet(0)->offsetGet(self::$objAudioTableFSEO), FRONTEND_AUDIO_URL))), new S('Location')); } // Do the form, make it happen ... $this->setMethod(new S('POST'))->setName(new S('audioRandomItem'))->setInputType(new S('submit'))->setName(new S('search_random_item'))->setValue(new S($objWA['audio_random']))->setContainerDiv(new B(TRUE))->setFormEndAndExecute(new B(TRUE)); break; } }
/** * Will check if the file path cache time expired or not, returning a boolean true or false. This method is used by core * developers to check if the need to refresh the cache or not. The cache is refreshed upon a given time, time specified by the * specific project developer according to his needs; * * @param string $cacheFile Path to the executed .tp file * @param integer $templateCacheTime What time was the file cached, so we can calculate the difference * @return mixed Will return an integer, or boolean false if it can't determine the cache time * @author Catalin Z. Alexandru <*****@*****.**> * @copyright Under the terms of the GNU General Public License v3 * @version $Id: 10_TPL.php 315 2009-10-11 07:11:31Z catalin.zamfir $ * @since Version 1.0 * @access private * @static */ private static function checkCacheFile(FilePath $cacheFile, I $templateCacheTime) { if ($cacheFile->checkPathExists()->toBoolean()) { return $cacheFile->getPathInfo('mtime')->toInt() + $templateCacheTime->toInt() > $_SERVER['REQUEST_TIME'] ? new B(TRUE) : new B(FALSE); } else { // Do return ... return new B(FALSE); } }
/** * Will unset the given key; * * This method, after we are done with our information will clear the cookie information stored at that key. This for example, * in the authentication module will deauthenticate the user. Other uses can be thought of in other modules;s * * @param S $objKey The key to unset; * @return boolean Will return true if it was able to unset the key; */ public function unSetKey(S $objKey) { switch ($this->objObjectCookie->getConfigKey(new S('authentication_cookie_store_type'))) { case 'cookie': // Trigger the browser cookie cleaning mechanism; $expTme = new I($_SERVER['REQUEST_TIME'] - 31556926); // Re-set the cookie; setcookie($this->objProjectString . _U . $this->objObjectCookie->getObjectCLASS() . _U . $objKey, new S(), $expTme->toInt(), new S('/')); break; case 'session': // Do unset ... unset($_SESSION[$this->objProjectString->toString()][$this->objObjectCookie->getObjectCLASS()->toString()][$objKey->toString()]); break; default: // Make an error on it, cause yeah ... self::renderScreenOfDeath(new S(__CLASS__), new S(SESSION_TYPE_ERROR), new S(SESSION_TYPE_ERROR_FIX)); break; } // Do return ... return new B(TRUE); }
/** * Will return an array (associative by default), containing a row of the MySQL result. This method will provide access to the * MySQL result returned as an array that can then be processed; * * @param R $queryResourceSet The resource set to be fetched * @param I $queryFetchMode One of the mysql_fetch_array () fetch modes, as an integer * @author Catalin Z. Alexandru <*****@*****.**> * @copyright Under the terms of the GNU General Public License v3 * @version $Id: 11_SQL.php 313 2009-10-09 13:27:52Z catalin.zamfir $ * @since Version 1.0 * @access private * @static */ private static function getQueryResultRow(R $queryResourceSet, I $queryFetchMode = NULL) { if ($queryFetchMode == NULL) { $queryFetchMode = new I(MYSQL_ASSOC); $temporaryArray = mysql_fetch_array($queryResourceSet->toResource(), $queryFetchMode->toInt()); } else { // Just return, taking the queryFetchMode, from the passed second parameter. We trust the developer!; $temporaryArray = mysql_fetch_array($queryResourceSet->toResource(), $queryFetchMode->toInt()); } if ($temporaryArray != FALSE) { foreach ($temporaryArray as $k => $v) { $v != NULL ? $temporaryArray[$k] = new S($v) : ($temporaryArray[$k] = new S(_NONE)); } // Return the new A, passed from mysql_fetch_array; return new A($temporaryArray); } else { // DO NOT MOVE. Set here to stop looping ... return FALSE; } }
/** * Will render a requested widget; * * This method is used to render a widget that usually is used in the frontend part of any website done with the help of this * platform. What are widgets you ask?! Well, it's quite simple. They are pieces of PHP code, usually tied to some * configuration options that control the way the widget functions or showns; * * Usually, configured widgets have enough power to be used in any way you want or need. For most of the times, the widgets * are called in the proper section of the frontend, but this method must permit the use of widgets, independent of the place * the developer needs them; * * @param $objWidgetToRender The widget to render; * @return mixed Depends on the widget; */ public function renderWidget(S $objW, A $objWA = NULL) { // Make an empty array if NULL ... if ($objWA == NULL) { $objWA = new A(); } // XML & RSS: Do a switch ... switch ($objW) { case 'widgetXML': // Yo man ... woohoooooo ... foreach ($this->getLyrics(_S('ORDER BY %objLyricsTableFDateAdded DESC LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', ((int) $objWA['objId']->toString() - 1) * 25000)->doToken('%UpperLimit', 25000)) as $k => $v) { // Set some requirements ... $objDTE = date('Y-m-d', (int) $v[self::$objLyricsTableFDateAdded]->toString()); $objLOC = URL::staticURL(new A(array(LYRICS_ITEM_URL, FRONTEND_SECTION_URL)), new A(array($v[self::$objLyricsTableFSEO], FRONTEND_LYRICS_URL))); // Get the (INNER) CHILD of every young SEO freak ... $objURL = $objWA['objXML']->addCHILD(Frontend::XML_URL); // Set the XML Sitemap kids ... $objURL->addCHILD(Frontend::XML_LOCATION, $objLOC); $objURL->addCHILD(Frontend::XML_LAST_MOD, $objDTE); $objURL->addCHILD(Frontend::XML_CHANGE_FREQ, self::XML_SITEMAP_FREQUENCY); $objURL->addCHILD(Frontend::XML_PRIORITY, self::XML_SITEMAP_PRIORITY); } // BK; break; case 'widgetRSS': // Yo man ... woohoooooo ... if ($_GET[FRONTEND_FEED_URL] == __CLASS__) { // Get'em 30 ... foreach ($this->getApprovedAudioFiles(new S('ORDER BY %objAudioTableFUploadedDate DESC LIMIT 0, 30')) as $k => $v) { // Set some requirements ... $objDTE = date(DATE_RFC822, (int) $v[self::$objAudioTableFUploadedDate]->toString()); $objLOC = URL::staticURL(new A(array(AUDIO_ITEM_URL, FRONTEND_SECTION_URL)), new A(array($v[self::$objAudioTableFSEO], FRONTEND_AUDIO_URL))); $objTTL = $v[self::$objAudioTableFTitle]->appendString(_DCSP)->appendString($v[self::$objAudioTableFArtist])->appendString(_DCSP)->appendString($v[self::$objAudioTableFAlbum]); $objDSC = $v[self::$objAudioTableFDescription]->entityEncode(ENT_QUOTES)->entityDecode(ENT_QUOTES)->stripTags(); // Get the (INNER) CHILD of every young SEO freak ... $objURL = $objWA['objXML']->addCHILD(Frontend::RSS_ITEM); // Set the RSS kids ... $objURL->addCHILD(Frontend::RSS_TITLE, $objTTL); $objURL->addCHILD(Frontend::RSS_LINK, $objLOC); $objURL->addCHILD(Frontend::RSS_GUID, $objLOC); $objURL->addCHILD(Frontend::RSS_PUBLISHED_DATE, $objDTE); $objURL->addCHILD(Frontend::RSS_DESCRIPTION, $objDSC); } } // BK; break; } // Do a switch ... switch ($objW) { case 'widgetList': // Check some needed requirements ... if ($_GET[FRONTEND_SECTION_URL] == FRONTEND_LYRICS_URL) { // Set some requirements ... $objPag = isset($_GET[LYRICS_PAGE_URL]) ? $_GET[LYRICS_PAGE_URL] : new S((string) 1); $objPag = new I((int) $objPag->toString()); // Fixes for a bugged user ... if ($objPag->toInt() == 0) { // Make the proper header, at first ... $this->setHeaderStr(new S(HDR::HEADER_404_NOT_FOUND)); // Give me back my free hardcore, Quoth the server, '404' ... $this->setHeaderKey(URL::staticURL(new A(array(FRONTEND_ERROR_URL)), new A(array('404'))), new S('Location')); } else { // Make it a string again ... $objPag = new S((string) $objPag->toInt()); } // Get your switches on ... if (isset($_GET[LYRICS_ITEM_URL])) { // Check that the article exists, before doing anything stupid ... if ($this->checkLyricURLIsUnique($objURL = $_GET[LYRICS_ITEM_URL])->toBoolean() == TRUE) { // Make the proper header, at first ... $this->setHeaderStr(new S(HDR::HEADER_404_NOT_FOUND)); // Give me back my free hardcore, Quoth the server, '404' ... $this->setHeaderKey(URL::staticURL(new A(array(FRONTEND_ERROR_URL)), new A(array('404'))), new S('Location')); } else { // Make me SEO ... yah! TPL::manageTTL($objTTL = $this->getLyricInfoByURL($objURL, self::$objLyricsTableFTitle)); TPL::manageTTL($objART = $this->getLyricInfoByURL($objURL, self::$objLyricsTableFArtist)); TPL::manageTTL($objALB = $this->getLyricInfoByURL($objURL, self::$objLyricsTableFAlbum)); TPL::manageTAG(new S('description'), new S('Titlu: ' . $objTTL . ', Artist: ' . $objART . ', Album: ' . $objALB . ', Lyrics: ' . $this->getLyricInfoByURL($objURL, self::$objLyricsTableFLyrics)->entityDecode(ENT_QUOTES)->doToken('<br />', _SP)->stripTags()->doSubStr(0, 128))); // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . '-Item' . TPL_EXTENSION); TPL::tpSet($objWA, new S('objWidgetArray'), $tpF); TPL::tpSet($objURL, new S('objURL'), $tpF); TPL::tpSet($this->ATH, new S('ATH'), $tpF); TPL::tpSet($this->STG, new S('STG'), $tpF); TPL::tpSet($this, new S('LRQ'), $tpF); TPL::tpExe($tpF); } } else { if (isset($_GET[LYRICS_SEARCH_URL])) { // Get audio by page ... $objCnt = $this->getLyricCountForSearch($_GET[LYRICS_SEARCH_URL]); $objArt = $this->getLyricsByPageAndSearch($objPag, $_GET[LYRICS_SEARCH_URL]); } else { // Do me SEO, yah baby! ... TPL::manageTTL(_S(FRONTEND_LYRICS_URL)); // Make a condition to avoid dup. title tags on different pages ... if ((int) $objPag->toString() >= 1 && isset($_GET[LYRICS_PAGE_URL])) { TPL::manageTTL(_S(LYRICS_PAGE_URL)->appendString(_SP)->appendString($objPag)); } // Set some requirements ... $objArt = $this->getLyricsByPage($objPag); $objCnt = $this->getLyricCount(); } // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . TPL_EXTENSION); TPL::tpSet($objWA, new S('objWidgetArray'), $tpF); TPL::tpSet($objArt, new S('objAr'), $tpF); TPL::tpSet($this, new S('LRQ'), $tpF); TPL::tpExe($tpF); // Set them paginations ... if ($objCnt->toInt() > (int) self::$objItemsPerPage->toString()) { self::$objFrontend->setPagination($objCnt, new I((int) self::$objItemsPerPage->toString())); } } } else { // Do the biggest error on the PLANET ... self::renderScreenOfDeath(new S(__CLASS__), new S(LYRICS_NEED_PROPER_SECTION), new S(LYRICS_NEED_PROPER_SECTION_FIX)); } // BK; break; case 'widgetTopN': if ($objWA['type'] == 1) { $objArt = $this->_Q(_QS('doSELECT')->doToken('%what', new S('%objLyricsTableFArtist, COUNT(%objLyricsTableFTitle) as count'))->doToken('%table', self::$objLyricsTable)->doToken('%condition', new S('GROUP BY %objLyricsTableFArtist ORDER BY count DESC LIMIT 0, 30'))); } else { $objArt = $this->_Q(_QS('doSELECT')->doToken('%what', new S('%objLyricsTableFAlbum, COUNT(%objLyricsTableFTitle) as count'))->doToken('%table', self::$objLyricsTable)->doToken('%condition', new S('GROUP BY %objLyricsTableFAlbum ORDER BY count DESC LIMIT 0, 30'))); } // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . $objW . TPL_EXTENSION); TPL::tpSet($objWA, new S('objWidgetArray'), $tpF); TPL::tpSet($objArt, new S('objAr'), $tpF); TPL::tpSet($this, new S('LRQ'), $tpF); TPL::tpExe($tpF); break; case 'widgetSearch': $this->renderForm(new S('widgetSearch')); break; } }
/** * Will return an unique code, based on a combination of sha1 and uniqid. First of ALL: do not relly on this method to return * the same hash code again and again, as for a combination of sha1 (2^64) it will never return the same code twice upon a large * field of possible situations. This method is rarelly used but has been promoted as a CORE method to generate a hased unique code * for different purposes (weak encryption, random things, etc.); * <code> * <?php * // Get an unique code * echo EXE::getUniqueCode (); # Will return a sha1 (uniqid ()); * ?> * </code> * * @param I $objLength The length of the string to get * @return S The code, stripped down to the desired length * @author Catalin Z. Alexandru <*****@*****.**> * @copyright Under the terms of the GNU General Public License v3 * @version $Id: 02_EXE.php 313 2009-10-09 13:27:52Z catalin.zamfir $ * @since Version 2.0 * @access public * @static * @final */ public static final function getUniqueCode(I $objLength = NULL) { // Get the code, from an md5, of uniqid; $objCode = new S(sha1(uniqid(rand(), TRUE))); // Either get it FULL, or just first N chars; if ($objLength == NULL) { // Return the code; return $objCode; } else { // Check something ... if ($objLength->toInt() > $objCode->toLength()->toInt()) { // Return the code; return $objCode; } else { // Trim it down to size ... return $objCode->doSubStr(0, $objLength->toInt()); } } }