public static function make_token($contentType, $objectId) { $ctype = ContentType::get_for_model($contentType); $_instance = new self(); $_instance->token = md5(uniqid(rand(), true)); $_instance->status = self::STATUS_NEW; $_instance->expires = date('Y-m-d H:i:s', time() + 7 * 24 * 60 * 60); $_instance->object_id = $objectId; $_instance->ContentType = $ctype; $_instance->save(); return $_instance; }
public function get_images() { $contentType = ContentType::get_for_model('Post', $this->post_type); $images = Doctrine_Query::create()->from('PjangoMedia o')->where('o.content_type_id = ? AND o.object_id = ?', array($contentType->id, $this->id))->execute(); return $images; }
function app_model_settings($request, $app_label = false, $model = false) { $templateArr = array('current_admin_menu' => $app_label, 'current_admin_submenu' => $model, 'current_admin_submenu2' => 'Settings', 'title' => __(sprintf('%s %s Settings', $app_label, $model))); $coreApps = array('Post'); $app_label0 = $app_label; if (in_array($app_label, $coreApps)) { $app_label = sprintf('Pjango\\Contrib\\%s', $app_label); } $contentType = ContentType::get_for_model($model, $app_label); $formClass = sprintf('%s\\Forms\\%sSettingsForm', $app_label, $model); $formData = array(); $ignoredSettings = array('is_active', 'title', 'show_title', 'category_id', 'content'); $settings = Doctrine_Query::create()->from('Settings o')->where('o.category = ? AND o.site_id = ? ', array($app_label, SITE_ID))->fetchArray(); foreach ($settings as $settingsValue) { $formData[$settingsValue['name']] = $settingsValue['value']; } if (class_exists('PageLayout')) { $pageLayout = Doctrine_Query::create()->from('PageLayout o')->where('o.site_id = ? AND o.content_type_id = ?', array(SITE_ID, $contentType->id))->fetchOne(); if ($pageLayout) { $formData = array_merge($formData, $pageLayout->toArray()); } } if ($request->POST) { $form = new $formClass($request->POST); try { if (!$form->is_valid()) { throw new Exception(pjango_gettext('There are some errors, please correct them below.')); } $formData = $form->cleaned_data(); if (class_exists('PageLayout')) { if (!$pageLayout) { $pageLayout = new PageLayout(); } $pageLayout->fromArray($formData); $pageLayout->content_type_id = $contentType->id; $pageLayout->site_id = SITE_ID; $pageLayout->save(); } foreach ($formData as $key => $value) { if (in_array($key, $ignoredSettings)) { unset($formData[$key]); } } Settings::saveFromArray($app_label, $formData); Messages::Info('The operation completed successfully'); HttpResponseRedirect(sprintf('/admin/%s/%s/settings/', $app_label0, $model)); } catch (Exception $e) { Messages::Error($e->getMessage()); } } if (!$form) { $form = new $formClass($formData); } $templateArr['addchange_form'] = $form; render_to_response('admin/addchange.html', $templateArr); }
function admin_delete($request, $taxonomy = 'Post', $id) { $post = Doctrine::getTable('Post')->find($id); if ($post) { try { $contentType = ContentType::get_for_model('Post', $taxonomy); $deleted = Doctrine_Query::create()->delete('PjangoMedia o')->where('o.site_id = ? AND o.content_type_id = ? AND o.object_id = ?', array(SITE_ID, $contentType->id, $post->id))->execute(); $post->unlink('Categories'); $post->save(); $post->delete(); Messages::Info(pjango_gettext('1 record has been deleted.')); } catch (Exception $e) { Messages::Error($e->getMessage()); } } HttpResponseRedirect('/admin/' . $taxonomy . '/Post/'); }
function render($contxt, $stream) { $contentType = ContentType::get_for_model('Post', 'Pjango\\Contrib\\Post'); $slug = false; if (isset($this->args[0])) { $slug = $this->clearQuotes($this->args[0]); } $q = Doctrine_Query::create()->from('PostCategory c')->leftJoin('c.Translation t')->where('c.site_id = ? AND c.taxonomy = ?', array(SITE_ID, Post::TYPE_POST)); if ($slug) { $category = PostCategory::findBySlug($slug, Post::TYPE_POST); if ($category) { $q->andWhere('c.lft >= ? AND c.rgt <= ?', array($category->lft, $category->rgt)); } } $results = $q->execute(); //print_r($results->toArray()); $htmlContent = '<div class="section post">'; if ($pageLayout->show_title) { $htmlContent .= '<h2>' . __($pageLayout->title) . '</h2>'; } $htmlContent .= '<div class="box-content">'; //$htmlContent .= '<ul>'.implode('', $htmlItems).'</ul>'; $htmlContent .= '</div>'; $htmlContent .= '<div class="buttons"><div class="right"><a href="' . pjango_ini_get('SITE_URL') . '/post/">' . __('All Posts') . ' »</a></div></div>'; $htmlContent .= '<div style="clear:both;"></div>'; $htmlContent .= '</div>'; //$stream->write($htmlContent); }